android.app.admin.SystemUpdatePolicy Java Examples

The following examples show how to use android.app.admin.SystemUpdatePolicy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SystemUpdatePolicyFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@TargetApi(VERSION_CODES.P)
private boolean 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;
    }

    try {
        if (Util.SDK_INT >= VERSION_CODES.P
                && newPolicy != null && mFreezePeriods.size() != 0) {
            final List<FreezePeriod> periods = new ArrayList<>(mFreezePeriods.size());
            for (Period p : mFreezePeriods) {
                periods.add(p.toFreezePeriod());
            }
            newPolicy.setFreezePeriods(periods);
        }
        mDpm.setSystemUpdatePolicy(DeviceAdminReceiver.getComponentName(getActivity()),
                newPolicy);
        Toast.makeText(getContext(), "Policy set successfully", Toast.LENGTH_LONG).show();
        return true;
    } catch (IllegalArgumentException e) {
        Toast.makeText(getContext(), "Failed to set system update policy: " + e.getMessage(),
                Toast.LENGTH_LONG).show();
    }
    return false;
}
 
Example #2
Source File: LockedActivity.java    From cosu with Apache License 2.0 4 votes vote down vote up
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());
    }
}
 
Example #3
Source File: SystemUpdatePolicyFragment.java    From android-testdpc with Apache License 2.0 4 votes vote down vote up
@TargetApi(VERSION_CODES.P)
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);
        mFreezePeriodPanel.setVisibility(View.GONE);
    } 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;
        }
        if (Util.SDK_INT >= VERSION_CODES.P) {
            List<FreezePeriod> freezePeriods = policy.getFreezePeriods();
            mFreezePeriods.clear();
            for (FreezePeriod period : freezePeriods) {
                Period p = new Period(period.getStart(), period.getEnd());
                mFreezePeriods.add(p);
            }
            mFreezePeriodAdapter.notifyDataSetChanged();
            mFreezePeriodPanel.setVisibility(View.VISIBLE);
        }
    }
    mCurrentSystemUpdatePolicy.setText(policyDescription);
}