Skip to content

Reader: Fix deeplink activity disable/enable - #13012

Merged
malinajirka merged 3 commits into
developfrom
issue/13010-fix-reader-deeplink-registration
Sep 24, 2020
Merged

Reader: Fix deeplink activity disable/enable#13012
malinajirka merged 3 commits into
developfrom
issue/13010-fix-reader-deeplink-registration

Conversation

@aforcier

Copy link
Copy Markdown
Contributor

Fixes #13010. Adjusts the way we disable/re-enable the Reader deeplink activity when opening an external URL so that it works correctly on all devices.

Relies on #13002 since that's where the issue was noticed, but I didn't want to bury this deep change in an apparently unrelated PR. That one should be mergable independent of this fix.

The first step to address the issue was to remove the re-enabling logic from this finally block, which it seems is too soon for some devices, and we end up with the deeplink activity being re-enabled before the intent is handled and appearing when it was supposed to be removed. (My best guess is that this has been happening for a while and we just didn't notice, and/or that perhaps behavior changed in recent Android API levels so that startActivity unblocks the main thread earlier than before.)

However, this introduced a different issue: as soon as the chooser menu was shown, the app would close. This is because the pm.setComponentEnabledSetting() with COMPONENT_ENABLED_STATE_DISABLED call causes the system to close the activity in question (ReaderPostPagerActivity) in some cases. If the external URL was opened from the reader detail view, that's actually the current activity, and the app closes.

I/WindowManager:   Force finishing activity ActivityRecord{ea34428 u0 org.wordpress.android.beta/org.wordpress.android.ui.reader.ReaderPostPagerActivity t28021}
I/WindowManager:   Force finishing activity ActivityRecord{fadbc24 u0 org.wordpress.android.beta/org.wordpress.android.ui.main.WPMainActivity t28021}

You may be able to confirm this by checking out fb58104.

To address this, I moved the intent-filter rules for ReaderPostPagerActivity to an activity-alias. That way we enable/disable the alias activity for deeplinking instead, and the system never tries to force finish the real ReaderPostPagerActivity.

Finally, I also added a new call to re-enable deeplinking, when the app is backgrounded (we already do this when WPMainActivity is created or resumed). This should replace the work the finally block was doing, ensuring that deeplinks are re-enabled as the user leaves the app. This way links visited outside the app can still be picked up by the WordPress app and open the Reader, as before.

To test:

Note that if you have multiple different builds of the WordPress app installed, the other builds will always show - that's expected and not something a regular user will experience.

  1. Visit an external link from the Reader (the globe icon in the action bar in detail view works, but also check a Story block on WordPress.com).
  2. Confirm that there is either no chooser screen (if you only have one browser installed), or that if there is a chooser the WordPress app isn't an option
  3. Dismiss the chooser, visit another link, confirm the same behavior
  4. Choose to open a link in the browser
  5. Without returning to the app, visit a blog post link on a WordPress.com site
  6. Confirm that the chooser appears, allowing you to open the post in the Reader

PR submission checklist:

  • I have considered adding unit tests where possible.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

The alias is necessary so that the system doesn't try to
destroy ReaderPostPagerActivity when we disable the deeplinking
component via PackageManager#setComponentEnabledSetting. We
instead disable the alias, which leaves the real activity alone
but disables the intent-filter deeplinking behavior as intended.

This especially matters when ReaderPostPagerActivity is the
current activity, for example when an external URL is opened
from the Reader, as this ends up closing the app.
This call is needed when the user navigates away from the app after
ActivityLauncher#openUrlExternal has disabled deeplinks, so that we
can still catch appropriate links visited before the user re-opens
the app.
@aforcier aforcier added this to the 15.9 milestone Sep 24, 2020
@peril-wordpress-mobile

Copy link
Copy Markdown

You can trigger optional UI/connected tests for these changes by visiting CircleCI here.

@peril-wordpress-mobile

Copy link
Copy Markdown

You can test the changes on this Pull Request by downloading the APK here.

Base automatically changed from feature/stories-reader-detail to develop September 24, 2020 09:27

@malinajirka malinajirka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about activity-aliases ;).

The changes look good to me. Great job on figuring it out!!!

SideNote: I found one super minor issue, but I personally wouldn't worry about it. When you open the "choose app" dialog and rotate the device, the app appears in the dialog.

@malinajirka
malinajirka merged commit f0f9666 into develop Sep 24, 2020
@malinajirka
malinajirka deleted the issue/13010-fix-reader-deeplink-registration branch September 24, 2020 09:28
@aforcier

Copy link
Copy Markdown
Contributor Author

SideNote: I found one super minor issue, but I personally wouldn't worry about it. When you open the "choose app" dialog and rotate the device, the app appears in the dialog.

😀 yeah agreed, let's just stop here, good thinking though 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reader: Links opened from Reader sometimes trigger the deeplink component

2 participants