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

Commit 3979c1c

Browse files
committed
update BackgroundManager with new changes to how binding is happening
1 parent adc4251 commit 3979c1c

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,7 @@ class TorServiceController private constructor(): ServiceConsts() {
295295

296296
torServiceNotificationBuilder.build(application.applicationContext)
297297

298-
backgroundManagerPolicy.build(
299-
TorService::class.java,
300-
TorServiceConnection.torServiceConnection
301-
)
298+
backgroundManagerPolicy.build()
302299
}
303300
}
304301

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
* */
6767
package io.matthewnelson.topl_service.lifecycle
6868

69+
import android.content.Context
6970
import androidx.lifecycle.Lifecycle
7071
import androidx.lifecycle.LifecycleObserver
7172
import androidx.lifecycle.OnLifecycleEvent
@@ -117,15 +118,15 @@ import io.matthewnelson.topl_service.util.ServiceConsts
117118
* @param [executionDelay] Length of time before the policy gets executed *after* the application
118119
* is sent to the background.
119120
* @param [serviceClass] The Service class being managed
120-
* @param [serviceConnection] The ServiceConnection being used to bind with
121+
* @param [bindServiceFlag] The flag to be used when binding to the service
121122
* @see [io.matthewnelson.topl_service.service.components.binding.BaseServiceBinder.executeBackgroundPolicyJob]
122123
* @see [io.matthewnelson.topl_service.service.components.binding.BaseServiceBinder.cancelExecuteBackgroundPolicyJob]
123124
* */
124125
class BackgroundManager internal constructor(
125126
@BackgroundPolicy private val policy: String,
126127
private val executionDelay: Long,
127128
private val serviceClass: Class<*>,
128-
private val serviceConnection: TorServiceConnection
129+
private val bindServiceFlag: Int
129130
): ServiceConsts(), LifecycleObserver {
130131

131132

@@ -213,8 +214,8 @@ class BackgroundManager internal constructor(
213214
* test classes get initialized so they aren't overwritten by production classes.
214215
* */
215216
internal fun build(
216-
serviceClass: Class<*>,
217-
serviceConnection: TorServiceConnection
217+
serviceClass: Class<*> = TorService::class.java,
218+
bindServiceFlag: Int = Context.BIND_AUTO_CREATE
218219
) {
219220

220221
// Only initialize it once. Reflection has issues here
@@ -227,7 +228,7 @@ class BackgroundManager internal constructor(
227228
policyBuilder.chosenPolicy,
228229
policyBuilder.executionDelay,
229230
serviceClass,
230-
serviceConnection
231+
bindServiceFlag
231232
)
232233
}
233234
}
@@ -261,8 +262,9 @@ class BackgroundManager internal constructor(
261262
BaseService.startService(
262263
BaseService.getAppContext(),
263264
serviceClass,
264-
serviceConnection,
265-
includeIntentActionStart = false
265+
TorServiceConnection.torServiceConnection,
266+
includeIntentActionStart = false,
267+
bindServiceFlag = bindServiceFlag
266268
)
267269
}
268270
}

0 commit comments

Comments
 (0)