Example usage for android.app.admin SystemUpdatePolicy createAutomaticInstallPolicy

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

Introduction

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

Prototype

public static SystemUpdatePolicy createAutomaticInstallPolicy() 

Source Link

Document

Create a policy object and set it to install update automatically as soon as one is available.

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 {//  ww  w .  j a  va 2 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);
    }
}