Commit d8fc05b9 authored by Peter E Conn's avatar Peter E Conn Committed by Commit Bot

🕸️ Add FLAG_ACTIVITY_NEW_DOCUMENT to WebappActivity Intents.

On Samsung Lollipop devices the Intents used to communicate with a
foreground WebappActivity were causing a new instance of the
WebappActivity to be launched instead of causing onNewIntent of the
current Activity to be run. This only occurs when a
ChromeTabbedActivity is in the background, when it is not, onNewIntent
is called properly.

I'm not sure what is special about WebappActivity that causes this -
I've been unable to generate a smaller repro.

This issue is solved however by making sure both the
FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_NEW_DOCUMENT (which was
FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET in pre-Lollipop) have been set
on the Intent and FLAG_ONE_SHOT has been set on the PendingIntent.

Bug: 846528
Change-Id: I9602537e68b24a186961d29f4c4b1fb1ae9235b0
Reviewed-on: https://chromium-review.googlesource.com/1107631Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Commit-Queue: Peter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569286}
parent 3be9df1c
......@@ -66,18 +66,26 @@ class WebappActionsNotificationManager {
}
private Notification createNotification() {
int intentFlags = WebappLauncherActivity.getWebappActivityIntentFlags();
int pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT;
PendingIntent focusIntent = PendingIntent.getActivity(mWebappActivity, 0,
new Intent(mWebappActivity, mWebappActivity.getClass()).setAction(ACTION_FOCUS),
PendingIntent.FLAG_UPDATE_CURRENT);
new Intent(mWebappActivity, mWebappActivity.getClass())
.setAction(ACTION_FOCUS)
.setFlags(intentFlags),
pendingIntentFlags);
PendingIntent openInChromeIntent = PendingIntent.getActivity(mWebappActivity, 0,
new Intent(mWebappActivity, mWebappActivity.getClass())
.setAction(ACTION_OPEN_IN_CHROME),
PendingIntent.FLAG_UPDATE_CURRENT);
.setAction(ACTION_OPEN_IN_CHROME)
.setFlags(intentFlags),
pendingIntentFlags);
PendingIntent shareIntent = PendingIntent.getActivity(mWebappActivity, 0,
new Intent(mWebappActivity, mWebappActivity.getClass()).setAction(ACTION_SHARE),
PendingIntent.FLAG_UPDATE_CURRENT);
new Intent(mWebappActivity, mWebappActivity.getClass())
.setAction(ACTION_SHARE)
.setFlags(intentFlags),
pendingIntentFlags);
return NotificationBuilderFactory
.createChromeNotificationBuilder(
......
......@@ -212,6 +212,14 @@ public class WebappLauncherActivity extends Activity {
// Activity.
launchIntent.setAction(Intent.ACTION_VIEW);
launchIntent.setData(Uri.parse(WebappActivity.WEBAPP_SCHEME + "://" + info.id()));
launchIntent.setFlags(getWebappActivityIntentFlags());
return launchIntent;
}
/**
* Returns the set of Intent flags required to correctly launch a WebappActivity.
*/
public static int getWebappActivityIntentFlags() {
// Setting FLAG_ACTIVITY_CLEAR_TOP handles 2 edge cases:
// - If a legacy PWA is launching from a notification, we want to ensure that the URL being
// launched is the URL in the intent. If a paused WebappActivity exists for this id,
......@@ -222,10 +230,14 @@ public class WebappLauncherActivity extends Activity {
// clicks a link to takes them back to the scope of a WebAPK, we want to destroy the
// CustomTabActivity activity and go back to the WebAPK activity. It is intentional that
// Custom Tab will not be reachable with a back button.
launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
// In addition FLAG_ACTIVITY_NEW_DOCUMENT is required otherwise on Samsung Lollipop devices
// an Intent to an existing top Activity (such as sent from the Webapp Actions Notification)
// will trigger a new WebappActivity to be launched and onCreate called instead of
// onNewIntent of the existing WebappActivity being called.
return Intent.FLAG_ACTIVITY_NEW_TASK
| ApiCompatibilityUtils.getActivityNewDocumentFlag()
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
return launchIntent;
| Intent.FLAG_ACTIVITY_CLEAR_TOP;
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment