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
This commit is contained in:
@@ -799,7 +799,7 @@ public final class Settings {
|
||||
if (mCallGetCommand != null) {
|
||||
try {
|
||||
Bundle args = null;
|
||||
if (userHandle != UserHandle.myUserId()) {
|
||||
if (!isSelf) {
|
||||
args = new Bundle();
|
||||
args.putInt(CALL_METHOD_USER_KEY, userHandle);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.IWindowManager;
|
||||
@@ -55,16 +56,17 @@ public final class RotationPolicy {
|
||||
*/
|
||||
public static boolean isRotationLockToggleVisible(Context context) {
|
||||
return isRotationLockToggleSupported(context) &&
|
||||
Settings.System.getInt(context.getContentResolver(),
|
||||
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0) == 0;
|
||||
Settings.System.getIntForUser(context.getContentResolver(),
|
||||
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0,
|
||||
UserHandle.USER_CURRENT) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if rotation lock is enabled.
|
||||
*/
|
||||
public static boolean isRotationLocked(Context context) {
|
||||
return Settings.System.getInt(context.getContentResolver(),
|
||||
Settings.System.ACCELEROMETER_ROTATION, 0) == 0;
|
||||
return Settings.System.getIntForUser(context.getContentResolver(),
|
||||
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,8 +75,9 @@ public final class RotationPolicy {
|
||||
* Should be used by the rotation lock toggle.
|
||||
*/
|
||||
public static void setRotationLock(Context context, final boolean enabled) {
|
||||
Settings.System.putInt(context.getContentResolver(),
|
||||
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0);
|
||||
Settings.System.putIntForUser(context.getContentResolver(),
|
||||
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, 0,
|
||||
UserHandle.USER_CURRENT);
|
||||
|
||||
AsyncTask.execute(new Runnable() {
|
||||
@Override
|
||||
@@ -100,8 +103,9 @@ public final class RotationPolicy {
|
||||
* Should be used by Display settings and Accessibility settings.
|
||||
*/
|
||||
public static void setRotationLockForAccessibility(Context context, final boolean enabled) {
|
||||
Settings.System.putInt(context.getContentResolver(),
|
||||
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, enabled ? 1 : 0);
|
||||
Settings.System.putIntForUser(context.getContentResolver(),
|
||||
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY, enabled ? 1 : 0,
|
||||
UserHandle.USER_CURRENT);
|
||||
|
||||
AsyncTask.execute(new Runnable() {
|
||||
@Override
|
||||
@@ -121,16 +125,25 @@ public final class RotationPolicy {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a listener for rotation policy changes.
|
||||
* Registers a listener for rotation policy changes affecting the caller's user
|
||||
*/
|
||||
public static void registerRotationPolicyListener(Context context,
|
||||
RotationPolicyListener listener) {
|
||||
registerRotationPolicyListener(context, listener, UserHandle.getCallingUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a listener for rotation policy changes affecting a specific user,
|
||||
* or USER_ALL for all users.
|
||||
*/
|
||||
public static void registerRotationPolicyListener(Context context,
|
||||
RotationPolicyListener listener, int userHandle) {
|
||||
context.getContentResolver().registerContentObserver(Settings.System.getUriFor(
|
||||
Settings.System.ACCELEROMETER_ROTATION),
|
||||
false, listener.mObserver);
|
||||
false, listener.mObserver, userHandle);
|
||||
context.getContentResolver().registerContentObserver(Settings.System.getUriFor(
|
||||
Settings.System.HIDE_ROTATION_LOCK_TOGGLE_FOR_ACCESSIBILITY),
|
||||
false, listener.mObserver);
|
||||
false, listener.mObserver, userHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.android.systemui.recent.TaskDescription;
|
||||
import com.android.systemui.statusbar.policy.NotificationRowLayout;
|
||||
import com.android.systemui.statusbar.tablet.StatusBarPanel;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.ActivityOptions;
|
||||
import android.app.KeyguardManager;
|
||||
@@ -261,12 +262,7 @@ public abstract class BaseStatusBar extends SystemUI implements
|
||||
));
|
||||
}
|
||||
|
||||
// XXX: this is currently broken and will always return 0, but should start working at some point
|
||||
try {
|
||||
mCurrentUserId = ActivityManagerNative.getDefault().getCurrentUser().id;
|
||||
} catch (RemoteException e) {
|
||||
Log.v(TAG, "Couldn't get current user ID; guessing it's 0", e);
|
||||
}
|
||||
mCurrentUserId = ActivityManager.getCurrentUser();
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
|
||||
@@ -158,7 +158,8 @@ class QuickSettings {
|
||||
bluetoothController.addStateChangedCallback(mModel);
|
||||
batteryController.addStateChangedCallback(mModel);
|
||||
locationController.addStateChangedCallback(mModel);
|
||||
RotationPolicy.registerRotationPolicyListener(mContext, mRotationPolicyListener);
|
||||
RotationPolicy.registerRotationPolicyListener(mContext, mRotationPolicyListener,
|
||||
UserHandle.USER_ALL);
|
||||
}
|
||||
|
||||
private void queryForUserInformation() {
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.database.ContentObserver;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.hardware.display.WifiDisplayStatus;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.SettingNotFoundException;
|
||||
import android.text.TextUtils;
|
||||
@@ -94,6 +95,16 @@ class QuickSettingsModel implements BluetoothStateChangeCallback,
|
||||
}
|
||||
};
|
||||
|
||||
/** Broadcast receiver to act on user switches to update visuals of per-user state */
|
||||
private BroadcastReceiver mUserSwitchedReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
|
||||
onUserSwitched(intent);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** ContentObserver to determine the next alarm */
|
||||
private class NextAlarmObserver extends ContentObserver {
|
||||
public NextAlarmObserver(Handler handler) {
|
||||
@@ -203,6 +214,9 @@ class QuickSettingsModel implements BluetoothStateChangeCallback,
|
||||
IntentFilter alarmIntentFilter = new IntentFilter();
|
||||
alarmIntentFilter.addAction(Intent.ACTION_ALARM_CHANGED);
|
||||
context.registerReceiver(mAlarmIntentReceiver, alarmIntentFilter);
|
||||
|
||||
IntentFilter userSwitchedFilter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
|
||||
context.registerReceiver(mUserSwitchedReceiver, userSwitchedFilter);
|
||||
}
|
||||
|
||||
void updateResources() {
|
||||
@@ -609,4 +623,12 @@ class QuickSettingsModel implements BluetoothStateChangeCallback,
|
||||
onBrightnessLevelChanged();
|
||||
}
|
||||
|
||||
}
|
||||
// User switch: need to update visuals of all tiles known to have per-user state
|
||||
void onUserSwitched(Intent intent) {
|
||||
onRotationLockChanged();
|
||||
onBrightnessLevelChanged();
|
||||
onNextAlarmChanged();
|
||||
onBugreportChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.policy;
|
||||
import com.android.internal.view.RotationPolicy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.widget.CompoundButton;
|
||||
|
||||
public final class AutoRotateController implements CompoundButton.OnCheckedChangeListener {
|
||||
@@ -44,7 +45,8 @@ public final class AutoRotateController implements CompoundButton.OnCheckedChang
|
||||
|
||||
mCheckbox.setOnCheckedChangeListener(this);
|
||||
|
||||
RotationPolicy.registerRotationPolicyListener(context, mRotationPolicyListener);
|
||||
RotationPolicy.registerRotationPolicyListener(context, mRotationPolicyListener,
|
||||
UserHandle.USER_ALL);
|
||||
updateState();
|
||||
}
|
||||
|
||||
|
||||
@@ -506,6 +506,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
private boolean mPowerKeyTriggered;
|
||||
private long mPowerKeyTime;
|
||||
|
||||
SettingsObserver mSettingsObserver;
|
||||
ShortcutManager mShortcutManager;
|
||||
PowerManager.WakeLock mBroadcastWakeLock;
|
||||
boolean mHavePendingMediaKeyRepeatWithWakeLock;
|
||||
@@ -552,23 +553,32 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
}
|
||||
|
||||
void observe() {
|
||||
// Observe all users' changes
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
resolver.registerContentObserver(Settings.System.getUriFor(
|
||||
Settings.System.END_BUTTON_BEHAVIOR), false, this);
|
||||
Settings.System.END_BUTTON_BEHAVIOR), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
||||
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this);
|
||||
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
resolver.registerContentObserver(Settings.System.getUriFor(
|
||||
Settings.System.ACCELEROMETER_ROTATION), false, this);
|
||||
Settings.System.ACCELEROMETER_ROTATION), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
resolver.registerContentObserver(Settings.System.getUriFor(
|
||||
Settings.System.USER_ROTATION), false, this);
|
||||
Settings.System.USER_ROTATION), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
resolver.registerContentObserver(Settings.System.getUriFor(
|
||||
Settings.System.SCREEN_OFF_TIMEOUT), false, this);
|
||||
Settings.System.SCREEN_OFF_TIMEOUT), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
resolver.registerContentObserver(Settings.System.getUriFor(
|
||||
Settings.System.POINTER_LOCATION), false, this);
|
||||
Settings.System.POINTER_LOCATION), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
resolver.registerContentObserver(Settings.Secure.getUriFor(
|
||||
Settings.Secure.DEFAULT_INPUT_METHOD), false, this);
|
||||
Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
resolver.registerContentObserver(Settings.System.getUriFor(
|
||||
"fancy_rotation_anim"), false, this);
|
||||
"fancy_rotation_anim"), false, this,
|
||||
UserHandle.USER_ALL);
|
||||
updateSettings();
|
||||
}
|
||||
|
||||
@@ -875,8 +885,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
try {
|
||||
mOrientationListener.setCurrentRotation(windowManager.getRotation());
|
||||
} catch (RemoteException ex) { }
|
||||
SettingsObserver settingsObserver = new SettingsObserver(mHandler);
|
||||
settingsObserver.observe();
|
||||
mSettingsObserver = new SettingsObserver(mHandler);
|
||||
mSettingsObserver.observe();
|
||||
mShortcutManager = new ShortcutManager(context, mHandler);
|
||||
mShortcutManager.observe();
|
||||
mUiMode = context.getResources().getInteger(
|
||||
@@ -928,6 +938,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
Intent.EXTRA_DOCK_STATE_UNDOCKED);
|
||||
}
|
||||
|
||||
// register for multiuser-relevant broadcasts
|
||||
filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
|
||||
context.registerReceiver(mMultiuserReceiver, filter);
|
||||
|
||||
mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
mLongPressVibePattern = getLongIntArray(mContext.getResources(),
|
||||
com.android.internal.R.array.config_longPressVibePattern);
|
||||
@@ -1066,22 +1080,25 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
boolean updateRotation = false;
|
||||
synchronized (mLock) {
|
||||
mEndcallBehavior = Settings.System.getInt(resolver,
|
||||
mEndcallBehavior = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.END_BUTTON_BEHAVIOR,
|
||||
Settings.System.END_BUTTON_BEHAVIOR_DEFAULT);
|
||||
mIncallPowerBehavior = Settings.Secure.getInt(resolver,
|
||||
Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
|
||||
UserHandle.USER_CURRENT);
|
||||
mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
|
||||
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
|
||||
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT);
|
||||
Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
|
||||
UserHandle.USER_CURRENT);
|
||||
|
||||
// Configure rotation lock.
|
||||
int userRotation = Settings.System.getInt(resolver,
|
||||
Settings.System.USER_ROTATION, Surface.ROTATION_0);
|
||||
int userRotation = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.USER_ROTATION, Surface.ROTATION_0,
|
||||
UserHandle.USER_CURRENT);
|
||||
if (mUserRotation != userRotation) {
|
||||
mUserRotation = userRotation;
|
||||
updateRotation = true;
|
||||
}
|
||||
int userRotationMode = Settings.System.getInt(resolver,
|
||||
Settings.System.ACCELEROMETER_ROTATION, 0) != 0 ?
|
||||
int userRotationMode = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
|
||||
WindowManagerPolicy.USER_ROTATION_FREE :
|
||||
WindowManagerPolicy.USER_ROTATION_LOCKED;
|
||||
if (mUserRotationMode != userRotationMode) {
|
||||
@@ -1091,8 +1108,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
}
|
||||
|
||||
if (mSystemReady) {
|
||||
int pointerLocation = Settings.System.getInt(resolver,
|
||||
Settings.System.POINTER_LOCATION, 0);
|
||||
int pointerLocation = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
|
||||
if (mPointerLocationMode != pointerLocation) {
|
||||
mPointerLocationMode = pointerLocation;
|
||||
mHandler.sendEmptyMessage(pointerLocation != 0 ?
|
||||
@@ -1100,10 +1117,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
}
|
||||
}
|
||||
// use screen off timeout setting as the timeout for the lockscreen
|
||||
mLockScreenTimeout = Settings.System.getInt(resolver,
|
||||
Settings.System.SCREEN_OFF_TIMEOUT, 0);
|
||||
String imId = Settings.Secure.getString(resolver,
|
||||
Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||
mLockScreenTimeout = Settings.System.getIntForUser(resolver,
|
||||
Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
|
||||
String imId = Settings.Secure.getStringForUser(resolver,
|
||||
Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
|
||||
boolean hasSoftInput = imId != null && imId.length() > 0;
|
||||
if (mHasSoftInput != hasSoftInput) {
|
||||
mHasSoftInput = hasSoftInput;
|
||||
@@ -3557,6 +3574,19 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
}
|
||||
};
|
||||
|
||||
BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
|
||||
// tickle the settings observer: this first ensures that we're
|
||||
// observing the relevant settings for the newly-active user,
|
||||
// and then updates our own bookkeeping based on the now-
|
||||
// current user.
|
||||
mSettingsObserver.onChange(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void screenTurnedOff(int why) {
|
||||
EventLog.writeEvent(70000, 0);
|
||||
@@ -3889,16 +3919,19 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
|
||||
// mUserRotationMode and mUserRotation will be assigned by the content observer
|
||||
if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
|
||||
Settings.System.putInt(res,
|
||||
Settings.System.putIntForUser(res,
|
||||
Settings.System.USER_ROTATION,
|
||||
rot);
|
||||
Settings.System.putInt(res,
|
||||
rot,
|
||||
UserHandle.USER_CURRENT);
|
||||
Settings.System.putIntForUser(res,
|
||||
Settings.System.ACCELEROMETER_ROTATION,
|
||||
0);
|
||||
0,
|
||||
UserHandle.USER_CURRENT);
|
||||
} else {
|
||||
Settings.System.putInt(res,
|
||||
Settings.System.putIntForUser(res,
|
||||
Settings.System.ACCELEROMETER_ROTATION,
|
||||
1);
|
||||
1,
|
||||
UserHandle.USER_CURRENT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4218,8 +4251,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
}
|
||||
|
||||
public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
|
||||
final boolean hapticsDisabled = Settings.System.getInt(mContext.getContentResolver(),
|
||||
Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) == 0;
|
||||
final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
|
||||
if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user