Android Multi-User Mode

Source: Internet
Author: User
Keywords android multi user mode multi user mode android 2 users on android
Linux users and groups
Linux is a multi-user operating system, each user has a private space on the machine, especially it will have a quota of disk space to store files, receive private mail messages, etc. Linux must ensure that this part of the private space is only visible to its owner (similar to a bank account, of course only visible to the depositor himself), and it should ensure that no user can use system applications to infringe other users' private space ( Of course, you can't let others move the funds in my bank account casually).
Simple Application Server
USD1.00 New User Coupon
* Only 3,000 coupons available.
* Each new user can only get one coupon(except users from distributors).
* The coupon is valid for 30 days from the date of receipt.

In the Linux operating system, all users are identified by a unique user ID (UID->User ID). But if you choose to share information with other users, the shared user should be a member of one or more groups. This is identified by the group ID (GID->group ID) (several people have paid to establish a small company, this company name It is GID, our money is a shared resource, everyone can use and see). Each file can be associated with an exact group. For example, the user who is the file owner has read and write permissions for the file, while other users in the group only have read permissions, and users in the system that are not in the group do not have any permissions (not readable, not writeable, not executable).

Super user: In the Linux system, there is a special user -> super user (root), the root user can do almost anything in the Linux system, because the OS does not adopt a general protection mechanism for it, and the root user can access the system Each file can manage each user program that is running.

Switching between ordinary users and super users: Enter the command: su-on the Linux command line, and then enter the password of the root user to switch to the root user, but it is recommended that in general, do not use the root user at will, because the root user's operation mistakes will cause System files are lost or even system crashes.

On traditional computers, UIDs are followed by "people" (such as computer users or users). UID in Android is followed by "software" (such as Android applications).
Since every application has a UID, only with this UID can you access the relevant information covered by the UID. Therefore, if the UIDs of AP-1 and AP-2 are different, under the default (Default) situation, both parties cannot read the other's data. This divide-and-conquer approach can reduce malicious data damage by hacker software and improve the security of mobile phones.
When the mobile phone user (ie User) downloads your (ie developer) application, when it is installed (Install), Android will give a UID. This UID can be linked to the content of the AndroidManifest.xml file of the application. So when the User installs your application, you can view the contents of the AndroidManifest.xml file in the window on the screen. When viewing, the user will see your description of the purpose and permissions of the application. After you accept the program's intentions and permissions, Android will install it and give it a UID. In the unlikely event that there is a deviant behavior (attempting to make an unauthorized behavior) during the execution of your application, the user will get an Android warning message.

In some special cases, two applications can hold the same UID. For example, an application written by the same developer often needs to release a new version. These two versions of the program can hold the same UID to have the authority to transfer the copy of the data generated by the old version of the program to the new version of the software.


Pid is the process ID, Uid is the user ID, but Android is not the same as the computer. Each computer user has a Uid, which user starts the program, the Uid of this program is that user, and each program in Android has a Uid , By default, Android will assign a Uid with a different general level to each program. If the applications need to call each other, only the Uid can be the same. This makes the shared data have a certain degree of security. Data cannot be obtained randomly between software. There is only one Uid for the same application, so there is no problem of access rights between the activities under the application.


Regarding the APPID UID userid, in the case of a single user, the appid is the Uid. In the case of multiple users, the new uid is recalculated through the appid and userid
public static int getUid(@UserIdInt int userId, @AppIdInt int appId) {
    if (MU_ENABLED) {
        return userId * PER_USER_RANGE + (appId% PER_USER_RANGE);
    } else {
        return appId;
    }
}
UserHandle contains three concepts: userid, uid, appid
Userid: How many actual users are there. For example, if my father is very poor and wants to share a mobile phone with his son, then we can share two users with the mobile phone, user 0 and user 1. The applications and data of the two users are independent.

uid: related to the application process. Except for sharduid applications, the uid of each application of each user is different. The uid of user 0's application starts from ten thousand.

appid: related to app, appid with the same package name is the same. Even for different users. For example, you and your son have installed WeChat on this phone, but the appid of the two WeChat is the same.
The scope of appid is
public static final int FIRST_APPLICATION_UID = 10000;
 
/**
 * Last of application-specific UIDs starting at
 * {@link #FIRST_APPLICATION_UID}.
 */
public static final int LAST_APPLICATION_UID = 19999;
For the process of user group, UID like u0_a86. The first part of this UID represents userId, and the latter part represents appId (the result of subtracting Process.FIRST_APPLICATION_UID).

   //uid cannot exceed the limit. Android has classified UIDs. The UID of the process where the APK is applied starts from 10000.
    //The process of the system APK is less than 10000
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.