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

Commit bd1788f4 authored by linus_lee's avatar linus_lee Committed by Steve Kondik
Browse files

Enable Buttons and Status Bar settings Multi-user enabled

The main issue is SystemUI process is shared across users, so calling getString(...)
will call UserHandle.myUserId() which will return the user id of the process.
To fix this, all relevant calls should be changed to get*ForUser as well as listen
to UserChanged event so that when the user switches, the settings are updated

Change-Id: I9ac3fbfec1646993028c34789a4299d85079f8f1
parent 5f9472c9
Loading
Loading
Loading
Loading
+62 −9
Original line number Diff line number Diff line
@@ -1255,6 +1255,10 @@ public final class Settings {
            for (String s : Secure.NAVIGATION_RING_TARGETS) {
                MOVED_TO_SECURE.add(s);
            }
            MOVED_TO_SECURE.add(Secure.DEV_FORCE_SHOW_NAVBAR);
            MOVED_TO_SECURE.add(Secure.KEYBOARD_BRIGHTNESS);
            MOVED_TO_SECURE.add(Secure.BUTTON_BRIGHTNESS);
            MOVED_TO_SECURE.add(Secure.BUTTON_BACKLIGHT_TIMEOUT);
        }

        private static final HashSet<String> MOVED_TO_GLOBAL;
@@ -1402,13 +1406,15 @@ public final class Settings {
                int userHandle) {
            if (MOVED_TO_SECURE.contains(name)) {
                Log.w(TAG, "Setting " + name + " has moved from android.provider.Settings.System"
                        + " to android.provider.Settings.Secure, value is unchanged.");
                return false;
                        + " to android.provider.Settings.Secure.");

                return Secure.putStringForUser(resolver, name, value, userHandle);
            }
            if (MOVED_TO_GLOBAL.contains(name) || MOVED_TO_SECURE_THEN_GLOBAL.contains(name)) {
                Log.w(TAG, "Setting " + name + " has moved from android.provider.Settings.System"
                        + " to android.provider.Settings.Global, value is unchanged.");
                return false;
                        + " to android.provider.Settings.Global.");

                return Global.putStringForUser(resolver, name, value, userHandle);
            }
            return sNameValueCache.putStringForUser(resolver, name, value, userHandle);
        }
@@ -2133,24 +2139,27 @@ public final class Settings {
        /**
         * The keyboard brightness to be used while the screen is on.
         * Valid value range is between 0 and {@link PowerManager#getMaximumKeyboardBrightness()}
         * @deprecated
         * @hide
         */
        public static final String KEYBOARD_BRIGHTNESS = "keyboard_brightness";
        public static final String KEYBOARD_BRIGHTNESS = Secure.KEYBOARD_BRIGHTNESS;

        /**
         * The button brightness to be used while the screen is on or after a button press,
         * depending on the value of {@link BUTTON_BACKLIGHT_TIMEOUT}.
         * Valid value range is between 0 and {@link PowerManager#getMaximumButtonBrightness()}
         * @deprecated
         * @hide
         */
        public static final String BUTTON_BRIGHTNESS = "button_brightness";
        public static final String BUTTON_BRIGHTNESS = Secure.BUTTON_BRIGHTNESS;

        /**
         * The time in ms to keep the button backlight on after pressing a button.
         * A value of 0 will keep the buttons on for as long as the screen is on.
         * @deprecated
         * @hide
         */
        public static final String BUTTON_BACKLIGHT_TIMEOUT = "button_backlight_timeout";
        public static final String BUTTON_BACKLIGHT_TIMEOUT = Secure.BUTTON_BACKLIGHT_TIMEOUT;

        /** Whether to allow one finger quick settings expansion on the right side of the statusbar.
         *
@@ -2613,9 +2622,10 @@ public final class Settings {

        /**
        * Developer options - Navigation Bar show switch
        * @deprecated
        * @hide
        */
        public static final String DEV_FORCE_SHOW_NAVBAR = "dev_force_show_navbar";
        public static final String DEV_FORCE_SHOW_NAVBAR = Secure.DEV_FORCE_SHOW_NAVBAR;


        /**
@@ -5878,6 +5888,40 @@ public final class Settings {
         */
        public static final String ADVANCED_MODE = "advanced_mode";

        /*
         * String to contain power menu actions
         * @hide
         */
        public static final String POWER_MENU_ACTIONS = "power_menu_actions";

        /**
         * Developer options - Navigation Bar show switch
         * @hide
         */
        public static final String DEV_FORCE_SHOW_NAVBAR = "dev_force_show_navbar";

        /**
         * The keyboard brightness to be used while the screen is on.
         * Valid value range is between 0 and {@link PowerManager#getMaximumKeyboardBrightness()}
         * @hide
         */
        public static final String KEYBOARD_BRIGHTNESS = "keyboard_brightness";

        /**
         * The button brightness to be used while the screen is on or after a button press,
         * depending on the value of {@link BUTTON_BACKLIGHT_TIMEOUT}.
         * Valid value range is between 0 and {@link PowerManager#getMaximumButtonBrightness()}
         * @hide
         */
        public static final String BUTTON_BRIGHTNESS = "button_brightness";

        /**
         * The time in ms to keep the button backlight on after pressing a button.
         * A value of 0 will keep the buttons on for as long as the screen is on.
         * @hide
         */
        public static final String BUTTON_BACKLIGHT_TIMEOUT = "button_backlight_timeout";

        /**
         * This are the settings to be backed up.
         *
@@ -6333,9 +6377,11 @@ public final class Settings {

        /**
         * String to contain power menu actions
         * @deprecated Use {@link android.provider.Settings.Secure#POWER_MENU_ACTIONS} instead
         * @hide
         */
        public static final String POWER_MENU_ACTIONS = "power_menu_actions";
        @Deprecated
        public static final String POWER_MENU_ACTIONS = Secure.POWER_MENU_ACTIONS;

        /**
         * Whether Views are allowed to save their attribute data.
@@ -7833,6 +7879,7 @@ public final class Settings {
        static {
            MOVED_TO_SECURE = new HashSet<String>(1);
            MOVED_TO_SECURE.add(Settings.Global.INSTALL_NON_MARKET_APPS);
            MOVED_TO_SECURE.add(Settings.Secure.POWER_MENU_ACTIONS);
        }

        /**
@@ -7929,6 +7976,12 @@ public final class Settings {
         * @return the corresponding content URI, or null if not present
         */
        public static Uri getUriFor(String name) {
            if (MOVED_TO_SECURE.contains(name)) {
                Log.w(TAG, "Setting " + name + " has moved from android.provider.Settings.Global"
                        + " to android.provider.Settings.Secure, returning Secure URI.");
                return Secure.getUriFor(Secure.CONTENT_URI, name);
            }

            return getUriFor(CONTENT_URI, name);
        }

+20 −1
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
    // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
    // is properly propagated through your change.  Not doing so will result in a loss of user
    // settings.
    private static final int DATABASE_VERSION = 122;
    private static final int DATABASE_VERSION = 123;

    private static final String HEADSET = "_headset";
    private static final String SPEAKER = "_speaker";
@@ -1954,6 +1954,25 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            upgradeVersion = 122;
        }

        if (upgradeVersion < 123) {
            // only the owner has access to global table, so we need to check that here
            if (mUserHandle == UserHandle.USER_OWNER) {
                String[] globalToSecure = new String[] { Settings.Secure.POWER_MENU_ACTIONS };

                moveSettingsToNewTable(db, TABLE_GLOBAL, TABLE_SECURE, globalToSecure, true);
            }

            String[] systemToSecure = new String[] {
                    Secure.DEV_FORCE_SHOW_NAVBAR,
                    Secure.KEYBOARD_BRIGHTNESS,
                    Secure.BUTTON_BRIGHTNESS,
                    Secure.BUTTON_BACKLIGHT_TIMEOUT
            };
            moveSettingsToNewTable(db, TABLE_SYSTEM, TABLE_SECURE, systemToSecure, true);

            upgradeVersion = 123;
        }

        // *** Remember to update DATABASE_VERSION above!

        if (upgradeVersion != currentVersion) {
+32 −10
Original line number Diff line number Diff line
@@ -20,14 +20,14 @@ import android.app.ActivityManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;

import com.android.systemui.cm.UserContentObserver;
import com.android.systemui.statusbar.policy.BatteryController;

public class BatteryLevelTextView extends TextView implements
@@ -43,8 +43,32 @@ public class BatteryLevelTextView extends TextView implements
    private boolean mAttached;
    private int mRequestedVisibility;

    private ContentObserver mObserver = new ContentObserver(new Handler()) {
        public void onChange(boolean selfChange, Uri uri) {
    private SettingsObserver mObserver = new SettingsObserver(new Handler());

    private class SettingsObserver extends UserContentObserver {
        public SettingsObserver(Handler handler) {
            super(handler);
        }

        @Override
        protected void observe() {
            super.observe();

            getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
                    STATUS_BAR_BATTERY_STYLE), false, this, UserHandle.USER_ALL);
            getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
                    STATUS_BAR_SHOW_BATTERY_PERCENT), false, this, UserHandle.USER_ALL);
        }

        @Override
        protected void unobserve() {
            super.unobserve();

            getContext().getContentResolver().unregisterContentObserver(this);
        }

        @Override
        public void update() {
            loadShowBatteryTextSetting();
        }
    };
@@ -104,10 +128,8 @@ public class BatteryLevelTextView extends TextView implements
        if (mBatteryController != null) {
            mBatteryController.addStateChangedCallback(this);
        }
        getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
                STATUS_BAR_BATTERY_STYLE), false, mObserver);
        getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
                STATUS_BAR_SHOW_BATTERY_PERCENT), false, mObserver);
        mObserver.observe();

        mAttached = true;
    }

@@ -115,7 +137,7 @@ public class BatteryLevelTextView extends TextView implements
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        mAttached = false;
        getContext().getContentResolver().unregisterContentObserver(mObserver);
        mObserver.unobserve();

        if (mBatteryController != null) {
            mBatteryController.removeStateChangedCallback(this);
+29 −6
Original line number Diff line number Diff line
@@ -36,12 +36,14 @@ import android.net.Uri;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import com.android.systemui.cm.UserContentObserver;
import com.android.systemui.statusbar.policy.BatteryController;

public class BatteryMeterView extends View implements DemoMode,
@@ -197,8 +199,31 @@ public class BatteryMeterView extends View implements DemoMode,
        }
    };

    private ContentObserver mObserver = new ContentObserver(new Handler()) {
        public void onChange(boolean selfChange, Uri uri) {
    SettingsObserver mObserver = new SettingsObserver(new Handler());

    private class SettingsObserver extends UserContentObserver {
        public SettingsObserver(Handler handler) {
            super(handler);
        }

        @Override
        protected void observe() {
            super.observe();

            getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
                    STATUS_BAR_BATTERY_STYLE), false, this, UserHandle.USER_ALL);
            getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
                    STATUS_BAR_SHOW_BATTERY_PERCENT), false, this, UserHandle.USER_ALL);
        }

        @Override
        protected void unobserve() {
            super.unobserve();
            getContext().getContentResolver().unregisterContentObserver(this);
        }

        @Override
        public void update() {
            loadShowBatterySetting();
            postInvalidate();
        }
@@ -218,10 +243,7 @@ public class BatteryMeterView extends View implements DemoMode,
        }
        mBatteryController.addStateChangedCallback(this);
        mAttached = true;
        getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
                STATUS_BAR_BATTERY_STYLE), false, mObserver);
        getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
                STATUS_BAR_SHOW_BATTERY_PERCENT), false, mObserver);
        mObserver.observe();
    }

    @Override
@@ -230,6 +252,7 @@ public class BatteryMeterView extends View implements DemoMode,

        mAttached = false;
        getContext().unregisterReceiver(mTracker);
        mObserver.unobserve();
        mBatteryController.removeStateChangedCallback(this);
    }

+19 −9
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.widget.ImageView;
import com.android.systemui.cm.ActionTarget;
import com.android.systemui.cm.NavigationRingHelpers;
import com.android.systemui.cm.ShortcutPickHelper;
import com.android.systemui.cm.UserContentObserver;
import com.android.systemui.statusbar.BaseStatusBar;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.StatusBarPanel;
@@ -96,6 +97,7 @@ public class SearchPanelView extends FrameLayout implements StatusBarPanel,
    private ImageView mLogoRight, mLogoLeft;
    private final ActionTarget mActionTarget;
    private ShortcutPickHelper mPicker;
    private SettingsObserver mSettingsObserver;

    public SearchPanelView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
@@ -111,8 +113,8 @@ public class SearchPanelView extends FrameLayout implements StatusBarPanel,
        // Instantiate receiver/observer
        IntentFilter filter = new IntentFilter();
        filter.addAction(BROADCAST);
        mContext.registerReceiver(mReceiver, filter);
        new SettingsObserver(new Handler());
        mContext.registerReceiverAsUser(mReceiver, UserHandle.ALL, filter, null, null);
        mSettingsObserver = new SettingsObserver(new Handler());
    }

    private void startAssistActivity() {
@@ -421,28 +423,30 @@ public class SearchPanelView extends FrameLayout implements StatusBarPanel,
    public void shortcutPicked(String uri) {
        if (uri != null) {
            int index = mTargetViews.indexOf(mSelectedView);
            Settings.Secure.putString(mContext.getContentResolver(),
                    Settings.Secure.NAVIGATION_RING_TARGETS[index], uri);
            Settings.Secure.putStringForUser(mContext.getContentResolver(),
                    Settings.Secure.NAVIGATION_RING_TARGETS[index], uri, UserHandle.USER_CURRENT);
        }
    }

    private class SettingsObserver extends ContentObserver {
    private class SettingsObserver extends UserContentObserver {
        SettingsObserver(Handler handler) {
            super(handler);
            observe();
        }

        void observe() {
        @Override
        protected void observe() {
            super.observe();

            ContentResolver resolver = mContext.getContentResolver();
            for (int i = 0; i < NavigationRingHelpers.MAX_ACTIONS; i++) {
                resolver.registerContentObserver(
                        Settings.Secure.getUriFor(Settings.Secure.NAVIGATION_RING_TARGETS[i]),
                        false, this);
                        false, this, UserHandle.USER_ALL);
            }
        }

        @Override
        public void onChange(boolean selfChange) {
        public void update() {
            updateDrawables();
        }
    }
@@ -533,6 +537,12 @@ public class SearchPanelView extends FrameLayout implements StatusBarPanel,
        }
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        mSettingsObserver.observe();
    }

    @Override
    protected void onDetachedFromWindow() {
        mPicker.cleanup();
Loading