Set 10sec timeout for acquired wakeLock

This commit is contained in:
sim 2022-01-14 09:14:40 +01:00
parent 8db0e41628
commit c678162e58
3 changed files with 3 additions and 7 deletions

View File

@ -23,9 +23,7 @@ private const val TAG = "RegisterBroadcastReceiver"
class RegisterBroadcastReceiver : BroadcastReceiver() { class RegisterBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) { override fun onReceive(context: Context?, intent: Intent?) {
wakeLock?.let { wakeLock?.acquire(10000L /*10 secs*/)
it.acquire()
}
when (intent!!.action) { when (intent!!.action) {
ACTION_REGISTER ->{ ACTION_REGISTER ->{
Log.i(TAG,"REGISTER") Log.i(TAG,"REGISTER")

View File

@ -36,9 +36,7 @@ class SSEListener (val context: Context) : EventSourceListener() {
override fun onEvent(eventSource: EventSource, id: String?, type: String?, data: String) { override fun onEvent(eventSource: EventSource, id: String?, type: String?, data: String) {
Log.d(TAG, "New SSE message event=$type message=$data") Log.d(TAG, "New SSE message event=$type message=$data")
wakeLock?.let { wakeLock?.acquire(10000L /*10 secs*/)
it.acquire()
}
when (type) { when (type) {
"warning" -> Log.d(TAG, "Warning event received.") "warning" -> Log.d(TAG, "Warning event received.")
"ping" -> Log.d(TAG, "SSE ping received.") "ping" -> Log.d(TAG, "SSE ping received.")

View File

@ -99,7 +99,7 @@ class StartService: Service(){
// we need this lock so our service gets not affected by Doze Mode // we need this lock so our service gets not affected by Doze Mode
wakeLock = (getSystemService(Context.POWER_SERVICE) as PowerManager).run { wakeLock = (getSystemService(Context.POWER_SERVICE) as PowerManager).run {
newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG).apply { newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG).apply {
acquire() acquire(10000L /*10 secs*/)
} }
} }