From e0b1d77650c0c745ef8c035a388192c5b423beb3 Mon Sep 17 00:00:00 2001 From: cketti Date: Mon, 6 Apr 2020 04:52:28 +0200 Subject: [PATCH] Remove BootReceiver --- app/core/src/main/java/com/fsck/k9/Core.kt | 6 +- .../java/com/fsck/k9/service/BootReceiver.kt | 99 ------------------- .../com/fsck/k9/service/CoreReceiver.java | 82 --------------- app/k9mail-jmap/src/main/AndroidManifest.xml | 18 ---- app/k9mail/src/main/AndroidManifest.xml | 18 ---- 5 files changed, 1 insertion(+), 222 deletions(-) delete mode 100644 app/core/src/main/java/com/fsck/k9/service/BootReceiver.kt delete mode 100644 app/core/src/main/java/com/fsck/k9/service/CoreReceiver.java diff --git a/app/core/src/main/java/com/fsck/k9/Core.kt b/app/core/src/main/java/com/fsck/k9/Core.kt index b41c3e92f..7741f5f1a 100644 --- a/app/core/src/main/java/com/fsck/k9/Core.kt +++ b/app/core/src/main/java/com/fsck/k9/Core.kt @@ -9,7 +9,6 @@ import android.os.Handler import android.os.Looper import com.fsck.k9.job.K9JobManager import com.fsck.k9.mail.internet.BinaryTempFileBody -import com.fsck.k9.service.BootReceiver import com.fsck.k9.service.StorageGoneReceiver import java.util.concurrent.SynchronousQueue import timber.log.Timber @@ -19,8 +18,6 @@ object Core : EarlyInit { private val appConfig: AppConfig by inject() private val jobManager: K9JobManager by inject() - private val componentsToDisable = listOf(BootReceiver::class.java) - /** * This needs to be called from [Application#onCreate][android.app.Application#onCreate] before calling through * to the super class's `onCreate` implementation and before initializing the dependency injection library. @@ -62,8 +59,7 @@ object Core : EarlyInit { private fun setServicesEnabled(context: Context, enabled: Boolean) { val pm = context.packageManager - val classes = componentsToDisable + appConfig.componentsToDisable - for (clazz in classes) { + for (clazz in appConfig.componentsToDisable) { val alreadyEnabled = pm.getComponentEnabledSetting(ComponentName(context, clazz)) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED diff --git a/app/core/src/main/java/com/fsck/k9/service/BootReceiver.kt b/app/core/src/main/java/com/fsck/k9/service/BootReceiver.kt deleted file mode 100644 index e9f26a317..000000000 --- a/app/core/src/main/java/com/fsck/k9/service/BootReceiver.kt +++ /dev/null @@ -1,99 +0,0 @@ -package com.fsck.k9.service - -import android.app.AlarmManager -import android.app.PendingIntent -import android.content.Context -import android.content.Intent -import android.net.Uri -import com.fsck.k9.EarlyInit -import com.fsck.k9.K9 -import com.fsck.k9.helper.K9AlarmManager -import com.fsck.k9.inject -import com.fsck.k9.job.K9JobManager -import timber.log.Timber - -class BootReceiver : CoreReceiver(), EarlyInit { - private val jobManager: K9JobManager by inject() - - override fun receive(context: Context, intent: Intent, _tmpWakeLockId: Int?): Int? { - var tmpWakeLockId = _tmpWakeLockId - Timber.i("BootReceiver.onReceive %s", intent) - - val action = intent.action - if (Intent.ACTION_BOOT_COMPLETED == action) { - // K9.setServicesEnabled(context, tmpWakeLockId); - // tmpWakeLockId = null; - } else if ("com.android.sync.SYNC_CONN_STATUS_CHANGED" == action) { - val bOps = K9.backgroundOps - if (bOps == K9.BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC) { - jobManager.scheduleAllMailJobs() - } - } else if (FIRE_INTENT == action) { - val alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT) - val alarmedAction = alarmedIntent.action - Timber.i("BootReceiver Got alarm to fire alarmedIntent %s", alarmedAction) - alarmedIntent.putExtra(CoreReceiver.WAKE_LOCK_ID, tmpWakeLockId) - tmpWakeLockId = null - context.startService(alarmedIntent) - } else if (SCHEDULE_INTENT == action) { - val atTime = intent.getLongExtra(AT_TIME, -1) - val alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT) - Timber.i("BootReceiver Scheduling intent %s for %tc", alarmedIntent, atTime) - - val pi = buildPendingIntent(context, intent) - val alarmMgr = K9AlarmManager.getAlarmManager(context) - - alarmMgr.set(AlarmManager.RTC_WAKEUP, atTime, pi) - } - - return tmpWakeLockId - } - - private fun buildPendingIntent(context: Context, intent: Intent): PendingIntent { - val alarmedIntent = intent.getParcelableExtra(ALARMED_INTENT) - val alarmedAction = alarmedIntent.action - - val i = Intent(context, BootReceiver::class.java) - i.action = FIRE_INTENT - i.putExtra(ALARMED_INTENT, alarmedIntent) - val uri = Uri.parse("action://" + alarmedAction!!) - i.data = uri - return PendingIntent.getBroadcast(context, 0, i, 0) - } - - companion object { - - const val FIRE_INTENT = "com.fsck.k9.service.BroadcastReceiver.fireIntent" - const val SCHEDULE_INTENT = "com.fsck.k9.service.BroadcastReceiver.scheduleIntent" - const val ALARMED_INTENT = "com.fsck.k9.service.BroadcastReceiver.pendingIntent" - const val AT_TIME = "com.fsck.k9.service.BroadcastReceiver.atTime" - - @JvmStatic - fun scheduleIntent(context: Context, atTime: Long, alarmedIntent: Intent) { - Timber.i("BootReceiver Got request to schedule alarmedIntent %s", alarmedIntent.action) - - val i = Intent() - i.setClass(context, BootReceiver::class.java) - i.action = SCHEDULE_INTENT - i.putExtra(ALARMED_INTENT, alarmedIntent) - i.putExtra(AT_TIME, atTime) - context.sendBroadcast(i) - } - - /** - * Cancel any scheduled alarm. - * - * @param context - */ - @JvmStatic - fun purgeSchedule(context: Context) { - val alarmService = K9AlarmManager.getAlarmManager(context) - alarmService.cancel(PendingIntent.getBroadcast(context, 0, object : Intent() { - override fun filterEquals(other: Intent): Boolean { - // we want to match all intents - return true - } - }, 0)) - } - } -} diff --git a/app/core/src/main/java/com/fsck/k9/service/CoreReceiver.java b/app/core/src/main/java/com/fsck/k9/service/CoreReceiver.java deleted file mode 100644 index 40cbbd289..000000000 --- a/app/core/src/main/java/com/fsck/k9/service/CoreReceiver.java +++ /dev/null @@ -1,82 +0,0 @@ - -package com.fsck.k9.service; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicInteger; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.os.PowerManager; -import timber.log.Timber; - -import com.fsck.k9.K9; -import com.fsck.k9.power.TracingPowerManager; -import com.fsck.k9.power.TracingPowerManager.TracingWakeLock; - -public class CoreReceiver extends BroadcastReceiver { - - public static final String WAKE_LOCK_RELEASE = "com.fsck.k9.service.CoreReceiver.wakeLockRelease"; - - public static final String WAKE_LOCK_ID = "com.fsck.k9.service.CoreReceiver.wakeLockId"; - - private static ConcurrentHashMap wakeLocks = new ConcurrentHashMap<>(); - private static AtomicInteger wakeLockSeq = new AtomicInteger(0); - - private static Integer getWakeLock(Context context) { - TracingPowerManager pm = TracingPowerManager.getPowerManager(context); - TracingWakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "CoreReceiver getWakeLock"); - wakeLock.setReferenceCounted(false); - wakeLock.acquire(K9.BOOT_RECEIVER_WAKE_LOCK_TIMEOUT); - Integer tmpWakeLockId = wakeLockSeq.getAndIncrement(); - wakeLocks.put(tmpWakeLockId, wakeLock); - Timber.v("CoreReceiver Created wakeLock %d", tmpWakeLockId); - return tmpWakeLockId; - } - - private static void releaseWakeLock(Integer wakeLockId) { - if (wakeLockId != null) { - TracingWakeLock wl = wakeLocks.remove(wakeLockId); - if (wl != null) { - Timber.v("CoreReceiver Releasing wakeLock %d", wakeLockId); - wl.release(); - } else { - Timber.w("BootReceiver WakeLock %d doesn't exist", wakeLockId); - } - } - } - - @Override - public void onReceive(Context context, Intent intent) { - Integer tmpWakeLockId = CoreReceiver.getWakeLock(context); - try { - Timber.i("CoreReceiver.onReceive %s", intent); - - if (CoreReceiver.WAKE_LOCK_RELEASE.equals(intent.getAction())) { - Integer wakeLockId = intent.getIntExtra(WAKE_LOCK_ID, -1); - if (wakeLockId != -1) { - Timber.v("CoreReceiver Release wakeLock %d", wakeLockId); - CoreReceiver.releaseWakeLock(wakeLockId); - } - } else { - tmpWakeLockId = receive(context, intent, tmpWakeLockId); - } - } finally { - CoreReceiver.releaseWakeLock(tmpWakeLockId); - } - } - - public Integer receive(Context context, Intent intent, Integer wakeLockId) { - return wakeLockId; - } - - public static void releaseWakeLock(Context context, int wakeLockId) { - Timber.v("CoreReceiver Got request to release wakeLock %d", wakeLockId); - - Intent i = new Intent(); - i.setClass(context, CoreReceiver.class); - i.setAction(WAKE_LOCK_RELEASE); - i.putExtra(WAKE_LOCK_ID, wakeLockId); - context.sendBroadcast(i); - } -} diff --git a/app/k9mail-jmap/src/main/AndroidManifest.xml b/app/k9mail-jmap/src/main/AndroidManifest.xml index 506766a7f..e60a23a4b 100644 --- a/app/k9mail-jmap/src/main/AndroidManifest.xml +++ b/app/k9mail-jmap/src/main/AndroidManifest.xml @@ -232,24 +232,6 @@ android:name="com.fsck.k9.ui.addaccount.AddAccountActivity" android:label="@string/add_account_action" /> - - - - - - - - - - - - - - diff --git a/app/k9mail/src/main/AndroidManifest.xml b/app/k9mail/src/main/AndroidManifest.xml index e63e1feb4..d256882f8 100644 --- a/app/k9mail/src/main/AndroidManifest.xml +++ b/app/k9mail/src/main/AndroidManifest.xml @@ -285,24 +285,6 @@ android:name=".ui.settings.account.AccountSettingsActivity" android:label="@string/account_settings_title_fmt" /> - - - - - - - - - - - - - -