Make use of config for auto-created guest users
If frameworks config config_guestUserAutoCreated=true, then Settings will: - Create a new guest user any time the current guest user is removed - Show "Guest" instead of "Add guest" - Show "Reset guest" instead of "Remove guest" Bug: 188542158 Test: With config_guestUserAutoCreated=true, delete current guest user using adb (`adb shell cmd user list -v --all` to find the user ids, then remove each guest user with `adb shell pm remove-user <id>`), then as owner, open multi-users settings page. Check that there is a item for "Guest" instead of "Add guest". Select "Guest", then confirm there is an item for "Reset guest" (it should be disabled). Select "Switch to guest", then switch back to owner. Open the multi-users settings page again. Check that "Reset guest" is now enabled. Tap "Reset guest", and press confirmation button, named "Reset". You should be take back to the main multi-user settings page and still see "Guest". Wait a few seconds, then use adb to confirm there is a guest user present. Test: With config_guestUserAutoCreated=true, switch to guest user, open multi-users settings page, check that there is an option to "Reset guest". Select "Reset guest", and press confirmation button, named "Reset". Phone should switch back to last active user, and QS tile should now show "Guest" instead of "Add guest". Run `adb shell cmd user list -v --all` to confirm guest has a new user id. Test: With config_guestUserAutoCreated=false, confirm that "Add guest" and "Remove guest" features remain unchanged Change-Id: I7d5b81bd2e5c6b999ae18cd6b1280ae0496db94b
This commit is contained in:
@@ -42,6 +42,9 @@ import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Settings screen for configuring, deleting or switching to a specific user.
|
||||
@@ -67,9 +70,13 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
private static final int DIALOG_CONFIRM_ENABLE_CALLING = 2;
|
||||
private static final int DIALOG_CONFIRM_ENABLE_CALLING_AND_SMS = 3;
|
||||
private static final int DIALOG_SETUP_USER = 4;
|
||||
private static final int DIALOG_CONFIRM_RESET_GUEST = 5;
|
||||
|
||||
private UserManager mUserManager;
|
||||
private UserCapabilities mUserCaps;
|
||||
private boolean mGuestUserAutoCreated;
|
||||
private final AtomicBoolean mGuestCreationScheduled = new AtomicBoolean();
|
||||
private final ExecutorService mExecutor = Executors.newSingleThreadExecutor();
|
||||
|
||||
@VisibleForTesting
|
||||
RestrictedPreference mSwitchUserPref;
|
||||
@@ -97,6 +104,9 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
mUserCaps = UserCapabilities.create(context);
|
||||
addPreferencesFromResource(R.xml.user_details_settings);
|
||||
|
||||
mGuestUserAutoCreated = getPrefContext().getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_guestUserAutoCreated);
|
||||
|
||||
initialize(context, getArguments());
|
||||
}
|
||||
|
||||
@@ -104,13 +114,20 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mSwitchUserPref.setEnabled(canSwitchUserNow());
|
||||
if (mGuestUserAutoCreated) {
|
||||
mRemoveUserPref.setEnabled((mUserInfo.flags & UserInfo.FLAG_INITIALIZED) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (preference == mRemoveUserPref) {
|
||||
if (canDeleteUser()) {
|
||||
showDialog(DIALOG_CONFIRM_REMOVE);
|
||||
if (mUserInfo.isGuest()) {
|
||||
showDialog(DIALOG_CONFIRM_RESET_GUEST);
|
||||
} else {
|
||||
showDialog(DIALOG_CONFIRM_REMOVE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else if (preference == mSwitchUserPref) {
|
||||
@@ -144,6 +161,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
public int getDialogMetricsCategory(int dialogId) {
|
||||
switch (dialogId) {
|
||||
case DIALOG_CONFIRM_REMOVE:
|
||||
case DIALOG_CONFIRM_RESET_GUEST:
|
||||
return SettingsEnums.DIALOG_USER_REMOVE;
|
||||
case DIALOG_CONFIRM_ENABLE_CALLING:
|
||||
return SettingsEnums.DIALOG_USER_ENABLE_CALLING;
|
||||
@@ -179,10 +197,30 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
switchUser();
|
||||
}
|
||||
});
|
||||
case DIALOG_CONFIRM_RESET_GUEST:
|
||||
return UserDialogs.createResetGuestDialog(getActivity(),
|
||||
(dialog, which) -> resetGuest());
|
||||
}
|
||||
throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase the current guest user and create a new one in the background. UserSettings will
|
||||
* handle guest creation after receiving the {@link UserSettings.RESULT_GUEST_REMOVED} result.
|
||||
*/
|
||||
private void resetGuest() {
|
||||
// Just to be safe, check that the selected user is a guest
|
||||
if (!mUserInfo.isGuest()) {
|
||||
return;
|
||||
}
|
||||
mMetricsFeatureProvider.action(getActivity(),
|
||||
SettingsEnums.ACTION_USER_GUEST_EXIT_CONFIRMED);
|
||||
|
||||
mUserManager.removeUser(mUserInfo.id);
|
||||
setResult(UserSettings.RESULT_GUEST_REMOVED);
|
||||
finishFragment();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@Override
|
||||
protected void showDialog(int dialogId) {
|
||||
@@ -239,11 +277,17 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
||||
if (mUserInfo.isGuest()) {
|
||||
// These are not for an existing user, just general Guest settings.
|
||||
// Default title is for calling and SMS. Change to calling-only here
|
||||
// TODO(b/191483069): These settings can't be changed unless guest user exists
|
||||
mPhonePref.setTitle(R.string.user_enable_calling);
|
||||
mDefaultGuestRestrictions = mUserManager.getDefaultGuestRestrictions();
|
||||
mPhonePref.setChecked(
|
||||
!mDefaultGuestRestrictions.getBoolean(UserManager.DISALLOW_OUTGOING_CALLS));
|
||||
mRemoveUserPref.setTitle(R.string.user_exit_guest_title);
|
||||
mRemoveUserPref.setTitle(mGuestUserAutoCreated
|
||||
? com.android.settingslib.R.string.guest_reset_guest
|
||||
: R.string.user_exit_guest_title);
|
||||
if (mGuestUserAutoCreated) {
|
||||
mRemoveUserPref.setEnabled((mUserInfo.flags & UserInfo.FLAG_INITIALIZED) != 0);
|
||||
}
|
||||
} else {
|
||||
mPhonePref.setChecked(!mUserManager.hasUserRestriction(
|
||||
UserManager.DISALLOW_OUTGOING_CALLS, new UserHandle(userId)));
|
||||
|
Reference in New Issue
Block a user