Sentaroh/SMBSync2

Android 11 Permissions issue

Closed this issue · 11 comments

Hi,
On Android 11, we now need to grant permission to access Non Specific App files/directories
Mainly, the /Android/data and /Android/obb

I saw that you once enabled it in older commits, before it was removed. Now, SMBSync 2 is no more able to access the above two paths on Android 11

Is there a reason the "ask for permissions" feature for the non specific apps paths was removed ? I see that File Explorer applications can still use that permission

Best regards

Hi,

Since Android 11, /Android/data and /Android/obb no longer have access rights, so they are no longer accessible.
https://developer.android.com/training/data-storage/manage-all-files#operations-allowed-manage-external-storage

Best regards.

I am aware of it,
However, the real issue is not with Android/data and Android/obb, but with more important /Download folder.
Currently, SMBSync2 can no loger sync the files in /Download when target is API 30.

Solutions:

  • when an app uses FLAG_GRANT_READ_URI_PERMISSION and FLAG_GRANT_WRITE_URI_PERMISSION, it can allow third party apps to access a specific app folder. Can this fix the issue for SMBSync2 to access /Download ? I am not sure if this needs a special permission in the client app, or if it is automatically achieved when the app targets API 30. I am quiet sure that /Download has by default the FLAG_GRANT_WRITE_URI_PERMISSION set to allow apps to download files there !

Another solution:

  • after further reading, I understand why apps like MixPlorer or the default built in file managers can access Android/data, Android/obb and /Download
    Answer:

Are there any exceptions for Android/obb directories given that some package installers, like app stores, need access to it?
Apps that hold the REQUEST_INSTALL_PACKAGES permission can access other apps’ Android/obb directories.

Since these apps allow installing third party apk, they can access these folders once they are granted REQUEST_INSTALL_PACKAGES permission.
Do you think it is needed for SMBSync to have this permission ?

Access is not vital for Android/data and Android/obb , but not having it for /Download is annoying

Thank you and best regards

For the above issue regarding the Download folder:
https://developer.android.com/about/versions/11/privacy/storage#test-file-directory-access

  1. Invoke an intent with the ACTION_OPEN_DOCUMENT action. Check that the Android/data/ and Android/obb/ directories both don't appear.
  2. Do one of the following:
  • Enable the RESTRICT_STORAGE_ACCESS_FRAMEWORK app compatibility flag.
  • Target Android 11 or higher.
  1. Invoke an intent with the ACTION_OPEN_DOCUMENT_TREE action. Check that the Download directory appears and the action button associated with the directory is grayed out.

Not sure if there is something I missed, but access to Download should be possible
Currently, I cannot access any zip/pdf files downloaded there

Hi,

REQUEST_INSTALL_PACKAGES permission.

It is not a file manager app, so we consider it unnecessary.

When the Target SDK is Android 11 or later, "ALL_FILE_ACCESS" must be enabled in order to access the "Download" directory.
https://developer.android.com/training/data-storage/manage-all-files

I'm thinking of asking for permission to use "ALL_FILE_ACCESS" in Android 12.

Best regards.

I'm thinking of asking for permission to use "ALL_FILE_ACCESS" in Android 12.

Well, does it mean that on Android 11 we will not be able to access Downloads folder ?

It is very easy to add the MANAGE_EXTERNAL_STORAGE permission to the Manifest and the needed intent for ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION

However, it seems that it is not enough to browse Downloads folder. It needs more code for MediaStore.Downloads.INTERNAL_CONTENT_URI and MediaStore.Downloads.EXTERNAL_CONTENT_URI

I do not want to add it as I am not sure it is how you want to implement it. Furthermore, your app will not be allowed into Play for now because of a temporary covid19 Android policy forcing devs to wait early 2021 before accepting new requests for MANAGE_EXTERNAL_STORAGE permission

It is just very annoying because the Downloads folder is one worth to sync like the media files

Best regards

Hi,

Well, does it mean that on Android 11 we will not be able to access Downloads folder ?

If you get permission from the Downloads directory with "ACTION_OPEN_DOCUMENT_TREE", you can access the files, but I don't think it is possible to implement it in SMBSync2 because it requires special processing.
For this reason, I chose "ALL_FILE_ACCESS".

I'm thinking of implementing "ALL_FILE_ACCESS" after seeing the trend of Android 12.

Best regards.

If you get permission from the Downloads directory with "ACTION_OPEN_DOCUMENT_TREE", you can access the files, but I don't think it is possible to implement it in SMBSync2 because it requires special processing.

You are right, it doesn't work, I tested a few ways. I do not plan to continue and add a custom build support if you do not want it because you cannot merge it to Play for now.

However, what about a fix like this:

  • you add a popup warning on first start when target SDK is 30 to warn user that Downloads folder is no longer supported temporarily due to Google Covid-19 Policy until sometime in 2021
  • you add debug code for ALL_FILE_ACCESS
  • once Google Play Policy allows again the MANAGE_EXTERNAL_STORAGE policy later in 2021, you activate the debug code

Because, meanwhile, the Downloads folder is silently failing to sync without any notification/message to user. At first, on my new Galaxy S20, I thought it was a bug. That's why I got back looking at the sources :-)

Best regards

Because, meanwhile, the Downloads folder is silently failing to sync without any notification/message to user.

In my environment (Pixel4A Android11 Build:RQ1A.2021205.008) and Emulator (Android11), I am able to access the download directory without any problems.
Are there any special conditions?
image

Best regards.

I tested on Galaxy S20 with Android 11 and the emulator
I have access to Downloads, but no files are synchronized and target files are deleted because app does not see them in Master

For android/data, I get the permission denied warning, but not for files in Downloads

Can you try again the sync of newly downloaded zip files for example ?

Best regards

Hi,

This is the result of a normal termination tested with the emulator.
1.Delete the files contained in the "Download" directory.
2.Download zip file(DSC_0002.zip) from SMB server.
3.Perform sync(/storage/emulated/o/Download to /storage/1F07-2019/Download)

Have you tried uninstalling and installing the app in Emulator and testing it?

logcat.txt
SMBSync2_profile_2021-01-14_00-15-44.txt
DSC_0002.zip

Best regards.

I am really sorry, after checking the debugger, it was caused by "Synchronize the files in root of the master directory" option unchecked AND Download folder set as the Master.

I kinda thought the option was only targeting the files in root of the sdcard. The description is clear however. I just forgot how it works and did not pay attention at the setting.

Sorry for the wasted time, but it now works properly even on Android 11

Many thanks again and best regards