public void waitForEmulator() throws CoreException {
    while (true) {
      List<AndroidDevice> devices = this.listDevices();
      if (devices != null) {
        for (AndroidDevice androidDevice : devices) {
          if (androidDevice.isEmulator() && androidDevice.getState() == AndroidDevice.STATE_DEVICE)
            return;
        }
      }
      try {
        Thread.sleep(200);
      } catch (InterruptedException e) {

      }
    }
  }
    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;
    }