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

Commit b4d4ce31 authored by Zak Cohen's avatar Zak Cohen Committed by Android (Google) Code Review
Browse files

Merge "Adds a screenshot wallpaper method to WallpaperManagerService." into nyc-mr1-dev

parents 1eb8c69b 3683fb1e
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -305,6 +305,11 @@ interface IWindowManager
     */
     */
    boolean isRotationFrozen();
    boolean isRotationFrozen();


    /**
     * Screenshot the current wallpaper layer, including the whole screen.
     */
    Bitmap screenshotWallpaper();

    /**
    /**
     * Used only for assist -- request a screenshot of the current application.
     * Used only for assist -- request a screenshot of the current application.
     */
     */
+45 −6
Original line number Original line Diff line number Diff line
@@ -6162,6 +6162,21 @@ public class WindowManagerService extends IWindowManager.Stub
        }
        }
    }
    }


    @Override
    public Bitmap screenshotWallpaper() {
        if (!checkCallingPermission(Manifest.permission.READ_FRAME_BUFFER,
                "screenshotWallpaper()")) {
            throw new SecurityException("Requires READ_FRAME_BUFFER permission");
        }
        try {
            Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "screenshotWallpaper");
            return screenshotApplicationsInner(null, Display.DEFAULT_DISPLAY, -1, -1, true, 1f,
                    Bitmap.Config.ARGB_8888, true);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
        }
    }

    /**
    /**
     * Takes a snapshot of the screen.  In landscape mode this grabs the whole screen.
     * Takes a snapshot of the screen.  In landscape mode this grabs the whole screen.
     * In portrait mode, it grabs the upper region of the screen based on the vertical dimension
     * In portrait mode, it grabs the upper region of the screen based on the vertical dimension
@@ -6178,7 +6193,7 @@ public class WindowManagerService extends IWindowManager.Stub
            @Override
            @Override
            public void run() {
            public void run() {
                Bitmap bm = screenshotApplicationsInner(null, Display.DEFAULT_DISPLAY, -1, -1,
                Bitmap bm = screenshotApplicationsInner(null, Display.DEFAULT_DISPLAY, -1, -1,
                        true, 1f, Bitmap.Config.ARGB_8888);
                        true, 1f, Bitmap.Config.ARGB_8888, false);
                try {
                try {
                    receiver.send(bm);
                    receiver.send(bm);
                } catch (RemoteException e) {
                } catch (RemoteException e) {
@@ -6208,14 +6223,27 @@ public class WindowManagerService extends IWindowManager.Stub
        try {
        try {
            Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "screenshotApplications");
            Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "screenshotApplications");
            return screenshotApplicationsInner(appToken, displayId, width, height, false,
            return screenshotApplicationsInner(appToken, displayId, width, height, false,
                    frameScale, Bitmap.Config.RGB_565);
                    frameScale, Bitmap.Config.RGB_565, false);
        } finally {
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
            Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
        }
        }
    }
    }


    /**
     * Takes a snapshot of the screen.  In landscape mode this grabs the whole screen.
     * In portrait mode, it grabs the full screenshot.
     *
     * @param displayId the Display to take a screenshot of.
     * @param width the width of the target bitmap
     * @param height the height of the target bitmap
     * @param includeFullDisplay true if the screen should not be cropped before capture
     * @param frameScale the scale to apply to the frame, only used when width = -1 and height = -1
     * @param config of the output bitmap
     * @param wallpaperOnly true if only the wallpaper layer should be included in the screenshot
     */
    Bitmap screenshotApplicationsInner(IBinder appToken, int displayId, int width, int height,
    Bitmap screenshotApplicationsInner(IBinder appToken, int displayId, int width, int height,
            boolean includeFullDisplay, float frameScale, Bitmap.Config config) {
            boolean includeFullDisplay, float frameScale, Bitmap.Config config,
            boolean wallpaperOnly) {
        final DisplayContent displayContent;
        final DisplayContent displayContent;
        synchronized(mWindowMap) {
        synchronized(mWindowMap) {
            displayContent = getDisplayContentLocked(displayId);
            displayContent = getDisplayContentLocked(displayId);
@@ -6242,7 +6270,7 @@ public class WindowManagerService extends IWindowManager.Stub


        boolean screenshotReady;
        boolean screenshotReady;
        int minLayer;
        int minLayer;
        if (appToken == null) {
        if (appToken == null && !wallpaperOnly) {
            screenshotReady = true;
            screenshotReady = true;
            minLayer = 0;
            minLayer = 0;
        } else {
        } else {
@@ -6282,11 +6310,20 @@ public class WindowManagerService extends IWindowManager.Stub
                if (ws.mLayer >= aboveAppLayer) {
                if (ws.mLayer >= aboveAppLayer) {
                    continue;
                    continue;
                }
                }
                if (wallpaperOnly && !ws.mIsWallpaper) {
                    continue;
                }
                if (ws.mIsImWindow) {
                if (ws.mIsImWindow) {
                    if (!includeImeInScreenshot) {
                    if (!includeImeInScreenshot) {
                        continue;
                        continue;
                    }
                    }
                } else if (ws.mIsWallpaper) {
                } else if (ws.mIsWallpaper) {
                    // If this is the wallpaper layer and we're only looking for the wallpaper layer
                    // then the target window state is this one.
                    if (wallpaperOnly) {
                        appWin = ws;
                    }

                    if (appWin == null) {
                    if (appWin == null) {
                        // We have not ran across the target window yet, so it is probably
                        // We have not ran across the target window yet, so it is probably
                        // behind the wallpaper. This can happen when the keyguard is up and
                        // behind the wallpaper. This can happen when the keyguard is up and
@@ -6334,8 +6371,10 @@ public class WindowManagerService extends IWindowManager.Stub
                    }
                    }
                }
                }


                if (ws.mAppToken != null && ws.mAppToken.token == appToken &&
                final boolean foundTargetWs =
                        ws.isDisplayedLw() && winAnim.getShown()) {
                        (ws.mAppToken != null && ws.mAppToken.token == appToken)
                        || (appWin != null && wallpaperOnly);
                if (foundTargetWs && ws.isDisplayedLw() && winAnim.getShown()) {
                    screenshotReady = true;
                    screenshotReady = true;
                }
                }


+5 −0
Original line number Original line Diff line number Diff line
@@ -590,4 +590,9 @@ public class IWindowManagerImpl implements IWindowManager {


    @Override
    @Override
    public void removeWallpaperInputConsumer() throws RemoteException {}
    public void removeWallpaperInputConsumer() throws RemoteException {}

    @Override
    public Bitmap screenshotWallpaper() throws RemoteException {
        return null;
    }
}
}