Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f493bf0c authored by Adam Bookatz's avatar Adam Bookatz
Browse files

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
parent f0582254
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -206,7 +206,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment

        mSwitchUserPref.setTitle(
                context.getString(com.android.settingslib.R.string.user_switch_to_user,
                        mUserInfo.name));
                        UserSettings.getUserName(context, mUserInfo)));

        if (mUserCaps.mDisallowSwitchUser) {
            mSwitchUserPref.setDisabledByAdmin(RestrictedLockUtilsInternal.getDeviceOwner(context));
+31 −22
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.users;

import android.annotation.NonNull;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Dialog;
@@ -505,10 +506,12 @@ public class UserSettings extends SettingsPreferenceFragment
        Bundle extras = new Bundle();
        extras.putInt(UserDetailsSettings.EXTRA_USER_ID, userInfo.id);
        extras.putBoolean(AppRestrictionsFragment.EXTRA_NEW_USER, newUser);
        new SubSettingLauncher(getContext())

        final Context context = getContext();
        new SubSettingLauncher(context)
                .setDestination(UserDetailsSettings.class.getName())
                .setArguments(extras)
                .setTitleText(userInfo.name)
                .setTitleText(getUserName(context, userInfo))
                .setSourceMetricsCategory(getMetricsCategory())
                .launch();
    }
@@ -859,32 +862,30 @@ public class UserSettings extends SettingsPreferenceFragment
            UserPreference pref;
            if (user.id == UserHandle.myUserId()) {
                pref = mMePreference;
            } else if (user.isGuest()) {
                pref = new UserPreference(getPrefContext(), null, user.id);
                pref.setTitle(R.string.user_guest);
                pref.setIcon(getEncircledDefaultIcon());
                pref.setKey(KEY_USER_GUEST);
            } else {
                final Context prefContext = getPrefContext();
                pref = new UserPreference(prefContext, null, user.id);
                pref.setTitle(getUserName(prefContext, user));
                userPreferences.add(pref);
                pref.setOnPreferenceClickListener(this);
                pref.setEnabled(canOpenUserDetails);
                pref.setSelectable(true);

                if (user.isGuest()) {
                    pref.setIcon(getEncircledDefaultIcon());
                    pref.setKey(KEY_USER_GUEST);
                    if (mUserCaps.mDisallowSwitchUser) {
                    pref.setDisabledByAdmin(RestrictedLockUtilsInternal.getDeviceOwner(context));
                        pref.setDisabledByAdmin(
                                RestrictedLockUtilsInternal.getDeviceOwner(context));
                    } else {
                        pref.setDisabledByAdmin(null);
                    }
                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) {
                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
    public boolean onPreferenceClick(Preference pref) {
        if (pref == mMePreference) {