fix: ASW-195 job 执行playbook初始化关闭第三方app

This commit is contained in:
zhangshuai
2024-11-27 10:42:54 +08:00
parent 83b17b5f5e
commit fa15fd76ca
2 changed files with 12 additions and 35 deletions

View File

@@ -858,26 +858,6 @@ public class AdbUtil {
return T.StrUtil.equals(result, packageName);
}
public List findPackageNameList() {
String result = commandExec.exec(AdbCommandBuilder.builder()
.serial(this.getSerial())
.buildFindPackageNameList()
.build()
);
List<String> packageNameList = T.ListUtil.list(true);
String prefix = "package:";
String[] lines = result.split("\\n");
for (String line : lines) {
String packageName = T.StrUtil.trim(line.substring(prefix.length()));
if (T.StrUtil.equals(DEFAULT_DROIDVNC_NG_PKG_NAME, packageName)) continue;
packageNameList.add(packageName);
}
return packageNameList;
}
public CommandResult startApp(String packageName) {
String result = commandExec.exec(AdbCommandBuilder.builder()
.serial(this.getSerial())
@@ -888,6 +868,14 @@ public class AdbUtil {
return new CommandResult(T.StrUtil.isNotEmpty(result) ? 1 : 0, result);
}
public void closeOtherApps() {
commandExec.exec(AdbCommandBuilder.builder()
.serial(this.getSerial())
.buildShellCommand(String.format("shell 'for app in $(pm list packages -3 | grep -v \"net.christianbeier.droidvnc_ng\" | cut -f 2 -d \":\"); do am force-stop $app; done'"))
.build());
}
private synchronized ExecutorService getThreadPool() {
if (threadPool == null) {
threadPool = new ThreadPoolExecutor(

View File

@@ -1,7 +1,5 @@
package net.geedge.api.util;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.log.Log;
import net.geedge.api.entity.EnvApiYml;
@@ -11,7 +9,6 @@ import net.geedge.common.RCode;
import net.geedge.common.T;
import java.io.File;
import java.util.List;
import java.util.Map;
public class PlaybookRunnable implements Runnable {
@@ -85,8 +82,7 @@ public class PlaybookRunnable implements Runnable {
//Close other apps
if (interrupt) return;
List<String> packageNameList = adbUtil.findPackageNameList();
this.closeApp(packageNameList, packageName);
adbUtil.closeOtherApps();
// clear app data
if (interrupt) return;
@@ -153,7 +149,9 @@ public class PlaybookRunnable implements Runnable {
AdbUtil.CommandResult allTcpdump = adbUtil.stopTcpdump(tcpdumpAll.output());
adbUtil.execShellCommand(String.format("shell rm -rf %s", allTcpdump.output()));
}
this.closeApp(ListUtil.empty(), packageName);
adbUtil.stopApp(packageName);
if (unInstall) {
adbUtil.uninstall(packageName);
}
@@ -167,15 +165,6 @@ public class PlaybookRunnable implements Runnable {
adbUtil.setInterrupt(true);
}
private void closeApp(List<String> packageNameList, String packageName) {
if (CollUtil.isNotEmpty(packageNameList)) {
for (String name : packageNameList) {
adbUtil.stopApp(name);
}
}
adbUtil.stopApp(packageName);
}
private void stopTcpdump(AdbUtil.CommandResult tcpdump, File logFile, String packageName) {
// stop tcpdump
AdbUtil.CommandResult stopTcpdump = adbUtil.stopTcpdump(tcpdump.output());