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