• 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.desktopmode.desktopwallpaperactivity
18 
19 import android.util.SparseArray
20 import android.view.Display.DEFAULT_DISPLAY
21 import android.window.WindowContainerToken
22 import androidx.core.util.keyIterator
23 import com.android.internal.protolog.ProtoLog
24 import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
25 
26 /** Provides per display window container tokens for [DesktopWallpaperActivity]. */
27 class DesktopWallpaperActivityTokenProvider {
28 
29     private val wallpaperActivityTokenByDisplayId = SparseArray<WindowContainerToken>()
30 
setTokennull31     fun setToken(token: WindowContainerToken, displayId: Int = DEFAULT_DISPLAY) {
32         logV("Setting desktop wallpaper activity token for display %s", displayId)
33         wallpaperActivityTokenByDisplayId[displayId] = token
34     }
35 
getTokennull36     fun getToken(displayId: Int = DEFAULT_DISPLAY): WindowContainerToken? {
37         return wallpaperActivityTokenByDisplayId[displayId]
38     }
39 
removeTokennull40     fun removeToken(displayId: Int = DEFAULT_DISPLAY) {
41         logV("Remove desktop wallpaper activity token for display %s", displayId)
42         wallpaperActivityTokenByDisplayId.delete(displayId)
43     }
44 
removeTokennull45     fun removeToken(token: WindowContainerToken) {
46         val displayId =
47             wallpaperActivityTokenByDisplayId.keyIterator().asSequence().find {
48                 wallpaperActivityTokenByDisplayId[it] == token
49             }
50         if (displayId != null) {
51             logV("Remove desktop wallpaper activity token for display %s", displayId)
52             wallpaperActivityTokenByDisplayId.delete(displayId)
53         }
54     }
55 
logVnull56     private fun logV(msg: String, vararg arguments: Any?) {
57         ProtoLog.v(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
58     }
59 
60     companion object {
61         private const val TAG = "DesktopWallpaperActivityTokenProvider"
62     }
63 }
64