@@ -23,6 +23,7 @@ import kotlinx.coroutines.Dispatchers
2323import kotlinx.coroutines.SupervisorJob
2424import kotlinx.coroutines.delay
2525import kotlinx.coroutines.withContext
26+ import kotlinx.coroutines.withTimeoutOrNull
2627import org.koin.core.component.KoinComponent
2728import org.koin.core.component.inject
2829import kotlin.time.Duration.Companion.seconds
@@ -31,7 +32,7 @@ class StartUpWorker(
3132 private val context : Context ,
3233 workerParams : WorkerParameters
3334) : CoroutineWorker(context, workerParams), KoinComponent {
34- private val mainContext = Dispatchers .Main + SupervisorJob ()
35+ private val mainContext = Dispatchers .Main .immediate + SupervisorJob ()
3536 private val workerContext = Dispatchers .Default
3637 private val appPrefs: AppPrefs by inject()
3738 private val rootUtils: RootUtils by inject()
@@ -57,7 +58,6 @@ class StartUpWorker(
5758 }
5859 }
5960
60-
6161 return Result .success()
6262 }
6363
@@ -71,7 +71,10 @@ class StartUpWorker(
7171 }
7272
7373 private suspend fun checkRequirements (): Boolean {
74- return appPrefs.runOnStartUp && rootUtils.isRootAvailable()
74+ return withTimeoutOrNull(5 .seconds) {
75+ rootUtils.getRootShell()
76+ appPrefs.runOnStartUp && rootUtils.isRootAvailable()
77+ } ? : false
7578 }
7679
7780 private suspend inline fun showNotificationAndThen (
@@ -137,7 +140,6 @@ class StartUpWorker(
137140 delayCount++
138141 }
139142 }
140-
141143 } else {
142144 builder.setContentText(context.getString(R .string.notification_start_up_description))
143145 notifyIfPossible(builder)
@@ -152,7 +154,7 @@ class StartUpWorker(
152154 ) == PackageManager .PERMISSION_GRANTED ||
153155 Build .VERSION .SDK_INT <= Build .VERSION_CODES .TIRAMISU
154156 ) {
155- runCatching { notificationManager.notify(SERVICE_ID , builder.build()) }.onFailure { it.printStackTrace() }
157+ runCatching { notificationManager.notify(SERVICE_ID , builder.build()) }
156158 }
157159 }
158160
0 commit comments