Example usage for android.app.admin SystemUpdatePolicy createWindowedInstallPolicy

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

Introduction

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

Prototype

public static SystemUpdatePolicy createWindowedInstallPolicy(int startTime, int endTime) 

Source Link

Document

Create a policy object and set it to: new system update will only be installed automatically when the system clock is inside a daily maintenance window.

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   www . jav a  2s.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);
    }
}