diff --git a/pom.xml b/pom.xml index 0b212ec..c4dd00b 100644 --- a/pom.xml +++ b/pom.xml @@ -71,6 +71,8 @@ **/application-*.yml **/logback-spring.xml + + lib/*.* **/*.* diff --git a/src/main/java/net/geedge/api/util/AdbUtil.java b/src/main/java/net/geedge/api/util/AdbUtil.java index ed901b2..beba56e 100644 --- a/src/main/java/net/geedge/api/util/AdbUtil.java +++ b/src/main/java/net/geedge/api/util/AdbUtil.java @@ -22,6 +22,9 @@ public class AdbUtil { 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 host; private Integer port; @@ -39,7 +42,10 @@ public class AdbUtil { this.serial = T.StrUtil.emptyToDefault(adb.getSerial(), ""); this.host = adb.getHost(); this.port = adb.getPort(); + // adb connect this.connect(); + // init + this.init(); } public static AdbUtil getInstance(DeviceApiYml.Adb connInfo) { @@ -76,12 +82,40 @@ public class AdbUtil { Runtime.getRuntime().halt(1); } } + } + + /** + * init + * su root + * install droidVNC NG + */ + private void init() { // adb root - CommandExec.exec(AdbCommandBuilder.builder() + String result = CommandExec.exec(AdbCommandBuilder.builder() .serial(this.getSerial()) .buildRootCommand() .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); } + /** + * 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() { if (threadPool == null) { diff --git a/src/main/resources/lib/droidvnc-np-2.6.0.apk b/src/main/resources/lib/droidvnc-np-2.6.0.apk new file mode 100644 index 0000000..474b1ca Binary files /dev/null and b/src/main/resources/lib/droidvnc-np-2.6.0.apk differ diff --git a/src/main/resources/lib/droidvnc-np-defaults.json b/src/main/resources/lib/droidvnc-np-defaults.json new file mode 100644 index 0000000..e6d8f37 --- /dev/null +++ b/src/main/resources/lib/droidvnc-np-defaults.json @@ -0,0 +1,6 @@ +{ + "password": "", + "port": 5900, + "viewOnly": false, + "accessKey": "d042e2b5d5f348588a4e1a243eb7a9a0" +} \ No newline at end of file