WHY IS ADB DENIED ACCESS TO MULTI-USER STORAGE?
The whole story is about Android's filesystem emulation in order to have a permission-less directory (/sdcard
) which allowsmakes file sharing among multiple UNIX users (apps) possible. It's achieved through mount namespaces and different VIEWs of /data/media
mounted in /mnt/runtime/
. Apps belonging to secondary as well as primary user have isolated mount namespaces. For details please see What is the “u#_everybody” UID? and What is /storage/emulated/0/?.
HOW TO ACCESS MULTIPLE-USERS FILES FROM ADB
?
HOW TOWITH ROOT ACCESS MULTIPLE-USERS FILES FROM ADB
?:
With root access you You can mount the emulated filesystem without default_normal
option:
After reboot you should be able to read files in /storage/emulated/10
from adb shell
.
WITHOUT ROOT ACCESS:
On Android 9+ filesystem level access to secondary users/profiles is not possible from adb
on user
builds of ROMs (i.e. without root). Only interaction through adb
commands which support --user
option (am
, pm
, content
etc.) is possible. Documented in What’s in Android 9 for enterprise apps:
"To help keep work data in the work profile, the Android Debug Bridge (adb) tool can’t access directories and files in the work profile."
If the files owned by secondary users are accessible to primary user (through adb
or any other means, except through Device/Work Policy Controller app), it breaks the intended isolation between users/profiles which is controlled through Android APIs. See more details in How to share files between regular account and work account?
It should be noted that Android Debugging Bridge (adb
) is meant to be used by developers for debugging, not by end users. That's why a fully-managed device owner can completely disable adb
.
There's a suggested workaround to transfer data with secondary users/profiles as explained in Testing Multiple Users:
"
adb
(or more accurately theadbd
daemon) always runs as the system user (user ID = 0) regardless of which user is current. Therefore device paths that are user dependent (such as/sdcard/
) always resolve as the system user."
...
"Access to/sdcard
paths of secondary users is denied starting in Android 9."
...
"Becauseadb
runs as the system user and data is sandboxed in Android 9 and higher, you must use content providers to push or pull any test data from a nonsystem user."
For instance to transfer test.jpg
file to /storage/emulated/10/Pictures/
run the following commands from adb shell
:
~$ content insert --user 10 --uri content://media/external/images/media/ --bind _display_name:s:test.jpg
~$ ID=$(content query --user 10 --projection _id --uri content://media/external/images/media/ --where _display_name=\'test.jpg\' | grep -o '_id=[0-9]*' | cut -d= -f2)
~$ content write --user 10 --uri content://media/external/images/media/$ID < test.jpg
However it's not a practical approach for bulk data transfers on a regular basis.