Android Weixin Service

Source: Internet
Author: User
Tags eol

Brief introduction

Think for a long time, why the Android service kill not to die? Why does it automatically turn on accept messages without giving it permission or manually starting it? Is it weird?

Regardless of what method it uses, look at its source code, and then analyze the introduction of its own conclusions.


Service and broadcast in code analysis Androidmanifest.xml

<!--notification Broadcast accepts--><receiver android:name= "Com.tencent.mm.booter.NotifyReceiver" android:exported= "false"/&gt ; <receiver android:name= "com.tencent.mm.booter.notification.NotificationDeleteReceive"/><!--the Radio--- <receiver android:name= "Com.tencent.mm.sandbox.monitor.CrashUploadAlarmReceiver" android:exported= "false"/ ><receiver android:name= "Com.tencent.mm.booter.MountReceiver" > <intent-filter> <action Androi D:name= "Android.intent.action.MEDIA_MOUNTED"/> <action android:name= "Android.intent.action.MEDIA_EJECT"/&G        T <action android:name= "Android.intent.action.MEDIA_UNMOUNTED"/> <action android:name= "android.intent.acti On. Media_shared "/> <action android:name=" Android.intent.action.MEDIA_SCANNER_STARTED "/> <action A Ndroid:name= "Android.intent.action.MEDIA_SCANNER_FINISHED"/> <action android:name= " Android.intent.action.MEDIA_REMOVED "/> < Action android:name= "Android.intent.action.MEDIA_BAD_REMOVAL"/> <data android:scheme= "file"/> </i Ntent-filter></receiver><service android:name= "Com.tencent.mm.booter.notifyreceiver$notifyservice"/ ><service android:name= "Com.tencent.mm.modelfriend.addrbookobserver$addrbookservice"/><receiver Android:name= "Com.tencent.mm.booter.BluetoothReceiver" >//Bluetooth radio <intent-filter> <action Android:name = "Android.media.SCO_AUDIO_STATE_CHANGED"/> <action android:name= "android.media.ACTION_SCO_AUDIO_STATE_ UPDATED "/> </intent-filter></receiver><receiver android:name=" Com.tencent.mm.booter.InstallReceiver ">//Install package ads <intent-filter> <action android:name=" COM.ANDROID.V Ending.    Install_referrer "/>//only accept errors? </intent-filter></receiver><receiver android:name= "com.tencent.mm.booter.mmreceivers$ Toolsprocessreceiver "android:exported=" false "android:procesS= ": Tools"/><receiver android:name= "com.tencent.mm.plugin.backup.bakpcmodel.BakchatPcmgrNorify"//Notification bar broadcast Android:permission= "" > <intent-filter> <action android:name= "Mmbakchatservicestart"/> &L T;action android:name= "Mmbakchatservicestop"/> </intent-filter></receiver><service android:name = "Com.tencent.mm.plugin.backup.bakpcmodel.BakchatPcUsbService" android:exported= "false" > <intent-filter > <action android:name= "com.tencent.mm.plugin.backup.bakpcmodel.BakchatPcUsbService"/> </intent-fil Ter></service><service android:name= "Com.tencent.mm.booter.CoreService"//Core Services android:process= ":p Ush "/><service android:name=" com.tencent.mm.booter.cache.CacheService "//Buffer service android:process=":p Ush "/>< Receiver Android:name= "Com.tencent.mm.booter.mmreceivers$bootreceiver"//Start Broadcast android:process= ":p Ush" > <in Tent-filter> <action AndroiD:name= "Android.intent.action.BOOT_COMPLETED"/> </intent-filter></receiver><receiver android: Name= "Com.tencent.mm.booter.mmreceivers$connectionreceiver"//Connect webcasts android:process= ":p Ush" > < intent-filter> <action android:name= "Android.net.conn.CONNECTIVITY_CHANGE"/> </intent-filter>&lt ;/receiver><receiver android:name= "com.tencent.mm.booter.mmreceivers$alarmreceiver"//Timer android:process= " :p ush "/><receiver android:name=" com.tencent.mm.jni.platformcomm.Alarm "//Platform Timer android:exported=" false "an droid:process= ":p ush"/><receiver android:name= "com.tencent.mm.plugin.base.stub.wxentryactivity$ Entryreceiver "> <intent-filter> <action android:name=" Com.tencent.mm.plugin.openapi.Intent.ACTION_H Andle_app_register "/> <action android:name=" com.tencent.mm.plugin.openapi.Intent.ACTION_HANDLE_APP_ UNREGISTER "/> </intent-filter></receiver><service anDroid:name= "Com.tencent.mm.remoteservice.RemoteService"/> <receiver android:name= " Com.tencent.mm.modelstat.WatchDogPushReceiver "//Watchdog broadcast android:exported=" false "android:process=":p ush "/>< Service android:name= "Com.tencent.mm.pluginsdk.model.downloader.filedownloadmanger$filedownloadservice"/> <receiver android:name= "Com.tencent.mm.pluginsdk.model.downloader.filedownloadmanger$filedownloadreceiver" > <intent-filter> <action android:name= "Android.intent.action.DOWNLOAD_COMPLETE"/> <ac tion android:name= "Android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED"/> </intent-filter></receiver ><service android:name= "Com.tencent.mm.plugin.accountsync.model.AccountAuthenticatorService" Android:     Exported= "true" > <intent-filter> <action android:name= "Android.accounts.AccountAuthenticator"/> </intent-filter> <meta-data android:name= "Android.accounts.AccountAuthentiCator "android:resource=" @xml/g "/></service><service android:name=" Com.tencent.mm.plugin.accountsyn C.model.contactssyncservice "android:exported=" true "> <intent-filter> <action android:name=" Android Oid.content.SyncAdapter "/> </intent-filter> <meta-data android:name=" Android.content.SyncAdapter        "Android:resource=" @xml/bf "/> <meta-data android:name=" Android.provider.CONTACTS_STRUCTURE " Android:resource= "@xml/aa"/></service><receiver android:name= " Com.tencent.mm.plugin.gcm.modelgcm.GcmBroadcastReceiver "android:permission=" Com.google.android.c2dm.permission.SEND "> <intent-filter> <action android:name=" com.google.android. C2dm.intent.RECEIVE "/> <action android:name=" Com.google.android.c2dm.intent.REGISTRATION "/> <c Ategory android:name= "com.tencent.mm"/> </intent-filter></receiver><service android:naMe= "Com.tencent.mm.plugin.notification.ui.failsendmsgnotification$failsendnormalmsgnotificationservice"/> <service android:name= "com.tencent.mm.plugin.notification.ui.failsendmsgnotification$ Failsendsnsmsgnotificationservice "/><service android:name=" Com.tencent.mm.sandbox.monitor.ExceptionMonitorService "android:process=": Sandbox "/><service//service Android: Name= "Com.tencent.mm.sandbox.updater.UpdaterService" android:process= ": Sandbox"/><receiver//Android:name= "Com.tencent.mm.plugin.shoot.remote.remotenetscenemgr$respreceiver" android:exported= "false" android:process= ": Tools ">--></receiver><receiver//Register broadcast Android:name="        Com.tencent.mm.plugin.shootstub.communicate.ReqReceiver "android:exported=" false "> <intent-filter> <action android:name= "Com.tencent.mm.action.SHOOT_STUB_REQ"/> </intent-filter></receiver>// Web service <service android:name= "Com.tencent.mm.plugin.webview.stub.WebViEwstubservice "/> 
Coreservice Core Services

public class Coreservice extends Service implements F, AG, BS {private as EoE;//SDK Platform Library Private AB EoF = new AB ();//Network Letter Interest private Boolean EoG = true;public final int eoH = -1213;private Final AE EoI = new D (this);p rivate com.tencent.mm.modelst AT.K eoj = null; Telephone management interface Private Addrbookobserver eok; Local Contacts monitor private watchdogpushreceiver EoL; Watchdog (push message) private Wakerlock EoM = null;private com.tencent.mm.platformtools.k EoN = new COM.TENCENT.MM.PLATFORMTOOLS.K (); Platform Interface Private AX Eoo = new Ax (new E (this), false);//thread-related operations (similar to Handle) private void DV ()//restart {X.W ("[Email protecte D]/B4TB64LLPIZVC/MOQITZBN6RBAUK+SD "," [Complete EXIT] "); Br.is (). E (3, 10000," "); Bn.ondestroy (); try {// Timer MMReceivers.AlarmReceiver.ao (Getapplicationcontext ()); MMReceivers.AlarmReceiver.am (Getapplicationcontext ()); Alarm.ab (Getapplicationcontext ()); X.appenderclose (); Log Record process.killprocess (Process.mypid ()); return;} catch (Exception localexception) {}}public final void as (Boolean Paramboolean)//similar to start{if (!paramboolean) {X.W ("[EMAIL&NBSP;PROTECTED]/B4TB64LLPIZVC/MOQITZBN6RBAUK+SD", "[NETWORK LOST]"), Br. IO (). EBE = false;br. IP (). GN (0); Br. In (). A (10502, "", null); if (THIS.EOG) {br. IR (). Iy (); This.eoF.Ei ();} This.eog = false;} while (true) {RETURN;X.W ("[EMAIL&NBSP;PROTECTED]/B4TB64LLPIZVC/MOQITZBN6RBAUK+SD", "[NETWORK CONNECTED]"), Br. IO (). EBE = True;boolean bool = this.eoF.Ej (), if (THIS.EOG) && (!bool)) {object[] Arrayofobject = new Object[1];ar Rayofobject[0] = boolean.valueof (THIS.EOG); X.i ("[EMAIL&NBSP;PROTECTED]/B4TB64LLPIZVC/MOQITZBN6RBAUK+SD", "Network Not change or can ' t get network info, Laststatus connect:%b ", Arrayofobject);} if (bool) Br. IR (). Iy (); this.eog = true;br. IP (). GN (1); Br. In (). A (10501, "", null), if (This.eom = = null) This.eom = new Wakerlock (Getapplicationcontext ()); if (!this.eom.islocking ( )) This.eoM.lock (14000L); X.i ("[EMAIL&NBSP;PROTECTED]/B4TB64LLPIZVC/MOQITZBN6RBAUK+SD", "Checking ready, start in 7000ms "); This.eoO.dv (7000L);}} Public final Boolean B (int paramint, byte[] paramarrayofbyte) {int i = 0; if (Getsharedpreferences ("System_config_prefs", M.gh ()). Getboolean ("Settings_fully_exit", True)) x.i ("[email   PROTECTED]/B4TB64LLPIZVC/MOQITZBN6RBAUK+SD "," fully exited, no need to notify worker ");    while (true) {return i;    Intent localintent = new Intent (this, notifyreceiver.class);    Localintent.putextra ("Notify_option_type", 2);    Localintent.putextra ("Notify_uin", This.eoE.ID (). QK ());    Localintent.putextra ("Notify_resptype", paramint);    Localintent.putextra ("Notify_respbuf", paramarrayofbyte); Localintent.putextra ("Notfiy_recv_time", CM.    Jo ());    Localintent.putextra ("Notify_skey", This.eoE.ID (). Sq ()); X.I ("[Email protected]/b4tb64llpizvc/moqitzbn6rbauk+sd", "Notify broadcast:" + localintent.getaction () + ", type    = "+ Paramint);      try {sendbroadcast (localintent);    LABEL165:I = 1;      } catch (Exception localexception) {object[] Arrayofobject = new Object[1]; Arrayofobject[i] = localexceptIon.tostring ();      X.F ("[Email protected]/b4tb64llpizvc/moqitzbn6rbauk+sd", "OnNotify hasdestroyed%s", arrayOfObject); Break label165:}}}public ibinder Onbind (Intent paramintent) {x.d ("[Email protected]/b4tb64llpizvc/moqitzbn6rba Uk+sd "," onbind~~~ ThreadID: "+ thread.currentthread ()); return This.eoe;} @JgMethodChecked (author=20, fcomment= "checked", lastdate= "20140429", Reviewer=20, vcomment={  Com.jg.EType.RECEIVERCHECK}) public void OnCreate () {Object localobject = null;  X.D ("[Email protected]/b4tb64llpizvc/moqitzbn6rbauk+sd", "Oncreate~~~threadid:" + Thread.currentThread ());  Super.oncreate ();  if (Build.VERSION.SDK_INT < 18)//Set process properties according to version Startforeground ( -1213, New Notification ()); ClassLoader Localclassloader = CoreService.class.getClassLoader ();  Load Service O.A (COM.TENCENT.MM.SDK.A.JBQ, Localclassloader); The corresponding properties JBQ the following//public static string JBQ = "WECHATBASEPRJ",//public static string jBr = "wechatnetwork";//Public Stati C String jBs = "Wechatxlog";//public static string jBt =" Wechatkvcomm ";//public static string Jbu =" WECHATCDN ";//public static string JBV =    "Wechataccessory";//public static string jBx = "WECHATWEBP";//public static string jby = "Wechatutils"; AK Localak = new AK (Looper.getmainlooper ()); Message Thread Platformcomm.a (Ai.getcontext (), Localak),//Platform Universal interface g LOCALG = new g (this); A message localg.  DX ();  AC.A (THIS.EOI);  if (Platformcomm.exg = = null) Platformcomm.exg = this; BR.A (Localak);  Communication Interface Br.setcontext (Getapplicationcontext ());  BR.A (new Bt ());  Br.a (New Bu ()); BR.A (this);//Communication interface if (This.eoj = = null) This.eoj = new COM.TENCENT.MM.MODELSTAT.K ();  Network and push Br.a (THIS.EOJ);  BR.A (New BK ()); This.eoe = Br.  IR ();     if (This.eoe = = null) {x.i ("[Email protected]/b4tb64llpizvc/moqitzbn6rbauk+sd", "Autoauth is null and new one"); This.eoe = new as (Br.    Ae ());    BR.E (THIS.EOE);    Label228:bn.onCreate ();    if (br.is () = null) break label551; X.I ("[Email protected]/b4tb64llpizvC/moqitzbn6rbauk+sd "," Nettaskadapter is null and new one ");  BR.A (new BP ()); while (true) {if (br.it () = = null) {x.i ("[Email protected]/b4tb64llpizvc/moqitzbn6rbauk+sd", "Nettas      Kadapter is null and new one ");      BR.A (New Bo ());    Br.it (). EBo = this;    } String str1 = localg.getstring (". Com.tencent.mm.debug.server.host.http");    String str2 = localg.getstring (". Com.tencent.mm.debug.server.ports.http");    String STR3 = localg.getstring (". Com.tencent.mm.debug.server.host.socket");    String STR4 = localg.getstring (". Com.tencent.mm.debug.server.ports.socket");    This.eoe.c (str1, str2, STR3, STR4);    String STR5 = localg.getstring (". Com.tencent.mm.debug.server.host.newdns");    String STR6;    String STR7;    Label389:connectivitymanager Localconnectivitymanager;      if ((STR5! = null) && (Str5.contains (":"))) {string[] arrayofstring = Str5.split (":");      STR6 = arrayofstring[0];      STR7 = arrayofstring[1]; This.eoE.setNewDnsDEbughost (STR6, STR7); MMReceivers.AlarmReceiver.ao (Getapplicationcontext ());      Start Accepting MMReceivers.AlarmReceiver.an (Getapplicationcontext ());    Localconnectivitymanager = (Connectivitymanager) getsystemservice ("Connectivity");      } try {//network Networkinfo localnetworkinfo = Localconnectivitymanager.getactivenetworkinfo ();      Localobject = Localnetworkinfo; Label436:if ((Localobject! = null) && (localobject.getstate () = = NetworkInfo.State.CONNECTED)) Break label      581; Br.      IO (). EBE = false; Br.      IP (). GN (0);      Label464:this.eoK = new Addrbookobserver (this);      Getcontentresolver (). Registercontentobserver (COM.TENCENT.MM.PLUGINSDK.A.AJF (), True, This.eok);      This.eol = new Watchdogpushreceiver ();      Registerreceiver (This.eol, New Intentfilter ("Com.tencent.mm.WatchDogPushReceiver"));      O.A (Com.tencent.mm.sdk.a.jby, CoreService.class.getClassLoader ());      Return X.W ("[EMAIL&NBSP;PROTECTED]/B4TB64LLPIZVC/MOQITZBN6RBAUK+SD", "Autoauth is not null and reset");      This.eoE.reset (); Break LABEL228:LABEL551:X.W (' [email protected]/b4tb64llpizvc/moqitzbn6rbauk+sd ', ' nettaskadapter is ' not ' null a '      nd reset ");    Label581:br.IS (). reset (); } catch (Exception localexception) {x.e ("[Email protected]/b4tb64llpizvc/moqitzbn6rbauk+sd", "Getactivene      Tworkinfo failed. "); Break LABEL436:BR.      IO (). EBE = true; Br.      IP (). GN (1);      Break LABEL464:STR6 = STR5;      STR7 = null; Break label389:}}}public void OnDestroy ()//Destroy {X.D ("[Email protected]/b4tb64llpizvc/moqitzbn6rbauk+sd", "ondes troy~~~ ThreadID: "+ thread.currentthread ()); THIS.EOJ.A (10002, NULL, NULL); Push message related Getcontentresolver (). Unregistercontentobserver (This.eok); Cancel Address Book Monitor unregisterreceiver (This.eol); Cancel Push Super.ondestroy ();D V (); Restart}public void Onrebind (Intent paramintent) {x.d ("[Email protected]/b4tb64llpizvc/moqitzbn6rbauk+sd", " onrebind~~~ ThreadID: "+ thread.currentthread ()); Super.onrebind (paramintent);} public boolean onunbind (Intent paramintent) {x.d ("[Email protected]/b4tb64llpizvc/moqitzbn6rbauk+sd", " onunbind~~~ ThreadID: "+ thread.currentthread ()); Br. IO (). A (null); Communication Interface Br.iu (). A (null); return Super.onunbind (paramintent);} Public final void restartprocess ()//reboot for {X.W ("[Email protected]/b4tb64llpizvc/moqitzbn6rbauk+sd", " Restartprocess ");D V ();}}


Conclusion

Why does its service not kill the dead? The author guesses as follows:

1. Reflection modifies the system's properties on its own app so that it can accept the broadcast. (not found from the source)

2, the General SDK Library has a call, QQ, Address Book and other shared a library, this library to determine that the service is started. (not found from the source)

3, Timer cycle trigger start, for example: The end process is a time interval, whether to use this interval to start each other? (Guessing, not detailed follow-up source)

4, the app is listed as the system level, so as to install to the system directory. (not found in source code)


Whether the conclusion is right or not, you will know the result by self-test.


Android Weixin Service

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.