• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.wm.shell.util
18 
19 import android.app.ActivityManager.RunningTaskInfo
20 import android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED
21 import android.content.pm.ActivityInfo
22 import android.graphics.Rect
23 import com.android.wm.shell.desktopmode.CaptionState
24 import com.android.wm.shell.desktopmode.education.data.WindowingEducationProto
25 
26 /**
27  * Create an instance of [CaptionState.AppHandle] with parameters as properties.
28  *
29  * Any fields without corresponding parameters will retain their default values.
30  */
createAppHandleStatenull31 fun createAppHandleState(
32     runningTaskInfo: RunningTaskInfo = createTaskInfo(),
33     isHandleMenuExpanded: Boolean = false,
34     globalAppHandleBounds: Rect = Rect(),
35     isCapturedLinkAvailable: Boolean = false
36 ): CaptionState.AppHandle =
37     CaptionState.AppHandle(
38         runningTaskInfo = runningTaskInfo,
39         isHandleMenuExpanded = isHandleMenuExpanded,
40         globalAppHandleBounds = globalAppHandleBounds,
41         isCapturedLinkAvailable = isCapturedLinkAvailable)
42 
43 /**
44  * Create an instance of [CaptionState.AppHeader] with parameters as properties.
45  *
46  * Any fields without corresponding parameters will retain their default values.
47  */
48 fun createAppHeaderState(
49     runningTaskInfo: RunningTaskInfo = createTaskInfo(),
50     isHeaderMenuExpanded: Boolean = false,
51     globalAppChipBounds: Rect = Rect(),
52     isCapturedLinkAvailable: Boolean = false
53 ): CaptionState.AppHeader =
54     CaptionState.AppHeader(
55         runningTaskInfo = runningTaskInfo,
56         isHeaderMenuExpanded = isHeaderMenuExpanded,
57         globalAppChipBounds = globalAppChipBounds,
58         isCapturedLinkAvailable = isCapturedLinkAvailable)
59 
60 /**
61  * Create an instance of [RunningTaskInfo] with parameters as properties.
62  *
63  * Any fields without corresponding parameters will retain their default values.
64  */
65 fun createTaskInfo(
66     deviceWindowingMode: Int = WINDOWING_MODE_UNDEFINED,
67     runningTaskPackageName: String = GMAIL_PACKAGE_NAME,
68 ): RunningTaskInfo =
69     RunningTaskInfo().apply {
70       configuration.windowConfiguration.windowingMode = deviceWindowingMode
71       topActivityInfo = ActivityInfo().apply { packageName = runningTaskPackageName }
72     }
73 
74 /**
75  * Constructs a [WindowingEducationProto] object, populating its fields with the provided
76  * parameters.
77  *
78  * Any fields without corresponding parameters will retain their default values.
79  */
createWindowingEducationProtonull80 fun createWindowingEducationProto(
81     appHandleHintViewedTimestampMillis: Long? = null,
82     appHandleHintUsedTimestampMillis: Long? = null,
83     appUsageStats: Map<String, Int>? = null,
84     appUsageStatsLastUpdateTimestampMillis: Long? = null,
85     enterDesktopModeHintViewedTimestampMillis: Long? = null,
86     exitDesktopModeHintViewedTimestampMillis: Long? = null,
87 ): WindowingEducationProto =
88     WindowingEducationProto.newBuilder()
89         .apply {
90           if (appHandleHintViewedTimestampMillis != null) {
91             setAppHandleHintViewedTimestampMillis(appHandleHintViewedTimestampMillis)
92           }
93           if (appHandleHintUsedTimestampMillis != null) {
94             setAppHandleHintUsedTimestampMillis(appHandleHintUsedTimestampMillis)
95           }
96           if (enterDesktopModeHintViewedTimestampMillis != null) {
97               setEnterDesktopModeHintViewedTimestampMillis(enterDesktopModeHintViewedTimestampMillis)
98           }
99           if (exitDesktopModeHintViewedTimestampMillis != null) {
100               setExitDesktopModeHintViewedTimestampMillis(exitDesktopModeHintViewedTimestampMillis)
101           }
102           setAppHandleEducation(
103               createAppHandleEducationProto(appUsageStats, appUsageStatsLastUpdateTimestampMillis))
104         }
105         .build()
106 
107 /**
108  * Constructs a [WindowingEducationProto.AppHandleEducation] object, populating its fields with the
109  * provided parameters.
110  *
111  * Any fields without corresponding parameters will retain their default values.
112  */
createAppHandleEducationProtonull113 fun createAppHandleEducationProto(
114     appUsageStats: Map<String, Int>? = null,
115     appUsageStatsLastUpdateTimestampMillis: Long? = null
116 ): WindowingEducationProto.AppHandleEducation =
117     WindowingEducationProto.AppHandleEducation.newBuilder()
118         .apply {
119           if (appUsageStats != null) putAllAppUsageStats(appUsageStats)
120           if (appUsageStatsLastUpdateTimestampMillis != null) {
121             setAppUsageStatsLastUpdateTimestampMillis(appUsageStatsLastUpdateTimestampMillis)
122           }
123         }
124         .build()
125 
126 const val GMAIL_PACKAGE_NAME = "com.google.android.gm"
127 const val YOUTUBE_PACKAGE_NAME = "com.google.android.youtube"
128 const val LAUNCHER_PACKAGE_NAME = "com.google.android.apps.nexuslauncher"
129