From 11dbfcd6e916ba494ebbf9662232c511b1e18cc6 Mon Sep 17 00:00:00 2001 From: sim Date: Sat, 2 Nov 2024 12:39:21 +0000 Subject: [PATCH] Lint --- .../distributor/nextpush/AppCompanion.kt | 3 +++ .../distributor/nextpush/WakeLock.kt | 6 ++--- .../nextpush/activities/LinkActivity.kt | 4 ++-- .../distributor/ConnectorTokenValidity.kt | 6 +++-- .../nextpush/distributor/FailedReason.kt | 22 ++++++++++--------- .../distributor/RaiseAppToForeground.kt | 8 +++---- .../RaiseAppToForegroundFactory.kt | 2 +- .../receivers/RegisterBroadcastReceiver.kt | 15 ++++++++----- .../nextpush/services/StartService.kt | 1 - 9 files changed, 38 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/AppCompanion.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/AppCompanion.kt index 8401bec..397cb79 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/AppCompanion.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/AppCompanion.kt @@ -10,14 +10,17 @@ object AppCompanion { * to avoid testing buffered responses on boot. */ val booting = AtomicBoolean(false) + /** * Check if we have internet access. * The initial value is true, because the first time we check it is before * [RestartNetworkCallback] is registered. */ val hasInternet = AtomicBoolean(true) + /** Have we received the start event ? To check the reverse proxy timeout is high enough */ val started = AtomicBoolean(false) + /** Have we received the ping event ? To check the reverse proxy timeout is high enough */ val pinged = AtomicBoolean(false) val bufferedResponseChecked = AtomicBoolean(false) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/WakeLock.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/WakeLock.kt index c8db0c6..c1004f5 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/WakeLock.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/WakeLock.kt @@ -10,7 +10,7 @@ import android.util.Log class WakeLock(context: Context) { private var wakeLock: PowerManager.WakeLock = (context.getSystemService(Context.POWER_SERVICE) as PowerManager) - .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG) + .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG) /** * Acquire the [WakeLock][PowerManager.WakeLock] with 10 seconds timeout. @@ -46,7 +46,7 @@ class WakeLock(context: Context) { fun new(context: Context): WakeLock { Log.d(TAG, "Generating a new instance") instance?.release() - return WakeLock(context).also { + return WakeLock(context).also { instance = it } } @@ -65,4 +65,4 @@ class WakeLock(context: Context) { instance = null } } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/activities/LinkActivity.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/activities/LinkActivity.kt index e14ddf6..02ee31a 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/activities/LinkActivity.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/activities/LinkActivity.kt @@ -7,7 +7,7 @@ import android.os.Bundle import android.util.Log import org.unifiedpush.distributor.nextpush.distributor.EXTRA_PI -class LinkActivity: Activity() { +class LinkActivity : Activity() { private val TAG = LinkActivity::class.simpleName override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -22,4 +22,4 @@ class LinkActivity: Activity() { } ?: setResult(RESULT_CANCELED) finish() } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/ConnectorTokenValidity.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/ConnectorTokenValidity.kt index 4430c79..5d25022 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/ConnectorTokenValidity.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/ConnectorTokenValidity.kt @@ -6,8 +6,10 @@ package org.unifiedpush.distributor.nextpush.distributor enum class ConnectorTokenValidity { /** This is a new token. */ TOKEN_NEW, + /** This is a known token, which match the provided application. */ TOKEN_REGISTERED_OK, + /** This is a known token, but it doesn't match the application. */ - TOKEN_NOK, -} \ No newline at end of file + TOKEN_NOK +} diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/FailedReason.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/FailedReason.kt index aff5c38..1cc543a 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/FailedReason.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/FailedReason.kt @@ -4,18 +4,20 @@ package org.unifiedpush.distributor.nextpush.distributor * A registration request may fail for different reasons. */ enum class FailedReason { -/** - * This is a generic error type, you can try to register again directly. - */ + /** + * This is a generic error type, you can try to register again directly. + */ INTERNAL_ERROR, -/** - * The registration failed because of missing network connection, try again when network is back. - */ + + /** + * The registration failed because of missing network connection, try again when network is back. + */ NETWORK, -/** - * The distributor requires a user action to work. For instance, the distributor may be log out of the push server and requires the user to log in. The user must interact with the distributor or sending a new registration will fail again. - */ - ACTION_REQUIRED, + + /** + * The distributor requires a user action to work. For instance, the distributor may be log out of the push server and requires the user to log in. The user must interact with the distributor or sending a new registration will fail again. + */ + ACTION_REQUIRED /* * The distributor requires a VAPID key and the app didn't provide one during registration. VAPID_REQUIRED, diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/RaiseAppToForeground.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/RaiseAppToForeground.kt index 860f8c5..bed1c7c 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/RaiseAppToForeground.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/RaiseAppToForeground.kt @@ -13,7 +13,7 @@ import java.util.concurrent.Executors import java.util.concurrent.ScheduledFuture import java.util.concurrent.TimeUnit -class RaiseAppToForeground(private val context: Context, private val app: String, private val onUnbound: () -> Unit): ServiceConnection, Runnable { +class RaiseAppToForeground(private val context: Context, private val app: String, private val onUnbound: () -> Unit) : ServiceConnection, Runnable { /** * Is the service bound ? This is a per service connection @@ -23,7 +23,7 @@ class RaiseAppToForeground(private val context: Context, private val app: String private val foregroundImportance = listOf( RunningAppProcessInfo.IMPORTANCE_FOREGROUND, - RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE, + RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE ) /** @@ -64,7 +64,6 @@ class RaiseAppToForeground(private val context: Context, private val app: String `package` = app action = ACTION } - //val sConnection = RaiseAppToForeground(context, app) /** Bind to the target raise to the foreground service */ context.bindService(intent, this, Context.BIND_AUTO_CREATE) /** Call [run] (unbind) in 5 seconds */ @@ -121,7 +120,8 @@ class RaiseAppToForeground(private val context: Context, private val app: String private const val TAG = "RaiseAppToForeground" private const val TARGET_CLASS = "org.unifiedpush.android.connector.RaiseToForegroundService" private const val ACTION = "org.unifiedpush.android.distributor.RAISE_TO_FOREGROUND" + /** Executor to unbind 5 seconds later */ private val unbindExecutor = Executors.newSingleThreadScheduledExecutor() } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/RaiseAppToForegroundFactory.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/RaiseAppToForegroundFactory.kt index d619b28..35af08d 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/RaiseAppToForegroundFactory.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/distributor/RaiseAppToForegroundFactory.kt @@ -36,4 +36,4 @@ object RaiseAppToForegroundFactory { } private val instances: MutableMap = mutableMapOf() private const val TAG = "RaiseAppToForegroundFactory" -} \ No newline at end of file +} 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 5e98dfa..e3123c2 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 @@ -45,8 +45,11 @@ class RegisterBroadcastReceiver : BroadcastReceiver() { * Get application package name following AND_3 specifications. */ private fun getApplicationAnd3(context: Context, intent: Intent): String? { - return if (Build.VERSION.SDK_INT >= 34) getApplicationAnd3SharedId(context, intent) - else getApplicationAnd3PendingIntent(intent) + return if (Build.VERSION.SDK_INT >= 34) { + getApplicationAnd3SharedId(context, intent) + } else { + getApplicationAnd3PendingIntent(intent) + } } /** @@ -128,7 +131,7 @@ class RegisterBroadcastReceiver : BroadcastReceiver() { when (checkToken(context, connectorToken, application)) { ConnectorTokenValidity.TOKEN_REGISTERED_OK -> onRegisterKnownToken(context, connectorToken) ConnectorTokenValidity.TOKEN_NOK -> onRegisterNokToken(context, connectorToken, application) - ConnectorTokenValidity.TOKEN_NEW ->onRegisterNewToken(context, connectorToken, application) + ConnectorTokenValidity.TOKEN_NEW -> onRegisterNewToken(context, connectorToken, application) } AppCompanion.createQueue.removeToken(connectorToken) } else { @@ -179,9 +182,9 @@ class RegisterBroadcastReceiver : BroadcastReceiver() { ) else -> createApp( - context, - application, - connectorToken + context, + application, + connectorToken ) { success -> when (success) { true -> { diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/StartService.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/StartService.kt index 7877b10..412e4f7 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/StartService.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/StartService.kt @@ -5,7 +5,6 @@ import android.content.Context import android.content.Intent import android.os.Build import android.os.IBinder -import android.os.PowerManager import android.util.Log import org.unifiedpush.distributor.nextpush.AppCompanion import org.unifiedpush.distributor.nextpush.WakeLock