Skip to content

Commit 6bcd732

Browse files
Jim MillerAdam Cohen
authored andcommitted
Switch back to user switcher in keyguard
Change-Id: I9acfb61fd34ad24a299e1f11f792e9e240f2b065
1 parent 61cd69c commit 6bcd732

File tree

6 files changed

+46
-25
lines changed

6 files changed

+46
-25
lines changed

core/res/res/layout/keyguard_multi_user_selector_widget.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<!-- This is a view that shows general status information in Keyguard. -->
2121
<com.android.internal.policy.impl.keyguard.KeyguardWidgetFrame
2222
xmlns:android="http://schemas.android.com/apk/res/android"
23+
android:id="@+id/keyguard_multi_user_selector"
2324
android:layout_width="match_parent"
2425
android:layout_height="match_parent">
2526

core/res/res/values/symbols.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,7 @@
12991299
<java-symbol type="id" name="kg_widget_region" />
13001300
<java-symbol type="id" name="left_strip" />
13011301
<java-symbol type="id" name="right_strip" />
1302+
<java-symbol type="id" name="keyguard_multi_user_selector" />
13021303

13031304
<java-symbol type="integer" name="config_carDockRotation" />
13041305
<java-symbol type="integer" name="config_defaultUiModeType" />

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,4 +820,8 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
820820
}
821821
}
822822

823+
public void goToUserSwitcher() {
824+
mAppWidgetContainer.setCurrentPage(getWidgetPosition(R.id.keyguard_multi_user_selector));
825+
}
826+
823827
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ public KeyguardMultiUserAvatar(Context context, AttributeSet attrs) {
7171

7272
public KeyguardMultiUserAvatar(Context context, AttributeSet attrs, int defStyle) {
7373
super(context, attrs, defStyle);
74-
75-
Resources res = context.getResources();
76-
mActiveTextColor = res.getColor(R.color.kg_multi_user_text_active);
77-
mInactiveTextColor = res.getColor(R.color.kg_multi_user_text_inactive);
7874
}
7975

8076
public void setup(UserInfo user, KeyguardMultiUserSelectorView userSelector) {
@@ -84,8 +80,12 @@ public void setup(UserInfo user, KeyguardMultiUserSelectorView userSelector) {
8480
}
8581

8682
private void init() {
83+
Resources res = mContext.getResources();
84+
mActiveTextColor = res.getColor(R.color.kg_multi_user_text_active);
85+
mInactiveTextColor = res.getColor(R.color.kg_multi_user_text_inactive);
86+
8787
mUserImage = (ImageView) findViewById(R.id.keyguard_user_avatar);
88-
mUserName = (TextView) findViewById(R.id.keyguard_user_name);
88+
mUserName = (TextView) findViewById(R.id.keyguard_user_name);
8989

9090
mUserImage.setImageDrawable(Drawable.createFromPath(mUserInfo.iconPath));
9191
mUserName.setText(mUserInfo.name);

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
import android.content.res.Resources;
2525
import android.graphics.PixelFormat;
2626
import android.os.IBinder;
27+
import android.os.Parcelable;
2728
import android.os.SystemProperties;
2829
import android.util.Log;
2930
import android.util.Slog;
31+
import android.util.SparseArray;
3032
import android.view.LayoutInflater;
3133
import android.view.View;
3234
import android.view.ViewGroup;
@@ -89,7 +91,7 @@ public synchronized void show() {
8991

9092
boolean enableScreenRotation = shouldEnableScreenRotation();
9193

92-
maybeCreateKeyguardLocked(enableScreenRotation);
94+
maybeCreateKeyguardLocked(enableScreenRotation, false);
9395
maybeEnableScreenRotation(enableScreenRotation);
9496

9597
// Disable common aspects of the system/status/navigation bars that are not appropriate or
@@ -120,13 +122,19 @@ public ViewManagerHost(Context context) {
120122
@Override
121123
protected void onConfigurationChanged(Configuration newConfig) {
122124
super.onConfigurationChanged(newConfig);
123-
maybeCreateKeyguardLocked(shouldEnableScreenRotation());
125+
maybeCreateKeyguardLocked(shouldEnableScreenRotation(), false);
124126
}
125127
}
126128

127-
private void maybeCreateKeyguardLocked(boolean enableScreenRotation) {
129+
SparseArray<Parcelable> mStateContainer = new SparseArray<Parcelable>();
130+
131+
private void maybeCreateKeyguardLocked(boolean enableScreenRotation, boolean userSwitched) {
128132
final boolean isActivity = (mContext instanceof Activity); // for test activity
129133

134+
if (mKeyguardHost != null) {
135+
mKeyguardHost.saveHierarchyState(mStateContainer);
136+
}
137+
130138
if (mKeyguardHost == null) {
131139
if (DEBUG) Log.d(TAG, "keyguard host is null, creating it...");
132140

@@ -161,11 +169,13 @@ private void maybeCreateKeyguardLocked(boolean enableScreenRotation) {
161169
mWindowLayoutParams = lp;
162170
mViewManager.addView(mKeyguardHost, lp);
163171
}
164-
inflateKeyguardView();
172+
inflateKeyguardView(userSwitched);
165173
mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);
174+
175+
mKeyguardHost.restoreHierarchyState(mStateContainer);
166176
}
167177

168-
private void inflateKeyguardView() {
178+
private void inflateKeyguardView(boolean userSwitched) {
169179
View v = mKeyguardHost.findViewById(R.id.keyguard_host_view);
170180
if (v != null) {
171181
mKeyguardHost.removeView(v);
@@ -179,6 +189,10 @@ private void inflateKeyguardView() {
179189
mKeyguardView.setLockPatternUtils(mLockPatternUtils);
180190
mKeyguardView.setViewMediatorCallback(mViewMediatorCallback);
181191

192+
if (userSwitched) {
193+
mKeyguardView.goToUserSwitcher();
194+
}
195+
182196
if (mScreenOn) {
183197
mKeyguardView.show();
184198
}
@@ -219,11 +233,11 @@ public void setNeedsInput(boolean needsInput) {
219233
/**
220234
* Reset the state of the view.
221235
*/
222-
public synchronized void reset() {
236+
public synchronized void reset(boolean userSwitched) {
223237
if (DEBUG) Log.d(TAG, "reset()");
224238
// User might have switched, check if we need to go back to keyguard
225239
// TODO: It's preferable to stay and show the correct lockscreen or unlock if none
226-
maybeCreateKeyguardLocked(shouldEnableScreenRotation());
240+
maybeCreateKeyguardLocked(shouldEnableScreenRotation(), userSwitched);
227241
}
228242

229243
public synchronized void onScreenTurnedOff() {

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public interface ViewMediatorCallback {
291291
public void onUserSwitched(int userId) {
292292
// Note that the mLockPatternUtils user has already been updated from setCurrentUser.
293293
synchronized (KeyguardViewMediator.this) {
294-
resetStateLocked();
294+
resetStateLocked(true);
295295
}
296296
// We should always go back to the locked state when a user
297297
// switch happens. Is there a more direct way to do this?
@@ -351,7 +351,7 @@ public void onSimStateChanged(IccCardConstants.State simState) {
351351
+ "device isn't provisioned yet.");
352352
doKeyguardLocked();
353353
} else {
354-
resetStateLocked();
354+
resetStateLocked(false);
355355
}
356356
}
357357
}
@@ -364,7 +364,7 @@ public void onSimStateChanged(IccCardConstants.State simState) {
364364
+ "showing; need to show keyguard so user can enter sim pin");
365365
doKeyguardLocked();
366366
} else {
367-
resetStateLocked();
367+
resetStateLocked(false);
368368
}
369369
}
370370
break;
@@ -377,14 +377,14 @@ public void onSimStateChanged(IccCardConstants.State simState) {
377377
} else {
378378
if (DEBUG) Log.d(TAG, "PERM_DISABLED, resetStateLocked to"
379379
+ "show permanently disabled message in lockscreen.");
380-
resetStateLocked();
380+
resetStateLocked(false);
381381
}
382382
}
383383
break;
384384
case READY:
385385
synchronized (this) {
386386
if (isShowing()) {
387-
resetStateLocked();
387+
resetStateLocked(false);
388388
}
389389
}
390390
break;
@@ -530,7 +530,7 @@ public void onScreenTurnedOff(int why) {
530530
}
531531
} else if (mShowing) {
532532
notifyScreenOffLocked();
533-
resetStateLocked();
533+
resetStateLocked(false);
534534
} else if (why == WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT
535535
|| (why == WindowManagerPolicy.OFF_BECAUSE_OF_USER && !lockImmediately)) {
536536
// if the screen turned off because of timeout or the user hit the power button
@@ -644,7 +644,7 @@ public void setKeyguardEnabled(boolean enabled) {
644644
if (DEBUG) Log.d(TAG, "onKeyguardExitResult(false), resetting");
645645
mExitSecureCallback.onKeyguardExitResult(false);
646646
mExitSecureCallback = null;
647-
resetStateLocked();
647+
resetStateLocked(false);
648648
} else {
649649
showLocked();
650650

@@ -805,11 +805,12 @@ private void doKeyguardLocked() {
805805

806806
/**
807807
* Send message to keyguard telling it to reset its state.
808+
* @param userSwitched true if we're resetting state because user switched
808809
* @see #handleReset()
809810
*/
810-
private void resetStateLocked() {
811+
private void resetStateLocked(boolean userSwitched) {
811812
if (DEBUG) Log.d(TAG, "resetStateLocked");
812-
Message msg = mHandler.obtainMessage(RESET);
813+
Message msg = mHandler.obtainMessage(RESET, userSwitched ? 1 : 0, 0);
813814
mHandler.sendMessage(msg);
814815
}
815816

@@ -1046,7 +1047,7 @@ public void handleMessage(Message msg) {
10461047
handleHide();
10471048
return ;
10481049
case RESET:
1049-
handleReset();
1050+
handleReset(msg.arg1 != 0);
10501051
return ;
10511052
case VERIFY_UNLOCK:
10521053
handleVerifyUnlock();
@@ -1289,13 +1290,13 @@ private void handleWakeWhenReady(int keyCode) {
12891290
}
12901291

12911292
/**
1292-
* Handle message sent by {@link #resetStateLocked()}
1293+
* Handle message sent by {@link #resetStateLocked(boolean)}
12931294
* @see #RESET
12941295
*/
1295-
private void handleReset() {
1296+
private void handleReset(boolean userSwitched) {
12961297
synchronized (KeyguardViewMediator.this) {
12971298
if (DEBUG) Log.d(TAG, "handleReset");
1298-
mKeyguardViewManager.reset();
1299+
mKeyguardViewManager.reset(userSwitched);
12991300
}
13001301
}
13011302

0 commit comments

Comments
 (0)