1 /*
2  * Copyright (C) 2022 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.qs
18 
19 import com.android.systemui.animation.Expandable
20 import com.android.systemui.qs.FgsManagerController.OnDialogDismissedListener
21 import com.android.systemui.qs.FgsManagerController.OnNumberOfPackagesChangedListener
22 import kotlinx.coroutines.flow.MutableStateFlow
23 
24 /** A fake [FgsManagerController] to be used in tests. */
25 class FakeFgsManagerController(
26     showFooterDot: Boolean = false,
27     numRunningPackages: Int = 0,
28 ) : FgsManagerController {
29 
30     override var numRunningPackages = numRunningPackages
31         set(value) {
32             if (value != field) {
33                 field = value
34                 newChangesSinceDialogWasDismissed = true
<lambda>null35                 numRunningPackagesListeners.forEach { it.onNumberOfPackagesChanged(value) }
36             }
37         }
38 
39     override var newChangesSinceDialogWasDismissed = false
40         private set
41 
42     override val showFooterDot: MutableStateFlow<Boolean> = MutableStateFlow(showFooterDot)
43 
44     override var includesUserVisibleJobs = false
45         private set
46 
47     private val numRunningPackagesListeners = LinkedHashSet<OnNumberOfPackagesChangedListener>()
48     private val dialogDismissedListeners = LinkedHashSet<OnDialogDismissedListener>()
49 
50     /** Simulate that a fgs dialog was just dismissed. */
simulateDialogDismissnull51     fun simulateDialogDismiss() {
52         newChangesSinceDialogWasDismissed = false
53         dialogDismissedListeners.forEach { it.onDialogDismissed() }
54     }
55 
initnull56     override fun init() {}
57 
showDialognull58     override fun showDialog(expandable: Expandable?) {}
59 
addOnNumberOfPackagesChangedListenernull60     override fun addOnNumberOfPackagesChangedListener(listener: OnNumberOfPackagesChangedListener) {
61         numRunningPackagesListeners.add(listener)
62     }
63 
removeOnNumberOfPackagesChangedListenernull64     override fun removeOnNumberOfPackagesChangedListener(
65         listener: OnNumberOfPackagesChangedListener
66     ) {
67         numRunningPackagesListeners.remove(listener)
68     }
69 
addOnDialogDismissedListenernull70     override fun addOnDialogDismissedListener(listener: OnDialogDismissedListener) {
71         dialogDismissedListeners.add(listener)
72     }
73 
removeOnDialogDismissedListenernull74     override fun removeOnDialogDismissedListener(listener: OnDialogDismissedListener) {
75         dialogDismissedListeners.remove(listener)
76     }
77 
visibleButtonsCountnull78     override fun visibleButtonsCount(): Int = 0
79 }
80