From e14340190370e79010f9255c97d78ae00694f603 Mon Sep 17 00:00:00 2001 From: Tiger Date: Thu, 17 Nov 2022 22:21:37 +0800 Subject: [PATCH] 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 --- .../view/InsetsAnimationControlImpl.java | 10 ++--- core/java/android/view/InsetsController.java | 23 +++++------ .../android/view/InsetsSourceConsumer.java | 2 +- .../android/view/InsetsSourceControl.java | 38 +++++++++++------ .../view/ImeInsetsSourceConsumerTest.java | 16 ++++---- .../view/InsetsAnimationControlImplTest.java | 17 ++++---- .../android/view/InsetsControllerTest.java | 41 ++++++++++--------- .../view/InsetsSourceConsumerTest.java | 16 ++++---- .../wm/shell/common/DisplayImeController.java | 2 +- .../common/DisplayImeControllerTest.java | 3 +- .../com/android/server/wm/InsetsPolicy.java | 19 +++++---- .../server/wm/InsetsSourceProvider.java | 14 +++---- .../server/wm/InsetsStateController.java | 3 +- .../android/server/wm/InsetsPolicyTest.java | 10 ++--- 14 files changed, 116 insertions(+), 98 deletions(-) diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java index 81a696a3ad72e..164865966eade 100644 --- a/core/java/android/view/InsetsAnimationControlImpl.java +++ b/core/java/android/view/InsetsAnimationControlImpl.java @@ -217,7 +217,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro public void updateSurfacePosition(SparseArray 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); diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index 31e82a3e3deac..421efed838521 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -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 diff --git a/core/java/android/view/InsetsSourceConsumer.java b/core/java/android/view/InsetsSourceConsumer.java index 21c0395000f0d..b8c4eaa782e7c 100644 --- a/core/java/android/view/InsetsSourceConsumer.java +++ b/core/java/android/view/InsetsSourceConsumer.java @@ -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) { diff --git a/core/java/android/view/InsetsSourceControl.java b/core/java/android/view/InsetsSourceControl.java index 5f1cbba58d3c2..610cfe40ebce4 100644 --- a/core/java/android/view/InsetsSourceControl.java +++ b/core/java/android/view/InsetsSourceControl.java @@ -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 CREATOR - = new Creator() { + public static final @NonNull Creator 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); diff --git a/core/tests/coretests/src/android/view/ImeInsetsSourceConsumerTest.java b/core/tests/coretests/src/android/view/ImeInsetsSourceConsumerTest.java index 0bf133fe01b60..9b8a0e952beb0 100644 --- a/core/tests/coretests/src/android/view/ImeInsetsSourceConsumerTest.java +++ b/core/tests/coretests/src/android/view/ImeInsetsSourceConsumerTest.java @@ -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 */); } }); } diff --git a/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java b/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java index c88255ef0e002..19ff5982f65f7 100644 --- a/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java +++ b/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java @@ -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 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)); diff --git a/core/tests/coretests/src/android/view/InsetsControllerTest.java b/core/tests/coretests/src/android/view/InsetsControllerTest.java index c6fa778763a8b..fad9a5ca057ca 100644 --- a/core/tests/coretests/src/android/view/InsetsControllerTest.java +++ b/core/tests/coretests/src/android/view/InsetsControllerTest.java @@ -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 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; diff --git a/core/tests/coretests/src/android/view/InsetsSourceConsumerTest.java b/core/tests/coretests/src/android/view/InsetsSourceConsumerTest.java index 672252f6c7506..521b65edf2bd7 100644 --- a/core/tests/coretests/src/android/view/InsetsSourceConsumerTest.java +++ b/core/tests/coretests/src/android/view/InsetsSourceConsumerTest.java @@ -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); }); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java index d9b4f475a50cd..7aae6335398ad 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/DisplayImeController.java @@ -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; } } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java index a92fbd2c847ae..22df362a6ed35 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/DisplayImeControllerTest.java @@ -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) }; } diff --git a/services/core/java/com/android/server/wm/InsetsPolicy.java b/services/core/java/com/android/server/wm/InsetsPolicy.java index 059c81e4d755e..35e1fbb61b68a 100644 --- a/services/core/java/com/android/server/wm/InsetsPolicy.java +++ b/services/core/java/com/android/server/wm/InsetsPolicy.java @@ -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 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); } diff --git a/services/core/java/com/android/server/wm/InsetsSourceProvider.java b/services/core/java/com/android/server/wm/InsetsSourceProvider.java index b1ac8e2df463e..5171f5b02899a 100644 --- a/services/core/java/com/android/server/wm/InsetsSourceProvider.java +++ b/services/core/java/com/android/server/wm/InsetsSourceProvider.java @@ -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; } diff --git a/services/core/java/com/android/server/wm/InsetsStateController.java b/services/core/java/com/android/server/wm/InsetsStateController.java index cad32c5fac44f..455cd48babec8 100644 --- a/services/core/java/com/android/server/wm/InsetsStateController.java +++ b/services/core/java/com/android/server/wm/InsetsStateController.java @@ -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()); } diff --git a/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java b/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java index fd2a1d1c352fa..fff8675a46578 100644 --- a/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java +++ b/services/tests/wmtests/src/com/android/server/wm/InsetsPolicyTest.java @@ -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());