From c41ed32b607d0ec19db5770c557d9984b515598a Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Wed, 25 Sep 2019 11:19:26 -0700 Subject: [PATCH] Remove embedded & document launch always restrictions from a bubble * No longer need the embedded flag as of ag/9341444 * Instead of requiring the app to specify documentLaunchMode=always we'll apply the relevant intent flags to force that behaviour * Adds a new param to include a "fillInIntent" which can adjust the flags on the PendingIntent. Bug: 138325285 Test: manual with BubblesTest (removed the flags in the test app, things should still bubble) Test: atest NotificationManagerTest (needs CTS CL) Change-Id: I08de491fc89d8182f2b2a7df95c985d8be847aab --- api/test-current.txt | 2 +- core/java/android/app/ActivityView.java | 6 ++++-- .../android/systemui/bubbles/BubbleController.java | 11 ----------- .../systemui/bubbles/BubbleExpandedView.java | 8 +++++++- .../notification/NotificationManagerService.java | 14 -------------- 5 files changed, 12 insertions(+), 29 deletions(-) diff --git a/api/test-current.txt b/api/test-current.txt index a40cb923065fa..1811ced92a6bf 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -130,7 +130,7 @@ package android.app { method public void startActivity(@NonNull android.content.Intent); method public void startActivity(@NonNull android.content.Intent, android.os.UserHandle); method public void startActivity(@NonNull android.app.PendingIntent); - method public void startActivity(@NonNull android.app.PendingIntent, @NonNull android.app.ActivityOptions); + method public void startActivity(@NonNull android.app.PendingIntent, @Nullable android.content.Intent, @NonNull android.app.ActivityOptions); } public abstract static class ActivityView.StateCallback { diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java index b56c00e44d3f2..fbf1f59141a82 100644 --- a/core/java/android/app/ActivityView.java +++ b/core/java/android/app/ActivityView.java @@ -22,6 +22,7 @@ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLI import static android.view.Display.INVALID_DISPLAY; import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.TestApi; import android.app.ActivityManager.StackInfo; import android.content.ComponentName; @@ -324,16 +325,17 @@ public class ActivityView extends ViewGroup { * this method can be called. * * @param pendingIntent Intent used to launch an activity. + * @param fillInIntent Additional Intent data, see {@link Intent#fillIn Intent.fillIn()}. * @param options options for the activity * * @see StateCallback * @see #startActivity(Intent) */ - public void startActivity(@NonNull PendingIntent pendingIntent, + public void startActivity(@NonNull PendingIntent pendingIntent, @Nullable Intent fillInIntent, @NonNull ActivityOptions options) { options.setLaunchDisplayId(mVirtualDisplay.getDisplay().getDisplayId()); try { - pendingIntent.send(null /* context */, 0 /* code */, null /* intent */, + pendingIntent.send(getContext(), 0 /* code */, fillInIntent, null /* onFinished */, null /* handler */, null /* requiredPermission */, options.toBundle()); } catch (PendingIntent.CanceledException e) { diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java index 8240345070195..81c255f0268d9 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java @@ -18,7 +18,6 @@ package com.android.systemui.bubbles; import static android.app.Notification.FLAG_AUTOGROUP_SUMMARY; import static android.app.Notification.FLAG_BUBBLE; -import static android.content.pm.ActivityInfo.DOCUMENT_LAUNCH_ALWAYS; import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL; import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL_ALL; import static android.service.notification.NotificationListenerService.REASON_CANCEL; @@ -962,16 +961,6 @@ public class BubbleController implements ConfigurationController.ConfigurationLi + intent); return false; } - if (info.documentLaunchMode != DOCUMENT_LAUNCH_ALWAYS) { - Log.w(TAG, "Unable to send as bubble -- activity is not documentLaunchMode=always " - + "for intent: " + intent); - return false; - } - if ((info.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { - Log.w(TAG, "Unable to send as bubble -- activity is not embeddable for intent: " - + intent); - return false; - } return true; } diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java index 521ebde7d2f0a..6f953d5845894 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java @@ -16,6 +16,8 @@ package com.android.systemui.bubbles; +import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK; +import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT; import static android.view.Display.INVALID_DISPLAY; import static com.android.systemui.bubbles.BubbleDebugConfig.DEBUG_BUBBLE_EXPANDED_VIEW; @@ -128,8 +130,12 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList Log.d(TAG, "onActivityViewReady: calling startActivity, " + "bubble=" + getBubbleKey()); } + Intent fillInIntent = new Intent(); + // Apply flags to make behaviour match documentLaunchMode=always. + fillInIntent.addFlags(FLAG_ACTIVITY_NEW_DOCUMENT); + fillInIntent.addFlags(FLAG_ACTIVITY_MULTIPLE_TASK); try { - mActivityView.startActivity(mBubbleIntent, options); + mActivityView.startActivity(mBubbleIntent, fillInIntent, options); } catch (RuntimeException e) { // If there's a runtime exception here then there's something // wrong with the intent, we can't really recover / try to populate diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index d480cb6e98007..389142f0c56d0 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -49,7 +49,6 @@ import static android.content.Context.BIND_ALLOW_WHITELIST_MANAGEMENT; import static android.content.Context.BIND_AUTO_CREATE; import static android.content.Context.BIND_FOREGROUND_SERVICE; import static android.content.Context.BIND_NOT_PERCEPTIBLE; -import static android.content.pm.ActivityInfo.DOCUMENT_LAUNCH_ALWAYS; import static android.content.pm.PackageManager.FEATURE_LEANBACK; import static android.content.pm.PackageManager.FEATURE_TELEVISION; import static android.content.pm.PackageManager.MATCH_ALL; @@ -88,7 +87,6 @@ import static android.service.notification.NotificationListenerService.TRIM_FULL import static android.service.notification.NotificationListenerService.TRIM_LIGHT; import static android.util.StatsLogInternal.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_MISSING; import static android.util.StatsLogInternal.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__ACTIVITY_INFO_NOT_RESIZABLE; -import static android.util.StatsLogInternal.BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__DOCUMENT_LAUNCH_NOT_ALWAYS; import static android.view.WindowManager.LayoutParams.TYPE_TOAST; import static com.android.server.am.PendingIntentRecord.FLAG_ACTIVITY_SENDER; @@ -5238,18 +5236,6 @@ public class NotificationManagerService extends SystemService { + intent); return false; } - if (info.documentLaunchMode != DOCUMENT_LAUNCH_ALWAYS) { - StatsLog.write(StatsLog.BUBBLE_DEVELOPER_ERROR_REPORTED, packageName, - BUBBLE_DEVELOPER_ERROR_REPORTED__ERROR__DOCUMENT_LAUNCH_NOT_ALWAYS); - Log.w(TAG, "Unable to send as bubble -- activity is not documentLaunchMode=always " - + "for intent: " + intent); - return false; - } - if ((info.flags & ActivityInfo.FLAG_ALLOW_EMBEDDED) == 0) { - Log.w(TAG, "Unable to send as bubble -- activity is not embeddable for intent: " - + intent); - return false; - } return true; }