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

Commit b7804795 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Remove direct WM lock from WPC#onTopProcChanged

Currently it is only used for VR mode. If it is not enabled, nothing
needs to be done. And if the proc state is change while VR is enabled,
post a message to update the state to avoid nested lock.

Also a minor cleanup for non-null WindowProcessListener.

Bug: 159104503
Test: WindowProcessControllerTests
Change-Id: If30ab2336dfdb56e3871845d65fe298aa696633d
parent 8f7dd599
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ final class VrController {
    //      - Calls to setPersistentVrThread will fail.
    //      - No threads will have elevated scheduling priority for VR.
    //
    private int mVrState = FLAG_NON_VR_MODE;
    private volatile int mVrState = FLAG_NON_VR_MODE;

    // The single VR render thread on the device that is given elevated scheduling priority.
    private int mVrRenderThreadTid = 0;
@@ -145,6 +145,14 @@ final class VrController {
        }
    }

    /**
     * Called without lock to determine whether to call {@link #onTopProcChangedLocked} in lock. It
     * is used to optimize performance for the path that may have lock contention frequently.
     */
    boolean isInterestingToSchedGroup() {
        return (mVrState & (FLAG_VR_MODE | FLAG_PERSISTENT_VR_MODE)) != 0;
    }

    /**
     * Called when ActivityManagerService's TOP_APP process has changed.
     *
+11 −15
Original line number Diff line number Diff line
@@ -229,7 +229,8 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    private final OomScoreReferenceState mOomRefState;

    public WindowProcessController(@NonNull ActivityTaskManagerService atm, ApplicationInfo info,
            String name, int uid, int userId, Object owner, WindowProcessListener listener) {
            String name, int uid, int userId, Object owner,
            @NonNull WindowProcessListener listener) {
        mInfo = info;
        mName = name;
        mUid = uid;
@@ -390,7 +391,6 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    }

    void postPendingUiCleanMsg(boolean pendingUiClean) {
        if (mListener == null) return;
        // Posting on handler so WM lock isn't held when we call into AM.
        final Message m = PooledLambda.obtainMessage(
                WindowProcessListener::setPendingUiClean, mListener, pendingUiClean);
@@ -1150,7 +1150,6 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    }

    void clearProfilerIfNeeded() {
        if (mListener == null) return;
        // Posting on handler so WM lock isn't held when we call into AM.
        mAtm.mH.sendMessage(PooledLambda.obtainMessage(
                WindowProcessListener::clearProfilerIfNeeded, mListener));
@@ -1158,7 +1157,6 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio

    void updateProcessInfo(boolean updateServiceConnectionActivities, boolean activityChange,
            boolean updateOomAdj, boolean addPendingTopUid) {
        if (mListener == null) return;
        if (addPendingTopUid) {
            mAtm.mAmInternal.addPendingTopUid(mUid, mPid);
        }
@@ -1172,14 +1170,12 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    }

    void updateServiceConnectionActivities() {
        if (mListener == null) return;
        // Posting on handler so WM lock isn't held when we call into AM.
        mAtm.mH.sendMessage(PooledLambda.obtainMessage(
                WindowProcessListener::updateServiceConnectionActivities, mListener));
    }

    void setPendingUiCleanAndForceProcessStateUpTo(int newState) {
        if (mListener == null) return;
        // Posting on handler so WM lock isn't held when we call into AM.
        final Message m = PooledLambda.obtainMessage(
                WindowProcessListener::setPendingUiCleanAndForceProcessStateUpTo,
@@ -1188,7 +1184,7 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    }

    boolean isRemoved() {
        return mListener == null ? false : mListener.isRemoved();
        return mListener.isRemoved();
    }

    private boolean shouldSetProfileProc() {
@@ -1213,7 +1209,6 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    }

    void onStartActivity(int topProcessState, ActivityInfo info) {
        if (mListener == null) return;
        String packageName = null;
        if ((info.flags & ActivityInfo.FLAG_MULTIPROCESS) == 0
                || !"android".equals(info.packageName)) {
@@ -1237,7 +1232,6 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    }

    void appDied(String reason) {
        if (mListener == null) return;
        // Posting on handler so WM lock isn't held when we call into AM.
        final Message m = PooledLambda.obtainMessage(
                WindowProcessListener::appDied, mListener, reason);
@@ -1478,7 +1472,7 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio

    /** Returns the total time (in milliseconds) spent executing in both user and system code. */
    public long getCpuTime() {
        return (mListener != null) ? mListener.getCpuTime() : 0;
        return mListener.getCpuTime();
    }

    void addRecentTask(Task task) {
@@ -1606,9 +1600,13 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio

    @HotPath(caller = HotPath.OOM_ADJUSTMENT)
    public void onTopProcChanged() {
        synchronized (mAtm.mGlobalLockWithoutBoost) {
        if (mAtm.mVrController.isInterestingToSchedGroup()) {
            mAtm.mH.post(() -> {
                synchronized (mAtm.mGlobalLock) {
                    mAtm.mVrController.onTopProcChangedLocked(this);
                }
            });
        }
    }

    @HotPath(caller = HotPath.OOM_ADJUSTMENT)
@@ -1692,8 +1690,6 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
    }

    void dumpDebug(ProtoOutputStream proto, long fieldId) {
        if (mListener != null) {
        mListener.dumpDebug(proto, fieldId);
    }
}
}