From 34024fe26a17483b6bd2e9b7fbdfaf5e91c3938c Mon Sep 17 00:00:00 2001 From: Liran Binyamin Date: Thu, 1 May 2025 14:33:01 -0400 Subject: [PATCH] Send bubble bar distance to shell We previously sent the top coordinate of the bubble bar to shell. However when the screen height changes, launcher takes a bit longer to update than shell. So instead of calculating the top coordinate on the launcher side, we now send the amount of space between the bubble bar and the bottom of the screen to shell, where we can offset that as needed. Bug: 392893178 Flag: com.android.wm.shell.enable_bubble_bar Test: manual - send some bubbles - launch app - expand - swipe to home - fold and unfold Change-Id: I57b96db49dab1e2304fde8dc55a99eaaf85e40f8 --- .../taskbar/bubbles/BubbleBarController.java | 15 +++++------ .../taskbar/bubbles/BubbleBarView.java | 17 ++++++------ .../bubbles/BubbleBarViewController.java | 10 +++---- .../com/android/quickstep/SystemUiProxy.kt | 27 ++++++++++--------- .../bubbles/BubbleBarViewScreenshotTest.kt | 2 -- .../PersistentBubbleStashControllerTest.kt | 2 -- .../TransientBubbleStashControllerTest.kt | 2 -- .../animation/BubbleBarViewAnimatorTest.kt | 2 -- 8 files changed, 33 insertions(+), 44 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java index b6a0ffe53c..5b641e9bb0 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java @@ -123,8 +123,7 @@ public class BubbleBarController extends IBubblesListener.Stub { private BubbleCreator mBubbleCreator; private BubbleBarLocationListener mBubbleBarLocationListener; - // Cache last sent top coordinate to avoid sending duplicate updates to shell - private int mLastSentBubbleBarTop; + private int mLastSentBubbleBarTopToScreenBottom; private boolean mIsImeVisible = false; @@ -531,8 +530,8 @@ public class BubbleBarController extends IBubblesListener.Stub { /** Tells WMShell to show the currently selected bubble. */ public void showSelectedBubble() { if (getSelectedBubbleKey() != null) { - mLastSentBubbleBarTop = mBarView.getRestingTopPositionOnScreen(); - mSystemUiProxy.showBubble(getSelectedBubbleKey(), mLastSentBubbleBarTop); + mLastSentBubbleBarTopToScreenBottom = mBarView.getTopToScreenBottom(); + mSystemUiProxy.showBubble(getSelectedBubbleKey(), mLastSentBubbleBarTopToScreenBottom); } else { Log.w(TAG, "Trying to show the selected bubble but it's null"); } @@ -630,10 +629,10 @@ public class BubbleBarController extends IBubblesListener.Stub { } private void onBubbleBarBoundsChanged(boolean forceUpdate) { - int newTop = mBarView.getRestingTopPositionOnScreen(); - if (newTop != mLastSentBubbleBarTop || forceUpdate) { - mLastSentBubbleBarTop = newTop; - mSystemUiProxy.updateBubbleBarTopOnScreen(newTop); + int bubbleBarTopToScreenBottom = mBarView.getTopToScreenBottom(); + if (bubbleBarTopToScreenBottom != mLastSentBubbleBarTopToScreenBottom || forceUpdate) { + mLastSentBubbleBarTopToScreenBottom = bubbleBarTopToScreenBottom; + mSystemUiProxy.updateBubbleBarTopToScreenBottom(bubbleBarTopToScreenBottom); } } diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java index f104d93094..c1cddd06d1 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java @@ -651,13 +651,15 @@ public class BubbleBarView extends FrameLayout { } } - /** - * Get bubble bar top coordinate on screen when bar is resting - */ - public int getRestingTopPositionOnScreen() { - int displayHeight = mController.getScreenHeight(); + /** Get the distance between the bubble bar top coordinate and the bottom of the screen */ + public int getTopToScreenBottom() { + // the bottom of the bubble bar is aligned with the bottom of the screen. the distance + // between the top of the bubble bar and the bottom of the screen is the height of the + // bubble bar minus the y translation. since the bubble bar is always above the bottom of + // the screen, the translation is negative and the overall result is a positive value that + // represents the distance int bubbleBarHeight = getBubbleBarBounds().height(); - return displayHeight - bubbleBarHeight + (int) mController.getBubbleBarTranslationY(); + return bubbleBarHeight - (int) mController.getBubbleBarTranslationY(); } /** Returns the bounds with translation that may have been applied. */ @@ -1646,9 +1648,6 @@ public class BubbleBarView extends FrameLayout { /** Interface for BubbleBarView to communicate with its controller. */ public interface Controller { - /** Returns the screen height. */ - int getScreenHeight(); - /** Returns the translation Y that the bubble bar should have. */ float getBubbleBarTranslationY(); diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java index c74140a8fe..82cd3d86e4 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java @@ -280,11 +280,6 @@ public class BubbleBarViewController { : PINNING_PERSISTENT; mBubbleBarPinning.updateValue(pinningValue); mBarView.setController(new BubbleBarView.Controller() { - @Override - public int getScreenHeight() { - return mActivity.getScreenSize().y; - } - @Override public float getBubbleBarTranslationY() { return mBubbleStashController.getBubbleBarTranslationY(); @@ -741,7 +736,8 @@ public class BubbleBarViewController { public boolean isEventOverBubbleBar(MotionEvent event) { if (!isBubbleBarVisible()) return false; final Rect bounds = getBubbleBarBounds(); - final int bubbleBarTopOnScreen = mBarView.getRestingTopPositionOnScreen(); + final int bubbleBarTopOnScreen = + mActivity.getScreenSize().y - mBarView.getTopToScreenBottom(); final float x = event.getX(); return event.getRawY() >= bubbleBarTopOnScreen && x >= bounds.left && x <= bounds.right; } @@ -1336,7 +1332,7 @@ public class BubbleBarViewController { * Notifies SystemUI to expand the selected bubble when the bubble is released. */ public void onBubbleDragRelease(BubbleBarLocation location) { - mSystemUiProxy.stopBubbleDrag(location, mBarView.getRestingTopPositionOnScreen()); + mSystemUiProxy.stopBubbleDrag(location, mBarView.getTopToScreenBottom()); } /** Handle given bubble being dismissed */ diff --git a/quickstep/src/com/android/quickstep/SystemUiProxy.kt b/quickstep/src/com/android/quickstep/SystemUiProxy.kt index a7b9d41828..8abc9a592b 100644 --- a/quickstep/src/com/android/quickstep/SystemUiProxy.kt +++ b/quickstep/src/com/android/quickstep/SystemUiProxy.kt @@ -574,10 +574,13 @@ class SystemUiProxy @Inject constructor(@ApplicationContext private val context: * Tells SysUI to show the bubble with the provided key. * * @param key the key of the bubble to show. - * @param top top coordinate of bubble bar on screen + * @param bubbleBarTopToScreenBottom distance between the top coordinate of bubble bar and the + * bottom of the screen */ - fun showBubble(key: String?, top: Int) = - executeWithErrorLog({ "Failed call showBubble" }) { bubbles?.showBubble(key, top) } + fun showBubble(key: String?, bubbleBarTopToScreenBottom: Int) = + executeWithErrorLog({ "Failed call showBubble" }) { + bubbles?.showBubble(key, bubbleBarTopToScreenBottom) + } /** Tells SysUI to remove all bubbles. */ fun removeAllBubbles() = @@ -603,11 +606,12 @@ class SystemUiProxy @Inject constructor(@ApplicationContext private val context: * expanded. * * @param location location of the bubble bar - * @param top new top coordinate for bubble bar on screen + * @param bubbleBarTopToScreenBottom distance between the new top coordinate for bubble bar and + * the bottom of the screen */ - fun stopBubbleDrag(location: BubbleBarLocation?, top: Int) = + fun stopBubbleDrag(location: BubbleBarLocation?, bubbleBarTopToScreenBottom: Int) = executeWithErrorLog({ "Failed call stopBubbleDrag" }) { - bubbles?.stopBubbleDrag(location, top) + bubbles?.stopBubbleDrag(location, bubbleBarTopToScreenBottom) } /** @@ -643,13 +647,12 @@ class SystemUiProxy @Inject constructor(@ApplicationContext private val context: } /** - * Tells SysUI the top coordinate of bubble bar on screen - * - * @param topOnScreen top coordinate for bubble bar on screen + * Tells SysUI the distance between the top coordinate of the bubble bar and the bottom of the + * screen */ - fun updateBubbleBarTopOnScreen(topOnScreen: Int) = - executeWithErrorLog({ "Failed call updateBubbleBarTopOnScreen" }) { - bubbles?.updateBubbleBarTopOnScreen(topOnScreen) + fun updateBubbleBarTopToScreenBottom(bubbleBarTopToScreenBottom: Int) = + executeWithErrorLog({ "Failed call updateBubbleBarTopToScreenBottom" }) { + bubbles?.updateBubbleBarTopToScreenBottom(bubbleBarTopToScreenBottom) } /** diff --git a/quickstep/tests/multivalentScreenshotTests/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewScreenshotTest.kt b/quickstep/tests/multivalentScreenshotTests/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewScreenshotTest.kt index a206d4e18b..5325d506f3 100644 --- a/quickstep/tests/multivalentScreenshotTests/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewScreenshotTest.kt +++ b/quickstep/tests/multivalentScreenshotTests/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewScreenshotTest.kt @@ -127,8 +127,6 @@ class BubbleBarViewScreenshotTest(emulationSpec: DeviceEmulationSpec) { bubbleBarView.setPadding(0, paddingTop, 0, 0) bubbleBarView.setController( object : BubbleBarView.Controller { - override fun getScreenHeight(): Int = 0 - override fun getBubbleBarTranslationY(): Float = 0f override fun onBubbleBarTouched() {} diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashControllerTest.kt index 4f88ec1544..0421a13aec 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashControllerTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashControllerTest.kt @@ -394,8 +394,6 @@ class PersistentBubbleStashControllerTest { bubbleBarView.layoutParams = FrameLayout.LayoutParams(0, 0) bubbleBarView.setController( object : BubbleBarView.Controller { - override fun getScreenHeight(): Int = 0 - override fun getBubbleBarTranslationY(): Float = 0f override fun onBubbleBarTouched() {} diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashControllerTest.kt index c721af0a0f..f0822dac93 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashControllerTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashControllerTest.kt @@ -559,8 +559,6 @@ class TransientBubbleStashControllerTest { FrameLayout.LayoutParams(BUBBLE_BAR_WIDTH, BUBBLE_BAR_HEIGHT) bubbleBarView.setController( object : BubbleBarView.Controller { - override fun getScreenHeight(): Int = 0 - override fun getBubbleBarTranslationY(): Float = 0f override fun onBubbleBarTouched() {} diff --git a/quickstep/tests/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimatorTest.kt b/quickstep/tests/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimatorTest.kt index 3e6d53f545..0a9ee2c8b6 100644 --- a/quickstep/tests/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimatorTest.kt +++ b/quickstep/tests/src/com/android/launcher3/taskbar/bubbles/animation/BubbleBarViewAnimatorTest.kt @@ -1398,8 +1398,6 @@ class BubbleBarViewAnimatorTest { bubbleBarView = BubbleBarView(context) bubbleBarView.setController( object : BubbleBarView.Controller { - override fun getScreenHeight(): Int = 0 - override fun getBubbleBarTranslationY(): Float = 0f override fun onBubbleBarTouched() {}