@@ -381,6 +381,8 @@ public class PolicyManagementFragment extends BaseSearchablePolicyPreferenceFrag
381
381
private static final String SET_TIME_KEY = "set_time" ;
382
382
private static final String SET_TIME_ZONE_KEY = "set_time_zone" ;
383
383
384
+ private static final String SET_PROFILE_NAME_KEY = "set_profile_name" ;
385
+
384
386
private static final String MANAGE_OVERRIDE_APN_KEY = "manage_override_apn" ;
385
387
386
388
private static final String MANAGED_SYSTEM_UPDATES_KEY = "managed_system_updates" ;
@@ -661,6 +663,8 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
661
663
findPreference (SET_TIME_KEY ).setOnPreferenceClickListener (this );
662
664
findPreference (SET_TIME_ZONE_KEY ).setOnPreferenceClickListener (this );
663
665
666
+ findPreference (SET_PROFILE_NAME_KEY ).setOnPreferenceClickListener (this );
667
+
664
668
findPreference (MANAGE_OVERRIDE_APN_KEY ).setOnPreferenceClickListener (this );
665
669
findPreference (MANAGED_SYSTEM_UPDATES_KEY ).setOnPreferenceClickListener (this );
666
670
@@ -1126,6 +1130,9 @@ public void onPositiveButtonClicked(String[] lockTaskArray) {
1126
1130
case CROSS_PROFILE_CALENDAR_KEY :
1127
1131
showFragment (new CrossProfileCalendarFragment ());
1128
1132
return true ;
1133
+ case SET_PROFILE_NAME_KEY :
1134
+ showSetProfileNameDialog ();
1135
+ return true ;
1129
1136
}
1130
1137
return false ;
1131
1138
}
@@ -3399,7 +3406,7 @@ private void showSetScreenBrightnessDialog() {
3399
3406
* Shows a dialog that asks the user for a screen off timeout value, then sets this value as
3400
3407
* screen off timeout.
3401
3408
*/
3402
- @ TargetApi (28 )
3409
+ @ TargetApi (Build . VERSION_CODES . LOLLIPOP )
3403
3410
private void showSetScreenOffTimeoutDialog () {
3404
3411
if (getActivity () == null || getActivity ().isFinishing ()) {
3405
3412
return ;
@@ -3514,6 +3521,36 @@ private void showSetTimeZoneDialog() {
3514
3521
.show ();
3515
3522
}
3516
3523
3524
+ /**
3525
+ * Shows a dialog that asks the user to set a profile name.
3526
+ */
3527
+ @ TargetApi (28 )
3528
+ private void showSetProfileNameDialog () {
3529
+ if (getActivity () == null || getActivity ().isFinishing ()) {
3530
+ return ;
3531
+ }
3532
+
3533
+ final View dialogView = getActivity ().getLayoutInflater ().inflate (
3534
+ R .layout .simple_edittext , null );
3535
+ final EditText profileNameEditText = (EditText ) dialogView .findViewById (
3536
+ R .id .input );
3537
+ profileNameEditText .setText ("" );
3538
+
3539
+ new AlertDialog .Builder (getActivity ())
3540
+ .setTitle (R .string .set_profile_name )
3541
+ .setView (dialogView )
3542
+ .setPositiveButton (android .R .string .ok , (dialogInterface , i ) -> {
3543
+ final String newProfileName = profileNameEditText .getText ().toString ();
3544
+ if (newProfileName .isEmpty ()) {
3545
+ showToast (R .string .no_profile_name );
3546
+ return ;
3547
+ }
3548
+ mDevicePolicyManager .setProfileName (mAdminComponentName , newProfileName );
3549
+ })
3550
+ .setNegativeButton (android .R .string .cancel , null )
3551
+ .show ();
3552
+ }
3553
+
3517
3554
private void chooseAccount () {
3518
3555
if (getActivity () == null || getActivity ().isFinishing ()) {
3519
3556
return ;
0 commit comments