Android Source Search----Multi-user phone process problems

Source: Internet
Author: User

android4.2 added multi-user functionality and finally kept up with Linux in the long-overdue. But the mobile phone's multi-user is actually quite chicken, imagine mobile phone This mobile device is basically the unique ID of each person, so there is basically no multi-user sharing device situation. Because of this and the reason for the patent, so the multi-user function on the phone is turned off, only the multi-user on the tablet is open. But thanks to Google's developers for introducing a multiuser mechanism, it helps to develop some security systems.

But after opening the multi-user, there is a comparison of the egg pain is not able to call in multiple users to send text messages. Check the source of the knowledge, this is Android for the phone communication this piece is not long user compatibility adaptation. Just in the Phoneapp simple rude to do a single-user judgment if (userhandle.myuserid () = = userinfo.root_user_id), in other users can not use the phone and text messages at all. And there is no such communication demand on the tablet, so Google developers are not in this piece to do code adaptation. Alas, our company projects need this aspect of the function, that is, under the multi-user can also call to send text messages. So can only hard this scalp, to do Google personnel unfinished work. This process is painful after the early after looking for several phone aspects of the more familiar with the brother to help analyze code, add up to have a fast 10 days of work, finally initially meet the demand, can call to send text messages. Here are some of the problems encountered in this process, make an excerpt for forgetting.

First, understand the multi-user principle, even if the multi-user is exactly a what and what kind of implementation mechanism. Multi-user fixed-name thinking, is to isolate another user space on the same device, the program running in this space is isolated from the normal space running program, completely in two processes, of course, the storage of data, such as the database is completely independent. The most intuitive feeling is that two users in the same application, then the navigation page of the two applications need to walk two times. Of course, this involves a lot of isolation, such as install, lock screen, some settings, etc., so after looking at the source code after 4.2, will find that basically all the modules are related to multi-user judgment, this shows that android in the addition of users this feature, Google developers have done a huge amount of work Ah, Here expresses admiration and gratitude.

OK, gossip less, continue to talk about the phone process of multi-user problems.

One. Once a multiuser is created, there is a com.android.phone process under that user, but the process is completely out of the box because it has been judged in the process portal Phoneapp:

public void OnCreate () {
if (userhandle.myuserid () = = 0) {
We is running as the primary user, so should bring up the
Global phone state.
if (Msimtelephonymanager.getdefault (). ismultisimenabled ()) {
Mphoneglobals = new Msimphoneglobals (this);
} else {
Mphoneglobals = new Phoneglobals (this);
}
Mphoneglobals.oncreate ();
}
}

See, only 0 users (root user), the phone module can be initialized. So the first change here is to take away this judgment, this is very easy, no longer repeat.

The OnCreate () method in code location Android/packages/services/telephony/src/com/android/phone/phoneapp.java


Two. After removing the judgment, of course, I hope to call directly, but things will never be so smooth, then the following anomaly blocked the road:

E/androidruntime (3452): caused by:java.lang.SecurityException
E/androidruntime (3452):At Android.os.BinderProxy.transact (Native Method)
E/androidruntime (3452):At Android.os.ServiceManagerProxy.addService (servicemanagernative.java:150)
E/androidruntime (3452):At Android.os.ServiceManager.addService (servicemanager.java:72)
E/androidruntime (3452):At Com.android.internal.telephony.iccsmsinterfacemanager.<init> (iccsmsinterfacemanager.java:128)
E/androidruntime (3452):At Com.android.internal.telephony.PhoneProxy.init (phoneproxy.java:95)
E/androidruntime (3452):At Com.android.internal.telephony.phoneproxy.<init> (phoneproxy.java:84)
E/androidruntime (3452):At Com.android.internal.telephony.PhoneFactory.makeDefaultPhone (phonefactory.java:134)
E/androidruntime (3452):At Com.android.internal.telephony.PhoneFactory.makeDefaultPhones (phonefactory.java:59)
E/androidruntime (3452):At Com.android.phone.PhoneGlobals.onCreate (phoneglobals.java:416)
E/androidruntime (3452):At Com.android.phone.PhoneApp.onCreate (phoneapp.java:45)
E/androidruntime (3452):At Android.app.Instrumentation.callApplicationOnCreate (instrumentation.java:1009)
E/androidruntime (3452):At Android.app.LoadedApk.makeApplication (loadedapk.java:526)
E/androidruntime (3452):... More

Analysis of the Exception log, found to be in the addition of an SMS-related service isms failure, reported a SecurityException. But in the ordinary user under this service is added successfully, so there is a preliminary speculation, is to add the system services This action is not any process can do, because the average user under the phone process uid=1001, and in the multi-user phone uid=901001 (9 users), So guess is the bottom C code in the AddService of the caller did the permission control. Sure enough, tracking AddService source finally followed the C layer, in service_manager.c there is a Do_add_service () method, this method is ServiceManager AddService method of the final realization, In this method, the caller's UID is judged:

int Svc_can_register (unsigned uid, uint16_t *name)
{
if (uid = = 0) | | (uid = = Aid_system))
return 1;

for (n = 0; n < sizeof (allowed)/sizeof (allowed[0]); n++)
if (uid = = allowed[n].uid) && str16eq (name, allowed[n].name))
return 1;

return 0;
}

It can be found that only root,system, and the system based on the phone, SMS and other processes can be judged, and 9 users of the phone process uid==901001 (multi-user process Uid==userid*100000+uid), obviously not within this range, Of course, adding system services failed. The modification method is to add a multi-user compatibility uid = uid% 100000 in this area. In this way many users under the relevant process can also add system services.

Code location: Android/frameworks/native/cmds/servicemanager/service_manager.c's Svc_can_register () method.


Three. The service has been added, and things are far from over. Next, in multi-user, call "Unable to access mobile network".

Apparently the phone is not connected, check log.

I/rilj (3839): couldn ' t find ' rild ' socket; Retrying after timeout
I/rilj (3839): couldn ' t find ' rild ' socket; Retrying after timeout
I/rilj (3839): couldn ' t find ' rild ' socket; Retrying after timeout
I/rilj (3839): couldn ' t find ' rild ' socket; Retrying after timeout
I/rilj (3839): couldn ' t find ' rild ' socket; Retrying after timeout
I/rilj (3839): couldn ' t find ' rild ' socket; Retrying after timeout
I/rilj (3839): couldn ' t find ' rild ' socket; Retrying after timeout
E/rilj (3839): couldn ' t find ' rild ' socket after 8 times, continuing to retry silently

These logs were reported in the Ril.java. This is the Java layer and the RIL layer of communication class, and this exception is in the link with the Ril when reported, the explanation in the multi-user is not linked Ril.

Things are very difficult to get here, I have no contact with Ril communication this piece of AH. But the project is urgent, only to help the company's phone this research and development staff. Finally, Huang Tian, after discussions with the phone this person, after the discussion, found a solution: is in the user switch, the RIL a disconnection process, because the RIL link can only be a client link, and many users will have more than one phone process. So in this case, you must disconnect the RIL link from the previous user and relink the RIL in the new user. Sure, there's a need for someone familiar with the phone to find a way to switch links, and our company happens to have all the talent, and it's not too difficult to achieve such a solution.

At the same time, in order to connect the RIL also in the Activitymanagerservice startprocesslocked () method to open the phone process, the process of gid=1001. Here is a permission to judge, for gid!= 1001 of the process is not connected to the RIL service.


Four. To replace two system services when the user switches

Switch Phoneinterfacemanager in the phone service (call related)Iccsmsinterfacemanager switch isms (texting related)

These two modifications are primarily to ensure that when the user is switched back and forth, the other process obtains the phone text message related state operation through these two services correctly.


Well, the overall main thing is to do these four revisions. Although here is very simple, but the whole process is actually very long tangled, once thought can not solve, after all, Google personnel this piece is also a simple rude did not deal with. But fortunately it was finally solved with the help of my colleague.

Thanks to my colleague!


Android Source Search----Multi-user phone process problems

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.