From 49828c9bf1100f962a6985b7a1a651c756bbe66f Mon Sep 17 00:00:00 2001 From: sim Date: Tue, 29 Aug 2023 23:12:50 +0200 Subject: [PATCH] Always use applicationContext in receiver --- .../receivers/RegisterBroadcastReceiver.kt | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/receivers/RegisterBroadcastReceiver.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/receivers/RegisterBroadcastReceiver.kt index 50a217b..0d5e8b5 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/receivers/RegisterBroadcastReceiver.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/receivers/RegisterBroadcastReceiver.kt @@ -32,7 +32,8 @@ private const val WAKE_LOCK_TAG = "NextPush:RegisterBroadcastReceiver:lock" class RegisterBroadcastReceiver : BroadcastReceiver() { - override fun onReceive(context: Context, intent: Intent?) { + override fun onReceive(rContext: Context, intent: Intent?) { + val context = rContext.applicationContext wakeLock = (context.getSystemService(Context.POWER_SERVICE) as PowerManager).run { newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG) } @@ -48,17 +49,17 @@ class RegisterBroadcastReceiver : BroadcastReceiver() { Log.w(TAG, "Trying to register an app without packageName") return } - when (checkToken(context.applicationContext, connectorToken, application)) { - TOKEN_REGISTERED_OK -> sendEndpoint(context.applicationContext, connectorToken) + when (checkToken(context, connectorToken, application)) { + TOKEN_REGISTERED_OK -> sendEndpoint(context, connectorToken) TOKEN_NOK -> sendRegistrationFailed( - context.applicationContext, + context, application, connectorToken ) TOKEN_NEW -> { - if (!isConnected(context.applicationContext)) { + if (!isConnected(context)) { sendRegistrationFailed( - context.applicationContext, + context, application, connectorToken, message = "NextPush is not connected" @@ -69,11 +70,11 @@ class RegisterBroadcastReceiver : BroadcastReceiver() { createQueue.add(connectorToken) delayRemove(createQueue, connectorToken) createApp( - context.applicationContext, + context, application, connectorToken ) { - sendEndpoint(context.applicationContext, connectorToken) + sendEndpoint(context, connectorToken) createQueue.remove(connectorToken) } } else { @@ -85,13 +86,13 @@ class RegisterBroadcastReceiver : BroadcastReceiver() { ACTION_UNREGISTER -> { Log.i(TAG, "UNREGISTER") val connectorToken = intent.getStringExtra(EXTRA_TOKEN) ?: "" - getDb(context.applicationContext).getPackageName(connectorToken) ?: return + getDb(context).getPackageName(connectorToken) ?: return if (connectorToken !in delQueue) { delQueue.add(connectorToken) delayRemove(delQueue, connectorToken) try { - deleteApp(context.applicationContext, connectorToken) { + deleteApp(context, connectorToken) { Log.d(TAG, "Unregistration is finished") delQueue.remove(connectorToken) }