feat(US-12, US-13): request battery exemption on launch, verify test coverage
MainActivity now requests battery optimization exemption on first launch so the foreground service survives Doze mode during long walks. The REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission was already declared in the manifest. Unit test coverage confirmed across all core logic: BeepGeneratorTest (4), BpmCalculatorTest (6), SettingsRepositoryTest (6).
This commit is contained in:
parent
d296f2bfec
commit
12f38c19ab
1 changed files with 16 additions and 0 deletions
|
|
@ -1,6 +1,10 @@
|
|||
package net.jeena.pacer
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.PowerManager
|
||||
import android.provider.Settings
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
|
|
@ -18,6 +22,7 @@ class MainActivity : ComponentActivity() {
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
requestBatteryOptimizationExemption()
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
PacerTheme {
|
||||
|
|
@ -30,4 +35,15 @@ class MainActivity : ComponentActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestBatteryOptimizationExemption() {
|
||||
val pm = getSystemService(PowerManager::class.java)
|
||||
if (!pm.isIgnoringBatteryOptimizations(packageName)) {
|
||||
startActivity(
|
||||
Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
|
||||
data = Uri.parse("package:$packageName")
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue