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

[BUG] Storage permission is asked in Android 13 and can't be granted #14423

Closed
WhtUsrWrks opened this issue Sep 11, 2023 · 90 comments · Fixed by #15825
Closed

[BUG] Storage permission is asked in Android 13 and can't be granted #14423

WhtUsrWrks opened this issue Sep 11, 2023 · 90 comments · Fixed by #15825
Labels
2.16 2.17 Bug Help Wanted Requesting Pull Requests from volunteers Priority-High
Milestone

Comments

@WhtUsrWrks
Copy link

Hi.. I hadn't used ankidroid so my Samsung Galaxy A21 removed its permissions, and I wanted to use it again today but when I open it it says "Grant storage permission", but I've granted all permissions and it still asks. I've tried u installing and reinstalling and it says the same thing. I don't seem to have a dedicated Storage Permission option in permission manager but it has permission for files and that's on... I don't know what else to change? Thank you

@welcome
Copy link

welcome bot commented Sep 11, 2023

Hello! 👋 Thanks for logging this issue. Please remember we are all volunteers here, so some patience may be required before we can get to the issue. Also remember that the fastest way to get resolution on an issue is to propose a change directly, https://github.com/ankidroid/Anki-Android/wiki/Contributing

@thedroiddiv
Copy link
Member

@WhtUsrWrks can you share screenshot of the permission screen and the popup where it is asking permissions? Or better maybe attach a screen recording.

@ByteCodeRoad
Copy link

I have the same issue on my Xiaomi Redmi Note 10 Pro. I have attached a screen recording and written some device info below.

  • Model: M2101K6G
  • MIUI version: MIUI Global 14.0.2.0(TKFMIXM)
  • Android version: 13 TKQ1.221013.002
  • Android security update: 2023-04-01
VID_20230913_155251.mp4

@thedroiddiv
Copy link
Member

Thanks for sharing!

@BrayanDSO
Copy link
Member

I'm pinning this so we don't forget it

@BrayanDSO BrayanDSO pinned this issue Sep 17, 2023
@BrayanDSO BrayanDSO changed the title How to grant storage permission again? [BUG] Storage permission is asked in Android 13 and can't be granted Sep 17, 2023
@Ezkielnet
Copy link

Hello.
I have the same problem with One Plus Nord 2, Android 13.

@lukstbit
Copy link
Member

Nobody mentioned which version of the app are they running. Is the app installed from the app store, downloaded from here etc?

@feleck
Copy link

feleck commented Sep 19, 2023

Version 2.6.15 from the app store. Android 13, pixel 6a

@WhtUsrWrks
Copy link
Author

WhtUsrWrks commented Sep 19, 2023 via email

@Ezkielnet
Copy link

Ezkielnet commented Sep 19, 2023

I could enter, unintentionally. I wanted to show you the gray error message at the bottom and when I hit Delete app data, the app opened.

Record_2023-09-19-19-25-11.mp4

@Sc3l3t0n
Copy link

Could this be the problem?
This would at least explain why the system does not ask for memory access in the first place.

Three new permission is introduced with Android 13: READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, and READ_MEDIA_AUDIO. If you were using READ_EXTERNAL_STORAGE for accessing files, then you need to use one of these new permissions. If a user with Android 13 has previously granted this permission, then all is good. If not, then the permission request for READ_EXTERNAL_STORAGE will be ignored.

Source: https://medium.com/@muhammadbilal4074/storage-permission-in-android-13-89372e543864#:~:text=Three%20new%20permission%20is%20introduced,permission%2C%20then%20all%20is%20good.

@queue-tip
Copy link

I experience the same running version 2.16.5 on Pixel 7 Pro with Android 13 (September 2023 update)

@hmenke
Copy link

hmenke commented Sep 23, 2023

Launching AnkiDroid this logcat is produced.

09-23 21:21:47.398 18391 19178 I Role    : com.ichi2.anki not qualified for android.app.role.HOME due to missing RequiredComponent{mIntentFilterData=IntentFilterData{mAction='android.intent.action.MAIN', mCategories='[android.intent.category.HOME]', mDataScheme='null', mDataType='null'}, mMinTargetSdkVersion=1, mPermission='null', mQueryFlags=0, mMetaData=[]}
09-23 21:21:47.401 18391 19178 I Role    : com.ichi2.anki not qualified for android.app.role.DIALER due to missing RequiredComponent{mIntentFilterData=IntentFilterData{mAction='android.intent.action.DIAL', mCategories='[]', mDataScheme='null', mDataType='null'}, mMinTargetSdkVersion=1, mPermission='null', mQueryFlags=0, mMetaData=[]}
09-23 21:21:47.404 18391 18642 I Role    : com.ichi2.anki not qualified for android.app.role.SMS due to missing RequiredComponent{mIntentFilterData=IntentFilterData{mAction='android.provider.Telephony.SMS_DELIVER', mCategories='[]', mDataScheme='null', mDataType='null'}, mMinTargetSdkVersion=1, mPermission='android.permission.BROADCAST_SMS', mQueryFlags=0, mMetaData=[]}
09-23 21:21:47.406 20072 20072 E AppInfoDashboard: Package: com.ichi2.anki not found for user: 10
09-23 21:21:47.406 20072 20072 E AppInfoDashboard: Package: com.ichi2.anki not found for user: 11
09-23 21:21:47.407  1494  5310 E AppOps  : Bad call made by uid 1000. Package "com.ichi2.anki" does not belong to uid -1.
09-23 21:21:47.407  1494  5310 E AppOps  : noteOperation
09-23 21:21:47.407  1494  5310 E AppOps  : java.lang.SecurityException: Specified package "com.ichi2.anki" under uid -1 but it is not
09-23 21:21:47.407  1494  5310 E AppOps  : 	at com.android.server.appop.AppOpsService.verifyAndGetBypass(AppOpsService.java:4703)
09-23 21:21:47.407  1494  5310 E AppOps  : 	at com.android.server.appop.AppOpsService.noteOperationUnchecked(AppOpsService.java:3466)
09-23 21:21:47.407  1494  5310 E AppOps  : 	at com.android.server.appop.AppOpsService.noteOperationImpl(AppOpsService.java:3454)
09-23 21:21:47.407  1494  5310 E AppOps  : 	at com.android.server.appop.AppOpsService.-$$Nest$mnoteOperationImpl(Unknown Source:0)
09-23 21:21:47.407  1494  5310 E AppOps  : 	at com.android.server.appop.AppOpsService$CheckOpsDelegateDispatcher.lambda$noteOperation$4(AppOpsService.java:7662)
09-23 21:21:47.407  1494  5310 E AppOps  : 	at com.android.server.appop.AppOpsService$CheckOpsDelegateDispatcher.$r8$lambda$oOwUoG55BBmJ6yiwhp3OAq3tQ30(Unknown Source:0)
09-23 21:21:47.407  1494  5310 E AppOps  : 	at com.android.server.appop.AppOpsService$CheckOpsDelegateDispatcher$$ExternalSyntheticLambda3.apply(Unknown Source:32)
09-23 21:21:47.407  1494  5310 E AppOps  : 	at com.android.server.policy.AppOpsPolicy.noteOperation(AppOpsPolicy.java:225)
09-23 21:21:47.407  1494  5310 E AppOps  : 	at com.android.server.appop.AppOpsService$CheckOpsDelegateDispatcher.noteOperation(AppOpsService.java:7660)
09-23 21:21:47.407  1494  5310 E AppOps  : 	at com.android.server.appop.AppOpsService.noteOperation(AppOpsService.java:3438)
09-23 21:21:47.407  1494  5310 E AppOps  : 	at com.android.internal.app.IAppOpsService$Stub.onTransact(IAppOpsService.java:479)
09-23 21:21:47.407  1494  5310 E AppOps  : 	at android.os.Binder.execTransactInternal(Binder.java:1309)
09-23 21:21:47.407  1494  5310 E AppOps  : 	at android.os.Binder.execTransact(Binder.java:1268)

@dae
Copy link
Contributor

dae commented Sep 24, 2023

@gragramel
Copy link

Dear AnkiDroid Team/Users,

I experienced the same with AnkiDroid 2.16.5 on Android 13 smartphone.
Nevertheless, I was able to workaround that blocking issue by doing the following:

  1. Cleaned up AnkiDroid app stored data (perhaps/probably optional)
  2. Uninstalled AnkiDroid 2.16.5 app
  3. Via Neo Store (F-Droid-like app), I managed to install older AnkiDroid 2.16.3 => OK (I was then able to: launch AnkiDroid, connect, sync and use app without any blocker)
  4. Still via Neo Store, I managed to upgrade to AnkiDroid 2.16.4 => OK (I was able to: launch AnkiDroid, then was asked to: "grant access to all files (special access)), then, once access granted, I was able to: connect, sync and use app without any blocker)
  5. Still via Neo Store, I upgraded to AnkiDroid 2.16.5 => OK (I was able to: launch AnkiDroid, connect, sync and use app without any blocker)

If I compare this situation to my initial launch of AnkiDroid (blocked by current issue), here is the main difference: First time, I was launching AnkiDroid (2.16.5) after a long period of inactivity (and multiple intermediate AnkiDroid updates), so last time I launched it, it was a version v2.x<2.16 (at that time, grant special access to all files was not yet required).

So from my own experience, and only based on it, here are my conclusions on that issue:

  • It appears that 2.16.4 (upgrading a fresh 2.16.3 install) behaves correctly and request user to grant AnkiDroid app to "access all files".
  • It appears that 2.16.5 (upgrading from old running 2.1x install) behaves unexpectedly and drives use to app properties/permissions, while it should drive it to: "special access" > "all files access" > AnkiDroid ( v ).

Hope this help.

Best regards,

@gregyski
Copy link

I experienced this as well.

Device: Pixel 7 Pro
Android version: 13
Android security update: 2023-08-05
Ankidroid version: 2.16.5

I exhibited the same symptoms as ByteCodeRoad's video, additionally looking under "...->All Permissions" and not finding Storage there either. Deleting app data as per Ezkielnet and then logging back in and syncing solved it.

@snowtimeglass
Copy link
Contributor

snowtimeglass commented Sep 30, 2023

when I hit Delete app data, the app opened.

Deleting app data as per Ezkielnet and then logging back in and syncing solved it.

@Ezkielnet @gregyski
Thank you for sharing information about the unexpected discovery.

Just to be sure, after tapping the "Get started" in the initial screen, were you actually able to see the deck list screen? (And it was without being asked for any sort of permissions?)

(I don't have an Android 13 device so I can't try this way myself.)

@Ezkielnet
Copy link

when I hit Delete app data, the app opened.

Deleting app data as per Ezkielnet and then logging back in and syncing solved it.

@Ezkielnet @gregyski Thank you for sharing information about the unexpected discovery.

Just to be sure, after tapping the "Get started" in the initial screen, were you actually able to see the deck list screen? (And it was without being asked for any sort of permissions?)

(I don't have an Android 13 device so I can't try this way myself.)

Yes, I can use the application perfectly. I can't be sure if it asks for permissions afterwards because I enabled them manually.

@snowtimeglass
Copy link
Contributor

Yes, I can use the application perfectly.

How nice. Thank you.

I can't be sure if it asks for permissions afterwards because I enabled them manually.

Which permission items did you manually enable?
(Are those in the ByteCodeRoad's video?)

@Ezkielnet
Copy link

Ezkielnet commented Sep 30, 2023

Which permission items did you manually enable? (Are those in the ByteCodeRoad's video?)

When I had the error I enabled all of them, but I just saw that none of them are active.

WhatsApp Image 2023-09-30 at 14 53 51_4574cf73

@gregyski
Copy link

gregyski commented Sep 30, 2023

when I hit Delete app data, the app opened.

Deleting app data as per Ezkielnet and then logging back in and syncing solved it.

@Ezkielnet @gregyski Thank you for sharing information about the unexpected discovery.

Just to be sure, after tapping the "Get started" in the initial screen, were you actually able to see the deck list screen? (And it was without being asked for any sort of permissions?)

(I don't have an Android 13 device so I can't try this way myself.)

If I'm understanding the question properly, before the "fix" I'd launch the app and be taken directly to permissions without ever seeing any of the Ankidroid interface. After the "fix", for all practical purposes I was starting with a fresh installation so I had to log in and sync to get my decks back from Ankiweb. I did not, at that time, get asked for any further permissions. Note that I had, when trying to fix the issue originally, manually enabled the "Read and write to the Ankidroid database" permission so that was set as well, so while that had no impact on the original problem, I don't know if it impacted the "fix". Hope that helps.

Edit: I just checked my permissions and things again match Ezkielnet. I currently show "No permissions allowed" despite my not actually adjusting them since the "fix". The app is working normally.

@snowtimeglass
Copy link
Contributor

So, after the "Delete app data", the prior manual permissions may be no impact or annulled, and the app works properly without requiring permissions... I think I have a better understanding of the situation. Thank you for the feedbacks.

@david-allison
Copy link
Member

A DocumentFile is an abstraction which can either be a file on the local system, or from a file provider such as Google Drive.

On the local file system, this can be between 20 and 100x slower for basic operations. Listing files can be significantly slower than this (if it works at all). These files do not support random access and can't be passed into any of the standard File-based APIs

On the network, the situation is worse. It depends on external providers, and there are known bugs where folder structures are not represented properly and the listing of files is incomplete

https://commonsware.com/blog/2019/12/01/scoped-storage-stories-problems-saf.html

In my opinion, it is not a safe API which we can use to copy an AnkiDroid collection & media. Especially as a failed transfer would permanently delete user data.


On the Play Store, we only support the removed storage permission if a user is using an older version of Android or if a user has upgraded from 2.15 to 2.16. A fresh install from the Play Store does not use any storage permissions on a modern version of Android.

This issue occurs because a user did not migrate their storage to the new location when prompted, and Android has revoked their permission to the legacy location.

When AnkiDroid had access to the legacy location, it produced backups which can be restored from, BUT: these backups do not include media (we have a huge cohort of users with gigabytes of media)

@alexanderadam
Copy link
Contributor

Thank you so much for your explanations!

In my opinion, it is not a safe API which we can use to copy an AnkiDroid collection & media. Especially as a failed transfer would permanently delete user data.

So how come that users don't experience any deleted data with other apps?
For instance apps like Round Sync do heavy I/O and I never experienced any deleted data.

And what is the long-term plan now?
Keeping AnkiDroid builds completely unusable instead of risking to use the newer API?

@david-allison
Copy link
Member

Round Sync uses MANAGE_EXTERNAL_STORAGE, which we can't use on Google Play:

https://github.com/newhinton/Round-Sync/blob/master/app/src/main/AndroidManifest.xml


The long term plan is above: #14423 (comment)

@mikehardy
Copy link
Member

I think that solution is fine in general (#14423 (comment))

We are already nagging people about doing the migration and syncing, I'm not sure what more we can do?

The string in your proposed patch could perhaps be less specific about no longer able to access after uninstall and more about "Your collection is in the shared storage area of your device, but we no longer have access to it and Google no longer permits us to request access to it." ...then the other stuff. It could be the system revoked permission, it could be they uninstalled/reinstalled, it could be the user themselves revoked permission... we're not sure why but we don't have permission so the string might be genericized a bit to reflect that

@david-allison
Copy link
Member

My patch definitely needs some TLC, I won't have time to bring it through

  • move the warning to when the user presses the button asking for permission
  • string fixes
  • (possibly) go through and handle 'restore backup'

@mikehardy mikehardy added Priority-Critical Help Wanted Requesting Pull Requests from volunteers 2.17 and removed Priority-High labels Feb 26, 2024
@alexanderadam
Copy link
Contributor

Round Sync uses MANAGE_EXTERNAL_STORAGE, which we can't use on Google Play:

https://github.com/newhinton/Round-Sync/blob/master/app/src/main/AndroidManifest.xml

I think it's also capable of using SAF.
It can't do random seek on large file (300 MB) in this example but I don't know whether this is relevant to Anki.

The long term plan is above: #14423 (comment)

Got it 👍

btw I really appreciate your communication to clarify things. 🙏

@TheAdityaGupta
Copy link

May I know what is the current status of this write external storage issue?
What is done?
What Can't be done?
What needs to be done? etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.16 2.17 Bug Help Wanted Requesting Pull Requests from volunteers Priority-High
Projects
None yet