• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.statusbar.window
18 
19 import android.app.StatusBarManager
20 import android.app.StatusBarManager.WINDOW_STATE_SHOWING
21 import android.app.StatusBarManager.WINDOW_STATUS_BAR
22 import android.app.StatusBarManager.WindowVisibleState
23 import android.app.StatusBarManager.windowStateToString
24 import android.util.Log
25 import com.android.systemui.dagger.SysUISingleton
26 import com.android.systemui.dagger.qualifiers.DisplayId
27 import com.android.systemui.statusbar.CommandQueue
28 import com.android.systemui.statusbar.phone.CentralSurfaces
29 import javax.inject.Inject
30 
31 /**
32  * A centralized class maintaining the state of the status bar window.
33  *
34  * @deprecated use
35  *   [com.android.systemui.statusbar.window.data.repository.StatusBarWindowStateRepositoryStore.defaultDisplay]
36  *   repo instead.
37  *
38  * Classes that want to get updates about the status bar window state should subscribe to this class
39  * via [addListener] and should NOT add their own callback on [CommandQueue].
40  */
41 @SysUISingleton
42 @Deprecated("Use StatusBarWindowStateRepositoryStore.defaultDisplay instead")
43 class StatusBarWindowStateController
44 @Inject
45 constructor(@DisplayId private val thisDisplayId: Int, commandQueue: CommandQueue) {
46     private val commandQueueCallback =
47         object : CommandQueue.Callbacks {
setWindowStatenull48             override fun setWindowState(
49                 displayId: Int,
50                 @StatusBarManager.WindowType window: Int,
51                 @WindowVisibleState state: Int,
52             ) {
53                 this@StatusBarWindowStateController.setWindowState(displayId, window, state)
54             }
55         }
56     private val listeners: MutableSet<StatusBarWindowStateListener> = HashSet()
57 
58     @WindowVisibleState private var windowState: Int = WINDOW_STATE_SHOWING
59 
60     init {
61         commandQueue.addCallback(commandQueueCallback)
62     }
63 
64     /** Adds a listener. */
addListenernull65     fun addListener(listener: StatusBarWindowStateListener) {
66         listeners.add(listener)
67     }
68 
removeListenernull69     fun removeListener(listener: StatusBarWindowStateListener) {
70         listeners.remove(listener)
71     }
72 
73     /** Returns true if the window is currently showing. */
windowIsShowingnull74     fun windowIsShowing() = windowState == WINDOW_STATE_SHOWING
75 
76     private fun setWindowState(
77         displayId: Int,
78         @StatusBarManager.WindowType window: Int,
79         @WindowVisibleState state: Int,
80     ) {
81         if (displayId != thisDisplayId) {
82             return
83         }
84         if (window != WINDOW_STATUS_BAR) {
85             return
86         }
87         if (windowState == state) {
88             return
89         }
90 
91         windowState = state
92         if (CentralSurfaces.DEBUG_WINDOW_STATE) {
93             Log.d(CentralSurfaces.TAG, "Status bar " + windowStateToString(state))
94         }
95         listeners.forEach { it.onStatusBarWindowStateChanged(state) }
96     }
97 }
98