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 permission handling in Multimedia editor #5841

Merged

Conversation

david-allison
Copy link
Member

Purpose / Description

Editing a note, selecting "Record Audio", with denied & remembered permissions would soft crash the app.

Fixes

Fixes #5407

Approach

Explained in #5407

Define 3 transitions (between Multimedia UIs):

  • Init - initial load
  • UI - Menu Item is clicked, (changing from "Record Audio" to "Insert Image").
    • Treat this as cancellable
  • Activity - Pronunciation calls "Record Audio" with a known clip to allow for preview and pronunciation recreation.
    • This is invoked by the caller, so there's no way to know whether the previous UI is in a valid state. Treat this is non-cancellable.

  • Allow "Record Audio" to fail a transition
    • UI - Failing will keep the application on the previous multimedia UI.
      • Requires changes to avoid destroying the previous context until the new context validates.
    • Init - Cancel the Activity
    • Activity - Allow access to "Record Audio" without permissions
  • Save the state of a transition to allow the async onRequestPermissionsResult to reapply the context.
  • Mark the state as having "permissions requested", so they're not re-requested when calling recreateEditingUi
  • Show a toast notification on "Permission Denied"
  • Ensure "Record Audio" can be used without permissions.

How Has This Been Tested?

  • Deny permissions:
  • Selecting from the attachment fails and takes you back to the main screen/
  • A preview from pronunciation succeeds

Toasts are displayed on permissions issues.

Checklist

  • You have not changed whitespace unnecessarily (it makes diffs hard to read)
  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • Your code follows the style of the project (e.g. never omit braces in if statements)
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code

@david-allison
Copy link
Member Author

I worry this is too complex, I hope splitting this into commits makes it easier to review.

@david-allison
Copy link
Member Author

I'll get on with the auto fixes tomorrow

@mikehardy mikehardy added the Needs Author Reply Waiting for a reply from the original author label Mar 21, 2020
Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

I thought the separate commits made it pretty easy to review. I don't mind larger PRs especially if they show the transform in bite-size chunks like that - I keep the big diff open on one tab to make sure a comment I'd write isn't addressed somewhere later, and then flip through each commit - no problem.
Lots of little things I think but nothing serious that seemed off, and if it works, it works - I'll pull it and test it after this round
Good work digging through the advanced editor it's not easy to reason about

david-allison and others added 21 commits March 22, 2020 10:32
We can get to the AudioView screen from the pronunciation screen,
this is a one-way transition, and should succeed, even if we can't
use the screen to record audio.
Previously, we would get into a loop of asking for permissions if
the user ticked "deny & remember".

Now we close the dialog and cancel the activity.

We now only try and redraw if we were successful.

Fixes ankidroid#5407
If we went through the permission check once, we don't need to go
through it again
Previously, onLostFocus would kill the previous activity. If we fail
navigation due to permissions, then we had nowhere to go

Now, we only perform this if we have permission and can create a
field controller
@david-allison david-allison force-pushed the issue-5407-multimedia-permission-loop branch from 4f74876 to dc6615b Compare March 22, 2020 11:22
@david-allison
Copy link
Member Author

Review fixes done.

@timrae
Copy link
Member

timrae commented Mar 22, 2020

Codacy Here is an overview of what got changed by this pull request:

Issues
======
- Added 1
           

Complexity increasing per file
==============================
- AnkiDroid/src/main/java/com/ichi2/utils/Permissions.java  1
         

See the complete overview on Codacy

@mikehardy
Copy link
Member

Same as the other - this one looks great just waiting on CI to go through owing to macOS intermittency 💪

@mikehardy mikehardy removed the Needs Author Reply Waiting for a reply from the original author label Mar 22, 2020
@mikehardy mikehardy added this to the 2.9.6 Release milestone Mar 22, 2020
@mikehardy mikehardy changed the title Fixes #5407 - Multimedia Permission Denied Soft Crash Loop Fix permission handling in Multimedia editor Mar 22, 2020
@mikehardy mikehardy merged commit eb89b5b into ankidroid:master Mar 22, 2020
@mikehardy
Copy link
Member

2.10alpha54 released just now has this whenever google delivers it to you

@david-allison david-allison deleted the issue-5407-multimedia-permission-loop branch March 22, 2020 20:28
@mikehardy
Copy link
Member

released in 2.9.6beta4

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.

When I refuse recording permission, the application gets stuck.
3 participants