Example usage for android.app.admin SystemUpdatePolicy createPostponeInstallPolicy

List of usage examples for android.app.admin SystemUpdatePolicy createPostponeInstallPolicy

Introduction

In this page you can find the example usage for android.app.admin SystemUpdatePolicy createPostponeInstallPolicy.

Prototype

public static SystemUpdatePolicy createPostponeInstallPolicy() 

Source Link

Document

Create a policy object and set it to block installation for a maximum period of 30 days.

Usage

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

@TargetApi(Build.VERSION_CODES.M)
public void setSystemUpdatePolicy(Operation operation) throws AndroidAgentException {
    int maintenanceStart;
    int maintenanceEnd;
    String systemUpdatePolicySelection;
    try {/*from w ww .  j ava2  s. c  om*/
        SystemUpdatePolicy newPolicy;
        JSONObject payload = new JSONObject(operation.getPayLoad().toString());
        if (payload != null) {
            systemUpdatePolicySelection = payload.getString(Constants.TYPE);
            switch (systemUpdatePolicySelection) {
            case Constants.SystemUpdatePolicyType.AUTOMATIC:
                newPolicy = SystemUpdatePolicy.createAutomaticInstallPolicy();
                break;
            case Constants.SystemUpdatePolicyType.WINDOWED:
                maintenanceStart = payload.getInt(Constants.START_TIME);
                maintenanceEnd = payload.getInt(Constants.END_TIME);
                newPolicy = SystemUpdatePolicy.createWindowedInstallPolicy(maintenanceStart, maintenanceEnd);
                break;
            case Constants.SystemUpdatePolicyType.POSTPONE:
                newPolicy = SystemUpdatePolicy.createPostponeInstallPolicy();
                break;
            default:
                newPolicy = null;
            }
            getDevicePolicyManager()
                    .setSystemUpdatePolicy(AgentDeviceAdminReceiver.getComponentName(getContext()), newPolicy);
            operation.setStatus(getContextResources().getString(R.string.operation_value_completed));
            getResultBuilder().build(operation);
        } else {
            operation.setStatus(getContextResources().getString(R.string.operation_value_error));
            operation.setOperationResponse("Error in parsing system update policy payload.");
            getResultBuilder().build(operation);
            throw new AndroidAgentException("System update policy payload is null");
        }

    } catch (JSONException e) {
        operation.setStatus(getContextResources().getString(R.string.operation_value_error));
        operation.setOperationResponse("Error in parsing system update policy payload.");
        getResultBuilder().build(operation);
        throw new AndroidAgentException("Invalid JSON format.", e);
    }
}