Add public type and ID to InsetsSourceControl
This CL replaces the InternalInsetsType with the InsetsType and the ID
in InsetsSourceControl. The is a step to remove InternalInsetsType like
we did to InsetsSource.
Bug: 234093736
Test: atest ImeInsetsSourceConsumerTest InsetsAnimationControlImplTest
InsetsControllerTest InsetsSourceConsumerTest DisplayImeControllerTest
InsetsPolicyTest
Change-Id: I01aa4930cccf295abdc2efd9f762d035d03748ce
This commit is contained in:
@@ -217,7 +217,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
|
||||
public void updateSurfacePosition(SparseArray<InsetsSourceControl> controls) {
|
||||
for (int i = controls.size() - 1; i >= 0; i--) {
|
||||
final InsetsSourceControl control = controls.valueAt(i);
|
||||
final InsetsSourceControl c = mControls.get(control.getType());
|
||||
final InsetsSourceControl c = mControls.get(control.getId());
|
||||
if (c == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -395,7 +395,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
|
||||
// control may be null if it got revoked.
|
||||
continue;
|
||||
}
|
||||
state.getSource(control.getType()).setVisible(shown);
|
||||
state.getSource(control.getId()).setVisible(shown);
|
||||
}
|
||||
return getInsetsFromState(state, frame, typeSideMap);
|
||||
}
|
||||
@@ -413,7 +413,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
|
||||
// control may be null if it got revoked.
|
||||
continue;
|
||||
}
|
||||
if (state == null || state.getSource(control.getType()).isVisible()) {
|
||||
if (state == null || state.getSource(control.getId()).isVisible()) {
|
||||
insets = Insets.max(insets, control.getInsetsHint());
|
||||
}
|
||||
}
|
||||
@@ -443,7 +443,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
|
||||
// TODO: Implement behavior when inset spans over multiple types
|
||||
for (int i = controls.size() - 1; i >= 0; i--) {
|
||||
final InsetsSourceControl control = controls.valueAt(i);
|
||||
final InsetsSource source = mInitialInsetsState.getSource(control.getType());
|
||||
final InsetsSource source = mInitialInsetsState.getSource(control.getId());
|
||||
final SurfaceControl leash = control.getLeash();
|
||||
|
||||
mTmpMatrix.setTranslate(control.getSurfacePosition().x, control.getSurfacePosition().y);
|
||||
@@ -521,7 +521,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
|
||||
continue;
|
||||
}
|
||||
@InternalInsetsSide int side = InsetsState.getInsetSide(control.getInsetsHint());
|
||||
if (side == ISIDE_FLOATING && control.getType() == ITYPE_IME) {
|
||||
if (side == ISIDE_FLOATING && control.getType() == WindowInsets.Type.ime()) {
|
||||
side = ISIDE_BOTTOM;
|
||||
}
|
||||
sideControlsMap.add(side, control);
|
||||
|
||||
@@ -888,7 +888,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
|
||||
for (InsetsSourceControl activeControl : activeControls) {
|
||||
if (activeControl != null) {
|
||||
// TODO(b/122982984): Figure out why it can be null.
|
||||
mTmpControlArray.put(activeControl.getType(), activeControl);
|
||||
mTmpControlArray.put(activeControl.getId(), activeControl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -910,10 +910,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
|
||||
// Ensure to create source consumers if not available yet.
|
||||
for (int i = mTmpControlArray.size() - 1; i >= 0; i--) {
|
||||
final InsetsSourceControl control = mTmpControlArray.valueAt(i);
|
||||
final @InternalInsetsType int type = control.getType();
|
||||
final InsetsSourceConsumer consumer = getSourceConsumer(type);
|
||||
final InsetsSourceConsumer consumer = getSourceConsumer(control.getId());
|
||||
consumer.setControl(control, showTypes, hideTypes);
|
||||
controllableTypes |= InsetsState.toPublicType(type);
|
||||
controllableTypes |= control.getType();
|
||||
}
|
||||
|
||||
if (mTmpControlArray.size() > 0) {
|
||||
@@ -1265,7 +1264,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
|
||||
}
|
||||
final InsetsSourceControl control = consumer.getControl();
|
||||
if (control != null && control.getLeash() != null) {
|
||||
controls.put(control.getType(), new InsetsSourceControl(control));
|
||||
controls.put(control.getId(), new InsetsSourceControl(control));
|
||||
typesReady |= consumer.getType();
|
||||
} else if (animationType == ANIMATION_TYPE_SHOW) {
|
||||
if (DEBUG) Log.d(TAG, "collectSourceControls no control for show(). fromIme: "
|
||||
@@ -1422,14 +1421,14 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public @NonNull InsetsSourceConsumer getSourceConsumer(@InternalInsetsType int type) {
|
||||
InsetsSourceConsumer controller = mSourceConsumers.get(type);
|
||||
if (controller != null) {
|
||||
return controller;
|
||||
public @NonNull InsetsSourceConsumer getSourceConsumer(int id) {
|
||||
InsetsSourceConsumer consumer = mSourceConsumers.get(id);
|
||||
if (consumer != null) {
|
||||
return consumer;
|
||||
}
|
||||
controller = mConsumerCreator.apply(this, type);
|
||||
mSourceConsumers.put(type, controller);
|
||||
return controller;
|
||||
consumer = mConsumerCreator.apply(this, id);
|
||||
mSourceConsumers.put(id, consumer);
|
||||
return consumer;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
||||
@@ -132,7 +132,7 @@ public class InsetsSourceConsumer {
|
||||
mSourceControl = control;
|
||||
if (control != null) {
|
||||
if (DEBUG) Log.d(TAG, String.format("setControl -> %s on %s",
|
||||
InsetsState.typeToString(control.getType()),
|
||||
WindowInsets.Type.toString(control.getType()),
|
||||
mController.getHost().getRootViewTitle()));
|
||||
}
|
||||
if (mSourceControl == null) {
|
||||
|
||||
@@ -22,13 +22,14 @@ import static android.view.InsetsSourceControlProto.LEASH;
|
||||
import static android.view.InsetsSourceControlProto.POSITION;
|
||||
import static android.view.InsetsSourceControlProto.TYPE;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.graphics.Insets;
|
||||
import android.graphics.Point;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.proto.ProtoOutputStream;
|
||||
import android.view.InsetsState.InternalInsetsType;
|
||||
import android.view.WindowInsets.Type.InsetsType;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Objects;
|
||||
@@ -40,7 +41,8 @@ import java.util.function.Consumer;
|
||||
*/
|
||||
public class InsetsSourceControl implements Parcelable {
|
||||
|
||||
private final @InternalInsetsType int mType;
|
||||
private final int mId;
|
||||
private final @InsetsType int mType;
|
||||
private final @Nullable SurfaceControl mLeash;
|
||||
private final boolean mInitiallyVisible;
|
||||
private final Point mSurfacePosition;
|
||||
@@ -52,8 +54,9 @@ public class InsetsSourceControl implements Parcelable {
|
||||
private boolean mSkipAnimationOnce;
|
||||
private int mParcelableFlags;
|
||||
|
||||
public InsetsSourceControl(@InternalInsetsType int type, @Nullable SurfaceControl leash,
|
||||
public InsetsSourceControl(int id, @InsetsType int type, @Nullable SurfaceControl leash,
|
||||
boolean initiallyVisible, Point surfacePosition, Insets insetsHint) {
|
||||
mId = id;
|
||||
mType = type;
|
||||
mLeash = leash;
|
||||
mInitiallyVisible = initiallyVisible;
|
||||
@@ -62,6 +65,7 @@ public class InsetsSourceControl implements Parcelable {
|
||||
}
|
||||
|
||||
public InsetsSourceControl(InsetsSourceControl other) {
|
||||
mId = other.mId;
|
||||
mType = other.mType;
|
||||
if (other.mLeash != null) {
|
||||
mLeash = new SurfaceControl(other.mLeash, "InsetsSourceControl");
|
||||
@@ -75,6 +79,7 @@ public class InsetsSourceControl implements Parcelable {
|
||||
}
|
||||
|
||||
public InsetsSourceControl(Parcel in) {
|
||||
mId = in.readInt();
|
||||
mType = in.readInt();
|
||||
mLeash = in.readTypedObject(SurfaceControl.CREATOR);
|
||||
mInitiallyVisible = in.readBoolean();
|
||||
@@ -83,6 +88,10 @@ public class InsetsSourceControl implements Parcelable {
|
||||
mSkipAnimationOnce = in.readBoolean();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return mType;
|
||||
}
|
||||
@@ -153,6 +162,7 @@ public class InsetsSourceControl implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(mId);
|
||||
dest.writeInt(mType);
|
||||
dest.writeTypedObject(mLeash, mParcelableFlags);
|
||||
dest.writeBoolean(mInitiallyVisible);
|
||||
@@ -177,7 +187,8 @@ public class InsetsSourceControl implements Parcelable {
|
||||
}
|
||||
final InsetsSourceControl that = (InsetsSourceControl) o;
|
||||
final SurfaceControl thatLeash = that.mLeash;
|
||||
return mType == that.mType
|
||||
return mId == that.mId
|
||||
&& mType == that.mType
|
||||
&& ((mLeash == thatLeash)
|
||||
|| (mLeash != null && thatLeash != null && mLeash.isSameSurface(thatLeash)))
|
||||
&& mInitiallyVisible == that.mInitiallyVisible
|
||||
@@ -188,22 +199,26 @@ public class InsetsSourceControl implements Parcelable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(mType, mLeash, mInitiallyVisible, mSurfacePosition, mInsetsHint,
|
||||
return Objects.hash(mId, mType, mLeash, mInitiallyVisible, mSurfacePosition, mInsetsHint,
|
||||
mSkipAnimationOnce);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "InsetsSourceControl: {"
|
||||
+ "type=" + InsetsState.typeToString(mType)
|
||||
+ ", mSurfacePosition=" + mSurfacePosition
|
||||
+ ", mInsetsHint=" + mInsetsHint
|
||||
+ "mId=" + mId
|
||||
+ " mType=" + WindowInsets.Type.toString(mType)
|
||||
+ (mInitiallyVisible ? " initiallyVisible" : "")
|
||||
+ " mSurfacePosition=" + mSurfacePosition
|
||||
+ " mInsetsHint=" + mInsetsHint
|
||||
+ (mSkipAnimationOnce ? " skipAnimationOnce" : "")
|
||||
+ "}";
|
||||
}
|
||||
|
||||
public void dump(String prefix, PrintWriter pw) {
|
||||
pw.print(prefix);
|
||||
pw.print("InsetsSourceControl type="); pw.print(InsetsState.typeToString(mType));
|
||||
pw.print("InsetsSourceControl mId="); pw.print(mId);
|
||||
pw.print(" mType="); pw.print(WindowInsets.Type.toString(mType));
|
||||
pw.print(" mLeash="); pw.print(mLeash);
|
||||
pw.print(" mInitiallyVisible="); pw.print(mInitiallyVisible);
|
||||
pw.print(" mSurfacePosition="); pw.print(mSurfacePosition);
|
||||
@@ -212,8 +227,7 @@ public class InsetsSourceControl implements Parcelable {
|
||||
pw.println();
|
||||
}
|
||||
|
||||
public static final @android.annotation.NonNull Creator<InsetsSourceControl> CREATOR
|
||||
= new Creator<InsetsSourceControl>() {
|
||||
public static final @NonNull Creator<InsetsSourceControl> CREATOR = new Creator<>() {
|
||||
public InsetsSourceControl createFromParcel(Parcel in) {
|
||||
return new InsetsSourceControl(in);
|
||||
}
|
||||
@@ -231,7 +245,7 @@ public class InsetsSourceControl implements Parcelable {
|
||||
*/
|
||||
public void dumpDebug(ProtoOutputStream proto, long fieldId) {
|
||||
final long token = proto.start(fieldId);
|
||||
proto.write(TYPE, InsetsState.typeToString(mType));
|
||||
proto.write(TYPE, WindowInsets.Type.toString(mType));
|
||||
|
||||
final long surfaceToken = proto.start(POSITION);
|
||||
proto.write(X, mSurfacePosition.x);
|
||||
|
||||
@@ -92,8 +92,8 @@ public class ImeInsetsSourceConsumerTest {
|
||||
|
||||
@Test
|
||||
public void testImeVisibility() {
|
||||
final InsetsSourceControl ime =
|
||||
new InsetsSourceControl(ITYPE_IME, mLeash, false, new Point(), Insets.NONE);
|
||||
final InsetsSourceControl ime = new InsetsSourceControl(ITYPE_IME, WindowInsets.Type.ime(),
|
||||
mLeash, false, new Point(), Insets.NONE);
|
||||
mController.onControlsChanged(new InsetsSourceControl[] { ime });
|
||||
|
||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
||||
@@ -121,8 +121,8 @@ public class ImeInsetsSourceConsumerTest {
|
||||
mController.show(WindowInsets.Type.ime(), true /* fromIme */, null /* statsToken */);
|
||||
|
||||
// set control and verify visibility is applied.
|
||||
InsetsSourceControl control =
|
||||
new InsetsSourceControl(ITYPE_IME, mLeash, false, new Point(), Insets.NONE);
|
||||
InsetsSourceControl control = new InsetsSourceControl(ITYPE_IME,
|
||||
WindowInsets.Type.ime(), mLeash, false, new Point(), Insets.NONE);
|
||||
mController.onControlsChanged(new InsetsSourceControl[] { control });
|
||||
// IME show animation should be triggered when control becomes available.
|
||||
verify(mController).applyAnimation(
|
||||
@@ -161,8 +161,8 @@ public class ImeInsetsSourceConsumerTest {
|
||||
}
|
||||
|
||||
// set control and verify visibility is applied.
|
||||
InsetsSourceControl control = Mockito.spy(
|
||||
new InsetsSourceControl(ITYPE_IME, mLeash, false, new Point(), Insets.NONE));
|
||||
InsetsSourceControl control = Mockito.spy(new InsetsSourceControl(ITYPE_IME,
|
||||
WindowInsets.Type.ime(), mLeash, false, new Point(), Insets.NONE));
|
||||
// Simulate IME source control set this flag when the target has starting window.
|
||||
control.setSkipAnimationOnce(true);
|
||||
|
||||
@@ -173,7 +173,7 @@ public class ImeInsetsSourceConsumerTest {
|
||||
verify(control).getAndClearSkipAnimationOnce();
|
||||
verify(mController).applyAnimation(eq(WindowInsets.Type.ime()),
|
||||
eq(true) /* show */, eq(false) /* fromIme */,
|
||||
eq(expectSkipAnim) /* skipAnim */, null /* statsToken */);
|
||||
eq(expectSkipAnim) /* skipAnim */, eq(null) /* statsToken */);
|
||||
}
|
||||
|
||||
// If previously hasViewFocus is false, verify when requesting the IME visible next
|
||||
@@ -187,7 +187,7 @@ public class ImeInsetsSourceConsumerTest {
|
||||
verify(control).getAndClearSkipAnimationOnce();
|
||||
verify(mController).applyAnimation(eq(WindowInsets.Type.ime()),
|
||||
eq(true) /* show */, eq(true) /* fromIme */,
|
||||
eq(false) /* skipAnim */, null /* statsToken */);
|
||||
eq(false) /* skipAnim */, eq(null) /* statsToken */);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class InsetsAnimationControlImplTest {
|
||||
private InsetsAnimationControlImpl mController;
|
||||
|
||||
private SurfaceSession mSession = new SurfaceSession();
|
||||
private SurfaceControl mTopLeash;
|
||||
private SurfaceControl mStatusLeash;
|
||||
private SurfaceControl mNavLeash;
|
||||
private InsetsState mInsetsState;
|
||||
|
||||
@@ -80,7 +80,7 @@ public class InsetsAnimationControlImplTest {
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mTopLeash = new SurfaceControl.Builder(mSession)
|
||||
mStatusLeash = new SurfaceControl.Builder(mSession)
|
||||
.setName("testSurface")
|
||||
.build();
|
||||
mNavLeash = new SurfaceControl.Builder(mSession)
|
||||
@@ -92,15 +92,16 @@ public class InsetsAnimationControlImplTest {
|
||||
InsetsSourceConsumer topConsumer = new InsetsSourceConsumer(ITYPE_STATUS_BAR, mInsetsState,
|
||||
() -> mMockTransaction, mMockController);
|
||||
topConsumer.setControl(
|
||||
new InsetsSourceControl(
|
||||
ITYPE_STATUS_BAR, mTopLeash, true, new Point(0, 0),
|
||||
Insets.of(0, 100, 0, 0)),
|
||||
new InsetsSourceControl(ITYPE_STATUS_BAR, WindowInsets.Type.statusBars(),
|
||||
mStatusLeash, true, new Point(0, 0), Insets.of(0, 100, 0, 0)),
|
||||
new int[1], new int[1]);
|
||||
|
||||
InsetsSourceConsumer navConsumer = new InsetsSourceConsumer(ITYPE_NAVIGATION_BAR,
|
||||
mInsetsState, () -> mMockTransaction, mMockController);
|
||||
navConsumer.setControl(new InsetsSourceControl(ITYPE_NAVIGATION_BAR, mNavLeash, true,
|
||||
new Point(400, 0), Insets.of(0, 0, 100, 0)), new int[1], new int[1]);
|
||||
navConsumer.setControl(
|
||||
new InsetsSourceControl(ITYPE_NAVIGATION_BAR, WindowInsets.Type.navigationBars(),
|
||||
mNavLeash, true, new Point(400, 0), Insets.of(0, 0, 100, 0)),
|
||||
new int[1], new int[1]);
|
||||
navConsumer.hide();
|
||||
|
||||
SparseArray<InsetsSourceControl> controls = new SparseArray<>();
|
||||
@@ -143,7 +144,7 @@ public class InsetsAnimationControlImplTest {
|
||||
assertEquals(2, params.size());
|
||||
SurfaceParams first = params.get(0);
|
||||
SurfaceParams second = params.get(1);
|
||||
SurfaceParams topParams = first.surface == mTopLeash ? first : second;
|
||||
SurfaceParams topParams = first.surface == mStatusLeash ? first : second;
|
||||
SurfaceParams navParams = first.surface == mNavLeash ? first : second;
|
||||
assertPosition(topParams.matrix, new Rect(0, 0, 500, 100), new Rect(0, -70, 500, 30));
|
||||
assertPosition(navParams.matrix, new Rect(400, 0, 500, 500), new Rect(460, 0, 560, 500));
|
||||
|
||||
@@ -174,7 +174,7 @@ public class InsetsControllerTest {
|
||||
|
||||
@Test
|
||||
public void testControlsChanged() {
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR));
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars()));
|
||||
assertNotNull(mController.getSourceConsumer(ITYPE_STATUS_BAR).getControl().getLeash());
|
||||
mController.addOnControllableInsetsChangedListener(
|
||||
((controller, typeMask) -> assertEquals(statusBars(), typeMask)));
|
||||
@@ -185,7 +185,7 @@ public class InsetsControllerTest {
|
||||
OnControllableInsetsChangedListener listener
|
||||
= mock(OnControllableInsetsChangedListener.class);
|
||||
mController.addOnControllableInsetsChangedListener(listener);
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR));
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars()));
|
||||
mController.onControlsChanged(new InsetsSourceControl[0]);
|
||||
assertNull(mController.getSourceConsumer(ITYPE_STATUS_BAR).getControl());
|
||||
InOrder inOrder = Mockito.inOrder(listener);
|
||||
@@ -197,7 +197,7 @@ public class InsetsControllerTest {
|
||||
@Test
|
||||
public void testControlsRevoked_duringAnim() {
|
||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR));
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars()));
|
||||
|
||||
ArgumentCaptor<WindowInsetsAnimationController> animationController =
|
||||
ArgumentCaptor.forClass(WindowInsetsAnimationController.class);
|
||||
@@ -226,7 +226,8 @@ public class InsetsControllerTest {
|
||||
|
||||
InsetsSourceControl control =
|
||||
new InsetsSourceControl(
|
||||
ITYPE_STATUS_BAR, mLeash, true, new Point(), Insets.of(0, 10, 0, 0));
|
||||
ITYPE_STATUS_BAR, statusBars(), mLeash, true, new Point(),
|
||||
Insets.of(0, 10, 0, 0));
|
||||
mController.onControlsChanged(new InsetsSourceControl[]{control});
|
||||
mController.controlWindowInsetsAnimation(0, 0 /* durationMs */,
|
||||
new LinearInterpolator(),
|
||||
@@ -278,7 +279,7 @@ public class InsetsControllerTest {
|
||||
|
||||
@Test
|
||||
public void testApplyImeVisibility() {
|
||||
InsetsSourceControl ime = createControl(ITYPE_IME);
|
||||
InsetsSourceControl ime = createControl(ITYPE_IME, ime());
|
||||
mController.onControlsChanged(new InsetsSourceControl[] { ime });
|
||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
||||
mController.getSourceConsumer(ITYPE_IME).onWindowFocusGained(true);
|
||||
@@ -417,7 +418,7 @@ public class InsetsControllerTest {
|
||||
|
||||
@Test
|
||||
public void testRestoreStartsAnimation() {
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR));
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars()));
|
||||
|
||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
||||
mController.hide(statusBars());
|
||||
@@ -434,7 +435,7 @@ public class InsetsControllerTest {
|
||||
assertTrue(mController.getState().getSource(ITYPE_STATUS_BAR).isVisible());
|
||||
|
||||
// Gaining control
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR));
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars()));
|
||||
assertEquals(ANIMATION_TYPE_HIDE, mController.getAnimationType(statusBars()));
|
||||
mController.cancelExistingAnimations();
|
||||
assertFalse(isRequestedVisible(mController, statusBars()));
|
||||
@@ -455,7 +456,7 @@ public class InsetsControllerTest {
|
||||
mController.show(ime(), true /* fromIme */, null /* statsToken */);
|
||||
|
||||
// Gaining control shortly after
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_IME));
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_IME, ime()));
|
||||
|
||||
assertEquals(ANIMATION_TYPE_SHOW, mController.getAnimationType(ime()));
|
||||
mController.cancelExistingAnimations();
|
||||
@@ -473,7 +474,7 @@ public class InsetsControllerTest {
|
||||
assertFalse(mController.getState().getSource(ITYPE_IME).isVisible());
|
||||
|
||||
// Gaining control shortly after
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_IME));
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_IME, ime()));
|
||||
|
||||
// Pretend IME is calling
|
||||
mController.show(ime(), true /* fromIme */, null /* statsToken */);
|
||||
@@ -488,7 +489,7 @@ public class InsetsControllerTest {
|
||||
|
||||
@Test
|
||||
public void testAnimationEndState_controller() throws Exception {
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR));
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars()));
|
||||
|
||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
||||
WindowInsetsAnimationControlListener mockListener =
|
||||
@@ -514,7 +515,7 @@ public class InsetsControllerTest {
|
||||
|
||||
@Test
|
||||
public void testCancellation_afterGainingControl() throws Exception {
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR));
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_STATUS_BAR, statusBars()));
|
||||
|
||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
||||
WindowInsetsAnimationControlListener mockListener =
|
||||
@@ -635,7 +636,7 @@ public class InsetsControllerTest {
|
||||
public void testFrameUpdateDuringAnimation() {
|
||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
||||
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_IME));
|
||||
mController.onControlsChanged(createSingletonControl(ITYPE_IME, ime()));
|
||||
|
||||
// Pretend IME is calling
|
||||
mController.show(ime(), true /* fromIme */, null /* statsToken */);
|
||||
@@ -926,23 +927,23 @@ public class InsetsControllerTest {
|
||||
latch.await();
|
||||
}
|
||||
|
||||
private InsetsSourceControl createControl(@InternalInsetsType int type) {
|
||||
private InsetsSourceControl createControl(int id, @InsetsType int type) {
|
||||
|
||||
// Simulate binder behavior by copying SurfaceControl. Otherwise, InsetsController will
|
||||
// attempt to release mLeash directly.
|
||||
SurfaceControl copy = new SurfaceControl(mLeash, "InsetsControllerTest.createControl");
|
||||
return new InsetsSourceControl(type, copy, InsetsState.getDefaultVisibility(type),
|
||||
new Point(), Insets.NONE);
|
||||
return new InsetsSourceControl(id, type, copy,
|
||||
(type & WindowInsets.Type.defaultVisible()) != 0, new Point(), Insets.NONE);
|
||||
}
|
||||
|
||||
private InsetsSourceControl[] createSingletonControl(@InternalInsetsType int type) {
|
||||
return new InsetsSourceControl[] { createControl(type) };
|
||||
private InsetsSourceControl[] createSingletonControl(int id, @InsetsType int type) {
|
||||
return new InsetsSourceControl[] { createControl(id, type) };
|
||||
}
|
||||
|
||||
private InsetsSourceControl[] prepareControls() {
|
||||
final InsetsSourceControl navBar = createControl(ITYPE_NAVIGATION_BAR);
|
||||
final InsetsSourceControl statusBar = createControl(ITYPE_STATUS_BAR);
|
||||
final InsetsSourceControl ime = createControl(ITYPE_IME);
|
||||
final InsetsSourceControl navBar = createControl(ITYPE_NAVIGATION_BAR, navigationBars());
|
||||
final InsetsSourceControl statusBar = createControl(ITYPE_STATUS_BAR, statusBars());
|
||||
final InsetsSourceControl ime = createControl(ITYPE_IME, ime());
|
||||
|
||||
InsetsSourceControl[] controls = new InsetsSourceControl[3];
|
||||
controls[0] = navBar;
|
||||
|
||||
@@ -113,8 +113,8 @@ public class InsetsSourceConsumerTest {
|
||||
instrumentation.waitForIdleSync();
|
||||
|
||||
mConsumer.setControl(
|
||||
new InsetsSourceControl(ITYPE_STATUS_BAR, mLeash, true /* initialVisible */,
|
||||
new Point(), Insets.NONE),
|
||||
new InsetsSourceControl(ITYPE_STATUS_BAR, statusBars(), mLeash,
|
||||
true /* initialVisible */, new Point(), Insets.NONE),
|
||||
new int[1], new int[1]);
|
||||
}
|
||||
|
||||
@@ -182,8 +182,8 @@ public class InsetsSourceConsumerTest {
|
||||
verifyZeroInteractions(mMockTransaction);
|
||||
int[] hideTypes = new int[1];
|
||||
mConsumer.setControl(
|
||||
new InsetsSourceControl(ITYPE_STATUS_BAR, mLeash, true /* initialVisible */,
|
||||
new Point(), Insets.NONE),
|
||||
new InsetsSourceControl(ITYPE_STATUS_BAR, statusBars(), mLeash,
|
||||
true /* initialVisible */, new Point(), Insets.NONE),
|
||||
new int[1], hideTypes);
|
||||
assertEquals(statusBars(), hideTypes[0]);
|
||||
assertFalse(mRemoveSurfaceCalled);
|
||||
@@ -200,8 +200,8 @@ public class InsetsSourceConsumerTest {
|
||||
mRemoveSurfaceCalled = false;
|
||||
int[] hideTypes = new int[1];
|
||||
mConsumer.setControl(
|
||||
new InsetsSourceControl(ITYPE_STATUS_BAR, mLeash, false /* initialVisible */,
|
||||
new Point(), Insets.NONE),
|
||||
new InsetsSourceControl(ITYPE_STATUS_BAR, statusBars(), mLeash,
|
||||
false /* initialVisible */, new Point(), Insets.NONE),
|
||||
new int[1], hideTypes);
|
||||
assertTrue(mRemoveSurfaceCalled);
|
||||
assertEquals(0, hideTypes[0]);
|
||||
@@ -230,7 +230,7 @@ public class InsetsSourceConsumerTest {
|
||||
InsetsSourceConsumer imeConsumer = insetsController.getSourceConsumer(ITYPE_IME);
|
||||
|
||||
// Initial IME insets source control with its leash.
|
||||
imeConsumer.setControl(new InsetsSourceControl(ITYPE_IME, mLeash,
|
||||
imeConsumer.setControl(new InsetsSourceControl(ITYPE_IME, ime(), mLeash,
|
||||
false /* initialVisible */, new Point(), Insets.NONE), new int[1], new int[1]);
|
||||
reset(mMockTransaction);
|
||||
|
||||
@@ -239,7 +239,7 @@ public class InsetsSourceConsumerTest {
|
||||
insetsController.controlWindowInsetsAnimation(ime(), 0L,
|
||||
null /* interpolator */, null /* cancellationSignal */, null /* listener */);
|
||||
assertEquals(ANIMATION_TYPE_USER, insetsController.getAnimationType(ime()));
|
||||
imeConsumer.setControl(new InsetsSourceControl(ITYPE_IME, mLeash,
|
||||
imeConsumer.setControl(new InsetsSourceControl(ITYPE_IME, ime(), mLeash,
|
||||
true /* initialVisible */, new Point(), Insets.NONE), new int[1], new int[1]);
|
||||
verify(mMockTransaction, never()).show(mLeash);
|
||||
});
|
||||
|
||||
@@ -261,7 +261,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
|
||||
if (activeControl == null) {
|
||||
continue;
|
||||
}
|
||||
if (activeControl.getType() == InsetsState.ITYPE_IME) {
|
||||
if (activeControl.getType() == WindowInsets.Type.ime()) {
|
||||
imeSourceControl = activeControl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,8 @@ public class DisplayImeControllerTest extends ShellTestCase {
|
||||
private InsetsSourceControl[] insetsSourceControl() {
|
||||
return new InsetsSourceControl[]{
|
||||
new InsetsSourceControl(
|
||||
ITYPE_IME, mock(SurfaceControl.class), false, new Point(0, 0), Insets.NONE)
|
||||
ITYPE_IME, ime(), mock(SurfaceControl.class), false, new Point(0, 0),
|
||||
Insets.NONE)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -97,8 +97,7 @@ class InsetsPolicy {
|
||||
return;
|
||||
}
|
||||
for (InsetsSourceControl control : controls) {
|
||||
final @InternalInsetsType int type = control.getType();
|
||||
if (mShowingTransientTypes.indexOf(type) != -1) {
|
||||
if (mShowingTransientTypes.indexOf(control.getId()) != -1) {
|
||||
// The visibilities of transient bars will be handled with animations.
|
||||
continue;
|
||||
}
|
||||
@@ -108,8 +107,9 @@ class InsetsPolicy {
|
||||
|
||||
// We use alpha to control the visibility here which aligns the logic at
|
||||
// SurfaceAnimator.createAnimationLeash
|
||||
mDisplayContent.getPendingTransaction().setAlpha(
|
||||
leash, InsetsState.getDefaultVisibility(type) ? 1f : 0f);
|
||||
final boolean visible =
|
||||
(control.getType() & WindowInsets.Type.defaultVisible()) != 0;
|
||||
mDisplayContent.getPendingTransaction().setAlpha(leash, visible ? 1f : 0f);
|
||||
}
|
||||
}
|
||||
if (hasLeash) {
|
||||
@@ -627,14 +627,15 @@ class InsetsPolicy {
|
||||
final SparseArray<InsetsSourceControl> controls = new SparseArray<>();
|
||||
final IntArray showingTransientTypes = mShowingTransientTypes;
|
||||
for (int i = showingTransientTypes.size() - 1; i >= 0; i--) {
|
||||
final @InternalInsetsType int type = showingTransientTypes.get(i);
|
||||
WindowContainerInsetsSourceProvider provider = mStateController.getSourceProvider(type);
|
||||
InsetsSourceControl control = provider.getControl(mDummyControlTarget);
|
||||
final int sourceId = showingTransientTypes.get(i);
|
||||
final WindowContainerInsetsSourceProvider provider =
|
||||
mStateController.getSourceProvider(sourceId);
|
||||
final InsetsSourceControl control = provider.getControl(mDummyControlTarget);
|
||||
if (control == null || control.getLeash() == null) {
|
||||
continue;
|
||||
}
|
||||
typesReady |= InsetsState.toPublicType(type);
|
||||
controls.put(control.getType(), new InsetsSourceControl(control));
|
||||
typesReady |= control.getType();
|
||||
controls.put(sourceId, new InsetsSourceControl(control));
|
||||
}
|
||||
controlAnimationUnchecked(typesReady, controls, show, callback);
|
||||
}
|
||||
|
||||
@@ -125,8 +125,8 @@ abstract class InsetsSourceProvider {
|
||||
mDisplayContent = displayContent;
|
||||
mStateController = stateController;
|
||||
mFakeControl = new InsetsSourceControl(
|
||||
source.getId(), null /* leash */, false /* initialVisible */, new Point(),
|
||||
Insets.NONE);
|
||||
source.getId(), source.getType(), null /* leash */, false /* initialVisible */,
|
||||
new Point(), Insets.NONE);
|
||||
mControllable = (InsetsPolicy.CONTROLLABLE_TYPES & source.getType()) != 0;
|
||||
}
|
||||
|
||||
@@ -472,8 +472,8 @@ abstract class InsetsSourceProvider {
|
||||
final SurfaceControl leash = mAdapter.mCapturedLeash;
|
||||
mControlTarget = target;
|
||||
updateVisibility();
|
||||
mControl = new InsetsSourceControl(mSource.getId(), leash, mClientVisible, surfacePosition,
|
||||
mInsetsHint);
|
||||
mControl = new InsetsSourceControl(mSource.getId(), mSource.getType(), leash,
|
||||
mClientVisible, surfacePosition, mInsetsHint);
|
||||
|
||||
ProtoLog.d(WM_DEBUG_WINDOW_INSETS,
|
||||
"InsetsSource Control %s for target %s", mControl, mControlTarget);
|
||||
@@ -557,9 +557,9 @@ abstract class InsetsSourceProvider {
|
||||
// The surface transaction of preparing leash is not applied yet. We don't send it
|
||||
// to the client in case that the client applies its transaction sooner than ours
|
||||
// that we could unexpectedly overwrite the surface state.
|
||||
return new InsetsSourceControl(mControl.getType(), null /* leash */,
|
||||
mControl.isInitiallyVisible(), mControl.getSurfacePosition(),
|
||||
mControl.getInsetsHint());
|
||||
return new InsetsSourceControl(mControl.getId(), mControl.getType(),
|
||||
null /* leash */, mControl.isInitiallyVisible(),
|
||||
mControl.getSurfacePosition(), mControl.getInsetsHint());
|
||||
}
|
||||
return mControl;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import android.view.InsetsSource;
|
||||
import android.view.InsetsSourceControl;
|
||||
import android.view.InsetsState;
|
||||
import android.view.InsetsState.InternalInsetsType;
|
||||
import android.view.WindowInsets;
|
||||
|
||||
import com.android.internal.protolog.common.ProtoLog;
|
||||
import com.android.server.inputmethod.InputMethodManagerInternal;
|
||||
@@ -80,7 +81,7 @@ class InsetsStateController {
|
||||
return;
|
||||
}
|
||||
for (InsetsSourceControl control : controls) {
|
||||
if (control.getType() == ITYPE_IME) {
|
||||
if (control.getType() == WindowInsets.Type.ime()) {
|
||||
mDisplayContent.mWmService.mH.post(() ->
|
||||
InputMethodManagerInternal.get().removeImeSurface());
|
||||
}
|
||||
|
||||
@@ -196,14 +196,14 @@ public class InsetsPolicyTest extends WindowTestsBase {
|
||||
mDisplayContent.getInsetsStateController().getControlsForDispatch(dialog);
|
||||
assertNotNull(dialogControls);
|
||||
assertEquals(1, dialogControls.length);
|
||||
assertEquals(ITYPE_NAVIGATION_BAR, dialogControls[0].getType());
|
||||
assertEquals(navigationBars(), dialogControls[0].getType());
|
||||
|
||||
// fullscreenApp is hiding status bar, and it can keep controlling status bar.
|
||||
final InsetsSourceControl[] fullscreenAppControls =
|
||||
mDisplayContent.getInsetsStateController().getControlsForDispatch(fullscreenApp);
|
||||
assertNotNull(fullscreenAppControls);
|
||||
assertEquals(1, fullscreenAppControls.length);
|
||||
assertEquals(ITYPE_STATUS_BAR, fullscreenAppControls[0].getType());
|
||||
assertEquals(statusBars(), fullscreenAppControls[0].getType());
|
||||
|
||||
// Assume mFocusedWindow is updated but mTopFullscreenOpaqueWindowState hasn't.
|
||||
final WindowState newFocusedFullscreenApp = addWindow(TYPE_APPLICATION, "newFullscreenApp");
|
||||
@@ -231,7 +231,7 @@ public class InsetsPolicyTest extends WindowTestsBase {
|
||||
mDisplayContent.getInsetsStateController().getControlsForDispatch(panel);
|
||||
assertNotNull(panelControls);
|
||||
assertEquals(1, panelControls.length);
|
||||
assertEquals(ITYPE_NAVIGATION_BAR, panelControls[0].getType());
|
||||
assertEquals(navigationBars(), panelControls[0].getType());
|
||||
|
||||
// Add notificationShade and make it can receive keys.
|
||||
final WindowState shade = addWindow(TYPE_NOTIFICATION_SHADE, "notificationShade");
|
||||
@@ -253,7 +253,7 @@ public class InsetsPolicyTest extends WindowTestsBase {
|
||||
panelControls = mDisplayContent.getInsetsStateController().getControlsForDispatch(panel);
|
||||
assertNotNull(panelControls);
|
||||
assertEquals(1, panelControls.length);
|
||||
assertEquals(ITYPE_NAVIGATION_BAR, panelControls[0].getType());
|
||||
assertEquals(navigationBars(), panelControls[0].getType());
|
||||
}
|
||||
|
||||
@SetupWindows(addWindows = W_ACTIVITY)
|
||||
@@ -316,7 +316,7 @@ public class InsetsPolicyTest extends WindowTestsBase {
|
||||
assertEquals(2, controls.length);
|
||||
for (int i = controls.length - 1; i >= 0; i--) {
|
||||
final InsetsSourceControl control = controls[i];
|
||||
if (control.getType() == ITYPE_STATUS_BAR) {
|
||||
if (control.getType() == statusBars()) {
|
||||
assertNull(controls[i].getLeash());
|
||||
} else {
|
||||
assertNotNull(controls[i].getLeash());
|
||||
|
||||
Reference in New Issue
Block a user