1 /*
<lambda>null2  * 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.pipeline.satellite.data.demo
18 
19 import com.android.systemui.dagger.SysUISingleton
20 import com.android.systemui.dagger.qualifiers.Application
21 import com.android.systemui.statusbar.pipeline.satellite.data.DeviceBasedSatelliteRepository
22 import com.android.systemui.statusbar.pipeline.satellite.shared.model.SatelliteConnectionState
23 import javax.inject.Inject
24 import kotlinx.coroutines.CoroutineScope
25 import kotlinx.coroutines.Job
26 import kotlinx.coroutines.flow.MutableStateFlow
27 import kotlinx.coroutines.launch
28 
29 /** A satellite repository that represents the latest satellite values sent via demo mode. */
30 @SysUISingleton
31 class DemoDeviceBasedSatelliteRepository
32 @Inject
33 constructor(
34     private val dataSource: DemoDeviceBasedSatelliteDataSource,
35     @Application private val scope: CoroutineScope,
36 ) : DeviceBasedSatelliteRepository {
37     private var demoCommandJob: Job? = null
38 
39     override val isSatelliteProvisioned = MutableStateFlow(true)
40     override val connectionState = MutableStateFlow(SatelliteConnectionState.Unknown)
41     override val signalStrength = MutableStateFlow(0)
42     override val isSatelliteAllowedForCurrentLocation = MutableStateFlow(true)
43 
44     fun startProcessingCommands() {
45         demoCommandJob =
46             scope.launch { dataSource.satelliteEvents.collect { event -> processEvent(event) } }
47     }
48 
49     fun stopProcessingCommands() {
50         demoCommandJob?.cancel()
51     }
52 
53     private fun processEvent(event: DemoDeviceBasedSatelliteDataSource.DemoSatelliteEvent) {
54         connectionState.value = event.connectionState
55         signalStrength.value = event.signalStrength
56     }
57 }
58