Example #1
0
  /**
   * Get the Android preferences from the preferences.json file, if any exist.
   *
   * @return The preferences in a JSONObject, or an empty JSONObject if no preferences are defined.
   */
  public JSONObject getAndroidPreferences() {
    final File descFile = getDistributionFile("preferences.json");
    if (descFile == null) {
      // Logging and existence checks are handled in getDistributionFile.
      return new JSONObject();
    }

    try {
      final JSONObject all = FileUtils.readJSONObjectFromFile(descFile);

      if (!all.has("AndroidPreferences")) {
        return new JSONObject();
      }

      return all.getJSONObject("AndroidPreferences");

    } catch (IOException e) {
      Log.e(LOGTAG, "Error getting distribution descriptor file.", e);
      Telemetry.addToHistogram(HISTOGRAM_CODE_CATEGORY, CODE_CATEGORY_MALFORMED_DISTRIBUTION);
      return new JSONObject();
    } catch (JSONException e) {
      Log.e(LOGTAG, "Error parsing preferences.json", e);
      Telemetry.addToHistogram(HISTOGRAM_CODE_CATEGORY, CODE_CATEGORY_MALFORMED_DISTRIBUTION);
      return new JSONObject();
    }
  }
Example #2
0
  public DistributionDescriptor getDescriptor() {
    File descFile = getDistributionFile("preferences.json");
    if (descFile == null) {
      // Logging and existence checks are handled in getDistributionFile.
      return null;
    }

    try {
      JSONObject all = FileUtils.readJSONObjectFromFile(descFile);

      if (!all.has("Global")) {
        Log.e(LOGTAG, "Distribution preferences.json has no Global entry!");
        return null;
      }

      return new DistributionDescriptor(all.getJSONObject("Global"));

    } catch (IOException e) {
      Log.e(LOGTAG, "Error getting distribution descriptor file.", e);
      Telemetry.addToHistogram(HISTOGRAM_CODE_CATEGORY, CODE_CATEGORY_MALFORMED_DISTRIBUTION);
      return null;
    } catch (JSONException e) {
      Log.e(LOGTAG, "Error parsing preferences.json", e);
      Telemetry.addToHistogram(HISTOGRAM_CODE_CATEGORY, CODE_CATEGORY_MALFORMED_DISTRIBUTION);
      return null;
    }
  }
Example #3
0
  public JSONArray getBookmarks() {
    File bookmarks = getDistributionFile("bookmarks.json");
    if (bookmarks == null) {
      // Logging and existence checks are handled in getDistributionFile.
      return null;
    }

    try {
      return new JSONArray(FileUtils.readStringFromFile(bookmarks));
    } catch (IOException e) {
      Log.e(LOGTAG, "Error getting bookmarks", e);
      Telemetry.addToHistogram(HISTOGRAM_CODE_CATEGORY, CODE_CATEGORY_MALFORMED_DISTRIBUTION);
      return null;
    } catch (JSONException e) {
      Log.e(LOGTAG, "Error parsing bookmarks.json", e);
      Telemetry.addToHistogram(HISTOGRAM_CODE_CATEGORY, CODE_CATEGORY_MALFORMED_DISTRIBUTION);
      return null;
    }
  }