Skip to content

Commit f752202

Browse files
author
Adam Cohen
committed
Plumbing to allow keyguard to be shown with user switcher (issue 7175023)
-> Also reduced calls to lockNow, and moved this call in ActivityManagerService Change-Id: I9ba34ca902f7c0f71fa4ec302104688ca8d11f55
1 parent 17f36d1 commit f752202

File tree

11 files changed

+113
-64
lines changed

11 files changed

+113
-64
lines changed

core/java/android/view/IWindowManager.aidl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import android.content.res.Configuration;
2424
import android.graphics.Bitmap;
2525
import android.graphics.Point;
2626
import android.graphics.Rect;
27+
import android.os.Bundle;
2728
import android.os.IRemoteCallback;
2829
import android.view.IApplicationToken;
2930
import android.view.IDisplayContentChangeListener;
@@ -209,9 +210,9 @@ interface IWindowManager
209210
boolean hasNavigationBar();
210211

211212
/**
212-
* Lock the device immediately.
213+
* Lock the device immediately with the specified options (can be null).
213214
*/
214-
void lockNow();
215+
void lockNow(in Bundle options);
215216

216217
/**
217218
* Gets the token for the focused window.

core/java/android/view/WindowManagerPolicy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.content.res.Configuration;
2222
import android.graphics.Rect;
2323
import android.graphics.RectF;
24+
import android.os.Bundle;
2425
import android.os.IBinder;
2526
import android.os.Looper;
2627
import android.view.animation.Animation;
@@ -1096,7 +1097,7 @@ interface OnKeyguardExitResult {
10961097
/**
10971098
* Lock the device now.
10981099
*/
1099-
public void lockNow();
1100+
public void lockNow(Bundle options);
11001101

11011102
/**
11021103
* Set the last used input method window state. This state is used to make IME transition

core/java/com/android/internal/widget/LockPatternUtils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.content.Intent;
2828
import android.content.pm.PackageManager;
2929
import android.os.Binder;
30+
import android.os.Bundle;
3031
import android.os.IBinder;
3132
import android.os.Process;
3233
import android.os.RemoteException;
@@ -98,6 +99,26 @@ public class LockPatternUtils {
9899
*/
99100
public static final int MIN_PATTERN_REGISTER_FAIL = MIN_LOCK_PATTERN_SIZE;
100101

102+
/**
103+
* Tells the keyguard to show the user switcher when the keyguard is created.
104+
*/
105+
public static final String KEYGUARD_SHOW_USER_SWITCHER = "showuserswitcher";
106+
107+
/**
108+
* Tells the keyguard to show the security challenge when the keyguard is created.
109+
*/
110+
public static final String KEYGUARD_SHOW_SECURITY_CHALLENGE = "showsecuritychallenge";
111+
112+
/**
113+
* Options used to lock the device upon user switch.
114+
*/
115+
public static final Bundle USER_SWITCH_LOCK_OPTIONS = new Bundle();
116+
117+
static {
118+
USER_SWITCH_LOCK_OPTIONS.putBoolean(KEYGUARD_SHOW_USER_SWITCHER, true);
119+
USER_SWITCH_LOCK_OPTIONS.putBoolean(KEYGUARD_SHOW_SECURITY_CHALLENGE, true);
120+
}
121+
101122
/**
102123
* The bit in LOCK_BIOMETRIC_WEAK_FLAGS to be used to indicate whether liveliness should
103124
* be used

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4047,21 +4047,36 @@ public void userActivity() {
40474047
}
40484048
}
40494049

4050-
Runnable mScreenLockTimeout = new Runnable() {
4050+
class ScreenLockTimeout implements Runnable {
4051+
Bundle options;
4052+
4053+
@Override
40514054
public void run() {
40524055
synchronized (this) {
40534056
if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
40544057
if (mKeyguardMediator != null) {
4055-
mKeyguardMediator.doKeyguardTimeout();
4058+
mKeyguardMediator.doKeyguardTimeout(options);
40564059
}
40574060
mLockScreenTimerActive = false;
4061+
options = null;
40584062
}
40594063
}
4060-
};
40614064

4062-
public void lockNow() {
4065+
public void setLockOptions(Bundle options) {
4066+
this.options = options;
4067+
}
4068+
}
4069+
4070+
ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4071+
4072+
public void lockNow(Bundle options) {
40634073
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
40644074
mHandler.removeCallbacks(mScreenLockTimeout);
4075+
if (options != null) {
4076+
// In case multiple calls are made to lockNow, we don't wipe out the options
4077+
// until the runnable actually executes.
4078+
mScreenLockTimeout.setLockOptions(options);
4079+
}
40654080
mHandler.post(mScreenLockTimeout);
40664081
}
40674082

policy/src/com/android/internal/policy/impl/keyguard/KeyguardMultiUserSelectorView.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,6 @@ public void onClick(View v) {
119119
public void run() {
120120
try {
121121
ActivityManagerNative.getDefault().switchUser(avatar.getUserInfo().id);
122-
WindowManagerGlobal.getWindowManagerService().lockNow();
123-
// Set the new active user, and make it appear active
124-
avatar.resetPressedState();
125-
mCallback.showSecurityView();
126-
mActiveUserAvatar = avatar;
127-
mActiveUserAvatar.setActive(true, false, 0, null);
128122
} catch (RemoteException re) {
129123
Log.e(TAG, "Couldn't switch user " + re);
130124
}

policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewManager.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@
2323
import android.content.res.Configuration;
2424
import android.content.res.Resources;
2525
import android.graphics.PixelFormat;
26+
import android.os.Bundle;
2627
import android.os.IBinder;
2728
import android.os.Parcelable;
2829
import android.os.SystemProperties;
2930
import android.util.Log;
3031
import android.util.Slog;
3132
import android.util.SparseArray;
33+
import android.view.KeyEvent;
3234
import android.view.LayoutInflater;
3335
import android.view.View;
3436
import android.view.ViewGroup;
3537
import android.view.ViewManager;
3638
import android.view.WindowManager;
3739
import android.widget.FrameLayout;
3840

39-
import com.android.internal.policy.impl.keyguard.KeyguardSecurityModel.SecurityMode;
40-
import com.android.internal.widget.LockPatternUtils;
4141
import com.android.internal.R;
42+
import com.android.internal.widget.LockPatternUtils;
4243

4344
/**
4445
* Manages creating, showing, hiding and resetting the keyguard. Calls back
@@ -87,12 +88,12 @@ public KeyguardViewManager(Context context, ViewManager viewManager,
8788
* Show the keyguard. Will handle creating and attaching to the view manager
8889
* lazily.
8990
*/
90-
public synchronized void show() {
91+
public synchronized void show(Bundle options) {
9192
if (DEBUG) Log.d(TAG, "show(); mKeyguardView==" + mKeyguardView);
9293

9394
boolean enableScreenRotation = shouldEnableScreenRotation();
9495

95-
maybeCreateKeyguardLocked(enableScreenRotation, false);
96+
maybeCreateKeyguardLocked(enableScreenRotation, options);
9697
maybeEnableScreenRotation(enableScreenRotation);
9798

9899
// Disable common aspects of the system/status/navigation bars that are not appropriate or
@@ -123,13 +124,13 @@ public ViewManagerHost(Context context) {
123124
@Override
124125
protected void onConfigurationChanged(Configuration newConfig) {
125126
super.onConfigurationChanged(newConfig);
126-
maybeCreateKeyguardLocked(shouldEnableScreenRotation(), false);
127+
maybeCreateKeyguardLocked(shouldEnableScreenRotation(), null);
127128
}
128129
}
129130

130131
SparseArray<Parcelable> mStateContainer = new SparseArray<Parcelable>();
131132

132-
private void maybeCreateKeyguardLocked(boolean enableScreenRotation, boolean userSwitched) {
133+
private void maybeCreateKeyguardLocked(boolean enableScreenRotation, Bundle options) {
133134
final boolean isActivity = (mContext instanceof Activity); // for test activity
134135

135136
if (mKeyguardHost != null) {
@@ -170,13 +171,13 @@ private void maybeCreateKeyguardLocked(boolean enableScreenRotation, boolean use
170171
mWindowLayoutParams = lp;
171172
mViewManager.addView(mKeyguardHost, lp);
172173
}
173-
inflateKeyguardView(userSwitched);
174+
inflateKeyguardView(options);
174175
mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);
175176

176177
mKeyguardHost.restoreHierarchyState(mStateContainer);
177178
}
178179

179-
private void inflateKeyguardView(boolean userSwitched) {
180+
private void inflateKeyguardView(Bundle options) {
180181
View v = mKeyguardHost.findViewById(R.id.keyguard_host_view);
181182
if (v != null) {
182183
mKeyguardHost.removeView(v);
@@ -190,11 +191,16 @@ private void inflateKeyguardView(boolean userSwitched) {
190191
mKeyguardView.setLockPatternUtils(mLockPatternUtils);
191192
mKeyguardView.setViewMediatorCallback(mViewMediatorCallback);
192193

193-
if (userSwitched) {
194+
if (options != null && options.getBoolean(LockPatternUtils.KEYGUARD_SHOW_USER_SWITCHER)) {
194195
mKeyguardView.goToUserSwitcher();
195196
mKeyguardView.showNextSecurityScreenIfPresent();
196197
}
197198

199+
if (options != null &&
200+
options.getBoolean(LockPatternUtils.KEYGUARD_SHOW_SECURITY_CHALLENGE)) {
201+
mKeyguardView.showNextSecurityScreenIfPresent();
202+
}
203+
198204
if (mScreenOn) {
199205
mKeyguardView.show();
200206
}
@@ -235,11 +241,11 @@ public void setNeedsInput(boolean needsInput) {
235241
/**
236242
* Reset the state of the view.
237243
*/
238-
public synchronized void reset(boolean userSwitched) {
244+
public synchronized void reset(Bundle options) {
239245
if (DEBUG) Log.d(TAG, "reset()");
240246
// User might have switched, check if we need to go back to keyguard
241247
// TODO: It's preferable to stay and show the correct lockscreen or unlock if none
242-
maybeCreateKeyguardLocked(shouldEnableScreenRotation(), userSwitched);
248+
maybeCreateKeyguardLocked(shouldEnableScreenRotation(), options);
243249
}
244250

245251
public synchronized void onScreenTurnedOff() {
@@ -281,7 +287,7 @@ public void run() {
281287

282288
public synchronized void verifyUnlock() {
283289
if (DEBUG) Log.d(TAG, "verifyUnlock()");
284-
show();
290+
show(null);
285291
mKeyguardView.verifyUnlock();
286292
}
287293

0 commit comments

Comments
 (0)