-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
71 changed files
with
889 additions
and
773 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Dhizuku API | ||
|
||
简体中文 | [English](README.md) | ||
|
||
Dhizuku API 是 [Dhizuku](https://github.com/iamr0s/Dhizuku) 的 API。 | ||
|
||
## 导入 | ||
|
||
|
||
![Maven Central](https://img.shields.io/maven-central/v/io.github.iamr0s/Dhizuku-API) | ||
|
||
|
||
```groovy | ||
def dhizuku_version = "version of api" | ||
implementation "io.github.iamr0s:Dhizuku-API:$dhizuku_version" | ||
``` | ||
|
||
### 初始化 | ||
|
||
执行如下代码从而初始化Dhizuku-API,如果初始化失败(Dhizuku不存在、未激活)就开始调用其余API会抛出错误 | ||
|
||
```java | ||
Dhizuku.init(context) // return boolean | ||
``` | ||
|
||
### 请求权限 | ||
|
||
某些API接口需要先请求权限才能运行 | ||
|
||
```java | ||
|
||
if (Dhizuku.isPermissionGranted()) return | ||
|
||
Dhizuku.requestPermission(new DhizukuRequestPermissionListener() { | ||
@Override | ||
public void onRequestPermission(int grantResult) throws RemoteException { | ||
if (grantResult == PackageManager.PERMISSION_GRANTED) { | ||
// do success code | ||
}else { | ||
// do failure code | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
### 接口与更改记录 | ||
|
||
### Binder Wrapper | ||
|
||
IBinder 常用于普通应用与系统的基础通信方式。Dhizuku 提供一个接口用于代理 IBinder,应用可以通过此接口以 Dhizuku 的身份与系统通信。 | ||
|
||
[BinderWrapper Demo](https://github.com/iamr0s/Dhizuku-API/blob/main/demo-binder_wrapper) | ||
|
||
### User Service | ||
|
||
> Dhizuku.getVersionCode() >= 3 | ||
一个基于 AIDL 机制的简易 Service,Service 运行于 Dhizuku 提供的隔离空间。 | ||
|
||
通常的用法是先声明一个 AIDL 文件,再于 Service 中将其实现,随后通过 Dhizuku 提供的接口将其启动。 | ||
|
||
[UserService Demo](https://github.com/iamr0s/Dhizuku-API/blob/main/demo-user_service) | ||
|
||
### Delegated Scopes | ||
|
||
> Dhizuku.getVersionCode() >= 5 | ||
不论是在 Binder Wrapper 还是 User Service 调用 DevicePolicyManager 都显得颇为复杂,通过 Delegated Scopes 可以简化这个操作。 | ||
|
||
通常的用法是给应用授予 Delegated Scopes,随后应用可以自行通过 DevicePolicyManager 调用被纳入 Delegated Scopes 的接口。 | ||
|
||
[DelegatedScopes Demo](https://github.com/iamr0s/Dhizuku-API/blob/main/demo-delegated_scopes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
plugins { | ||
id 'com.android.application' | ||
} | ||
|
||
android { | ||
namespace 'com.rosan.dhizuku.demo' | ||
compileSdk 33 | ||
|
||
defaultConfig { | ||
applicationId "com.rosan.dhizuku.binder_wrapper" | ||
minSdk 26 | ||
targetSdk 33 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildFeatures { | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'androidx.appcompat:appcompat:1.6.1' | ||
implementation 'com.google.android.material:material:1.9.0' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.5' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' | ||
|
||
implementation project(":hidden-api") | ||
implementation project(":dhizuku-api-impl") | ||
} |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...user_service/ExampleInstrumentedTest.java → ...dhizuku/demo/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.rosan.dhizuku.demo_user_service; | ||
package com.rosan.dhizuku.demo; | ||
|
||
import android.content.Context; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../rosan/dhizuku/demo_user_service/App.java → ...main/java/com/rosan/dhizuku/demo/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.rosan.dhizuku.demo_user_service; | ||
package com.rosan.dhizuku.demo; | ||
|
||
import android.app.Application; | ||
|
||
|
36 changes: 36 additions & 0 deletions
36
demo-binder_wrapper/src/main/java/com/rosan/dhizuku/demo/BaseActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.rosan.dhizuku.demo; | ||
|
||
import android.widget.Toast; | ||
|
||
import androidx.activity.ComponentActivity; | ||
import androidx.annotation.StringRes; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class BaseActivity extends ComponentActivity { | ||
protected void toast(@StringRes int resId) { | ||
toast(getString(resId)); | ||
} | ||
|
||
protected void toast(Object... objects) { | ||
runOnUiThread(() -> { | ||
Toast.makeText(this, join(objects), Toast.LENGTH_SHORT).show(); | ||
}); | ||
} | ||
|
||
String join(List<Object> objects) { | ||
String sep = " "; | ||
StringBuilder builder = new StringBuilder(); | ||
int count = 0; | ||
for (Object element : objects) { | ||
if (++count > 1) builder.append(" "); | ||
builder.append(element == null ? "null" : element); | ||
} | ||
return builder.toString(); | ||
} | ||
|
||
String join(Object... objects) { | ||
return join(Arrays.asList(objects)); | ||
} | ||
} |
Oops, something went wrong.