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

Commit 9dbd3ea3 authored by Tianjie Xu's avatar Tianjie Xu Committed by Gerrit Code Review
Browse files

Merge "Acquire the wake lock to ensure RoR isn't delayed"

parents 65cef543 caefed18
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.os.Handler;
import android.os.PowerManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserManager;
@@ -119,6 +120,8 @@ class RebootEscrowManager {
     */
    private static final int DEFAULT_LOAD_ESCROW_DATA_RETRY_COUNT = 3;
    private static final int DEFAULT_LOAD_ESCROW_DATA_RETRY_INTERVAL_SECONDS = 30;
    // 3 minutes. It's enough for the default 3 retries with 30 seconds interval
    private static final int DEFAULT_WAKE_LOCK_TIMEOUT_MILLIS = 180_000;

    @IntDef(prefix = {"ERROR_"}, value = {
            ERROR_NONE,
@@ -187,6 +190,9 @@ class RebootEscrowManager {

    private final RebootEscrowKeyStoreManager mKeyStoreManager;

    PowerManager.WakeLock mWakeLock;


    interface Callbacks {
        boolean isUserSecure(int userId);

@@ -279,6 +285,11 @@ class RebootEscrowManager {
            return mRebootEscrowProvider;
        }

        PowerManager.WakeLock getWakeLock() {
            final PowerManager pm = mContext.getSystemService(PowerManager.class);
            return pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RebootEscrowManager");
        }

        public RebootEscrowProviderInterface getRebootEscrowProvider() {
            return mRebootEscrowProvider;
        }
@@ -365,6 +376,13 @@ class RebootEscrowManager {
            return;
        }

        // Acquire the wake lock to make sure our scheduled task will run.
        mWakeLock = mInjector.getWakeLock();
        if (mWakeLock != null) {
            mWakeLock.setReferenceCounted(false);
            mWakeLock.acquire(DEFAULT_WAKE_LOCK_TIMEOUT_MILLIS);
        }

        mInjector.post(retryHandler, () -> loadRebootEscrowDataWithRetry(
                retryHandler, 0, users, rebootEscrowUsers));
    }
@@ -519,6 +537,10 @@ class RebootEscrowManager {
        // Clear the saved reboot escrow provider
        mInjector.clearRebootEscrowProvider();
        clearMetricsStorage();

        if (mWakeLock != null) {
            mWakeLock.release();
        }
    }

    private RebootEscrowKey getAndClearRebootEscrowKey(SecretKey kk) throws IOException {