From f1de2b6e76ca93fc42da373adfc4f64d034ede50 Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Thu, 3 Dec 2020 12:04:20 -0800 Subject: [PATCH] Cleanup IPinnedStackController and IPinnedStackListener 2/N Deprecates the following - IPinnedStackListener#onConfigurationChanged, switched to use onConfigurationChanged callback in WMShell - IPinnedStackListener#onDisplayInfoChanged, switched to use DisplayChangeController Bug: 174702196 Test: atest WMShellUnitTests Change-Id: Id2161883bd520c99888a561ae058154da06ecb51 --- .../android/view/IPinnedStackListener.aidl | 13 -------- .../pip/PinnedStackListenerForwarder.java | 31 ------------------- .../src/com/android/wm/shell/pip/Pip.java | 7 +++++ .../wm/shell/pip/PipBoundsAlgorithm.java | 4 +-- .../wm/shell/pip/PipTaskOrganizer.java | 1 - .../wm/shell/pip/phone/PipController.java | 29 ++++++++--------- .../pip/phone/PipResizeGestureHandler.java | 1 + .../wm/shell/pip/phone/PipTouchHandler.java | 6 ++-- .../wm/shell/pip/tv/PipController.java | 1 + .../com/android/systemui/wmshell/WMShell.java | 5 +++ .../com/android/server/wm/DisplayContent.java | 4 --- .../server/wm/PinnedStackController.java | 30 ------------------ 12 files changed, 33 insertions(+), 99 deletions(-) diff --git a/core/java/android/view/IPinnedStackListener.aidl b/core/java/android/view/IPinnedStackListener.aidl index 84dd8af5e3426..29c9c155e978c 100644 --- a/core/java/android/view/IPinnedStackListener.aidl +++ b/core/java/android/view/IPinnedStackListener.aidl @@ -57,19 +57,6 @@ oneway interface IPinnedStackListener { */ void onActivityHidden(in ComponentName componentName); - /** - * Called when the window manager has detected change on DisplayInfo, or - * when the listener is first registered to allow the listener to synchronized its state with - * the controller. - */ - void onDisplayInfoChanged(in DisplayInfo displayInfo); - - /** - * Called by the window manager at the beginning of a configuration update cascade - * since the metrics from these resources are used for bounds calculations. - */ - void onConfigurationChanged(); - /** * Called by the window manager when the aspect ratio is reset. */ diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PinnedStackListenerForwarder.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PinnedStackListenerForwarder.java index 5593268588fde..d59aec2cc4461 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PinnedStackListenerForwarder.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PinnedStackListenerForwarder.java @@ -20,7 +20,6 @@ import android.app.RemoteAction; import android.content.ComponentName; import android.content.pm.ParceledListSlice; import android.os.RemoteException; -import android.view.DisplayInfo; import android.view.IPinnedStackListener; import android.view.WindowManagerGlobal; @@ -85,18 +84,6 @@ public class PinnedStackListenerForwarder { } } - private void onDisplayInfoChanged(DisplayInfo displayInfo) { - for (PinnedStackListener listener : mListeners) { - listener.onDisplayInfoChanged(displayInfo); - } - } - - private void onConfigurationChanged() { - for (PinnedStackListener listener : mListeners) { - listener.onConfigurationChanged(); - } - } - private void onAspectRatioChanged(float aspectRatio) { for (PinnedStackListener listener : mListeners) { listener.onAspectRatioChanged(aspectRatio); @@ -133,20 +120,6 @@ public class PinnedStackListenerForwarder { }); } - @Override - public void onDisplayInfoChanged(DisplayInfo displayInfo) { - mShellMainExecutor.execute(() -> { - PinnedStackListenerForwarder.this.onDisplayInfoChanged(displayInfo); - }); - } - - @Override - public void onConfigurationChanged() { - mShellMainExecutor.execute(() -> { - PinnedStackListenerForwarder.this.onConfigurationChanged(); - }); - } - @Override public void onAspectRatioChanged(float aspectRatio) { mShellMainExecutor.execute(() -> { @@ -168,10 +141,6 @@ public class PinnedStackListenerForwarder { public void onActivityHidden(ComponentName componentName) {} - public void onDisplayInfoChanged(DisplayInfo displayInfo) {} - - public void onConfigurationChanged() {} - public void onAspectRatioChanged(float aspectRatio) {} } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/Pip.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/Pip.java index da9ce0aacedcf..1f07542c9a272 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/Pip.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/Pip.java @@ -20,6 +20,7 @@ import android.annotation.Nullable; import android.app.PictureInPictureParams; import android.content.ComponentName; import android.content.pm.ActivityInfo; +import android.content.res.Configuration; import android.graphics.Rect; import com.android.wm.shell.common.annotations.ExternalThread; @@ -81,6 +82,12 @@ public interface Pip { default void movePipToFullscreen() { } + /** + * Called when configuration is changed. + */ + default void onConfigurationChanged(Configuration newConfig) { + } + /** * Called when display size or font size of settings changed */ diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsAlgorithm.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsAlgorithm.java index 1bb5eda25058f..22d8ed50c10e8 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsAlgorithm.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsAlgorithm.java @@ -102,9 +102,7 @@ public class PipBoundsAlgorithm { return mSnapAlgorithm; } - /** - * Responds to IPinnedStackListener on configuration change. - */ + /** Responds to configuration change. */ public void onConfigurationChanged(Context context) { reloadResources(context); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java index 167b9f9975f38..9081783eeab80 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java @@ -502,7 +502,6 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, mPipMenuController.attach(leash); - if (mShouldIgnoreEnteringPipTransition) { final Rect destinationBounds = mPipBoundsState.getBounds(); // animation is finished in the Launcher and here we directly apply the final touch. diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java index 3234ef6ccf664..46fff85ca58d0 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java @@ -33,6 +33,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.pm.ParceledListSlice; +import android.content.res.Configuration; import android.graphics.Rect; import android.os.RemoteException; import android.os.UserHandle; @@ -104,6 +105,9 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac // Skip if we aren't in PIP or haven't actually entered PIP yet. We still need to update // the display layout in the bounds handler in this case. onDisplayRotationChangedNotInPip(mContext, toRotation); + // do not forget to update the movement bounds as well. + updateMovementBounds(mPipBoundsState.getNormalBounds(), true /* fromRotation */, + false /* fromImeAdjustment */, false /* fromShelfAdjustment */, t); return; } // If there is an animation running (ie. from a shelf offset), then ensure that we calculate @@ -136,7 +140,7 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac } }; - private DisplayController.OnDisplaysChangedListener mFixedRotationListener = + private final DisplayController.OnDisplaysChangedListener mFixedRotationListener = new DisplayController.OnDisplaysChangedListener() { @Override public void onFixedRotationStarted(int displayId, int newRotation) { @@ -187,18 +191,6 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac } } - @Override - public void onDisplayInfoChanged(DisplayInfo displayInfo) { - mPipBoundsState.setDisplayInfo(displayInfo); - } - - @Override - public void onConfigurationChanged() { - mPipBoundsAlgorithm.onConfigurationChanged(mContext); - mTouchHandler.onConfigurationChanged(); - mPipBoundsState.onConfigurationChanged(); - } - @Override public void onAspectRatioChanged(float aspectRatio) { // TODO(b/169373982): Remove this callback as it is redundant with PipTaskOrg params @@ -333,6 +325,15 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac }); } + @Override + public void onConfigurationChanged(Configuration newConfig) { + mMainExecutor.execute(() -> { + mPipBoundsAlgorithm.onConfigurationChanged(mContext); + mTouchHandler.onConfigurationChanged(); + mPipBoundsState.onConfigurationChanged(); + }); + } + @Override public void onDensityOrFontScaleChanged() { mMainExecutor.execute(() -> { @@ -532,7 +533,7 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac * * @return {@code true} if internal {@link DisplayInfo} is rotated, {@code false} otherwise. */ - public boolean onDisplayRotationChanged(Context context, Rect outBounds, Rect oldBounds, + private boolean onDisplayRotationChanged(Context context, Rect outBounds, Rect oldBounds, Rect outInsetBounds, int displayId, int fromRotation, int toRotation, WindowContainerTransaction t) { // Bail early if the event is not sent to current {@link #mDisplayInfo} diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java index 88a11689b90ba..2f5219c59bf29 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java @@ -93,6 +93,7 @@ public class PipResizeGestureHandler { private int mDelta; private float mTouchSlop; + private boolean mAllowGesture; private boolean mIsAttached; private boolean mIsEnabled; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java index 9281f58f522f3..33439a412b4d5 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java @@ -86,7 +86,7 @@ public class PipTouchHandler { private boolean mEnableStash = true; // The reference inset bounds, used to determine the dismiss fraction - private Rect mInsetBounds = new Rect(); + private final Rect mInsetBounds = new Rect(); private int mExpandedShortestEdgeSize; // Used to workaround an issue where the WM rotation happens before we are notified, allowing @@ -94,7 +94,8 @@ public class PipTouchHandler { private int mDeferResizeToNormalBoundsUntilRotation = -1; private int mDisplayRotation; - private Handler mHandler = new Handler(); + private final Handler mHandler = new Handler(); + private final PipAccessibilityInteractionConnection mConnection; // Behaviour states private int mMenuState = MENU_STATE_NONE; @@ -108,7 +109,6 @@ public class PipTouchHandler { private float mSavedSnapFraction = -1f; private boolean mSendingHoverAccessibilityEvents; private boolean mMovementWithinDismiss; - private PipAccessibilityInteractionConnection mConnection; // Touch state private final PipTouchState mTouchState; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipController.java index 763370bec1c97..018f45e2facea 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/PipController.java @@ -297,6 +297,7 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac /** * Updates the PIP per configuration changed. */ + @Override public void onConfigurationChanged(Configuration newConfig) { loadConfigurationsAndApply(newConfig); mPipNotification.onConfigurationChanged(mContext); diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java index a879a1ef4b777..2a18f3c550ede 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java @@ -167,6 +167,11 @@ public final class WMShell extends SystemUI }); mConfigurationController.addCallback(new ConfigurationController.ConfigurationListener() { + @Override + public void onConfigChanged(Configuration newConfig) { + pip.onConfigurationChanged(newConfig); + } + @Override public void onDensityOrFontScaleChanged() { pip.onDensityOrFontScaleChanged(); diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index e88f8e3908335..0678a5e4383bd 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -2298,10 +2298,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp .setSubtype(getConfiguration().orientation) .addTaggedData(MetricsEvent.FIELD_DISPLAY_ID, getDisplayId())); } - - if (mPinnedStackControllerLocked != null) { - mPinnedStackControllerLocked.onDisplayInfoChanged(getDisplayInfo()); - } } /** diff --git a/services/core/java/com/android/server/wm/PinnedStackController.java b/services/core/java/com/android/server/wm/PinnedStackController.java index fd42b2467d198..8fe2481f9eda5 100644 --- a/services/core/java/com/android/server/wm/PinnedStackController.java +++ b/services/core/java/com/android/server/wm/PinnedStackController.java @@ -127,7 +127,6 @@ class PinnedStackController { try { listener.asBinder().linkToDeath(mPinnedStackListenerDeathHandler, 0); mPinnedStackListener = listener; - notifyDisplayInfoChanged(mDisplayInfo); notifyImeVisibilityChanged(mIsImeShowing, mImeHeight); notifyMovementBoundsChanged(false /* fromImeAdjustment */); notifyActionsChanged(mActions); @@ -171,23 +170,6 @@ class PinnedStackController { } } - private void setDisplayInfo(DisplayInfo displayInfo) { - mDisplayInfo.copyFrom(displayInfo); - notifyDisplayInfoChanged(mDisplayInfo); - } - - /** - * In the case where the display rotation is changed but there is no stack, we can't depend on - * onTaskStackBoundsChanged() to be called. But we still should update our known display info - * with the new state so that we can update SystemUI. - */ - void onDisplayInfoChanged(DisplayInfo displayInfo) { - synchronized (mService.mGlobalLock) { - setDisplayInfo(displayInfo); - notifyMovementBoundsChanged(false /* fromImeAdjustment */); - } - } - /** * Sets the Ime state and height. */ @@ -288,18 +270,6 @@ class PinnedStackController { } } - /** - * Notifies listeners that the PIP animation is about to happen. - */ - private void notifyDisplayInfoChanged(DisplayInfo displayInfo) { - if (mPinnedStackListener == null) return; - try { - mPinnedStackListener.onDisplayInfoChanged(displayInfo); - } catch (RemoteException e) { - Slog.e(TAG_WM, "Error delivering DisplayInfo changed event.", e); - } - } - void dump(String prefix, PrintWriter pw) { pw.println(prefix + "PinnedStackController"); pw.println(prefix + " mIsImeShowing=" + mIsImeShowing);