Android 12.0 Solution to the problem that calling the screenshot api in system Launcher3 always returns null

1 Overview

In the development of the 12.0 system rom product, in the development of Launcher3, at some point it is necessary to call the screenshot interface to implement the screenshot function, and in Launcher3, it is found that when the system screenshot interface SurfaceControl.screenshot is called to take a screenshot, Always null,
cannot obtain the screenshot function of the current page of the system, so it is necessary to find the reason why the current screenshot fails and then realize the screenshot function. Let’s analyze the process of taking screenshots and then solve it. Question.

2. Regarding the core class of the solution where calling the screenshot function in Launcher3 always returns null

frameworks\native\services\surfaceflinger\SurfaceFlinger.cpp

3. Analysis and implementation of the core functions of the solution that always returns null when calling the screenshot function in Launcher3

SurfaceFlinger is a system service that implements the establishment, control, and management of Surface, creates display display channels, controls GraphicBuffer application rotation, and synchronizes based on Vsync events
 Management needs to participate in the display The surface overlays the HWComposer hardware overlay onto the screen.
Each Window of the application will be associated with a Surface, and the Surface will be associated with the real Graphic Buffer buffer queue. There are many APIs for android drawing,
such as 2D drawing skia; 3D drawing OpenGL, Vulkan, etc., drawn on the surface

3.1 Related methods of calling screenshots

There are four types of Android screenshots: View screenshots, WebView screenshots, system screenshots and adb screenshots
First, let’s take a look at the screenshot function that can be called through commands in app development
Use screencap to implement screenshots. You can also implement screenshots by calling the screenshot API. Next, let’s see how to call the relevant screenshot API to implement the screenshot function. Next, see

Guess you like

Origin blog.csdn.net/baidu_41666295/article/details/134818328