android-permissionsfile-accessandroid-11

Android 11: avc: denied { read } for name="sdcard"


After upgrading to Android 11, access to my app’s files under /sdcard/Android/data/<packageId>/files is no longer possible. I get the following error:

type=1400 audit(0.0:672): avc: denied { read } for name="sdcard" dev="tmpfs" ino=6474 scontext=u:r:untrusted_app_29:s0:c244,c256,c512,c768 tcontext=u:object_r:mnt_sdcard_file:s0 tclass=lnk_file permissive=0 app=com.example.myapp

This behavior presists even after I request MANAGE_EXTERNAL_STORAGE in the manifest and grant it to the app.

I understand that, even with maximum storage permissions, Android 11 restricts access to certain paths, including /sdcard/Android/data. However, the directory I am trying to access is the app’s own data dir.

How do I get access to this path while using File and the like, rather than SAF?


Solution

  • Closer examination of the issue revealed that the app tried to access its own data dir through /mnt/sdcard/Android/data/<packageId>/files. While (on my device) /mnt/sdcard and /sdcard are both symlinks pointing to the same target, apparently they are not created equal.

    Removing the path setting, causing the app to fall back to the data dir as reported by the API, fixed things for me.

    I ran some more tests and found the following:

    It is also worth noting that the docs mention /sdcard specifically.

    Conclusion: App access to their external private storage area depends on the path used. Different ways of addressing the same path may yield different results.