@Override
 public void passOperationToSystemApp(Operation operation) throws AndroidAgentException {
   if (getApplicationManager().isPackageInstalled(Constants.SERVICE_PACKAGE_NAME)) {
     CommonUtils.callSystemApp(
         getContext(), operation.getCode(), Boolean.toString(operation.isEnabled()), null);
   } else {
     if (operation.isEnabled()) {
       Log.e(TAG, "Invalid operation code received");
     }
   }
 }
 @Override
 public void disenrollDevice(Operation operation) {
   boolean status = operation.isEnabled();
   if (status) {
     CommonUtils.disableAdmin(getContext());
   }
 }
  @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");
    }
  }
  /**
   * Revokes device encrypt policy on the device (Device external storage encryption).
   *
   * @param operation - Operation object.
   */
  private void revokeEncryptPolicy(org.wso2.emm.agent.beans.Operation operation) {

    boolean encryptStatus =
        (devicePolicyManager.getStorageEncryptionStatus()
                != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED
            && (devicePolicyManager.getStorageEncryptionStatus()
                    == devicePolicyManager.ENCRYPTION_STATUS_ACTIVE
                || devicePolicyManager.getStorageEncryptionStatus()
                    == devicePolicyManager.ENCRYPTION_STATUS_ACTIVATING));

    if (operation.isEnabled() && encryptStatus) {
      devicePolicyManager.setStorageEncryption(deviceAdmin, false);
    }
  }
 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
 @Override
 public void handleUserRestriction(Operation operation) throws AndroidAgentException {
   boolean isEnable = operation.isEnabled();
   String key = operation.getCode();
   operation.setStatus(getContextResources().getString(R.string.operation_value_completed));
   getResultBuilder().build(operation);
   if (isEnable) {
     getDevicePolicyManager().addUserRestriction(getCdmDeviceAdmin(), key);
     if (Constants.DEBUG_MODE_ENABLED) {
       Log.d(TAG, "Restriction added: " + key);
     }
   } else {
     getDevicePolicyManager().clearUserRestriction(getCdmDeviceAdmin(), key);
     if (Constants.DEBUG_MODE_ENABLED) {
       Log.d(TAG, "Restriction cleared: " + key);
     }
   }
 }
 /**
  * Revokes camera policy on the device.
  *
  * @param operation - Operation object.
  */
 private void revokeCameraPolicy(org.wso2.emm.agent.beans.Operation operation) {
   if (!operation.isEnabled()) {
     devicePolicyManager.setCameraDisabled(deviceAdmin, false);
   }
 }