Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6286ed0 authored by Peter Cai's avatar Peter Cai
Browse files

feat: Acquire partial wake lock for all foreground tasks

All of our foreground tasks require the CPU to be at least awake to make
any progress. We could keep the screen on but we really only need the
partial wake lock to make sure progress is made.
parent 360760b7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <application
        android:enableOnBackInvokedCallback="true"
+10 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.os.Binder
import android.os.IBinder
import android.os.PowerManager
import android.util.Log
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationCompat
@@ -91,6 +92,12 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
    }
    val euiccChannelManager: EuiccChannelManager by euiccChannelManagerDelegate

    val wakeLock: PowerManager.WakeLock by lazy {
        (getSystemService(POWER_SERVICE) as PowerManager).run {
            newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this::class.simpleName)
        }
    }

    /**
     * The state of a "foreground" task (named so due to the need to startForeground())
     */
@@ -275,6 +282,8 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {

            updateForegroundNotification(title, iconRes)

            wakeLock.acquire(10 * 60 * 1000L /*10 minutes*/)

            try {
                withContext(Dispatchers.IO + NonCancellable) { // Any LPA-related task must always complete
                    this@EuiccChannelManagerService.task()
@@ -290,6 +299,7 @@ class EuiccChannelManagerService : LifecycleService(), OpenEuiccContextMarker {
                    postForegroundTaskFailureNotification(failureTitle)
                }
            } finally {
                wakeLock.release()
                if (isActive) {
                    stopSelf()
                }