diff --git a/core/java/android/app/trust/ITrustManager.aidl b/core/java/android/app/trust/ITrustManager.aidl index 9985cc02965be..6d27103ac4cc2 100644 --- a/core/java/android/app/trust/ITrustManager.aidl +++ b/core/java/android/app/trust/ITrustManager.aidl @@ -26,6 +26,7 @@ import android.hardware.biometrics.BiometricSourceType; */ interface ITrustManager { void reportUnlockAttempt(boolean successful, int userId); + void reportUserRequestedUnlock(int userId); void reportUnlockLockout(int timeoutMs, int userId); void reportEnabledTrustAgentsChanged(int userId); void registerTrustListener(in ITrustListener trustListener); diff --git a/core/java/android/app/trust/TrustManager.java b/core/java/android/app/trust/TrustManager.java index 177de835554bf..4b2c1631aa924 100644 --- a/core/java/android/app/trust/TrustManager.java +++ b/core/java/android/app/trust/TrustManager.java @@ -84,6 +84,19 @@ public class TrustManager { } } + /** + * Reports that the user {@code userId} is likely interested in unlocking the device. + * + * Requires the {@link android.Manifest.permission#ACCESS_KEYGUARD_SECURE_STORAGE} permission. + */ + public void reportUserRequestedUnlock(int userId) { + try { + mService.reportUserRequestedUnlock(userId); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + /** * Reports that user {@param userId} has entered a temporary device lockout. * diff --git a/core/java/android/service/trust/ITrustAgentService.aidl b/core/java/android/service/trust/ITrustAgentService.aidl index 21661db0606a6..ec3b8575ed360 100644 --- a/core/java/android/service/trust/ITrustAgentService.aidl +++ b/core/java/android/service/trust/ITrustAgentService.aidl @@ -25,6 +25,7 @@ import android.service.trust.ITrustAgentServiceCallback; */ interface ITrustAgentService { oneway void onUnlockAttempt(boolean successful); + oneway void onUserRequestedUnlock(); oneway void onUnlockLockout(int timeoutMs); oneway void onTrustTimeout(); oneway void onDeviceLocked(); diff --git a/core/java/android/service/trust/TrustAgentService.java b/core/java/android/service/trust/TrustAgentService.java index 22ed1b8138b93..fba61cfd801ec 100644 --- a/core/java/android/service/trust/TrustAgentService.java +++ b/core/java/android/service/trust/TrustAgentService.java @@ -186,6 +186,7 @@ public class TrustAgentService extends Service { private static final int MSG_ESCROW_TOKEN_ADDED = 7; private static final int MSG_ESCROW_TOKEN_STATE_RECEIVED = 8; private static final int MSG_ESCROW_TOKEN_REMOVED = 9; + private static final int MSG_USER_REQUESTED_UNLOCK = 10; private static final String EXTRA_TOKEN = "token"; private static final String EXTRA_TOKEN_HANDLE = "token_handle"; @@ -219,6 +220,9 @@ public class TrustAgentService extends Service { case MSG_UNLOCK_ATTEMPT: onUnlockAttempt(msg.arg1 != 0); break; + case MSG_USER_REQUESTED_UNLOCK: + onUserRequestedUnlock(); + break; case MSG_UNLOCK_LOCKOUT: onDeviceUnlockLockout(msg.arg1); break; @@ -306,7 +310,7 @@ public class TrustAgentService extends Service { * * @see #FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE * - * TODO(b/213631672): Hook up call from system server & SystemUI, then un-hide + * TODO(b/213631672): Add CTS tests * @hide */ public void onUserRequestedUnlock() { @@ -664,6 +668,11 @@ public class TrustAgentService extends Service { mHandler.obtainMessage(MSG_UNLOCK_ATTEMPT, successful ? 1 : 0, 0).sendToTarget(); } + @Override + public void onUserRequestedUnlock() { + mHandler.obtainMessage(MSG_USER_REQUESTED_UNLOCK).sendToTarget(); + } + @Override public void onUnlockLockout(int timeoutMs) { mHandler.obtainMessage(MSG_UNLOCK_LOCKOUT, timeoutMs, 0).sendToTarget(); diff --git a/services/core/java/com/android/server/trust/TrustAgentWrapper.java b/services/core/java/com/android/server/trust/TrustAgentWrapper.java index 79231f7097385..593250cb9293b 100644 --- a/services/core/java/com/android/server/trust/TrustAgentWrapper.java +++ b/services/core/java/com/android/server/trust/TrustAgentWrapper.java @@ -460,6 +460,19 @@ public class TrustAgentWrapper { } } + /** + * @see android.service.trust.TrustAgentService#onUserRequestedUnlock() + */ + public void onUserRequestedUnlock() { + try { + if (mTrustAgentService != null) { + mTrustAgentService.onUserRequestedUnlock(); + } + } catch (RemoteException e) { + onError(e); + } + } + /** * @see android.service.trust.TrustAgentService#onUnlockLockout(int) */ diff --git a/services/core/java/com/android/server/trust/TrustManagerService.java b/services/core/java/com/android/server/trust/TrustManagerService.java index 4b71742c86c82..206e70fddbbe9 100644 --- a/services/core/java/com/android/server/trust/TrustManagerService.java +++ b/services/core/java/com/android/server/trust/TrustManagerService.java @@ -122,6 +122,7 @@ public class TrustManagerService extends SystemService { private static final int MSG_DISPATCH_UNLOCK_LOCKOUT = 13; private static final int MSG_REFRESH_DEVICE_LOCKED_FOR_USER = 14; private static final int MSG_SCHEDULE_TRUST_TIMEOUT = 15; + public static final int MSG_USER_REQUESTED_UNLOCK = 16; private static final int TRUST_USUALLY_MANAGED_FLUSH_DELAY = 2 * 60 * 1000; private static final String TRUST_TIMEOUT_ALARM_TAG = "TrustManagerService.trustTimeoutForUser"; @@ -963,6 +964,15 @@ public class TrustManagerService extends SystemService { } } + private void dispatchUserRequestedUnlock(int userId) { + for (int i = 0; i < mActiveAgents.size(); i++) { + AgentInfo info = mActiveAgents.valueAt(i); + if (info.userId == userId) { + info.agent.onUserRequestedUnlock(); + } + } + } + private void dispatchUnlockLockout(int timeoutMs, int userId) { for (int i = 0; i < mActiveAgents.size(); i++) { AgentInfo info = mActiveAgents.valueAt(i); @@ -1091,6 +1101,12 @@ public class TrustManagerService extends SystemService { .sendToTarget(); } + @Override + public void reportUserRequestedUnlock(int userId) throws RemoteException { + enforceReportPermission(); + mHandler.obtainMessage(MSG_USER_REQUESTED_UNLOCK, userId).sendToTarget(); + } + @Override public void reportUnlockLockout(int timeoutMs, int userId) throws RemoteException { enforceReportPermission(); @@ -1364,6 +1380,9 @@ public class TrustManagerService extends SystemService { case MSG_DISPATCH_UNLOCK_ATTEMPT: dispatchUnlockAttempt(msg.arg1 != 0, msg.arg2); break; + case MSG_USER_REQUESTED_UNLOCK: + dispatchUserRequestedUnlock(msg.arg1); + break; case MSG_DISPATCH_UNLOCK_LOCKOUT: dispatchUnlockLockout(msg.arg1, msg.arg2); break;