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

Commit 7e0ff786 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 abf3e789
Loading
Loading
Loading
Loading
+63 −9
Original line number Diff line number Diff line
@@ -1511,6 +1511,11 @@ public final class Settings {

            // At one time in System, then Global, but now back in Secure
            MOVED_TO_SECURE.add(Secure.INSTALL_NON_MARKET_APPS);

            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;
@@ -1662,13 +1667,15 @@ public final class Settings {
            android.util.SeempLog.record(android.util.SeempLog.getSeempPutApiIdFromValue(name));
            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);
        }
@@ -2481,24 +2488,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.
         *
@@ -2940,9 +2950,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;


        /**
@@ -6382,6 +6393,40 @@ public final class Settings {
         */
        public static final String ADVANCED_REBOOT = "advanced_reboot";

        /*
         * 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";

        /**
         * Default theme to use.  If empty, use system.
         * @hide
@@ -6881,9 +6926,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.
@@ -8498,6 +8545,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);
        }

        /** @hide */
@@ -8561,6 +8609,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);
        }

+2 −0
Original line number Diff line number Diff line
@@ -34,10 +34,12 @@ 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.AttributeSet;
import android.view.View;

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

public class BatteryMeterView extends View implements DemoMode,
+89 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */
package com.android.systemui.cm;

import android.app.ActivityManagerNative;
import android.app.IUserSwitchObserver;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.IRemoteCallback;
import android.os.RemoteException;
import android.util.Log;

/**
 * Simple extension of ContentObserver that also listens for user switch events to call update
 */
public abstract class UserContentObserver extends ContentObserver {
    private static final String TAG = "UserContentObserver";

    private Runnable mUpdateRunnable;

    private IUserSwitchObserver mUserSwitchObserver = new IUserSwitchObserver.Stub() {
        @Override
        public void onUserSwitching(int newUserId, IRemoteCallback reply) {
        }
        @Override
        public void onUserSwitchComplete(int newUserId) throws RemoteException {
            mHandler.post(mUpdateRunnable);
        }
        @Override
        public void onForegroundProfileSwitch(int newProfileId) {
        }
    };

    private Handler mHandler;

    public UserContentObserver(Handler handler) {
        super(handler);
        mHandler = handler;
        mUpdateRunnable = new Runnable() {
            @Override
            public void run() {
                update();
            }
        };
    }

    protected void observe() {
        try {
            ActivityManagerNative.getDefault().registerUserSwitchObserver(mUserSwitchObserver);
        } catch (RemoteException e) {
            Log.w(TAG, "Unable to register user switch observer!", e);
        }
    }

    protected void unobserve() {
        try {
            mHandler.removeCallbacks(mUpdateRunnable);
            ActivityManagerNative.getDefault().unregisterUserSwitchObserver(mUserSwitchObserver);
        } catch (RemoteException e) {
            Log.w(TAG, "Unable to unregister user switch observer!", e);
        }
    }

    protected abstract void update();

    @Override
    public void onChange(boolean selfChange) {
        update();
    }

    @Override
    public void onChange(boolean selfChange, Uri uri) {
        update();
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Message;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
+11 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.widget.ImageView;

import com.android.internal.statusbar.StatusBarIcon;
import com.android.systemui.R;
import com.android.systemui.cm.UserContentObserver;

import java.text.NumberFormat;
import java.util.ArrayList;
@@ -334,7 +335,7 @@ public class StatusBarIconView extends AnimatedImageView {
        return mSlot;
    }

    static class GlobalSettingsObserver extends ContentObserver {
    static class GlobalSettingsObserver extends UserContentObserver {
        private static GlobalSettingsObserver sInstance;
        private ArrayList<StatusBarIconView> mIconViews = new ArrayList<StatusBarIconView>();
        private Context mContext;
@@ -365,18 +366,24 @@ public class StatusBarIconView extends AnimatedImageView {
            }
        }

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

            mContext.getContentResolver().registerContentObserver(
                    Settings.System.getUriFor(Settings.System.STATUS_BAR_NOTIF_COUNT),
                    false, this);
        }

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

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

        @Override
        public void onChange(boolean selfChange) {
        public void update() {
            boolean showIconCount = Settings.System.getIntForUser(mContext.getContentResolver(),
                    Settings.System.STATUS_BAR_NOTIF_COUNT, 0, UserHandle.USER_CURRENT) == 1;
            for (StatusBarIconView sbiv : mIconViews) {
Loading