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.systemui.statusbar.policy
18 
19 import android.media.projection.StopReason
20 import java.io.PrintWriter
21 
22 class FakeCastController : CastController {
23     private var listeners = mutableListOf<CastController.Callback>()
24 
25     private var castDevices = emptyList<CastDevice>()
26 
27     var lastStoppedDevice: CastDevice? = null
28         private set
29 
addCallbacknull30     override fun addCallback(listener: CastController.Callback) {
31         listeners += listener
32     }
33 
removeCallbacknull34     override fun removeCallback(listener: CastController.Callback) {
35         listeners -= listener
36     }
37 
getCastDevicesnull38     override fun getCastDevices(): List<CastDevice> {
39         return castDevices
40     }
41 
setCastDevicesnull42     fun setCastDevices(devices: List<CastDevice>) {
43         castDevices = devices
44         listeners.forEach { it.onCastDevicesChanged() }
45     }
46 
startCastingnull47     override fun startCasting(device: CastDevice?) {}
48 
stopCastingnull49     override fun stopCasting(device: CastDevice?, @StopReason stopReason: Int) {
50         lastStoppedDevice = device
51     }
52 
hasConnectedCastDevicenull53     override fun hasConnectedCastDevice(): Boolean {
54         return castDevices.any { it.state == CastDevice.CastState.Connected }
55     }
56 
dumpnull57     override fun dump(pw: PrintWriter, args: Array<out String>) {}
58 
setDiscoveringnull59     override fun setDiscovering(request: Boolean) {}
60 
setCurrentUserIdnull61     override fun setCurrentUserId(currentUserId: Int) {}
62 }
63