/** * Revokes EMM policy on the device. * * @param operation - Operation object. * @return status - Revoke status. */ public void revokeExistingPolicy(org.wso2.emm.agent.beans.Operation operation) throws AndroidAgentException { switch (operation.getCode()) { case Constants.Operation.CAMERA: revokeCameraPolicy(operation); break; case Constants.Operation.INSTALL_APPLICATION: revokeInstallAppPolicy(operation); break; case Constants.Operation.ENCRYPT_STORAGE: revokeEncryptPolicy(operation); break; case Constants.Operation.PASSCODE_POLICY: revokePasswordPolicy(); break; case Constants.Operation.WIFI: revokeWifiPolicy(operation); break; default: String msg = "Invalid operation code received"; Log.e(TAG, msg); throw new AndroidAgentException(msg); } }
@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 installAppBundle(Operation operation) throws AndroidAgentException { try { if (operation.getCode().equals(Constants.Operation.INSTALL_APPLICATION)) { JSONObject appData = new JSONObject(operation.getPayLoad().toString()); installApplication(appData, operation); } else if (operation.getCode().equals(Constants.Operation.INSTALL_APPLICATION_BUNDLE)) { JSONArray jArray; jArray = new JSONArray(operation.getPayLoad().toString()); for (int i = 0; i < jArray.length(); i++) { JSONObject appObj = jArray.getJSONObject(i); installApplication(appObj, operation); } } if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Application bundle installation started"); } } catch (JSONException e) { operation.setStatus(getContextResources().getString(R.string.operation_value_error)); getResultBuilder().build(operation); throw new AndroidAgentException("Invalid JSON format.", e); } }
@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); } } }