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

Commit 86b7446c authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Break direct calls to UserController object in AMS from activity classes (12/n)

Make calls from activity classes go through ActivityManagerInternal
interface to case UserController instead of calling AMS.mUserController
object directly. Note that calls to UserController should not hold the
AMS lock.

Bug: 80414790
Test: Existing tests pass
Change-Id: Ie56f08d10b62d609e9b5e31f45b5f0d6eed3a9d4
parent 9333840e
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.ComponentName;
import android.content.IIntentSender;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.UserInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.IBinder;
@@ -216,4 +217,16 @@ public abstract class ActivityManagerInternal {

    public abstract void updateOomAdj();
    public abstract void sendForegroundProfileChanged(int userId);

    /**
     * Returns whether the given user requires credential entry at this time. This is used to
     * intercept activity launches for work apps when the Work Challenge is present.
     */
    public abstract boolean shouldConfirmCredentials(int userId);
    public abstract int[] getCurrentProfileIds();
    public abstract UserInfo getCurrentUser();
    public abstract void ensureNotSpecialUser(int userId);
    public abstract boolean isCurrentProfile(int userId);
    public abstract boolean hasStartedUserState(int userId);
    public abstract void finishUserSwitch(Object uss);
}
+37 −3
Original line number Diff line number Diff line
@@ -22319,10 +22319,9 @@ public class ActivityManagerService extends IActivityManager.Stub
        @Override
        public boolean isUserRunning(int userId, int flags) {
            synchronized (ActivityManagerService.this) {
            // Holding am lock isn't required to call into user controller.
            return mUserController.isUserRunning(userId, flags);
        }
        }
        @Override
        public void trimApplications() {
@@ -22392,6 +22391,41 @@ public class ActivityManagerService extends IActivityManager.Stub
        public void sendForegroundProfileChanged(int userId) {
            mUserController.sendForegroundProfileChanged(userId);
        }
        @Override
        public boolean shouldConfirmCredentials(int userId) {
            return mUserController.shouldConfirmCredentials(userId);
        }
        @Override
        public int[] getCurrentProfileIds() {
            return mUserController.getCurrentProfileIds();
        }
        @Override
        public UserInfo getCurrentUser() {
            return mUserController.getCurrentUser();
        }
        @Override
        public void ensureNotSpecialUser(int userId) {
            mUserController.ensureNotSpecialUser(userId);
        }
        @Override
        public boolean isCurrentProfile(int userId) {
            return mUserController.isCurrentProfile(userId);
        }
        @Override
        public boolean hasStartedUserState(int userId) {
            return mUserController.hasStartedUserState(userId);
        }
        @Override
        public void finishUserSwitch(Object uss) {
            mUserController.finishUserSwitch((UserState) uss);
        }
    }
    /**
+2 −2
Original line number Diff line number Diff line
@@ -1877,7 +1877,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo
        // TODO: To be more accurate, the mark should be before the onCreate,
        //       not after the onResume. But for subsequent starts, onResume is fine.
        if (hasProcess()) {
            cpuTimeAtResume = service.mAm.mProcessCpuTracker.getCpuTimeForPid(app.getPid());
            cpuTimeAtResume = app.getCpuTime();
        } else {
            cpuTimeAtResume = 0; // Couldn't get the cpu time of process
        }
@@ -2186,7 +2186,7 @@ final class ActivityRecord extends ConfigurationContainer implements AppWindowCo

        return (info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0
                || (mStackSupervisor.isCurrentProfileLocked(userId)
                && service.mAm.mUserController.isUserRunning(userId, 0 /* flags */));
                && service.mAmInternal.isUserRunning(userId, 0 /* flags */));
    }

    /**
+3 −4
Original line number Diff line number Diff line
@@ -457,7 +457,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        mHandler = new ActivityStackHandler(supervisor.mLooper);
        mWindowManager = mService.mWindowManager;
        mStackId = stackId;
        mCurrentUser = mService.mAm.mUserController.getCurrentUserId();
        mCurrentUser = mService.mAmInternal.getCurrentUserId();
        mTmpRect2.setEmpty();
        // Set display id before setting activity and window type to make sure it won't affect
        // stacks on a wrong display.
@@ -1622,8 +1622,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai

            if (prev.hasProcess() && prev.cpuTimeAtResume > 0
                    && mService.mAm.mBatteryStatsService.isOnBattery()) {
                long diff = mService.mAm.mProcessCpuTracker.getCpuTimeForPid(prev.app.getPid())
                        - prev.cpuTimeAtResume;
                long diff = prev.app.getCpuTime() - prev.cpuTimeAtResume;
                if (diff > 0) {
                    BatteryStatsImpl bsi = mService.mAm.mBatteryStatsService.getActiveStatistics();
                    synchronized (bsi) {
@@ -2398,7 +2397,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        // Make sure that the user who owns this activity is started.  If not,
        // we will just leave it as is because someone should be bringing
        // another user's activities to the top of the stack.
        if (!mService.mAm.mUserController.hasStartedUserState(next.userId)) {
        if (!mService.mAmInternal.hasStartedUserState(next.userId)) {
            Slog.w(TAG, "Skipping resume of top activity " + next
                    + ": user " + next.userId + " is stopped");
            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
+4 −4
Original line number Diff line number Diff line
@@ -2112,12 +2112,12 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
            // Complete user switch
            if (startingUsers != null) {
                for (int i = 0; i < startingUsers.size(); i++) {
                    mService.mAm.mUserController.finishUserSwitch(startingUsers.get(i));
                    mService.mAmInternal.finishUserSwitch(startingUsers.get(i));
                }
            }
        }

        mService.mAm.trimApplications();
        mService.mAmInternal.trimApplications();
        //dump();
        //mWindowManager.dump();

@@ -3837,7 +3837,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
    /** Checks whether the userid is a profile of the current user. */
    boolean isCurrentProfileLocked(int userId) {
        if (userId == mCurrentUser) return true;
        return mService.mAm.mUserController.isCurrentProfile(userId);
        return mService.mAmInternal.isCurrentProfile(userId);
    }

    /**
@@ -4789,7 +4789,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D

            // If the user must confirm credentials (e.g. when first launching a work app and the
            // Work Challenge is present) let startActivityInPackage handle the intercepting.
            if (!mService.mAm.mUserController.shouldConfirmCredentials(task.userId)
            if (!mService.mAmInternal.shouldConfirmCredentials(task.userId)
                    && task.getRootActivity() != null) {
                final ActivityRecord targetActivity = task.getTopActivity();

Loading