예제 #1
0
  /**
   * Blacklisting apps.
   *
   * @param code - Operation code.
   * @param data - Data required(Application data).
   */
  public void blacklistApps(String code, String data) {
    ArrayList<DeviceAppInfo> apps = appList.getInstalledApps();
    JSONArray appList = new JSONArray();
    String identity = null;
    try {
      JSONObject resultApp = new JSONObject(data);
      if (!resultApp.isNull(resources.getString(R.string.intent_extra_data))) {
        resultApp = (JSONObject) resultApp.get(resources.getString(R.string.intent_extra_data));
      }

      identity = (String) resultApp.get(resources.getString(R.string.intent_extra_identity));
    } catch (JSONException e) {
      Log.e(TAG, "Invalid JSON format." + e);
    }

    for (DeviceAppInfo app : apps) {
      JSONObject result = new JSONObject();
      try {
        result.put(resources.getString(R.string.intent_extra_name), app.getAppname());
        result.put(resources.getString(R.string.intent_extra_package), app.getPackagename());
        if (identity.trim().equals(app.getPackagename())) {
          result.put(resources.getString(R.string.intent_extra_not_violated), false);
          result.put(resources.getString(R.string.intent_extra_package), app.getPackagename());
        } else {
          result.put(resources.getString(R.string.intent_extra_not_violated), true);
        }

      } catch (JSONException e) {
        Log.e(TAG, "Invalid JSON format." + e);
      }
      appList.put(result);
    }

    resultBuilder.build(code, appList);
  }
예제 #2
0
  /**
   * Retrieve device application information.
   *
   * @param code - Operation code.
   */
  public void getApplicationList(String code) {
    ArrayList<DeviceAppInfo> apps = appList.getInstalledApps();

    JSONArray result = new JSONArray();
    int size = apps.size();

    for (int i = 0; i < size; i++) {
      JSONObject app = new JSONObject();
      try {
        app.put(APP_INFO_TAG_NAME, Uri.encode(apps.get(i).getAppname()));
        app.put(APP_INFO_TAG_PACKAGE, apps.get(i).getPackagename());
        app.put(APP_INFO_TAG_ICON, apps.get(i).getIcon());
        result.put(app);
      } catch (JSONException e) {
        Log.e(TAG, "Invalid JSON format." + e);
      }
    }

    resultBuilder.build(code, result);
  }