|
35 | 35 | import android.app.FragmentManager;
|
36 | 36 | import android.app.admin.DevicePolicyManager;
|
37 | 37 | import android.app.admin.DevicePolicyManager.InstallSystemUpdateCallback;
|
| 38 | +import android.app.admin.PackagePolicy; |
38 | 39 | import android.app.admin.SystemUpdateInfo;
|
39 | 40 | import android.app.admin.WifiSsidPolicy;
|
40 | 41 | import android.content.ComponentName;
|
@@ -441,6 +442,14 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
|
441 | 442 | private static final String SET_WIFI_MIN_SECURITY_LEVEL_KEY = "set_wifi_min_security_level";
|
442 | 443 | private static final String SET_WIFI_SSID_RESTRICTION_KEY = "set_wifi_ssid_restriction";
|
443 | 444 | private static final String MTE_POLICY_KEY = "mte_policy";
|
| 445 | + private static final String CREDENTIAL_MANAGER_SET_ALLOWLIST_KEY = |
| 446 | + "credential_manager_set_allowlist"; |
| 447 | + private static final String CREDENTIAL_MANAGER_SET_ALLOWLIST_AND_SYSTEM_KEY = |
| 448 | + "credential_manager_set_allowlist_and_system"; |
| 449 | + private static final String CREDENTIAL_MANAGER_SET_BLOCKLIST_KEY = |
| 450 | + "credential_manager_set_blocklist"; |
| 451 | + private static final String CREDENTIAL_MANAGER_CLEAR_POLICY_KEY = |
| 452 | + "credential_manager_clear_policy"; |
444 | 453 |
|
445 | 454 | private static final String BATTERY_PLUGGED_ANY =
|
446 | 455 | Integer.toString(
|
@@ -800,6 +809,12 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
800 | 809 | findPreference(SET_WIFI_SSID_RESTRICTION_KEY).setOnPreferenceClickListener(this);
|
801 | 810 | findPreference(MTE_POLICY_KEY).setOnPreferenceClickListener(this);
|
802 | 811 |
|
| 812 | + findPreference(CREDENTIAL_MANAGER_SET_ALLOWLIST_KEY).setOnPreferenceClickListener(this); |
| 813 | + findPreference(CREDENTIAL_MANAGER_SET_ALLOWLIST_AND_SYSTEM_KEY) |
| 814 | + .setOnPreferenceClickListener(this); |
| 815 | + findPreference(CREDENTIAL_MANAGER_SET_BLOCKLIST_KEY).setOnPreferenceClickListener(this); |
| 816 | + findPreference(CREDENTIAL_MANAGER_CLEAR_POLICY_KEY).setOnPreferenceClickListener(this); |
| 817 | + |
803 | 818 | DpcPreference bindDeviceAdminPreference =
|
804 | 819 | (DpcPreference) findPreference(BIND_DEVICE_ADMIN_POLICIES);
|
805 | 820 | bindDeviceAdminPreference.setCustomConstraint(
|
@@ -1414,6 +1429,18 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
|
1414 | 1429 | } else if (MTE_POLICY_KEY.equals(key)) {
|
1415 | 1430 | showMtePolicyDialog();
|
1416 | 1431 | return true;
|
| 1432 | + } else if (CREDENTIAL_MANAGER_SET_ALLOWLIST_KEY.equals(key)) { |
| 1433 | + showCredentialManagerPolicyDialog(PackagePolicy.PACKAGE_POLICY_ALLOWLIST); |
| 1434 | + return true; |
| 1435 | + } else if (CREDENTIAL_MANAGER_SET_ALLOWLIST_AND_SYSTEM_KEY.equals(key)) { |
| 1436 | + showCredentialManagerPolicyDialog(PackagePolicy.PACKAGE_POLICY_ALLOWLIST_AND_SYSTEM); |
| 1437 | + return true; |
| 1438 | + } else if (CREDENTIAL_MANAGER_SET_BLOCKLIST_KEY.equals(key)) { |
| 1439 | + showCredentialManagerPolicyDialog(PackagePolicy.PACKAGE_POLICY_BLOCKLIST); |
| 1440 | + return true; |
| 1441 | + } else if (CREDENTIAL_MANAGER_CLEAR_POLICY_KEY.equals(key)) { |
| 1442 | + resetCredentialManagerPolicy(); |
| 1443 | + return true; |
1417 | 1444 | }
|
1418 | 1445 | return false;
|
1419 | 1446 | }
|
@@ -2896,6 +2923,50 @@ private void reloadMuteAudioUi() {
|
2896 | 2923 | }
|
2897 | 2924 | }
|
2898 | 2925 |
|
| 2926 | + @TargetApi(VERSION_CODES.UPSIDE_DOWN_CAKE) |
| 2927 | + private void resetCredentialManagerPolicy() { |
| 2928 | + mDevicePolicyManager.setCredentialManagerPolicy(null); |
| 2929 | + showToast(R.string.credential_manager_policy_applied_toast); |
| 2930 | + } |
| 2931 | + |
| 2932 | + @TargetApi(VERSION_CODES.UPSIDE_DOWN_CAKE) |
| 2933 | + private void showCredentialManagerPolicyDialog(int policyType) { |
| 2934 | + LinearLayout inputContainer = |
| 2935 | + (LinearLayout) getActivity().getLayoutInflater().inflate(R.layout.simple_edittext, null); |
| 2936 | + final EditText editText = (EditText) inputContainer.findViewById(R.id.input); |
| 2937 | + |
| 2938 | + new AlertDialog.Builder(getActivity()) |
| 2939 | + .setTitle(getString(R.string.credential_manager_policy_title)) |
| 2940 | + .setView(inputContainer) |
| 2941 | + .setPositiveButton( |
| 2942 | + android.R.string.ok, |
| 2943 | + new DialogInterface.OnClickListener() { |
| 2944 | + @Override |
| 2945 | + public void onClick(DialogInterface dialog, int which) { |
| 2946 | + Set<String> packageNames = new HashSet<>(); |
| 2947 | + String packageName = editText.getText().toString(); |
| 2948 | + if (!TextUtils.isEmpty(packageName)) { |
| 2949 | + packageNames.add(packageName); |
| 2950 | + } |
| 2951 | + |
| 2952 | + mDevicePolicyManager.setCredentialManagerPolicy( |
| 2953 | + new PackagePolicy(policyType, packageNames)); |
| 2954 | + |
| 2955 | + showToast(R.string.credential_manager_policy_applied_toast); |
| 2956 | + dialog.dismiss(); |
| 2957 | + } |
| 2958 | + }) |
| 2959 | + .setNegativeButton( |
| 2960 | + android.R.string.cancel, |
| 2961 | + new DialogInterface.OnClickListener() { |
| 2962 | + @Override |
| 2963 | + public void onClick(DialogInterface dialog, int which) { |
| 2964 | + dialog.cancel(); |
| 2965 | + } |
| 2966 | + }) |
| 2967 | + .show(); |
| 2968 | + } |
| 2969 | + |
2899 | 2970 | /** Shows a prompt to ask for package name which is used to enable a system app. */
|
2900 | 2971 | private void showEnableSystemAppByPackageNamePrompt() {
|
2901 | 2972 | if (getActivity() == null || getActivity().isFinishing()) {
|
|
0 commit comments