/** Upgrading device firmware over the air (OTA). */ public void upgradeFirmware(boolean isStatusCheck) { Log.i(TAG, "An upgrade has been requested"); Context context = this.getApplicationContext(); Preference.putBoolean( context, context.getResources().getString(R.string.firmware_status_check_in_progress), isStatusCheck); Preference.putString( context, context.getResources().getString(R.string.firmware_download_progress), String.valueOf(DEFAULT_STATE_INFO_CODE)); Preference.putInt( context, context.getResources().getString(R.string.operation_id), operationId); String schedule = null; String server; if (command != null && !command.trim().isEmpty()) { try { JSONObject upgradeData = new JSONObject(command); if (!upgradeData.isNull(context.getResources().getString(R.string.alarm_schedule))) { schedule = (String) upgradeData.get(context.getResources().getString(R.string.alarm_schedule)); } if (!upgradeData.isNull(context.getResources().getString(R.string.firmware_server))) { server = (String) upgradeData.get(context.getResources().getString(R.string.firmware_server)); if (URLUtil.isValidUrl(server)) { Preference.putString( context, context.getResources().getString(R.string.firmware_server), server); } } } catch (JSONException e) { Log.e(TAG, "Firmware upgrade payload parsing failed." + e); } } if (schedule != null && !schedule.trim().isEmpty()) { Log.i(TAG, "Upgrade has been scheduled to " + schedule); Preference.putString( context, context.getResources().getString(R.string.alarm_schedule), schedule); try { AlarmUtils.setOneTimeAlarm(context, schedule, Constants.Operation.UPGRADE_FIRMWARE, null); } catch (ParseException e) { Log.e(TAG, "One time alarm time string parsing failed." + e); } } else { if (isStatusCheck) { Log.i(TAG, "Firmware status check is initiated by admin."); } else { Log.i(TAG, "Upgrade request initiated by admin."); } // Prepare for upgrade OTADownload otaDownload = new OTADownload(context); otaDownload.startOTA(); } }
/** * Executes device management operations on the device. * * @param code - Operation object. */ public void doTask(String code) { switch (code) { case Constants.Operation.DEVICE_LOCK: enableHardLock(); break; case Constants.Operation.DEVICE_UNLOCK: disableHardLock(); break; case Constants.Operation.ENABLE_ADMIN: startAdmin(); break; case Constants.Operation.UPGRADE_FIRMWARE: upgradeFirmware(false); break; case Constants.Operation.REBOOT: rebootDevice(); break; case Constants.Operation.EXECUTE_SHELL_COMMAND: if (command != null) { executeShellCommand(command); } break; case Constants.Operation.SILENT_INSTALL_APPLICATION: if (appUri != null) { silentInstallApp(getApplicationContext(), appUri, command); } break; case Constants.Operation.SILENT_UPDATE_APPLICATION: if (appUri != null) { silentInstallApp(getApplicationContext(), appUri, command); } break; case Constants.Operation.SILENT_UNINSTALL_APPLICATION: if (appUri != null) { silentUninstallApp(getApplicationContext(), appUri, command); } break; case Constants.Operation.REMOVE_DEVICE_OWNER: SettingsManager.clearDeviceOwner(); break; case Constants.Operation.DISALLOW_ADJUST_VOLUME: SettingsManager.restrict(DISALLOW_ADJUST_VOLUME, restrictionCode); break; case Constants.Operation.DISALLOW_ADD_USER: SettingsManager.restrict(DISALLOW_ADD_USER, restrictionCode); break; case Constants.Operation.DISALLOW_APPS_CONTROL: SettingsManager.restrict(DISALLOW_APPS_CONTROL, restrictionCode); break; case Constants.Operation.DISALLOW_CONFIG_BLUETOOTH: SettingsManager.restrict(DISALLOW_CONFIG_BLUETOOTH, restrictionCode); break; case Constants.Operation.DISALLOW_CONFIG_CELL_BROADCASTS: SettingsManager.restrict(DISALLOW_CONFIG_CELL_BROADCASTS, restrictionCode); break; case Constants.Operation.DISALLOW_CONFIG_CREDENTIALS: SettingsManager.restrict(DISALLOW_CONFIG_CREDENTIALS, restrictionCode); break; case Constants.Operation.DISALLOW_CONFIG_MOBILE_NETWORKS: SettingsManager.restrict(DISALLOW_CONFIG_MOBILE_NETWORKS, restrictionCode); break; case Constants.Operation.DISALLOW_CONFIG_TETHERING: SettingsManager.restrict(DISALLOW_CONFIG_TETHERING, restrictionCode); break; case Constants.Operation.DISALLOW_CONFIG_VPN: SettingsManager.restrict(DISALLOW_CONFIG_VPN, restrictionCode); break; case Constants.Operation.DISALLOW_CONFIG_WIFI: SettingsManager.restrict(DISALLOW_CONFIG_WIFI, restrictionCode); break; case Constants.Operation.DISALLOW_CREATE_WINDOWS: SettingsManager.restrict(DISALLOW_CREATE_WINDOWS, restrictionCode); break; case Constants.Operation.DISALLOW_CROSS_PROFILE_COPY_PASTE: SettingsManager.restrict(DISALLOW_CROSS_PROFILE_COPY_PASTE, restrictionCode); break; case Constants.Operation.DISALLOW_DEBUGGING_FEATURES: SettingsManager.restrict(DISALLOW_DEBUGGING_FEATURES, restrictionCode); break; case Constants.Operation.DISALLOW_FACTORY_RESET: SettingsManager.restrict(DISALLOW_FACTORY_RESET, restrictionCode); break; case Constants.Operation.DISALLOW_INSTALL_APPS: SettingsManager.restrict(DISALLOW_INSTALL_APPS, restrictionCode); break; case Constants.Operation.DISALLOW_INSTALL_UNKNOWN_SOURCES: SettingsManager.restrict(DISALLOW_INSTALL_UNKNOWN_SOURCES, restrictionCode); break; case Constants.Operation.DISALLOW_MODIFY_ACCOUNTS: SettingsManager.restrict(DISALLOW_MODIFY_ACCOUNTS, restrictionCode); break; case Constants.Operation.DISALLOW_MOUNT_PHYSICAL_MEDIA: SettingsManager.restrict(DISALLOW_MOUNT_PHYSICAL_MEDIA, restrictionCode); break; case Constants.Operation.DISALLOW_NETWORK_RESET: SettingsManager.restrict(DISALLOW_NETWORK_RESET, restrictionCode); break; case Constants.Operation.DISALLOW_OUTGOING_BEAM: SettingsManager.restrict(DISALLOW_OUTGOING_BEAM, restrictionCode); break; case Constants.Operation.DISALLOW_OUTGOING_CALLS: SettingsManager.restrict(DISALLOW_OUTGOING_CALLS, restrictionCode); break; case Constants.Operation.DISALLOW_REMOVE_USER: SettingsManager.restrict(DISALLOW_REMOVE_USER, restrictionCode); break; case Constants.Operation.DISALLOW_SAFE_BOOT: SettingsManager.restrict(DISALLOW_SAFE_BOOT, restrictionCode); break; case Constants.Operation.DISALLOW_SHARE_LOCATION: SettingsManager.restrict(DISALLOW_SHARE_LOCATION, restrictionCode); break; case Constants.Operation.DISALLOW_SMS: SettingsManager.restrict(DISALLOW_SMS, restrictionCode); break; case Constants.Operation.DISALLOW_UNINSTALL_APPS: SettingsManager.restrict(DISALLOW_UNINSTALL_APPS, restrictionCode); break; case Constants.Operation.DISALLOW_UNMUTE_MICROPHONE: SettingsManager.restrict(DISALLOW_UNMUTE_MICROPHONE, restrictionCode); break; case Constants.Operation.DISALLOW_USB_FILE_TRANSFER: SettingsManager.restrict(DISALLOW_USB_FILE_TRANSFER, restrictionCode); break; case Constants.Operation.ENSURE_VERIFY_APPS: SettingsManager.restrict(ENSURE_VERIFY_APPS, restrictionCode); break; case Constants.Operation.ALLOW_PARENT_PROFILE_APP_LINKING: SettingsManager.restrict(ALLOW_PARENT_PROFILE_APP_LINKING, restrictionCode); break; case Constants.Operation.AUTO_TIME: SettingsManager.setAutoTimeRequired(restrictionCode); break; case Constants.Operation.SET_SCREEN_CAPTURE_DISABLED: SettingsManager.setScreenCaptureDisabled(restrictionCode); break; case Constants.Operation.APP_RESTRICTION: if (command != null && (command.equals("true") || command.equals("false"))) { SettingsManager.setVisibilityOfApp(appUri, Boolean.parseBoolean(command)); } break; // Only With Android M. case Constants.Operation.SET_STATUS_BAR_DISABLED: SettingsManager.setStatusBarDisabled(restrictionCode); break; case Constants.Operation.GET_FIRMWARE_UPGRADE_PACKAGE_STATUS: Preference.putBoolean( context, context.getResources().getString(R.string.firmware_status_check_in_progress), true); upgradeFirmware(true); break; case Constants.Operation.WIPE_DATA: try { Runtime.getRuntime().exec("sh"); Runtime.getRuntime().exec("am broadcast -a android.intent.action.MASTER_CLEAR"); } catch (IOException e) { Log.e("TAG", "Shell command execution failed." + e); } break; case Constants.Operation.GET_FIRMWARE_UPGRADE_DOWNLOAD_PROGRESS: publishFirmwareDownloadProgress(); break; case Constants.Operation.GET_FIRMWARE_BUILD_DATE: publishFirmwareBuildDate(); break; default: Log.e(TAG, "Invalid operation code received"); break; } }