Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43765b77 authored by Xiaohui Chen's avatar Xiaohui Chen
Browse files

Cleanup USER_OWNER in SettingsProvider[Test]

Fixed up the tests and re-enabled it.
Still suppressed one test because what it relies on Settings.Bookmarks
is broken because Settings query format changed.
Fixed a bug in SettingsProvider that the package query is using the
wrong user id.

Bug: 19913735
Change-Id: Ied86a261defba2706f726a13bc32f385f7d93787
parent 683675ea
Loading
Loading
Loading
Loading
+140 −111
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
@@ -37,7 +36,6 @@ import android.test.suitebuilder.annotation.Suppress;
import java.util.List;

/** Unit test for SettingsProvider. */
@Suppress  // Failing.
public class SettingsProviderTest extends AndroidTestCase {
    @MediumTest
    public void testNameValueCache() {
@@ -53,41 +51,69 @@ public class SettingsProviderTest extends AndroidTestCase {
        assertEquals(1, r.delete(Settings.Secure.getUriFor("test_service"), null, null));
        assertEquals(null, Settings.Secure.getString(r, "test_service"));

        // Try all the same things in the System table
        // Apps should not be able to use System settings.
        try {
            Settings.System.putString(r, "test_setting", "Value");
        assertEquals("Value", Settings.System.getString(r, "test_setting"));
            fail("IllegalArgumentException expected");
        } catch (java.lang.IllegalArgumentException e) {
            // expected
        }
    }

        Settings.System.putString(r, "test_setting", "New");
        assertEquals("New", Settings.System.getString(r, "test_setting"));
    @MediumTest
    public void testRowNameContentUriForSecure() {
        final String testKey = "testRowNameContentUriForSecure";
        final String testValue = "testValue";
        final String secondTestValue = "testValueNew";

        assertEquals(1, r.delete(Settings.System.getUriFor("test_setting"), null, null));
        assertEquals(null, Settings.System.getString(r, "test_setting"));
        try {
            testRowNameContentUri(Settings.Secure.CONTENT_URI, Settings.Secure.NAME,
                    Settings.Secure.VALUE, testKey, testValue, secondTestValue);
        } finally {
            // clean up
            Settings.Secure.putString(getContext().getContentResolver(), testKey, null);
        }
    }

    @MediumTest
    public void testRowNameContentUri() {
        ContentResolver r = getContext().getContentResolver();
    public void testRowNameContentUriForSystem() {
        final String testKey = Settings.System.VIBRATE_ON;
        assertTrue("Settings.System.PUBLIC_SETTINGS cannot be empty.  We need to use one of it"
                + " for testing.  Only settings key in this collection will be accepted by the"
                + " framework.", Settings.System.PUBLIC_SETTINGS.contains(testKey));
        final String testValue = "0";
        final String secondTestValue = "1";
        final String oldValue =
                Settings.System.getString(getContext().getContentResolver(), testKey);

        try {
            testRowNameContentUri(Settings.System.CONTENT_URI, Settings.System.NAME,
                    Settings.System.VALUE, testKey, testValue, secondTestValue);
        } finally {
            // restore old value
            if (oldValue != null) {
                Settings.System.putString(getContext().getContentResolver(), testKey, oldValue);
            }
        }
    }

        assertEquals("content://settings/system/test_setting",
                Settings.System.getUriFor("test_setting").toString());
        assertEquals("content://settings/secure/test_service",
                Settings.Secure.getUriFor("test_service").toString());
    private void testRowNameContentUri(Uri table, String nameField, String valueField,
            String testKey, String testValue, String secondTestValue) {
        ContentResolver r = getContext().getContentResolver();

        // These tables use the row name (not ID) as their content URI.
        Uri tables[] = { Settings.System.CONTENT_URI, Settings.Secure.CONTENT_URI };
        for (Uri table : tables) {
        ContentValues v = new ContentValues();
            v.put(Settings.System.NAME, "test_key");
            v.put(Settings.System.VALUE, "Test");
            Uri uri = r.insert(table, v);
            assertEquals(table.toString() + "/test_key", uri.toString());
        v.put(nameField, testKey);
        v.put(valueField, testValue);

        r.insert(table, v);
        Uri uri = Uri.parse(table.toString() + "/" + testKey);

        // Query with a specific URI and no WHERE clause succeeds.
        Cursor c = r.query(uri, null, null, null, null);
        try {
            assertTrue(c.moveToNext());
                assertEquals("test_key", c.getString(c.getColumnIndex(Settings.System.NAME)));
                assertEquals("Test", c.getString(c.getColumnIndex(Settings.System.VALUE)));
            assertEquals(testKey, c.getString(c.getColumnIndex(nameField)));
            assertEquals(testValue, c.getString(c.getColumnIndex(valueField)));
            assertFalse(c.moveToNext());
        } finally {
            c.close();
@@ -96,41 +122,37 @@ public class SettingsProviderTest extends AndroidTestCase {
        // Query with a specific URI and a WHERE clause fails.
        try {
            r.query(uri, null, "1", null, null);
                fail("UnsupportedOperationException expected");
            } catch (UnsupportedOperationException e) {
                if (!e.toString().contains("WHERE clause")) throw e;
            fail("IllegalArgumentException expected");
        } catch (IllegalArgumentException e) {
            // expected
        }

        // Query with a tablewide URI and a WHERE clause succeeds.
            c = r.query(table, null, "name='test_key'", null, null);
        c = r.query(table, null, "name='" + testKey + "'", null, null);
        try {
            assertTrue(c.moveToNext());
                assertEquals("test_key", c.getString(c.getColumnIndex(Settings.System.NAME)));
                assertEquals("Test", c.getString(c.getColumnIndex(Settings.System.VALUE)));
            assertEquals(testKey, c.getString(c.getColumnIndex(nameField)));
            assertEquals(testValue, c.getString(c.getColumnIndex(valueField)));
            assertFalse(c.moveToNext());
        } finally {
            c.close();
        }

        v = new ContentValues();
            v.put(Settings.System.VALUE, "Toast");
        // NAME is still needed, although the uri should be specific enough. Why?
        v.put(nameField, testKey);
        v.put(valueField, secondTestValue);
        assertEquals(1, r.update(uri, v, null, null));

        c = r.query(uri, null, null, null, null);
        try {
            assertTrue(c.moveToNext());
                assertEquals("test_key", c.getString(c.getColumnIndex(Settings.System.NAME)));
                assertEquals("Toast", c.getString(c.getColumnIndex(Settings.System.VALUE)));
            assertEquals(testKey, c.getString(c.getColumnIndex(nameField)));
            assertEquals(secondTestValue, c.getString(c.getColumnIndex(valueField)));
            assertFalse(c.moveToNext());
        } finally {
            c.close();
        }

            assertEquals(1, r.delete(uri, null, null));
        }

        assertEquals(null, Settings.System.getString(r, "test_key"));
        assertEquals(null, Settings.Secure.getString(r, "test_key"));
    }

    @MediumTest
@@ -139,7 +161,7 @@ public class SettingsProviderTest extends AndroidTestCase {
        ContentResolver r = getContext().getContentResolver();

        // Make sure there's an owner
        assertTrue(findUser(um, UserHandle.USER_OWNER));
        assertTrue(findUser(um, UserHandle.USER_SYSTEM));

        // create a new user to use for testing
        UserInfo otherUser = um.createUser("TestUser1", UserInfo.FLAG_GUEST);
@@ -148,21 +170,17 @@ public class SettingsProviderTest extends AndroidTestCase {
            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);
            final String testKey = "testSettingsChangeForOtherUser";
            final String testValue1 = "value1";
            final String testValue2 = "value2";
            Settings.Secure.putString(r, testKey, testValue1);
            Settings.Secure.putStringForUser(r, testKey, testValue2, 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));
            assertEquals(testValue1, Settings.Secure.getString(r, testKey));
            assertEquals(testValue2, Settings.Secure.getStringForUser(r, testKey, 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);
@@ -170,6 +188,7 @@ public class SettingsProviderTest extends AndroidTestCase {
    }

    @MediumTest
    @Suppress  // Settings.Bookmarks uses a query format that's not supported now.
    public void testRowNumberContentUri() {
        ContentResolver r = getContext().getContentResolver();

@@ -196,47 +215,56 @@ public class SettingsProviderTest extends AndroidTestCase {
    public void testParseProviderList() {
        ContentResolver r = getContext().getContentResolver();

        // Make sure we get out what we put in.
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
                "test1,test2,test3");
        assertEquals(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED),
                "test1,test2,test3");

        // We only accept "+value" and "-value"
        // Test adding a value
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
                "");
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+test1");
        assertEquals("test1",
                Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED));
        assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test1"));

        // Test adding a second value
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+test2");
        assertEquals("test1,test2",
                Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED));
        assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test1"));
        assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test2"));

        // Test adding a third value
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+test3");
        assertEquals("test1,test2,test3",
                Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED));
        assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test1"));
        assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test2"));
        assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test3"));

        // Test deleting the first value in a 3 item list
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-test1");
        assertEquals("test2,test3",
                Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED));
        assertFalse(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test1"));

        // Test deleting the middle value in a 3 item list
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
                "test1,test2,test3");
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-test2");
        assertEquals("test1,test3",
                Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED));
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+test4");
        assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test2"));
        assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test3"));
        assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test4"));
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-test3");
        assertFalse(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test3"));

        // Test deleting the last value in a 3 item list
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
                "test1,test2,test3");
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-test3");
        assertEquals("test1,test2",
                Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED));
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "+test5");
        assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test2"));
        assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test4"));
        assertTrue(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test5"));
        Settings.Secure.putString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, "-test5");
        assertFalse(Settings.Secure.getString(r, Settings.Secure.LOCATION_PROVIDERS_ALLOWED)
                .contains("test5"));
     }

    private boolean findUser(UserManager um, int userHandle) {
@@ -254,7 +282,7 @@ public class SettingsProviderTest extends AndroidTestCase {
        ContentResolver r = getContext().getContentResolver();

        // Make sure there's an owner
        assertTrue(findUser(um, UserHandle.USER_OWNER));
        assertTrue(findUser(um, UserHandle.USER_SYSTEM));

        // create a new user to use for testing
        UserInfo user = um.createUser("TestUser1", UserInfo.FLAG_GUEST);
@@ -266,12 +294,12 @@ public class SettingsProviderTest extends AndroidTestCase {
            final int SELF_VALUE = 40;
            final int OTHER_VALUE = 27;

            Settings.System.putInt(r, TEST_KEY, SELF_VALUE);
            Settings.System.putIntForUser(r, TEST_KEY, OTHER_VALUE, user.id);
            Settings.Secure.putInt(r, TEST_KEY, SELF_VALUE);
            Settings.Secure.putIntForUser(r, TEST_KEY, OTHER_VALUE, user.id);

            // Verify that they read back as intended
            int myValue = Settings.System.getInt(r, TEST_KEY, 0);
            int otherValue = Settings.System.getIntForUser(r, TEST_KEY, 0, user.id);
            int myValue = Settings.Secure.getInt(r, TEST_KEY, 0);
            int otherValue = Settings.Secure.getIntForUser(r, TEST_KEY, 0, user.id);
            assertTrue("Running as user " + UserHandle.myUserId()
                    + " and reading/writing as user " + user.id
                    + ", expected to read " + SELF_VALUE + " but got " + myValue,
@@ -310,7 +338,8 @@ public class SettingsProviderTest extends AndroidTestCase {
        assertCanBeHandled(new Intent(Settings.ACTION_MEMORY_CARD_SETTINGS));
        assertCanBeHandled(new Intent(Settings.ACTION_NETWORK_OPERATOR_SETTINGS));
        assertCanBeHandled(new Intent(Settings.ACTION_PRIVACY_SETTINGS));
        assertCanBeHandled(new Intent(Settings.ACTION_QUICK_LAUNCH_SETTINGS));
        //TODO: seems no one is using this anymore.
//        assertCanBeHandled(new Intent(Settings.ACTION_QUICK_LAUNCH_SETTINGS));
        assertCanBeHandled(new Intent(Settings.ACTION_SEARCH_SETTINGS));
        assertCanBeHandled(new Intent(Settings.ACTION_SECURITY_SETTINGS));
        assertCanBeHandled(new Intent(Settings.ACTION_SETTINGS));
+30 −30

File changed.

Preview size limit exceeded, changes collapsed.

+2 −1
Original line number Diff line number Diff line
@@ -123,7 +123,8 @@ public class SettingsHelper {
        }

        if (sBroadcastOnRestore.contains(name)) {
            oldValue = table.lookup(cr, name, UserHandle.USER_OWNER);
            // TODO: http://b/22388012
            oldValue = table.lookup(cr, name, UserHandle.USER_SYSTEM);
            sendBroadcast = true;
        }

+28 −26
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.providers.settings;

import android.Manifest;
import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.app.AppGlobals;
import android.app.backup.BackupManager;
import android.content.BroadcastReceiver;
import android.content.ContentProvider;
@@ -27,6 +27,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
@@ -47,6 +48,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
@@ -208,13 +210,13 @@ public class SettingsProvider extends ContentProvider {
    private volatile UserManager mUserManager;

    // We have to call in the package manager with no lock held,
    private volatile PackageManager mPackageManager;
    private volatile IPackageManager mPackageManager;

    @Override
    public boolean onCreate() {
        synchronized (mLock) {
            mUserManager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
            mPackageManager = getContext().getPackageManager();
            mUserManager = UserManager.get(getContext());
            mPackageManager = AppGlobals.getPackageManager();
            mSettingsRegistry = new SettingsRegistry();
        }
        registerBroadcastReceivers();
@@ -496,7 +498,7 @@ public class SettingsProvider extends ContentProvider {
    }

    private void dumpForUser(int userId, PrintWriter pw) {
        if (userId == UserHandle.USER_OWNER) {
        if (userId == UserHandle.USER_SYSTEM) {
            pw.println("GLOBAL SETTINGS (user " + userId + ")");
            Cursor globalCursor = getAllGlobalSettings(ALL_COLUMNS);
            dumpSettings(globalCursor, pw);
@@ -547,7 +549,7 @@ public class SettingsProvider extends ContentProvider {
            @Override
            public void onReceive(Context context, Intent intent) {
                final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
                        UserHandle.USER_OWNER);
                        UserHandle.USER_SYSTEM);

                switch (intent.getAction()) {
                    case Intent.ACTION_USER_REMOVED: {
@@ -584,7 +586,7 @@ public class SettingsProvider extends ContentProvider {
        synchronized (mLock) {
            // Get the settings.
            SettingsState settingsState = mSettingsRegistry.getSettingsLocked(
                    SettingsRegistry.SETTINGS_TYPE_GLOBAL, UserHandle.USER_OWNER);
                    SettingsRegistry.SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM);

            List<String> names = settingsState.getSettingNamesLocked();

@@ -612,7 +614,7 @@ public class SettingsProvider extends ContentProvider {
        // Get the value.
        synchronized (mLock) {
            return mSettingsRegistry.getSettingLocked(SettingsRegistry.SETTINGS_TYPE_GLOBAL,
                    UserHandle.USER_OWNER, name);
                    UserHandle.USER_SYSTEM, name);
        }
    }

@@ -656,19 +658,19 @@ public class SettingsProvider extends ContentProvider {
                case MUTATION_OPERATION_INSERT: {
                    return mSettingsRegistry
                            .insertSettingLocked(SettingsRegistry.SETTINGS_TYPE_GLOBAL,
                                    UserHandle.USER_OWNER, name, value, getCallingPackage());
                                    UserHandle.USER_SYSTEM, name, value, getCallingPackage());
                }

                case MUTATION_OPERATION_DELETE: {
                    return mSettingsRegistry.deleteSettingLocked(
                            SettingsRegistry.SETTINGS_TYPE_GLOBAL,
                            UserHandle.USER_OWNER, name);
                            UserHandle.USER_SYSTEM, name);
                }

                case MUTATION_OPERATION_UPDATE: {
                    return mSettingsRegistry
                            .updateSettingLocked(SettingsRegistry.SETTINGS_TYPE_GLOBAL,
                                    UserHandle.USER_OWNER, name, value, getCallingPackage());
                                    UserHandle.USER_SYSTEM, name, value, getCallingPackage());
                }
            }
        }
@@ -903,7 +905,7 @@ public class SettingsProvider extends ContentProvider {
        }

        // Enforce what the calling package can mutate the system settings.
        enforceRestrictedSystemSettingsMutationForCallingPackage(operation, name);
        enforceRestrictedSystemSettingsMutationForCallingPackage(operation, name, runAsUserId);

        // Resolve the userId on whose behalf the call is made.
        final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(runAsUserId);
@@ -1001,7 +1003,7 @@ public class SettingsProvider extends ContentProvider {
    }

    private void enforceRestrictedSystemSettingsMutationForCallingPackage(int operation,
            String name) {
            String name, int userId) {
        // System/root/shell can mutate whatever secure settings they want.
        final int callingUid = Binder.getCallingUid();
        if (callingUid == android.os.Process.SYSTEM_UID
@@ -1019,7 +1021,7 @@ public class SettingsProvider extends ContentProvider {
                }

                // The calling package is already verified.
                PackageInfo packageInfo = getCallingPackageInfoOrThrow();
                PackageInfo packageInfo = getCallingPackageInfoOrThrow(userId);

                // Privileged apps can do whatever they want.
                if ((packageInfo.applicationInfo.privateFlags
@@ -1039,7 +1041,7 @@ public class SettingsProvider extends ContentProvider {
                }

                // The calling package is already verified.
                PackageInfo packageInfo = getCallingPackageInfoOrThrow();
                PackageInfo packageInfo = getCallingPackageInfoOrThrow(userId);

                // Privileged apps can do whatever they want.
                if ((packageInfo.applicationInfo.privateFlags &
@@ -1053,17 +1055,17 @@ public class SettingsProvider extends ContentProvider {
        }
    }

    private PackageInfo getCallingPackageInfoOrThrow() {
    private PackageInfo getCallingPackageInfoOrThrow(int userId) {
        try {
            return mPackageManager.getPackageInfo(getCallingPackage(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            return mPackageManager.getPackageInfo(getCallingPackage(), 0, userId);
        } catch (RemoteException e) {
            throw new IllegalStateException("Calling package doesn't exist");
        }
    }

    private int getGroupParentLocked(int userId) {
        // Most frequent use case.
        if (userId == UserHandle.USER_OWNER) {
        if (userId == UserHandle.USER_SYSTEM) {
            return userId;
        }
        // We are in the same process with the user manager and the returned
@@ -1401,8 +1403,8 @@ public class SettingsProvider extends ContentProvider {
            migrateLegacySettingsForUserIfNeededLocked(userId);

            // Ensure global settings loaded if owner.
            if (userId == UserHandle.USER_OWNER) {
                final int globalKey = makeKey(SETTINGS_TYPE_GLOBAL, UserHandle.USER_OWNER);
            if (userId == UserHandle.USER_SYSTEM) {
                final int globalKey = makeKey(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM);
                ensureSettingsStateLocked(globalKey);
            }

@@ -1541,7 +1543,7 @@ public class SettingsProvider extends ContentProvider {

        private void migrateAllLegacySettingsIfNeeded() {
            synchronized (mLock) {
                final int key = makeKey(SETTINGS_TYPE_GLOBAL, UserHandle.USER_OWNER);
                final int key = makeKey(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM);
                File globalFile = getSettingsFile(key);
                if (globalFile.exists()) {
                    return;
@@ -1591,7 +1593,7 @@ public class SettingsProvider extends ContentProvider {
        private void migrateLegacySettingsForUserLocked(DatabaseHelper dbHelper,
                SQLiteDatabase database, int userId) {
            // Move over the global settings if owner.
            if (userId == UserHandle.USER_OWNER) {
            if (userId == UserHandle.USER_SYSTEM) {
                final int globalKey = makeKey(SETTINGS_TYPE_GLOBAL, userId);
                ensureSettingsStateLocked(globalKey);
                SettingsState globalSettings = mSettingsStates.get(globalKey);
@@ -1898,7 +1900,7 @@ public class SettingsProvider extends ContentProvider {
                }

                // Set the global settings version if owner.
                if (mUserId == UserHandle.USER_OWNER) {
                if (mUserId == UserHandle.USER_SYSTEM) {
                    SettingsState globalSettings = getSettingsLocked(
                            SettingsRegistry.SETTINGS_TYPE_GLOBAL, mUserId);
                    globalSettings.setVersionLocked(newVersion);
@@ -1914,7 +1916,7 @@ public class SettingsProvider extends ContentProvider {
            }

            private SettingsState getGlobalSettingsLocked() {
                return getSettingsLocked(SETTINGS_TYPE_GLOBAL, UserHandle.USER_OWNER);
                return getSettingsLocked(SETTINGS_TYPE_GLOBAL, UserHandle.USER_SYSTEM);
            }

            private SettingsState getSecureSettingsLocked(int userId) {
@@ -1960,7 +1962,7 @@ public class SettingsProvider extends ContentProvider {

                // v119: Reset zen + ringer mode.
                if (currentVersion == 118) {
                    if (userId == UserHandle.USER_OWNER) {
                    if (userId == UserHandle.USER_SYSTEM) {
                        final SettingsState globalSettings = getGlobalSettingsLocked();
                        globalSettings.updateSettingLocked(Settings.Global.ZEN_MODE,
                                Integer.toString(Settings.Global.ZEN_MODE_OFF),
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ abstract class BaseSettingsProviderTest extends AndroidTestCase {
            Settings.NameValueTable.NAME, Settings.NameValueTable.VALUE
    };

    protected int mSecondaryUserId = UserHandle.USER_OWNER;
    protected int mSecondaryUserId = UserHandle.USER_SYSTEM;

    @Override
    public void setContext(Context context) {
Loading