Example usage for android.app.admin DevicePolicyManager ENCRYPTION_STATUS_ACTIVATING

List of usage examples for android.app.admin DevicePolicyManager ENCRYPTION_STATUS_ACTIVATING

Introduction

In this page you can find the example usage for android.app.admin DevicePolicyManager ENCRYPTION_STATUS_ACTIVATING.

Prototype

int ENCRYPTION_STATUS_ACTIVATING

To view the source code for android.app.admin DevicePolicyManager ENCRYPTION_STATUS_ACTIVATING.

Click Source Link

Document

Result code for #getStorageEncryptionStatus : indicating that encryption is not currently active, but is currently being activated.

Usage

From source file:org.wso2.emm.agent.services.operation.OperationManagerCOSU.java

@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);
    }/*ww  w.  j  a  va 2s.c  o  m*/

    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));
        operation.setOperationResponse("Error in parsing ENCRYPT payload.");
        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");
    }
}

From source file:org.wso2.iot.agent.services.operation.OperationManagerCOSU.java

@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(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);
    }//from   w w  w  .  j ava 2  s . co m

    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));
        operation.setOperationResponse("Error in parsing ENCRYPT payload.");
        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");
    }
}

From source file:org.wso2.mdm.agent.services.Operation.java

/**
 * Encrypt/Decrypt device storage./*from w  w w .  ja va  2s .  c  om*/
 * @param code        - Operation code.
 * @param data        - Data required(Encryption enable/disable switch).
 * @param requestMode - Request mode(Normal mode or policy bundle mode).
 */
public void encryptStorage(String code, String data) throws AndroidAgentException {
    boolean doEncrypt = true;
    try {
        JSONObject encryptData = new JSONObject(data);
        if (!encryptData.isNull(resources.getString(R.string.intent_extra_function))
                && encryptData.get(resources.getString(R.string.intent_extra_function)).toString()
                        .equalsIgnoreCase(resources.getString(R.string.intent_extra_encrypt))) {
            doEncrypt = true;
        } else if (!encryptData.isNull(resources.getString(R.string.intent_extra_function))
                && encryptData.get(resources.getString(R.string.intent_extra_function)).toString()
                        .equalsIgnoreCase(resources.getString(R.string.intent_extra_decrypt))) {
            doEncrypt = false;
        } else if (!encryptData.isNull(resources.getString(R.string.intent_extra_function))) {
            doEncrypt = Boolean.parseBoolean(
                    encryptData.get(resources.getString(R.string.intent_extra_function)).toString());
        }
    } catch (JSONException e) {
        throw new AndroidAgentException("Invalid JSON format.", e);
    }

    ComponentName admin = new ComponentName(context, AgentDeviceAdminReceiver.class);

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

        devicePolicyManager.setStorageEncryption(admin, doEncrypt);
        Intent intent = new Intent(DevicePolicyManager.ACTION_START_ENCRYPTION);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);

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

        devicePolicyManager.setStorageEncryption(admin, doEncrypt);
    }

    String status;
    if (devicePolicyManager.getStorageEncryptionStatus() != DevicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) {
        status = resources.getString(R.string.shared_pref_default_status);
    } else {
        status = resources.getString(R.string.shared_pref_false_status);
    }

    resultBuilder.build(code, status);

}