Android 殺不死的程序

2021-08-09 14:57:28 字數 3509 閱讀 1187

首先,正常下,當我們退出程式或手動殺死後,我們的程式就停止執行了。或者不退出在後台執行時,使用360加速球清理時,也會殺死我們的程序。個人理解360加速時,把不被新增信任的程序用乙個for迴圈,在迴圈裡乙個個的kill。於是有了一種思路,在我們應用中開啟兩個程序,當乙個程序被殺死時,另外乙個程序啟動被殺死的程序,相互守護。沿著這思路,開始擼**。

1.建立兩個service:locationservice

和remoteservices

locationservice

代表主程序,remoteservices代表守護程序。這裡要實現remoteservices是另外的程序需要在androidmanifest

中配置:

<service

android

:name=

".remoteservices"

android

:enabled=

"true"

android

:exported=

"true"

android

:process=

".remoteservices"/>

接下來是要對這兩個service相互繫結,相互監聽對方的狀態。兩個程序中的通訊我們可以使用aidl,這裡不對aidl細講,不了解的朋友可以去查下。
建立乙個processidle.aidl檔案
// processidle.aidl

package inner;

inte***ce processidle

這裡只定義乙個方法getprocessname(),用於獲取程序名。接下來編寫locationservice

和remoteservices兩個類。

remoteservices
public classremoteservicesextendsservice 

@override

public intonstartcommand(intent intent,intflags,intstartid)

remoteservices.this.bindservice(newintent(remoteservices.this, locationservice.class),myconn, context.bind_important

);return

start_sticky

;

}@override

public voidoncreate()

//        showwindow("remoteservices*****=");

}classmybinderextendsprocessidle.stub

}classmyconnimplementsserviceconnection

@override

public voidonservicedisconnected(componentname name)

}windowmanagermwm;

textviewview;private voidshowwindow(string text)

@override

public voidondestroy()

}

locationservice

public classlocationserviceextendsservice

@override

public intonstartcommand(intent intent,intflags,intstartid)

locationservice.this.bindservice(newintent(locationservice.this, remoteservices.class),myconn2, context.bind_important

);return

start_sticky

;

}@override

public voidoncreate()

//        showwindow("locationservices*****=");

}classmybinderextendsprocessidle.stub

}classmyconn2implementsserviceconnection

@override

public voidonservicedisconnected(componentname name)

}windowmanagermwm;

textviewview;private voidshowwindow(string text)

@override

public voidondestroy()

}

這兩個類的**內容幾乎相同,其中的邏輯是先判斷另一程序是否在執行,如果否就先啟動,然後再進行繫結。當監聽到另一程序斷開時,就再次啟動並繫結。就是下面的**塊
class myconn2 implements serviceconnection 

@override

public void onservicedisconnected(componentname name)

}

Linux中殺不死的程序

前段時間,一哥們,去殺linux伺服器的程序,發現kill命令失靈了,怎麼殺都殺不死。然後上網查了下資料,原來是要被殺的程序,成為了殭屍程序。殭屍程序的檢視方法 利用命令ps,可以看到有標記為z的程序就是殭屍程序。知道了原因,就想怎麼去把這個殭屍程序乾掉。網上說了兩種方法,一種最簡單的方法,重啟伺服...

殺不死的Service

專案需要,這兩天研究了一下service 1 onstartcommand 中 return start stick 2 onstartcommand 中 startforeground 3 ondestroy 中 startservice 4 註冊broadcastreceiver 監聽系統廣播 ...

Android中的程序保活(不死程序)

android中的程序保活方式主要分為以下三種 白色保活 啟動前台service 灰色保活 利用系統的漏洞啟動前台service 黑色保活 白色保活灰色保活 這種保活手段是應用範圍最廣泛。它是利用系統的漏洞來啟動乙個前台的service程序,與普通的啟動方式區別在於,它不會在系統通知欄處出現乙個no...