Nightly app does not appear in task switcher when opening external links

VERIFIED FIXED in Firefox 41

Status

()

Firefox for Android
Overlays
VERIFIED FIXED
3 years ago
3 years ago

People

(Reporter: TeoVermesan, Assigned: mhaigh)

Tracking

41 Branch
Firefox 41
All
Android
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox41 disabled, fennecNightly+)

Details

Attachments

(1 attachment)

(Reporter)

Description

3 years ago
Prerequisites:
-Close Nightly
-Tab queue pref is disabled

Steps to reproduce:
1. Open gmail app, tap on a link and choose to open with Nightly
2. Open Task Manager

Expected results:
- Nightly and gmail should appear in task switcher

Actual results:
- Only gmail appears in task switcher

Note:
- if tab queue pref is enabled and choose to "Open Now" the link or from tab queue notification, Nightly appears in task manager

Note:

14-05 build not affected
15-05 build affected
pushlog: http://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=1fab94ad196c&tochange=127a78bac3f1


Is it Bug 1155911 - [tab queue] Opening external links can cause two nightly apps in task switcher ?
Duplicate of this bug: 1166062
Blocks: 1112185
tracking-fennec: --- → ?
Depends on: 1155911
(Assignee)

Comment 2

3 years ago
I've been performing a four point test to verify a fix for this:
1, with TQ turned OFF, verify that Fx is visible in the recents list when launched from an external application.
2, with TQ turned OFF, verify that an extra Fx entry isn't visible in the recents list when launched from an external application.
3, with TQ turned ON, verify that Fx is visible in the recents list when launched from a TQ action (notification or "open now" button).
4, with TQ turned ON, verify that an extra Fx entry isn't visible in the recents list when the TQ toast is shown.

Issue is that on 4.x it's sufficient to have android:excludeFromRecents="true" attached to the TabQueueDispatcher and this seems to work for all use cases, but this same code causes test case 1 and 3 to fail in 5.x.  If I remove the android:excludeFromRecents="true" attached to the TabQueueDispatcher Activity then 5.x works for all use cases but 4.x fails on case 2 and 4.

I've spent a while playing about with tastAffinity, noHistory, excludeFromRecents, launch flags, creating a secondary launch activity with different manifest attributes and nothing else seems to effect.

rnewman: you got any other ideas?
Flags: needinfo?(rnewman)
We have a pretty complicated set of activities here.

TabQueuePrompt is singleTop with no affinity.
TabQueueService has affinity TABQUEUE.
TabQueueDispatcher is singleTask with no affinity.
BrowserApp is singleTask with affinity BROWSER and preserving task state.


When ACTION_VIEW arrives, TabQueueDispatcher starts. It has no affinity (which *should* mean the task chosen is $ANDROID_PACKAGE_NAME) but is singleTask, so if one already exists it is repurposed. The resulting activity is the base of its task stack.

Tab queue is turned off, so we immediately do this:

        intent.setClassName(getApplicationContext(), AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
        startActivity(intent);
        finish();

Note particularly that we're reusing the previous intent. See below for why that's important.

We start BrowserApp. This pulls the existing BROWSER task, or creates a new one, clears any activities on top of it apart from BrowserApp, and launches it with the intent.

Then we finish TabQueueDispatcher, which should end the task labeled $ANDROID_PACKAGE_NAME.

So why do we get two entries in the tab switcher? Because we have two recent tasks. We have BrowserApp's task (BROWSER), and TabQueueDispatcher's task ($ANDROID_PACKAGE_NAME).

The latter's task is blank because there are no activities left on the top of the stack.

This leads us to mhaigh's fix: mark TabQueueDispatcher with excludeFromRecents=true.


That's the correct fix. But when TabQueueDispatcher handles the incoming intent, that excludeFromRecents is sticky when we later dispatch to BrowserApp.

Check this out:

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.0_r1/com/android/server/am/ActivityRecord.java/#468


            if (intent != null && (aInfo.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) != 0) {
                intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            }


Given that we want to reuse this intent (as if we were redelivering it), the fix here, then, is to undo that intent flag, which is the only one set by ActivityRecord. If I still remember my Java bitwise operators:

        intent.setClassName(getApplicationContext(), AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);

        // Unset FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS while preserving all other flags.
        // If we were launched by an app requesting that we're excluded from recents... well, sorry.
        int flags = intent.getFlags() & ~Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS;
        intent.setFlags(flags);
        startActivity(intent);
        finish();


The other possible solution: have TabQueueDispatcher *not* be a singleTask activity, and rely on it finishing itself.


Over to you, Martyn: you'll be at work pretty shortly, and you can try this out while fx-team is closed.
Assignee: nobody → mhaigh
Status: NEW → ASSIGNED
tracking-fennec: ? → Nightly+
Component: General → Overlays
Flags: needinfo?(rnewman)
Hardware: ARM → All
(Assignee)

Comment 4

3 years ago
Created attachment 8608019 [details] [diff] [review]
Nightly app does not appear in task switcher when opening external links

By Jove that worked!

I've twiddled the EXCLUDE_FROM_RECENTS flag when we initially grab the intent, so any further action taken will have that flag unset.

I've also removed the taskAffinity from the Service, as it's not supported, and moved it to the TabQueueDispatcher.  

Possible follow up bug would be to determine if the launchMode is actually needed for TabQueueDispatcher, as we call finish on all paths.
Attachment #8608019 - Flags: review?(rnewman)
Comment on attachment 8608019 [details] [diff] [review]
Nightly app does not appear in task switcher when opening external links

Review of attachment 8608019 [details] [diff] [review]:
-----------------------------------------------------------------

If it passes all of your tests, let's give it a shot!
Attachment #8608019 - Flags: review?(rnewman) → review+
https://hg.mozilla.org/mozilla-central/rev/ec09ecf7fc9f
Status: ASSIGNED → RESOLVED
Last Resolved: 3 years ago
status-firefox41: affected → fixed
Resolution: --- → FIXED
Target Milestone: --- → Firefox 41
(Reporter)

Comment 8

3 years ago
Nightly and gmail both appear in the task switcher, so verified as fixed using:
Device: Nexus 4 (Android 5.0)
Build: Firefox for Android 41.0a1 (2015-05-21)
Status: RESOLVED → VERIFIED
status-firefox41: fixed → disabled
You need to log in before you can comment on or make changes to this bug.