In-depth analysis of Android start-up network latency

Source: Internet
Author: User

In general, the phone's property is persistent to true, and therefore the phone process is also earlier called, the application that is android:presistent decorated will be started by am when the system is booted, even if it is not running, AM also calls startprocesslocked to start the process. Start the package com.android.phone called the phone application, which will call directly to Phoneapp's OnCreate (), performing an initial net-finding action.

We look at the source code as follows:

Alps\packages\services\telephony\androidmanifest.xml

<application android:name= "Phoneapp"

Android:persistent= "true"

......

Then the phone is normally called log should be as follows:

01-01 14:01:47.890:i/activitymanager (717): Start proc Com.android.phone for added application com.android.phone:pid= 991 uid=1001 gids={41001, 3002, 3001, 3003, 1028, 1015, 1004, 2002, 1023}
You can see from the above log that the phone process is normally called. But we go to look for the network delay of the phone to reproduce the time to find that the phone process is not normal, but is run in the phone process of the components launched, reference log as follows:

01-29 14:08:29.842:i/activitymanager (723): Start proc Com.android.phone for service com.mediatek.cellconnservice/. phonestatesmgrservice:pid=990 uid=1001 gids={41001, 3002, 3001, 3003, 1028, 1015, 1004, 2002, 1023}
From the log above you can see that the current phone process is called by the Cellconnservice.phonestatesmgrservice service, we view Phonestatesmgrservice source discovery, the service as a component of the phone running in the phone process. The reference source is as follows:

<applicationandroid:process= "Com.android.phone"//Through this android:process= "Com.android.phone" attribute, we can specify the process that a component runs. We can set this property so that each component runs in its own process, or only some components can share a process. We want to allow components in different applications to run in the same process by setting the "Android:process" property. Here Com.mediatek.CellConnService runs as a component in Com.android.phone
Android:allowclearuserdata= "false"
......
<service android:name= ". Phonestatesmgrservice ">
<intent-filter>
<action android:name= "Android.intent.action.Cellconnservice"/>
<action android:name= "Com.mediatek.CellConnService.IPhoneStatesMgrService"/>
</intent-filter>
</service>

Then if the phone process is called by the phone's interface, then the initialization of the network can not be done, but wait until the Alps\packages\services\telephony\androidmanifest.xml In the Otastartupreceiver receive boot_completed can call up Phoneapp, and then execute its oncreate () to initialize the operation to find the net. This will undoubtedly lead to a delay in finding the net. So at this point we need to find out where to start the phonestagtesmgrservice. Here we need to focus on an action---cellconnservicewith bold red above, and then we'll go over the log and refer to log as follows:

01-29 14:08:29.764:w/contextimpl (882): Implicit intents with StartService is not safe:intent {Act=android.intent.actio N.cellconnservice} android.content.contextwrapper.startservice:494 com.mediatek.cellconnservice.cellconnmgr.register:159 Com.android.systemui.huawei.mobilestatemanager.<init >:106
01-29 14:08:29.852:w/contextimpl (882): Implicit intents with StartService is not safe:intent {Act=android.intent.actio N.cellconnservice} android.content.contextwrapper.bindservice:517 com.mediatek.cellconnservice.cellconnmgr.register:160 Com.android.systemui.huawei.mobilestatemanager.<init >:106
01-29 14:08:32.294:w/contextimpl (882): Implicit intents with StartService is not safe:intent {Act=android.intent.actio N.cellconnservice} android.content.contextwrapper.startservice:494 com.mediatek.cellconnservice.cellconnmgr.register:159 Com.android.systemui.huawei.mobilestatemanager.<init >:106
01-29 14:08:32.307:w/contextimpl (882): Implicit intents with StartService is not safe:intent {Act=android.intent.action.cellconnservice} android.content.contextwrapper.bindservice:517 com.mediatek.cellconnservice.cellconnmgr.register:160 Com.android.systemui.huawei.Mobilestatemanager. <init>:106

From the log above we see that Mobilestatemanager started a service through intent, and the service that receives the intent is precisely phonestagtesmgrservice, the reference code is as follows:

Code one: The Phonestatesmgrservice interface is started here, in the class of cellconnmgr under Cellconnservic.
public void Register (Context ctx) {
LOG.D (TAG, "register");


Mctx = CTX;


Intent it = new Intent ("Android.intent.action.CELLCONNSERVICE");
Mctx.startservice (IT);
Mctx.bindservice (it, mconnection, context.bind_auto_create);
}
Code two: Here is a call to the constructor in Mobilestatemanager under Systemui
Public Mobilestatemanager (Context context) {
Mcontext = context;
Mcellconnmgr = new Cellconnmgr (null);
Mcellconnmgr.register (Mcontext);//The interface that initiates the Phonestatesmgrservice service is called here
Mitelephony = Getitelephony ();
Mconnmanager = (Connectivitymanager) mcontext.getsystemservice (Context.connectivity_service);
Updatesiminfolist ();
}

So we are here to optimize the code, so the problem is solved.

It is important to note that as a component run in the Com.android.phone process is not only com.mediatek.CellConnService, for example, Com.android.providers.telephony, etc., here I also put Com.androi D.providers.telephony called Com.android.phone analysis method to share with you.

Here is the log that calls the Com.android.phone process by calling Com.android.providers.telephony, as follows:

01-30 11:02:44.750:i/activitymanager (714): Start proc Com.android.phone for content provider com.android.providers.telephony/. telephonyprovider:pid=999 uid=1001 gids={41001, 3002, 3001, 3003, 1028, 1015, 1004, 2002, 1023}
You can see from the above log that the phone process was made by com.android.providers.telephony/. Telephonyprovider called, the following troubleshooting Telephonyprovider How to call the phone process.
First, by viewing the source confirmation can be as follows:
<application android:process= "Com.android.phone"
Android:allowclearuserdata= "false"
Android:allowbackup= "false"
Android:label= "@string/app_label"
android:icon= "@drawable/ic_launcher_phone" >


<provider android:name= "Telephonyprovider"
android:authorities= "Telephony"
Android:exported= "true"
Android:multiprocess= "false"/>
<!--m:code Analyze 002, new feature, Declear Cbprovider. @{--
<provider android:name= "Cbprovider"
Android:authorities= "CB"
Android:exported= "true"
Android:multiprocess= "false"/>
<!--@--
<provider android:name= "Smsprovider"
Android:authorities= "SMS"
Android:exported= "true"
Android:multiprocess= "false"
android:readpermission= "Android.permission.READ_SMS"
android:writepermission= "Android.permission.WRITE_SMS"/>
<!--m:code Analyze 003, new feature, Declear Wappushprovider. @{--
<provider android:name= "Wappushprovider"
Android:authorities= "Wappush"
Android:exported= "true"
Android:multiprocess= "false"/>
<!--@--
<provider android:name= "Mmsprovider"
Android:authorities= "MMS"
Android:exported= "true"
Android:multiprocess= "false"
android:readpermission= "Android.permission.READ_SMS"
android:writepermission= "Android.permission.WRITE_SMS" >
<grant-uri-permission android:pathprefix= "/part/"/>
<grant-uri-permission android:pathprefix= "/drm/"/>
</provider>
<provider android:name= "Mmssmsprovider"
Android:authorities= "mms-sms"
Android:exported= "true"
Android:multiprocess= "false"
android:readpermission= "Android.permission.READ_SMS"
android:writepermission= "Android.permission.WRITE_SMS"/>
<!--M:add for Mtk_only_owner_sim_support--
<provider android:name= "Usersmsprovider"
Android:authorities= "usersms"
Android:exported= "true"
Android:multiprocess= "false"
android:readpermission= "Android.permission.READ_SMS"
android:writepermission= "Android.permission.WRITE_SMS"/>
<provider android:name= "Usercbprovider"
Android:authorities= "USERCB"
Android:exported= "true"
Android:multiprocess= "false"
android:readpermission= "Android.permission.READ_SMS"
android:writepermission= "Android.permission.WRITE_SMS"/>
<provider android:name= "Usermmsprovider"
Android:authorities= "Usermms"
Android:exported= "true"
Android:multiprocess= "false"
android:readpermission= "Android.permission.READ_SMS"
android:writepermission= "Android.permission.WRITE_SMS" >
<grant-uri-permission android:pathprefix= "/part/"/>
<grant-uri-permission android:pathprefix= "/drm/"/>
</provider>
<!--@--
</application>
</manifest>
From the above source view Telephonyprovider belongs to the Com.android.phone process, you can call Telephonyprovider to start the phone process, so further troubleshooting, from the following log to determine the process ID is 878 Com.mediatek . Systemui in Activitymanager call Telephonyprovider, and make Telephonyprovider run on the phone process, And then started the com.andorid.phone process, that is to say we call up the telephonyprovider indirectly called the phone process, called the telephonyprovider of the conventional method is through the "content:// Telephony ", here to focus onandroid:authorities= "Telephony";
01-30 11:02:44.640:d/signalclusterview (878): Setwifiindicators, Visible=false, [email protected]0, [email protected], Contentdescription=wi-fi connection is disconnected
01-30 11:02:44.643:v/phonestatusbar (878): Carrierlabel for GEMINI=ANDROID.WIDGET.LINEARLAYOUT{42563B40 I.E ... ...... I. 0,0-0,0 #7f080013 App:id/carrier_label_gemini} show=true
01-30 11:02:44.658:d/activitymanager (714): getcontentproviderimpl:from [email protected] (pid=878) to get content provi Der Telephony
01-30 11:02:44.750:i/activitymanager (714): Start proc Com.android.phone for content provider com.android.providers.telephony/. telephonyprovider:pid=999 uid=1001 gids={41001, 3002, 3001, 3003, 1028, 1015, 1004, 2002, 1023}
From the above log it is 878 process (systemui) called com.android.providers.telephony/. Telephonyprovider (Process ID 999), that is, Systemui called the Telephonyprovider, and then called the Com.android.phone process. The reference log is as follows:

01-30 11:02:42.133:i/surfaceflinger (146): Eventthread Client Pid (714) created

So we need to troubleshoot the code in the Systemui, and refer to the following troubleshooting methods:

01-30 11:02:44.640:d/signalclusterview (878): Setwifiindicators, Visible=false, [email protected], [email protected], Contentdescription=wi-fi connection is disconnected
01-30 11:02:44.643:v/phonestatusbar (878): Carrierlabel for GEMINI=ANDROID.WIDGET.LINEARLAYOUT{42563B40 I.E ... ...... I. 0,0-0,0 #7f080013 App:id/carrier_label_gemini} show=true
01-30 11:02:44.658:d/activitymanager (714): getcontentproviderimpl:from [email protected] (pid=878) to get content provi Der Telephony
01-30 11:02:44.750:i/activitymanager (714): Start proc Com.android.phone for content provider com.android.providers.telephony/. telephonyprovider:pid=999 uid=1001 gids={41001, 3002, 3001, 3003, 1028, 1015, 1004, 2002, 1023}
From the above log it is 878 process (systemui) called com.android.providers.telephony/. Telephonyprovider (Process ID 999), that is to say, is still systemui called Telephonyprovider, and then called the Com.android.phone process.
Then according to the log in the Telephonyprovider process, the above marked red place (878 for the systemui process) to do the operation, the following is the source of the call relationship, from the following source to see that there are many places called Telephonyprovider, such as Huaweiquicksettingscontroller and so on. Need to check out why these places are called.

In the Siminfomanager class
public static final Uri Content_uri =
Uri.parse ("Content://telephony/siminfo");
......
public static list<siminforecord> getinsertedsiminfolist (Context ctx) {
Logd ("[getinsertedsiminfolist]+");
arraylist<siminforecord> simlist = new arraylist<siminforecord> ();
cursor cursor = ctx.getcontentresolver (). Query (Content_uri,
NULL, SLOT + "! =" + Slot_none, NULL, NULL);//Call here Telephonyprovider
try {
if (cursor! = NULL) {
while (Cursor.movetonext ()) {
Simlist.add (fromcursor (cursor));
}
}
} finally {
if (cursor! = NULL) {
Cursor.close ();
}
}
Logd ("[getinsertedsiminfolist]-" + simlist.size () + "infos return");
return simlist;
}

In the Simhelper class
private static list<siminfomanager.siminforecord> Getsortedsiminfolist (context context) {
list<siminfomanager.siminforecord> siminfolist = siminfomanager.getinsertedsiminfolist (context);
Collections.sort (Siminfolist, New comparator<siminfomanager.siminforecord> () {
.....
In the Phonestatusbar class

public void Showsimindicator (String businesstype) {
if (missimindicatorshowing) {
Hidesimindicator ();
}
Mbusinesstype = Businesstype;
Long Simid = Simhelper.getdefaultsim (Mcontext, Businesstype);
XLOG.D (TAG, "showsimindicator, show SIM indicator which business is" + Businesstype + "Simid =" +simid+ ".");
if (Simid = = Android.provider.Settings.System.DEFAULT_SIM_SETTING_ALWAYS_ASK) {
list<siminfomanager.siminforecord> Siminfos = simhelper.getsiminfolist (Mcontext);
....
There are many calls in the source code, perhaps in order to get the status of the SIM call Telephonyprovider, the specific cumbersome log and code is not explained.

To this entire analysis process is here, if in doubt can send a message to me, together to discuss.



In-depth analysis of Android start-up network latency

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.