31
31
import com .qihoo360 .i .Factory ;
32
32
import com .qihoo360 .loader2 .mgr .IServiceConnection ;
33
33
import com .qihoo360 .mobilesafe .core .BuildConfig ;
34
- import com .qihoo360 .replugin .utils .basic .ArrayMap ;
35
34
import com .qihoo360 .replugin .RePlugin ;
36
35
import com .qihoo360 .replugin .base .IPC ;
37
36
import com .qihoo360 .replugin .base .ThreadUtils ;
38
37
import com .qihoo360 .replugin .component .ComponentList ;
39
38
import com .qihoo360 .replugin .component .utils .PluginClientHelper ;
39
+ import com .qihoo360 .replugin .helper .JSONHelper ;
40
40
import com .qihoo360 .replugin .helper .LogDebug ;
41
41
import com .qihoo360 .replugin .helper .LogRelease ;
42
+ import com .qihoo360 .replugin .utils .basic .ArrayMap ;
43
+
44
+ import org .json .JSONArray ;
45
+ import org .json .JSONObject ;
42
46
43
47
import java .lang .reflect .Field ;
44
48
import java .lang .reflect .InvocationTargetException ;
45
49
import java .lang .reflect .Method ;
46
50
import java .util .ArrayList ;
51
+ import java .util .Map ;
47
52
import java .util .concurrent .Callable ;
48
53
49
54
import static com .qihoo360 .replugin .helper .LogDebug .LOG ;
@@ -422,7 +427,9 @@ private boolean installServiceLocked(ServiceRecord sr) {
422
427
sr .service = s ;
423
428
424
429
// 开启“坑位”服务,防止进程被杀
425
- startPitService ();
430
+ ComponentName pitCN = getPitComponentName ();
431
+ sr .pitComponentName = pitCN ;
432
+ startPitService (pitCN );
426
433
return true ;
427
434
}
428
435
@@ -487,7 +494,9 @@ private void recycleServiceLocked(ServiceRecord r) {
487
494
r .service .onDestroy ();
488
495
489
496
// 停止“坑位”服务,系统可以根据需要来回收了
490
- stopPitService ();
497
+ ComponentName pitCN = getPitComponentName ();
498
+ r .pitComponentName = pitCN ;
499
+ stopPitService (pitCN );
491
500
}
492
501
493
502
// 通过反射调用Service.attachBaseContext方法(Protected的)
@@ -535,6 +544,13 @@ public boolean unbindService(IServiceConnection conn) throws RemoteException {
535
544
return PluginServiceServer .this .unbindServiceLocked (conn );
536
545
}
537
546
}
547
+
548
+ @ Override
549
+ public String dump () throws RemoteException {
550
+ synchronized (LOCKER ) {
551
+ return PluginServiceServer .this .dump ();
552
+ }
553
+ }
538
554
}
539
555
540
556
// 通过Client端传来的IBinder(Messenger)来获取Pid,以及进程信息
@@ -548,19 +564,24 @@ private ProcessRecord retrieveProcessRecordLocked(Messenger client) {
548
564
return pr ;
549
565
}
550
566
551
- // 开启“坑位”服务,防止进程被杀
552
- private void startPitService () {
553
- // TODO 其实,有一种更好的办法……敬请期待
567
+ // 构建一个占坑服务
568
+ private ComponentName getPitComponentName () {
554
569
String pname = IPC .getCurrentProcessName ();
555
570
int process = PluginClientHelper .getProcessInt (pname );
556
571
557
- ComponentName cn = PluginPitService .makeComponentName (mContext , process );
572
+ return PluginPitService .makeComponentName (mContext , process );
573
+ }
574
+
575
+ // 开启“坑位”服务,防止进程被杀
576
+ private void startPitService (ComponentName pitCN ) {
577
+ // TODO 其实,有一种更好的办法……敬请期待
578
+
558
579
if (LOG ) {
559
- LogDebug .d (TAG , "startPitService: Start " + cn );
580
+ LogDebug .d (TAG , "startPitService: Start " + pitCN );
560
581
}
561
582
562
583
Intent intent = new Intent ();
563
- intent .setComponent (cn );
584
+ intent .setComponent (pitCN );
564
585
565
586
try {
566
587
mContext .startService (intent );
@@ -571,17 +592,14 @@ private void startPitService() {
571
592
}
572
593
573
594
// 停止“坑位”服务,系统可以根据需要来回收了
574
- private void stopPitService () {
575
- String pname = IPC .getCurrentProcessName ();
576
- int process = PluginClientHelper .getProcessInt (pname );
595
+ private void stopPitService (ComponentName pitCN ) {
577
596
578
- ComponentName cn = PluginPitService .makeComponentName (mContext , process );
579
597
if (LOG ) {
580
- LogDebug .d (TAG , "stopPitService: Stop " + cn );
598
+ LogDebug .d (TAG , "stopPitService: Stop " + pitCN );
581
599
}
582
600
583
601
Intent intent = new Intent ();
584
- intent .setComponent (cn );
602
+ intent .setComponent (pitCN );
585
603
try {
586
604
mContext .stopService (intent );
587
605
} catch (Exception e ) {
@@ -590,4 +608,34 @@ private void stopPitService() {
590
608
}
591
609
}
592
610
593
- }
611
+ /**
612
+ * dump当前进程中运行的service详细信息,供client端使用
613
+ *
614
+ * @return
615
+ */
616
+ private String dump () {
617
+
618
+ if (mServicesByName == null || mServicesByName .isEmpty ()) {
619
+ return null ;
620
+ }
621
+
622
+ JSONArray jsonArray = new JSONArray ();
623
+
624
+ JSONObject serviceObj ;
625
+ for (Map .Entry <ComponentName , ServiceRecord > entry : mServicesByName .entrySet ()) {
626
+ ComponentName key = entry .getKey ();
627
+ ServiceRecord value = entry .getValue ();
628
+
629
+ serviceObj = new JSONObject ();
630
+
631
+ JSONHelper .putNoThrows (serviceObj , "className" , key .getClassName ());
632
+ JSONHelper .putNoThrows (serviceObj , "process" , value .getServiceInfo ().processName );
633
+ JSONHelper .putNoThrows (serviceObj , "plugin" , value .getPlugin ());
634
+ JSONHelper .putNoThrows (serviceObj , "pitClassName" , value .getPitComponentName ().getClassName ());
635
+
636
+ jsonArray .put (serviceObj );
637
+ }
638
+
639
+ return jsonArray .toString ();
640
+ }
641
+ }
0 commit comments