From 49affea25bcb669d845672f04b1352871c8aa8f6 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 16 Feb 2017 20:41:08 -0800 Subject: [PATCH] Fix trampoline activities when relaunching PiP - We should be checking the actual launched-from package since that stores the source package across trampoline activities Bug: 35458117 Test: Enter PiP from a trampoline activity, launch again from Launcher and ensure that it is expanded Change-Id: Ia0e586e8b21dee63b513bd61a41a24e7da4325e1 --- core/java/android/app/ITaskStackListener.aidl | 5 +++-- core/java/android/app/TaskStackListener.java | 2 +- .../src/com/android/systemui/pip/phone/PipManager.java | 8 ++++---- .../src/com/android/systemui/pip/tv/PipManager.java | 2 +- .../systemui/recents/misc/SystemServicesProxy.java | 9 ++++----- .../core/java/com/android/server/am/ActivityStarter.java | 4 +--- .../server/am/TaskChangeNotificationController.java | 6 +++--- .../com/android/server/wm/PinnedStackController.java | 4 ++-- 8 files changed, 19 insertions(+), 21 deletions(-) diff --git a/core/java/android/app/ITaskStackListener.aidl b/core/java/android/app/ITaskStackListener.aidl index 5e420c085b539..983435024a9b2 100644 --- a/core/java/android/app/ITaskStackListener.aidl +++ b/core/java/android/app/ITaskStackListener.aidl @@ -32,9 +32,10 @@ oneway interface ITaskStackListener { * running in the pinned stack and the activity is not actually started, but the task is either * brought to the front or a new Intent is delivered to it. * - * @param sourceComponent the component name of the activity that initiated the restart attempt + * @param launchedFromPackage the package name of the activity that initiated the restart + * attempt */ - void onPinnedActivityRestartAttempt(in ComponentName sourceComponent); + void onPinnedActivityRestartAttempt(String launchedFromPackage); /** * Called whenever the pinned stack is done animating a resize. diff --git a/core/java/android/app/TaskStackListener.java b/core/java/android/app/TaskStackListener.java index 35c67d30cc5a6..5a0845f02b29c 100644 --- a/core/java/android/app/TaskStackListener.java +++ b/core/java/android/app/TaskStackListener.java @@ -35,7 +35,7 @@ public abstract class TaskStackListener extends ITaskStackListener.Stub { } @Override - public void onPinnedActivityRestartAttempt(ComponentName sourceComponent) throws RemoteException { + public void onPinnedActivityRestartAttempt(String launchedFromPackage) throws RemoteException { } @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 42f1b1424877e..ae402efabc7f8 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java @@ -76,7 +76,7 @@ public class PipManager implements BasePipManager { } @Override - public void onPinnedActivityRestartAttempt(ComponentName sourceComponent) { + public void onPinnedActivityRestartAttempt(String launchedFromPackage) { if (!checkCurrentUserId(false /* debug */)) { return; } @@ -84,11 +84,11 @@ public class PipManager implements BasePipManager { // Expand the activity back to fullscreen only if it was attempted to be restarted from // another package than the top activity in the stack boolean expandPipToFullscreen = true; - if (sourceComponent != null) { + if (launchedFromPackage != null) { ComponentName topActivity = PipUtils.getTopPinnedActivity(mContext, mActivityManager); - if (topActivity != null && topActivity.getPackageName().equals( - sourceComponent.getPackageName())) { + if (topActivity != null + && topActivity.getPackageName().equals(launchedFromPackage)) { expandPipToFullscreen = false; } } 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 112fedbc0996f..376a0b6bdcbcf 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java +++ b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java @@ -695,7 +695,7 @@ public class PipManager implements BasePipManager { } @Override - public void onPinnedActivityRestartAttempt(ComponentName sourceComponent) { + public void onPinnedActivityRestartAttempt(String launchedFromPackage) { if (DEBUG) Log.d(TAG, "onPinnedActivityRestartAttempt()"); if (!checkCurrentUserId(DEBUG)) { return; diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java index eae1b81554860..cda902b6fb69c 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java +++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java @@ -153,7 +153,7 @@ public class SystemServicesProxy { public void onTaskStackChanged() { } public void onTaskSnapshotChanged(int taskId, TaskSnapshot snapshot) { } public void onActivityPinned() { } - public void onPinnedActivityRestartAttempt(ComponentName sourceComponent) { } + public void onPinnedActivityRestartAttempt(String launchedFromPackage) { } public void onPinnedStackAnimationEnded() { } public void onActivityForcedResizable(String packageName, int taskId) { } public void onActivityDismissingDockedStack() { } @@ -198,10 +198,10 @@ public class SystemServicesProxy { } @Override - public void onPinnedActivityRestartAttempt(ComponentName sourceComponent) + public void onPinnedActivityRestartAttempt(String launchedFromPackage) throws RemoteException{ mHandler.removeMessages(H.ON_PINNED_ACTIVITY_RESTART_ATTEMPT); - mHandler.obtainMessage(H.ON_PINNED_ACTIVITY_RESTART_ATTEMPT, sourceComponent) + mHandler.obtainMessage(H.ON_PINNED_ACTIVITY_RESTART_ATTEMPT, launchedFromPackage) .sendToTarget(); } @@ -1244,8 +1244,7 @@ public class SystemServicesProxy { } case ON_PINNED_ACTIVITY_RESTART_ATTEMPT: { for (int i = mTaskStackListeners.size() - 1; i >= 0; i--) { - mTaskStackListeners.get(i).onPinnedActivityRestartAttempt( - (ComponentName) msg.obj); + mTaskStackListeners.get(i).onPinnedActivityRestartAttempt((String) msg.obj); } break; } diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java index 4b07af0d00dc7..7605a1e0ffc37 100644 --- a/services/core/java/com/android/server/am/ActivityStarter.java +++ b/services/core/java/com/android/server/am/ActivityStarter.java @@ -585,10 +585,8 @@ class ActivityStarter { // The activity was already running in the pinned stack so it wasn't started, but either // brought to the front or the new intent was delivered to it since it was already in // front. Notify anyone interested in this piece of information. - final ComponentName sourceComponent = sourceRecord == null ? null : - sourceRecord.realActivity; mService.mTaskChangeNotificationController.notifyPinnedActivityRestartAttempt( - sourceComponent); + sourceRecord.launchedFromPackage); return; } } diff --git a/services/core/java/com/android/server/am/TaskChangeNotificationController.java b/services/core/java/com/android/server/am/TaskChangeNotificationController.java index 2990dffd8e5ca..9dfc7cd84f401 100644 --- a/services/core/java/com/android/server/am/TaskChangeNotificationController.java +++ b/services/core/java/com/android/server/am/TaskChangeNotificationController.java @@ -97,7 +97,7 @@ class TaskChangeNotificationController { }; private final TaskStackConsumer mNotifyPinnedActivityRestartAttempt = (l, m) -> { - l.onPinnedActivityRestartAttempt((ComponentName) m.obj); + l.onPinnedActivityRestartAttempt((String) m.obj); }; private final TaskStackConsumer mNotifyPinnedStackAnimationEnded = (l, m) -> { @@ -267,11 +267,11 @@ class TaskChangeNotificationController { * running in the pinned stack and the activity was not actually started, but the task is * either brought to the front or a new Intent is delivered to it. */ - void notifyPinnedActivityRestartAttempt(ComponentName sourceComponent) { + void notifyPinnedActivityRestartAttempt(String launchedFromPackage) { mHandler.removeMessages(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG); final Message msg = mHandler.obtainMessage(NOTIFY_PINNED_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG, - sourceComponent); + launchedFromPackage); forAllLocalListeners(mNotifyPinnedActivityRestartAttempt, msg); msg.sendToTarget(); } diff --git a/services/core/java/com/android/server/wm/PinnedStackController.java b/services/core/java/com/android/server/wm/PinnedStackController.java index 6a8417dc440b7..cfeb1980eafb9 100644 --- a/services/core/java/com/android/server/wm/PinnedStackController.java +++ b/services/core/java/com/android/server/wm/PinnedStackController.java @@ -233,7 +233,7 @@ class PinnedStackController { * @return the movement bounds for the given {@param stackBounds} and the current state of the * controller. */ - Rect getMovementBounds(Rect stackBounds) { + private Rect getMovementBounds(Rect stackBounds) { return getMovementBounds(stackBounds, true /* adjustForIme */); } @@ -241,7 +241,7 @@ class PinnedStackController { * @return the movement bounds for the given {@param stackBounds} and the current state of the * controller. */ - Rect getMovementBounds(Rect stackBounds, boolean adjustForIme) { + private Rect getMovementBounds(Rect stackBounds, boolean adjustForIme) { final Rect movementBounds = new Rect(); getInsetBounds(movementBounds);