xref: /aosp_15_r20/frameworks/base/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotData.kt (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
1 package com.android.systemui.screenshot
2 
3 import android.content.ComponentName
4 import android.graphics.Bitmap
5 import android.graphics.Insets
6 import android.graphics.Rect
7 import android.os.UserHandle
8 import android.view.Display
9 import android.view.WindowManager
10 import android.view.WindowManager.ScreenshotSource
11 import android.view.WindowManager.ScreenshotType
12 import androidx.annotation.VisibleForTesting
13 import com.android.internal.util.ScreenshotRequest
14 
15 /** [ScreenshotData] represents the current state of a single screenshot being acquired. */
16 data class ScreenshotData(
17     @ScreenshotType val type: Int,
18     @ScreenshotSource val source: Int,
19     /** UserHandle for the owner of the app being screenshotted, if known. */
20     val userHandle: UserHandle,
21     /** ComponentName of the top-most app in the screenshot. */
22     val topComponent: ComponentName?,
23     val taskId: Int,
24     val originalScreenBounds: Rect?,
25     val originalInsets: Insets,
26     var bitmap: Bitmap?,
27     val displayId: Int,
28 ) {
29     val packageNameString
30         get() = topComponent?.packageName ?: ""
31 
32     companion object {
33         @JvmStatic
fromRequestnull34         fun fromRequest(request: ScreenshotRequest, displayId: Int = Display.DEFAULT_DISPLAY) =
35             ScreenshotData(
36                 type = request.type,
37                 source = request.source,
38                 userHandle = UserHandle.of(request.userId),
39                 topComponent = request.topComponent,
40                 originalScreenBounds = request.boundsInScreen,
41                 taskId = request.taskId,
42                 originalInsets = request.insets,
43                 bitmap = request.bitmap,
44                 displayId = displayId,
45             )
46 
47         @VisibleForTesting
48         fun forTesting(
49             userHandle: UserHandle = UserHandle.CURRENT,
50             source: Int = ScreenshotSource.SCREENSHOT_KEY_CHORD,
51             topComponent: ComponentName? = null,
52             bitmap: Bitmap? = null,
53         ) =
54             ScreenshotData(
55                 type = WindowManager.TAKE_SCREENSHOT_FULLSCREEN,
56                 source = source,
57                 userHandle = userHandle,
58                 topComponent = topComponent,
59                 originalScreenBounds = null,
60                 taskId = 0,
61                 originalInsets = Insets.NONE,
62                 bitmap = bitmap,
63                 displayId = Display.DEFAULT_DISPLAY,
64             )
65     }
66 }
67