diff options
| author | 2021-06-30 16:53:59 -0700 | |
|---|---|---|
| committer | 2021-07-01 10:53:52 -0700 | |
| commit | caefed18a228a8b1c5b7d606406d50b068c06f6a (patch) | |
| tree | 023fd87f2bdee6807c5e8de5e155d1604deb0dcf | |
| parent | 7405010f23758b09ac60e1e4b763efd4db3e253a (diff) | |
Acquire the wake lock to ensure RoR isn't delayed
The server based RoR is time critical, and the secret has a life time
of 10 minutes by default. In one bug, we find the task scheduled by
RebootEscrowManager doesn't run until 13 minutes later. As a
precaution, hold the wake lock in RebootEscrowManager to make sure the
resume on reboot completes.
Bug: 191784420
Test: trigger a RoR
Change-Id: Ife17e279d28b73d22213188a795d0edab99d0818
| -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 { |