这个地方借鉴了前一段时间吵得热闹的 蜻蜓FM app的问题,蜻蜓FM app在内部做了5个进程,并且这5个进程互相保护,不被安全APP杀死.
大致的原理: 5个进程不断查询其他某一个进程的运行状况,当有所监查的进程不存在了,无论是因为安全软件kill了还是因为程序本身奔溃了,就将其重新启动,但是如果监控的服务和被监控的服务如果在同一个进程,那就无法实现,因为被监控的进程crash了,意味着监控的进程也crash了,那么两者都奔溃了,就不可能重启了,所以监控和被监控的两个对象必须不能够在同一个进程中.
下面做一个简单测试工程:
<1> : 工程树如下:
<2> : 工程文件内容如下:
IProtectServiceA.aidl
// IProtectServiceA.aidl package org.durian.durianprotectprocess; // Declare any non-default types here with import statements interface IProtectServiceA { /** * Demonstrates some basic types that you can use as parameters * and return values in AIDL. */ void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString); void startServiceB(); void stopServiceB(); }
IProtectServiceB.aidl
// IProtectServiceB.aidl
package org.durian.durianprotectprocess;
// Declare any non-default types here with import statements
interface IProtectServiceB {
/**
* Demonstrates some basic types that you can use as parameters
* and return values in AIDL.
*/
void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
double aDouble, String aString);
void startServiceA();
void stopServiceA();
}
ProtectServiceA.java