diff --git a/app/src/main/java/io/homeassistant/companion/android/sensors/SensorReceiver.kt b/app/src/main/java/io/homeassistant/companion/android/sensors/SensorReceiver.kt index 9a2eebe1c54..417dd41e304 100644 --- a/app/src/main/java/io/homeassistant/companion/android/sensors/SensorReceiver.kt +++ b/app/src/main/java/io/homeassistant/companion/android/sensors/SensorReceiver.kt @@ -11,6 +11,7 @@ import android.net.wifi.WifiManager import android.os.PowerManager import dagger.hilt.android.AndroidEntryPoint import io.homeassistant.companion.android.BuildConfig +import io.homeassistant.companion.android.common.sensors.AndroidOsSensorManager import io.homeassistant.companion.android.common.sensors.AudioSensorManager import io.homeassistant.companion.android.common.sensors.BatterySensorManager import io.homeassistant.companion.android.common.sensors.BluetoothSensorManager @@ -52,6 +53,7 @@ class SensorReceiver : SensorReceiverBase() { val MANAGERS = listOf( ActivitySensorManager(), AndroidAutoSensorManager(), + AndroidOsSensorManager(), AppSensorManager(), AudioSensorManager(), BatterySensorManager(), diff --git a/common/src/main/java/io/homeassistant/companion/android/common/sensors/AndroidOsSensorManager.kt b/common/src/main/java/io/homeassistant/companion/android/common/sensors/AndroidOsSensorManager.kt new file mode 100644 index 00000000000..c1745baa8aa --- /dev/null +++ b/common/src/main/java/io/homeassistant/companion/android/common/sensors/AndroidOsSensorManager.kt @@ -0,0 +1,80 @@ +package io.homeassistant.companion.android.common.sensors + +import android.content.Context +import android.os.Build +import io.homeassistant.companion.android.common.R as commonR + +class AndroidOsSensorManager : SensorManager { + + companion object { + val osVersion = SensorManager.BasicSensor( + "android_os_version", + "sensor", + commonR.string.basic_sensor_name_android_os_version, + commonR.string.sensor_description_android_os_version, + "mdi:android", + entityCategory = SensorManager.ENTITY_CATEGORY_DIAGNOSTIC + ) + val osSecurityPatch = SensorManager.BasicSensor( + "android_os_security_patch", + "sensor", + commonR.string.basic_sensor_name_android_os_security_patch, + commonR.string.sensor_description_android_os_security_patch, + "mdi:security", + entityCategory = SensorManager.ENTITY_CATEGORY_DIAGNOSTIC + ) + } + + override fun docsLink(): String { + return "https://companion.home-assistant.io/docs/core/sensors#android-os-sensors" + } + + override val name: Int + get() = commonR.string.sensor_name_android_os + + override suspend fun getAvailableSensors(context: Context): List { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + listOf(osVersion, osSecurityPatch) + } else { + listOf(osVersion) + } + } + + override fun requiredPermissions(sensorId: String): Array { + return arrayOf() + } + + override fun requestSensorUpdate( + context: Context + ) { + checkState(context, osVersion) + checkState(context, osSecurityPatch) + } + + private fun checkState( + context: Context, + sensor: SensorManager.BasicSensor + ) { + if (!isEnabled(context, sensor)) { + return + } + + onSensorUpdated( + context, + sensor, + when (sensor.id) { + osVersion.id -> Build.VERSION.RELEASE + osSecurityPatch.id -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Build.VERSION.SECURITY_PATCH + } else { + "unknown" + } + else -> { + "unknown" + } + }, + sensor.statelessIcon, + mapOf() + ) + } +} diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index b4e0ea750bc..aa924882ff6 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -42,6 +42,8 @@ Detected Activity Next Alarm Android Auto + OS Version + Security Patch App Importance App Inactive App Memory @@ -494,6 +496,8 @@ Total count of active notifications that are visible to the user including silent, persistent and the Sensor Worker notifications. If the app is in the foreground, background or any other state it can be. If the phone is currently connected to an Android Auto head unit. + Android OS version. + Android OS security patch. Whether the app is currently considered inactive by the system Total used and available memory for the app App Rx GB since last device reboot @@ -574,6 +578,7 @@ Activity Sensors Alarm Sensor Android Auto Sensors + Android OS Sensors App Sensors Audio Mode Audio Sensors diff --git a/wear/src/main/java/io/homeassistant/companion/android/sensors/SensorReceiver.kt b/wear/src/main/java/io/homeassistant/companion/android/sensors/SensorReceiver.kt index c2b3ee8f417..0f22282656b 100644 --- a/wear/src/main/java/io/homeassistant/companion/android/sensors/SensorReceiver.kt +++ b/wear/src/main/java/io/homeassistant/companion/android/sensors/SensorReceiver.kt @@ -14,6 +14,7 @@ import androidx.core.app.TaskStackBuilder import androidx.core.net.toUri import dagger.hilt.android.AndroidEntryPoint import io.homeassistant.companion.android.BuildConfig +import io.homeassistant.companion.android.common.sensors.AndroidOsSensorManager import io.homeassistant.companion.android.common.sensors.AudioSensorManager import io.homeassistant.companion.android.common.sensors.BatterySensorManager import io.homeassistant.companion.android.common.sensors.BluetoothSensorManager @@ -54,6 +55,7 @@ class SensorReceiver : SensorReceiverBase() { companion object { const val TAG = "SensorReceiver" private val allManager = listOf( + AndroidOsSensorManager(), AppSensorManager(), AudioSensorManager(), BatterySensorManager(),