1 /*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.systemui.screenshot.appclips
18
19 import android.app.TaskInfo
20 import android.content.ClipData
21 import android.content.pm.ActivityInfo
22 import android.content.pm.PackageManager
23 import android.graphics.drawable.Drawable
24
25 /**
26 * A class to hold the [ClipData] for backlinks, the corresponding app's [Drawable] icon, and
27 * represent error when necessary.
28 */
29 internal sealed class InternalBacklinksData(
30 // Fields from this object are made accessible through accessors to keep call sites simpler.
31 private val backlinkDisplayInfo: BacklinkDisplayInfo,
32 ) {
33 // Use separate field to access display label so that callers don't have to access through
34 // internal object.
35 var displayLabel: String
36 get() = backlinkDisplayInfo.displayLabel
37 set(value) {
38 backlinkDisplayInfo.displayLabel = value
39 }
40
41 // Use separate field to access app icon so that callers don't have to access through internal
42 // object.
43 val appIcon: Drawable
44 get() = backlinkDisplayInfo.appIcon
45
46 data class BacklinksData(val clipData: ClipData, private val icon: Drawable) :
47 InternalBacklinksData(BacklinkDisplayInfo(icon, clipData.description.label.toString()))
48
49 data class CrossProfileError(private val icon: Drawable, private var label: String) :
50 InternalBacklinksData(BacklinkDisplayInfo(icon, label))
51 }
52
53 /**
54 * A class to hold important members of [TaskInfo] and its associated user's [PackageManager] for
55 * ease of querying.
56 *
57 * @note A task can have a different app running on top. For example, an app "A" can use camera app
58 * to capture an image. In this case the top app will be the camera app even though the task
59 * belongs to app A. This is expected behaviour because user will be taking a screenshot of the
60 * content rendered by the camera (top) app.
61 */
62 internal data class InternalTaskInfo(
63 private val topActivityInfo: ActivityInfo,
64 val taskId: Int,
65 val userId: Int,
66 val packageManager: PackageManager
67 ) {
68 val topActivityNameForDebugLogging: String = topActivityInfo.name
69 val topActivityPackageName: String = topActivityInfo.packageName
<lambda>null70 val topActivityAppName: String by lazy { topActivityInfo.getAppName(packageManager) }
<lambda>null71 val topActivityAppIcon: Drawable by lazy { topActivityInfo.loadIcon(packageManager) }
72 }
73
getAppNamenull74 internal fun ActivityInfo.getAppName(packageManager: PackageManager) =
75 loadLabel(packageManager).toString()
76
77 internal fun ActivityInfo.getAppIcon(packageManager: PackageManager) = loadIcon(packageManager)
78
79 /** A class to hold data that is used for displaying backlink to user in SysUI activity. */
80 internal data class BacklinkDisplayInfo(val appIcon: Drawable, var displayLabel: String)
81