From 0c5a59292c20edb36ef3af946c8d74b76776c3a1 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Mon, 22 May 2017 17:41:06 -0700 Subject: [PATCH] Fix issue with TV PIP clobbering resize on orientation change. - When the device rotates due to a test that requests a specific orientation, the TV PiP logic was resizing the state back to mDefaultPipBounds, which doesn't change depending on orientation change, clobbering the bounds in the new orientation that were calculated in WM. Since TV does not really care about the rotation case, we can just ignore the configuration changes due to orientation changes for the sake of passing the common CTS tests across handhelds and TV. Bug: 38246863 Test: android.server.cts.ActivityManagerPinnedStackTests Change-Id: Id7988a0b02f14f67908d3202cdd73b186d9fea16 --- .../android/systemui/pip/BasePipManager.java | 3 ++- .../src/com/android/systemui/pip/PipUI.java | 2 +- .../android/systemui/pip/phone/PipManager.java | 3 ++- .../com/android/systemui/pip/tv/PipManager.java | 17 +++++++++++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/pip/BasePipManager.java b/packages/SystemUI/src/com/android/systemui/pip/BasePipManager.java index 68c80073d240b..36dbb0f3061b3 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/BasePipManager.java +++ b/packages/SystemUI/src/com/android/systemui/pip/BasePipManager.java @@ -17,12 +17,13 @@ package com.android.systemui.pip; import android.content.Context; +import android.content.res.Configuration; import java.io.PrintWriter; public interface BasePipManager { void initialize(Context context); void showPictureInPictureMenu(); - void onConfigurationChanged(); + void onConfigurationChanged(Configuration newConfig); void dump(PrintWriter pw); } diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipUI.java b/packages/SystemUI/src/com/android/systemui/pip/PipUI.java index a1f6553aa7d5b..b7164cbb32716 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/PipUI.java +++ b/packages/SystemUI/src/com/android/systemui/pip/PipUI.java @@ -72,7 +72,7 @@ public class PipUI extends SystemUI implements CommandQueue.Callbacks { return; } - mPipManager.onConfigurationChanged(); + mPipManager.onConfigurationChanged(newConfig); } @Override 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 5ca9fa55eb897..0373d77940d76 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java @@ -25,6 +25,7 @@ import android.app.IActivityManager; import android.content.ComponentName; import android.content.Context; import android.content.pm.ParceledListSlice; +import android.content.res.Configuration; import android.graphics.Rect; import android.os.Handler; import android.os.RemoteException; @@ -196,7 +197,7 @@ public class PipManager implements BasePipManager { /** * Updates the PIP per configuration changed. */ - public void onConfigurationChanged() { + public void onConfigurationChanged(Configuration newConfig) { mTouchHandler.onConfigurationChanged(); } diff --git a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java index 6490b33f37405..5414aad0a63f3 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java +++ b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java @@ -26,6 +26,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ParceledListSlice; +import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Rect; import android.media.session.MediaController; @@ -116,6 +117,7 @@ public class PipManager implements BasePipManager { private Rect mDefaultPipBounds = new Rect(); private Rect mSettingsPipBounds; private Rect mMenuModePipBounds; + private int mLastOrientation = Configuration.ORIENTATION_UNDEFINED; private boolean mInitialized; private int mPipTaskId = TASK_ID_NO_PIP; private ComponentName mPipComponentName; @@ -237,7 +239,7 @@ public class PipManager implements BasePipManager { } } - loadConfigurationsAndApply(); + loadConfigurationsAndApply(mContext.getResources().getConfiguration()); mMediaSessionManager = (MediaSessionManager) mContext.getSystemService(Context.MEDIA_SESSION_SERVICE); @@ -250,7 +252,14 @@ public class PipManager implements BasePipManager { mPipNotification = new PipNotification(context); } - private void loadConfigurationsAndApply() { + private void loadConfigurationsAndApply(Configuration newConfig) { + if (mLastOrientation != newConfig.orientation) { + // Don't resize the pinned stack on orientation change. TV does not care about this case + // and this could clobber the existing animation to the new bounds calculated by WM. + mLastOrientation = newConfig.orientation; + return; + } + Resources res = mContext.getResources(); mSettingsPipBounds = Rect.unflattenFromString(res.getString( R.string.pip_settings_bounds)); @@ -267,8 +276,8 @@ public class PipManager implements BasePipManager { /** * Updates the PIP per configuration changed. */ - public void onConfigurationChanged() { - loadConfigurationsAndApply(); + public void onConfigurationChanged(Configuration newConfig) { + loadConfigurationsAndApply(newConfig); mPipNotification.onConfigurationChanged(mContext); }