Exemple #1
0
  /** Moves an AVD. */
  private void moveAvd() {
    try {
      String avdName = mSdkCommandLine.getParamName();
      AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
      AvdInfo info = avdManager.getAvd(avdName, true /*validAvdOnly*/);

      if (info == null) {
        errorAndExit("There is no valid Android Virtual Device named '%s'.", avdName);
        return;
      }

      // This is a rename if there's a new name for the AVD
      String newName = mSdkCommandLine.getParamMoveNewName();
      if (newName != null && newName.equals(info.getName())) {
        // same name, not actually a rename operation
        newName = null;
      }

      // This is a move (of the data files) if there's a new location path
      String paramFolderPath = mSdkCommandLine.getParamLocationPath();
      if (paramFolderPath != null) {
        // check if paths are the same. Use File methods to account for OS idiosyncrasies.
        try {
          File f1 = new File(paramFolderPath).getCanonicalFile();
          File f2 = new File(info.getPath()).getCanonicalFile();
          if (f1.equals(f2)) {
            // same canonical path, so not actually a move
            paramFolderPath = null;
          }
        } catch (IOException e) {
          // Fail to resolve canonical path. Fail now since a move operation might fail
          // later and be harder to recover from.
          errorAndExit(e.getMessage());
          return;
        }
      }

      if (newName == null && paramFolderPath == null) {
        mSdkLog.warning("Move operation aborted: same AVD name, same canonical data path");
        return;
      }

      // If a rename was requested and no data move was requested, check if the original
      // data path is our default constructed from the AVD name. In this case we still want
      // to rename that folder too.
      if (newName != null && paramFolderPath == null) {
        // Compute the original data path
        File originalFolder =
            new File(
                AndroidLocation.getFolder() + AndroidLocation.FOLDER_AVD,
                info.getName() + AvdManager.AVD_FOLDER_EXTENSION);
        if (originalFolder.equals(info.getPath())) {
          try {
            // The AVD is using the default data folder path based on the AVD name.
            // That folder needs to be adjusted to use the new name.
            File f =
                new File(
                    AndroidLocation.getFolder() + AndroidLocation.FOLDER_AVD,
                    newName + AvdManager.AVD_FOLDER_EXTENSION);
            paramFolderPath = f.getCanonicalPath();
          } catch (IOException e) {
            // Fail to resolve canonical path. Fail now rather than later.
            errorAndExit(e.getMessage());
          }
        }
      }

      // Check for conflicts
      if (newName != null) {
        if (avdManager.getAvd(newName, false /*validAvdOnly*/) != null) {
          errorAndExit("There is already an AVD named '%s'.", newName);
          return;
        }

        File ini = info.getIniFile();
        if (ini.equals(AvdInfo.getIniFile(newName))) {
          errorAndExit("The AVD file '%s' is in the way.", ini.getCanonicalPath());
          return;
        }
      }

      if (paramFolderPath != null && new File(paramFolderPath).exists()) {
        errorAndExit(
            "There is already a file or directory at '%s'.\nUse --path to specify a different data folder.",
            paramFolderPath);
      }

      avdManager.moveAvd(info, newName, paramFolderPath, mSdkLog);
    } catch (AndroidLocationException e) {
      errorAndExit(e.getMessage());
    } catch (IOException e) {
      errorAndExit(e.getMessage());
    }
  }
Exemple #2
0
  /**
   * Displays the list of available AVDs for the given AvdManager.
   *
   * @param avdManager
   */
  public void displayAvdList(AvdManager avdManager) {
    mSdkLog.printf("Available Android Virtual Devices:\n");

    AvdInfo[] avds = avdManager.getValidAvds();
    for (int index = 0; index < avds.length; index++) {
      AvdInfo info = avds[index];
      if (index > 0) {
        mSdkLog.printf("---------\n");
      }
      mSdkLog.printf("    Name: %s\n", info.getName());
      mSdkLog.printf("    Path: %s\n", info.getPath());

      // get the target of the AVD
      IAndroidTarget target = info.getTarget();
      if (target.isPlatform()) {
        mSdkLog.printf(
            "  Target: %s (API level %s)\n", target.getName(), target.getVersion().getApiString());
      } else {
        mSdkLog.printf("  Target: %s (%s)\n", target.getName(), target.getVendor());
        mSdkLog.printf(
            "          Based on Android %s (API level %s)\n",
            target.getVersionName(), target.getVersion().getApiString());
      }

      // display some extra values.
      Map<String, String> properties = info.getProperties();
      if (properties != null) {
        String skin = properties.get(AvdManager.AVD_INI_SKIN_NAME);
        if (skin != null) {
          mSdkLog.printf("    Skin: %s\n", skin);
        }
        String sdcard = properties.get(AvdManager.AVD_INI_SDCARD_SIZE);
        if (sdcard == null) {
          sdcard = properties.get(AvdManager.AVD_INI_SDCARD_PATH);
        }
        if (sdcard != null) {
          mSdkLog.printf("  Sdcard: %s\n", sdcard);
        }
        String snapshot = properties.get(AvdManager.AVD_INI_SNAPSHOT_PRESENT);
        if (snapshot != null) {
          mSdkLog.printf("Snapshot: %s\n", snapshot);
        }
      }
    }

    // Are there some unused AVDs?
    AvdInfo[] badAvds = avdManager.getBrokenAvds();

    if (badAvds.length == 0) {
      return;
    }

    mSdkLog.printf("\nThe following Android Virtual Devices could not be loaded:\n");
    boolean needSeparator = false;
    for (AvdInfo info : badAvds) {
      if (needSeparator) {
        mSdkLog.printf("---------\n");
      }
      mSdkLog.printf("    Name: %s\n", info.getName() == null ? "--" : info.getName());
      mSdkLog.printf("    Path: %s\n", info.getPath() == null ? "--" : info.getPath());

      String error = info.getErrorMessage();
      mSdkLog.printf("   Error: %s\n", error == null ? "Uknown error" : error);
      needSeparator = true;
    }
  }