Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import io.homeassistant.companion.android.common.data.keychain.NamedKeyChain
import io.homeassistant.companion.android.common.data.prefs.PrefsRepository
import io.homeassistant.companion.android.common.sensors.AudioSensorManager
import io.homeassistant.companion.android.common.sensors.LastUpdateManager
import io.homeassistant.companion.android.common.util.HAStrictMode
import io.homeassistant.companion.android.common.util.isAutomotive
import io.homeassistant.companion.android.database.AppDatabase
import io.homeassistant.companion.android.database.settings.SensorUpdateFrequencySetting
Expand All @@ -34,8 +33,6 @@ import io.homeassistant.companion.android.themes.NightModeManager
import io.homeassistant.companion.android.util.LifecycleHandler
import io.homeassistant.companion.android.util.QuestUtil
import io.homeassistant.companion.android.util.initCrashSaving
import io.homeassistant.companion.android.util.threadPolicyIgnoredViolationRules
import io.homeassistant.companion.android.util.vmPolicyIgnoredViolationRules
import io.homeassistant.companion.android.websocket.WebsocketBroadcastReceiver
import io.homeassistant.companion.android.widgets.button.ButtonWidget
import io.homeassistant.companion.android.widgets.entity.EntityWidget
Expand Down Expand Up @@ -81,10 +78,10 @@ open class HomeAssistantApplication :
BuildConfig.DEBUG &&
!BuildConfig.NO_STRICT_MODE
) {
HAStrictMode.enable(
vmPolicyIgnoredViolationRules = vmPolicyIgnoredViolationRules,
threadPolicyIgnoredViolationRules = threadPolicyIgnoredViolationRules,
)
// HAStrictMode.enable(
// vmPolicyIgnoredViolationRules = vmPolicyIgnoredViolationRules,
// threadPolicyIgnoredViolationRules = threadPolicyIgnoredViolationRules,
// )
}

// We should initialize the logger as early as possible in the lifecycle of the application
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies {
ksp(libs.androidx.room.compiler)

api(libs.androidx.work.runtime.ktx)
implementation(libs.androidx.concurrent.ktx)

// TODO should not expose retrofit outside of common https://github.com/home-assistant/android/issues/5421
api(platform(libs.retrofit.bom))
Expand Down
8 changes: 4 additions & 4 deletions common/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ androidx.compose.ui:ui-util-android:1.9.4=debugAndroidTestCompileClasspath,debug
androidx.compose.ui:ui-util:1.9.4=androidTestImplementationDependenciesMetadata,debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,implementationDependenciesMetadata,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.compose.ui:ui:1.9.4=androidTestImplementationDependenciesMetadata,debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,implementationDependenciesMetadata,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.compose:compose-bom:2025.11.00=androidTestImplementationDependenciesMetadata,debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,implementationDependenciesMetadata,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.concurrent:concurrent-futures-ktx:1.1.0=debugRuntimeClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
androidx.concurrent:concurrent-futures-ktx:1.2.0=androidTestImplementationDependenciesMetadata,debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath
androidx.concurrent:concurrent-futures:1.1.0=debugRuntimeClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.concurrent:concurrent-futures:1.2.0=androidTestImplementationDependenciesMetadata,debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath
androidx.concurrent:concurrent-futures-ktx:1.2.0=androidTestImplementationDependenciesMetadata
androidx.concurrent:concurrent-futures-ktx:1.3.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,implementationDependenciesMetadata,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.concurrent:concurrent-futures:1.2.0=androidTestImplementationDependenciesMetadata
androidx.concurrent:concurrent-futures:1.3.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,implementationDependenciesMetadata,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.core:core-ktx:1.17.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,implementationDependenciesMetadata,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.core:core-viewtree:1.0.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,implementationDependenciesMetadata,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.core:core:1.1.0=androidTestImplementationDependenciesMetadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import android.app.NotificationManager
import android.content.Context
import android.content.pm.ServiceInfo
import android.os.Build
import androidx.concurrent.futures.await
import androidx.core.app.NotificationCompat
import androidx.core.content.getSystemService
import androidx.work.CoroutineWorker
import androidx.work.ForegroundInfo
import androidx.work.WorkInfo
import androidx.work.WorkManager
import androidx.work.WorkerParameters
import io.homeassistant.companion.android.common.R as commonR
import io.homeassistant.companion.android.common.data.servers.ServerManager
import io.homeassistant.companion.android.common.util.CHANNEL_SENSOR_WORKER
import io.homeassistant.companion.android.database.AppDatabase
import java.lang.IllegalStateException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber
Expand All @@ -28,6 +30,9 @@ abstract class SensorWorkerBase(val appContext: Context, workerParams: WorkerPar
companion object {
const val TAG = "SensorWorker"
const val NOTIFICATION_ID = 42

// WARNING: Use the tag from WebsocketManager in :app
private const val WEBSOCKET_MANAGER_TAG = "WebSocketManager"
}

private val notificationManager = appContext.getSystemService<NotificationManager>()!!
Expand All @@ -51,11 +56,7 @@ abstract class SensorWorkerBase(val appContext: Context, workerParams: WorkerPar
val foregroundInfo = ForegroundInfo(
NOTIFICATION_ID,
notification,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
} else {
0
},
determineForegroundServiceType(),
)
try {
setForeground(foregroundInfo)
Expand Down Expand Up @@ -88,6 +89,28 @@ abstract class SensorWorkerBase(val appContext: Context, workerParams: WorkerPar
Result.success()
}

private suspend fun determineForegroundServiceType(): Int {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
// if (isWebSocketManagerRunning()) {
// ServiceInfo.FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING
// } else {
// ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
// }
ServiceInfo.FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
} else {
0
}.apply { Timber.d("Using Foreground type: $this for updating sensor") }
}

private suspend fun isWebSocketManagerRunning(): Boolean {
return WorkManager.getInstance(applicationContext)
.getWorkInfosByTag(WEBSOCKET_MANAGER_TAG)
.await()
.any { it.state == WorkInfo.State.RUNNING }
}

protected fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationChannel = NotificationChannel(
Expand Down
8 changes: 4 additions & 4 deletions onboarding/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ androidx.compose.ui:ui-util-android:1.9.4=debugAndroidTestCompileClasspath,debug
androidx.compose.ui:ui-util:1.9.4=androidTestImplementationDependenciesMetadata,debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.compose.ui:ui:1.9.4=androidTestImplementationDependenciesMetadata,debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.compose:compose-bom:2025.11.00=androidTestImplementationDependenciesMetadata,debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.concurrent:concurrent-futures-ktx:1.1.0=debugRuntimeClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
androidx.concurrent:concurrent-futures-ktx:1.2.0=androidTestImplementationDependenciesMetadata,debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath
androidx.concurrent:concurrent-futures:1.1.0=debugRuntimeClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.concurrent:concurrent-futures:1.2.0=androidTestImplementationDependenciesMetadata,debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath
androidx.concurrent:concurrent-futures-ktx:1.2.0=androidTestImplementationDependenciesMetadata
androidx.concurrent:concurrent-futures-ktx:1.3.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugRuntimeClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
androidx.concurrent:concurrent-futures:1.2.0=androidTestImplementationDependenciesMetadata
androidx.concurrent:concurrent-futures:1.3.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugRuntimeClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.core:core-ktx:1.17.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.core:core-ktx:1.2.0=androidTestImplementationDependenciesMetadata
androidx.core:core-splashscreen:1.2.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
Expand Down
8 changes: 4 additions & 4 deletions wear/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ androidx.compose.ui:ui-util-android:1.9.4=debugAndroidTestCompileClasspath,debug
androidx.compose.ui:ui-util:1.9.4=androidTestImplementationDependenciesMetadata,debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.compose.ui:ui:1.9.4=androidTestImplementationDependenciesMetadata,debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.compose:compose-bom:2025.11.00=androidTestImplementationDependenciesMetadata,debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.concurrent:concurrent-futures-ktx:1.1.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath
androidx.concurrent:concurrent-futures-ktx:1.2.0=androidTestImplementationDependenciesMetadata,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.concurrent:concurrent-futures:1.1.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath
androidx.concurrent:concurrent-futures:1.2.0=androidTestImplementationDependenciesMetadata,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.concurrent:concurrent-futures-ktx:1.2.0=androidTestImplementationDependenciesMetadata
androidx.concurrent:concurrent-futures-ktx:1.3.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.concurrent:concurrent-futures:1.2.0=androidTestImplementationDependenciesMetadata
androidx.concurrent:concurrent-futures:1.3.0=debugAndroidTestCompileClasspath,debugAndroidTestRuntimeClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.constraintlayout:constraintlayout-core:1.0.0=debugRuntimeClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestRuntimeClasspath,releaseRuntimeClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestRuntimeClasspath
androidx.constraintlayout:constraintlayout:2.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
androidx.coordinatorlayout:coordinatorlayout:1.1.0=debugAndroidTestCompileClasspath,debugCompileClasspath,debugRuntimeClasspath,debugScreenshotTestCompileClasspath,debugScreenshotTestRuntimeClasspath,debugUnitTestCompileClasspath,debugUnitTestRuntimeClasspath,releaseCompileClasspath,releaseRuntimeClasspath,releaseScreenshotTestCompileClasspath,releaseScreenshotTestRuntimeClasspath,releaseUnitTestCompileClasspath,releaseUnitTestRuntimeClasspath
Expand Down
Loading