@Override public void disenrollDevice(Operation operation) { boolean status = operation.isEnabled(); if (status) { CommonUtils.disableAdmin(getContext()); } }
@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"); } } }
/** This method is used to invoke getEffectivePolicy in the backend */ private void getEffectivePolicy() { if (CommonUtils.isNetworkAvailable(context)) { String ipSaved = Preference.getString(context.getApplicationContext(), Constants.IP); ServerConfig utils = new ServerConfig(); utils.setServerIP(ipSaved); CommonUtils.callSecuredAPI( RegistrationActivity.this, utils.getAPIServerURL() + Constants.POLICY_ENDPOINT + deviceIdentifier, HTTP_METHODS.GET, null, RegistrationActivity.this, Constants.POLICY_REQUEST_CODE); } else { CommonDialogUtils.stopProgressDialog(progressDialog); CommonDialogUtils.showNetworkUnavailableMessage(RegistrationActivity.this); } }
private void registerDevice() { progressDialog = CommonDialogUtils.showPrgressDialog( RegistrationActivity.this, getResources().getString(R.string.dialog_enrolling), getResources().getString(R.string.dialog_please_wait), null); progressDialog.show(); String type = Preference.getString( context, context.getResources().getString(R.string.shared_pref_reg_type)); String username = Preference.getString(context, context.getResources().getString(R.string.username)); try { deviceInfoBuilder.build(type, username); } catch (AndroidAgentException e) { Log.e(TAG, "Error occurred while building the device info payload.", e); } // Check network connection availability before calling the API. if (CommonUtils.isNetworkAvailable(context)) { // Call device registration API. String ipSaved = Preference.getString(context.getApplicationContext(), Constants.IP); ServerConfig utils = new ServerConfig(); utils.setServerIP(ipSaved); CommonUtils.callSecuredAPI( RegistrationActivity.this, utils.getAPIServerURL() + Constants.REGISTER_ENDPOINT, HTTP_METHODS.POST, deviceInfoBuilder.getDeviceInfoPayload(), RegistrationActivity.this, Constants.REGISTER_REQUEST_CODE); } else { CommonDialogUtils.stopProgressDialog(progressDialog); CommonDialogUtils.showNetworkUnavailableMessage(RegistrationActivity.this); } }
@Override public void enterpriseWipe(Operation operation) throws AndroidAgentException { operation.setStatus(getContextResources().getString(R.string.operation_value_completed)); getResultBuilder().build(operation); CommonUtils.disableAdmin(getContext()); Intent intent = new Intent(getContext(), ServerDetails.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getContext().startActivity(intent); if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Started enterprise wipe"); } }
/** * This is used to send the registration Id to MDM server so that the server can use it as a * reference to identify the device when sending messages to Google server. * * @throws AndroidAgentException */ public void sendRegistrationId() throws AndroidAgentException { DeviceInfo deviceInfo = new DeviceInfo(context); DeviceInfoPayload deviceInfoPayload = new DeviceInfoPayload(context); deviceInfoPayload.build(); String replyPayload = deviceInfoPayload.getDeviceInfoPayload(); String ipSaved = Preference.getString(context, Constants.IP); ServerConfig utils = new ServerConfig(); utils.setServerIP(ipSaved); String url = utils.getAPIServerURL() + Constants.DEVICE_ENDPOINT + deviceInfo.getDeviceId(); CommonUtils.callSecuredAPI( context, url, org.wso2.emm.agent.proxy.utils.Constants.HTTP_METHODS.PUT, replyPayload, RegistrationActivity.this, Constants.GCM_REGISTRATION_ID_SEND_CODE); }