feat: 项目启动时,覆盖安装 droidVNC NG,并后台启动
1. droidVNC NG 依赖位于 lib/ 2. 依赖不加入 jar 包,部署时放置于 jar 同级 lib/ 目录下即可 3. droidVNC NG 版本为最新版本
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -71,6 +71,8 @@
|
|||||||
<excludes>
|
<excludes>
|
||||||
<exclude>**/application-*.yml</exclude>
|
<exclude>**/application-*.yml</exclude>
|
||||||
<exclude>**/logback-spring.xml</exclude>
|
<exclude>**/logback-spring.xml</exclude>
|
||||||
|
<!--lib 下的依赖不加入 jar,部署时放到 jar 文件同级即可-->
|
||||||
|
<exclude>lib/*.*</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
<includes>
|
<includes>
|
||||||
<include>**/*.*</include>
|
<include>**/*.*</include>
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ public class AdbUtil {
|
|||||||
|
|
||||||
private static AdbUtil instance;
|
private static AdbUtil instance;
|
||||||
|
|
||||||
|
private static String DEFAULT_DROIDVNC_NG_APK_PATH = "./lib/droidvnc-np-2.6.0.apk";
|
||||||
|
private static String DEFAULT_DROIDVNC_NG_DEFAULTS_JSON_PATH = "./lib/droidvnc-np-defaults.json";
|
||||||
|
|
||||||
private String serial;
|
private String serial;
|
||||||
private String host;
|
private String host;
|
||||||
private Integer port;
|
private Integer port;
|
||||||
@@ -39,7 +42,10 @@ public class AdbUtil {
|
|||||||
this.serial = T.StrUtil.emptyToDefault(adb.getSerial(), "");
|
this.serial = T.StrUtil.emptyToDefault(adb.getSerial(), "");
|
||||||
this.host = adb.getHost();
|
this.host = adb.getHost();
|
||||||
this.port = adb.getPort();
|
this.port = adb.getPort();
|
||||||
|
// adb connect
|
||||||
this.connect();
|
this.connect();
|
||||||
|
// init
|
||||||
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AdbUtil getInstance(DeviceApiYml.Adb connInfo) {
|
public static AdbUtil getInstance(DeviceApiYml.Adb connInfo) {
|
||||||
@@ -76,12 +82,40 @@ public class AdbUtil {
|
|||||||
Runtime.getRuntime().halt(1);
|
Runtime.getRuntime().halt(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* init
|
||||||
|
* su root
|
||||||
|
* install droidVNC NG
|
||||||
|
*/
|
||||||
|
private void init() {
|
||||||
// adb root
|
// adb root
|
||||||
CommandExec.exec(AdbCommandBuilder.builder()
|
String result = CommandExec.exec(AdbCommandBuilder.builder()
|
||||||
.serial(this.getSerial())
|
.serial(this.getSerial())
|
||||||
.buildRootCommand()
|
.buildRootCommand()
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
log.info("[init] [adb root] [result: {}]", result);
|
||||||
|
|
||||||
|
// install droidVNC NG
|
||||||
|
CommandResult installed = this.install(DEFAULT_DROIDVNC_NG_APK_PATH, true, true);
|
||||||
|
log.info("[init] [install droidVNC NG] [result: {}]", installed);
|
||||||
|
|
||||||
|
// 上传默认配置
|
||||||
|
this.execShellCommand("shell mkdir -p /storage/emulated/0/Android/data/net.christianbeier.droidvnc_ng/files");
|
||||||
|
this.push(DEFAULT_DROIDVNC_NG_DEFAULTS_JSON_PATH, "/storage/emulated/0/Android/data/net.christianbeier.droidvnc_ng/files/defaults.json");
|
||||||
|
|
||||||
|
// 无障碍权限
|
||||||
|
this.execShellCommand("shell settings put secure enabled_accessibility_services net.christianbeier.droidvnc_ng/.InputService:$(settings get secure enabled_accessibility_services)");
|
||||||
|
// 存储空间权限
|
||||||
|
this.execShellCommand("shell pm grant net.christianbeier.droidvnc_ng android.permission.WRITE_EXTERNAL_STORAGE");
|
||||||
|
// 屏幕录制权限
|
||||||
|
this.execShellCommand("shell appops set net.christianbeier.droidvnc_ng PROJECT_MEDIA allow");
|
||||||
|
|
||||||
|
// 后台启动
|
||||||
|
this.execShellCommand("shell am start-foreground-service -n net.christianbeier.droidvnc_ng/.MainService -a net.christianbeier.droidvnc_ng.ACTION_STOP --es net.christianbeier.droidvnc_ng.EXTRA_ACCESS_KEY d042e2b5d5f348588a4e1a243eb7a9a0");
|
||||||
|
this.execShellCommand("shell am start-foreground-service -n net.christianbeier.droidvnc_ng/.MainService -a net.christianbeier.droidvnc_ng.ACTION_START --es net.christianbeier.droidvnc_ng.EXTRA_ACCESS_KEY d042e2b5d5f348588a4e1a243eb7a9a0");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -540,6 +574,16 @@ public class AdbUtil {
|
|||||||
return new CommandResult(T.StrUtil.isEmpty(result) ? 0 : 1, result);
|
return new CommandResult(T.StrUtil.isEmpty(result) ? 0 : 1, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* exec shell command
|
||||||
|
*/
|
||||||
|
public void execShellCommand(String shellCmd) {
|
||||||
|
String result = CommandExec.exec(AdbCommandBuilder.builder()
|
||||||
|
.serial(this.getSerial())
|
||||||
|
.buildShellCommand(shellCmd)
|
||||||
|
.build());
|
||||||
|
log.info("[execShellCommand] [shellCmd: {}] [result: {}]", shellCmd, result);
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized ExecutorService getThreadPool() {
|
private synchronized ExecutorService getThreadPool() {
|
||||||
if (threadPool == null) {
|
if (threadPool == null) {
|
||||||
|
|||||||
BIN
src/main/resources/lib/droidvnc-np-2.6.0.apk
Normal file
BIN
src/main/resources/lib/droidvnc-np-2.6.0.apk
Normal file
Binary file not shown.
6
src/main/resources/lib/droidvnc-np-defaults.json
Normal file
6
src/main/resources/lib/droidvnc-np-defaults.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"password": "",
|
||||||
|
"port": 5900,
|
||||||
|
"viewOnly": false,
|
||||||
|
"accessKey": "d042e2b5d5f348588a4e1a243eb7a9a0"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user