Colota - Android GPS Location tracker
chore: remove dead API level checks and unreachable boot actions
Max Dietrichaf151219cd46
diff --git a/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt b/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.ktindex 464dcfaf..884931c0 100644--- a/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt+++ b/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt@@ -23,7 +23,6 @@ import com.Colota.util.DeviceInfoHelperimport com.Colota.util.FileOperationsimport com.Colota.util.AppLoggerimport com.Colota.util.SecureStorageHelper-import android.os.Buildimport com.facebook.react.bridge.*import com.facebook.react.modules.core.DeviceEventManagerModuleimport com.Colota.location.LocationProviderFactory@@ -260,11 +259,7 @@ class LocationServiceModule(reactContext: ReactApplicationContext) :serviceConfig.toIntent(serviceIntent)try {- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {- reactApplicationContext.startForegroundService(serviceIntent)- } else {- reactApplicationContext.startService(serviceIntent)- }+ reactApplicationContext.startForegroundService(serviceIntent)moduleScope.launch(Dispatchers.IO) {dbHelper.saveSetting("tracking_enabled", "true")}@@ -806,11 +801,7 @@ class LocationServiceModule(reactContext: ReactApplicationContext) :this.action = action}- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {- reactApplicationContext.startForegroundService(intent)- } else {- reactApplicationContext.startService(intent)- }+ reactApplicationContext.startForegroundService(intent)} catch (e: Exception) {AppLogger.e(TAG, "Failed to start service with action: $action", e)throw e@@ -900,7 +891,7 @@ class LocationServiceModule(reactContext: ReactApplicationContext) :val pid = android.os.Process.myPid()val process = Runtime.getRuntime().exec(arrayOf("logcat", "-d", "-v", "threadtime", "--pid=$pid"))val lines = process.inputStream.bufferedReader().readLines()- process.waitFor()+ process.waitFor(10, java.util.concurrent.TimeUnit.SECONDS)Arguments.createArray().apply {lines.filter { "Colota." in it }.forEach { pushString(it) }}diff --git a/apps/mobile/android/app/src/main/java/com/colota/service/BootReceiver.kt b/apps/mobile/android/app/src/main/java/com/colota/service/BootReceiver.ktindex 67828291..e6dffd4c 100644--- a/apps/mobile/android/app/src/main/java/com/colota/service/BootReceiver.kt+++ b/apps/mobile/android/app/src/main/java/com/colota/service/BootReceiver.kt@@ -9,7 +9,6 @@ import android.content.BroadcastReceiverimport com.Colota.data.DatabaseHelperimport android.content.Contextimport android.content.Intent-import android.os.Buildimport com.Colota.util.AppLoggerimport kotlinx.coroutines.*@@ -21,11 +20,8 @@ class LocationBootReceiver : BroadcastReceiver() {companion object {private const val TAG = "BootReceiver"- // Supported boot actions for better device compatibilityprivate val BOOT_ACTIONS = setOf(- Intent.ACTION_BOOT_COMPLETED,- Intent.ACTION_LOCKED_BOOT_COMPLETED,- "android.intent.action.QUICKBOOT_POWERON"+ Intent.ACTION_BOOT_COMPLETED)private const val MAX_DB_RETRIES = 3@@ -100,12 +96,7 @@ class LocationBootReceiver : BroadcastReceiver() {val serviceIntent = Intent(context, LocationForegroundService::class.java)config.toIntent(serviceIntent)- // Start service based on Android version- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {- context.startForegroundService(serviceIntent)- } else {- context.startService(serviceIntent)- }+ context.startForegroundService(serviceIntent)AppLogger.d(TAG, "Service start requested successfully")diff --git a/apps/mobile/android/app/src/main/java/com/colota/service/LocationForegroundService.kt b/apps/mobile/android/app/src/main/java/com/colota/service/LocationForegroundService.ktindex 2339b0f0..82eed6d8 100644--- a/apps/mobile/android/app/src/main/java/com/colota/service/LocationForegroundService.kt+++ b/apps/mobile/android/app/src/main/java/com/colota/service/LocationForegroundService.kt@@ -494,12 +494,7 @@ class LocationForegroundService : Service() {LocationServiceModule.sendTrackingStoppedEvent(reason)dbHelper.saveSetting("tracking_enabled", "false")- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {- stopForeground(Service.STOP_FOREGROUND_DETACH)- } else {- @Suppress("DEPRECATION")- stopForeground(false)- }+ stopForeground(Service.STOP_FOREGROUND_DETACH)notificationManager.notify(NotificationHelper.NOTIFICATION_ID,diff --git a/apps/mobile/android/app/src/main/java/com/colota/service/NotificationHelper.kt b/apps/mobile/android/app/src/main/java/com/colota/service/NotificationHelper.ktindex 6e1bdab9..16f2d9c6 100644--- a/apps/mobile/android/app/src/main/java/com/colota/service/NotificationHelper.kt+++ b/apps/mobile/android/app/src/main/java/com/colota/service/NotificationHelper.kt@@ -8,7 +8,6 @@ package com.Colota.serviceimport android.app.*import android.content.Contextimport android.content.Intent-import android.os.Buildimport androidx.core.app.NotificationCompatimport com.Colota.MainActivityimport java.util.Locale@@ -36,17 +35,15 @@ class NotificationHelper(}fun createChannel() {- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {- val channel = NotificationChannel(- CHANNEL_ID,- "Location Tracking",- NotificationManager.IMPORTANCE_LOW- ).apply {- description = "Shows active tracking status and sync queue"- setShowBadge(false)- }- notificationManager.createNotificationChannel(channel)+ val channel = NotificationChannel(+ CHANNEL_ID,+ "Location Tracking",+ NotificationManager.IMPORTANCE_LOW+ ).apply {+ description = "Shows active tracking status and sync queue"+ setShowBadge(false)}+ notificationManager.createNotificationChannel(channel)}fun buildTrackingNotification(title: String, statusText: String): Notification {diff --git a/apps/mobile/android/app/src/main/java/com/colota/util/DeviceInfoHelper.kt b/apps/mobile/android/app/src/main/java/com/colota/util/DeviceInfoHelper.ktindex 9da415dc..3b2adac0 100644--- a/apps/mobile/android/app/src/main/java/com/colota/util/DeviceInfoHelper.kt+++ b/apps/mobile/android/app/src/main/java/com/colota/util/DeviceInfoHelper.kt@@ -90,18 +90,10 @@ class DeviceInfoHelper(private val context: Context) {fun invalidateBatteryCache() = batteryCache.invalidate()fun isIgnoringBatteryOptimizations(): Boolean {- return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {- powerManager.isIgnoringBatteryOptimizations(context.packageName)- } else {- true // Battery optimization doesn't exist on older versions- }+ return powerManager.isIgnoringBatteryOptimizations(context.packageName)}fun requestIgnoreBatteryOptimizations(): Boolean {- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {- return true // Not applicable on older versions- }-return try {val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {data = Uri.parse("package:${context.packageName}")diff --git a/apps/mobile/android/app/src/test/java/com/Colota/service/LocationBootReceiverTest.kt b/apps/mobile/android/app/src/test/java/com/Colota/service/LocationBootReceiverTest.ktindex 7c73befb..190f48ab 100644--- a/apps/mobile/android/app/src/test/java/com/Colota/service/LocationBootReceiverTest.kt+++ b/apps/mobile/android/app/src/test/java/com/Colota/service/LocationBootReceiverTest.kt@@ -90,24 +90,6 @@ class LocationBootReceiverTest {verify { pendingResult.finish() }}- @Test- fun `onReceive calls goAsync for QUICKBOOT_POWERON`() {- val spy = spyk(receiver)- val pendingResult = mockk<BroadcastReceiver.PendingResult>(relaxed = true)- every { spy.goAsync() } returns pendingResult- every { mockContext.applicationContext } returns mockContext- mockDbReadyAndDisabled()-- val intent = mockk<Intent> {- every { action } returns "android.intent.action.QUICKBOOT_POWERON"- }- spy.onReceive(mockContext, intent)- Thread.sleep(500)-- verify { spy.goAsync() }- verify { pendingResult.finish() }- }-@Testfun `onReceive always calls finish even on error`() {val spy = spyk(receiver)@@ -143,8 +125,7 @@ class LocationBootReceiverTest {callHandleBootCompleted(mockContext, Intent.ACTION_BOOT_COMPLETED)- // Build.VERSION.SDK_INT is 0 in unit tests → startService (not startForegroundService)- verify { mockContext.startService(any()) }+ verify { mockContext.startForegroundService(any()) }}@Test@@ -159,7 +140,7 @@ class LocationBootReceiverTest {@Testfun `handleBootCompleted handles SecurityException gracefully`() = runTest {mockDbReadyAndEnabled()- every { mockContext.startService(any()) } throws SecurityException("Permission denied")+ every { mockContext.startForegroundService(any()) } throws SecurityException("Permission denied")// Should not throwcallHandleBootCompleted(mockContext, Intent.ACTION_BOOT_COMPLETED)