Loading services/core/java/com/android/server/notification/ManagedServices.java +6 −4 Original line number Diff line number Diff line Loading @@ -570,10 +570,12 @@ abstract public class ManagedServices { protected final void migrateToXml() { for (UserInfo user : mUm.getUsers()) { final ContentResolver cr = mContext.getContentResolver(); if (!TextUtils.isEmpty(getConfig().secureSettingName)) { addApprovedList(Settings.Secure.getStringForUser( cr, getConfig().secureSettingName, user.id), user.id, true); } if (!TextUtils.isEmpty(getConfig().secondarySettingName)) { addApprovedList(Settings.Secure.getStringForUser( cr, Loading services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java +51 −0 Original line number Diff line number Diff line Loading @@ -278,6 +278,36 @@ public class ManagedServicesTest extends UiServiceTestCase { } } @Test public void testReadXml_noLongerMigrateFromSettings() throws Exception { for (int approvalLevel : new int[] {APPROVAL_BY_COMPONENT, APPROVAL_BY_PACKAGE}) { ManagedServices service = new TestManagedServicesNoSettings(getContext(), mLock, mUserProfiles, mIpm, approvalLevel); // approved services aren't in xml TypedXmlPullParser parser = Xml.newFastPullParser(); parser.setInput(new BufferedInputStream(new ByteArrayInputStream(new byte[]{})), null); writeExpectedValuesToSettings(approvalLevel); service.migrateToXml(); // No crash? success ArrayMap<Integer, String> verifyMap = approvalLevel == APPROVAL_BY_COMPONENT ? mExpectedPrimary.get(service.mApprovalLevel) : mExpectedSecondary.get(service.mApprovalLevel); for (int userId : verifyMap.keySet()) { for (String verifyValue : verifyMap.get(userId).split(":")) { if (!TextUtils.isEmpty(verifyValue)) { assertFalse("service type " + service.mApprovalLevel + ":" + verifyValue + " is allowed for user " + userId, service.isPackageOrComponentAllowed(verifyValue, userId)); } } } } } @Test public void testReadXml() throws Exception { for (int approvalLevel : new int[] {APPROVAL_BY_COMPONENT, APPROVAL_BY_PACKAGE}) { Loading Loading @@ -1766,4 +1796,25 @@ public class ManagedServicesTest extends UiServiceTestCase { return true; } } class TestManagedServicesNoSettings extends TestManagedServices { public TestManagedServicesNoSettings(Context context, Object mutex, UserProfiles userProfiles, IPackageManager pm, int approvedServiceType) { super(context, mutex, userProfiles, pm, approvedServiceType); } @Override protected Config getConfig() { Config c = super.getConfig(); c.secureSettingName = null; c.secondarySettingName = null; return c; } @Override public boolean shouldReflectToSettings() { return false; } } } Loading
services/core/java/com/android/server/notification/ManagedServices.java +6 −4 Original line number Diff line number Diff line Loading @@ -570,10 +570,12 @@ abstract public class ManagedServices { protected final void migrateToXml() { for (UserInfo user : mUm.getUsers()) { final ContentResolver cr = mContext.getContentResolver(); if (!TextUtils.isEmpty(getConfig().secureSettingName)) { addApprovedList(Settings.Secure.getStringForUser( cr, getConfig().secureSettingName, user.id), user.id, true); } if (!TextUtils.isEmpty(getConfig().secondarySettingName)) { addApprovedList(Settings.Secure.getStringForUser( cr, Loading
services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java +51 −0 Original line number Diff line number Diff line Loading @@ -278,6 +278,36 @@ public class ManagedServicesTest extends UiServiceTestCase { } } @Test public void testReadXml_noLongerMigrateFromSettings() throws Exception { for (int approvalLevel : new int[] {APPROVAL_BY_COMPONENT, APPROVAL_BY_PACKAGE}) { ManagedServices service = new TestManagedServicesNoSettings(getContext(), mLock, mUserProfiles, mIpm, approvalLevel); // approved services aren't in xml TypedXmlPullParser parser = Xml.newFastPullParser(); parser.setInput(new BufferedInputStream(new ByteArrayInputStream(new byte[]{})), null); writeExpectedValuesToSettings(approvalLevel); service.migrateToXml(); // No crash? success ArrayMap<Integer, String> verifyMap = approvalLevel == APPROVAL_BY_COMPONENT ? mExpectedPrimary.get(service.mApprovalLevel) : mExpectedSecondary.get(service.mApprovalLevel); for (int userId : verifyMap.keySet()) { for (String verifyValue : verifyMap.get(userId).split(":")) { if (!TextUtils.isEmpty(verifyValue)) { assertFalse("service type " + service.mApprovalLevel + ":" + verifyValue + " is allowed for user " + userId, service.isPackageOrComponentAllowed(verifyValue, userId)); } } } } } @Test public void testReadXml() throws Exception { for (int approvalLevel : new int[] {APPROVAL_BY_COMPONENT, APPROVAL_BY_PACKAGE}) { Loading Loading @@ -1766,4 +1796,25 @@ public class ManagedServicesTest extends UiServiceTestCase { return true; } } class TestManagedServicesNoSettings extends TestManagedServices { public TestManagedServicesNoSettings(Context context, Object mutex, UserProfiles userProfiles, IPackageManager pm, int approvedServiceType) { super(context, mutex, userProfiles, pm, approvedServiceType); } @Override protected Config getConfig() { Config c = super.getConfig(); c.secureSettingName = null; c.secondarySettingName = null; return c; } @Override public boolean shouldReflectToSettings() { return false; } } }