Skip to content

Commit 5e08af0

Browse files
author
Christopher Tate
committed
Respect per-user rotation lock et alia
Various per-user settings such as rotation lock are relevant to the singleton PhoneWindowManager object. We now listen for user-switch broadcasts and reconfigure the active state based on the newly- active user's settings. The RotationPolicy toolset has also been updated to do the right thing, as has the Quick Settings UI. Bug 7213638 Change-Id: Iee2109e48df550b4c979d3f9c91b5d2b71a6a08e
1 parent a852ff3 commit 5e08af0

File tree

7 files changed

+120
-53
lines changed

7 files changed

+120
-53
lines changed

core/java/android/provider/Settings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ public String getStringForUser(ContentResolver cr, String name, final int userHa
799799
if (mCallGetCommand != null) {
800800
try {
801801
Bundle args = null;
802-
if (userHandle != UserHandle.myUserId()) {
802+
if (!isSelf) {
803803
args = new Bundle();
804804
args.putInt(CALL_METHOD_USER_KEY, userHandle);
805805
}

core/java/com/android/internal/view/RotationPolicy.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.os.Handler;
2424
import android.os.RemoteException;
2525
import android.os.ServiceManager;
26+
import android.os.UserHandle;
2627
import android.provider.Settings;
2728
import android.util.Log;
2829
import android.view.IWindowManager;
@@ -55,16 +56,17 @@ public static boolean isRotationLockToggleSupported(Context context) {
5556
*/
5657
public static boolean isRotationLockToggleVisible(Context context) {
5758
return isRotationLockToggleSupported(context) &&
58-
Settings.System.getInt(context.getContentResolver(),
59-
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0) == 0;
59+
Settings.System.getIntForUser(context.getContentResolver(),
60+
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0,
61+
UserHandle.USER_CURRENT) == 0;
6062
}
6163

6264
/**
6365
* Returns true if rotation lock is enabled.
6466
*/
6567
public static boolean isRotationLocked(Context context) {
66-
return Settings.System.getInt(context.getContentResolver(),
67-
Settings.System.ACCELEROMETER_ROTATION, 0) == 0;
68+
return Settings.System.getIntForUser(context.getContentResolver(),
69+
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) == 0;
6870
}
6971

7072
/**
@@ -73,8 +75,9 @@ public static boolean isRotationLocked(Context context) {
7375
* Should be used by the rotation lock toggle.
7476
*/
7577
public static void setRotationLock(Context context, final boolean enabled) {
76-
Settings.System.putInt(context.getContentResolver(),
77-
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0);
78+
Settings.System.putIntForUser(context.getContentResolver(),
79+
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0,
80+
UserHandle.USER_CURRENT);
7881

7982
AsyncTask.execute(new Runnable() {
8083
@Override
@@ -100,8 +103,9 @@ public void run() {
100103
* Should be used by Display settings and Accessibility settings.
101104
*/
102105
public static void setRotationLockForAccessibility(Context context, final boolean enabled) {
103-
Settings.System.putInt(context.getContentResolver(),
104-
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, enabled ? 1 : 0);
106+
Settings.System.putIntForUser(context.getContentResolver(),
107+
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, enabled ? 1 : 0,
108+
UserHandle.USER_CURRENT);
105109

106110
AsyncTask.execute(new Runnable() {
107111
@Override
@@ -121,16 +125,25 @@ public void run() {
121125
}
122126

123127
/**
124-
* Registers a listener for rotation policy changes.
128+
* Registers a listener for rotation policy changes affecting the caller's user
125129
*/
126130
public static void registerRotationPolicyListener(Context context,
127131
RotationPolicyListener listener) {
132+
registerRotationPolicyListener(context, listener, UserHandle.getCallingUserId());
133+
}
134+
135+
/**
136+
* Registers a listener for rotation policy changes affecting a specific user,
137+
* or USER_ALL for all users.
138+
*/
139+
public static void registerRotationPolicyListener(Context context,
140+
RotationPolicyListener listener, int userHandle) {
128141
context.getContentResolver().registerContentObserver(Settings.System.getUriFor(
129142
Settings.System.ACCELEROMETER_ROTATION),
130-
false, listener.mObserver);
143+
false, listener.mObserver, userHandle);
131144
context.getContentResolver().registerContentObserver(Settings.System.getUriFor(
132145
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY),
133-
false, listener.mObserver);
146+
false, listener.mObserver, userHandle);
134147
}
135148

136149
/**

packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.android.systemui.statusbar.policy.NotificationRowLayout;
3333
import com.android.systemui.statusbar.tablet.StatusBarPanel;
3434

35+
import android.app.ActivityManager;
3536
import android.app.ActivityManagerNative;
3637
import android.app.ActivityOptions;
3738
import android.app.KeyguardManager;
@@ -261,12 +262,7 @@ public void start() {
261262
));
262263
}
263264

264-
// XXX: this is currently broken and will always return 0, but should start working at some point
265-
try {
266-
mCurrentUserId = ActivityManagerNative.getDefault().getCurrentUser().id;
267-
} catch (RemoteException e) {
268-
Log.v(TAG, "Couldn't get current user ID; guessing it's 0", e);
269-
}
265+
mCurrentUserId = ActivityManager.getCurrentUser();
270266

271267
IntentFilter filter = new IntentFilter();
272268
filter.addAction(Intent.ACTION_USER_SWITCHED);

packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ void setup(NetworkController networkController, BluetoothController bluetoothCon
158158
bluetoothController.addStateChangedCallback(mModel);
159159
batteryController.addStateChangedCallback(mModel);
160160
locationController.addStateChangedCallback(mModel);
161-
RotationPolicy.registerRotationPolicyListener(mContext, mRotationPolicyListener);
161+
RotationPolicy.registerRotationPolicyListener(mContext, mRotationPolicyListener,
162+
UserHandle.USER_ALL);
162163
}
163164

164165
private void queryForUserInformation() {

packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickSettingsModel.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import android.graphics.drawable.Drawable;
3030
import android.hardware.display.WifiDisplayStatus;
3131
import android.os.Handler;
32+
import android.os.UserHandle;
3233
import android.provider.Settings;
3334
import android.provider.Settings.SettingNotFoundException;
3435
import android.text.TextUtils;
@@ -94,6 +95,16 @@ public void onReceive(Context context, Intent intent) {
9495
}
9596
};
9697

98+
/** Broadcast receiver to act on user switches to update visuals of per-user state */
99+
private BroadcastReceiver mUserSwitchedReceiver = new BroadcastReceiver() {
100+
@Override
101+
public void onReceive(Context context, Intent intent) {
102+
if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
103+
onUserSwitched(intent);
104+
}
105+
}
106+
};
107+
97108
/** ContentObserver to determine the next alarm */
98109
private class NextAlarmObserver extends ContentObserver {
99110
public NextAlarmObserver(Handler handler) {
@@ -203,6 +214,9 @@ public QuickSettingsModel(Context context) {
203214
IntentFilter alarmIntentFilter = new IntentFilter();
204215
alarmIntentFilter.addAction(Intent.ACTION_ALARM_CHANGED);
205216
context.registerReceiver(mAlarmIntentReceiver, alarmIntentFilter);
217+
218+
IntentFilter userSwitchedFilter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
219+
context.registerReceiver(mUserSwitchedReceiver, userSwitchedFilter);
206220
}
207221

208222
void updateResources() {
@@ -609,4 +623,12 @@ void refreshBrightnessTile() {
609623
onBrightnessLevelChanged();
610624
}
611625

612-
}
626+
// User switch: need to update visuals of all tiles known to have per-user state
627+
void onUserSwitched(Intent intent) {
628+
onRotationLockChanged();
629+
onBrightnessLevelChanged();
630+
onNextAlarmChanged();
631+
onBugreportChanged();
632+
}
633+
634+
}

packages/SystemUI/src/com/android/systemui/statusbar/policy/AutoRotateController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.android.internal.view.RotationPolicy;
2020

2121
import android.content.Context;
22+
import android.os.UserHandle;
2223
import android.widget.CompoundButton;
2324

2425
public final class AutoRotateController implements CompoundButton.OnCheckedChangeListener {
@@ -44,7 +45,8 @@ public AutoRotateController(Context context, CompoundButton checkbox,
4445

4546
mCheckbox.setOnCheckedChangeListener(this);
4647

47-
RotationPolicy.registerRotationPolicyListener(context, mRotationPolicyListener);
48+
RotationPolicy.registerRotationPolicyListener(context, mRotationPolicyListener,
49+
UserHandle.USER_ALL);
4850
updateState();
4951
}
5052

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ public void onInputEvent(InputEvent event) {
506506
private boolean mPowerKeyTriggered;
507507
private long mPowerKeyTime;
508508

509+
SettingsObserver mSettingsObserver;
509510
ShortcutManager mShortcutManager;
510511
PowerManager.WakeLock mBroadcastWakeLock;
511512
boolean mHavePendingMediaKeyRepeatWithWakeLock;
@@ -552,23 +553,32 @@ class SettingsObserver extends ContentObserver {
552553
}
553554

554555
void observe() {
556+
// Observe all users' changes
555557
ContentResolver resolver = mContext.getContentResolver();
556558
resolver.registerContentObserver(Settings.System.getUriFor(
557-
Settings.System.END_BUTTON_BEHAVIOR), false, this);
559+
Settings.System.END_BUTTON_BEHAVIOR), false, this,
560+
UserHandle.USER_ALL);
558561
resolver.registerContentObserver(Settings.Secure.getUriFor(
559-
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this);
562+
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
563+
UserHandle.USER_ALL);
560564
resolver.registerContentObserver(Settings.System.getUriFor(
561-
Settings.System.ACCELEROMETER_ROTATION), false, this);
565+
Settings.System.ACCELEROMETER_ROTATION), false, this,
566+
UserHandle.USER_ALL);
562567
resolver.registerContentObserver(Settings.System.getUriFor(
563-
Settings.System.USER_ROTATION), false, this);
568+
Settings.System.USER_ROTATION), false, this,
569+
UserHandle.USER_ALL);
564570
resolver.registerContentObserver(Settings.System.getUriFor(
565-
Settings.System.SCREEN_OFF_TIMEOUT), false, this);
571+
Settings.System.SCREEN_OFF_TIMEOUT), false, this,
572+
UserHandle.USER_ALL);
566573
resolver.registerContentObserver(Settings.System.getUriFor(
567-
Settings.System.POINTER_LOCATION), false, this);
574+
Settings.System.POINTER_LOCATION), false, this,
575+
UserHandle.USER_ALL);
568576
resolver.registerContentObserver(Settings.Secure.getUriFor(
569-
Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
577+
Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
578+
UserHandle.USER_ALL);
570579
resolver.registerContentObserver(Settings.System.getUriFor(
571-
"fancy_rotation_anim"), false, this);
580+
"fancy_rotation_anim"), false, this,
581+
UserHandle.USER_ALL);
572582
updateSettings();
573583
}
574584

@@ -875,8 +885,8 @@ public void init(Context context, IWindowManager windowManager,
875885
try {
876886
mOrientationListener.setCurrentRotation(windowManager.getRotation());
877887
} catch (RemoteException ex) { }
878-
SettingsObserver settingsObserver = new SettingsObserver(mHandler);
879-
settingsObserver.observe();
888+
mSettingsObserver = new SettingsObserver(mHandler);
889+
mSettingsObserver.observe();
880890
mShortcutManager = new ShortcutManager(context, mHandler);
881891
mShortcutManager.observe();
882892
mUiMode = context.getResources().getInteger(
@@ -928,6 +938,10 @@ public void init(Context context, IWindowManager windowManager,
928938
Intent.EXTRA_DOCK_STATE_UNDOCKED);
929939
}
930940

941+
// register for multiuser-relevant broadcasts
942+
filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
943+
context.registerReceiver(mMultiuserReceiver, filter);
944+
931945
mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
932946
mLongPressVibePattern = getLongIntArray(mContext.getResources(),
933947
com.android.internal.R.array.config_longPressVibePattern);
@@ -1066,22 +1080,25 @@ public void updateSettings() {
10661080
ContentResolver resolver = mContext.getContentResolver();
10671081
boolean updateRotation = false;
10681082
synchronized (mLock) {
1069-
mEndcallBehavior = Settings.System.getInt(resolver,
1083+
mEndcallBehavior = Settings.System.getIntForUser(resolver,
10701084
Settings.System.END_BUTTON_BEHAVIOR,
1071-
Settings.System.END_BUTTON_BEHAVIOR_DEFAULT);
1072-
mIncallPowerBehavior = Settings.Secure.getInt(resolver,
1085+
Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1086+
UserHandle.USER_CURRENT);
1087+
mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
10731088
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
1074-
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT);
1089+
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1090+
UserHandle.USER_CURRENT);
10751091

10761092
// Configure rotation lock.
1077-
int userRotation = Settings.System.getInt(resolver,
1078-
Settings.System.USER_ROTATION, Surface.ROTATION_0);
1093+
int userRotation = Settings.System.getIntForUser(resolver,
1094+
Settings.System.USER_ROTATION, Surface.ROTATION_0,
1095+
UserHandle.USER_CURRENT);
10791096
if (mUserRotation != userRotation) {
10801097
mUserRotation = userRotation;
10811098
updateRotation = true;
10821099
}
1083-
int userRotationMode = Settings.System.getInt(resolver,
1084-
Settings.System.ACCELEROMETER_ROTATION, 0) != 0 ?
1100+
int userRotationMode = Settings.System.getIntForUser(resolver,
1101+
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
10851102
WindowManagerPolicy.USER_ROTATION_FREE :
10861103
WindowManagerPolicy.USER_ROTATION_LOCKED;
10871104
if (mUserRotationMode != userRotationMode) {
@@ -1091,19 +1108,19 @@ public void updateSettings() {
10911108
}
10921109

10931110
if (mSystemReady) {
1094-
int pointerLocation = Settings.System.getInt(resolver,
1095-
Settings.System.POINTER_LOCATION, 0);
1111+
int pointerLocation = Settings.System.getIntForUser(resolver,
1112+
Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
10961113
if (mPointerLocationMode != pointerLocation) {
10971114
mPointerLocationMode = pointerLocation;
10981115
mHandler.sendEmptyMessage(pointerLocation != 0 ?
10991116
MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
11001117
}
11011118
}
11021119
// use screen off timeout setting as the timeout for the lockscreen
1103-
mLockScreenTimeout = Settings.System.getInt(resolver,
1104-
Settings.System.SCREEN_OFF_TIMEOUT, 0);
1105-
String imId = Settings.Secure.getString(resolver,
1106-
Settings.Secure.DEFAULT_INPUT_METHOD);
1120+
mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1121+
Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1122+
String imId = Settings.Secure.getStringForUser(resolver,
1123+
Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
11071124
boolean hasSoftInput = imId != null && imId.length() > 0;
11081125
if (mHasSoftInput != hasSoftInput) {
11091126
mHasSoftInput = hasSoftInput;
@@ -3557,6 +3574,19 @@ public void onReceive(Context context, Intent intent) {
35573574
}
35583575
};
35593576

3577+
BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
3578+
@Override
3579+
public void onReceive(Context context, Intent intent) {
3580+
if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
3581+
// tickle the settings observer: this first ensures that we're
3582+
// observing the relevant settings for the newly-active user,
3583+
// and then updates our own bookkeeping based on the now-
3584+
// current user.
3585+
mSettingsObserver.onChange(false);
3586+
}
3587+
}
3588+
};
3589+
35603590
/** {@inheritDoc} */
35613591
public void screenTurnedOff(int why) {
35623592
EventLog.writeEvent(70000, 0);
@@ -3889,16 +3919,19 @@ public void setUserRotationMode(int mode, int rot) {
38893919

38903920
// mUserRotationMode and mUserRotation will be assigned by the content observer
38913921
if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
3892-
Settings.System.putInt(res,
3922+
Settings.System.putIntForUser(res,
38933923
Settings.System.USER_ROTATION,
3894-
rot);
3895-
Settings.System.putInt(res,
3924+
rot,
3925+
UserHandle.USER_CURRENT);
3926+
Settings.System.putIntForUser(res,
38963927
Settings.System.ACCELEROMETER_ROTATION,
3897-
0);
3928+
0,
3929+
UserHandle.USER_CURRENT);
38983930
} else {
3899-
Settings.System.putInt(res,
3931+
Settings.System.putIntForUser(res,
39003932
Settings.System.ACCELEROMETER_ROTATION,
3901-
1);
3933+
1,
3934+
UserHandle.USER_CURRENT);
39023935
}
39033936
}
39043937

@@ -4218,8 +4251,8 @@ public void setCurrentOrientationLw(int newOrientation) {
42184251
}
42194252

42204253
public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
4221-
final boolean hapticsDisabled = Settings.System.getInt(mContext.getContentResolver(),
4222-
Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) == 0;
4254+
final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
4255+
Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
42234256
if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) {
42244257
return false;
42254258
}

0 commit comments

Comments
 (0)