public List<String> getAVDList() {
      if (buffer == null || buffer.length() < 1) return null;

      StringReader reader = new StringReader(buffer.toString());
      BufferedReader read = new BufferedReader(reader);
      String line = null;
      ArrayList<String> list = new ArrayList<String>();
      try {
        while ((line = read.readLine()) != null) {
          int idx = line.indexOf(PREFIX_NAME);
          if (idx > -1) {
            list.add(line.substring(idx + PREFIX_NAME.length()).trim());
          }
        }
      } catch (IOException e) {
        AndroidCore.log(IStatus.ERROR, "Error parsing the AVD list", e);
        return null;
      } finally {
        try {
          read.close();
          reader.close();
        } catch (IOException e) {
          /*ignored*/
        }
      }
      return list;
    }
  public AndroidSDKManager() {
    String sdkDir = AndroidCore.getSDKLocation();
    if (sdkDir == null)
      throw new IllegalStateException("No SDK is defined to work with the Android SDK Manager");

    if (!sdkDir.endsWith(File.separator)) {
      sdkDir = sdkDir + File.separator;
    }
    toolsDir = sdkDir + "tools" + File.separator;
    platformTools = sdkDir + "platform-tools" + File.separator;
  }
    public List<AndroidSDK> getSDKList() {
      if (buffer == null || buffer.length() < 1) return null;

      StringReader reader = new StringReader(buffer.toString());
      BufferedReader read = new BufferedReader(reader);
      ArrayList<AndroidSDK> sdkList = new ArrayList<AndroidSDK>();

      String line = null;
      try {
        AndroidSDK sdk = null;
        while ((line = read.readLine()) != null) {
          final int scolIdx = line.indexOf(':');
          if (scolIdx < 0) {
            continue;
          }
          String[] pair = new String[2];
          pair[0] = line.substring(0, scolIdx).trim();
          pair[1] = line.substring(scolIdx + 1).trim();
          if ("id".equalsIgnoreCase(pair[0])) {
            sdk = new AndroidSDK();
            sdkList.add(sdk);
            int vIndex = pair[1].indexOf("or");
            sdk.setId(pair[1].substring(vIndex + "or".length()).replace("\"", ""));
          } else if ("Type".equalsIgnoreCase(pair[0])) {
            Assert.isNotNull(sdk);
            sdk.setType(pair[1].trim());
          } else if ("API level".equalsIgnoreCase(pair[0])) {
            Assert.isNotNull(sdk);
            sdk.setApiLevel(Integer.parseInt(pair[1]));
          }
        }
      } catch (IOException e) {
        AndroidCore.log(IStatus.ERROR, "Error parsing the SDK list", e);
      } finally {
        try {
          read.close();
          reader.close();
        } catch (IOException e) {
          // ignored
        }
      }
      return sdkList;
    }
    public List<AndroidDevice> getDeviceList() {
      if (buffer == null || buffer.length() < 1) return null;

      StringReader reader = new StringReader(buffer.toString());
      BufferedReader read = new BufferedReader(reader);
      String line = null;
      ArrayList<AndroidDevice> list = new ArrayList<AndroidDevice>();
      try {
        while ((line = read.readLine()) != null) {
          if (line.isEmpty() || line.contains("List of devices attached")) continue;
          String[] values = line.split("\t");
          if (values.length == 2) {
            AndroidDevice device = new AndroidDevice();
            device.setSerialNumber(values[0].trim());
            device.setEmulator(values[0].contains("emulator"));

            if ("device".equals(values[1].trim())) {
              device.setState(AndroidDevice.STATE_DEVICE);
            } else if ("offline".equals(values[1].trim())) {
              device.setState(AndroidDevice.STATE_OFFLINE);
            }
            list.add(device);
          }
        }
      } catch (IOException e) {
        AndroidCore.log(IStatus.ERROR, "Error parsing the Android device list", e);
        return null;
      } finally {
        try {
          read.close();
          reader.close();
        } catch (IOException e) {
          /*ignored*/
        }
      }
      return list;
    }
 /**
  * Returns an error string or null if it is OK
  *
  * @return
  */
 public String getErrorString() {
   String text = buffer.toString();
   if (text.startsWith("Error:")) {
     StringReader reader = new StringReader(text);
     BufferedReader read = new BufferedReader(reader);
     try {
       String line = read.readLine();
       if (line == null) {
         return "";
       }
       return line.substring(7);
     } catch (IOException e) {
       AndroidCore.log(IStatus.ERROR, "Error parsing the create project command result", e);
     } finally {
       try {
         read.close();
         reader.close();
       } catch (IOException e) {
         // ignored
       }
     }
   }
   return null;
 }