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

Commit 52f1d752 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Show the current user in power menu

Shows a little indicator next to the current user in the power menu
when multi-user is enabled.

Fixed a bug where Settings was sometimes being launched in the wrong
process when there are 2 instances running.

Change-Id: Iaf2a00f6d1871fd2a88d8982439e445423bb2896
parent 59075643
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.IntentSender;
import android.content.pm.ApplicationInfo;
import android.content.pm.ConfigurationInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.UserInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.Uri;
@@ -1495,6 +1496,14 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            return true;
        }

        case GET_CURRENT_USER_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            UserInfo userInfo = getCurrentUser();
            reply.writeNoException();
            userInfo.writeToParcel(reply, 0);
            return true;
        }

        case REMOVE_SUB_TASK_TRANSACTION:
        {
            data.enforceInterface(IActivityManager.descriptor);
@@ -3531,6 +3540,18 @@ class ActivityManagerProxy implements IActivityManager
        return result;
    }

    public UserInfo getCurrentUser() throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        mRemote.transact(SWITCH_USER_TRANSACTION, data, reply, 0);
        reply.readException();
        UserInfo userInfo = UserInfo.CREATOR.createFromParcel(reply);
        reply.recycle();
        data.recycle();
        return userInfo;
    }

    public boolean removeSubTask(int taskId, int subTaskIndex) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
+5 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.ConfigurationInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.ProviderInfo;
import android.content.pm.UserInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.Uri;
@@ -321,6 +322,7 @@ public interface IActivityManager extends IInterface {

    // Multi-user APIs
    public boolean switchUser(int userid) throws RemoteException;
    public UserInfo getCurrentUser() throws RemoteException;

    public boolean removeSubTask(int taskId, int subTaskIndex) throws RemoteException;

@@ -575,4 +577,5 @@ public interface IActivityManager extends IInterface {
    int REMOVE_CONTENT_PROVIDER_EXTERNAL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+141;
    int GET_MY_MEMORY_STATE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+142;
    int KILL_PROCESSES_BELOW_FOREGROUND_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+143;
    int GET_CURRENT_USER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+144;
}
+10 −1
Original line number Diff line number Diff line
@@ -200,10 +200,19 @@ class GlobalActions implements DialogInterface.OnDismissListener, DialogInterfac

        List<UserInfo> users = mContext.getPackageManager().getUsers();
        if (users.size() > 1) {
            UserInfo currentUser;
            try {
                currentUser = ActivityManagerNative.getDefault().getCurrentUser();
            } catch (RemoteException re) {
                currentUser = null;
            }
            for (final UserInfo user : users) {
                boolean isCurrentUser = currentUser == null
                        ? user.id == 0 : (currentUser.id == user.id);
                SinglePressAction switchToUser = new SinglePressAction(
                        com.android.internal.R.drawable.ic_menu_cc,
                        user.name != null ? user.name : "Primary") {
                        (user.name != null ? user.name : "Primary")
                        + (isCurrentUser ? " \u2714" : "")) {
                    public void onPress() {
                        try {
                            ActivityManagerNative.getDefault().switchUser(user.id);
+19 −6
Original line number Diff line number Diff line
@@ -1795,12 +1795,15 @@ public final class ActivityManagerService extends ActivityManagerNative
    final ProcessRecord getProcessRecordLocked(
            String processName, int uid) {
        if (uid == Process.SYSTEM_UID) {
            // The system gets to run in any process.  If there are multiple
            // processes with the same uid, just pick the first (this
            // should never happen).
            SparseArray<ProcessRecord> procs = mProcessNames.getMap().get(
                    processName);
            return procs != null ? procs.valueAt(0) : null;
            SparseArray<ProcessRecord> procs = mProcessNames.getMap().get(processName);
            if (procs == null) return null;
            int N = procs.size();
            for (int i = 0; i < N; i++) {
                if (UserId.isSameUser(procs.keyAt(i), uid)) {
                    return procs.valueAt(i);
                }
            }
            return null;
        }
        // uid = applyUserId(uid);
        ProcessRecord proc = mProcessNames.get(processName, uid);
@@ -14645,6 +14648,16 @@ public final class ActivityManagerService extends ActivityManagerNative
        return true;
    }
    @Override
    public UserInfo getCurrentUser() throws RemoteException {
        final int callingUid = Binder.getCallingUid();
        if (callingUid != 0 && callingUid != Process.myUid()) {
            Slog.e(TAG, "Trying to get user from unauthorized app");
            return null;
        }
        return AppGlobals.getPackageManager().getUser(mCurrentUserId);
    }
    private void onUserRemoved(Intent intent) {
        int extraUserId = intent.getIntExtra(Intent.EXTRA_USERID, -1);
        if (extraUserId < 1) return;