Vulkan-Samples icon indicating copy to clipboard operation
Vulkan-Samples copied to clipboard

Android 11 Permissions

Open r-kaczynski opened this issue 3 years ago • 3 comments

Issue:

Vulkan Samples currently require access to directories/files outside the app's directory. Android 11 changed how storage permissions work and at the moment the only way to bypass the storage permission requirements is to request the MANAGE_EXTERNAL_STORAGE permission with adb. The Vulkan Samples application actually requests this permission already but it doesn't appear to work reliably, at least on S23. Similarly, we also have to manually create the output log directory to avoid exceptions being generated.

Proposed Fix:

  • Change the build system to pack the assets and shaders into the APK
  • Add an AssetManager class which makes use of AAssetManager to load assets
  • Change the filesystem and other asset loading code to support this
  • Modify the Java code to change the location of the external directory so that Vulkan Samples can output to a directory inside the app (Android/data/com.khronos.vulkan_samples/...)

A similar solution to this was previously proposed, and rejected: https://github.com/KhronosGroup/Vulkan-Samples/issues/39, but we feel that this is worth revisiting.

r-kaczynski avatar Mar 23 '23 11:03 r-kaczynski

Could we instead sync assets/shaders to a directory such as /sdcard/Android/data/com.khronos.vulkan_samples/files? would that require external storage permissions?

JoseEmilio-ARM avatar Apr 24 '23 15:04 JoseEmilio-ARM

I also checked it is not working well on Pixel 6 and S22 device, application cannot access asset and shader well. I change the logic and make a PR #678. Could you check it is working well on your device?

As I checked WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE don't need to request permission from API level 19. https://developer.android.com/reference/android/Manifest.permission#WRITE_EXTERNAL_STORAGE

And about pack the assets and shaders into the APK, I personally not recommend it. Because it has around 800MB currently with out compress, it could be huge size for APK even after compressed, and also it could increase build time.

stmazoni avatar Apr 25 '23 05:04 stmazoni

Just to help others hitting this, the workaround for samples not showing in the GUI in the current build is to manually grant the permissions:

adb shell pm grant com.khronos.vulkan_samples android.permission.READ_EXTERNAL_STORAGE
adb shell pm grant com.khronos.vulkan_samples android.permission.WRITE_EXTERNAL_STORAGE

However, it will still abort() because it cant create a log file:

Abort message: 'terminating with uncaught exception of type spdlog::spdlog_ex: Failed opening file /storage/emulated/0/com.khronos.vulkan_samples/output/logs/2023-05-24_09-09-13_log.txt for writing: No such file or directory

solidpixel avatar May 24 '23 08:05 solidpixel