Merge "Trim invalid users" into oc-mr1-dev

This commit is contained in:
TreeHugger Robot
2017-09-12 22:42:19 +00:00
committed by Android (Google) Code Review
2 changed files with 21 additions and 1 deletions

View File

@@ -99,6 +99,7 @@ abstract public class ManagedServices {
protected final Object mMutex;
private final UserProfiles mUserProfiles;
private final IPackageManager mPm;
private final UserManager mUm;
private final Config mConfig;
// contains connections to all connected services, including app services
@@ -138,6 +139,7 @@ abstract public class ManagedServices {
mPm = pm;
mConfig = getConfig();
mApprovalLevel = APPROVAL_BY_COMPONENT;
mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
}
abstract protected Config getConfig();
@@ -296,7 +298,9 @@ abstract public class ManagedServices {
final int userId = XmlUtils.readIntAttribute(parser, ATT_USER_ID, 0);
final boolean isPrimary =
XmlUtils.readBooleanAttribute(parser, ATT_IS_PRIMARY, true);
addApprovedList(approved, userId, isPrimary);
if (mUm.getUserInfo(userId) != null) {
addApprovedList(approved, userId, isPrimary);
}
mUseXml = true;
}
}

View File

@@ -254,6 +254,14 @@ public class ManagedServicesTest extends NotificationTestCase {
loadXml(service);
verifyExpectedApprovedEntries(service);
int[] invalidUsers = new int[] {98, 99};
for (int invalidUser : invalidUsers) {
assertFalse("service type " + service.mApprovalLevel + ":"
+ invalidUser + " is allowed for user " + invalidUser,
service.isPackageOrComponentAllowed(
String.valueOf(invalidUser), invalidUser));
}
}
}
@@ -616,6 +624,14 @@ public class ManagedServicesTest extends NotificationTestCase {
xml.append(getXmlEntry(
mExpectedSecondary.get(service.mApprovalLevel).get(userId), userId, false));
}
xml.append("<" + ManagedServices.TAG_MANAGED_SERVICES + " "
+ ManagedServices.ATT_USER_ID + "=\"99\" "
+ ManagedServices.ATT_IS_PRIMARY + "=\"true\" "
+ ManagedServices.ATT_APPROVED_LIST + "=\"99\" />\n");
xml.append("<" + ManagedServices.TAG_MANAGED_SERVICES + " "
+ ManagedServices.ATT_USER_ID + "=\"98\" "
+ ManagedServices.ATT_IS_PRIMARY + "=\"false\" "
+ ManagedServices.ATT_APPROVED_LIST + "=\"98\" />\n");
xml.append("</" + service.getConfig().xmlTag + ">");
XmlPullParser parser = Xml.newPullParser();