Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit 8c7dd93

Browse files
committed
add BackgroundManager Policy method to check requirements for enabling Builder option stopServiceOnTaskRemoved
1 parent ccb8e61 commit 8c7dd93

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

topl-service/src/main/java/io/matthewnelson/topl_service/lifecycle/BackgroundManager.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ class BackgroundManager internal constructor(
151151
class Builder {
152152

153153
@BackgroundPolicy
154-
internal lateinit var chosenPolicy: String
154+
private lateinit var chosenPolicy: String
155155
private var executionDelay: Long = 30_000L
156-
internal var killAppIfTaskIsRemoved = false
156+
private var killAppIfTaskIsRemoved = false
157157

158158
/**
159159
* Stops [TorService] after being in the background for the declared [secondsFrom5To45].
@@ -221,7 +221,16 @@ class BackgroundManager internal constructor(
221221
*
222222
* @param [policyBuilder] The [BackgroundManager.Builder] to be built during initialization
223223
* */
224-
class Policy(internal val policyBuilder: Builder) {
224+
class Policy internal constructor (private val policyBuilder: Builder) {
225+
226+
internal fun configurationIsCompliant(stopServiceOnTaskRemoved: Boolean): Boolean {
227+
return if (stopServiceOnTaskRemoved) {
228+
policyBuilder.chosenPolicy == BackgroundPolicy.RUN_IN_FOREGROUND &&
229+
policyBuilder.killAppIfTaskIsRemoved
230+
} else {
231+
true
232+
}
233+
}
225234

226235
/**
227236
* Only available internally, so this is where we intercept for integration testing.

0 commit comments

Comments
 (0)