diff options
author | 2022-11-14 15:27:21 +0800 | |
---|---|---|
committer | 2022-11-14 17:07:36 +0800 | |
commit | aa1a278e3e599f7f078398495e47230a8168855e (patch) | |
tree | 720140ee5cbc0c538ea5ea9abcc2723c01a169de | |
parent | c9275cea51620e4e3dd901fcf6347bf8a36fbac1 (diff) |
Describe requested visibilities in public types (6/n: clean up)
This CL
- removes unused files and imports,
- refines WindowInsets.Type#toString(int),
- reuses WindowInsets.Type#toString(int) in ControllerActivity, and
- refines RemoteInsetsControlTarget#isRequestedVisible.
Bug: 253420890
Bug: 234093736
Test: Open Window Insets Controller and see if ControllableInsetsTypes
displays expected strings.
Test: Execute `adb shell dumpsys window all` and see if the strings of
"Requested non-default-visibility types" are as expected.
Change-Id: I2aa041096db9880a32281fa684312c1f43d1c4a3
7 files changed, 15 insertions, 330 deletions
diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl index e2bc5668d058..ff341bb77c27 100644 --- a/core/java/android/view/IWindowManager.aidl +++ b/core/java/android/view/IWindowManager.aidl @@ -53,7 +53,6 @@ import android.view.IWindowSessionCallback; import android.view.KeyEvent; import android.view.InputEvent; import android.view.InsetsState; -import android.view.InsetsVisibilities; import android.view.MagnificationSpec; import android.view.MotionEvent; import android.view.InputChannel; diff --git a/core/java/android/view/InsetsVisibilities.aidl b/core/java/android/view/InsetsVisibilities.aidl deleted file mode 100644 index bd573ea7bc35..000000000000 --- a/core/java/android/view/InsetsVisibilities.aidl +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (c) 2021, The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.view; - -parcelable InsetsVisibilities; diff --git a/core/java/android/view/InsetsVisibilities.java b/core/java/android/view/InsetsVisibilities.java deleted file mode 100644 index 7d259fb91634..000000000000 --- a/core/java/android/view/InsetsVisibilities.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.view; - -import android.annotation.NonNull; -import android.os.Parcel; -import android.os.Parcelable; - -import java.util.Arrays; -import java.util.StringJoiner; - -/** - * A collection of visibilities of insets. This is used for carrying the requested visibilities. - * @hide - */ -public class InsetsVisibilities implements Parcelable { - - private static final int UNSPECIFIED = 0; - private static final int VISIBLE = 1; - private static final int INVISIBLE = -1; - - private final int[] mVisibilities = new int[InsetsState.SIZE]; - - public InsetsVisibilities() { - } - - public InsetsVisibilities(InsetsVisibilities other) { - set(other); - } - - public InsetsVisibilities(Parcel in) { - in.readIntArray(mVisibilities); - } - - /** - * Copies from another {@link InsetsVisibilities}. - * - * @param other an instance of {@link InsetsVisibilities}. - */ - public void set(InsetsVisibilities other) { - System.arraycopy(other.mVisibilities, InsetsState.FIRST_TYPE, mVisibilities, - InsetsState.FIRST_TYPE, InsetsState.SIZE); - } - - /** - * Sets a visibility to a type. - * - * @param type The {@link @InsetsState.InternalInsetsType}. - * @param visible {@code true} represents visible; {@code false} represents invisible. - */ - public void setVisibility(@InsetsState.InternalInsetsType int type, boolean visible) { - mVisibilities[type] = visible ? VISIBLE : INVISIBLE; - } - - /** - * Returns the specified insets visibility of the type. If it has never been specified, - * this returns the default visibility. - * - * @param type The {@link @InsetsState.InternalInsetsType}. - * @return The specified visibility or the default one if it is not specified. - */ - public boolean getVisibility(@InsetsState.InternalInsetsType int type) { - final int visibility = mVisibilities[type]; - return visibility == UNSPECIFIED - ? InsetsState.getDefaultVisibility(type) - : visibility == VISIBLE; - } - - @Override - public String toString() { - StringJoiner joiner = new StringJoiner(", "); - for (int type = InsetsState.FIRST_TYPE; type <= InsetsState.LAST_TYPE; type++) { - final int visibility = mVisibilities[type]; - if (visibility != UNSPECIFIED) { - joiner.add(InsetsState.typeToString(type) + ": " - + (visibility == VISIBLE ? "visible" : "invisible")); - } - } - return joiner.toString(); - } - - @Override - public int hashCode() { - return Arrays.hashCode(mVisibilities); - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof InsetsVisibilities)) { - return false; - } - return Arrays.equals(mVisibilities, ((InsetsVisibilities) other).mVisibilities); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeIntArray(mVisibilities); - } - - public void readFromParcel(@NonNull Parcel in) { - in.readIntArray(mVisibilities); - } - - public static final @NonNull Creator<InsetsVisibilities> CREATOR = - new Creator<InsetsVisibilities>() { - - public InsetsVisibilities createFromParcel(Parcel in) { - return new InsetsVisibilities(in); - } - - public InsetsVisibilities[] newArray(int size) { - return new InsetsVisibilities[size]; - } - }; -} diff --git a/core/java/android/view/WindowInsets.java b/core/java/android/view/WindowInsets.java index d77e499357b9..fc0144fa85b0 100644 --- a/core/java/android/view/WindowInsets.java +++ b/core/java/android/view/WindowInsets.java @@ -1463,37 +1463,37 @@ public final class WindowInsets { public static String toString(@InsetsType int types) { StringBuilder result = new StringBuilder(); if ((types & STATUS_BARS) != 0) { - result.append("statusBars |"); + result.append("statusBars "); } if ((types & NAVIGATION_BARS) != 0) { - result.append("navigationBars |"); + result.append("navigationBars "); } if ((types & CAPTION_BAR) != 0) { - result.append("captionBar |"); + result.append("captionBar "); } if ((types & IME) != 0) { - result.append("ime |"); + result.append("ime "); } if ((types & SYSTEM_GESTURES) != 0) { - result.append("systemGestures |"); + result.append("systemGestures "); } if ((types & MANDATORY_SYSTEM_GESTURES) != 0) { - result.append("mandatorySystemGestures |"); + result.append("mandatorySystemGestures "); } if ((types & TAPPABLE_ELEMENT) != 0) { - result.append("tappableElement |"); + result.append("tappableElement "); } if ((types & DISPLAY_CUTOUT) != 0) { - result.append("displayCutout |"); + result.append("displayCutout "); } if ((types & WINDOW_DECOR) != 0) { - result.append("windowDecor |"); + result.append("windowDecor "); } if ((types & SYSTEM_OVERLAYS) != 0) { - result.append("systemOverlays |"); + result.append("systemOverlays "); } if (result.length() > 0) { - result.delete(result.length() - 2, result.length()); + result.delete(result.length() - 1, result.length()); } return result.toString(); } diff --git a/core/tests/coretests/src/android/view/InsetsVisibilitiesTest.java b/core/tests/coretests/src/android/view/InsetsVisibilitiesTest.java deleted file mode 100644 index 5664e0b0aa0f..000000000000 --- a/core/tests/coretests/src/android/view/InsetsVisibilitiesTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.view; - -import static android.view.InsetsState.FIRST_TYPE; -import static android.view.InsetsState.LAST_TYPE; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - -import android.platform.test.annotations.Presubmit; -import android.view.InsetsState.InternalInsetsType; - -import androidx.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Tests for {@link InsetsVisibilities}. - * - * <p>Build/Install/Run: - * atest FrameworksCoreTests:InsetsVisibilities - * - * <p>This test class is a part of Window Manager Service tests and specified in - * {@link com.android.server.wm.test.filters.FrameworksTestsFilter}. - */ -@Presubmit -@RunWith(AndroidJUnit4.class) -public class InsetsVisibilitiesTest { - - @Test - public void testEquals() { - final InsetsVisibilities v1 = new InsetsVisibilities(); - final InsetsVisibilities v2 = new InsetsVisibilities(); - final InsetsVisibilities v3 = new InsetsVisibilities(); - assertEquals(v1, v2); - assertEquals(v1, v3); - - for (@InternalInsetsType int type = FIRST_TYPE; type <= LAST_TYPE; type++) { - v1.setVisibility(type, false); - v2.setVisibility(type, false); - } - assertEquals(v1, v2); - assertNotEquals(v1, v3); - - for (@InternalInsetsType int type = FIRST_TYPE; type <= LAST_TYPE; type++) { - v1.setVisibility(type, true); - v2.setVisibility(type, true); - } - assertEquals(v1, v2); - assertNotEquals(v1, v3); - } - - @Test - public void testSet() { - for (@InternalInsetsType int type = FIRST_TYPE; type <= LAST_TYPE; type++) { - final InsetsVisibilities v1 = new InsetsVisibilities(); - final InsetsVisibilities v2 = new InsetsVisibilities(); - - v1.setVisibility(type, true); - assertNotEquals(v1, v2); - - v2.set(v1); - assertEquals(v1, v2); - - v2.setVisibility(type, false); - assertNotEquals(v1, v2); - - v1.set(v2); - assertEquals(v1, v2); - } - } - - @Test - public void testCopyConstructor() { - for (@InternalInsetsType int type = FIRST_TYPE; type <= LAST_TYPE; type++) { - final InsetsVisibilities v1 = new InsetsVisibilities(); - v1.setVisibility(type, true); - final InsetsVisibilities v2 = new InsetsVisibilities(v1); - assertEquals(v1, v2); - - v2.setVisibility(type, false); - assertNotEquals(v1, v2); - } - } - - @Test - public void testGetterAndSetter() { - final InsetsVisibilities v1 = new InsetsVisibilities(); - final InsetsVisibilities v2 = new InsetsVisibilities(); - - for (@InternalInsetsType int type = FIRST_TYPE; type <= LAST_TYPE; type++) { - assertEquals(InsetsState.getDefaultVisibility(type), v1.getVisibility(type)); - } - - for (@InternalInsetsType int type = FIRST_TYPE; type <= LAST_TYPE; type++) { - v1.setVisibility(type, true); - assertTrue(v1.getVisibility(type)); - - v2.setVisibility(type, false); - assertFalse(v2.getVisibility(type)); - } - } -} diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 8b3444318636..a1947caea3e1 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -6741,10 +6741,9 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp @Override public boolean isRequestedVisible(@InsetsType int types) { - if (types == ime()) { - return getInsetsStateController().getImeSourceProvider().isImeShowing(); - } - return (mRequestedVisibleTypes & types) != 0; + return ((types & ime()) != 0 + && getInsetsStateController().getImeSourceProvider().isImeShowing()) + || (mRequestedVisibleTypes & types) != 0; } @Override diff --git a/tests/WindowInsetsTests/src/com/google/android/test/windowinsetstests/ControllerActivity.java b/tests/WindowInsetsTests/src/com/google/android/test/windowinsetstests/ControllerActivity.java index e6b60cfbe84f..167d560633ab 100644 --- a/tests/WindowInsetsTests/src/com/google/android/test/windowinsetstests/ControllerActivity.java +++ b/tests/WindowInsetsTests/src/com/google/android/test/windowinsetstests/ControllerActivity.java @@ -88,46 +88,7 @@ public class ControllerActivity extends Activity implements View.OnApplyWindowIn } private static String insetsTypesToString(int types) { - if (types == 0) { - return "none"; - } - final StringBuilder sb = new StringBuilder(); - if ((types & Type.statusBars()) != 0) { - types &= ~Type.statusBars(); - sb.append("statusBars "); - } - if ((types & Type.navigationBars()) != 0) { - types &= ~Type.navigationBars(); - sb.append("navigationBars "); - } - if ((types & Type.captionBar()) != 0) { - types &= ~Type.captionBar(); - sb.append("captionBar "); - } - if ((types & Type.ime()) != 0) { - types &= ~Type.ime(); - sb.append("ime "); - } - if ((types & Type.systemGestures()) != 0) { - types &= ~Type.systemGestures(); - sb.append("systemGestures "); - } - if ((types & Type.mandatorySystemGestures()) != 0) { - types &= ~Type.mandatorySystemGestures(); - sb.append("mandatorySystemGestures "); - } - if ((types & Type.tappableElement()) != 0) { - types &= ~Type.tappableElement(); - sb.append("tappableElement "); - } - if ((types & Type.displayCutout()) != 0) { - types &= ~Type.displayCutout(); - sb.append("displayCutout "); - } - if (types != 0) { - sb.append("unknownTypes:").append(types); - } - return sb.toString(); + return types == 0 ? "none" : WindowInsets.Type.toString(types); } @Override |