Add call to TrustManager for SystemUI to propagate unlock requests to a

trust agent.

Still TODO: Add CTS test once SystemUI code is in to call this.

Test: manual testing with temporary call from SystemUI & logcat
Bug: 213631672
Change-Id: If76c033a73580e16a25ad0a6775e4e145644d926
This commit is contained in:
Dave McCloskey
2022-01-13 11:23:17 -08:00
parent 42ce00e938
commit 997c684ac2
6 changed files with 57 additions and 1 deletions

View File

@@ -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);

View File

@@ -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.
*

View File

@@ -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();

View File

@@ -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();

View File

@@ -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)
*/

View File

@@ -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;