Merge "Add and improve logged TrustAgent connection events" into lmp-preview-dev

This commit is contained in:
Adrian Roos
2014-05-27 23:46:49 +00:00
committed by Android (Google) Code Review
2 changed files with 23 additions and 0 deletions

View File

@@ -63,6 +63,11 @@ public class TrustAgentWrapper {
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_GRANT_TRUST:
if (!isConnected()) {
Log.w(TAG, "Agent is not connected, cannot grant trust: "
+ mName.flattenToShortString());
return;
}
mTrusted = true;
mMessage = (CharSequence) msg.obj;
boolean initiatedByUser = msg.arg1 != 0;
@@ -119,6 +124,7 @@ public class TrustAgentWrapper {
public void onServiceConnected(ComponentName name, IBinder service) {
if (DEBUG) Log.v(TAG, "TrustAgent started : " + name.flattenToString());
mTrustAgentService = ITrustAgentService.Stub.asInterface(service);
mTrustManagerService.mArchive.logAgentConnected(mUserId, name);
setCallback(mCallback);
}
@@ -179,7 +185,10 @@ public class TrustAgentWrapper {
public void unbind() {
if (DEBUG) Log.v(TAG, "TrustAgent unbound : " + mName.flattenToShortString());
mTrustManagerService.mArchive.logAgentStopped(mUserId, mName);
mContext.unbindService(mConnection);
mTrustAgentService = null;
mHandler.sendEmptyMessage(MSG_REVOKE_TRUST);
}
public boolean isConnected() {

View File

@@ -33,6 +33,8 @@ public class TrustArchive {
private static final int TYPE_REVOKE_TRUST = 1;
private static final int TYPE_TRUST_TIMEOUT = 2;
private static final int TYPE_AGENT_DIED = 3;
private static final int TYPE_AGENT_CONNECTED = 4;
private static final int TYPE_AGENT_STOPPED = 5;
private static final int HISTORY_LIMIT = 200;
@@ -79,6 +81,14 @@ public class TrustArchive {
addEvent(new Event(TYPE_AGENT_DIED, userId, agent, null, 0, false));
}
public void logAgentConnected(int userId, ComponentName agent) {
addEvent(new Event(TYPE_AGENT_CONNECTED, userId, agent, null, 0, false));
}
public void logAgentStopped(int userId, ComponentName agent) {
addEvent(new Event(TYPE_AGENT_STOPPED, userId, agent, null, 0, false));
}
private void addEvent(Event e) {
if (mEvents.size() >= HISTORY_LIMIT) {
mEvents.removeFirst();
@@ -152,6 +162,10 @@ public class TrustArchive {
return "TrustTimeout";
case TYPE_AGENT_DIED:
return "AgentDied";
case TYPE_AGENT_CONNECTED:
return "AgentConnected";
case TYPE_AGENT_STOPPED:
return "AgentStopped";
default:
return "Unknown(" + type + ")";
}