Ensure bouncer in correct position on swipe. Remove orientationlistener.
This adds a hook to onLayout to move the bouncer to the correct screen side on large format devices. KeyguardBouncer already calls updateLayoutForSecurityMode() when the security mode is created, but this can happen before the bouncer has actually been attached to the screen (hence width = 0, so the bouncer gets left-aligned). It's also done in onResume(), but this is only called when the bouncer is at the correct place after swipe (hence causing the "jump" when swiping up). Also, removes orientationlistener from KeyguardBouncer, and replaces it with a proxied "updateResources" call. I messed up; I thought that orientationlistener worked like deviceorientationlistener, which notifies on screen rotation. Instead, it notifies on _every_ angle change, which would have led to a lot of layout passes as it'd update the bouncer gravity whenever the device moved. Oops. Test: atest SystemUITests: com.android.keyguard.KeyguardSecurityContainerControllerTest Bug: 177303121 Change-Id: I6d68e553c3114e043bcc126ba7b6910f98ce6694
This commit is contained in:
@@ -487,5 +487,9 @@ public class KeyguardHostViewController extends ViewController<KeyguardHostView>
|
||||
mView.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
|
||||
if (mKeyguardSecurityContainerController != null) {
|
||||
mKeyguardSecurityContainerController.updateResources();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import android.util.MathUtils;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.OrientationEventListener;
|
||||
import android.view.VelocityTracker;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
@@ -107,7 +106,6 @@ public class KeyguardSecurityContainer extends FrameLayout {
|
||||
private boolean mOneHandedMode = false;
|
||||
private SecurityMode mSecurityMode = SecurityMode.Invalid;
|
||||
private ViewPropertyAnimator mRunningOneHandedAnimator;
|
||||
private final OrientationEventListener mOrientationEventListener;
|
||||
|
||||
private final WindowInsetsAnimation.Callback mWindowInsetsAnimationCallback =
|
||||
new WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) {
|
||||
@@ -247,13 +245,6 @@ public class KeyguardSecurityContainer extends FrameLayout {
|
||||
super(context, attrs, defStyle);
|
||||
mSpringAnimation = new SpringAnimation(this, DynamicAnimation.Y);
|
||||
mViewConfiguration = ViewConfiguration.get(context);
|
||||
|
||||
mOrientationEventListener = new OrientationEventListener(context) {
|
||||
@Override
|
||||
public void onOrientationChanged(int orientation) {
|
||||
updateLayoutForSecurityMode(mSecurityMode);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void onResume(SecurityMode securityMode, boolean faceAuthEnabled) {
|
||||
@@ -262,7 +253,6 @@ public class KeyguardSecurityContainer extends FrameLayout {
|
||||
updateBiometricRetry(securityMode, faceAuthEnabled);
|
||||
|
||||
updateLayoutForSecurityMode(securityMode);
|
||||
mOrientationEventListener.enable();
|
||||
}
|
||||
|
||||
void updateLayoutForSecurityMode(SecurityMode securityMode) {
|
||||
@@ -385,7 +375,6 @@ public class KeyguardSecurityContainer extends FrameLayout {
|
||||
mAlertDialog = null;
|
||||
}
|
||||
mSecurityViewFlipper.setWindowInsetsAnimationCallback(null);
|
||||
mOrientationEventListener.disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -663,6 +652,15 @@ public class KeyguardSecurityContainer extends FrameLayout {
|
||||
childState << MEASURED_HEIGHT_STATE_SHIFT));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
|
||||
// After a layout pass, we need to re-place the inner bouncer, as our bounds may have
|
||||
// changed.
|
||||
updateSecurityViewLocation(/* animate= */false);
|
||||
}
|
||||
|
||||
void showAlmostAtWipeDialog(int attempts, int remaining, int userType) {
|
||||
String message = null;
|
||||
switch (userType) {
|
||||
|
||||
@@ -29,6 +29,7 @@ import static com.android.systemui.DejankUtils.whitelistIpcs;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Configuration;
|
||||
import android.metrics.LogMaker;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
@@ -74,6 +75,8 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
|
||||
private final SecurityCallback mSecurityCallback;
|
||||
private final ConfigurationController mConfigurationController;
|
||||
|
||||
private int mLastOrientation = Configuration.ORIENTATION_UNDEFINED;
|
||||
|
||||
private SecurityMode mCurrentSecurityMode = SecurityMode.Invalid;
|
||||
|
||||
private final Gefingerpoken mGlobalTouchListener = new Gefingerpoken() {
|
||||
@@ -212,6 +215,7 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
|
||||
mAdminSecondaryLockScreenController = adminSecondaryLockScreenControllerFactory.create(
|
||||
mKeyguardSecurityCallback);
|
||||
mConfigurationController = configurationController;
|
||||
mLastOrientation = getResources().getConfiguration().orientation;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -498,6 +502,19 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
|
||||
return getCurrentSecurityController();
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply keyguard configuration from the currently active resources. This can be called when the
|
||||
* device configuration changes, to re-apply some resources that are qualified on the device
|
||||
* configuration.
|
||||
*/
|
||||
public void updateResources() {
|
||||
int newOrientation = getResources().getConfiguration().orientation;
|
||||
if (newOrientation != mLastOrientation) {
|
||||
mLastOrientation = newOrientation;
|
||||
mView.updateLayoutForSecurityMode(mCurrentSecurityMode);
|
||||
}
|
||||
}
|
||||
|
||||
static class Factory {
|
||||
|
||||
private final KeyguardSecurityContainer mView;
|
||||
|
||||
@@ -25,9 +25,11 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
@@ -96,6 +98,9 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase {
|
||||
private ConfigurationController mConfigurationController;
|
||||
@Mock
|
||||
private EmergencyButtonController mEmergencyButtonController;
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
private Configuration mConfiguration;
|
||||
|
||||
private KeyguardSecurityContainerController mKeyguardSecurityContainerController;
|
||||
private KeyguardPasswordViewController mKeyguardPasswordViewController;
|
||||
@@ -103,6 +108,11 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
mConfiguration = new Configuration();
|
||||
mConfiguration.setToDefaults(); // Defaults to ORIENTATION_UNDEFINED.
|
||||
|
||||
when(mResources.getConfiguration()).thenReturn(mConfiguration);
|
||||
when(mView.getResources()).thenReturn(mResources);
|
||||
when(mAdminSecondaryLockScreenControllerFactory.create(any(KeyguardSecurityCallback.class)))
|
||||
.thenReturn(mAdminSecondaryLockScreenController);
|
||||
when(mSecurityViewFlipper.getWindowInsetsController()).thenReturn(mWindowInsetsController);
|
||||
@@ -154,4 +164,17 @@ public class KeyguardSecurityContainerControllerTest extends SysuiTestCase {
|
||||
verify(mWindowInsetsController).controlWindowInsetsAnimation(
|
||||
eq(ime()), anyLong(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResourcesUpdate_callsThroughOnRotationChange() {
|
||||
// Rotation is the same, shouldn't cause an update
|
||||
mKeyguardSecurityContainerController.updateResources();
|
||||
verify(mView, times(0)).updateLayoutForSecurityMode(any());
|
||||
|
||||
// Update rotation. Should trigger update
|
||||
mConfiguration.orientation = Configuration.ORIENTATION_LANDSCAPE;
|
||||
|
||||
mKeyguardSecurityContainerController.updateResources();
|
||||
verify(mView, times(1)).updateLayoutForSecurityMode(any());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user