All Projects → lcodecorex → Keepalive

lcodecorex / Keepalive

Licence: mit
Fighting against force-stop kill process on Android with binder ioctl / Android高级保活

Programming Languages

java
68154 projects - #9 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Keepalive

Androidsecurity
Android安全实践
Stars: ✭ 150 (-60.11%)
Mutual labels:  ndk, jni
Android Disassembler
Disassemble ANY files including .so (NDK, JNI), Windows PE(EXE, DLL, SYS, etc), linux binaries, libraries, and any other files such as pictures, audios, etc(for fun)files on Android. Capstone-based disassembler application on android. 안드로이드 NDK 공유 라이브러리, Windows 바이너리, etc,... 리버싱 앱
Stars: ✭ 250 (-33.51%)
Mutual labels:  ndk, jni
Jpegkit Android
Efficient JPEG operations for Android without the risk of an OutOfMemoryException.
Stars: ✭ 154 (-59.04%)
Mutual labels:  ndk, jni
Androiddevwithcpp
Android Develop With C++
Stars: ✭ 106 (-71.81%)
Mutual labels:  ndk, jni
Jni.hpp
A modern, type-safe, header-only, C++14 wrapper for JNI
Stars: ✭ 313 (-16.76%)
Mutual labels:  ndk, jni
Googleserialport
Android串口通信:抱歉,学会它真的可以为所欲为 ! ! !
Stars: ✭ 130 (-65.43%)
Mutual labels:  ndk, jni
Jnioor
基于C++模板函数与Fluent API设计的JNI反射库,极大的简化JNI反射调用,提高JNI开发效率与稳定性
Stars: ✭ 278 (-26.06%)
Mutual labels:  ndk, jni
Relinker
A robust native library loader for Android.
Stars: ✭ 2,612 (+594.68%)
Mutual labels:  ndk, jni
Camera2GLPreview
Android camera preview application using Camera2 API and OpenGL ES/Vulkan
Stars: ✭ 140 (-62.77%)
Mutual labels:  ndk, jni
NativeGL demo
此程序使用android native代码实现EGL,并使用SurfaceView作为OpenGL绘图窗口。即可提高图形渲染性能,又可使用java层定义的图形界面
Stars: ✭ 43 (-88.56%)
Mutual labels:  ndk, jni
Android Luajit Launcher
Android NativeActivity based launcher for LuaJIT, implementing the main loop within Lua land via FFI
Stars: ✭ 87 (-76.86%)
Mutual labels:  ndk, jni
SecurityDemo
ndk进行简单的签名校验,密钥保护demo,android应用签名校验
Stars: ✭ 22 (-94.15%)
Mutual labels:  ndk, jni
Androidlearn
Android Custom Views
Stars: ✭ 66 (-82.45%)
Mutual labels:  ndk, binder
Native Opencv Android Template
A tutorial for setting up OpenCV 4.5.0 (and other 4.x.y version) for Android in Android Studio with Native Development Kit (NDK) support.
Stars: ✭ 131 (-65.16%)
Mutual labels:  ndk, jni
Anyndk
🔥 Android native library, make your development faster and easier. Android各种native库,让你的开发更快更简单
Stars: ✭ 35 (-90.69%)
Mutual labels:  ndk, jni
ChangeVoice
NDK语音消息的变声处理
Stars: ✭ 33 (-91.22%)
Mutual labels:  ndk, jni
premake-android-studio
premake5 module for android-studio and gradle build.
Stars: ✭ 24 (-93.62%)
Mutual labels:  ndk, jni
Jni4android
JNI Generater for Android
Stars: ✭ 261 (-30.59%)
Mutual labels:  ndk, jni
Agentnet
Deep Reinforcement Learning library for humans
Stars: ✭ 298 (-20.74%)
Mutual labels:  binder
Nutzmore
让Nutz更好用
Stars: ✭ 328 (-12.77%)
Mutual labels:  activity

KeepAlive

KeepAlive是在Leoric(通过JNI复活进程)的基础上,实现了通过ioctl复活进程,能最大程度提高复活率。

master分支是利用 libbinder.so 与 ActivityManagerService 通信的版本,ioctl分支是使用 ioctl 与 binder 驱动通信的版本。

  1. 该项目仅供学习和参考,在android4.4到android9.0的模拟器上有效,在真机上不能保证保活成功(MIUI等定制系统已封杀了这个方案)。
  2. 对于自研轻量定制的 Android系统,对一些系统应用的保活,这个方案还是很有优势的。资源占用少,用户无感知,成功率高。
  3. 不建议在C端产品上使用。
  4. 可作为学习binder框架的一个案例。

使用方法

  1. 在Application中注册KeepAlive服务
@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    KeepAliveConfigs configs = new KeepAliveConfigs(
                    new KeepAliveConfigs.Config(getPackageName() + ":resident",
                            Service1.class.getCanonicalName()));
    KeepAlive.init(base, configs);
}
  1. Service1对应的进程名是":resident",或者其它任意命名
<service
    android:name="Service1"
    android:process=":resident" />

Service需要继承KeepAliveService,否则在Android4.4上将没有保活效果。

  1. 在合适的地方,启动Service1,它将自动唤醒保活进程
startService(new Intent(MainActivity.this, Service1.class));

如果需要服务自启动,看第6条。

  1. 忽略电池优化
configs.ignoreBatteryOptimization();
  1. 防止短时间内重复启动
// 配置短时间重启限制,每次重启间隔限制是10s,最多允许3次10秒内的连续重启
configs.rebootThreshold(10*1000, 3);

注:保活和重启限制相违背,更准确的应该做崩溃重启限制。

  1. 设置应用自启执行的操作
configs.setOnBootReceivedListener(new KeepAliveConfigs.OnBootReceivedListener() {
    @Override
    public void onReceive(Context context, Intent intent) {
        // 设置服务自启
        context.startService(new Intent(context, Service1.class));
    }
});

实现原理

应对方法

下面是一种简单的方法杀死 KeepAlive:

ps -A | grep `ps -A | grep keepalive | awk '{print $1}' | head -1` | awk '{print $2}' | xargs kill -19 && am force-stop com.boolbird.keepalive

对于系统有两种思路可以选择:

  1. 加入在 force-stop 期间不允许启动新的进程的逻辑
  2. 修改 force-stop 的杀进程逻辑为:预先收集好所有进程再进行 kill(如有必要还可以先发送 SIGSTOP)

测试

项目根目录下的kill_alive.sh用于重复杀进程测试。

问题

1、怎么保活多个进程 2、避免在Application中初始化第三方库,避免在所有进程都初始化第三方库

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].