Merge "Potential fix for accidental deactivation of profile owner" into lmp-mr1-dev

This commit is contained in:
Amith Yamasani
2014-12-05 18:56:52 +00:00
committed by Android (Google) Code Review

View File

@@ -303,8 +303,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
if (Intent.ACTION_USER_REMOVED.equals(action)) { if (Intent.ACTION_USER_REMOVED.equals(action)) {
removeUserData(userHandle); removeUserData(userHandle);
} else if (Intent.ACTION_USER_STARTED.equals(action) } else if (Intent.ACTION_USER_STARTED.equals(action)
|| Intent.ACTION_PACKAGE_CHANGED.equals(action)
|| Intent.ACTION_PACKAGE_REMOVED.equals(action)
|| Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) { || Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
if (Intent.ACTION_USER_STARTED.equals(action)) { if (Intent.ACTION_USER_STARTED.equals(action)) {
@@ -313,8 +311,14 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
mUserData.remove(userHandle); mUserData.remove(userHandle);
} }
} }
handlePackagesChanged(null /* check all admins */, userHandle);
handlePackagesChanged(userHandle); } else if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
|| (Intent.ACTION_PACKAGE_ADDED.equals(action)
&& intent.getBooleanExtra(Intent.EXTRA_REPLACING, false))) {
handlePackagesChanged(intent.getData().getSchemeSpecificPart(), userHandle);
} else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)
&& !intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
handlePackagesChanged(intent.getData().getSchemeSpecificPart(), userHandle);
} }
} }
}; };
@@ -899,7 +903,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
} }
} }
private void handlePackagesChanged(int userHandle) { private void handlePackagesChanged(String packageName, int userHandle) {
boolean removed = false; boolean removed = false;
if (DBG) Slog.d(LOG_TAG, "Handling package changes for user " + userHandle); if (DBG) Slog.d(LOG_TAG, "Handling package changes for user " + userHandle);
DevicePolicyData policy = getUserData(userHandle); DevicePolicyData policy = getUserData(userHandle);
@@ -908,11 +912,17 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
for (int i = policy.mAdminList.size() - 1; i >= 0; i--) { for (int i = policy.mAdminList.size() - 1; i >= 0; i--) {
ActiveAdmin aa = policy.mAdminList.get(i); ActiveAdmin aa = policy.mAdminList.get(i);
try { try {
if (pm.getPackageInfo(aa.info.getPackageName(), 0, userHandle) == null // If we're checking all packages or if the specific one we're checking matches,
|| pm.getReceiverInfo(aa.info.getComponent(), 0, userHandle) == null) { // then check if the package and receiver still exist.
removed = true; final String adminPackage = aa.info.getPackageName();
policy.mAdminList.remove(i); if (packageName == null || packageName.equals(adminPackage)) {
policy.mAdminMap.remove(aa.info.getComponent()); if (pm.getPackageInfo(adminPackage, 0, userHandle) == null
|| pm.getReceiverInfo(aa.info.getComponent(), 0, userHandle)
== null) {
removed = true;
policy.mAdminList.remove(i);
policy.mAdminMap.remove(aa.info.getComponent());
}
} }
} catch (RemoteException re) { } catch (RemoteException re) {
// Shouldn't happen // Shouldn't happen