private void setSystemUpdatePolicy() { SystemUpdatePolicy newPolicy; switch (mSystemUpdatePolicySelection.getCheckedRadioButtonId()) { case R.id.system_update_policy_automatic: newPolicy = SystemUpdatePolicy.createAutomaticInstallPolicy(); break; case R.id.system_update_policy_Windowed: newPolicy = SystemUpdatePolicy.createWindowedInstallPolicy( mMaintenanceStart, mMaintenanceEnd); break; case R.id.system_update_policy_postpone: newPolicy = SystemUpdatePolicy.createPostponeInstallPolicy(); break; case R.id.system_update_policy_none: default: newPolicy = null; } mDpm.setSystemUpdatePolicy(DeviceAdminReceiver.getComponentName(getActivity()), newPolicy); }
private void reloadSystemUpdatePolicy() { SystemUpdatePolicy policy = mDpm.getSystemUpdatePolicy(); String policyDescription = "Unknown"; if (policy == null) { policyDescription = "None"; mSystemUpdatePolicySelection.check(R.id.system_update_policy_none); mMaintenanceWindowDetails.setVisibility(View.INVISIBLE); } else { switch (policy.getPolicyType()) { case SystemUpdatePolicy.TYPE_INSTALL_AUTOMATIC: policyDescription = "Automatic"; mSystemUpdatePolicySelection.check(R.id.system_update_policy_automatic); mMaintenanceWindowDetails.setVisibility(View.INVISIBLE); break; case SystemUpdatePolicy.TYPE_INSTALL_WINDOWED: { mMaintenanceStart = policy.getInstallWindowStart(); mMaintenanceEnd = policy.getInstallWindowEnd(); policyDescription = String.format("Windowed: %s-%s", formatMinutes(mMaintenanceStart), formatMinutes(mMaintenanceEnd)); updateMaintenanceWindowDisplay(); mSystemUpdatePolicySelection.check(R.id.system_update_policy_Windowed); mMaintenanceWindowDetails.setVisibility(View.VISIBLE); break; } case SystemUpdatePolicy.TYPE_POSTPONE: policyDescription = "Postpone"; mSystemUpdatePolicySelection.check(R.id.system_update_policy_postpone); mMaintenanceWindowDetails.setVisibility(View.INVISIBLE); break; } } mCurrentSystemUpdatePolicy.setText(policyDescription); }
private void setDefaultCosuPolicies(boolean active){ // set user restrictions setUserRestriction(UserManager.DISALLOW_SAFE_BOOT, active); setUserRestriction(UserManager.DISALLOW_FACTORY_RESET, active); setUserRestriction(UserManager.DISALLOW_ADD_USER, active); setUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA, active); setUserRestriction(UserManager.DISALLOW_ADJUST_VOLUME, active); // disable keyguard and status bar mDevicePolicyManager.setKeyguardDisabled(mAdminComponentName, active); mDevicePolicyManager.setStatusBarDisabled(mAdminComponentName, active); // enable STAY_ON_WHILE_PLUGGED_IN enableStayOnWhilePluggedIn(active); // set system update policy if (active){ mDevicePolicyManager.setSystemUpdatePolicy(mAdminComponentName, SystemUpdatePolicy.createWindowedInstallPolicy(60, 120)); } else { mDevicePolicyManager.setSystemUpdatePolicy(mAdminComponentName, null); } // set this Activity as a lock task package mDevicePolicyManager.setLockTaskPackages(mAdminComponentName, active ? new String[]{getPackageName()} : new String[]{}); IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MAIN); intentFilter.addCategory(Intent.CATEGORY_HOME); intentFilter.addCategory(Intent.CATEGORY_DEFAULT); if (active) { // set Cosu activity as home intent receiver so that it is started // on reboot mDevicePolicyManager.addPersistentPreferredActivity( mAdminComponentName, intentFilter, new ComponentName( getPackageName(), LockedActivity.class.getName())); } else { mDevicePolicyManager.clearPackagePersistentPreferredActivities( mAdminComponentName, getPackageName()); } }