summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Louis Chang <louischang@google.com> 2019-04-24 18:35:20 +0800
committer Louis Chang <louischang@google.com> 2019-07-29 14:44:19 +0800
commit477e93ea569b3b83a284ba1a52fd32e321a75663 (patch)
treed6f5ffad157f3efff0eaaf0f75bec84f8ff6a6e3
parent31a00d0a73a69f5c728ea64d87b98b045fa0b188 (diff)
Adding caller display id when launching activities via PendingIntent
Activities were launched on primary display when they were started via PendingIntent, because we didn’t have the caller information from PendingIntent and were unable to determine the preferred displays for the newly created activities. Applications should use the correct context while calling PendingIntent.send(). Also fix that animation type could be overrides when merging two activity options. Bug: 130967908 Test: atest MultiDisplayActivityLaunchTests Change-Id: I9c50900937f20a83768d5e676b93c4c02665f8cb
-rw-r--r--core/java/android/app/ActivityOptions.java33
-rw-r--r--core/java/android/app/PendingIntent.java11
-rw-r--r--services/core/java/com/android/server/wm/ActivityRecord.java2
-rw-r--r--services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java6
4 files changed, 49 insertions, 3 deletions
diff --git a/core/java/android/app/ActivityOptions.java b/core/java/android/app/ActivityOptions.java
index 926044bffdd0..b8d9575f4b0f 100644
--- a/core/java/android/app/ActivityOptions.java
+++ b/core/java/android/app/ActivityOptions.java
@@ -177,6 +177,13 @@ public class ActivityOptions {
private static final String KEY_LAUNCH_DISPLAY_ID = "android.activity.launchDisplayId";
/**
+ * The id of the display where the caller was on.
+ * @see #setCallerDisplayId(int)
+ * @hide
+ */
+ private static final String KEY_CALLER_DISPLAY_ID = "android.activity.callerDisplayId";
+
+ /**
* The windowing mode the activity should be launched into.
* @hide
*/
@@ -269,6 +276,8 @@ public class ActivityOptions {
= "android:activity.remoteAnimationAdapter";
/** @hide */
+ public static final int ANIM_UNDEFINED = -1;
+ /** @hide */
public static final int ANIM_NONE = 0;
/** @hide */
public static final int ANIM_CUSTOM = 1;
@@ -299,7 +308,7 @@ public class ActivityOptions {
private String mPackageName;
private Rect mLaunchBounds;
- private int mAnimationType = ANIM_NONE;
+ private int mAnimationType = ANIM_UNDEFINED;
private int mCustomEnterResId;
private int mCustomExitResId;
private int mCustomInPlaceResId;
@@ -318,6 +327,7 @@ public class ActivityOptions {
private int mExitCoordinatorIndex;
private PendingIntent mUsageTimeReport;
private int mLaunchDisplayId = INVALID_DISPLAY;
+ private int mCallerDisplayId = INVALID_DISPLAY;
@WindowConfiguration.WindowingMode
private int mLaunchWindowingMode = WINDOWING_MODE_UNDEFINED;
@WindowConfiguration.ActivityType
@@ -896,7 +906,7 @@ public class ActivityOptions {
Slog.w(TAG, e);
}
mLaunchBounds = opts.getParcelable(KEY_LAUNCH_BOUNDS);
- mAnimationType = opts.getInt(KEY_ANIM_TYPE);
+ mAnimationType = opts.getInt(KEY_ANIM_TYPE, ANIM_UNDEFINED);
switch (mAnimationType) {
case ANIM_CUSTOM:
mCustomEnterResId = opts.getInt(KEY_ANIM_ENTER_RES_ID, 0);
@@ -945,6 +955,7 @@ public class ActivityOptions {
}
mLockTaskMode = opts.getBoolean(KEY_LOCK_TASK_MODE, false);
mLaunchDisplayId = opts.getInt(KEY_LAUNCH_DISPLAY_ID, INVALID_DISPLAY);
+ mCallerDisplayId = opts.getInt(KEY_CALLER_DISPLAY_ID, INVALID_DISPLAY);
mLaunchWindowingMode = opts.getInt(KEY_LAUNCH_WINDOWING_MODE, WINDOWING_MODE_UNDEFINED);
mLaunchActivityType = opts.getInt(KEY_LAUNCH_ACTIVITY_TYPE, ACTIVITY_TYPE_UNDEFINED);
mLaunchTaskId = opts.getInt(KEY_LAUNCH_TASK_ID, -1);
@@ -1204,6 +1215,17 @@ public class ActivityOptions {
}
/** @hide */
+ public int getCallerDisplayId() {
+ return mCallerDisplayId;
+ }
+
+ /** @hide */
+ public ActivityOptions setCallerDisplayId(int callerDisplayId) {
+ mCallerDisplayId = callerDisplayId;
+ return this;
+ }
+
+ /** @hide */
public int getLaunchWindowingMode() {
return mLaunchWindowingMode;
}
@@ -1447,7 +1469,9 @@ public class ActivityOptions {
if (mLaunchBounds != null) {
b.putParcelable(KEY_LAUNCH_BOUNDS, mLaunchBounds);
}
- b.putInt(KEY_ANIM_TYPE, mAnimationType);
+ if (mAnimationType != ANIM_UNDEFINED) {
+ b.putInt(KEY_ANIM_TYPE, mAnimationType);
+ }
if (mUsageTimeReport != null) {
b.putParcelable(KEY_USAGE_TIME_REPORT, mUsageTimeReport);
}
@@ -1506,6 +1530,9 @@ public class ActivityOptions {
if (mLaunchDisplayId != INVALID_DISPLAY) {
b.putInt(KEY_LAUNCH_DISPLAY_ID, mLaunchDisplayId);
}
+ if (mCallerDisplayId != INVALID_DISPLAY) {
+ b.putInt(KEY_CALLER_DISPLAY_ID, mCallerDisplayId);
+ }
if (mLaunchWindowingMode != WINDOWING_MODE_UNDEFINED) {
b.putInt(KEY_LAUNCH_WINDOWING_MODE, mLaunchWindowingMode);
}
diff --git a/core/java/android/app/PendingIntent.java b/core/java/android/app/PendingIntent.java
index 6f7a0607cbdb..4b4a071ecf72 100644
--- a/core/java/android/app/PendingIntent.java
+++ b/core/java/android/app/PendingIntent.java
@@ -893,6 +893,17 @@ public final class PendingIntent implements Parcelable {
String resolvedType = intent != null ?
intent.resolveTypeIfNeeded(context.getContentResolver())
: null;
+
+ if (context != null && isActivity()) {
+ // Set the context display id as preferred for this activity launches, so that it
+ // can land on caller's display. Or just brought the task to front at the display
+ // where it was on since it has higher preference.
+ ActivityOptions activityOptions = options != null ? new ActivityOptions(options)
+ : ActivityOptions.makeBasic();
+ activityOptions.setCallerDisplayId(context.getDisplayId());
+ options = activityOptions.toBundle();
+ }
+
return ActivityManager.getService().sendIntentSender(
mTarget, mWhitelistToken, code, intent, resolvedType,
onFinished != null
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index 015464e94ffc..31e8bbdab71c 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -30,6 +30,7 @@ import static android.app.ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_DOWN;
import static android.app.ActivityOptions.ANIM_THUMBNAIL_ASPECT_SCALE_UP;
import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_DOWN;
import static android.app.ActivityOptions.ANIM_THUMBNAIL_SCALE_UP;
+import static android.app.ActivityOptions.ANIM_UNDEFINED;
import static android.app.ActivityTaskManager.INVALID_STACK_ID;
import static android.app.ActivityTaskManager.INVALID_TASK_ID;
import static android.app.AppOpsManager.MODE_ALLOWED;
@@ -2096,6 +2097,7 @@ final class ActivityRecord extends ConfigurationContainer {
pendingOptions.getRemoteAnimationAdapter());
break;
case ANIM_NONE:
+ case ANIM_UNDEFINED:
break;
default:
Slog.e(TAG_WM, "applyOptionsLocked: Unknown animationType=" + animationType);
diff --git a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
index 0d18b30c1b0b..47c53e91578a 100644
--- a/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
+++ b/services/core/java/com/android/server/wm/TaskLaunchParamsModifier.java
@@ -321,6 +321,12 @@ class TaskLaunchParamsModifier implements LaunchParamsModifier {
displayId = sourceDisplayId;
}
+ if (displayId == INVALID_DISPLAY && options != null) {
+ final int callerDisplayId = options.getCallerDisplayId();
+ if (DEBUG) appendLog("display-from-caller=" + callerDisplayId);
+ displayId = callerDisplayId;
+ }
+
if (displayId != INVALID_DISPLAY
&& mSupervisor.mRootActivityContainer.getActivityDisplay(displayId) == null) {
displayId = currentParams.mPreferredDisplayId;