• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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.quickstep
18 
19 import android.content.Context
20 import android.util.Log
21 import com.android.launcher3.dagger.ApplicationContext
22 import com.android.launcher3.dagger.LauncherAppSingleton
23 import com.android.launcher3.util.DaggerSingletonObject
24 import com.android.launcher3.util.Executors.MAIN_EXECUTOR
25 import com.android.quickstep.dagger.QuickstepBaseAppComponent
26 import javax.inject.Inject
27 
28 @LauncherAppSingleton
29 class SystemDecorationChangeObserver @Inject constructor(@ApplicationContext context: Context) {
30     companion object {
31         private const val TAG = "SystemDecorationChangeObserver"
32         private const val DEBUG = false
33 
34         @JvmStatic
35         val INSTANCE: DaggerSingletonObject<SystemDecorationChangeObserver> =
36             DaggerSingletonObject<SystemDecorationChangeObserver>(
37                 QuickstepBaseAppComponent::getSystemDecorationChangeObserver
38             )
39     }
40 
41     interface DisplayDecorationListener {
onDisplayAddSystemDecorationsnull42         fun onDisplayAddSystemDecorations(displayId: Int)
43 
44         fun onDisplayRemoved(displayId: Int)
45 
46         fun onDisplayRemoveSystemDecorations(displayId: Int)
47     }
48 
49     fun notifyAddSystemDecorations(displayId: Int) {
50         if (DEBUG) Log.d(TAG, "SystemDecorationAdded: $displayId")
51         for (listener in mDisplayDecorationListeners) {
52             MAIN_EXECUTOR.execute { listener.onDisplayAddSystemDecorations(displayId) }
53         }
54     }
55 
notifyOnDisplayRemovednull56     fun notifyOnDisplayRemoved(displayId: Int) {
57         if (DEBUG) Log.d(TAG, "displayRemoved: $displayId")
58         for (listener in mDisplayDecorationListeners) {
59             MAIN_EXECUTOR.execute { listener.onDisplayRemoved(displayId) }
60         }
61     }
62 
notifyDisplayRemoveSystemDecorationsnull63     fun notifyDisplayRemoveSystemDecorations(displayId: Int) {
64         if (DEBUG) Log.d(TAG, "SystemDecorationRemoved: $displayId")
65         for (listener in mDisplayDecorationListeners) {
66             MAIN_EXECUTOR.execute { listener.onDisplayRemoveSystemDecorations(displayId) }
67         }
68     }
69 
70     private val mDisplayDecorationListeners = ArrayList<DisplayDecorationListener>()
71 
registerDisplayDecorationListenernull72     fun registerDisplayDecorationListener(listener: DisplayDecorationListener) {
73         if (DEBUG) Log.d(TAG, "registerDisplayDecorationListener")
74         mDisplayDecorationListeners.add(listener)
75     }
76 
unregisterDisplayDecorationListenernull77     fun unregisterDisplayDecorationListener(listener: DisplayDecorationListener) {
78         if (DEBUG) Log.d(TAG, "unregisterDisplayDecorationListener")
79         mDisplayDecorationListeners.remove(listener)
80     }
81 }
82