Merge "Don't always change username when adding account" into sc-dev am: 5e98a92fe8
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/14056085 Change-Id: I5f9f5c16d688e25a8f0072164a69e5153b39d3c4
This commit is contained in:
@@ -50,14 +50,23 @@ public class ProfileUpdateReceiver extends BroadcastReceiver {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int userId = UserHandle.myUserId();
|
final int userId = UserHandle.myUserId();
|
||||||
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
final UserManager um = context.getSystemService(UserManager.class);
|
||||||
String profileName = Utils.getMeProfileName(context, false /* partial name */);
|
final String newName = Utils.getMeProfileName(context, false /* partial name */);
|
||||||
if (profileName != null && profileName.length() > 0) {
|
if (newName != null && newName.length() > 0 && !isCurrentNameInteresting(context, um)) {
|
||||||
um.setUserName(userId, profileName);
|
um.setUserName(userId, newName);
|
||||||
// Flag that we've written the profile one time at least. No need to do it in the
|
// Flag that we've written the profile one time at least. No need to do it in the
|
||||||
// future.
|
// future.
|
||||||
prefs.edit().putBoolean(KEY_PROFILE_NAME_COPIED_ONCE, true).commit();
|
prefs.edit().putBoolean(KEY_PROFILE_NAME_COPIED_ONCE, true).commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns whether the current user name is different from the default one. */
|
||||||
|
private static boolean isCurrentNameInteresting(Context context, UserManager um) {
|
||||||
|
final String currentName = um.getUserName();
|
||||||
|
final String defaultName = um.isRestrictedProfile() || um.isProfile() ?
|
||||||
|
context.getString(com.android.settingslib.R.string.user_new_profile_name) :
|
||||||
|
context.getString(com.android.settingslib.R.string.user_new_user_name);
|
||||||
|
return currentName != null && !currentName.equals(defaultName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user