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

Commit 9a8fc252 authored by wilsonshih's avatar wilsonshih
Browse files

Support to record multiple activities in the same task as one snapshot.

So the snapshot can be easier to be used with current SnapshotDrawer,
also the overall structure would be much similar with associated task
starting window.

- Record a single activity snapshot while multiple activities in the
  same leaf task are closing together, this can be extention if mulitple
  adjacent will happen.
- Share the snapshot from activities: because the key of cache must be
  an activity, so each activity can be the key to find this snapshot
  from cache, but the activities must be exactly match when calling
  getSnapshot.
- Remove the snapshot if one of activity removed, usually the
  configuration of rest activities will be changed, so doesn't need to
  keep the snapshot.

Bug: 259497289
Bug: 274997067
Test: atest ActivitySnapshotControllerTests
Test: test on sample app, monitor the snapshot of adjacent activities
should work like single activity snapshot.

Change-Id: I357010ab79eda165564e36fe7203fc508dbc357b
parent 3fca7acc
Loading
Loading
Loading
Loading
+24 −13
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.wm;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_DREAM;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_DREAM;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;

import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
@@ -180,17 +181,9 @@ abstract class AbsAppSnapshotController<TYPE extends WindowContainer,
        if (snapshot == null) {
        if (snapshot == null) {
            return null;
            return null;
        }
        }
        final HardwareBuffer buffer = snapshot.getHardwareBuffer();
        if (buffer.getWidth() == 0 || buffer.getHeight() == 0) {
            buffer.close();
            Slog.e(TAG, "Invalid snapshot dimensions " + buffer.getWidth() + "x"
                    + buffer.getHeight());
            return null;
        } else {
        mCache.putSnapshot(source, snapshot);
        mCache.putSnapshot(source, snapshot);
        return snapshot;
        return snapshot;
    }
    }
    }


    @VisibleForTesting
    @VisibleForTesting
    int getSnapshotMode(TYPE source) {
    int getSnapshotMode(TYPE source) {
@@ -210,6 +203,11 @@ abstract class AbsAppSnapshotController<TYPE extends WindowContainer,


    @Nullable
    @Nullable
    TaskSnapshot snapshot(TYPE source) {
    TaskSnapshot snapshot(TYPE source) {
        return snapshot(source, mHighResSnapshotScale);
    }

    @Nullable
    TaskSnapshot snapshot(TYPE source, float scale) {
        TaskSnapshot.Builder builder = new TaskSnapshot.Builder();
        TaskSnapshot.Builder builder = new TaskSnapshot.Builder();
        final Rect crop = prepareTaskSnapshot(source, builder);
        final Rect crop = prepareTaskSnapshot(source, builder);
        if (crop == null) {
        if (crop == null) {
@@ -218,7 +216,7 @@ abstract class AbsAppSnapshotController<TYPE extends WindowContainer,
        }
        }
        Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "createSnapshot");
        Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "createSnapshot");
        final ScreenCapture.ScreenshotHardwareBuffer screenshotBuffer = createSnapshot(source,
        final ScreenCapture.ScreenshotHardwareBuffer screenshotBuffer = createSnapshot(source,
                mHighResSnapshotScale, crop, builder);
                scale, crop, builder);
        Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
        Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
        if (screenshotBuffer == null) {
        if (screenshotBuffer == null) {
            // Failed to acquire image. Has been logged.
            // Failed to acquire image. Has been logged.
@@ -227,7 +225,19 @@ abstract class AbsAppSnapshotController<TYPE extends WindowContainer,
        builder.setCaptureTime(SystemClock.elapsedRealtimeNanos());
        builder.setCaptureTime(SystemClock.elapsedRealtimeNanos());
        builder.setSnapshot(screenshotBuffer.getHardwareBuffer());
        builder.setSnapshot(screenshotBuffer.getHardwareBuffer());
        builder.setColorSpace(screenshotBuffer.getColorSpace());
        builder.setColorSpace(screenshotBuffer.getColorSpace());
        return builder.build();
        final TaskSnapshot snapshot = builder.build();
        return validateSnapshot(snapshot);
    }

    private static TaskSnapshot validateSnapshot(@NonNull TaskSnapshot snapshot) {
        final HardwareBuffer buffer = snapshot.getHardwareBuffer();
        if (buffer.getWidth() == 0 || buffer.getHeight() == 0) {
            buffer.close();
            Slog.e(TAG, "Invalid snapshot dimensions " + buffer.getWidth() + "x"
                    + buffer.getHeight());
            return null;
        }
        return snapshot;
    }
    }


    @Nullable
    @Nullable
@@ -432,7 +442,7 @@ abstract class AbsAppSnapshotController<TYPE extends WindowContainer,
        InsetUtils.addInsets(contentInsets, letterboxInsets);
        InsetUtils.addInsets(contentInsets, letterboxInsets);
        // Note, the app theme snapshot is never translucent because we enforce a non-translucent
        // Note, the app theme snapshot is never translucent because we enforce a non-translucent
        // color above
        // color above
        return new TaskSnapshot(
        final TaskSnapshot taskSnapshot = new TaskSnapshot(
                System.currentTimeMillis() /* id */,
                System.currentTimeMillis() /* id */,
                SystemClock.elapsedRealtimeNanos() /* captureTime */,
                SystemClock.elapsedRealtimeNanos() /* captureTime */,
                topActivity.mActivityComponent, hwBitmap.getHardwareBuffer(),
                topActivity.mActivityComponent, hwBitmap.getHardwareBuffer(),
@@ -441,6 +451,7 @@ abstract class AbsAppSnapshotController<TYPE extends WindowContainer,
                contentInsets, letterboxInsets, false /* isLowResolution */,
                contentInsets, letterboxInsets, false /* isLowResolution */,
                false /* isRealSnapshot */, source.getWindowingMode(),
                false /* isRealSnapshot */, source.getWindowingMode(),
                getAppearance(source), false /* isTranslucent */, false /* hasImeSurface */);
                getAppearance(source), false /* isTranslucent */, false /* hasImeSurface */);
        return validateSnapshot(taskSnapshot);
    }
    }


    static Rect getSystemBarInsets(Rect frame, InsetsState state) {
    static Rect getSystemBarInsets(Rect frame, InsetsState state) {
+269 −85

File changed.

Preview size limit exceeded, changes collapsed.

+9 −5
Original line number Original line Diff line number Diff line
@@ -1327,7 +1327,8 @@ class BackNavigationController {
                return mAnimationTarget;
                return mAnimationTarget;
            }
            }


            void createStartingSurface(@NonNull WindowContainer closeWindow) {
            void createStartingSurface(@NonNull WindowContainer closeWindow,
                    @NonNull ActivityRecord[] visibleOpenActivities) {
                if (!mIsOpen) {
                if (!mIsOpen) {
                    return;
                    return;
                }
                }
@@ -1346,7 +1347,7 @@ class BackNavigationController {
                if (mainActivity == null) {
                if (mainActivity == null) {
                    return;
                    return;
                }
                }
                final TaskSnapshot snapshot = getSnapshot(mTarget);
                final TaskSnapshot snapshot = getSnapshot(mTarget, visibleOpenActivities);
                mRequestedStartingSurfaceId = openTask.mAtmService.mTaskOrganizerController
                mRequestedStartingSurfaceId = openTask.mAtmService.mTaskOrganizerController
                        .addWindowlessStartingSurface(openTask, mainActivity,
                        .addWindowlessStartingSurface(openTask, mainActivity,
                                // Choose configuration from closeWindow, because the configuration
                                // Choose configuration from closeWindow, because the configuration
@@ -1489,7 +1490,8 @@ class BackNavigationController {
                        // Try to draw two snapshot within a WindowlessStartingWindow, or find
                        // Try to draw two snapshot within a WindowlessStartingWindow, or find
                        // another key for StartingWindowRecordManager.
                        // another key for StartingWindowRecordManager.
                        && openAnimationAdaptor.length == 1) {
                        && openAnimationAdaptor.length == 1) {
                    openAnimationAdaptor[0].createStartingSurface(closeWindow);
                    openAnimationAdaptor[0].createStartingSurface(closeWindow,
                            visibleOpenActivities);
                } else {
                } else {
                    for (int i = visibleOpenActivities.length - 1; i >= 0; --i) {
                    for (int i = visibleOpenActivities.length - 1; i >= 0; --i) {
                        setLaunchBehind(visibleOpenActivities[i]);
                        setLaunchBehind(visibleOpenActivities[i]);
@@ -1671,7 +1673,8 @@ class BackNavigationController {
        mPendingAnimationBuilder = null;
        mPendingAnimationBuilder = null;
    }
    }


    static TaskSnapshot getSnapshot(@NonNull WindowContainer w) {
    static TaskSnapshot getSnapshot(@NonNull WindowContainer w,
            ActivityRecord[] visibleOpenActivities) {
        if (w.asTask() != null) {
        if (w.asTask() != null) {
            final Task task = w.asTask();
            final Task task = w.asTask();
            return task.mRootWindowContainer.mWindowManager.mTaskSnapshotController.getSnapshot(
            return task.mRootWindowContainer.mWindowManager.mTaskSnapshotController.getSnapshot(
@@ -1681,7 +1684,8 @@ class BackNavigationController {


        if (w.asActivityRecord() != null) {
        if (w.asActivityRecord() != null) {
            final ActivityRecord ar = w.asActivityRecord();
            final ActivityRecord ar = w.asActivityRecord();
            return ar.mWmService.mSnapshotController.mActivitySnapshotController.getSnapshot(ar);
            return ar.mWmService.mSnapshotController.mActivitySnapshotController
                    .getSnapshot(visibleOpenActivities);
        }
        }
        return null;
        return null;
    }
    }
+1 −3
Original line number Original line Diff line number Diff line
@@ -160,9 +160,7 @@ class SnapshotController {
                if (!allOpensOptInOnBackInvoked() || mCloseActivities.isEmpty()) {
                if (!allOpensOptInOnBackInvoked() || mCloseActivities.isEmpty()) {
                    return;
                    return;
                }
                }
                for (int i = mCloseActivities.size() - 1; i >= 0; --i) {
                controller.recordSnapshot(mCloseActivities);
                    controller.recordSnapshot(mCloseActivities.get(i));
                }
            }
            }
        }
        }
    }
    }
+3 −1

File changed.

Preview size limit exceeded, changes collapsed.

Loading