Properly destroy TrustAgentWrapper when not bound
Also fixes a potential issue where refreshing agents
for a user that no longer exists would result in a crash.
Bug: 18318629
Change-Id: I3589ea7e0f2e63fca02daeecf3ca964a8a8e4b3b
diff --git a/services/core/java/com/android/server/trust/TrustAgentWrapper.java b/services/core/java/com/android/server/trust/TrustAgentWrapper.java
index b2bcf75..4906bd1 100644
--- a/services/core/java/com/android/server/trust/TrustAgentWrapper.java
+++ b/services/core/java/com/android/server/trust/TrustAgentWrapper.java
@@ -39,9 +39,7 @@
import android.util.Slog;
import android.service.trust.ITrustAgentService;
import android.service.trust.ITrustAgentServiceCallback;
-import android.service.trust.TrustAgentService;
-import java.util.ArrayList;
import java.util.List;
/**
@@ -160,7 +158,7 @@
mTrustManagerService.updateTrust(mUserId, false);
break;
case MSG_RESTART_TIMEOUT:
- unbind();
+ destroy();
mTrustManagerService.resetAgent(mName, mUserId);
break;
case MSG_SET_TRUST_AGENT_FEATURES_COMPLETED:
@@ -367,7 +365,9 @@
return mMessage;
}
- public void unbind() {
+ public void destroy() {
+ mHandler.removeMessages(MSG_RESTART_TIMEOUT);
+
if (!mBound) {
return;
}
@@ -378,7 +378,6 @@
mTrustAgentService = null;
mSetTrustAgentFeaturesToken = null;
mHandler.sendEmptyMessage(MSG_REVOKE_TRUST);
- mHandler.removeMessages(MSG_RESTART_TIMEOUT);
}
public boolean isConnected() {
diff --git a/services/core/java/com/android/server/trust/TrustManagerService.java b/services/core/java/com/android/server/trust/TrustManagerService.java
index fe5cb33..2388c85 100644
--- a/services/core/java/com/android/server/trust/TrustManagerService.java
+++ b/services/core/java/com/android/server/trust/TrustManagerService.java
@@ -208,7 +208,8 @@
obsoleteAgents.addAll(mActiveAgents);
for (UserInfo userInfo : userInfos) {
- if (userInfo.partial || !userInfo.isEnabled() || userInfo.guestToRemove) continue;
+ if (userInfo == null || userInfo.partial || !userInfo.isEnabled()
+ || userInfo.guestToRemove) continue;
if (!userInfo.supportsSwitchTo()) continue;
if (!mActivityManager.isUserRunning(userInfo.id)) continue;
if (lockPatternUtils.getKeyguardStoredPasswordQuality(userInfo.id)
@@ -258,7 +259,7 @@
if (info.agent.isManagingTrust()) {
trustMayHaveChanged = true;
}
- info.agent.unbind();
+ info.agent.destroy();
mActiveAgents.remove(info);
}
}
@@ -290,7 +291,7 @@
if (info.agent.isManagingTrust()) {
trustMayHaveChanged = true;
}
- info.agent.unbind();
+ info.agent.destroy();
mActiveAgents.removeAt(i);
}
}
@@ -308,7 +309,7 @@
if (info.agent.isManagingTrust()) {
trustMayHaveChanged = true;
}
- info.agent.unbind();
+ info.agent.destroy();
mActiveAgents.removeAt(i);
}
}