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

Commit 0c45c90a authored by wilsonshih's avatar wilsonshih
Browse files

Clean up StartingWindowRecord from record manager once it is removed.

The snapshot starting window can scheduled to be remove later while
calling removeIfPossible, but it should also clean up itself from the
record manager.

Bug: 299852784
Test: create several task snapshot window, check on the dumpheap to
verify them can be removed from record manager.

Change-Id: If704363bb24124b618e7fe8dfeb98bf2c8286058
parent 15e79656
Loading
Loading
Loading
Loading
+7 −5
Original line number Original line Diff line number Diff line
@@ -35,13 +35,14 @@ class SnapshotWindowCreator {
    void makeTaskSnapshotWindow(StartingWindowInfo startingWindowInfo, TaskSnapshot snapshot) {
    void makeTaskSnapshotWindow(StartingWindowInfo startingWindowInfo, TaskSnapshot snapshot) {
        final int taskId = startingWindowInfo.taskInfo.taskId;
        final int taskId = startingWindowInfo.taskInfo.taskId;
        // Remove any existing starting window for this task before adding.
        // Remove any existing starting window for this task before adding.
        mStartingWindowRecordManager.removeWindow(taskId, true);
        mStartingWindowRecordManager.removeWindow(taskId);
        final TaskSnapshotWindow surface = TaskSnapshotWindow.create(startingWindowInfo,
        final TaskSnapshotWindow surface = TaskSnapshotWindow.create(startingWindowInfo,
                startingWindowInfo.appToken, snapshot, mMainExecutor,
                startingWindowInfo.appToken, snapshot, mMainExecutor,
                () -> mStartingWindowRecordManager.removeWindow(taskId, true));
                () -> mStartingWindowRecordManager.removeWindow(taskId));
        if (surface != null) {
        if (surface != null) {
            final SnapshotWindowRecord tView = new SnapshotWindowRecord(surface,
            final SnapshotWindowRecord tView = new SnapshotWindowRecord(surface,
                    startingWindowInfo.taskInfo.topActivityType, mMainExecutor);
                    startingWindowInfo.taskInfo.topActivityType, mMainExecutor,
                    taskId, mStartingWindowRecordManager);
            mStartingWindowRecordManager.addRecord(taskId, tView);
            mStartingWindowRecordManager.addRecord(taskId, tView);
        }
        }
    }
    }
@@ -50,8 +51,9 @@ class SnapshotWindowCreator {
        private final TaskSnapshotWindow mTaskSnapshotWindow;
        private final TaskSnapshotWindow mTaskSnapshotWindow;


        SnapshotWindowRecord(TaskSnapshotWindow taskSnapshotWindow,
        SnapshotWindowRecord(TaskSnapshotWindow taskSnapshotWindow,
                int activityType, ShellExecutor removeExecutor) {
                int activityType, ShellExecutor removeExecutor, int id,
            super(activityType, removeExecutor);
                StartingSurfaceDrawer.StartingWindowRecordManager recordManager) {
            super(activityType, removeExecutor, id, recordManager);
            mTaskSnapshotWindow = taskSnapshotWindow;
            mTaskSnapshotWindow = taskSnapshotWindow;
            mBGColor = mTaskSnapshotWindow.getBackgroundColor();
            mBGColor = mTaskSnapshotWindow.getBackgroundColor();
        }
        }
+1 −1
Original line number Original line Diff line number Diff line
@@ -358,7 +358,7 @@ class SplashscreenWindowCreator extends AbsSplashWindowCreator {
            }
            }
        }
        }
        if (shouldSaveView) {
        if (shouldSaveView) {
            mStartingWindowRecordManager.removeWindow(taskId, true);
            mStartingWindowRecordManager.removeWindow(taskId);
            saveSplashScreenRecord(appToken, taskId, view, suggestType);
            saveSplashScreenRecord(appToken, taskId, view, suggestType);
        }
        }
        return shouldSaveView;
        return shouldSaveView;
+15 −5
Original line number Original line Diff line number Diff line
@@ -188,7 +188,7 @@ public class StartingSurfaceDrawer {
        final SnapshotRecord record = sRecord instanceof SnapshotRecord
        final SnapshotRecord record = sRecord instanceof SnapshotRecord
                ? (SnapshotRecord) sRecord : null;
                ? (SnapshotRecord) sRecord : null;
        if (record != null && record.hasImeSurface()) {
        if (record != null && record.hasImeSurface()) {
            records.removeWindow(taskId, true);
            records.removeWindow(taskId);
        }
        }
    }
    }


@@ -256,10 +256,15 @@ public class StartingSurfaceDrawer {


        @WindowConfiguration.ActivityType protected final int mActivityType;
        @WindowConfiguration.ActivityType protected final int mActivityType;
        protected final ShellExecutor mRemoveExecutor;
        protected final ShellExecutor mRemoveExecutor;
        private final int mTaskId;
        private final StartingWindowRecordManager mRecordManager;


        SnapshotRecord(int activityType, ShellExecutor removeExecutor) {
        SnapshotRecord(int activityType, ShellExecutor removeExecutor, int taskId,
                StartingWindowRecordManager recordManager) {
            mActivityType = activityType;
            mActivityType = activityType;
            mRemoveExecutor = removeExecutor;
            mRemoveExecutor = removeExecutor;
            mTaskId = taskId;
            mRecordManager = recordManager;
        }
        }


        @Override
        @Override
@@ -301,6 +306,7 @@ public class StartingSurfaceDrawer {
        @CallSuper
        @CallSuper
        protected void removeImmediately() {
        protected void removeImmediately() {
            mRemoveExecutor.removeCallbacks(mScheduledRunnable);
            mRemoveExecutor.removeCallbacks(mScheduledRunnable);
            mRecordManager.onRecordRemoved(mTaskId);
        }
        }
    }
    }


@@ -316,7 +322,7 @@ public class StartingSurfaceDrawer {
                taskIds[i] = mStartingWindowRecords.keyAt(i);
                taskIds[i] = mStartingWindowRecords.keyAt(i);
            }
            }
            for (int i = taskSize - 1; i >= 0; --i) {
            for (int i = taskSize - 1; i >= 0; --i) {
                removeWindow(taskIds[i], true);
                removeWindow(taskIds[i]);
            }
            }
        }
        }


@@ -335,9 +341,13 @@ public class StartingSurfaceDrawer {
            }
            }
        }
        }


        void removeWindow(int taskId, boolean immediately) {
        void removeWindow(int taskId) {
            mTmpRemovalInfo.taskId = taskId;
            mTmpRemovalInfo.taskId = taskId;
            removeWindow(mTmpRemovalInfo, immediately);
            removeWindow(mTmpRemovalInfo, true/* immediately */);
        }

        void onRecordRemoved(int taskId) {
            mStartingWindowRecords.remove(taskId);
        }
        }


        StartingWindowRecord getRecord(int taskId) {
        StartingWindowRecord getRecord(int taskId) {
+5 −3
Original line number Original line Diff line number Diff line
@@ -92,7 +92,8 @@ class WindowlessSnapshotWindowCreator {


        final SnapshotWindowRecord record = new SnapshotWindowRecord(mViewHost, wlw.mChildSurface,
        final SnapshotWindowRecord record = new SnapshotWindowRecord(mViewHost, wlw.mChildSurface,
                taskDescription.getBackgroundColor(), snapshot.hasImeSurface(),
                taskDescription.getBackgroundColor(), snapshot.hasImeSurface(),
                runningTaskInfo.topActivityType, removeExecutor);
                runningTaskInfo.topActivityType, removeExecutor,
                taskId, mStartingWindowRecordManager);
        mStartingWindowRecordManager.addRecord(taskId, record);
        mStartingWindowRecordManager.addRecord(taskId, record);
        info.notifyAddComplete(wlw.mChildSurface);
        info.notifyAddComplete(wlw.mChildSurface);
    }
    }
@@ -104,8 +105,9 @@ class WindowlessSnapshotWindowCreator {


        SnapshotWindowRecord(SurfaceControlViewHost viewHost, SurfaceControl childSurface,
        SnapshotWindowRecord(SurfaceControlViewHost viewHost, SurfaceControl childSurface,
                int bgColor, boolean hasImeSurface, int activityType,
                int bgColor, boolean hasImeSurface, int activityType,
                ShellExecutor removeExecutor) {
                ShellExecutor removeExecutor, int id,
            super(activityType, removeExecutor);
                StartingSurfaceDrawer.StartingWindowRecordManager recordManager) {
            super(activityType, removeExecutor, id, recordManager);
            mViewHost = viewHost;
            mViewHost = viewHost;
            mChildSurface = childSurface;
            mChildSurface = childSurface;
            mBGColor = bgColor;
            mBGColor = bgColor;