|
33 | 33 | import android.app.Fragment;
|
34 | 34 | import android.app.FragmentManager;
|
35 | 35 | import android.app.admin.DevicePolicyManager;
|
| 36 | +import android.app.admin.DevicePolicyManager.InstallUpdateCallback; |
36 | 37 | import android.app.admin.SystemUpdateInfo;
|
37 | 38 | import android.content.ComponentName;
|
38 | 39 | import android.content.ContentResolver;
|
|
80 | 81 | import android.widget.RadioButton;
|
81 | 82 | import android.widget.RadioGroup;
|
82 | 83 | import android.widget.Toast;
|
83 |
| - |
84 | 84 | import com.afwsamples.testdpc.AddAccountActivity;
|
85 | 85 | import com.afwsamples.testdpc.BuildConfig;
|
86 | 86 | import com.afwsamples.testdpc.CrossProfileAppsFragment;
|
|
92 | 92 | import com.afwsamples.testdpc.common.BaseSearchablePolicyPreferenceFragment;
|
93 | 93 | import com.afwsamples.testdpc.common.CertificateUtil;
|
94 | 94 | import com.afwsamples.testdpc.common.MediaDisplayFragment;
|
| 95 | +import com.afwsamples.testdpc.common.PackageInstallationUtils; |
95 | 96 | import com.afwsamples.testdpc.common.UserArrayAdapter;
|
96 | 97 | import com.afwsamples.testdpc.common.Util;
|
97 | 98 | import com.afwsamples.testdpc.common.preference.CustomConstraint;
|
|
100 | 101 | import com.afwsamples.testdpc.common.preference.DpcPreferenceHelper;
|
101 | 102 | import com.afwsamples.testdpc.common.preference.DpcSwitchPreference;
|
102 | 103 | import com.afwsamples.testdpc.comp.BindDeviceAdminFragment;
|
103 |
| -import com.afwsamples.testdpc.common.PackageInstallationUtils; |
104 | 104 | import com.afwsamples.testdpc.policy.blockuninstallation.BlockUninstallationInfoArrayAdapter;
|
105 | 105 | import com.afwsamples.testdpc.policy.certificate.DelegatedCertInstallerFragment;
|
106 | 106 | import com.afwsamples.testdpc.policy.keyguard.LockScreenPolicyFragment;
|
|
126 | 126 | import com.afwsamples.testdpc.profilepolicy.permission.ManageAppPermissionsFragment;
|
127 | 127 | import com.afwsamples.testdpc.transferownership.PickTransferComponentFragment;
|
128 | 128 | import com.afwsamples.testdpc.util.MainThreadExecutor;
|
129 |
| - |
130 | 129 | import java.io.ByteArrayInputStream;
|
131 | 130 | import java.io.File;
|
132 | 131 | import java.io.FileNotFoundException;
|
@@ -371,6 +370,8 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
|
371 | 370 |
|
372 | 371 | private static final String MANAGE_OVERRIDE_APN_KEY = "manage_override_apn";
|
373 | 372 |
|
| 373 | + private static final String MANAGED_SYSTEM_UPDATES_KEY = "managed_system_updates"; |
| 374 | + |
374 | 375 | private static final String SET_PRIVATE_DNS_MODE_KEY = "set_private_dns_mode";
|
375 | 376 |
|
376 | 377 | private static final String BATTERY_PLUGGED_ANY = Integer.toString(
|
@@ -621,6 +622,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
621 | 622 | findPreference(SET_TIME_ZONE_KEY).setOnPreferenceClickListener(this);
|
622 | 623 |
|
623 | 624 | findPreference(MANAGE_OVERRIDE_APN_KEY).setOnPreferenceClickListener(this);
|
| 625 | + findPreference(MANAGED_SYSTEM_UPDATES_KEY).setOnPreferenceClickListener(this); |
624 | 626 |
|
625 | 627 | findPreference(CROSS_PROFILE_CALENDAR_KEY).setOnPreferenceClickListener(this);
|
626 | 628 |
|
@@ -1061,13 +1063,46 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
|
1061 | 1063 | case MANAGE_OVERRIDE_APN_KEY:
|
1062 | 1064 | showFragment(new OverrideApnFragment());
|
1063 | 1065 | return true;
|
| 1066 | + case MANAGED_SYSTEM_UPDATES_KEY: |
| 1067 | + promptInstallUpdate(); |
| 1068 | + return true; |
1064 | 1069 | case CROSS_PROFILE_CALENDAR_KEY:
|
1065 | 1070 | showFragment(new CrossProfileCalendarFragment());
|
1066 | 1071 | return true;
|
1067 | 1072 | }
|
1068 | 1073 | return false;
|
1069 | 1074 | }
|
1070 | 1075 |
|
| 1076 | + @TargetApi(Build.VERSION_CODES.Q) |
| 1077 | + private void promptInstallUpdate() { |
| 1078 | + new AlertDialog.Builder(getActivity()) |
| 1079 | + .setMessage(R.string.install_update_prompt) |
| 1080 | + .setTitle(R.string.install_update) |
| 1081 | + .setPositiveButton( |
| 1082 | + R.string.install_update_prompt_yes, (dialogInterface, i) -> installUpdate()) |
| 1083 | + .setNegativeButton( |
| 1084 | + R.string.install_update_prompt_no, (dialogInterface, i) -> {}) |
| 1085 | + .create() |
| 1086 | + .show(); |
| 1087 | + } |
| 1088 | + |
| 1089 | + @TargetApi(Build.VERSION_CODES.Q) |
| 1090 | + private void installUpdate() { |
| 1091 | + File file = new File(getContext().getFilesDir(), "ota.zip"); |
| 1092 | + Uri uri = FileProvider.getUriForFile( |
| 1093 | + getActivity(), BuildConfig.APPLICATION_ID + ".fileprovider", file); |
| 1094 | + mDevicePolicyManager.installSystemUpdate( |
| 1095 | + mAdminComponentName, |
| 1096 | + uri, |
| 1097 | + new MainThreadExecutor(), |
| 1098 | + new InstallUpdateCallback() { |
| 1099 | + @Override |
| 1100 | + public void onInstallUpdateError(int errorCode, String errorMessage) { |
| 1101 | + showToast("Error code: " + errorCode); |
| 1102 | + } |
| 1103 | + }); |
| 1104 | + } |
| 1105 | + |
1071 | 1106 | @RequiresApi(api = Build.VERSION_CODES.M)
|
1072 | 1107 | private void testKeyCanBeUsedForSigning() {
|
1073 | 1108 | KeyChain.choosePrivateKeyAlias(getActivity(), new KeyChainAliasCallback() {
|
|
0 commit comments