diff options
12 files changed, 165 insertions, 171 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java index f0da35df39ee..243e2f430c10 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java @@ -787,7 +787,7 @@ public class BubbleController implements ConfigurationChangeListener, mLayerView.setOnApplyWindowInsetsListener((view, windowInsets) -> { if (!windowInsets.equals(mWindowInsets) && mLayerView != null) { mWindowInsets = windowInsets; - mBubblePositioner.update(); + mBubblePositioner.update(DeviceConfig.create(mContext, mWindowManager)); mLayerView.onDisplaySizeChanged(); } return windowInsets; @@ -797,7 +797,7 @@ public class BubbleController implements ConfigurationChangeListener, mStackView.setOnApplyWindowInsetsListener((view, windowInsets) -> { if (!windowInsets.equals(mWindowInsets) && mStackView != null) { mWindowInsets = windowInsets; - mBubblePositioner.update(); + mBubblePositioner.update(DeviceConfig.create(mContext, mWindowManager)); mStackView.onDisplaySizeChanged(); } return windowInsets; @@ -979,7 +979,7 @@ public class BubbleController implements ConfigurationChangeListener, @Override public void onConfigurationChanged(Configuration newConfig) { if (mBubblePositioner != null) { - mBubblePositioner.update(); + mBubblePositioner.update(DeviceConfig.create(mContext, mWindowManager)); } if (mStackView != null && newConfig != null) { if (newConfig.densityDpi != mDensityDpi diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java index 09ae84a50328..1efd9df3a1d9 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java @@ -16,10 +16,7 @@ package com.android.wm.shell.bubbles; -import static android.view.View.LAYOUT_DIRECTION_RTL; - import android.content.Context; -import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Insets; import android.graphics.Point; @@ -28,9 +25,7 @@ import android.graphics.Rect; import android.graphics.RectF; import android.util.Log; import android.view.Surface; -import android.view.WindowInsets; import android.view.WindowManager; -import android.view.WindowMetrics; import androidx.annotation.VisibleForTesting; @@ -68,15 +63,12 @@ public class BubblePositioner { private static final float EXPANDED_VIEW_BUBBLE_BAR_LANDSCAPE_WIDTH_PERCENT = 0.4f; private Context mContext; - private WindowManager mWindowManager; + private DeviceConfig mDeviceConfig; private Rect mScreenRect; private @Surface.Rotation int mRotation = Surface.ROTATION_0; private Insets mInsets; private boolean mImeVisible; private int mImeHeight; - private boolean mIsLargeScreen; - private boolean mIsSmallTablet; - private Rect mPositionRect; private int mDefaultMaxBubbles; private int mMaxBubbles; @@ -110,44 +102,27 @@ public class BubblePositioner { public BubblePositioner(Context context, WindowManager windowManager) { mContext = context; - mWindowManager = windowManager; - update(); + mDeviceConfig = DeviceConfig.create(context, windowManager); + update(mDeviceConfig); } /** * Available space and inset information. Call this when config changes * occur or when added to a window. */ - public void update() { - WindowMetrics windowMetrics = mWindowManager.getCurrentWindowMetrics(); - if (windowMetrics == null) { - return; - } - WindowInsets metricInsets = windowMetrics.getWindowInsets(); - Insets insets = metricInsets.getInsetsIgnoringVisibility(WindowInsets.Type.navigationBars() - | WindowInsets.Type.statusBars() - | WindowInsets.Type.displayCutout()); - - final Rect bounds = windowMetrics.getBounds(); - Configuration config = mContext.getResources().getConfiguration(); - mIsLargeScreen = config.smallestScreenWidthDp >= 600; - if (mIsLargeScreen) { - float largestEdgeDp = Math.max(config.screenWidthDp, config.screenHeightDp); - mIsSmallTablet = largestEdgeDp < 960; - } else { - mIsSmallTablet = false; - } + public void update(DeviceConfig deviceConfig) { + mDeviceConfig = deviceConfig; if (BubbleDebugConfig.DEBUG_POSITIONER) { Log.w(TAG, "update positioner:" + " rotation: " + mRotation - + " insets: " + insets - + " isLargeScreen: " + mIsLargeScreen - + " isSmallTablet: " + mIsSmallTablet + + " insets: " + deviceConfig.getInsets() + + " isLargeScreen: " + deviceConfig.isLargeScreen() + + " isSmallTablet: " + deviceConfig.isSmallTablet() + " showingInBubbleBar: " + mShowingInBubbleBar - + " bounds: " + bounds); + + " bounds: " + deviceConfig.getWindowBounds()); } - updateInternal(mRotation, insets, bounds); + updateInternal(mRotation, deviceConfig.getInsets(), deviceConfig.getWindowBounds()); } @VisibleForTesting @@ -175,15 +150,15 @@ public class BubblePositioner { mExpandedViewLargeScreenWidth = isLandscape() ? (int) (bounds.width() * EXPANDED_VIEW_BUBBLE_BAR_LANDSCAPE_WIDTH_PERCENT) : (int) (bounds.width() * EXPANDED_VIEW_BUBBLE_BAR_PORTRAIT_WIDTH_PERCENT); - } else if (mIsSmallTablet) { + } else if (mDeviceConfig.isSmallTablet()) { mExpandedViewLargeScreenWidth = (int) (bounds.width() * EXPANDED_VIEW_SMALL_TABLET_WIDTH_PERCENT); } else { mExpandedViewLargeScreenWidth = res.getDimensionPixelSize(R.dimen.bubble_expanded_view_largescreen_width); } - if (mIsLargeScreen) { - if (mIsSmallTablet) { + if (mDeviceConfig.isLargeScreen()) { + if (mDeviceConfig.isSmallTablet()) { final int centeredInset = (bounds.width() - mExpandedViewLargeScreenWidth) / 2; mExpandedViewLargeScreenInsetClosestEdge = centeredInset; mExpandedViewLargeScreenInsetFurthestEdge = centeredInset; @@ -264,13 +239,12 @@ public class BubblePositioner { /** @return whether the device is in landscape orientation. */ public boolean isLandscape() { - return mContext.getResources().getConfiguration().orientation - == Configuration.ORIENTATION_LANDSCAPE; + return mDeviceConfig.isLandscape(); } /** @return whether the screen is considered large. */ public boolean isLargeScreen() { - return mIsLargeScreen; + return mDeviceConfig.isLargeScreen(); } /** @@ -281,7 +255,7 @@ public class BubblePositioner { * to the left or right side. */ public boolean showBubblesVertically() { - return isLandscape() || mIsLargeScreen; + return isLandscape() || mDeviceConfig.isLargeScreen(); } /** Size of the bubble. */ @@ -334,7 +308,7 @@ public class BubblePositioner { } private int getExpandedViewLargeScreenInsetFurthestEdge(boolean isOverflow) { - if (isOverflow && mIsLargeScreen) { + if (isOverflow && mDeviceConfig.isLargeScreen()) { return mScreenRect.width() - mExpandedViewLargeScreenInsetClosestEdge - mOverflowWidth; @@ -358,7 +332,7 @@ public class BubblePositioner { final int pointerTotalHeight = getPointerSize(); final int expandedViewLargeScreenInsetFurthestEdge = getExpandedViewLargeScreenInsetFurthestEdge(isOverflow); - if (mIsLargeScreen) { + if (mDeviceConfig.isLargeScreen()) { // Note: // If we're in portrait OR if we're a small tablet, then the two insets values will // be equal. If we're landscape and a large tablet, the two values will be different. @@ -439,12 +413,12 @@ public class BubblePositioner { */ public float getExpandedViewHeight(BubbleViewProvider bubble) { boolean isOverflow = bubble == null || BubbleOverflow.KEY.equals(bubble.getKey()); - if (isOverflow && showBubblesVertically() && !mIsLargeScreen) { + if (isOverflow && showBubblesVertically() && !mDeviceConfig.isLargeScreen()) { // overflow in landscape on phone is max return MAX_HEIGHT; } - if (mIsLargeScreen && !mIsSmallTablet && !isOverflow) { + if (mDeviceConfig.isLargeScreen() && !mDeviceConfig.isSmallTablet() && !isOverflow) { // the expanded view height on large tablets is calculated based on the shortest screen // size and is the same in both portrait and landscape int maxVerticalInset = Math.max(mInsets.top, mInsets.bottom); @@ -529,11 +503,9 @@ public class BubblePositioner { */ public PointF getExpandedBubbleXY(int index, BubbleStackView.StackViewState state) { boolean showBubblesVertically = showBubblesVertically(); - boolean isRtl = mContext.getResources().getConfiguration().getLayoutDirection() - == LAYOUT_DIRECTION_RTL; int onScreenIndex; - if (showBubblesVertically || !isRtl) { + if (showBubblesVertically || !mDeviceConfig.isRtl()) { onScreenIndex = index; } else { // If bubbles are shown horizontally, check if RTL language is used. @@ -554,10 +526,10 @@ public class BubblePositioner { if (showBubblesVertically) { int inset = mExpandedViewLargeScreenInsetClosestEdge; y = rowStart + positionInRow; - int left = mIsLargeScreen + int left = mDeviceConfig.isLargeScreen() ? inset - mExpandedViewPadding - mBubbleSize : mPositionRect.left; - int right = mIsLargeScreen + int right = mDeviceConfig.isLargeScreen() ? mPositionRect.right - inset + mExpandedViewPadding : mPositionRect.right - mBubbleSize; x = state.onLeft @@ -693,13 +665,10 @@ public class BubblePositioner { * @param isAppBubble whether this start position is for an app bubble or not. */ public PointF getDefaultStartPosition(boolean isAppBubble) { - final int layoutDirection = mContext.getResources().getConfiguration().getLayoutDirection(); // Normal bubbles start on the left if we're in LTR, right otherwise. // TODO (b/294284894): update language around "app bubble" here // App bubbles start on the right in RTL, left otherwise. - final boolean startOnLeft = isAppBubble - ? layoutDirection == LAYOUT_DIRECTION_RTL - : layoutDirection != LAYOUT_DIRECTION_RTL; + final boolean startOnLeft = isAppBubble ? mDeviceConfig.isRtl() : !mDeviceConfig.isRtl(); return getStartPosition(startOnLeft ? StackPinnedEdge.LEFT : StackPinnedEdge.RIGHT); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java index 2cee675e83be..8f904c42d247 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java @@ -61,6 +61,7 @@ import android.view.ViewGroup; import android.view.ViewOutlineProvider; import android.view.ViewPropertyAnimator; import android.view.ViewTreeObserver; +import android.view.WindowManager; import android.view.WindowManagerPolicyConstants; import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; @@ -1001,7 +1002,8 @@ public class BubbleStackView extends FrameLayout mOrientationChangedListener = (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { - mPositioner.update(); + mPositioner.update(DeviceConfig.create(mContext, mContext.getSystemService( + WindowManager.class))); onDisplaySizeChanged(); mExpandedAnimationController.updateResources(); mStackAnimationController.updateResources(); @@ -1522,7 +1524,8 @@ public class BubbleStackView extends FrameLayout @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - mPositioner.update(); + WindowManager windowManager = mContext.getSystemService(WindowManager.class); + mPositioner.update(DeviceConfig.create(mContext, Objects.requireNonNull(windowManager))); getViewTreeObserver().addOnComputeInternalInsetsListener(this); getViewTreeObserver().addOnDrawListener(mSystemGestureExcludeUpdater); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/DeviceConfig.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/DeviceConfig.kt new file mode 100644 index 000000000000..929330918174 --- /dev/null +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/DeviceConfig.kt @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2023 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 com.android.wm.shell.bubbles + +import android.content.Context +import android.content.res.Configuration +import android.content.res.Configuration.ORIENTATION_LANDSCAPE +import android.graphics.Insets +import android.graphics.Rect +import android.view.View.LAYOUT_DIRECTION_RTL +import android.view.WindowInsets +import android.view.WindowManager +import kotlin.math.max + +/** Contains device configuration used for positioning bubbles on the screen. */ +data class DeviceConfig( + val isLargeScreen: Boolean, + val isSmallTablet: Boolean, + val isLandscape: Boolean, + val isRtl: Boolean, + val windowBounds: Rect, + val insets: Insets +) { + companion object { + + private const val LARGE_SCREEN_MIN_EDGE_DP = 600 + private const val SMALL_TABLET_MAX_EDGE_DP = 960 + + @JvmStatic + fun create(context: Context, windowManager: WindowManager): DeviceConfig { + val windowMetrics = windowManager.currentWindowMetrics + val metricInsets = windowMetrics.windowInsets + val insets = metricInsets.getInsetsIgnoringVisibility(WindowInsets.Type.navigationBars() + or WindowInsets.Type.statusBars() + or WindowInsets.Type.displayCutout()) + val windowBounds = windowMetrics.bounds + val config: Configuration = context.resources.configuration + val isLargeScreen = config.smallestScreenWidthDp >= LARGE_SCREEN_MIN_EDGE_DP + val largestEdgeDp = max(config.screenWidthDp, config.screenHeightDp) + val isSmallTablet = isLargeScreen && largestEdgeDp < SMALL_TABLET_MAX_EDGE_DP + val isLandscape = context.resources.configuration.orientation == ORIENTATION_LANDSCAPE + val isRtl = context.resources.configuration.layoutDirection == LAYOUT_DIRECTION_RTL + return DeviceConfig( + isLargeScreen = isLargeScreen, + isSmallTablet = isSmallTablet, + isLandscape = isLandscape, + isRtl = isRtl, + windowBounds = windowBounds, + insets = insets + ) + } + } +} diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarLayerView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarLayerView.java index e788341df5f8..92cb436528cc 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarLayerView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarLayerView.java @@ -28,13 +28,16 @@ import android.graphics.drawable.ColorDrawable; import android.view.TouchDelegate; import android.view.View; import android.view.ViewTreeObserver; +import android.view.WindowManager; import android.widget.FrameLayout; import com.android.wm.shell.bubbles.BubbleController; import com.android.wm.shell.bubbles.BubbleOverflow; import com.android.wm.shell.bubbles.BubblePositioner; import com.android.wm.shell.bubbles.BubbleViewProvider; +import com.android.wm.shell.bubbles.DeviceConfig; +import java.util.Objects; import java.util.function.Consumer; import kotlin.Unit; @@ -104,7 +107,8 @@ public class BubbleBarLayerView extends FrameLayout @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - mPositioner.update(); + WindowManager windowManager = mContext.getSystemService(WindowManager.class); + mPositioner.update(DeviceConfig.create(mContext, Objects.requireNonNull(windowManager))); getViewTreeObserver().addOnComputeInternalInsetsListener(this); } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubbleDataTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubbleDataTest.java index 26c73946c1c6..4bca96b187b5 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubbleDataTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubbleDataTest.java @@ -192,7 +192,7 @@ public class BubbleDataTest extends ShellTestCase { mMainExecutor); mPositioner = new TestableBubblePositioner(mContext, - mock(WindowManager.class)); + mContext.getSystemService(WindowManager.class)); mBubbleData = new BubbleData(getContext(), mBubbleLogger, mPositioner, mEducationController, mMainExecutor); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubbleOverflowTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubbleOverflowTest.java index cb29a21e2f5b..f5b0174642d1 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubbleOverflowTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubbleOverflowTest.java @@ -53,7 +53,8 @@ public class BubbleOverflowTest extends ShellTestCase { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - mPositioner = new TestableBubblePositioner(mContext, mock(WindowManager.class)); + mPositioner = new TestableBubblePositioner(mContext, + mContext.getSystemService(WindowManager.class)); when(mBubbleController.getPositioner()).thenReturn(mPositioner); when(mBubbleController.getStackView()).thenReturn(mock(BubbleStackView.class)); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubblePositionerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubblePositionerTest.java index 287a97c9b5b0..835ebe2206ad 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubblePositionerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubblePositionerTest.java @@ -16,33 +16,17 @@ package com.android.wm.shell.bubbles; -import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; -import static android.content.res.Configuration.ORIENTATION_PORTRAIT; -import static android.view.View.LAYOUT_DIRECTION_LTR; -import static android.view.View.LAYOUT_DIRECTION_RTL; - import static com.google.common.truth.Truth.assertThat; import static com.google.common.util.concurrent.MoreExecutors.directExecutor; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - import android.content.Intent; -import android.content.res.Configuration; import android.graphics.Insets; import android.graphics.PointF; import android.graphics.Rect; import android.graphics.RectF; import android.os.UserHandle; import android.testing.AndroidTestingRunner; -import android.testing.TestableLooper; -import android.testing.TestableResources; -import android.util.DisplayMetrics; -import android.view.WindowInsets; import android.view.WindowManager; -import android.view.WindowMetrics; import androidx.test.filters.SmallTest; @@ -52,36 +36,20 @@ import com.android.wm.shell.ShellTestCase; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; /** * Tests operations and the resulting state managed by {@link BubblePositioner}. */ @SmallTest @RunWith(AndroidTestingRunner.class) -@TestableLooper.RunWithLooper(setAsMainLooper = true) public class BubblePositionerTest extends ShellTestCase { - private static final int MIN_WIDTH_FOR_TABLET = 600; - private BubblePositioner mPositioner; - private Configuration mConfiguration; - - @Mock - private WindowManager mWindowManager; - @Mock - private WindowMetrics mWindowMetrics; @Before public void setUp() { - MockitoAnnotations.initMocks(this); - - mConfiguration = spy(new Configuration()); - TestableResources testableResources = mContext.getOrCreateTestableResources(); - testableResources.overrideConfiguration(mConfiguration); - - mPositioner = new BubblePositioner(mContext, mWindowManager); + WindowManager windowManager = mContext.getSystemService(WindowManager.class); + mPositioner = new BubblePositioner(mContext, windowManager); } @Test @@ -91,11 +59,11 @@ public class BubblePositionerTest extends ShellTestCase { Rect availableRect = new Rect(screenBounds); availableRect.inset(insets); - new WindowManagerConfig() + DeviceConfig deviceConfig = new ConfigBuilder() .setInsets(insets) .setScreenBounds(screenBounds) - .setUpConfig(); - mPositioner.update(); + .build(); + mPositioner.update(deviceConfig); assertThat(mPositioner.getAvailableRect()).isEqualTo(availableRect); assertThat(mPositioner.isLandscape()).isFalse(); @@ -105,16 +73,16 @@ public class BubblePositionerTest extends ShellTestCase { @Test public void testShowBubblesVertically_phonePortrait() { - new WindowManagerConfig().setOrientation(ORIENTATION_PORTRAIT).setUpConfig(); - mPositioner.update(); + DeviceConfig deviceConfig = new ConfigBuilder().build(); + mPositioner.update(deviceConfig); assertThat(mPositioner.showBubblesVertically()).isFalse(); } @Test public void testShowBubblesVertically_phoneLandscape() { - new WindowManagerConfig().setOrientation(ORIENTATION_LANDSCAPE).setUpConfig(); - mPositioner.update(); + DeviceConfig deviceConfig = new ConfigBuilder().setLandscape().build(); + mPositioner.update(deviceConfig); assertThat(mPositioner.isLandscape()).isTrue(); assertThat(mPositioner.showBubblesVertically()).isTrue(); @@ -122,8 +90,8 @@ public class BubblePositionerTest extends ShellTestCase { @Test public void testShowBubblesVertically_tablet() { - new WindowManagerConfig().setLargeScreen().setUpConfig(); - mPositioner.update(); + DeviceConfig deviceConfig = new ConfigBuilder().setLargeScreen().build(); + mPositioner.update(deviceConfig); assertThat(mPositioner.showBubblesVertically()).isTrue(); } @@ -131,8 +99,8 @@ public class BubblePositionerTest extends ShellTestCase { /** If a resting position hasn't been set, calling it will return the default position. */ @Test public void testGetRestingPosition_returnsDefaultPosition() { - new WindowManagerConfig().setUpConfig(); - mPositioner.update(); + DeviceConfig deviceConfig = new ConfigBuilder().build(); + mPositioner.update(deviceConfig); PointF restingPosition = mPositioner.getRestingPosition(); PointF defaultPosition = mPositioner.getDefaultStartPosition(); @@ -143,8 +111,8 @@ public class BubblePositionerTest extends ShellTestCase { /** If a resting position has been set, it'll return that instead of the default position. */ @Test public void testGetRestingPosition_returnsRestingPosition() { - new WindowManagerConfig().setUpConfig(); - mPositioner.update(); + DeviceConfig deviceConfig = new ConfigBuilder().build(); + mPositioner.update(deviceConfig); PointF restingPosition = new PointF(100, 100); mPositioner.setRestingPosition(restingPosition); @@ -155,8 +123,8 @@ public class BubblePositionerTest extends ShellTestCase { /** Test that the default resting position on phone is in upper left. */ @Test public void testGetRestingPosition_bubble_onPhone() { - new WindowManagerConfig().setUpConfig(); - mPositioner.update(); + DeviceConfig deviceConfig = new ConfigBuilder().build(); + mPositioner.update(deviceConfig); RectF allowableStackRegion = mPositioner.getAllowableStackPositionRegion(1 /* bubbleCount */); @@ -168,8 +136,8 @@ public class BubblePositionerTest extends ShellTestCase { @Test public void testGetRestingPosition_bubble_onPhone_RTL() { - new WindowManagerConfig().setLayoutDirection(LAYOUT_DIRECTION_RTL).setUpConfig(); - mPositioner.update(); + DeviceConfig deviceConfig = new ConfigBuilder().setRtl().build(); + mPositioner.update(deviceConfig); RectF allowableStackRegion = mPositioner.getAllowableStackPositionRegion(1 /* bubbleCount */); @@ -182,8 +150,8 @@ public class BubblePositionerTest extends ShellTestCase { /** Test that the default resting position on tablet is middle left. */ @Test public void testGetRestingPosition_chatBubble_onTablet() { - new WindowManagerConfig().setLargeScreen().setUpConfig(); - mPositioner.update(); + DeviceConfig deviceConfig = new ConfigBuilder().setLargeScreen().build(); + mPositioner.update(deviceConfig); RectF allowableStackRegion = mPositioner.getAllowableStackPositionRegion(1 /* bubbleCount */); @@ -195,9 +163,8 @@ public class BubblePositionerTest extends ShellTestCase { @Test public void testGetRestingPosition_chatBubble_onTablet_RTL() { - new WindowManagerConfig().setLargeScreen().setLayoutDirection( - LAYOUT_DIRECTION_RTL).setUpConfig(); - mPositioner.update(); + DeviceConfig deviceConfig = new ConfigBuilder().setLargeScreen().setRtl().build(); + mPositioner.update(deviceConfig); RectF allowableStackRegion = mPositioner.getAllowableStackPositionRegion(1 /* bubbleCount */); @@ -210,8 +177,8 @@ public class BubblePositionerTest extends ShellTestCase { /** Test that the default resting position on tablet is middle right. */ @Test public void testGetDefaultPosition_appBubble_onTablet() { - new WindowManagerConfig().setLargeScreen().setUpConfig(); - mPositioner.update(); + DeviceConfig deviceConfig = new ConfigBuilder().setLargeScreen().build(); + mPositioner.update(deviceConfig); RectF allowableStackRegion = mPositioner.getAllowableStackPositionRegion(1 /* bubbleCount */); @@ -223,9 +190,8 @@ public class BubblePositionerTest extends ShellTestCase { @Test public void testGetRestingPosition_appBubble_onTablet_RTL() { - new WindowManagerConfig().setLargeScreen().setLayoutDirection( - LAYOUT_DIRECTION_RTL).setUpConfig(); - mPositioner.update(); + DeviceConfig deviceConfig = new ConfigBuilder().setLargeScreen().setRtl().build(); + mPositioner.update(deviceConfig); RectF allowableStackRegion = mPositioner.getAllowableStackPositionRegion(1 /* bubbleCount */); @@ -237,9 +203,8 @@ public class BubblePositionerTest extends ShellTestCase { @Test public void testHasUserModifiedDefaultPosition_false() { - new WindowManagerConfig().setLargeScreen().setLayoutDirection( - LAYOUT_DIRECTION_RTL).setUpConfig(); - mPositioner.update(); + DeviceConfig deviceConfig = new ConfigBuilder().setLargeScreen().setRtl().build(); + mPositioner.update(deviceConfig); assertThat(mPositioner.hasUserModifiedDefaultPosition()).isFalse(); @@ -250,9 +215,8 @@ public class BubblePositionerTest extends ShellTestCase { @Test public void testHasUserModifiedDefaultPosition_true() { - new WindowManagerConfig().setLargeScreen().setLayoutDirection( - LAYOUT_DIRECTION_RTL).setUpConfig(); - mPositioner.update(); + DeviceConfig deviceConfig = new ConfigBuilder().setLargeScreen().setRtl().build(); + mPositioner.update(deviceConfig); assertThat(mPositioner.hasUserModifiedDefaultPosition()).isFalse(); @@ -266,12 +230,12 @@ public class BubblePositionerTest extends ShellTestCase { Insets insets = Insets.of(10, 20, 5, 15); Rect screenBounds = new Rect(0, 0, 1800, 2600); - new WindowManagerConfig() + DeviceConfig deviceConfig = new ConfigBuilder() .setLargeScreen() .setInsets(insets) .setScreenBounds(screenBounds) - .setUpConfig(); - mPositioner.update(); + .build(); + mPositioner.update(deviceConfig); Intent intent = new Intent(Intent.ACTION_VIEW).setPackage(mContext.getPackageName()); Bubble bubble = Bubble.createAppBubble(intent, new UserHandle(1), null, directExecutor()); @@ -311,58 +275,47 @@ public class BubblePositionerTest extends ShellTestCase { * Sets up window manager to return config values based on what you need for the test. * By default it sets up a portrait phone without any insets. */ - private class WindowManagerConfig { + private static class ConfigBuilder { private Rect mScreenBounds = new Rect(0, 0, 1000, 2000); private boolean mIsLargeScreen = false; - private int mOrientation = ORIENTATION_PORTRAIT; - private int mLayoutDirection = LAYOUT_DIRECTION_LTR; + private boolean mIsSmallTablet = false; + private boolean mIsLandscape = false; + private boolean mIsRtl = false; private Insets mInsets = Insets.of(0, 0, 0, 0); - public WindowManagerConfig setScreenBounds(Rect screenBounds) { + public ConfigBuilder setScreenBounds(Rect screenBounds) { mScreenBounds = screenBounds; return this; } - public WindowManagerConfig setLargeScreen() { + public ConfigBuilder setLargeScreen() { mIsLargeScreen = true; return this; } - public WindowManagerConfig setOrientation(int orientation) { - mOrientation = orientation; + public ConfigBuilder setSmallTablet() { + mIsSmallTablet = true; return this; } - public WindowManagerConfig setLayoutDirection(int layoutDirection) { - mLayoutDirection = layoutDirection; + public ConfigBuilder setLandscape() { + mIsLandscape = true; return this; } - public WindowManagerConfig setInsets(Insets insets) { - mInsets = insets; + public ConfigBuilder setRtl() { + mIsRtl = true; return this; } - public void setUpConfig() { - mConfiguration.smallestScreenWidthDp = mIsLargeScreen - ? MIN_WIDTH_FOR_TABLET - : MIN_WIDTH_FOR_TABLET - 1; - mConfiguration.orientation = mOrientation; - mConfiguration.screenWidthDp = pxToDp(mScreenBounds.width()); - mConfiguration.screenHeightDp = pxToDp(mScreenBounds.height()); - - when(mConfiguration.getLayoutDirection()).thenReturn(mLayoutDirection); - WindowInsets windowInsets = mock(WindowInsets.class); - when(windowInsets.getInsetsIgnoringVisibility(anyInt())).thenReturn(mInsets); - when(mWindowMetrics.getWindowInsets()).thenReturn(windowInsets); - when(mWindowMetrics.getBounds()).thenReturn(mScreenBounds); - when(mWindowManager.getCurrentWindowMetrics()).thenReturn(mWindowMetrics); + public ConfigBuilder setInsets(Insets insets) { + mInsets = insets; + return this; } - private int pxToDp(float px) { - int dpi = mContext.getResources().getDisplayMetrics().densityDpi; - float dp = px / ((float) dpi / DisplayMetrics.DENSITY_DEFAULT); - return (int) dp; + private DeviceConfig build() { + return new DeviceConfig(mIsLargeScreen, mIsSmallTablet, mIsLandscape, mIsRtl, + mScreenBounds, mInsets); } } } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubblesNavBarMotionEventHandlerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubblesNavBarMotionEventHandlerTest.java index 44ff35466ae2..c4b9c9ba43f1 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubblesNavBarMotionEventHandlerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubblesNavBarMotionEventHandlerTest.java @@ -55,8 +55,6 @@ public class BubblesNavBarMotionEventHandlerTest extends ShellTestCase { private BubblesNavBarMotionEventHandler mMotionEventHandler; @Mock - private WindowManager mWindowManager; - @Mock private Runnable mInterceptTouchRunnable; @Mock private MotionEventListener mMotionEventListener; @@ -66,7 +64,7 @@ public class BubblesNavBarMotionEventHandlerTest extends ShellTestCase { public void setUp() { MockitoAnnotations.initMocks(this); TestableBubblePositioner positioner = new TestableBubblePositioner(getContext(), - mWindowManager); + getContext().getSystemService(WindowManager.class)); mMotionEventHandler = new BubblesNavBarMotionEventHandler(getContext(), positioner, mInterceptTouchRunnable, mMotionEventListener); mMotionEventTime = SystemClock.uptimeMillis(); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/animation/ExpandedAnimationControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/animation/ExpandedAnimationControllerTest.java index 335222e98c6c..6403e794a33e 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/animation/ExpandedAnimationControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/animation/ExpandedAnimationControllerTest.java @@ -66,7 +66,8 @@ public class ExpandedAnimationControllerTest extends PhysicsAnimationLayoutTestC public void setUp() throws Exception { super.setUp(); - mPositioner = new BubblePositioner(getContext(), mock(WindowManager.class)); + mPositioner = new BubblePositioner(getContext(), + getContext().getSystemService(WindowManager.class)); mPositioner.updateInternal(Configuration.ORIENTATION_PORTRAIT, Insets.of(0, 0, 0, 0), new Rect(0, 0, mDisplayWidth, mDisplayHeight)); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/animation/ExpandedViewAnimationControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/animation/ExpandedViewAnimationControllerTest.java index 991913afbb90..f6609872852f 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/animation/ExpandedViewAnimationControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/animation/ExpandedViewAnimationControllerTest.java @@ -50,9 +50,6 @@ public class ExpandedViewAnimationControllerTest extends ShellTestCase { private ExpandedViewAnimationController mController; @Mock - private WindowManager mWindowManager; - - @Mock private BubbleExpandedView mMockExpandedView; @Before @@ -60,7 +57,7 @@ public class ExpandedViewAnimationControllerTest extends ShellTestCase { MockitoAnnotations.initMocks(this); TestableBubblePositioner positioner = new TestableBubblePositioner(getContext(), - mWindowManager); + getContext().getSystemService(WindowManager.class)); mController = new ExpandedViewAnimationControllerImpl(getContext(), positioner); mController.setExpandedView(mMockExpandedView); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/animation/StackAnimationControllerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/animation/StackAnimationControllerTest.java index 31fafcaab7cc..0c22908be9eb 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/animation/StackAnimationControllerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/animation/StackAnimationControllerTest.java @@ -313,7 +313,8 @@ public class StackAnimationControllerTest extends PhysicsAnimationLayoutTestCase bubbleCountSupplier, onBubbleAnimatedOutAction, onStackAnimationFinished, - new TestableBubblePositioner(mContext, mock(WindowManager.class))); + new TestableBubblePositioner(mContext, + mContext.getSystemService(WindowManager.class))); } @Override |