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

Commit f391fc16 authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Do not use wm lock in TaskChangeNotificationController"

parents 4edb231b e5700ffc
Loading
Loading
Loading
Loading
+12 −15
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@ import static android.app.WaitResult.LAUNCH_STATE_WARM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY;
import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_SECONDARY;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
@@ -448,33 +447,31 @@ class ActivityMetricsLogger {
        mLaunchObserver = new LaunchObserverRegistryImpl(looper);
    }

    private void logWindowState(String state, int durationSecs) {
        mMetricsLogger.count(state, durationSecs);
    }

    void logWindowState() {
        final long now = SystemClock.elapsedRealtime() / 1000;
        if (mWindowState != WINDOW_STATE_INVALID) {
            // We log even if the window state hasn't changed, because the user might remain in
            // home/fullscreen move forever and we would like to track this kind of behavior
            // too.
            mMetricsLogger.count(TRON_WINDOW_STATE_VARZ_STRINGS[mWindowState],
                    (int) (now - mLastLogTimeSecs));
            mLoggerHandler.sendMessage(PooledLambda.obtainMessage(
                    ActivityMetricsLogger::logWindowState, this,
                    TRON_WINDOW_STATE_VARZ_STRINGS[mWindowState], (int) (now - mLastLogTimeSecs)));
        }
        mLastLogTimeSecs = now;

        mWindowState = WINDOW_STATE_INVALID;
        Task rootTask = mSupervisor.mRootWindowContainer.getTopDisplayFocusedRootTask();
        if (rootTask == null) {
            return;
        }

        if (rootTask.isActivityTypeAssistant()) {
        final Task focusedTask = mSupervisor.mRootWindowContainer.getTopDisplayFocusedRootTask();
        if (focusedTask == null)  return;
        if (focusedTask.isActivityTypeAssistant()) {
            mWindowState = WINDOW_STATE_ASSISTANT;
            return;
        }

        @WindowingMode int windowingMode = rootTask.getWindowingMode();
        if (windowingMode == WINDOWING_MODE_PINNED) {
            rootTask = mSupervisor.mRootWindowContainer.findRootTaskBehind(rootTask);
            windowingMode = rootTask.getWindowingMode();
        }
        @WindowingMode final int windowingMode = focusedTask.getWindowingMode();
        switch (windowingMode) {
            case WINDOWING_MODE_FULLSCREEN:
                mWindowState = WINDOW_STATE_STANDARD;
@@ -491,7 +488,7 @@ class ActivityMetricsLogger {
                break;
            default:
                if (windowingMode != WINDOWING_MODE_UNDEFINED) {
                    throw new IllegalStateException("Unknown windowing mode for task=" + rootTask
                    Slog.wtf(TAG, "Unknown windowing mode for task=" + focusedTask
                            + " windowingMode=" + windowingMode);
                }
        }
+1 −1
Original line number Diff line number Diff line
@@ -956,7 +956,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
        mActivityClientController = new ActivityClientController(this);

        mTaskChangeNotificationController =
                new TaskChangeNotificationController(mGlobalLock, mTaskSupervisor, mH);
                new TaskChangeNotificationController(mTaskSupervisor, mH);
        mLockTaskController = new LockTaskController(mContext, mTaskSupervisor, mH,
                mTaskChangeNotificationController);
        mActivityStartController = new ActivityStartController(this);
+0 −4
Original line number Diff line number Diff line
@@ -2206,10 +2206,6 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
                task.mTaskId, reason, topActivity.info.applicationInfo.packageName);
    }

    void logRootTaskState() {
        mActivityMetricsLogger.logWindowState();
    }

    void scheduleUpdateMultiWindowMode(Task task) {
        final PooledConsumer c = PooledLambda.obtainConsumer(
                ActivityTaskSupervisor::addToMultiWindowModeChangedList, this,
+0 −20
Original line number Diff line number Diff line
@@ -2583,26 +2583,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        mDisplayManagerInternal.setDisplayAccessUIDs(mDisplayAccessUIDs);
    }

    Task findRootTaskBehind(Task rootTask) {
        final TaskDisplayArea taskDisplayArea = rootTask.getDisplayArea();
        if (taskDisplayArea != null) {
            final boolean[] hasFound = new boolean[1];
            // TODO(b/175136051): should this be only the direct child root task?
            final Task rootTaskBehind = taskDisplayArea.getRootTask(task -> {
                if (hasFound[0]) {
                    return true;
                }
                hasFound[0] = task == rootTask;
                return false;
            });
            if (rootTaskBehind != null) {
                return rootTaskBehind;
            }
        }
        throw new IllegalStateException("Failed to find a root task behind root task =" + rootTask
                + " in=" + taskDisplayArea);
    }

    Configuration getDisplayOverrideConfiguration(int displayId) {
        final DisplayContent displayContent = getDisplayContentOrCreate(displayId);
        if (displayContent == null) {
+22 −30
Original line number Diff line number Diff line
@@ -29,12 +29,12 @@ import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.window.TaskSnapshot;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.SomeArgs;

import java.util.ArrayList;

class TaskChangeNotificationController {
    private static final int LOG_TASK_STATE_MSG = 1;
    private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG = 2;
    private static final int NOTIFY_ACTIVITY_PINNED_LISTENERS_MSG = 3;
    private static final int NOTIFY_ACTIVITY_RESTART_ATTEMPT_LISTENERS_MSG = 4;
@@ -64,12 +64,11 @@ class TaskChangeNotificationController {
    // Delay in notifying task stack change listeners (in millis)
    private static final int NOTIFY_TASK_STACK_CHANGE_LISTENERS_DELAY = 100;

    // Global lock used by the service the instantiate objects of this class.
    private final Object mServiceLock;
    private final ActivityTaskSupervisor mTaskSupervisor;
    private final Handler mHandler;

    // Task stack change listeners in a remote process.
    @GuardedBy("mRemoteTaskStackListeners")
    private final RemoteCallbackList<ITaskStackListener> mRemoteTaskStackListeners =
            new RemoteCallbackList<>();

@@ -77,6 +76,7 @@ class TaskChangeNotificationController {
     * Task stack change listeners in a local process. Tracked separately so that they can be
     * called on the same thread.
     */
    @GuardedBy("mLocalTaskStackListeners")
    private final ArrayList<ITaskStackListener> mLocalTaskStackListeners = new ArrayList<>();

    private final TaskStackConsumer mNotifyTaskStackChanged = (l, m) -> {
@@ -195,12 +195,6 @@ class TaskChangeNotificationController {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case LOG_TASK_STATE_MSG: {
                    synchronized (mServiceLock) {
                        mTaskSupervisor.logRootTaskState();
                    }
                    break;
                }
                case NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG:
                    forAllRemoteListeners(mNotifyTaskStackChanged, msg);
                    break;
@@ -283,41 +277,39 @@ class TaskChangeNotificationController {
        }
    }

    public TaskChangeNotificationController(Object serviceLock,
            ActivityTaskSupervisor taskSupervisor, Handler handler) {
        mServiceLock = serviceLock;
    TaskChangeNotificationController(ActivityTaskSupervisor taskSupervisor, Handler handler) {
        mTaskSupervisor = taskSupervisor;
        mHandler = new MainHandler(handler.getLooper());
    }

    public void registerTaskStackListener(ITaskStackListener listener) {
        synchronized (mServiceLock) {
            if (listener != null) {
                if (Binder.getCallingPid() == android.os.Process.myPid()) {
        if (listener instanceof Binder) {
            synchronized (mLocalTaskStackListeners) {
                if (!mLocalTaskStackListeners.contains(listener)) {
                    mLocalTaskStackListeners.add(listener);
                }
                } else {
                    mRemoteTaskStackListeners.register(listener);
            }
        } else if (listener != null) {
            synchronized (mRemoteTaskStackListeners) {
                mRemoteTaskStackListeners.register(listener);
            }
        }
    }

    public void unregisterTaskStackListener(ITaskStackListener listener) {
        synchronized (mServiceLock) {
            if (listener != null) {
                if (Binder.getCallingPid() == android.os.Process.myPid()) {
        if (listener instanceof Binder) {
            synchronized (mLocalTaskStackListeners) {
                mLocalTaskStackListeners.remove(listener);
                } else {
                    mRemoteTaskStackListeners.unregister(listener);
            }
        } else if (listener != null) {
            synchronized (mRemoteTaskStackListeners) {
                mRemoteTaskStackListeners.unregister(listener);
            }
        }
    }

    private void forAllRemoteListeners(TaskStackConsumer callback, Message message) {
        synchronized (mServiceLock) {
        synchronized (mRemoteTaskStackListeners) {
            for (int i = mRemoteTaskStackListeners.beginBroadcast() - 1; i >= 0; i--) {
                try {
                    // Make a one-way callback to the listener
@@ -331,7 +323,7 @@ class TaskChangeNotificationController {
    }

    private void forAllLocalListeners(TaskStackConsumer callback, Message message) {
        synchronized (mServiceLock) {
        synchronized (mLocalTaskStackListeners) {
            for (int i = mLocalTaskStackListeners.size() - 1; i >= 0; i--) {
                try {
                    callback.accept(mLocalTaskStackListeners.get(i), message);
@@ -344,7 +336,7 @@ class TaskChangeNotificationController {

    /** Notifies all listeners when the task stack has changed. */
    void notifyTaskStackChanged() {
        mHandler.sendEmptyMessage(LOG_TASK_STATE_MSG);
        mTaskSupervisor.getActivityMetricsLogger().logWindowState();
        mHandler.removeMessages(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
        final Message msg = mHandler.obtainMessage(NOTIFY_TASK_STACK_CHANGE_LISTENERS_MSG);
        forAllLocalListeners(mNotifyTaskStackChanged, msg);