am 4902e5ff: am ae9b5cd0: Merge "Pass initiatedByUser to TrustListeners" into lmp-dev

* commit '4902e5ff1cbefa3b2e8a07b434873344a45b21d3':
  Pass initiatedByUser to TrustListeners
This commit is contained in:
Adrian Roos
2014-08-07 14:04:25 +00:00
committed by Android Git Automerger
6 changed files with 41 additions and 23 deletions

View File

@@ -22,6 +22,6 @@ package android.app.trust;
* {@hide}
*/
oneway interface ITrustListener {
void onTrustChanged(boolean enabled, int userId);
void onTrustChanged(boolean enabled, int userId, boolean initiatedByUser);
void onTrustManagedChanged(boolean managed, int userId);
}

View File

@@ -34,6 +34,7 @@ public class TrustManager {
private static final int MSG_TRUST_MANAGED_CHANGED = 2;
private static final String TAG = "TrustManager";
private static final String DATA_INITIATED_BY_USER = "initiatedByUser";
private final ITrustManager mService;
private final ArrayMap<TrustListener, ITrustListener> mTrustListeners;
@@ -95,14 +96,17 @@ public class TrustManager {
try {
ITrustListener.Stub iTrustListener = new ITrustListener.Stub() {
@Override
public void onTrustChanged(boolean enabled, int userId) throws RemoteException {
mHandler.obtainMessage(MSG_TRUST_CHANGED, (enabled ? 1 : 0), userId,
trustListener).sendToTarget();
public void onTrustChanged(boolean enabled, int userId, boolean initiatedByUser) {
Message m = mHandler.obtainMessage(MSG_TRUST_CHANGED, (enabled ? 1 : 0), userId,
trustListener);
if (initiatedByUser) {
m.getData().putBoolean(DATA_INITIATED_BY_USER, initiatedByUser);
}
m.sendToTarget();
}
@Override
public void onTrustManagedChanged(boolean managed, int userId)
throws RemoteException {
public void onTrustManagedChanged(boolean managed, int userId) {
mHandler.obtainMessage(MSG_TRUST_MANAGED_CHANGED, (managed ? 1 : 0), userId,
trustListener).sendToTarget();
}
@@ -139,7 +143,11 @@ public class TrustManager {
public void handleMessage(Message msg) {
switch(msg.what) {
case MSG_TRUST_CHANGED:
((TrustListener)msg.obj).onTrustChanged(msg.arg1 != 0, msg.arg2);
boolean initiatedByUser = msg.peekData() != null &&
msg.peekData().getBoolean(DATA_INITIATED_BY_USER);
((TrustListener)msg.obj).onTrustChanged(
msg.arg1 != 0, msg.arg2, initiatedByUser);
break;
case MSG_TRUST_MANAGED_CHANGED:
((TrustListener)msg.obj).onTrustManagedChanged(msg.arg1 != 0, msg.arg2);
@@ -153,8 +161,10 @@ public class TrustManager {
* Reports that the trust state has changed.
* @param enabled if true, the system believes the environment to be trusted.
* @param userId the user, for which the trust changed.
* @param initiatedByUser indicates that the user has explicitly initiated an action that
* proves the user is about to use the device.
*/
void onTrustChanged(boolean enabled, int userId);
void onTrustChanged(boolean enabled, int userId, boolean initiatedByUser);
/**
* Reports that whether trust is managed has changed

View File

@@ -229,13 +229,16 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener {
private SparseBooleanArray mUserFingerprintRecognized = new SparseBooleanArray();
@Override
public void onTrustChanged(boolean enabled, int userId) {
public void onTrustChanged(boolean enabled, int userId, boolean initiatedByUser) {
mUserHasTrust.put(userId, enabled);
for (int i = 0; i < mCallbacks.size(); i++) {
KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
if (cb != null) {
cb.onTrustChanged(userId);
if (enabled && initiatedByUser) {
cb.onTrustInitiatedByUser(userId);
}
}
}
}

View File

@@ -178,6 +178,11 @@ public class KeyguardUpdateMonitorCallback {
*/
public void onTrustManagedChanged(int userId) { }
/**
* Called when the user has proved to a trust agent that they want to use the device.
*/
public void onTrustInitiatedByUser(int userId) { }
/**
* Called when a fingerprint is recognized.
* @param userId

View File

@@ -93,7 +93,6 @@ public class TrustAgentWrapper {
mTrusted = true;
mMessage = (CharSequence) msg.obj;
boolean initiatedByUser = msg.arg1 != 0;
// TODO: Handle initiatedByUser.
long durationMs = msg.getData().getLong(DATA_DURATION);
if (durationMs > 0) {
mHandler.removeMessages(MSG_TRUST_TIMEOUT);
@@ -102,7 +101,7 @@ public class TrustAgentWrapper {
mTrustManagerService.mArchive.logGrantTrust(mUserId, mName,
(mMessage != null ? mMessage.toString() : null),
durationMs, initiatedByUser);
mTrustManagerService.updateTrust(mUserId);
mTrustManagerService.updateTrust(mUserId, initiatedByUser);
break;
case MSG_TRUST_TIMEOUT:
if (DEBUG) Slog.v(TAG, "Trust timed out : " + mName.flattenToShortString());
@@ -115,7 +114,7 @@ public class TrustAgentWrapper {
if (msg.what == MSG_REVOKE_TRUST) {
mTrustManagerService.mArchive.logRevokeTrust(mUserId, mName);
}
mTrustManagerService.updateTrust(mUserId);
mTrustManagerService.updateTrust(mUserId, false);
break;
case MSG_RESTART_TIMEOUT:
unbind();
@@ -130,7 +129,7 @@ public class TrustAgentWrapper {
if (DEBUG) Log.v(TAG, "Re-enabling agent because it acknowledged "
+ "enabled features: " + mName);
mTrustDisabledByDpm = false;
mTrustManagerService.updateTrust(mUserId);
mTrustManagerService.updateTrust(mUserId, false);
}
} else {
if (DEBUG) Log.w(TAG, "Ignoring MSG_SET_TRUST_AGENT_FEATURES_COMPLETED "
@@ -144,7 +143,7 @@ public class TrustAgentWrapper {
mMessage = null;
}
mTrustManagerService.mArchive.logManagingTrust(mUserId, mName, mManagingTrust);
mTrustManagerService.updateTrust(mUserId);
mTrustManagerService.updateTrust(mUserId, false);
break;
}
}
@@ -282,7 +281,7 @@ public class TrustAgentWrapper {
}
if (mTrustDisabledByDpm != trustDisabled) {
mTrustDisabledByDpm = trustDisabled;
mTrustManagerService.updateTrust(mUserId);
mTrustManagerService.updateTrust(mUserId, false);
}
return trustDisabled;
}

View File

@@ -148,13 +148,13 @@ public class TrustManagerService extends SystemService {
private void updateTrustAll() {
List<UserInfo> userInfos = mUserManager.getUsers(true /* excludeDying */);
for (UserInfo userInfo : userInfos) {
updateTrust(userInfo.id);
updateTrust(userInfo.id, false);
}
}
public void updateTrust(int userId) {
public void updateTrust(int userId, boolean initiatedByUser) {
dispatchOnTrustManagedChanged(aggregateIsTrustManaged(userId), userId);
dispatchOnTrustChanged(aggregateIsTrusted(userId), userId);
dispatchOnTrustChanged(aggregateIsTrusted(userId), userId, initiatedByUser);
}
void refreshAgentList() {
@@ -272,7 +272,7 @@ public class TrustManagerService extends SystemService {
}
}
if (trustMayHaveChanged) {
updateTrust(userId);
updateTrust(userId, false);
}
refreshAgentList();
}
@@ -375,7 +375,7 @@ public class TrustManagerService extends SystemService {
if (successful && !mUserHasAuthenticatedSinceBoot.get(userId)) {
mUserHasAuthenticatedSinceBoot.put(userId, true);
updateTrust(userId);
updateTrust(userId, false);
}
}
@@ -386,7 +386,7 @@ public class TrustManagerService extends SystemService {
updateTrustAll();
} else {
mUserHasAuthenticatedSinceBoot.put(userId, false);
updateTrust(userId);
updateTrust(userId, false);
}
}
@@ -410,10 +410,11 @@ public class TrustManagerService extends SystemService {
}
}
private void dispatchOnTrustChanged(boolean enabled, int userId) {
private void dispatchOnTrustChanged(boolean enabled, int userId, boolean initiatedByUser) {
if (!enabled) initiatedByUser = false;
for (int i = 0; i < mTrustListeners.size(); i++) {
try {
mTrustListeners.get(i).onTrustChanged(enabled, userId);
mTrustListeners.get(i).onTrustChanged(enabled, userId, initiatedByUser);
} catch (DeadObjectException e) {
Slog.d(TAG, "Removing dead TrustListener.");
mTrustListeners.remove(i);