Add BootCompleteReceiver to start PushController on device boot
This commit is contained in:
parent
5520fdac96
commit
7a940240c3
2 changed files with 55 additions and 0 deletions
|
@ -0,0 +1,46 @@
|
|||
package com.fsck.k9.controller.push
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED
|
||||
import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED
|
||||
import android.content.pm.PackageManager.DONT_KILL_APP
|
||||
import java.lang.Exception
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import timber.log.Timber
|
||||
|
||||
class BootCompleteReceiver : BroadcastReceiver(), KoinComponent {
|
||||
private val pushController: PushController by inject()
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent?) {
|
||||
Timber.v("BootCompleteReceiver.onReceive()")
|
||||
|
||||
pushController.init()
|
||||
}
|
||||
}
|
||||
|
||||
class BootCompleteManager(context: Context) {
|
||||
private val packageManager = context.packageManager
|
||||
private val componentName = ComponentName(context, BootCompleteReceiver::class.java)
|
||||
|
||||
fun enableReceiver() {
|
||||
Timber.v("Enable BootCompleteReceiver")
|
||||
try {
|
||||
packageManager.setComponentEnabledSetting(componentName, COMPONENT_ENABLED_STATE_ENABLED, DONT_KILL_APP)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Error enabling BootCompleteReceiver")
|
||||
}
|
||||
}
|
||||
|
||||
fun disableReceiver() {
|
||||
Timber.v("Disable BootCompleteReceiver")
|
||||
try {
|
||||
packageManager.setComponentEnabledSetting(componentName, COMPONENT_ENABLED_STATE_DISABLED, DONT_KILL_APP)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Error disabling BootCompleteReceiver")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -338,6 +338,15 @@
|
|||
android:resource="@xml/message_list_widget_info" />
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".controller.push.BootCompleteReceiver"
|
||||
android:exported="false"
|
||||
android:enabled="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name=".widget.list.MessageListWidgetService"
|
||||
android:enabled="true"
|
||||
|
|
Loading…
Reference in a new issue