Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ dependencies {
compileOnly(libs.auto.service.annotations)
ksp(libs.auto.service.ksp)
ksp(libs.auto.service)

testImplementation(libs.kotlin.test)
testImplementation(libs.junit4)
testImplementation(libs.robolectric)
testImplementation(libs.androidx.test.core)
}

kotlin {
Expand Down Expand Up @@ -98,5 +103,12 @@ android {
lint {
warning.add("InvalidFragmentVersionForActivityResult")
}

testOptions {
unitTests {
isIncludeAndroidResources = true
isReturnDefaultValues = true
}
}
namespace = "com.anod.car.home"
}
16 changes: 16 additions & 0 deletions app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application>
<!--
Debug-only: re-export SwitchInCarActivity so it can be launched from
scripts/switch_incar.sh via `adb shell am start`. Release builds keep
exported="false" (see main AndroidManifest.xml).
-->
<activity
android:name="com.anod.car.home.incar.SwitchInCarActivity"
android:exported="true"
tools:replace="android:exported" />
</application>
</manifest>
14 changes: 3 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<activity android:name="com.anod.car.home.OverlayActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:exported="true"
android:exported="false"
android:launchMode="singleInstance"
android:taskAffinity="com.anod.car.home.overlay"
android:theme="@style/BrightnessTheme" />
Expand All @@ -83,7 +83,7 @@
android:name="com.anod.car.home.ShortcutActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:exported="true"
android:exported="false"
android:launchMode="singleInstance"
android:noHistory="true"
android:taskAffinity="com.anod.car.home.shortcut"
Expand Down Expand Up @@ -128,7 +128,7 @@
android:name="com.anod.car.home.incar.SwitchInCarActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:exported="true"
android:exported="false"
android:label="@string/switch_in_car_activity"
android:launchMode="singleInstance"
android:noHistory="true"
Expand Down Expand Up @@ -254,14 +254,6 @@
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />

<activity
android:name=".incar.AcceptCallActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:excludeFromRecents="true"
android:launchMode="singleTop"
android:taskAffinity=""
android:theme="@style/BrightnessTheme" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
Expand Down
138 changes: 0 additions & 138 deletions app/src/main/java/com/anod/car/home/incar/AcceptCallActivity.kt

This file was deleted.

61 changes: 35 additions & 26 deletions app/src/main/java/com/anod/car/home/incar/ModeDetector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object ModeDetector {

val prefState: BooleanArray
get() = synchronized(sLock) {
return sPrefState
return sPrefState.copyOf()
}

fun eventsState(): List<InCarStatus.EventState> {
Expand All @@ -54,7 +54,9 @@ object ModeDetector {
}

fun onRegister(context: Context) {
sEventState[FLAG_POWER] = Power.isConnected(context)
synchronized(sLock) {
sEventState[FLAG_POWER] = Power.isConnected(context)
}
}

fun updatePrefState(prefs: InCarInterface) {
Expand All @@ -68,21 +70,23 @@ object ModeDetector {
}

fun forceState(prefs: InCarInterface, forceMode: Boolean) {
updatePrefState(prefs)
if (sPrefState[FLAG_POWER]) {
sEventState[FLAG_POWER] = forceMode
}
if (sPrefState[FLAG_HEADSET]) {
sEventState[FLAG_HEADSET] = forceMode
}
if (sPrefState[FLAG_BLUETOOTH]) {
sEventState[FLAG_BLUETOOTH] = forceMode
}
if (sPrefState[FLAG_ACTIVITY]) {
sEventState[FLAG_ACTIVITY] = forceMode
}
if (sPrefState[FLAG_CAR_DOCK]) {
sEventState[FLAG_CAR_DOCK] = forceMode
synchronized(sLock) {
updatePrefState(prefs)
if (sPrefState[FLAG_POWER]) {
sEventState[FLAG_POWER] = forceMode
}
if (sPrefState[FLAG_HEADSET]) {
sEventState[FLAG_HEADSET] = forceMode
}
if (sPrefState[FLAG_BLUETOOTH]) {
sEventState[FLAG_BLUETOOTH] = forceMode
}
if (sPrefState[FLAG_ACTIVITY]) {
sEventState[FLAG_ACTIVITY] = forceMode
}
if (sPrefState[FLAG_CAR_DOCK]) {
sEventState[FLAG_CAR_DOCK] = forceMode
}
}
}

Expand All @@ -99,15 +103,16 @@ object ModeDetector {
onPowerConnected(prefs, context)
}

updatePrefState(prefs)
updateEventState(prefs, intent)
if (BuildConfig.DEBUG) {
for (i in sPrefState.indices) {
AppLog.d(sTitles[i] + ": pref - " + sPrefState[i] + ", event - " + sEventState[i])
val newMode = synchronized(sLock) {
updatePrefState(prefs)
updateEventState(prefs, intent)
if (BuildConfig.DEBUG) {
for (i in sPrefState.indices) {
AppLog.d(sTitles[i] + ": pref - " + sPrefState[i] + ", event - " + sEventState[i])
}
}
detectNewMode()
}

val newMode = detectNewMode()
AppLog.i("New mode: " + newMode + " Car Mode: " + ModeService.sInCarMode)
if (!ModeService.sInCarMode && newMode) {
val service = ModeService.createStartIntent(context, ModeService.MODE_SWITCH_ON)
Expand Down Expand Up @@ -231,12 +236,16 @@ object ModeDetector {
}

fun switchOn(prefs: InCarInterface, modeHandler: ModeHandler) {
sMode = true
synchronized(sLock) {
sMode = true
}
modeHandler.enable(prefs)
}

fun switchOff(prefs: InCarInterface, modeHandler: ModeHandler) {
sMode = false
synchronized(sLock) {
sMode = false
}
modeHandler.disable(prefs)
}
}
Loading