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

Commit 6e358852 authored by Raj Yengisetty's avatar Raj Yengisetty Committed by Gerrit Code Review
Browse files

Support settings for Multi-User

Change-Id: I25a5f6ab65c92d7bb66ee23fa67d0d0a3cd4d485
parent c09f1162
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3025,6 +3025,7 @@ public final class Settings {
            PHONE_BLACKLIST_PRIVATE_NUMBER_MODE,
            PHONE_BLACKLIST_UNKNOWN_NUMBER_MODE,
            PHONE_BLACKLIST_REGEX_ENABLED,
            STATUS_BAR_SHOW_BATTERY_PERCENT,
        };

        /**
+31 −8
Original line number Diff line number Diff line
package com.android.systemui;

import android.app.ActivityManager;
import android.content.Context;
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.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
        BatteryController.BatteryStateChangeCallback{

    private static final String STATUS_BAR_SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";

    private BatteryController mBatteryController;
    private boolean mShow;

    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_SHOW_BATTERY_PERCENT), false, this, UserHandle.USER_ALL);
        }
        @Override
        protected void unobserve() {
            super.unobserve();
            getContext().getContentResolver().unregisterContentObserver(this);
        }
        @Override
        public void update() {
            loadShowBatteryTextSetting();
            setVisibility(mShow ? View.VISIBLE : View.GONE);
        }
@@ -29,8 +50,10 @@ public class BatteryLevelTextView extends TextView implements
    }

    private void loadShowBatteryTextSetting() {
        mShow = 0 != Settings.System.getInt(
            getContext().getContentResolver(), Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0);
        int currentUserId = ActivityManager.getCurrentUser();
        mShow = 0 != Settings.System.getIntForUser(
                getContext().getContentResolver(),
                Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0, currentUserId);
    }

    @Override
@@ -51,13 +74,13 @@ public class BatteryLevelTextView extends TextView implements
    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
           Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT), false, mObserver);
        mObserver.observe();
    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        mObserver.unobserve();

        if (mBatteryController != null) {
            mBatteryController.removeStateChangedCallback(this);
+5 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui;

import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -216,8 +217,10 @@ public class BatteryMeterView extends View implements DemoMode,
        levels.recycle();
        colors.recycle();
        atts.recycle();
        mShowPercent = ENABLE_PERCENT && 0 != Settings.System.getInt(
                context.getContentResolver(), "status_bar_show_battery_percent", 0);
        int currentUserId = ActivityManager.getCurrentUser();

        mShowPercent = ENABLE_PERCENT && 0 != Settings.System.getIntForUser(
                context.getContentResolver(), "status_bar_show_battery_percent", 0, currentUserId);
        mWarningString = context.getString(R.string.battery_meter_very_low_overlay_symbol);
        mCriticalLevel = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_criticalBatteryWarningLevel);
+86 −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);
        }
    };

    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();
    }
}
+5 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.phone;

import android.animation.LayoutTransition;
import android.app.ActivityManager;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
@@ -76,8 +77,10 @@ public class KeyguardStatusBarView extends RelativeLayout
    }

    private void loadShowBatteryTextSetting() {
        mShow = 0 != Settings.System.getInt(
            getContext().getContentResolver(), Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0);
        int currentUserId = ActivityManager.getCurrentUser();
        mShow = 0 != Settings.System.getIntForUser(
                getContext().getContentResolver(), Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT,
                0, currentUserId);
    }

    @Override
Loading