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

Commit 08488bf3 authored by Kenny Guy's avatar Kenny Guy
Browse files

Allow user to be started in background.

Change-Id: I2adeb258cd33765a559c1f952c47088abbc4336c
parent 2c965bc5
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -1713,6 +1713,15 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            return true;
        }

        case START_USER_IN_BACKGROUND_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            int userid = data.readInt();
            boolean result = startUserInBackground(userid);
            reply.writeNoException();
            reply.writeInt(result ? 1 : 0);
            return true;
        }

        case STOP_USER_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            int userid = data.readInt();
@@ -4304,6 +4313,19 @@ class ActivityManagerProxy implements IActivityManager
        return result;
    }

    public boolean startUserInBackground(int userid) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeInt(userid);
        mRemote.transact(START_USER_IN_BACKGROUND_TRANSACTION, data, reply, 0);
        reply.readException();
        boolean result = reply.readInt() != 0;
        reply.recycle();
        data.recycle();
        return result;
    }

    public int stopUser(int userid, IStopUserCallback callback) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
+2 −0
Original line number Diff line number Diff line
@@ -349,6 +349,7 @@ public interface IActivityManager extends IInterface {

    // Multi-user APIs
    public boolean switchUser(int userid) throws RemoteException;
    public boolean startUserInBackground(int userid) throws RemoteException;
    public int stopUser(int userid, IStopUserCallback callback) throws RemoteException;
    public UserInfo getCurrentUser() throws RemoteException;
    public boolean isUserRunning(int userid, boolean orStopping) throws RemoteException;
@@ -715,4 +716,5 @@ public interface IActivityManager extends IInterface {

    // Start of L transactions
    int GET_TAG_FOR_INTENT_SENDER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+210;
    int START_USER_IN_BACKGROUND_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+211;
}
+39 −16
Original line number Diff line number Diff line
@@ -16081,8 +16081,20 @@ public final class ActivityManagerService extends ActivityManagerNative
    // Multi-user methods
    /**
     * Start user, if its not already running, but don't bring it to foreground.
     */
    @Override
    public boolean startUserInBackground(final int userId) {
        return startUser(userId, /* foreground */ false);
    }
    @Override
    public boolean switchUser(final int userId) {
        return startUser(userId, /* foregound */ true);
    }
    private boolean startUser(final int userId, boolean foreground) {
        if (checkCallingPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
                != PackageManager.PERMISSION_GRANTED) {
            String msg = "Permission Denial: switchUser() from pid="
@@ -16120,12 +16132,18 @@ public final class ActivityManagerService extends ActivityManagerNative
                    needStart = true;
                }
                mCurrentUserId = userId;
                final Integer userIdInt = Integer.valueOf(userId);
                mUserLru.remove(userIdInt);
                mUserLru.add(userIdInt);
                if (foreground) {
                    mCurrentUserId = userId;
                    mWindowManager.setCurrentUser(userId);
                } else {
                    final Integer currentUserIdInt = Integer.valueOf(mCurrentUserId);
                    mUserLru.remove(currentUserIdInt);
                    mUserLru.add(currentUserIdInt);
                }
                // Once the internal notion of the active user has switched, we lock the device
                // with the option to show the user switcher on the keyguard.
@@ -16150,12 +16168,15 @@ public final class ActivityManagerService extends ActivityManagerNative
                    needStart = true;
                }
                if (foreground) {
                    mHandler.removeMessages(REPORT_USER_SWITCH_MSG);
                    mHandler.removeMessages(USER_SWITCH_TIMEOUT_MSG);
                    mHandler.sendMessage(mHandler.obtainMessage(REPORT_USER_SWITCH_MSG,
                            oldUserId, userId, uss));
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(USER_SWITCH_TIMEOUT_MSG,
                            oldUserId, userId, uss), USER_SWITCH_TIMEOUT);
                }
                if (needStart) {
                    Intent intent = new Intent(Intent.ACTION_USER_STARTED);
                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
@@ -16186,16 +16207,18 @@ public final class ActivityManagerService extends ActivityManagerNative
                    }
                }
                if (foreground) {
                    boolean homeInFront = mStackSupervisor.switchUserLocked(userId, uss);
                    if (homeInFront) {
                        startHomeActivityLocked(userId);
                    } else {
                        mStackSupervisor.resumeTopActivitiesLocked();
                    }
                    EventLogTags.writeAmSwitchUser(userId);
                    getUserManagerLocked().userForeground(userId);
                    sendUserSwitchBroadcastsLocked(oldUserId, userId);
                }
                if (needStart) {
                    Intent intent = new Intent(Intent.ACTION_USER_STARTING);
                    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);