summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/keyguard/KeyguardSecurityContainerTest.java18
-rw-r--r--packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java26
2 files changed, 39 insertions, 5 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/keyguard/KeyguardSecurityContainerTest.java b/packages/SystemUI/multivalentTests/src/com/android/keyguard/KeyguardSecurityContainerTest.java
index 94d3b2ccc9e5..176824fd4c5d 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/keyguard/KeyguardSecurityContainerTest.java
+++ b/packages/SystemUI/multivalentTests/src/com/android/keyguard/KeyguardSecurityContainerTest.java
@@ -61,6 +61,7 @@ import com.android.systemui.classifier.FalsingA11yDelegate;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.policy.UserSwitcherController;
+import com.android.systemui.statusbar.policy.UserSwitcherController.UserSwitchCallback;
import com.android.systemui.user.data.source.UserRecord;
import com.android.systemui.util.concurrency.FakeExecutor;
import com.android.systemui.util.settings.GlobalSettings;
@@ -70,6 +71,8 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
@@ -96,6 +99,9 @@ public class KeyguardSecurityContainerTest extends SysuiTestCase {
private UserSwitcherController mUserSwitcherController;
@Mock
private FalsingA11yDelegate mFalsingA11yDelegate;
+ @Captor
+ private ArgumentCaptor<UserSwitchCallback> mUserSwitchCallbackCaptor =
+ ArgumentCaptor.forClass(UserSwitchCallback.class);
private KeyguardSecurityContainer mKeyguardSecurityContainer;
private FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock());
@@ -360,6 +366,18 @@ public class KeyguardSecurityContainerTest extends SysuiTestCase {
}
@Test
+ public void goingOutOfUserSwitcherRemovesCallback() {
+ // WHEN UserSwitcherViewMode is initialized
+ setupUserSwitcher();
+ verify(mUserSwitcherController).addUserSwitchCallback(mUserSwitchCallbackCaptor.capture());
+
+ // Back to default mode, as SIM PIN would be
+ initMode(MODE_DEFAULT);
+ verify(mUserSwitcherController).removeUserSwitchCallback(
+ mUserSwitchCallbackCaptor.getValue());
+ }
+
+ @Test
public void testOnDensityOrFontScaleChanged() {
setupUserSwitcher();
View oldUserSwitcher = mKeyguardSecurityContainer.findViewById(
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
index f05cbf422707..2d27f1c0ca73 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
@@ -1067,6 +1067,8 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
@Override
public void onDestroy() {
+ mUserSwitcherController.removeUserSwitchCallback(mUserSwitchCallback);
+
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(mView);
constraintSet.clear(mUserSwitcherViewGroup.getId());
@@ -1075,6 +1077,8 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
mView.removeView(mUserSwitcherViewGroup);
mView.removeView(mUserSwitcher);
+ mUserSwitcher = null;
+ mUserSwitcherViewGroup = null;
}
private void findLargeUserIcon(int userId, Consumer<Drawable> consumer) {
@@ -1102,6 +1106,10 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
return;
}
+ if (mUserSwitcherViewGroup == null) {
+ return;
+ }
+
mUserSwitcherViewGroup.setAlpha(0f);
ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
int yTrans = mView.getResources().getDimensionPixelSize(R.dimen.pin_view_trans_y_entry);
@@ -1110,14 +1118,18 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
- mUserSwitcherViewGroup.setAlpha(1f);
- mUserSwitcherViewGroup.setTranslationY(0f);
+ if (mUserSwitcherViewGroup != null) {
+ mUserSwitcherViewGroup.setAlpha(1f);
+ mUserSwitcherViewGroup.setTranslationY(0f);
+ }
}
});
animator.addUpdateListener(animation -> {
- float value = (float) animation.getAnimatedValue();
- mUserSwitcherViewGroup.setAlpha(value);
- mUserSwitcherViewGroup.setTranslationY(yTrans - yTrans * value);
+ if (mUserSwitcherViewGroup != null) {
+ float value = (float) animation.getAnimatedValue();
+ mUserSwitcherViewGroup.setAlpha(value);
+ mUserSwitcherViewGroup.setTranslationY(yTrans - yTrans * value);
+ }
});
animator.start();
}
@@ -1148,6 +1160,10 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
Log.e(TAG, "Current user in user switcher is null.");
return;
}
+ if (mUserSwitcher == null) {
+ Log.w(TAG, "User switcher is not inflated, cannot setupUserSwitcher");
+ return;
+ }
final String currentUserName = mUserSwitcherController.getCurrentUserName();
findLargeUserIcon(currentUser.info.id,
(Drawable userIcon) -> {