Skip to content
Snippets Groups Projects
Commit 0dd83be7 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

JamiJobService: use EXTRA_TIMEOUT to manage service timeout

Change-Id: Iaf6504c2aab085c9f6ed5d7fd631b8276ee3ffc3
parent 7227365d
No related branches found
No related tags found
No related merge requests found
......@@ -32,19 +32,16 @@ class JamiJobService : JobService() {
try {
try {
ContextCompat.startForegroundService(this, Intent(SyncService.ACTION_START)
.putExtra(SyncService.EXTRA_TIMEOUT, JOB_DURATION)
.setClass(this, SyncService::class.java))
} catch (e: IllegalStateException) {
Log.e(TAG, "Error starting service", e)
}
JamiApplication.instance?.startDaemon(this)
Handler().postDelayed({
Log.w(TAG, "jobFinished() $params")
try {
startService(Intent(SyncService.ACTION_STOP).setClass(this, SyncService::class.java))
} catch (ignored: IllegalStateException) {
}
jobFinished(params, false)
}, JOB_DURATION)
JamiApplication.instance?.startDaemon(this)
}, JOB_DURATION + 500)
} catch (e: Exception) {
Log.e(TAG, "onStartJob failed", e)
}
......@@ -67,7 +64,7 @@ class JamiJobService : JobService() {
private val TAG = JamiJobService::class.java.name
const val JOB_INTERVAL = 12 * DateUtils.HOUR_IN_MILLIS
const val JOB_FLEX = 60 * DateUtils.MINUTE_IN_MILLIS
const val JOB_DURATION = 10 * DateUtils.SECOND_IN_MILLIS
const val JOB_DURATION = 7 * DateUtils.SECOND_IN_MILLIS
const val JOB_ID = 3905
}
}
\ No newline at end of file
......@@ -50,9 +50,11 @@ class SyncService : Service() {
if (notification == null) {
val deleteIntent = Intent(ACTION_STOP)
.setClass(applicationContext, SyncService::class.java)
val contentIntent = Intent(Intent.ACTION_VIEW)
.setClass(applicationContext, HomeActivity::class.java)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
notification = NotificationCompat.Builder(this, NotificationServiceImpl.NOTIF_CHANNEL_SYNC)
.setContentTitle(getString(R.string.notif_sync_title))
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
......@@ -77,21 +79,25 @@ class SyncService : Service() {
val timeout = intent.getLongExtra(EXTRA_TIMEOUT, -1)
if (timeout > 0) {
Handler().postDelayed({
try {
startService(Intent(ACTION_STOP).setClass(applicationContext, SyncService::class.java))
} catch (ignored: IllegalStateException) {
}
stop()
}, timeout)
}
} else if (ACTION_STOP == action) {
stop()
}
return START_NOT_STICKY
}
private fun stop() {
serviceUsers--
if (serviceUsers == 0) {
try {
stopForeground(true)
stopSelf()
notification = null
} catch (ignored: IllegalStateException) {
}
notification = null
}
return START_NOT_STICKY
}
override fun onBind(intent: Intent): IBinder? = null
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment