Skip to content

Conversation

@ericli3690
Copy link
Member

@ericli3690 ericli3690 commented Aug 27, 2025

Purpose / Description

  • When AnkiDroid requests mandatory permissions on first-time-launch -- particularly below API 29 when it requests the storage permission -- providing the permission and then hitting continue causes the window to appear a second time. The user then needs to hit "Continue" for a second time.
  • Looking through the logs, this seems to be because the onStartupResponse listener attached to the StartupResponse StateFlow is being triggered twice with the RequestPermissions state, despite RequestPermissions only being posted to the StateFlow exactly once. This change sets the StateFlow's value to null when the RequestPermissions state is received, ensuring duplicate listener calls do not occur and ensuring the permission screen is only launched once.

Before Change, API 29- (BUG VISIBLE):
before_change_api29minus.webm

After Change, API 29-:
after_change_api29minus.webm

Before Change, API 30+:
before_change_api30plus.webm

After Change, API 30+:
after_change_api30plus.webm

Fixes

Approach

  • Simply sets the StateFlow to null after a StateFlow value of RequestPermissions is received.

How Has This Been Tested?

  • Solves the bug at and below API 29 on an emulated Pixel 3a, API 28.
  • On API 30+, (tested with a Medium Tablet, API 36), the previous flow was that the user would see the permissions screen for granting the external storage permission, click to enable it, be directed to the OS settings, and then click "back" to return to the app, where the switch would now be highlighted as "granted" and the continue button available for pressing. However, with this change, upon clicking "back" to return to the app, the DeckPicker activity will immediately launch. I personally think this is a fine change, and an ok price to pay for the lack of duplicate screens showing up below API 29. See the above videos.

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code

When AnkiDroid requests mandatory permissions on first-time-launch -- particularly below API 29 when it requests the storage permission -- providing the permission and then hitting continue causes the window to appear a second time. The user then needs to hit "Continue" for a second time.

Looking through the logs, this seems to be because the `onStartupResponse` listener attached to the StartupResponse StateFlow is being triggered twice with the RequestPermissions state, despite RequestPermissions only being posted to the StateFlow exactly once. This change sets the StateFlow's value to null when the RequestPermissions state is received, ensuring duplicate listener calls do not occur and ensuring the permission screen is only launched once.
@ericli3690
Copy link
Member Author

See the attached videos for a clearer picture of what this edit causes. Please also read what I've written under "How Has This Been Tested", too. Let me know if this is actually an intended feature.

Copy link
Contributor

@criticalAY criticalAY left a comment

Choose a reason for hiding this comment

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

LGTM!

@BrayanDSO BrayanDSO added this pull request to the merge queue Sep 4, 2025
@BrayanDSO BrayanDSO added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Review labels Sep 4, 2025
Merged via the queue into ankidroid:main with commit 0eca596 Sep 4, 2025
13 checks passed
@github-actions github-actions bot added this to the 2.23 release milestone Sep 4, 2025
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants