Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4750: Fixes SDK 31 support #4752

Merged
merged 5 commits into from
Nov 23, 2022
Merged

Fix #4750: Fixes SDK 31 support #4752

merged 5 commits into from
Nov 23, 2022

Conversation

BenHenning
Copy link
Sponsor Member

@BenHenning BenHenning commented Nov 21, 2022

Explanation

Fixes #4750

This PR fixes issues that were introduced in #4747 when trying to use the app on an actual API 31 device. The problems come from two breaking changes in Android 12:

  • Public activities, services, and providers must be marked as exported (this only affected our SplashActivity).
  • PendingIntents must be explicitly marked as mutable/immutable (this only affects WorkManager, but that's tricky for us).

The WorkManager issue was fixed in version 2.7.0 (where we currently depend on version 2.4.0), but we can't actually updated in a way that would be low-risk to cherry-pick (since it would require updating our Kotlin SDK to 1.5.x instead of 1.4.x). A safer option is to disable WorkManager outright, but while doing this I discovered that we have unrestricted getInstance() calls that will force WorkManager to get created regardless. This was fixed by introducing a new analytics-specific application creation listener and ensuring those do not get called for SDK 31+. #4751 is tracking fixing this longer term. Approximately 9% of our users will have analytics disabled until we properly fix it & push a new release.

Note that I opted for a fix-forward instead of rolling back #4747 since these are small PRs that need to be easily cherry-picked, and it's guaranteed that the target SDK change be isolated to SDK 31 devices (so developers would still be able to use the app on lower versions).

Proper testing for ensuring this works requires manual testing, for now (as we don't have automated end-to-end tests). I manually verified that the app opens and can be used on Android 12. One test exemption was added for the new listener since it's an interface and thus not testable.

A new regex check was also added to ensure WorkManager.getInstance calls always go through the new listener to avoid future situations where they can accidentally trigger an instance creation when it's not wanted.

Essential Checklist

  • The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • Any changes to scripts/assets files have their rationale included in the PR explanation.
  • The PR follows the style guide.
  • The PR does not contain any unnecessary code changes from Android Studio (reference).
  • The PR is made from a branch that's not called "develop" and is up-to-date with "develop".
  • The PR is assigned to the appropriate reviewers (reference).

For UI-specific PRs only

This is mainly an infrastructural change as it's literally fixing whether the app can open at all on SDK 31+ devices, so there's not much to show.

This ensures SplashActivity is properly exported, and that WorkManager
is disabled on SDK 31+ (since it requires a non-trivial version
upgrade).
@BenHenning BenHenning added the PR: Cherrypick requested Indicates that a PR is being requested for being cherrypicked into the ongoing release branch. label Nov 21, 2022
@BenHenning BenHenning marked this pull request as ready for review November 21, 2022 18:37
@BenHenning
Copy link
Sponsor Member Author

@seanlip PTAL (or @rt4914 if you get a chance).

@seanlip seanlip assigned BenHenning and unassigned seanlip Nov 21, 2022
Copy link
Contributor

@rt4914 rt4914 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

@rt4914 rt4914 removed their assignment Nov 22, 2022
@oppiabot oppiabot bot added the PR: LGTM label Nov 22, 2022
@oppiabot
Copy link

oppiabot bot commented Nov 22, 2022

Hi @BenHenning, this PR is ready to be merged. Please address any remaining comments prior to merging, and feel free to merge this PR once the CI checks pass and you're happy with it. Thanks!

@BenHenning
Copy link
Sponsor Member Author

Thanks all!

@BenHenning BenHenning enabled auto-merge (squash) November 23, 2022 05:56
@BenHenning BenHenning merged commit d7bb2a3 into develop Nov 23, 2022
@BenHenning BenHenning deleted the fix-android-31-support branch November 23, 2022 07:58
BenHenning added a commit that referenced this pull request Nov 23, 2022
## Explanation
Fixes #4750

This PR fixes issues that were introduced in #4747 when trying to use
the app on an actual API 31 device. The problems come from two breaking
changes in Android 12:
- Public activities, services, and providers must be marked as exported
(this only affected our SplashActivity).
- PendingIntents must be explicitly marked as mutable/immutable (this
only affects WorkManager, but that's tricky for us).

The WorkManager issue was fixed in version 2.7.0 (where we currently
depend on version 2.4.0), but we can't actually updated in a way that
would be low-risk to cherry-pick (since it would require updating our
Kotlin SDK to 1.5.x instead of 1.4.x). A safer option is to disable
WorkManager outright, but while doing this I discovered that we have
unrestricted getInstance() calls that will force WorkManager to get
created regardless. This was fixed by introducing a new
analytics-specific application creation listener and ensuring those do
not get called for SDK 31+. #4751 is tracking fixing this longer term.
Approximately 9% of our users will have analytics disabled until we
properly fix it & push a new release.

Note that I opted for a fix-forward instead of rolling back #4747 since
these are small PRs that need to be easily cherry-picked, and it's
guaranteed that the target SDK change be isolated to SDK 31 devices (so
developers would still be able to use the app on lower versions).

Proper testing for ensuring this works requires manual testing, for now
(as we don't have automated end-to-end tests). I manually verified that
the app opens and can be used on Android 12. One test exemption was
added for the new listener since it's an interface and thus not
testable.

A new regex check was also added to ensure WorkManager.getInstance calls
always go through the new listener to avoid future situations where they
can accidentally trigger an instance creation when it's not wanted.

## Essential Checklist
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

## For UI-specific PRs only
This is mainly an infrastructural change as it's literally fixing
whether the app can open at all on SDK 31+ devices, so there's not much
to show.
@BenHenning BenHenning added the PR: Cherrypick completed Indicates a cherrypick request was approved & completed for a PR. label Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Cherrypick completed Indicates a cherrypick request was approved & completed for a PR. PR: Cherrypick requested Indicates that a PR is being requested for being cherrypicked into the ongoing release branch. PR: LGTM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App can't be installed on SDK 31 devices
3 participants