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
18 
19 import android.app.Activity
20 import android.app.ActivityManager
21 import android.content.ComponentName
22 import android.os.Bundle
23 import android.view.WindowManager
24 import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
25 import com.android.wm.shell.util.KtProtoLog
26 
27 /**
28  * A transparent activity used in the desktop mode to show the wallpaper under the freeform windows.
29  * This activity will be running in `FULLSCREEN` windowing mode, which ensures it hides Launcher.
30  * When entering desktop, we would ensure that it's added behind desktop apps and removed when
31  * leaving the desktop mode.
32  *
33  * Note! This activity should NOT interact directly with any other code in the Shell without calling
34  * onto the shell main thread. Activities are always started on the main thread.
35  */
36 class DesktopWallpaperActivity : Activity() {
37 
onCreatenull38     override fun onCreate(savedInstanceState: Bundle?) {
39         KtProtoLog.d(WM_SHELL_DESKTOP_MODE, "DesktopWallpaperActivity: onCreate")
40         super.onCreate(savedInstanceState)
41         window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
42     }
43 
44     companion object {
45         private const val SYSTEM_UI_PACKAGE_NAME = "com.android.systemui"
46         private val wallpaperActivityComponent =
47             ComponentName(SYSTEM_UI_PACKAGE_NAME, DesktopWallpaperActivity::class.java.name)
48 
49         @JvmStatic
isWallpaperTasknull50         fun isWallpaperTask(taskInfo: ActivityManager.RunningTaskInfo) =
51             taskInfo.baseIntent.component?.let(::isWallpaperComponent) ?: false
52 
53         @JvmStatic
54         fun isWallpaperComponent(component: ComponentName) =
55             component == wallpaperActivityComponent
56     }
57 }
58