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

Commit edcfc187 authored by Suprabh Shukla's avatar Suprabh Shukla Committed by Android (Google) Code Review
Browse files

Merge "Changing the message on user switching dialog."

parents df94885e 4fe508b6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -3623,6 +3623,8 @@
    <string name="user_switched">Current user <xliff:g id="name" example="Bob">%1$s</xliff:g>.</string>
    <!-- Message shown when switching to a user [CHAR LIMIT=none] -->
    <string name="user_switching_message">Switching to <xliff:g id="name" example="Bob">%1$s</xliff:g>\u2026</string>
    <!-- Message when logging out a user on a split user system -->
    <string name="user_logging_out_message">Logging out <xliff:g id="name" example="Bob">%1$s</xliff:g>\u2026</string>
    <!-- Default name of the owner user [CHAR LIMIT=20] -->
    <string name="owner_name" msgid="3879126011135546571">Owner</string>
    <!-- Error message title [CHAR LIMIT=35] -->
+1 −0
Original line number Diff line number Diff line
@@ -932,6 +932,7 @@
  <java-symbol type="string" name="upload_file" />
  <java-symbol type="string" name="user_switched" />
  <java-symbol type="string" name="user_switching_message" />
  <java-symbol type="string" name="user_logging_out_message" />
  <java-symbol type="string" name="volume_alarm" />
  <java-symbol type="string" name="volume_icon_description_bluetooth" />
  <java-symbol type="string" name="volume_icon_description_incall" />
+15 −13
Original line number Diff line number Diff line
@@ -1646,7 +1646,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                break;
            }
            case START_USER_SWITCH_UI_MSG: {
                mUserController.showUserSwitchDialog(msg.arg1, (String) msg.obj);
                mUserController.showUserSwitchDialog((Pair<UserInfo, UserInfo>) msg.obj);
                break;
            }
            case DISMISS_DIALOG_UI_MSG: {
@@ -20251,25 +20251,27 @@ public final class ActivityManagerService extends ActivityManagerNative
    }
    @Override
    public boolean switchUser(final int userId) {
        enforceShellRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES, userId);
        String userName;
        synchronized (this) {
            UserInfo userInfo = mUserController.getUserInfo(userId);
            if (userInfo == null) {
                Slog.w(TAG, "No user info for user #" + userId);
    public boolean switchUser(final int targetUserId) {
        enforceShellRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES, targetUserId);
        UserInfo currentUserInfo;
        UserInfo targetUserInfo;
        synchronized (this) {
            int currentUserId = mUserController.getCurrentUserIdLocked();
            currentUserInfo = mUserController.getUserInfo(currentUserId);
            targetUserInfo = mUserController.getUserInfo(targetUserId);
            if (targetUserInfo == null) {
                Slog.w(TAG, "No user info for user #" + targetUserId);
                return false;
            }
            if (userInfo.isManagedProfile()) {
                Slog.w(TAG, "Cannot switch to User #" + userId + ": not a full user");
            if (targetUserInfo.isManagedProfile()) {
                Slog.w(TAG, "Cannot switch to User #" + targetUserId + ": not a full user");
                return false;
            }
            userName = userInfo.name;
            mUserController.setTargetUserIdLocked(userId);
            mUserController.setTargetUserIdLocked(targetUserId);
        }
        Pair<UserInfo, UserInfo> userNames = new Pair<>(currentUserInfo, targetUserInfo);
        mUiHandler.removeMessages(START_USER_SWITCH_UI_MSG);
        mUiHandler.sendMessage(mUiHandler.obtainMessage(START_USER_SWITCH_UI_MSG, userId, 0,
                userName));
        mUiHandler.sendMessage(mUiHandler.obtainMessage(START_USER_SWITCH_UI_MSG, userNames));
        return true;
    }
+4 −3
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.IMountService;
import android.os.storage.StorageManager;
import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseIntArray;
@@ -641,10 +642,10 @@ final class UserController {
        return true;
    }

    void showUserSwitchDialog(int userId, String userName) {
    void showUserSwitchDialog(Pair<UserInfo, UserInfo> fromToUserPair) {
        // The dialog will show and then initiate the user switch by calling startUserInForeground
        Dialog d = new UserSwitchingDialog(mService, mService.mContext, userId, userName,
                true /* above system */);
        Dialog d = new UserSwitchingDialog(mService, mService.mContext, fromToUserPair.first,
                fromToUserPair.second, true /* above system */);
        d.show();
    }

+14 −5
Original line number Diff line number Diff line
@@ -18,9 +18,12 @@ package com.android.server.am;

import android.app.AlertDialog;
import android.content.Context;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.os.Handler;
import android.os.Message;
import android.os.UserHandle;
import android.os.UserManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewTreeObserver;
@@ -49,20 +52,26 @@ final class UserSwitchingDialog extends AlertDialog
    @GuardedBy("this")
    private boolean mStartedUser;

    public UserSwitchingDialog(ActivityManagerService service, Context context,
            int userId, String userName, boolean aboveSystem) {
    public UserSwitchingDialog(ActivityManagerService service, Context context, UserInfo oldUser,
            UserInfo newUser, boolean aboveSystem) {
        super(context);

        mService = service;
        mUserId = userId;
        mUserId = newUser.id;

        // Set up the dialog contents
        setCancelable(false);
        Resources res = getContext().getResources();
        // Custom view due to alignment and font size requirements
        View view = LayoutInflater.from(getContext()).inflate(R.layout.user_switching_dialog, null);
        ((TextView) view.findViewById(R.id.message)).setText(
                res.getString(com.android.internal.R.string.user_switching_message, userName));

        String viewMessage;
        if (UserManager.isSplitSystemUser() && newUser.id == UserHandle.USER_SYSTEM) {
            viewMessage = res.getString(R.string.user_logging_out_message, oldUser.name);
        } else {
            viewMessage = res.getString(R.string.user_switching_message, newUser.name);
        }
        ((TextView) view.findViewById(R.id.message)).setText(viewMessage);
        setView(view);

        if (aboveSystem) {