diff --git a/core/java/android/view/IPinnedStackListener.aidl b/core/java/android/view/IPinnedStackListener.aidl index 806d81e39cca9..f4bee575f811c 100644 --- a/core/java/android/view/IPinnedStackListener.aidl +++ b/core/java/android/view/IPinnedStackListener.aidl @@ -54,14 +54,6 @@ oneway interface IPinnedStackListener { */ void onImeVisibilityChanged(boolean imeVisible, int imeHeight); - /** - * Called when window manager decides to adjust the pinned stack bounds because of the shelf, or - * when the listener is first registered to allow the listener to synchronized its state with - * the controller. This call will always be followed by a onMovementBoundsChanged() call - * with fromShelfAdjustment set to {@code true}. - */ - void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight); - /** * Called when window manager decides to adjust the minimized state, or when the listener * is first registered to allow the listener to synchronized its state with the controller. diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl index 1c3294858db8a..49e8800a36c6a 100644 --- a/core/java/android/view/IWindowManager.aidl +++ b/core/java/android/view/IWindowManager.aidl @@ -325,12 +325,6 @@ interface IWindowManager */ oneway void setPipVisibility(boolean visible); - /** - * Called by System UI to notify of changes to the visibility and height of the shelf. - */ - @UnsupportedAppUsage - void setShelfHeight(boolean visible, int shelfHeight); - /** * Called by System UI to enable or disable haptic feedback on the navigation bar buttons. */ diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl index 9228b178c76f6..1cabee1ae6793 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/ISystemUiProxy.aidl @@ -109,4 +109,9 @@ interface ISystemUiProxy { * Ends the system screen pinning. */ void stopScreenPinning() = 17; + + /** + * Sets the shelf height and visibility. + */ + void setShelfHeight(boolean visible, int shelfHeight) = 20; } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/PinnedStackListenerForwarder.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/PinnedStackListenerForwarder.java index 2797042ac1604..fe5a57a277a48 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/PinnedStackListenerForwarder.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/PinnedStackListenerForwarder.java @@ -68,13 +68,6 @@ public class PinnedStackListenerForwarder extends IPinnedStackListener.Stub { } } - @Override - public void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight) { - for (PinnedStackListener listener : mListeners) { - listener.onShelfVisibilityChanged(shelfVisible, shelfHeight); - } - } - @Override public void onMinimizedStateChanged(boolean isMinimized) { for (PinnedStackListener listener : mListeners) { @@ -143,8 +136,6 @@ public class PinnedStackListenerForwarder extends IPinnedStackListener.Stub { public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) {} - public void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight) {} - public void onMinimizedStateChanged(boolean isMinimized) {} public void onActionsChanged(ParceledListSlice actions) {} diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/WindowManagerWrapper.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/WindowManagerWrapper.java index 9f1a1fafeec6e..ad182fe57f81a 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/WindowManagerWrapper.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/WindowManagerWrapper.java @@ -143,14 +143,6 @@ public class WindowManagerWrapper { } } - public void setShelfHeight(boolean visible, int shelfHeight) { - try { - WindowManagerGlobal.getWindowManagerService().setShelfHeight(visible, shelfHeight); - } catch (RemoteException e) { - Log.w(TAG, "Failed to set shelf height"); - } - } - public void setRecentsVisibility(boolean visible) { try { WindowManagerGlobal.getWindowManagerService().setRecentsVisibility(visible); diff --git a/packages/SystemUI/src/com/android/systemui/pip/BasePipManager.java b/packages/SystemUI/src/com/android/systemui/pip/BasePipManager.java index e0fc31bc70b8b..05be4259dd3bb 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/BasePipManager.java +++ b/packages/SystemUI/src/com/android/systemui/pip/BasePipManager.java @@ -27,5 +27,6 @@ public interface BasePipManager { default void expandPip() {} default void hidePipMenu(Runnable onStartCallback, Runnable onEndCallback) {} void onConfigurationChanged(Configuration newConfig); + default void setShelfHeight(boolean visible, int height) {} default void dump(PrintWriter pw) {} } diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java b/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java index 6795bff6409ab..686e7db86c3bf 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java +++ b/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java @@ -55,6 +55,12 @@ public class PipBoundsHandler { private final Rect mTmpInsets = new Rect(); private final Point mTmpDisplaySize = new Point(); + /** + * Tracks the destination bounds, used for any following + * {@link #onMovementBoundsChanged(Rect, Rect, Rect, DisplayInfo)} calculations. + */ + private final Rect mLastDestinationBounds = new Rect(); + private IPinnedStackController mPinnedStackController; private ComponentName mLastPipComponentName; private float mReentrySnapFraction = INVALID_SNAP_FRACTION; @@ -119,6 +125,21 @@ public class PipBoundsHandler { mCurrentMinSize = minEdgeSize; } + /** + * Sets both shelf visibility and its height if applicable. + * @return {@code true} if the internal shelf state is changed, {@code false} otherwise. + */ + public boolean setShelfHeight(boolean shelfVisible, int shelfHeight) { + final boolean shelfShowing = shelfVisible && shelfHeight > 0; + if (shelfShowing == mIsShelfShowing && shelfHeight == mShelfHeight) { + return false; + } + + mIsShelfShowing = shelfVisible; + mShelfHeight = shelfHeight; + return true; + } + /** * Responds to IPinnedStackListener on IME visibility change. */ @@ -127,14 +148,6 @@ public class PipBoundsHandler { mImeHeight = imeHeight; } - /** - * Responds to IPinnedStackListener on shelf visibility change. - */ - public void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight) { - mIsShelfShowing = shelfVisible; - mShelfHeight = shelfHeight; - } - /** * Responds to IPinnedStackListener on minimized state change. */ @@ -185,6 +198,10 @@ public class PipBoundsHandler { mLastPipComponentName = null; } + public Rect getLastDestinationBounds() { + return mLastDestinationBounds; + } + /** * Responds to IPinnedStackListener on {@link DisplayInfo} change. * It will normally follow up with a @@ -232,6 +249,7 @@ public class PipBoundsHandler { try { mPinnedStackController.startAnimation(destinationBounds, sourceRectHint, -1 /* animationDuration */); + mLastDestinationBounds.set(destinationBounds); } catch (RemoteException e) { Log.e(TAG, "Failed to start PiP animation from SysUI", e); } diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipUI.java b/packages/SystemUI/src/com/android/systemui/pip/PipUI.java index 37c8163702cf0..682c76c6136a7 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/PipUI.java +++ b/packages/SystemUI/src/com/android/systemui/pip/PipUI.java @@ -85,6 +85,14 @@ public class PipUI extends SystemUI implements CommandQueue.Callbacks { mPipManager.onConfigurationChanged(newConfig); } + public void setShelfHeight(boolean visible, int height) { + if (mPipManager == null) { + return; + } + + mPipManager.setShelfHeight(visible, height); + } + @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (mPipManager == null) { diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java index 8dfae32a19395..369073c6564dc 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java @@ -142,14 +142,6 @@ public class PipManager implements BasePipManager { }); } - @Override - public void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight) { - mHandler.post(() -> { - mPipBoundsHandler.onShelfVisibilityChanged(shelfVisible, shelfHeight); - mTouchHandler.onShelfVisibilityChanged(shelfVisible, shelfHeight); - }); - } - @Override public void onMinimizedStateChanged(boolean isMinimized) { mHandler.post(() -> { @@ -161,14 +153,8 @@ public class PipManager implements BasePipManager { @Override public void onMovementBoundsChanged(Rect animatingBounds, boolean fromImeAdjustment, boolean fromShelfAdjustment) { - mHandler.post(() -> { - // Populate the inset / normal bounds and DisplayInfo from mPipBoundsHandler first. - mPipBoundsHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds, - animatingBounds, mTmpDisplayInfo); - mTouchHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds, - animatingBounds, fromImeAdjustment, fromShelfAdjustment, - mTmpDisplayInfo.rotation); - }); + mHandler.post(() -> updateMovementBounds(animatingBounds, fromImeAdjustment, + fromShelfAdjustment)); } @Override @@ -279,6 +265,31 @@ public class PipManager implements BasePipManager { mTouchHandler.showPictureInPictureMenu(); } + /** + * Sets both shelf visibility and its height. + */ + @Override + public void setShelfHeight(boolean visible, int height) { + mHandler.post(() -> { + final boolean changed = mPipBoundsHandler.setShelfHeight(visible, height); + if (changed) { + mTouchHandler.onShelfVisibilityChanged(visible, height); + updateMovementBounds(mPipBoundsHandler.getLastDestinationBounds(), + false /* fromImeAdjustment */, true /* fromShelfAdjustment */); + } + }); + } + + private void updateMovementBounds(Rect animatingBounds, boolean fromImeAdjustment, + boolean fromShelfAdjustment) { + // Populate inset / normal bounds and DisplayInfo from mPipBoundsHandler first. + mPipBoundsHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds, + animatingBounds, mTmpDisplayInfo); + mTouchHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds, + animatingBounds, fromImeAdjustment, fromShelfAdjustment, + mTmpDisplayInfo.rotation); + } + /** * Gets an instance of {@link PipManager}. */ diff --git a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java index 9268ee0705a28..e0ae8ed66f41b 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java +++ b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java @@ -58,6 +58,7 @@ import com.android.internal.policy.ScreenDecorationsUtils; import com.android.systemui.Dumpable; import com.android.systemui.SysUiServiceProvider; import com.android.systemui.model.SysUiState; +import com.android.systemui.pip.PipUI; import com.android.systemui.recents.OverviewProxyService.OverviewProxyListener; import com.android.systemui.shared.recents.IOverviewProxy; import com.android.systemui.shared.recents.ISystemUiProxy; @@ -353,6 +354,20 @@ public class OverviewProxyService implements CallbackController mActions = new ArrayList<>(); @@ -216,7 +214,6 @@ class PinnedStackController { mPinnedStackListener = listener; notifyDisplayInfoChanged(mDisplayInfo); notifyImeVisibilityChanged(mIsImeShowing, mImeHeight); - notifyShelfVisibilityChanged(mIsShelfShowing, mShelfHeight); // The movement bounds notification needs to be sent before the minimized state, since // SystemUI may use the bounds to retore the minimized position notifyMovementBoundsChanged(false /* fromImeAdjustment */, @@ -278,9 +275,7 @@ class PinnedStackController { mSnapAlgorithm.applySnapFraction(defaultBounds, movementBounds, snapFraction); } else { Gravity.apply(mDefaultStackGravity, size.getWidth(), size.getHeight(), insetBounds, - 0, Math.max(mIsImeShowing ? mImeHeight : 0, - mIsShelfShowing ? mShelfHeight : 0), - defaultBounds); + 0, mIsImeShowing ? mImeHeight : 0, defaultBounds); } return defaultBounds; } @@ -366,21 +361,6 @@ class PinnedStackController { notifyMovementBoundsChanged(true /* fromImeAdjustment */, false /* fromShelfAdjustment */); } - /** - * Sets the shelf state and height. - */ - void setAdjustedForShelf(boolean adjustedForShelf, int shelfHeight) { - final boolean shelfShowing = adjustedForShelf && shelfHeight > 0; - if (shelfShowing == mIsShelfShowing && shelfHeight == mShelfHeight) { - return; - } - - mIsShelfShowing = shelfShowing; - mShelfHeight = shelfHeight; - notifyShelfVisibilityChanged(shelfShowing, shelfHeight); - notifyMovementBoundsChanged(false /* fromImeAdjustment */, true /* fromShelfAdjustment */); - } - /** * Sets the current aspect ratio. */ @@ -439,16 +419,6 @@ class PinnedStackController { } } - private void notifyShelfVisibilityChanged(boolean shelfVisible, int shelfHeight) { - if (mPinnedStackListener != null) { - try { - mPinnedStackListener.onShelfVisibilityChanged(shelfVisible, shelfHeight); - } catch (RemoteException e) { - Slog.e(TAG_WM, "Error delivering bounds changed event.", e); - } - } - } - private void notifyAspectRatioChanged(float aspectRatio) { if (mPinnedStackListener == null) return; try { @@ -613,8 +583,6 @@ class PinnedStackController { pw.println(); pw.println(prefix + " mIsImeShowing=" + mIsImeShowing); pw.println(prefix + " mImeHeight=" + mImeHeight); - pw.println(prefix + " mIsShelfShowing=" + mIsShelfShowing); - pw.println(prefix + " mShelfHeight=" + mShelfHeight); pw.println(prefix + " mIsMinimized=" + mIsMinimized); pw.println(prefix + " mAspectRatio=" + mAspectRatio); pw.println(prefix + " mMinAspectRatio=" + mMinAspectRatio); diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 8b227a62ebaaa..b4309c74b3909 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -5593,16 +5593,6 @@ public class WindowManagerService extends IWindowManager.Stub } } - @Override - public void setShelfHeight(boolean visible, int shelfHeight) { - mAtmInternal.enforceCallerIsRecentsOrHasPermission(android.Manifest.permission.STATUS_BAR, - "setShelfHeight()"); - synchronized (mGlobalLock) { - getDefaultDisplayContentLocked().getPinnedStackController().setAdjustedForShelf(visible, - shelfHeight); - } - } - @Override public void statusBarVisibilityChanged(int displayId, int visibility) { if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR) diff --git a/services/tests/wmtests/src/com/android/server/wm/PinnedStackControllerTest.java b/services/tests/wmtests/src/com/android/server/wm/PinnedStackControllerTest.java deleted file mode 100644 index e9c2263401642..0000000000000 --- a/services/tests/wmtests/src/com/android/server/wm/PinnedStackControllerTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2018 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.server.wm; - -import static android.view.Display.DEFAULT_DISPLAY; - -import static com.android.dx.mockito.inline.extended.ExtendedMockito.never; -import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset; -import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify; -import static com.android.dx.mockito.inline.extended.ExtendedMockito.when; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.eq; - -import android.os.RemoteException; -import android.platform.test.annotations.Presubmit; -import android.view.IPinnedStackListener; - -import androidx.test.filters.SmallTest; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -/** - * Build/Install/Run: - * atest FrameworksServicesTests:PinnedStackControllerTest - */ -@SmallTest -@Presubmit -public class PinnedStackControllerTest extends WindowTestsBase { - - private static final int SHELF_HEIGHT = 300; - - @Mock private IPinnedStackListener mIPinnedStackListener; - @Mock private IPinnedStackListener.Stub mIPinnedStackListenerStub; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - - when(mIPinnedStackListener.asBinder()).thenReturn(mIPinnedStackListenerStub); - } - - @Test - public void setShelfHeight_shelfVisibilityChangedTriggered() throws RemoteException { - mWm.mAtmService.mSupportsPictureInPicture = true; - mWm.registerPinnedStackListener(DEFAULT_DISPLAY, mIPinnedStackListener); - - verify(mIPinnedStackListener).onImeVisibilityChanged(false, 0); - verify(mIPinnedStackListener).onShelfVisibilityChanged(false, 0); - verify(mIPinnedStackListener).onMovementBoundsChanged(any(), eq(false), - eq(false)); - verify(mIPinnedStackListener).onActionsChanged(any()); - verify(mIPinnedStackListener).onMinimizedStateChanged(anyBoolean()); - - reset(mIPinnedStackListener); - - mWm.setShelfHeight(true, SHELF_HEIGHT); - verify(mIPinnedStackListener).onShelfVisibilityChanged(true, SHELF_HEIGHT); - verify(mIPinnedStackListener).onMovementBoundsChanged(any(), eq(false), - eq(true)); - verify(mIPinnedStackListener, never()).onImeVisibilityChanged(anyBoolean(), anyInt()); - } -}