Merge "Fixed cts failure of WindowInsetsControllerTests" into tm-dev

This commit is contained in:
Shawn Lin
2022-04-28 13:11:10 +00:00
committed by Android (Google) Code Review
6 changed files with 39 additions and 42 deletions

View File

@@ -47,6 +47,7 @@ public class InsetsSource implements Parcelable {
private final Rect mFrame; private final Rect mFrame;
private @Nullable Rect mVisibleFrame; private @Nullable Rect mVisibleFrame;
private boolean mVisible; private boolean mVisible;
private boolean mInsetsRoundedCornerFrame;
private final Rect mTmpFrame = new Rect(); private final Rect mTmpFrame = new Rect();
@@ -63,6 +64,7 @@ public class InsetsSource implements Parcelable {
mVisibleFrame = other.mVisibleFrame != null mVisibleFrame = other.mVisibleFrame != null
? new Rect(other.mVisibleFrame) ? new Rect(other.mVisibleFrame)
: null; : null;
mInsetsRoundedCornerFrame = other.mInsetsRoundedCornerFrame;
} }
public void set(InsetsSource other) { public void set(InsetsSource other) {
@@ -71,6 +73,7 @@ public class InsetsSource implements Parcelable {
mVisibleFrame = other.mVisibleFrame != null mVisibleFrame = other.mVisibleFrame != null
? new Rect(other.mVisibleFrame) ? new Rect(other.mVisibleFrame)
: null; : null;
mInsetsRoundedCornerFrame = other.mInsetsRoundedCornerFrame;
} }
public void setFrame(int left, int top, int right, int bottom) { public void setFrame(int left, int top, int right, int bottom) {
@@ -110,6 +113,14 @@ public class InsetsSource implements Parcelable {
return mVisibleFrame == null || !mVisibleFrame.isEmpty(); return mVisibleFrame == null || !mVisibleFrame.isEmpty();
} }
public boolean getInsetsRoundedCornerFrame() {
return mInsetsRoundedCornerFrame;
}
public void setInsetsRoundedCornerFrame(boolean insetsRoundedCornerFrame) {
mInsetsRoundedCornerFrame = insetsRoundedCornerFrame;
}
/** /**
* Calculates the insets this source will cause to a client window. * Calculates the insets this source will cause to a client window.
* *
@@ -225,6 +236,7 @@ public class InsetsSource implements Parcelable {
pw.print(" visibleFrame="); pw.print(mVisibleFrame.toShortString()); pw.print(" visibleFrame="); pw.print(mVisibleFrame.toShortString());
} }
pw.print(" visible="); pw.print(mVisible); pw.print(" visible="); pw.print(mVisible);
pw.print(" insetsRoundedCornerFrame="); pw.print(mInsetsRoundedCornerFrame);
pw.println(); pw.println();
} }
@@ -247,6 +259,7 @@ public class InsetsSource implements Parcelable {
if (mVisible != that.mVisible) return false; if (mVisible != that.mVisible) return false;
if (excludeInvisibleImeFrames && !mVisible && mType == ITYPE_IME) return true; if (excludeInvisibleImeFrames && !mVisible && mType == ITYPE_IME) return true;
if (!Objects.equals(mVisibleFrame, that.mVisibleFrame)) return false; if (!Objects.equals(mVisibleFrame, that.mVisibleFrame)) return false;
if (mInsetsRoundedCornerFrame != that.mInsetsRoundedCornerFrame) return false;
return mFrame.equals(that.mFrame); return mFrame.equals(that.mFrame);
} }
@@ -256,6 +269,7 @@ public class InsetsSource implements Parcelable {
result = 31 * result + mFrame.hashCode(); result = 31 * result + mFrame.hashCode();
result = 31 * result + (mVisibleFrame != null ? mVisibleFrame.hashCode() : 0); result = 31 * result + (mVisibleFrame != null ? mVisibleFrame.hashCode() : 0);
result = 31 * result + (mVisible ? 1 : 0); result = 31 * result + (mVisible ? 1 : 0);
result = 31 * result + (mInsetsRoundedCornerFrame ? 1 : 0);
return result; return result;
} }
@@ -268,6 +282,7 @@ public class InsetsSource implements Parcelable {
mVisibleFrame = null; mVisibleFrame = null;
} }
mVisible = in.readBoolean(); mVisible = in.readBoolean();
mInsetsRoundedCornerFrame = in.readBoolean();
} }
@Override @Override
@@ -286,6 +301,7 @@ public class InsetsSource implements Parcelable {
dest.writeInt(0); dest.writeInt(0);
} }
dest.writeBoolean(mVisible); dest.writeBoolean(mVisible);
dest.writeBoolean(mInsetsRoundedCornerFrame);
} }
@Override @Override
@@ -294,6 +310,7 @@ public class InsetsSource implements Parcelable {
+ "mType=" + InsetsState.typeToString(mType) + "mType=" + InsetsState.typeToString(mType)
+ ", mFrame=" + mFrame.toShortString() + ", mFrame=" + mFrame.toShortString()
+ ", mVisible=" + mVisible + ", mVisible=" + mVisible
+ ", mInsetsRoundedCornerFrame=" + mInsetsRoundedCornerFrame
+ "}"; + "}";
} }

View File

@@ -294,9 +294,16 @@ public class InsetsState implements Parcelable {
return RoundedCorners.NO_ROUNDED_CORNERS; return RoundedCorners.NO_ROUNDED_CORNERS;
} }
// If mRoundedCornerFrame is set, we should calculate the new RoundedCorners based on this // If mRoundedCornerFrame is set, we should calculate the new RoundedCorners based on this
// frame. It's used for split-screen mode and devices with a task bar. // frame.
if (!mRoundedCornerFrame.isEmpty() && !mRoundedCornerFrame.equals(mDisplayFrame)) { final Rect roundedCornerFrame = new Rect(mRoundedCornerFrame);
return mRoundedCorners.insetWithFrame(frame, mRoundedCornerFrame); for (InsetsSource source : mSources) {
if (source != null && source.getInsetsRoundedCornerFrame()) {
final Insets insets = source.calculateInsets(roundedCornerFrame, false);
roundedCornerFrame.inset(insets);
}
}
if (!roundedCornerFrame.isEmpty() && !roundedCornerFrame.equals(mDisplayFrame)) {
return mRoundedCorners.insetWithFrame(frame, roundedCornerFrame);
} }
if (mDisplayFrame.equals(frame)) { if (mDisplayFrame.equals(frame)) {
return mRoundedCorners; return mRoundedCorners;

View File

@@ -300,10 +300,6 @@ public class DisplayPolicy {
// needs to be opaque. // needs to be opaque.
private WindowState mNavBarBackgroundWindow; private WindowState mNavBarBackgroundWindow;
// The window that draws fake rounded corners and should provide insets to calculate the correct
// rounded corner insets.
private WindowState mRoundedCornerWindow;
/** /**
* A collection of {@link AppearanceRegion} to indicate that which region of status bar applies * A collection of {@link AppearanceRegion} to indicate that which region of status bar applies
* which appearance. * which appearance.
@@ -970,16 +966,10 @@ public class DisplayPolicy {
mExtraNavBarAltPosition = getAltBarPosition(attrs); mExtraNavBarAltPosition = getAltBarPosition(attrs);
} }
if (attrs.insetsRoundedCornerFrame) { final InsetsSourceProvider provider = win.getControllableInsetProvider();
// Currently, only support one rounded corner window which is the TaskBar. if (provider != null && provider.getSource().getInsetsRoundedCornerFrame()
if (mRoundedCornerWindow != null && mRoundedCornerWindow != win) { != attrs.insetsRoundedCornerFrame) {
throw new IllegalArgumentException("Found multiple rounded corner window :" provider.getSource().setInsetsRoundedCornerFrame(attrs.insetsRoundedCornerFrame);
+ " current = " + mRoundedCornerWindow
+ " new = " + win);
}
mRoundedCornerWindow = win;
} else if (mRoundedCornerWindow == win) {
mRoundedCornerWindow = null;
} }
} }
@@ -1326,9 +1316,6 @@ public class DisplayPolicy {
if (mLastFocusedWindow == win) { if (mLastFocusedWindow == win) {
mLastFocusedWindow = null; mLastFocusedWindow = null;
} }
if (mRoundedCornerWindow == win) {
mRoundedCornerWindow = null;
}
mInsetsSourceWindowsExceptIme.remove(win); mInsetsSourceWindowsExceptIme.remove(win);
} }
@@ -1360,10 +1347,6 @@ public class DisplayPolicy {
return mNavigationBar != null ? mNavigationBar : mNavigationBarAlt; return mNavigationBar != null ? mNavigationBar : mNavigationBarAlt;
} }
WindowState getRoundedCornerWindow() {
return mRoundedCornerWindow;
}
/** /**
* Control the animation to run when a window's state changes. Return a positive number to * Control the animation to run when a window's state changes. Return a positive number to
* force the animation to a specific resource ID, {@link #ANIMATION_STYLEABLE} to use the * force the animation to a specific resource ID, {@link #ANIMATION_STYLEABLE} to use the

View File

@@ -46,7 +46,6 @@ import android.annotation.Nullable;
import android.app.ActivityTaskManager; import android.app.ActivityTaskManager;
import android.app.StatusBarManager; import android.app.StatusBarManager;
import android.app.WindowConfiguration; import android.app.WindowConfiguration;
import android.graphics.Insets;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.IntArray; import android.util.IntArray;
@@ -461,22 +460,10 @@ class InsetsPolicy {
private InsetsState adjustInsetsForRoundedCorners(WindowState w, InsetsState originalState, private InsetsState adjustInsetsForRoundedCorners(WindowState w, InsetsState originalState,
boolean copyState) { boolean copyState) {
final WindowState roundedCornerWindow = mPolicy.getRoundedCornerWindow();
final Task task = w.getTask(); final Task task = w.getTask();
if (task != null && !task.getWindowConfiguration().tasksAreFloating() if (task != null && !task.getWindowConfiguration().tasksAreFloating()) {
&& (roundedCornerWindow != null || task.inSplitScreen())) { // Use task bounds to calculating rounded corners if the task is not floating.
// Instead of using display frame to calculating rounded corner, for the fake rounded
// corners drawn by divider bar or task bar, we need to re-calculate rounded corners
// based on task bounds and if the task bounds is intersected with task bar, we should
// exclude the intersected part.
final Rect roundedCornerFrame = new Rect(task.getBounds()); final Rect roundedCornerFrame = new Rect(task.getBounds());
if (roundedCornerWindow != null
&& roundedCornerWindow.getControllableInsetProvider() != null) {
final InsetsSource source =
roundedCornerWindow.getControllableInsetProvider().getSource();
final Insets insets = source.calculateInsets(roundedCornerFrame, false);
roundedCornerFrame.inset(insets);
}
final InsetsState state = copyState ? new InsetsState(originalState) : originalState; final InsetsState state = copyState ? new InsetsState(originalState) : originalState;
state.setRoundedCornerFrame(roundedCornerFrame); state.setRoundedCornerFrame(roundedCornerFrame);
return state; return state;

View File

@@ -170,6 +170,7 @@ abstract class InsetsSourceProvider {
if (windowContainer == null) { if (windowContainer == null) {
setServerVisible(false); setServerVisible(false);
mSource.setVisibleFrame(null); mSource.setVisibleFrame(null);
mSource.setInsetsRoundedCornerFrame(false);
mSourceFrame.setEmpty(); mSourceFrame.setEmpty();
} else { } else {
mWindowContainer.getProvidedInsetsSources().put(mSource.getType(), mSource); mWindowContainer.getProvidedInsetsSources().put(mSource.getType(), mSource);

View File

@@ -3141,7 +3141,7 @@ public class ActivityRecordTests extends WindowTestsBase {
final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
InsetsSource imeSource = new InsetsSource(ITYPE_IME); InsetsSource imeSource = new InsetsSource(ITYPE_IME);
app.getInsetsState().addSource(imeSource); app.mAboveInsetsState.addSource(imeSource);
mDisplayContent.setImeLayeringTarget(app); mDisplayContent.setImeLayeringTarget(app);
mDisplayContent.updateImeInputAndControlTarget(app); mDisplayContent.updateImeInputAndControlTarget(app);
@@ -3158,10 +3158,12 @@ public class ActivityRecordTests extends WindowTestsBase {
// Simulate app re-start input or turning screen off/on then unlocked by un-secure // Simulate app re-start input or turning screen off/on then unlocked by un-secure
// keyguard to back to the app, expect IME insets is not frozen // keyguard to back to the app, expect IME insets is not frozen
mDisplayContent.updateImeInputAndControlTarget(app); mDisplayContent.updateImeInputAndControlTarget(app);
app.mActivityRecord.commitVisibility(true, false);
assertFalse(app.mActivityRecord.mImeInsetsFrozenUntilStartInput); assertFalse(app.mActivityRecord.mImeInsetsFrozenUntilStartInput);
imeSource.setVisible(true);
imeSource.setFrame(new Rect(100, 400, 500, 500)); imeSource.setFrame(new Rect(100, 400, 500, 500));
app.getInsetsState().addSource(imeSource); app.mAboveInsetsState.addSource(imeSource);
app.getInsetsState().setSourceVisible(ITYPE_IME, true);
// Verify when IME is visible and the app can receive the right IME insets from policy. // Verify when IME is visible and the app can receive the right IME insets from policy.
makeWindowVisibleAndDrawn(app, mImeWindow); makeWindowVisibleAndDrawn(app, mImeWindow);