Skip to content

Commit

Permalink
Merge pull request #362 from caofengbin/feature/fix_android_uninstall…
Browse files Browse the repository at this point in the history
…_with_result

fix:增加卸载安装包方法的返回值校验,应用包名不存在或错误时,认定步骤失败
  • Loading branch information
ZhouYixun authored Jun 19, 2023
2 parents b9a3d48 + 9e63363 commit 2870746
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ public static void pressKey(IDevice iDevice, AndroidKey androidKey) {
executeCommand(iDevice, String.format("input keyevent %s", androidKey.getCode()));
}

public static void uninstall(IDevice iDevice, String bundleId) throws InstallException {
iDevice.uninstallPackage(bundleId);
public static String uninstall(IDevice iDevice, String bundleId) throws InstallException {
return iDevice.uninstallPackage(bundleId);
}

public static void forceStop(IDevice iDevice, String bundleId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,13 @@ public void install(HandleContext handleContext, String path) {
public void uninstall(HandleContext handleContext, String appPackage) {
handleContext.setStepDes("卸载应用");
appPackage = TextHandler.replaceTrans(appPackage, globalParams);
handleContext.setDetail("App包名: " + appPackage);
try {
AndroidDeviceBridgeTool.uninstall(iDevice, appPackage);
String errorMessage = AndroidDeviceBridgeTool.uninstall(iDevice, appPackage);
if (errorMessage == null) {
handleContext.setDetail("App包名:" + appPackage + "卸载成功");
} else {
handleContext.setE(new Exception("uninstall app " + appPackage + " failed,errorMessage:" + errorMessage));
}
} catch (Exception e) {
handleContext.setE(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,12 @@ public void onMessage(String message, Session session) {
case "uninstallApp" -> {
JSONObject result = new JSONObject();
try {
AndroidDeviceBridgeTool.uninstall(iDevice, msg.getString("detail"));
result.put("detail", "success");
String errorMessage = AndroidDeviceBridgeTool.uninstall(iDevice, msg.getString("detail"));
if (errorMessage == null) {
result.put("detail", "success");
} else {
result.put("detail", "fail");
}
} catch (InstallException e) {
result.put("detail", "fail");
e.printStackTrace();
Expand Down

0 comments on commit 2870746

Please sign in to comment.