How does the multi-user feature work in terms of paths on Android?

为君一笑 提交于 2019-12-06 10:42:59

问题


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:

  1. the private, internal storage.
  2. the emulated external storage (built in external storage)
  3. 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?


回答1:


what will be the paths per each user

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 user
  • getExternalFilesDir() and the methods on Environment will return the right locations for external storage for the current user

I guess users can see the data stored on the sd cards that belong to other users

That is outside the bounds of the Android SDK, generally.

but what about the emulated external storage?

Each user gets their own space.

And can they also write other users' files or just read them?

Neither, barring bugs in the device.

Does each user get its own special path automatically?

Yes, if you are using the Android SDK APIs for determining base directories.

Could apps somehow bypass this by going to other paths?

No, because they will have neither read nor write access, barring bugs.

What can an app query about each installation of itself on the same device?

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.

Can they get the size of apps of other users?

I do not know what you mean by "size of apps", sorry.

Can they even get the list of apps of other users?

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.

Does multiple installation of the same app also take multiple size?

The APK and the pieces of it that are unpacked (e.g., DEX files) are shared, as I understand it.



来源:https://stackoverflow.com/questions/23202936/how-does-the-multi-user-feature-work-in-terms-of-paths-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!