jackBonadies / SeekerAndroid

Android client for the Soulseek peer-to-peer network
GNU General Public License v3.0
263 stars 4 forks source link

Using seeker on Android 12 requires setting directory everytime #17

Open keatit71 opened 2 years ago

keatit71 commented 2 years ago

Before updating to android 12 the app worked fine but now I can't choose the base download folder for seeker and even after creating another folder that works with it after every boot of the app I need to reselect it.

jackBonadies commented 2 years ago

Thanks for this, I will look into this now

shadowknight1620 commented 2 years ago

So I am able to select the download folder location in android 12. But after the app has been closed or shutdown when you boot it again it asks for the download folder location again and asks for folder access confirmation again. What is odd is sometimes it still has the location preserved when I boot it, yet more often it asks again. Wasn't an issue before and I've been using it on android 12 so I don't think it's only os related.

jackBonadies commented 2 years ago

Seeker will always remember the download folder location. The problem seems to be that on some devices the OS seems to revoke privileges, so even though Seeker remembers the location, it does not have proper privileges to write to it. I am not sure how to fix this. On invoking the intent to have the user select the folder I use flag "FLAG_GRANT_PERSISTABLE_URI_PERMISSION" and when they select the folder I call TakePersistableUriPermission which according to the docs is all that needs to be done (https://developer.android.com/reference/android/content/Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION). I have not been able to reproduce the issue on Samsung Android 12, unfortunately. Any ideas?

shadowknight1620 commented 2 years ago

The documentation says "Only URI permissions granted with Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION can be persisted." When using takePersistableUriPermission. But using FLAG_GRANT_PERSISTABLE_URI_PERMISSION needs combination with FLAG_GRANT_READ_URI_PERMISSION and/or FLAG_GRANT_WRITE_URI_PERMISSION, the URI permission grant can be persisted across device reboots until explicitly revoked with Context#revokeUriPermission(Uri, int).

This flag only offers the grant for possible persisting; the receiving application must call ContentResolver#takePersistableUriPermission(Uri, int) to actually persist.

I think this last bold part is maybe what you may be missing

shadowknight1620 commented 2 years ago

On a real note even if I must select a folder every boot I wouldn't really mind too much because having soulseek on my mobile is amazing and worth the little inconvenience of selecting the folder just for this app simply working. I thank you for your work on this, sincerely.

jackBonadies commented 2 years ago

TakePersistableUriPermission is called at what I believe are the two relevant places: https://github.com/jackBonadies/SeekerAndroid/blob/master/AndriodApp1/MainActivity.cs#L10073 https://github.com/jackBonadies/SeekerAndroid/blob/master/AndriodApp1/MainActivity.cs#L10153

And thanks for the kind words :) but I would still like to get this issue figured out somehow.. I know that for those who do have this problem it must be quite annoying.

jackBonadies commented 2 years ago

Perhaps enabling diagnostics would be helpful, if you would not mind! Though I don't know if diagnostics would reveal anything useful off the top of my head. I need to look closer at what it would be logging. And yes they are bitwise or - i.e. I want both Read and Write permission.

jackBonadies commented 2 years ago

The call wants to know which flags we want to persist. And I want both read (say 0x0001 for example) and write (0x0010) to persist. And so I OR them for 0x0011. If I AND'd them then I would get 0x0000 since the flags are exclusive. bitwise OR would combine them in this case, whereas bitwise AND would mask them.