KeyguardStateMonitor looses connection with keystore if keystore dies

When keystore dies it no longer gets information about the lock screen
visibility state. This state is vital to enforcing the "unlocked
device required" authorization of keymaster keys.

With this patch KeyguardStateMonitor tries to reestablish the connection
to keystore if communication fails.

Test: run atest android.keystore.cts.CipherTest#testKeyguardLockAndUnlock
      after killing keystore
Bug: 117552147

Change-Id: I8346e53c342bdba0f5960b1feba7c26db5cef33e
This commit is contained in:
Janis Danisevskis
2018-10-10 09:32:39 -07:00
parent c41a5d6bc0
commit 01c3c2fbac

View File

@@ -95,10 +95,22 @@ public class KeyguardStateMonitor extends IKeyguardStateCallback.Stub {
mIsShowing = showing;
mCallback.onShowingChanged();
try {
mKeystoreService.onKeyguardVisibilityChanged(showing, mCurrentUserId);
} catch (RemoteException e) {
Slog.e(TAG, "Error informing keystore of screen lock", e);
int retry = 2;
while (retry > 0) {
try {
mKeystoreService.onKeyguardVisibilityChanged(showing, mCurrentUserId);
break;
} catch (RemoteException e) {
if (retry == 2) {
Slog.w(TAG, "Error informing keystore of screen lock. Keystore may have died"
+ " -> refreshing service token and retrying");
mKeystoreService = IKeystoreService.Stub.asInterface(ServiceManager
.getService("android.security.keystore"));
} else {
Slog.e(TAG, "Error informing keystore of screen lock after retrying once", e);
}
--retry;
}
}
}