diff options
| -rw-r--r-- | services/core/java/com/android/server/locksettings/RebootEscrowManager.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/locksettings/RebootEscrowManager.java b/services/core/java/com/android/server/locksettings/RebootEscrowManager.java index b714c6d73613..4d525da220c7 100644 --- a/services/core/java/com/android/server/locksettings/RebootEscrowManager.java +++ b/services/core/java/com/android/server/locksettings/RebootEscrowManager.java @@ -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 { |