Merge "Fix test failure in MixedDeviceOwnerTest#testSecondaryLockscreen." into sc-dev

This commit is contained in:
TreeHugger Robot
2021-02-04 15:17:17 +00:00
committed by Android (Google) Code Review

View File

@@ -297,7 +297,7 @@ public class KeyguardSecurityContainer extends FrameLayout {
} }
private void updateSecurityViewGravity() { private void updateSecurityViewGravity() {
View securityView = getChildAt(0); View securityView = findKeyguardSecurityView();
if (securityView == null) { if (securityView == null) {
return; return;
@@ -320,7 +320,7 @@ public class KeyguardSecurityContainer extends FrameLayout {
* by the security view . * by the security view .
*/ */
private void updateSecurityViewLocation(boolean animate) { private void updateSecurityViewLocation(boolean animate) {
View securityView = getChildAt(0); View securityView = findKeyguardSecurityView();
if (securityView == null) { if (securityView == null) {
return; return;
@@ -355,6 +355,23 @@ public class KeyguardSecurityContainer extends FrameLayout {
} }
} }
@Nullable
private KeyguardSecurityViewFlipper findKeyguardSecurityView() {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
if (isKeyguardSecurityView(child)) {
return (KeyguardSecurityViewFlipper) child;
}
}
return null;
}
private boolean isKeyguardSecurityView(View view) {
return view instanceof KeyguardSecurityViewFlipper;
}
public void onPause() { public void onPause() {
if (mAlertDialog != null) { if (mAlertDialog != null) {
mAlertDialog.dismiss(); mAlertDialog.dismiss();
@@ -640,39 +657,30 @@ public class KeyguardSecurityContainer extends FrameLayout {
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// This is a little hacky, but this element only ever has one wrap_content child, and is
// itself set to match_parent, so we can take a couple of shortcuts compared to
// FrameLayout#onMeasure
int maxHeight = 0; int maxHeight = 0;
int maxWidth = 0; int maxWidth = 0;
int childState = 0; int childState = 0;
int count = getChildCount();
int halfWidthMeasureSpec = MeasureSpec.makeMeasureSpec( int halfWidthMeasureSpec = MeasureSpec.makeMeasureSpec(
MeasureSpec.getSize(widthMeasureSpec) / 2, MeasureSpec.getSize(widthMeasureSpec) / 2,
MeasureSpec.getMode(widthMeasureSpec)); MeasureSpec.getMode(widthMeasureSpec));
if (count > 1) { for (int i = 0; i < getChildCount(); i++) {
throw new IllegalStateException("KeyguardSecurityContainer should only have one child"); final View view = getChildAt(i);
} if (view.getVisibility() != GONE) {
if (mOneHandedMode && isKeyguardSecurityView(view)) {
if (count > 0) { measureChildWithMargins(view, halfWidthMeasureSpec, 0,
final View securityView = getChildAt(0);
if (securityView.getVisibility() != GONE) {
if (mOneHandedMode) {
measureChildWithMargins(securityView, halfWidthMeasureSpec, 0,
heightMeasureSpec, 0); heightMeasureSpec, 0);
} else { } else {
measureChildWithMargins(securityView, widthMeasureSpec, 0, measureChildWithMargins(view, widthMeasureSpec, 0,
heightMeasureSpec, 0); heightMeasureSpec, 0);
} }
final LayoutParams lp = (LayoutParams) securityView.getLayoutParams(); final LayoutParams lp = (LayoutParams) view.getLayoutParams();
maxWidth = Math.max(maxWidth, maxWidth = Math.max(maxWidth,
securityView.getMeasuredWidth() + lp.leftMargin + lp.rightMargin); view.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
maxHeight = Math.max(maxHeight, maxHeight = Math.max(maxHeight,
securityView.getMeasuredHeight() + lp.topMargin + lp.bottomMargin); view.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
childState = combineMeasuredStates(childState, securityView.getMeasuredState()); childState = combineMeasuredStates(childState, view.getMeasuredState());
} }
} }