Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ioctl #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ lint/outputs/
lint/tmp/
# lint/reports/
/.idea/
/.idea/
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/compiler.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/encodings.xml

This file was deleted.

25 changes: 0 additions & 25 deletions .idea/jarRepositories.xml

This file was deleted.

98 changes: 0 additions & 98 deletions .idea/misc.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# KeepAlive
KeepAlive是在[Leoric](https://github.com/tiann/Leoric)(通过JNI复活进程)的基础上,实现了通过ioctl复活进程,能最大程度提高复活率。
KeepAlive(通过JNI复活进程),实现了通过ioctl复活进程,能最大程度提高复活率。

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

**注**:
1. 该项目仅供学习和参考,在android4.4到android12.0的模拟器上有效,在真机上没有全面测试
1. 该项目仅供学习和参考,在android4.4到android9.0的模拟器上有效,在真机上不能保证保活成功(MIUI等定制系统已封杀了这个方案)
2. 对于自研轻量定制的 Android系统,对一些系统应用的保活,这个方案还是很有优势的。资源占用少,用户无感知,成功率高。
3. 不建议在C端产品上使用。
4. 可作为学习binder框架的一个案例。
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {

defaultConfig {
applicationId 'com.boolbird.keepalive'
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
Expand All @@ -27,6 +27,6 @@ android {
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar", '*.aar'])
implementation project(path: ':library')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":library")
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<service
android:name="com.boolbird.keepalive.demo.Service1"
android:process=":resident" />
<service android:name="com.boolbird.keepalive.demo.Service2" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Doc说明 (此类核心功能):
* +---------------------------+
* | @author qihao |
* | @date on 2021/5/10 15:28 |
* | @date on 2021/5/10 16:12 |
* +---------------------------+
* ┌─────────────────────────────────────────────────────────────┐
* │┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐│
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Doc说明 (此类核心功能):
* +---------------------------+
* | @author qihao |
* | @date on 2021/5/10 15:28 |
* | @date on 2021/5/10 16:12 |
* +---------------------------+
* ┌─────────────────────────────────────────────────────────────┐
* │┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐│
Expand Down
30 changes: 16 additions & 14 deletions app/src/main/java/com/boolbird/keepalive/demo/Service1.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Doc说明 (此类核心功能):
* +---------------------------+
* | @author qihao |
* | @date on 2021/5/10 15:29 |
* | @date on 2021/5/10 16:12 |
* +---------------------------+
* ┌─────────────────────────────────────────────────────────────┐
* │┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐│
Expand All @@ -31,22 +31,24 @@ public class Service1 extends KeepAliveService {
int x = 0;
private boolean exit = false;

@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "onCreate: Service1");
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG,"onStartCommand");
new Thread(new Runnable() {
@Override
public void run() {
while (!exit) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// int x = 8/0;
x++;
Log.d("Service1", x + "");
Log.d(TAG, "Service1 started");
new Thread(() -> {
while (!exit) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
x++;
Log.d("Service1", x + "");
}
}).start();
return super.onStartCommand(intent, flags, startId);
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/boolbird/keepalive/demo/Service2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.boolbird.keepalive.demo;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class Service2 extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onCreate() {
super.onCreate();
System.out.println("Service2 started");
}
}
25 changes: 4 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
google()
jcenter()

}
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}

task clean(type: Delete) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
8 changes: 2 additions & 6 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ android {
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"

consumerProguardFiles 'consumer-rules.pro'
externalNativeBuild {
cmake {
cppFlags ""
cppFlags "-std=c++11"
}
}
ndk {
Expand All @@ -33,13 +31,11 @@ android {
path "src/main/cpp/CMakeLists.txt"
}
}

lintOptions {
abortOnError false
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'me.weishu:free_reflection:2.2.0'
}
3 changes: 1 addition & 2 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
android:name="com.boolbird.keepalive.KeepAliveService"
android:process="android.process.daemon" />

<receiver
android:name="com.boolbird.keepalive.AutoBootReceiver">
<receiver android:name="com.boolbird.keepalive.AutoBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.TIME_TICK" />
Expand Down
Loading