Loading core/tests/coretests/src/android/provider/SettingsProviderTest.java +36 −0 Original line number Diff line number Diff line Loading @@ -131,6 +131,42 @@ public class SettingsProviderTest extends AndroidTestCase { assertEquals(null, Settings.Secure.getString(r, "test_key")); } @MediumTest public void testSettingsChangeForOtherUser() { UserManager um = (UserManager) getContext().getSystemService(Context.USER_SERVICE); ContentResolver r = getContext().getContentResolver(); // Make sure there's an owner assertTrue(findUser(um, UserHandle.USER_OWNER)); // create a new user to use for testing UserInfo otherUser = um.createUser("TestUser1", UserInfo.FLAG_GUEST); assertTrue(otherUser != null); try { assertNotSame("Current calling user id should not be the new guest user", otherUser.id, UserHandle.getCallingUserId()); Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "gps"); Settings.Secure.putStringForUser(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "network", otherUser.id); assertEquals("gps", Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)); assertEquals("network", Settings.Secure.getStringForUser( r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, otherUser.id)); assertNotSame("Current calling user id should not be the new guest user", otherUser.id, UserHandle.getCallingUserId()); Settings.Secure.setLocationProviderEnabledForUser(r, "network", false, otherUser.id); assertEquals("", Settings.Secure.getStringForUser( r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, otherUser.id)); } finally { // Tidy up um.removeUser(otherUser.id); } } @MediumTest public void testRowNumberContentUri() { ContentResolver r = getContext().getContentResolver(); Loading packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +3 −3 Original line number Diff line number Diff line Loading @@ -775,7 +775,7 @@ public class SettingsProvider extends ContentProvider { * @returns whether the database needs to be updated or not, also modifying * 'initialValues' if needed. */ private boolean parseProviderList(Uri url, ContentValues initialValues) { private boolean parseProviderList(Uri url, ContentValues initialValues, int desiredUser) { String value = initialValues.getAsString(Settings.Secure.VALUE); String newProviders = null; if (value != null && value.length() > 1) { Loading @@ -788,7 +788,7 @@ public class SettingsProvider extends ContentProvider { String providers = ""; String[] columns = {Settings.Secure.VALUE}; String where = Settings.Secure.NAME + "=\'" + Settings.Secure.LOCATION_PROVIDERS_ALLOWED + "\'"; Cursor cursor = query(url, columns, where, null, null); Cursor cursor = queryForUser(url, columns, where, null, null, desiredUser); if (cursor != null && cursor.getCount() == 1) { try { cursor.moveToFirst(); Loading Loading @@ -865,7 +865,7 @@ public class SettingsProvider extends ContentProvider { // Support enabling/disabling a single provider (using "+" or "-" prefix) String name = initialValues.getAsString(Settings.Secure.NAME); if (Settings.Secure.LOCATION_PROVIDERS_ALLOWED.equals(name)) { if (!parseProviderList(url, initialValues)) return null; if (!parseProviderList(url, initialValues, desiredUserHandle)) return null; } // If this is an insert() of a key that has been migrated to the global store, Loading Loading
core/tests/coretests/src/android/provider/SettingsProviderTest.java +36 −0 Original line number Diff line number Diff line Loading @@ -131,6 +131,42 @@ public class SettingsProviderTest extends AndroidTestCase { assertEquals(null, Settings.Secure.getString(r, "test_key")); } @MediumTest public void testSettingsChangeForOtherUser() { UserManager um = (UserManager) getContext().getSystemService(Context.USER_SERVICE); ContentResolver r = getContext().getContentResolver(); // Make sure there's an owner assertTrue(findUser(um, UserHandle.USER_OWNER)); // create a new user to use for testing UserInfo otherUser = um.createUser("TestUser1", UserInfo.FLAG_GUEST); assertTrue(otherUser != null); try { assertNotSame("Current calling user id should not be the new guest user", otherUser.id, UserHandle.getCallingUserId()); Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "gps"); Settings.Secure.putStringForUser(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "network", otherUser.id); assertEquals("gps", Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)); assertEquals("network", Settings.Secure.getStringForUser( r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, otherUser.id)); assertNotSame("Current calling user id should not be the new guest user", otherUser.id, UserHandle.getCallingUserId()); Settings.Secure.setLocationProviderEnabledForUser(r, "network", false, otherUser.id); assertEquals("", Settings.Secure.getStringForUser( r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, otherUser.id)); } finally { // Tidy up um.removeUser(otherUser.id); } } @MediumTest public void testRowNumberContentUri() { ContentResolver r = getContext().getContentResolver(); Loading
packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +3 −3 Original line number Diff line number Diff line Loading @@ -775,7 +775,7 @@ public class SettingsProvider extends ContentProvider { * @returns whether the database needs to be updated or not, also modifying * 'initialValues' if needed. */ private boolean parseProviderList(Uri url, ContentValues initialValues) { private boolean parseProviderList(Uri url, ContentValues initialValues, int desiredUser) { String value = initialValues.getAsString(Settings.Secure.VALUE); String newProviders = null; if (value != null && value.length() > 1) { Loading @@ -788,7 +788,7 @@ public class SettingsProvider extends ContentProvider { String providers = ""; String[] columns = {Settings.Secure.VALUE}; String where = Settings.Secure.NAME + "=\'" + Settings.Secure.LOCATION_PROVIDERS_ALLOWED + "\'"; Cursor cursor = query(url, columns, where, null, null); Cursor cursor = queryForUser(url, columns, where, null, null, desiredUser); if (cursor != null && cursor.getCount() == 1) { try { cursor.moveToFirst(); Loading Loading @@ -865,7 +865,7 @@ public class SettingsProvider extends ContentProvider { // Support enabling/disabling a single provider (using "+" or "-" prefix) String name = initialValues.getAsString(Settings.Secure.NAME); if (Settings.Secure.LOCATION_PROVIDERS_ALLOWED.equals(name)) { if (!parseProviderList(url, initialValues)) return null; if (!parseProviderList(url, initialValues, desiredUserHandle)) return null; } // If this is an insert() of a key that has been migrated to the global store, Loading