background
Starting with version 4.2 , Android supports multi-user (link here and here).
Each user has its apps and their private data is visible just for the user.
The question
How does the encapsulation of the data per user work in terms of paths and accessing files?
I mean, what will be the paths per each user for:
- the private, internal storage.
- the emulated external storage (built in external storage)
- the "real" external storage (sd cards)
?
I guess users can see the data stored on the sd cards that belong to other users, but what about the emulated external storage? And can they also write other users' files or just read them?
Does each user get its own special path automatically? or should the developer handle this?
If the developer needs to handle it, what should be used as the ID of the user?
The documentation says:
No matter which of these APIs you use to save data for a given user, the data will not be accessible while running as a different user.
But that's all assuming you use the APIs for your own path. Could apps somehow bypass this by going to other paths?
What can an app query about each installation of itself on the same device? Can they get the size of apps of other users? Can they even get the list of apps of other users?
Does multiple installation of the same app also take multiple size?
If you care, you're doing it wrong. Use the Android SDK APIs for determining base directories, and work from there. So, for example:
getFilesDir()
will return the right location for internal storage for the current usergetExternalFilesDir()
and the methods onEnvironment
will return the right locations for external storage for the current userThat is outside the bounds of the Android SDK, generally.
Each user gets their own space.
Neither, barring bugs in the device.
Yes, if you are using the Android SDK APIs for determining base directories.
No, because they will have neither read nor write access, barring bugs.
AFAIK, nothing. From the app's standpoint, the fact that there are several installations on one device is indistinguishable from being installed on several devices.
I do not know what you mean by "size of apps", sorry.
That's a fine question. I have not experimented with
PackageManager
to see what it exposes when used by apps run by secondary users. In theory, it should only report things that are available to the current user, particularly given Android's restricted profiles.The APK and the pieces of it that are unpacked (e.g., DEX files) are shared, as I understand it.