class UninstallIotLauncherAppsTask implements LaunchTask {

  @Override
  public LaunchResult run(
    @NotNull Executor executor, @NotNull IDevice device, @NotNull LaunchStatus launchStatus, @NotNull ConsolePrinter printer) {
    // Ignore the check if not running on an embedded device.
    if (!device.supportsFeature(IDevice.HardwareFeature.EMBEDDED)) {
      return LaunchResult.success();
    }

    // Check for IoT Launcher apps
    Set<String> installedIotLauncherApps = myChecker.getInstalledIotLauncherApps(device);
    installedIotLauncherApps.remove(myPackageName);
    if (!installedIotLauncherApps.isEmpty()) {
      String otherApplicationIds = StringUtil.join(installedIotLauncherApps, "\n");
      String reason = AndroidBundle.message("deployment.failed.uninstall.prompt.androidthings.text", otherApplicationIds);
      if (myPrompter.showQuestionPrompt(reason)) {
        Map<String, Throwable> failedUninstallApps = new TreeMap<>();
        for (String app : installedIotLauncherApps) {
          try {
            device.uninstallPackage(app);
          }
          catch (InstallException e) {
            failedUninstallApps.put(app, e);
          }
        }
        if (!failedUninstallApps.isEmpty()) {
          StringBuffer sb = new StringBuffer();
          for (Map.Entry a : failedUninstallApps.entrySet()) {
            sb.append(a.getKey());
            sb.append(": ");
            sb.append(a.getValue());
            sb.append("\n");
          }
          String errorMessage = AndroidBundle.message("deployment.failed.uninstall.prompt.androidthings.errortext", sb.toString());
          myPrompter.showErrorMessage(errorMessage);
          return LaunchResult.error("", getDescription());
        }
      } else {
        printer.stdout("Installation aborted");
        return LaunchResult.error("", getDescription());
      }
    }
    return LaunchResult.success();
  }

  public  UninstallIotLauncherAppsTask(Project project, String packageName);
  @VisibleForTesting  UninstallIotLauncherAppsTask(String packageName, IotInstallChecker checker, RetryingInstaller.Prompter prompter);

}