Android APP进程保护,在APP进程异常崩溃后能够重启

这个地方借鉴了前一段时间吵得热闹的 蜻蜓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
 


                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值