owncloud / android

:phone: The ownCloud Android App
GNU General Public License v2.0
3.79k stars 3.05k forks source link

[BUG] Some bugs in log files downloads #4280

Closed Aitorbp closed 7 months ago

Aitorbp commented 7 months ago

Related Issues

App: https://github.com/owncloud/android/issues/4217

QA

Aitorbp commented 7 months ago

First of all, to access the device's downloads folder we need read permissions. But we have said that we do not want to ask the user for these permissions for security.

Another option would be to download the log to the Application Downloads folder in the internal storage (/storage/emulated/0/Android/data/com.owncloud.android.debug/files/Download). To download here we do not need permissions, but the problem is that I have not found a way to navigate to this route. Whatever behavior you choose, it always takes me either to the generic Downloads folder or to the Recent folder.

Android 9 (Pie) introduced additional restrictions on URI security, and this may affect how certain types of URIs are opened, especially those related to file access.

In any case, I would rule out this last option, the ideal would be to download in the external Downloads folder, not in an internal one, which is difficult for the user to locate.

In short, I would ask the user for read permissions or restrict the download of logs for users with devices lower than Android 10.

Aitorbp commented 7 months ago

In versions previous to API 29 we need permissions to access the public Downloads folder. When we call checkSelfPermission to check if Manifest.permission.WRITE_EXTERNAL_STORAGE is allowed by the user, we receive a denied permission, even if we have it set in the Manifest. For this reason it is necessary to ask permissions to the user at runtime to be able to make the download to the DOWNLOADS public folder.

I leave an extract of where I have extracted the information: Request permission to read and write to external storage if necessary. If you need to access files in the public Downloads directory, you will need to request permission to read and write to external storage. You can do this by calling the checkSelfPermission() method and then requesting permission if the app does not already have it. I also leave this other documentation where it clarifies for which version the permissions are requested: https://medium.com/@wanxiao1994/android-storage-permission-adaptation-and-reading-writing-media-files-6b85121c9461

Aitorbp commented 7 months ago

To add a little more information, we are going to use MediaStore for downloading logs on Android 10 onwards. Mediastore allows users to retrieve and update media files more easily. Even after uninstalling the app, these files remain on the user's device.

It is a more optimal tool than the ones used before. In fact, thanks to this we no longer need to manipulate the name of the log if it is repeated, it will be done internally.

Unfortunately, the APIs used in Android 10 are not available in earlier versions, which means we must request permissions at runtime for earlier versions. More information about this here.

So in this PR, we limit this new functionality to Android versions equal to or greater than 10.

michaelstingl commented 7 months ago

Unfortunately, the APIs used in Android 10 are not available in earlier versions, which means we must request permissions at runtime for earlier versions. More information about this here.

So in this PR, we limit this new functionality to Android versions equal to or greater than 10.

Works for me 👍

jesmrec commented 7 months ago

Checks:

jesmrec commented 7 months ago

About the PR, i'd not add a new Calens entry, since it's fixing something that is not released. We already have a Calens entry for the "download log file". I'd modify the existing one, clarifying the strict availability (Android10+) instead of adding two entries about same feature.

jesmrec commented 7 months ago

About changes on Go to Downloads option. I noticed a behaviour change with one device (Pixel 7, Android 14)

In current master, clicking to Go to Downloads open the app and shows the Download folder ✅ In current branch, clicking to Go to Downloads : No app found for this action

any relevant change that could break the pointer to Downloads?

In Pixel 2, i reproduce this in both master and current In Samsung Tab i do not reproduce neither in master nor in current

How is this filtered to choose the app to open the Downloads?

Aitorbp commented 7 months ago

I have done some changes and removed calens. Could you check this @jesmrec ?

jesmrec commented 7 months ago

Ready to go on my side!