예제 #1
0
  /** Install an Application */
  private void installApplication(JSONObject data, String code) {
    String appUrl = null;
    String type = null;
    String os = null;

    try {
      JSONObject applicationData = data;
      appUrl = (String) applicationData.get(resources.getString(R.string.intent_extra_identity));
      if (!applicationData.isNull(resources.getString(R.string.intent_extra_type))) {
        type = (String) applicationData.get(resources.getString(R.string.intent_extra_type));
      }

      if (!applicationData.isNull(resources.getString(R.string.intent_extra_platform_id))) {
        os = (String) applicationData.get(resources.getString(R.string.intent_extra_platform_id));
      } else if (!applicationData.isNull(resources.getString(R.string.intent_extra_os))) {
        os = (String) applicationData.get(resources.getString(R.string.intent_extra_os));
      }

      if (type != null
          && type.equalsIgnoreCase(resources.getString(R.string.intent_extra_enterprise))) {
        if (os != null) {
          if (os.equalsIgnoreCase(resources.getString(R.string.intent_extra_android))) {
            appList.installApp(appUrl);
          }
        } else {
          appList.installApp(appUrl);
        }
      } else if (type != null
          && type.equalsIgnoreCase(resources.getString(R.string.intent_extra_market))) {
        if (os != null) {
          if (os.equalsIgnoreCase(resources.getString(R.string.intent_extra_android))) {
            triggerGooglePlayApp(appUrl);
          }
        } else {
          triggerGooglePlayApp(appUrl);
        }

      } else {
        if (os != null) {
          if (os.equalsIgnoreCase(resources.getString(R.string.intent_extra_android))) {
            appList.installApp(appUrl);
          }
        } else {
          appList.installApp(appUrl);
        }
      }

    } catch (JSONException e) {
      Log.e(TAG, "Invalid JSON format." + e);
    }
  }
예제 #2
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);
  }
예제 #3
0
  /**
   * Uninstall application.
   *
   * @param code - Operation code.
   * @param data - Data required(App package).
   */
  public void uninstallApplication(String code, String data) {
    String packageName;
    try {
      JSONObject appData = new JSONObject(data);
      packageName = (String) appData.get(resources.getString(R.string.intent_extra_identity));

      resultBuilder.build(code);

      appList.uninstallApplication(packageName);
    } catch (JSONException e) {
      Log.e(TAG, "Invalid JSON format." + e);
    }
  }
예제 #4
0
  /**
   * Create web clip (Web app shortcut on device home screen).
   *
   * @param code - Operation code.
   * @param data - Data required(Web app data).
   */
  public void createWebClip(String code, String data) {
    String appUrl = null;
    String title = null;

    try {
      JSONObject webClipData = new JSONObject(code);
      appUrl = (String) webClipData.get(resources.getString(R.string.intent_extra_identity));
      title = (String) webClipData.get(resources.getString(R.string.intent_extra_title));
    } catch (JSONException e) {
      Log.e(TAG, "Invalid JSON format. " + e);
    }

    resultBuilder.build(data);

    if (appUrl != null && title != null) {
      appList.createWebAppBookmark(appUrl, title);
    }
  }
예제 #5
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);
  }