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.net.Uri 8 import android.os.Process 9 import android.os.UserHandle 10 import android.view.Display 11 import android.view.WindowManager.ScreenshotSource 12 import android.view.WindowManager.ScreenshotType 13 import androidx.annotation.VisibleForTesting 14 import com.android.internal.util.ScreenshotRequest 15 16 /** [ScreenshotData] represents the current state of a single screenshot being acquired. */ 17 data class ScreenshotData( 18 @ScreenshotType var type: Int, 19 @ScreenshotSource var source: Int, 20 /** UserHandle for the owner of the app being screenshotted, if known. */ 21 var userHandle: UserHandle?, 22 /** ComponentName of the top-most app in the screenshot. */ 23 var topComponent: ComponentName?, 24 var screenBounds: Rect?, 25 var taskId: Int, 26 var insets: Insets, 27 var bitmap: Bitmap?, 28 var displayId: Int, 29 /** App-provided URL representing the content the user was looking at in the screenshot. */ 30 var contextUrl: Uri? = null, 31 ) { 32 val packageNameString: String 33 get() = if (topComponent == null) "" else topComponent!!.packageName 34 getUserOrDefaultnull35 fun getUserOrDefault(): UserHandle { 36 return userHandle ?: Process.myUserHandle() 37 } 38 39 companion object { 40 @JvmStatic fromRequestnull41 fun fromRequest(request: ScreenshotRequest, displayId: Int = Display.DEFAULT_DISPLAY) = 42 ScreenshotData( 43 type = request.type, 44 source = request.source, 45 userHandle = if (request.userId >= 0) UserHandle.of(request.userId) else null, 46 topComponent = request.topComponent, 47 screenBounds = request.boundsInScreen, 48 taskId = request.taskId, 49 insets = request.insets, 50 bitmap = request.bitmap, 51 displayId = displayId, 52 ) 53 54 @VisibleForTesting 55 fun forTesting() = 56 ScreenshotData( 57 type = 0, 58 source = 0, 59 userHandle = null, 60 topComponent = null, 61 screenBounds = null, 62 taskId = 0, 63 insets = Insets.NONE, 64 bitmap = null, 65 displayId = Display.DEFAULT_DISPLAY, 66 ) 67 } 68 } 69