Check new user restriction for profile removal

Test: make RunSettingsRoboTests
Bug: 31952368
Change-Id: I3c8b0820a5541201006d12f9893d5b89332334c2
diff --git a/src/com/android/settings/accounts/AccountPreferenceController.java b/src/com/android/settings/accounts/AccountPreferenceController.java
index fa99f77..a8b95d7 100644
--- a/src/com/android/settings/accounts/AccountPreferenceController.java
+++ b/src/com/android/settings/accounts/AccountPreferenceController.java
@@ -60,6 +60,7 @@
 
 import static android.content.Intent.EXTRA_USER;
 import static android.os.UserManager.DISALLOW_MODIFY_ACCOUNTS;
+import static android.os.UserManager.DISALLOW_REMOVE_MANAGED_PROFILE;
 import static android.os.UserManager.DISALLOW_REMOVE_USER;
 import static android.provider.Settings.EXTRA_AUTHORITIES;
 
@@ -172,7 +173,7 @@
                     rawData.add(data);
                 }
                 if (userInfo.isManagedProfile()) {
-                    if (!mHelper.hasBaseUserRestriction(DISALLOW_REMOVE_USER,
+                    if (!mHelper.hasBaseUserRestriction(DISALLOW_REMOVE_MANAGED_PROFILE,
                         UserHandle.myUserId())) {
                         SearchIndexableRaw data = new SearchIndexableRaw(mContext);
                         data.title = res.getString(R.string.remove_managed_profile_label);
@@ -306,7 +307,7 @@
                 mContext.getString(R.string.accessibility_category_work, workGroupSummary));
             profileData.removeWorkProfilePreference = newRemoveWorkProfilePreference(context);
             mHelper.enforceRestrictionOnPreference(profileData.removeWorkProfilePreference,
-                DISALLOW_REMOVE_USER, UserHandle.myUserId());
+                DISALLOW_REMOVE_MANAGED_PROFILE, UserHandle.myUserId());
             profileData.managedProfilePreference = newManagedProfileSettings();
         } else {
             preferenceGroup.setTitle(R.string.category_personal);
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
index 6e9083b..528d811 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountPreferenceControllerTest.java
@@ -242,7 +242,8 @@
         infos.add(new UserInfo(1, "user 1", UserInfo.FLAG_MANAGED_PROFILE));
         when(mUserManager.isManagedProfile()).thenReturn(false);
         when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
-        when(mAccountHelper.hasBaseUserRestriction(eq(UserManager.DISALLOW_REMOVE_USER), anyInt()))
+        when(mAccountHelper.hasBaseUserRestriction(
+                eq(UserManager.DISALLOW_REMOVE_MANAGED_PROFILE), anyInt()))
             .thenReturn(true);
 
         mController.updateRawDataToIndex(data);