コード例 #1
0
  /**
   * Install an Application.
   *
   * @param operation - Operation object.
   */
  private void installApplication(JSONObject data, org.wso2.emm.agent.beans.Operation operation)
      throws AndroidAgentException {
    String appUrl;
    String type;
    String name;
    String operationType;
    String schedule = null;

    try {
      if (!data.isNull(getContextResources().getString(R.string.app_type))) {
        type = data.getString(getContextResources().getString(R.string.app_type));

        if (type.equalsIgnoreCase(
            getContextResources().getString(R.string.intent_extra_enterprise))) {
          appUrl = data.getString(getContextResources().getString(R.string.app_url));
          if (data.has(getContextResources().getString(R.string.app_schedule))) {
            schedule = data.getString(getContextResources().getString(R.string.app_schedule));
          }
          operation.setStatus(getContextResources().getString(R.string.operation_value_completed));
          getResultBuilder().build(operation);
          getAppList().installApp(appUrl, schedule);

        } else if (type.equalsIgnoreCase(
            getContextResources().getString(R.string.intent_extra_public))) {
          appUrl = data.getString(getContextResources().getString(R.string.app_identifier));
          operation.setStatus(getContextResources().getString(R.string.operation_value_completed));
          getResultBuilder().build(operation);
          triggerGooglePlayApp(appUrl);

        } else if (type.equalsIgnoreCase(
            getContextResources().getString(R.string.intent_extra_web))) {
          name = data.getString(getContextResources().getString(R.string.intent_extra_name));
          appUrl = data.getString(getContextResources().getString(R.string.app_url));
          operationType = getContextResources().getString(R.string.operation_install);
          JSONObject payload = new JSONObject();
          payload.put(getContextResources().getString(R.string.intent_extra_identity), appUrl);
          payload.put(getContextResources().getString(R.string.intent_extra_title), name);
          payload.put(getContextResources().getString(R.string.operation_type), operationType);
          operation.setPayLoad(payload.toString());
          manageWebClip(operation);

        } else {
          operation.setStatus(getContextResources().getString(R.string.operation_value_error));
          getResultBuilder().build(operation);
          throw new AndroidAgentException("Invalid application details");
        }

        if (Constants.DEBUG_MODE_ENABLED) {
          Log.d(TAG, "Application installation started");
        }
      }
    } catch (JSONException e) {
      operation.setStatus(getContextResources().getString(R.string.operation_value_error));
      getResultBuilder().build(operation);
      throw new AndroidAgentException("Invalid JSON format.", e);
    }
  }
コード例 #2
0
  @Override
  public void wipeDevice(Operation operation) throws AndroidAgentException {
    String inputPin;
    String savedPin =
        Preference.getString(
            getContext(), getContextResources().getString(R.string.shared_pref_pin));
    JSONObject result = new JSONObject();
    String ownershipType = Preference.getString(getContext(), Constants.DEVICE_TYPE);

    try {
      JSONObject wipeKey = new JSONObject(operation.getPayLoad().toString());
      inputPin = (String) wipeKey.get(getContextResources().getString(R.string.shared_pref_pin));
      String status;
      if (Constants.OWNERSHIP_BYOD.equals(ownershipType.trim())
          || (inputPin != null && inputPin.trim().equals(savedPin.trim()))) {
        status = getContextResources().getString(R.string.shared_pref_default_status);
        result.put(getContextResources().getString(R.string.operation_status), status);
      } else {
        status = getContextResources().getString(R.string.shared_pref_false_status);
        result.put(getContextResources().getString(R.string.operation_status), status);
      }

      operation.setPayLoad(result.toString());

      if (status.equals(getContextResources().getString(R.string.shared_pref_default_status))) {
        Toast.makeText(
                getContext(),
                getContextResources().getString(R.string.toast_message_wipe),
                Toast.LENGTH_LONG)
            .show();
        operation.setStatus(getContextResources().getString(R.string.operation_value_completed));
        getResultBuilder().build(operation);

        if (Constants.DEBUG_MODE_ENABLED) {
          Log.d(TAG, "Started to wipe data");
        }
      } else {
        Toast.makeText(
                getContext(),
                getContextResources().getString(R.string.toast_message_wipe_failed),
                Toast.LENGTH_LONG)
            .show();
        operation.setStatus(getContextResources().getString(R.string.operation_value_error));
        getResultBuilder().build(operation);
      }
    } catch (JSONException e) {
      operation.setStatus(getContextResources().getString(R.string.operation_value_error));
      getResultBuilder().build(operation);
      throw new AndroidAgentException("Invalid JSON format.", e);
    }
  }
コード例 #3
0
  @Override
  public void encryptStorage(Operation operation) throws AndroidAgentException {
    boolean doEncrypt = operation.isEnabled();
    JSONObject result = new JSONObject();

    if (doEncrypt
        && getDevicePolicyManager().getStorageEncryptionStatus()
            != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED
        && (getDevicePolicyManager().getStorageEncryptionStatus()
            == DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE)) {

      getDevicePolicyManager().setStorageEncryption(getCdmDeviceAdmin(), doEncrypt);
      Intent intent = new Intent(DevicePolicyManager.ACTION_START_ENCRYPTION);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      getContext().startActivity(intent);

    } else if (!doEncrypt
        && getDevicePolicyManager().getStorageEncryptionStatus()
            != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED
        && (getDevicePolicyManager().getStorageEncryptionStatus()
                == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE
            || getDevicePolicyManager().getStorageEncryptionStatus()
                == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVATING)) {

      getDevicePolicyManager().setStorageEncryption(getCdmDeviceAdmin(), doEncrypt);
    }

    try {
      String status;
      if (getDevicePolicyManager().getStorageEncryptionStatus()
          != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) {
        status = getContextResources().getString(R.string.shared_pref_default_status);
        result.put(getContextResources().getString(R.string.operation_status), status);

      } else {
        status = getContextResources().getString(R.string.shared_pref_false_status);
        result.put(getContextResources().getString(R.string.operation_status), status);
      }
    } catch (JSONException e) {
      operation.setStatus(getContextResources().getString(R.string.operation_value_error));
      getResultBuilder().build(operation);
      throw new AndroidAgentException("Issue in parsing json", e);
    }
    operation.setPayLoad(result.toString());
    operation.setStatus(getContextResources().getString(R.string.operation_value_completed));
    getResultBuilder().build(operation);
    if (Constants.DEBUG_MODE_ENABLED) {
      Log.d(TAG, "Encryption process started");
    }
  }