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

Android 11 refuses to write to Android\data\org.openorienteering.mapper\files on SD card #1861

Open
xianchb opened this issue Jan 25, 2021 · 12 comments · May be fixed by #1894
Open

Android 11 refuses to write to Android\data\org.openorienteering.mapper\files on SD card #1861

xianchb opened this issue Jan 25, 2021 · 12 comments · May be fixed by #1894

Comments

@xianchb
Copy link
Contributor

xianchb commented Jan 25, 2021

Steps to reproduce

  1. A new Android 11 device(Mi 11, MIUI 12.0.17)
  2. Copy a omap file from computer to Android\data\org.openorienteering.mapper\files
  3. After modifying this omap, unable to write in

This may be due to the new feature of Android 11, which limits the write in permission.

https://developer.android.com/about/versions/11/privacy/storage
Android 11 (API level 30) further enhances the platform, giving better protection to app and user data on external storage. This release introduces several enhancements, such as opt-in raw file path access for media, batch edit operations for media, and an updated UI for the Storage Access Framework.
The release also offers improvements to scoped storage, which makes it easier for developers to fulfill their storage use cases after they migrate to using this storage model.

Solution suggestions

Users are allowed to enter file paths and search for files themselves.

Configuration

Mapper Version: 0.9.4
Operating System: Android 11(Mi 11, MIUI 12.0.17)

@xianchb xianchb changed the title Android 11: Android 11:Unable to write to Android\data\org.openorienteering.mapper\files Jan 25, 2021
@xianchb xianchb changed the title Android 11:Unable to write to Android\data\org.openorienteering.mapper\files Android 11:Unable to write in Android\data\org.openorienteering.mapper\files Jan 25, 2021
@xianchb xianchb changed the title Android 11:Unable to write in Android\data\org.openorienteering.mapper\files Unable to write in Android\data\org.openorienteering.mapper\files Jan 26, 2021
@dg0yt
Copy link
Member

dg0yt commented Jan 26, 2021

Thank you very much for reporting this issue. It is surprising, but it is not the first time with Android.

Android\data\org.openorienteering.mapper\files is an app-specific directory. This type of storage is explicitly meant to to give exclusive access to the app with the given ID (org.openorienteering.mapper here) without needing special permissions.

The Mapper app is build with android:targetSdkVersion=28 i.e. it claims to target API level 28 (Android 9). Newer devices should provide an environment which allows the application to run without issues. In particular, I don't see relevant behavioural changes in Android 11 for apps targeting less than Android 11.

@dg0yt dg0yt added the Android label Jan 26, 2021
@xianchb
Copy link
Contributor Author

xianchb commented Jan 26, 2021

Thank you very much for reporting this issue. It is surprising, but it is not the first time with Android.

Android\data\org.openorienteering.mapper\files is an app-specific directory. This type of storage is explicitly meant to to give exclusive access to the app with the given ID (org.openorienteering.mapper here) without needing special permissions.

The Mapper app is build with android:targetSdkVersion=28 i.e. it claims to target API level 28 (Android 9). Newer devices should provide an environment which allows the application to run without issues. In particular, I don't see relevant behavioural changes in Android 11 for apps targeting less than Android 11.

Whether the user can input the file path and put it in another path or can solve this problem. Or add the identification of suffix. When you click the. omap file, a list of applications will pop up, but there is no OOM in the list.

@dg0yt
Copy link
Member

dg0yt commented Jan 26, 2021

Whether the user can input the file path and put it in another path or can solve this problem.

Sure. However this has never been easy with the desktop app on Android.

Or add the identification of suffix. When you click the. omap file, a list of applications will pop up, but there is no OOM in the list.

As a starting point, find out how to register a MIME type for *.omap on Android. Then we can register Mapper for that MIME type.

Ah, and probably you don't just want to open the map file, but also all the template files you copied along with the map.

@xianchb
Copy link
Contributor Author

xianchb commented Jan 26, 2021

Whether the user can input the file path and put it in another path or can solve this problem.

Sure. However this has never been easy with the desktop app on Android.

Or add the identification of suffix. When you click the. omap file, a list of applications will pop up, but there is no OOM in the list.

As a starting point, find out how to register a MIME type for *.omap on Android. Then we can register Mapper for that MIME type.

Ah, and probably you don't just want to open the map file, but also all the template files you copied along with the map.

I am an Android Developer, if OOM APP needs to modify the interface, or I can participate in the development

@lpechacek
Copy link
Member

For the record, I cannot reproduce on the vanilla Android 11 (Goole Pixel 2).

Whether the user can input the file path and put it in another path or can solve this problem.

Sure. However this has never been easy with the desktop app on Android.

As a side note, files can be stored in /OOMapper directory at the storage volume top level. This is documented at https://www.openorienteering.org/mapper-manual/pages/android-storage.html .

@dg0yt
Copy link
Member

dg0yt commented Jan 26, 2021

As a side note, files can be stored in /OOMapper directory at the storage volume top level.

I wouldn't rely on Android allowing this forever. However, the app-specifc path must work.

@dg0yt
Copy link
Member

dg0yt commented Jan 26, 2021

I am an Android Developer, if OOM APP needs to modify the interface, or I can participate in the development

This is very much welcome. Even testing/debugging with the latest version is a great contribution. The full zoo of Windows, macOS, Linux and Android targets doesn't leave much resources for each system in particular.

However, note that most code is C++, that we support ancient versions of Android (great Galaxy Note tabs with Android 4.4), and that we need to build all libraries from source if they are not part of the operating system.

For future progress, switching to Qt 5.15 will give us more features from the cross-platform framework, including access to Android Storage Access Framework, but it will also bump the required version of Android.

Some older notes are on https://github.com/OpenOrienteering/mapper/wiki/Android.

@dg0yt
Copy link
Member

dg0yt commented Jan 26, 2021

I tested in Android Emulator with Android 11 = API level 30 ("Pixel 3a") now: OOMapper works as expected. But I couldn't move a downloaded example map to the app-specific directory with the supplied files application.

@xianchb
Copy link
Contributor Author

xianchb commented Jan 27, 2021

For the record, I cannot reproduce on the vanilla Android 11 (Goole Pixel 2).

Whether the user can input the file path and put it in another path or can solve this problem.

Sure. However this has never been easy with the desktop app on Android.

As a side note, files can be stored in /OOMapper directory at the storage volume top level. This is documented at https://www.openorienteering.org/mapper-manual/pages/android-storage.html .

I've tested /OOMapper, write in succeeded. I didn't notice this storage method before. Thank you very much.

@dg0yt
Copy link
Member

dg0yt commented Jan 27, 2021

Now I managed to upload maps to the app-specific folders via Android Studio. Results:

  • (1) The app-specific folder on the device works as intented.
  • (2) The app-specific folder on the SD card is read-only in Android 11.
    The issue does not show in Android 10.
  • (3) When browsing the folders in Mapper, the test file is flagged with the info icon. But the only information is that the file is in app-specific storage where it will be removed when uninstalling the app.
    (4) In contrast, read-only files in the "Examples" location are flagged with a warning icon, and there is a proper warning about the read-only state when opening the file.

It would be good to find what is needed to fix (2) on Android 11 while keeping the target API level at 28 for now.
In addition, it would be useful to flag the files similar to (4) while the location is read-only.

@dg0yt
Copy link
Member

dg0yt commented Mar 7, 2021

I experiment with the Storage Access Framework (SAF) around ACTION_OPEN_DOCUMENT_TREE, based on a backport of code from Qt 5.15 to 5.12. While the backport itself is easy, it turns out to need more work:

  • Qt's implementation is not mature enough (e.g. https://bugreports.qt.io/browse/QTBUG-90761). In particular ACTION_OPEN_DOCUMENT_TREE is hardly usable. I needed to add modifications and bugfixes.
  • We cannot use QSaveFile for atomic saving (with the unsafe direct-write fallback disabled). For Android, this is the main blocker for now. We might get away with doing a backup copy first, and enable the fallback to "unsafe" writing. And possibly write slowly to a temporary location first, and the just quickly copy to the target location. Maybe this needs a re-implementation of QSaveFile.
  • We also need interfacing with GDAL if we don't want to cut away support for most geospatial formats. Just copying to the cache is not enough when it comes to sidecar files (world files etc.).

video3

@dg0yt dg0yt linked a pull request Mar 7, 2021 that will close this issue
@dg0yt
Copy link
Member

dg0yt commented Mar 8, 2021

Backport and changes to Qt: OpenOrienteering/superbuild#88

@dg0yt dg0yt changed the title Unable to write in Android\data\org.openorienteering.mapper\files Android 11 refuses to write to Android\data\org.openorienteering.mapper\files on SD card Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants