feat: 组件解耦

This commit is contained in:
2025-11-27 16:52:43 +08:00
parent 4712855f6c
commit 0c122b9352
14 changed files with 96 additions and 61 deletions
@@ -57,7 +57,7 @@ class DeviceServiceManager(val context: Application) : ConnectivityManager.Netwo
/**
* 系统电量
*/
private val _batteryPercentage = MutableStateFlow(-1)
private val _batteryPercentage = MutableStateFlow(getBatteryLevel(context))
val batteryPercentage = _batteryPercentage.asStateFlow()
/**
@@ -293,6 +293,11 @@ class DeviceServiceManager(val context: Application) : ConnectivityManager.Netwo
}
}
private fun getBatteryLevel(context: Context): Int {
val bm = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager
return bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY)
}
inner class SysKeyReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val action = intent?.action ?: return