コード例 #1
0
 /**
  * Here we call the command and parse its output
  *
  * @param menu The menu of the caller.
  */
 public void addItemsToMenu(LauncherMenu menu) {
   KindleLauncher.LOG.debug("Refreshing the menu");
   try {
     parseJSONMenu();
   } catch (IOException e) {
     KindleLauncher.LOG.error(
         "Cannot create menu because script <" + getScriptStr() + "> cannot be executed?");
     e.printStackTrace();
   } catch (ParseException e) {
     KindleLauncher.LOG.error(
         "Cannot create menu because script <" + getScriptStr() + "> output cannot be parsed.");
     e.printStackTrace();
   }
   super.addItemsToMenu(menu);
 }
コード例 #2
0
  /**
   * Executes the command stored in the object and parses its stdout as JSON stops executing if
   * command returned non-zero exit code or non-empty stderr
   *
   * @throws IOException if there is a problem reading the JSON text
   * @throws ParseException if there is a problem parsing the JSON text
   */
  public void parseJSONMenu() throws IOException, ParseException {
    mMenuItems = new LauncherMenu[] {};
    JSONParser parse = new JSONParser();

    StringBuffer out = new StringBuffer();
    StringBuffer err = new StringBuffer();
    String cmd = "/mnt/us/extensions/wdexec.sh " + mExtDir.getAbsolutePath() + " ";
    if (mTimeout > 0) {
      cmd += "../timeout.sh -t " + mTimeout + " ";
    }
    cmd += getScriptStr();
    int retcode = KindleLauncher.SERVICES.getDeviceService().exec(cmd, out, err);
    if (retcode != 0) {
      throw new IOException("Script <" + cmd + "> returned non-zero exit code: " + retcode);
    }
    if (err.length() != 0) {
      throw new IOException("Script <" + cmd + "> returned non-emtpy stderr: " + err.toString());
    }

    KindleLauncher.LOG.debug("Loading JSON from script <" + cmd + "> stdout: " + out.toString());
    JSONObject obj = (JSONObject) parse.parse(out.toString());

    updateActions(obj);
  }