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

Commit 6143a02f authored by Kenny Guy's avatar Kenny Guy
Browse files

Start related users on boot and user switch.

Collect related initialized users and start
them on boot and user switch.
Update list users command to show whether a
user is running or not.

Change-Id: Ib3d5debcb01ec55a07d93450b988b0180fc63263
parent 48d04ec3
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.commands.pm;

import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.content.ComponentName;
import android.content.pm.ApplicationInfo;
import android.content.pm.ContainerEncryptionParams;
@@ -1089,13 +1090,16 @@ public final class Pm {

    public void runListUsers() {
        try {
            IActivityManager am = ActivityManagerNative.getDefault();

            List<UserInfo> users = mUm.getUsers(false);
            if (users == null) {
                System.err.println("Error: couldn't get users");
            } else {
                System.out.println("Users:");
                for (int i = 0; i < users.size(); i++) {
                    System.out.println("\t" + users.get(i).toString());
                    String running = am.isUserRunning(users.get(i).id, false) ? " running" : "";
                    System.out.println("\t" + users.get(i).toString() + running);
                }
            }
        } catch (RemoteException e) {
+42 −2
Original line number Diff line number Diff line
@@ -1073,6 +1073,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    static final int IMMERSIVE_MODE_LOCK_MSG = 37;
    static final int PERSIST_URI_GRANTS_MSG = 38;
    static final int REQUEST_ALL_PSS_MSG = 39;
    static final int START_RELATED_USERS_MSG = 40;
    static final int FIRST_ACTIVITY_STACK_MSG = 100;
    static final int FIRST_BROADCAST_QUEUE_MSG = 200;
@@ -1686,6 +1687,12 @@ public final class ActivityManagerService extends ActivityManagerNative
                requestPssAllProcsLocked(SystemClock.uptimeMillis(), true, false);
                break;
            }
            case START_RELATED_USERS_MSG: {
                synchronized (ActivityManagerService.this) {
                    startRelatedUsersLocked();
                }
                break;
            }
            }
        }
    };
@@ -5164,6 +5171,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                                userId);
                    }
                }
                scheduleStartRelatedUsersLocked();
            }
        }
    }
@@ -16105,6 +16113,8 @@ public final class ActivityManagerService extends ActivityManagerNative
            throw new SecurityException(msg);
        }
        if (DEBUG_MU) Slog.i(TAG_MU, "starting userid:" + userId + " fore:" + foreground);
        final long ident = Binder.clearCallingIdentity();
        try {
            synchronized (this) {
@@ -16365,6 +16375,32 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
    }
    void scheduleStartRelatedUsersLocked() {
        if (!mHandler.hasMessages(START_RELATED_USERS_MSG)) {
            mHandler.sendMessageDelayed(mHandler.obtainMessage(START_RELATED_USERS_MSG),
                    DateUtils.SECOND_IN_MILLIS);
        }
    }
    void startRelatedUsersLocked() {
        if (DEBUG_MU) Slog.i(TAG_MU, "startRelatedUsersLocked");
        List<UserInfo> relatedUsers = getUserManagerLocked().getRelatedUsers(mCurrentUserId);
        List<UserInfo> toStart = new ArrayList<UserInfo>(relatedUsers.size());
        for (UserInfo relatedUser : relatedUsers) {
            if ((relatedUser.flags & UserInfo.FLAG_INITIALIZED) == UserInfo.FLAG_INITIALIZED) {
                toStart.add(relatedUser);
            }
        }
        final int n = toStart.size();
        int i = 0;
        for (; i < n && i < (MAX_RUNNING_USERS - 1); ++i) {
            startUserInBackground(toStart.get(i).id);
        }
        if (i < n) {
            Slog.w(TAG_MU, "More related users than MAX_RUNNING_USERS");
        }
    }
    void finishUserSwitch(UserStartedState uss) {
        synchronized (this) {
            if (uss.mState == UserStartedState.STATE_BOOTING
@@ -16379,6 +16415,9 @@ public final class ActivityManagerService extends ActivityManagerNative
                        android.Manifest.permission.RECEIVE_BOOT_COMPLETED, AppOpsManager.OP_NONE,
                        true, false, MY_PID, Process.SYSTEM_UID, userId);
            }
            startRelatedUsersLocked();
            int num = mUserLru.size();
            int i = 0;
            while (num > MAX_RUNNING_USERS && i < mUserLru.size()) {
@@ -16430,6 +16469,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    }
    private int stopUserLocked(final int userId, final IStopUserCallback callback) {
        if (DEBUG_MU) Slog.i(TAG_MU, "stopUserLocked userId=" + userId);
        if (mCurrentUserId == userId) {
            return ActivityManager.USER_OP_IS_CURRENT;
        }