UserDetailsSettings uses Guest string, not Guest name

The UserDetailsSettings panel, and its title, show the user's UserInfo.name.
This is correct for a regular user (and for the Owner). But for a Guest user,
this is incorrect, and the user_guest string should be used instead.

The difference occurs if the system language is changed after the guest is created;
the word 'guest' should update to the current language, not be frozen to the
language at the time of the guest's creation.

Bug: 185309160
Test: atest UserDetailsSettingsTest
Change-Id: I545aa3e6cc5d00c0bcc49960f37dddd9334b153b
This commit is contained in:
Adam Bookatz
2021-04-22 17:03:41 -07:00
parent f05822549c
commit f493bf0cdb
2 changed files with 32 additions and 23 deletions

View File

@@ -206,7 +206,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
mSwitchUserPref.setTitle( mSwitchUserPref.setTitle(
context.getString(com.android.settingslib.R.string.user_switch_to_user, context.getString(com.android.settingslib.R.string.user_switch_to_user,
mUserInfo.name)); UserSettings.getUserName(context, mUserInfo)));
if (mUserCaps.mDisallowSwitchUser) { if (mUserCaps.mDisallowSwitchUser) {
mSwitchUserPref.setDisabledByAdmin(RestrictedLockUtilsInternal.getDeviceOwner(context)); mSwitchUserPref.setDisabledByAdmin(RestrictedLockUtilsInternal.getDeviceOwner(context));

View File

@@ -16,6 +16,7 @@
package com.android.settings.users; package com.android.settings.users;
import android.annotation.NonNull;
import android.app.Activity; import android.app.Activity;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.Dialog; import android.app.Dialog;
@@ -505,10 +506,12 @@ public class UserSettings extends SettingsPreferenceFragment
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putInt(UserDetailsSettings.EXTRA_USER_ID, userInfo.id); extras.putInt(UserDetailsSettings.EXTRA_USER_ID, userInfo.id);
extras.putBoolean(AppRestrictionsFragment.EXTRA_NEW_USER, newUser); extras.putBoolean(AppRestrictionsFragment.EXTRA_NEW_USER, newUser);
new SubSettingLauncher(getContext())
final Context context = getContext();
new SubSettingLauncher(context)
.setDestination(UserDetailsSettings.class.getName()) .setDestination(UserDetailsSettings.class.getName())
.setArguments(extras) .setArguments(extras)
.setTitleText(userInfo.name) .setTitleText(getUserName(context, userInfo))
.setSourceMetricsCategory(getMetricsCategory()) .setSourceMetricsCategory(getMetricsCategory())
.launch(); .launch();
} }
@@ -859,32 +862,30 @@ public class UserSettings extends SettingsPreferenceFragment
UserPreference pref; UserPreference pref;
if (user.id == UserHandle.myUserId()) { if (user.id == UserHandle.myUserId()) {
pref = mMePreference; pref = mMePreference;
} else if (user.isGuest()) { } else {
pref = new UserPreference(getPrefContext(), null, user.id); final Context prefContext = getPrefContext();
pref.setTitle(R.string.user_guest); pref = new UserPreference(prefContext, null, user.id);
pref.setIcon(getEncircledDefaultIcon()); pref.setTitle(getUserName(prefContext, user));
pref.setKey(KEY_USER_GUEST);
userPreferences.add(pref); userPreferences.add(pref);
pref.setOnPreferenceClickListener(this);
pref.setEnabled(canOpenUserDetails); pref.setEnabled(canOpenUserDetails);
pref.setSelectable(true); pref.setSelectable(true);
if (mUserCaps.mDisallowSwitchUser) { if (user.isGuest()) {
pref.setDisabledByAdmin(RestrictedLockUtilsInternal.getDeviceOwner(context)); pref.setIcon(getEncircledDefaultIcon());
pref.setKey(KEY_USER_GUEST);
if (mUserCaps.mDisallowSwitchUser) {
pref.setDisabledByAdmin(
RestrictedLockUtilsInternal.getDeviceOwner(context));
} else {
pref.setDisabledByAdmin(null);
}
} else { } else {
pref.setDisabledByAdmin(null); pref.setKey("id=" + user.id);
if (user.isAdmin()) {
pref.setSummary(R.string.user_admin);
}
} }
pref.setOnPreferenceClickListener(this);
} else {
pref = new UserPreference(getPrefContext(), null, user.id);
pref.setKey("id=" + user.id);
userPreferences.add(pref);
if (user.isAdmin()) {
pref.setSummary(R.string.user_admin);
}
pref.setTitle(user.name);
pref.setOnPreferenceClickListener(this);
pref.setEnabled(canOpenUserDetails);
pref.setSelectable(true);
} }
if (pref == null) { if (pref == null) {
continue; continue;
@@ -1063,6 +1064,14 @@ public class UserSettings extends SettingsPreferenceFragment
} }
} }
/** Returns the user's name, or the appropriate string in the case of a Guest. */
public static String getUserName(Context context, @NonNull UserInfo userInfo) {
if (userInfo.isGuest()) {
return context.getString(R.string.user_guest);
}
return userInfo.name;
}
@Override @Override
public boolean onPreferenceClick(Preference pref) { public boolean onPreferenceClick(Preference pref) {
if (pref == mMePreference) { if (pref == mMePreference) {