xuhcc / beancount-mobile

Data entry app for Beancount plain-text accounting system
GNU General Public License v3.0
114 stars 10 forks source link

Remove file permissions, use Storage Access Framework #6

Open bradyt opened 4 years ago

bradyt commented 4 years ago

I don't think this issue is a priority, but I think in the long term it is likely relevant.

I was able to use code examples at https://developer.android.com/training/data-storage/shared/documents-files to remove need for file permissions for my Android app.

I think then you could remove the following lines from App_Resources/Android/src/main/AndroidManifest.xml.

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

I'm not sure I'm reading this correctly, but it seems as soon as an app begins targeting Android 29, some of the old way of accessing files on Android will not be available. Note that ACTION_OPEN_DOCUMENT requires Android 19 but ACTION_GET_CONTENT only requires Android 16. A difference of about 3% of existing Android devices.

You could wait for one of your frameworks to implement this, I don't know if that would be NativeScript, Angular or Typescript. I've had to implement my own plugin for now, to get persistent and smooth read/write access to local files an Android.

You can see where I've implemented a custom plugin here: https://github.com/bradyt/cone/blob/v0.2.18/uri_picker/android/src/main/java/info/tangential/uri_picker/UriPickerPlugin.java#L81-L90.

EDITS:

  1. Where I said "Android 29", I meant API 29, Android 10, etc. See https://en.wikipedia.org/wiki/Android_version_history.
  2. I misspoke about ACTION_GET_CONTENT. That apparently goes back to API 1. But the framework goes back to API 17, if I'm reading this right: https://docs.nativescript.org/core-concepts/android-runtime/requirements. So then the difference in existing devices would only be 2%, according to https://developer.android.com/about/dashboards. You could use ACTION_GET_CONTENT to support those devices, but I think the user experience would be more like importing/exporting a file.
xuhcc commented 4 years ago

I'm not sure I'm reading this correctly, but it seems as soon as an app begins targeting Android 29, some of the old way of accessing files on Android will not be available.

Indeed, we had a problem with file access on Android 10. Temporary workaround was added in 69a88a30e438273e84faae9041bf8c10a1b3940f and I reported this problem to NativeScript team: https://github.com/NativeScript/NativeScript/issues/8203

bradyt commented 2 years ago

Indeed, we had a problem with file access on Android 10. Temporary workaround was added in 69a88a3 and I reported this problem to NativeScript team: NativeScript/NativeScript#8203

That issue was closed some months ago. I'm mildly curious if their fix is enough for this app. Isn't File.read only half the issue? You'll need File.write as well?

And does their approach to fixing File.read apply towards the direction of using Storage Access Framework to avoid requiring file permissions?

Above I mentioned hacking together my own use of Storage Access Framework, but fortunately @hpoul created file_picker_writable^1 and I have been using that. I believe the key idea is that they are using ACTION_OPEN_DOCUMENT at FilePickerWritableImpl.kt^2. Presumably we would want a NativeScript plugin that uses something like ACTION_OPEN_DOCUMENT in its implementation.

xuhcc commented 2 years ago

I think they fixed it in NativeScript 8.0 but this release contains so many breaking changes. Some plugins don't work at all and abandoned by their maintainers.