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

Commit f4ac4e7f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "WM: Mock or stub SurfaceControl and Surface calls in wm unit tests"

parents 2ff3f0bb e6e2b0f3
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -257,7 +257,7 @@ class ScreenRotationAnimation {
        mOriginalWidth = originalWidth;
        mOriginalHeight = originalHeight;

        final SurfaceControl.Transaction t = new SurfaceControl.Transaction();
        final SurfaceControl.Transaction t = mService.mTransactionFactory.make();
        try {
            mSurfaceControl = displayContent.makeOverlay()
                    .setName("ScreenshotSurface")
@@ -267,13 +267,13 @@ class ScreenRotationAnimation {

            // In case display bounds change, screenshot buffer and surface may mismatch so set a
            // scaling mode.
            SurfaceControl.Transaction t2 = new SurfaceControl.Transaction();
            SurfaceControl.Transaction t2 = mService.mTransactionFactory.make();
            t2.setOverrideScalingMode(mSurfaceControl, Surface.SCALING_MODE_SCALE_TO_WINDOW);
            t2.apply(true /* sync */);

            // Capture a screenshot into the surface we just created.
            final int displayId = display.getDisplayId();
            final Surface surface = new Surface();
            final Surface surface = mService.mSurfaceFactory.make();
            surface.copyFrom(mSurfaceControl);
            if (mService.mDisplayManagerInternal.screenshot(displayId, surface)) {
                t.setLayer(mSurfaceControl, SCREEN_FREEZE_LAYER_SCREENSHOT);
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.wm;

import android.view.Surface;

/**
 * Helper class to inject custom {@link Surface} objects into window manager.
 */
interface SurfaceFactory {
    Surface make();
};
+22 −8
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.view.SurfaceControl;
import android.view.WindowManager;
import android.view.animation.Animation;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ToBooleanFunction;

import java.io.PrintWriter;
@@ -700,24 +701,37 @@ class WallpaperController {
        mWallpaperTokens.remove(token);
    }

    /**
     * Take a screenshot of the wallpaper if it's visible.
     *
     * @return Bitmap of the wallpaper
     */
    Bitmap screenshotWallpaperLocked() {

    @VisibleForTesting
    boolean canScreenshotWallpaper() {
        return canScreenshotWallpaper(getTopVisibleWallpaper());
    }

    private boolean canScreenshotWallpaper(WindowState wallpaperWindowState) {
        if (!mService.mPolicy.isScreenOn()) {
            if (DEBUG_SCREENSHOT) {
                Slog.i(TAG_WM, "Attempted to take screenshot while display was off.");
            }
            return null;
            return false;
        }

        final WindowState wallpaperWindowState = getTopVisibleWallpaper();
        if (wallpaperWindowState == null) {
            if (DEBUG_SCREENSHOT) {
                Slog.i(TAG_WM, "No visible wallpaper to screenshot");
            }
            return false;
        }
        return true;
    }

    /**
     * Take a screenshot of the wallpaper if it's visible.
     *
     * @return Bitmap of the wallpaper
     */
    Bitmap screenshotWallpaperLocked() {
        final WindowState wallpaperWindowState = getTopVisibleWallpaper();
        if (!canScreenshotWallpaper(wallpaperWindowState)) {
            return null;
        }

+19 −3
Original line number Diff line number Diff line
@@ -814,8 +814,9 @@ public class WindowManagerService extends IWindowManager.Stub

    SurfaceBuilderFactory mSurfaceBuilderFactory = SurfaceControl.Builder::new;
    TransactionFactory mTransactionFactory = SurfaceControl.Transaction::new;
    SurfaceFactory mSurfaceFactory = Surface::new;

    private final SurfaceControl.Transaction mTransaction = mTransactionFactory.make();
    private final SurfaceControl.Transaction mTransaction;

    static void boostPriorityForLockedSection() {
        sThreadPriorityBooster.boost();
@@ -909,9 +910,21 @@ public class WindowManagerService extends IWindowManager.Stub
    public static WindowManagerService main(final Context context, final InputManagerService im,
            final boolean showBootMsgs, final boolean onlyCore, WindowManagerPolicy policy,
            ActivityTaskManagerService atm) {
        return main(context, im, showBootMsgs, onlyCore, policy, atm,
                SurfaceControl.Transaction::new);
    }

    /**
     * Creates and returns an instance of the WindowManagerService. This call allows the caller
     * to override the {@link TransactionFactory} to stub functionality under test.
     */
    @VisibleForTesting
    public static WindowManagerService main(final Context context, final InputManagerService im,
            final boolean showBootMsgs, final boolean onlyCore, WindowManagerPolicy policy,
            ActivityTaskManagerService atm, TransactionFactory transactionFactory) {
        DisplayThread.getHandler().runWithScissors(() ->
                sInstance = new WindowManagerService(context, im, showBootMsgs, onlyCore, policy,
                        atm), 0);
                        atm, transactionFactory), 0);
        return sInstance;
    }

@@ -933,7 +946,7 @@ public class WindowManagerService extends IWindowManager.Stub

    private WindowManagerService(Context context, InputManagerService inputManager,
            boolean showBootMsgs, boolean onlyCore, WindowManagerPolicy policy,
            ActivityTaskManagerService atm) {
            ActivityTaskManagerService atm, TransactionFactory transactionFactory) {
        installLock(this, INDEX_WINDOW);
        mGlobalLock = atm.getGlobalLock();
        mAtmService = atm;
@@ -962,6 +975,9 @@ public class WindowManagerService extends IWindowManager.Stub
        mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
        mDisplayWindowSettings = new DisplayWindowSettings(this);


        mTransactionFactory = transactionFactory;
        mTransaction = mTransactionFactory.make();
        mPolicy = policy;
        mAnimator = new WindowAnimator(this);
        mRoot = new RootWindowContainer(this);
+1 −2
Original line number Diff line number Diff line
@@ -59,8 +59,7 @@ public class AppChangeTransitionTests extends WindowTestsBase {
    public void setUpOnDisplay(DisplayContent dc) {
        mStack = createTaskStackOnDisplay(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_STANDARD, dc);
        mTask = createTaskInStack(mStack, 0 /* userId */);
        mToken = WindowTestUtils.createTestAppWindowToken(dc);
        mToken.mSkipOnParentChanged = false;
        mToken = WindowTestUtils.createTestAppWindowToken(dc, false /* skipOnParentChanged */);

        mTask.addChild(mToken, 0);

Loading