Fixed the timeout issue with the JobScheduler
This commit is contained in:
parent
f4b6bcb8d9
commit
34e2e0673b
@ -17,12 +17,17 @@
|
|||||||
package ch.dissem.apps.abit.service
|
package ch.dissem.apps.abit.service
|
||||||
|
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.IntentFilter
|
||||||
|
import android.net.ConnectivityManager
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import ch.dissem.apps.abit.notification.NetworkNotification
|
import ch.dissem.apps.abit.notification.NetworkNotification
|
||||||
import ch.dissem.apps.abit.notification.NetworkNotification.Companion.NETWORK_NOTIFICATION_ID
|
import ch.dissem.apps.abit.notification.NetworkNotification.Companion.NETWORK_NOTIFICATION_ID
|
||||||
import ch.dissem.bitmessage.BitmessageContext
|
import ch.dissem.bitmessage.BitmessageContext
|
||||||
import ch.dissem.bitmessage.utils.Property
|
import ch.dissem.bitmessage.utils.Property
|
||||||
|
import org.jetbrains.anko.connectivityManager
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a Service that returns an IBinder for the
|
* Define a Service that returns an IBinder for the
|
||||||
@ -34,6 +39,14 @@ class BitmessageService : Service() {
|
|||||||
private val bmc: BitmessageContext by lazy { Singleton.getBitmessageContext(this) }
|
private val bmc: BitmessageContext by lazy { Singleton.getBitmessageContext(this) }
|
||||||
private lateinit var notification: NetworkNotification
|
private lateinit var notification: NetworkNotification
|
||||||
|
|
||||||
|
private val connectivityReceiver: BroadcastReceiver = object: BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
|
if (bmc.isRunning() && connectivityManager.isActiveNetworkMetered){
|
||||||
|
bmc.shutdown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val cleanupHandler = Handler()
|
private val cleanupHandler = Handler()
|
||||||
private val cleanupTask: Runnable = object : Runnable {
|
private val cleanupTask: Runnable = object : Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
@ -45,6 +58,7 @@ class BitmessageService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
|
registerReceiver(connectivityReceiver, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
|
||||||
notification = NetworkNotification(this)
|
notification = NetworkNotification(this)
|
||||||
running = false
|
running = false
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,8 @@ class StartupNodeOnWifiService : JobService() {
|
|||||||
|
|
||||||
override fun onStopJob(params: JobParameters?): Boolean {
|
override fun onStopJob(params: JobParameters?): Boolean {
|
||||||
if (Preferences.isWifiOnly(this)) {
|
if (Preferences.isWifiOnly(this)) {
|
||||||
Singleton.getBitmessageContext(this).shutdown()
|
// Don't actually stop the service, otherwise it will be stopped after 1 or 10 minutes
|
||||||
|
// depending on Android version.
|
||||||
return Preferences.isFullNodeActive(this)
|
return Preferences.isFullNodeActive(this)
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
|
Loading…
Reference in New Issue
Block a user