diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/BatteryMeterView.java | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java index c4de63bdd303..fd2447bd47b4 100644 --- a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java +++ b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java @@ -18,6 +18,7 @@ package com.android.systemui; import static android.provider.Settings.System.SHOW_BATTERY_PERCENT; import android.animation.ArgbEvaluator; +import android.app.ActivityManager; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; @@ -40,6 +41,7 @@ import android.widget.TextView; import com.android.settingslib.Utils; import com.android.settingslib.graph.BatteryMeterDrawableBase; +import com.android.systemui.settings.CurrentUserTracker; import com.android.systemui.statusbar.phone.StatusBarIconController; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback; @@ -58,6 +60,7 @@ public class BatteryMeterView extends LinearLayout implements private final BatteryMeterDrawableBase mDrawable; private final String mSlotBattery; private final ImageView mBatteryIconView; + private final CurrentUserTracker mUserTracker; private TextView mBatteryPercentView; private BatteryController mBatteryController; @@ -72,6 +75,7 @@ public class BatteryMeterView extends LinearLayout implements private int mLightModeBackgroundColor; private int mLightModeFillColor; private float mDarkIntensity; + private int mUser; public BatteryMeterView(Context context) { this(context, null, 0); @@ -120,6 +124,16 @@ public class BatteryMeterView extends LinearLayout implements // Init to not dark at all. onDarkChanged(new Rect(), 0, DarkIconDispatcher.DEFAULT_ICON_TINT); + mUserTracker = new CurrentUserTracker(mContext) { + @Override + public void onUserSwitched(int newUserId) { + mUser = newUserId; + getContext().getContentResolver().unregisterContentObserver(mSettingObserver); + getContext().getContentResolver().registerContentObserver( + Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mSettingObserver, + newUserId); + } + }; } public void setForceShowPercent(boolean show) { @@ -145,16 +159,19 @@ public class BatteryMeterView extends LinearLayout implements super.onAttachedToWindow(); mBatteryController = Dependency.get(BatteryController.class); mBatteryController.addCallback(this); + mUser = ActivityManager.getCurrentUser(); getContext().getContentResolver().registerContentObserver( - Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mSettingObserver); + Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mSettingObserver, mUser); updateShowPercent(); Dependency.get(TunerService.class).addTunable(this, StatusBarIconController.ICON_BLACKLIST); Dependency.get(ConfigurationController.class).addCallback(this); + mUserTracker.startTracking(); } @Override public void onDetachedFromWindow() { super.onDetachedFromWindow(); + mUserTracker.stopTracking(); mBatteryController.removeCallback(this); getContext().getContentResolver().unregisterContentObserver(mSettingObserver); Dependency.get(TunerService.class).removeTunable(this); @@ -191,8 +208,8 @@ public class BatteryMeterView extends LinearLayout implements private void updateShowPercent() { final boolean showing = mBatteryPercentView != null; - if (0 != Settings.System.getInt(getContext().getContentResolver(), - SHOW_BATTERY_PERCENT, 0) || mForceShowPercent) { + if (0 != Settings.System.getIntForUser(getContext().getContentResolver(), + SHOW_BATTERY_PERCENT, 0, mUser) || mForceShowPercent) { if (!showing) { mBatteryPercentView = loadPercentView(); if (mTextColor != 0) mBatteryPercentView.setTextColor(mTextColor); |