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.bluetooth.qsdialog
18 
19 import android.util.Log
20 import com.android.systemui.dagger.SysUISingleton
21 import javax.inject.Inject
22 
23 /** Interactor class responsible for interacting with the Bluetooth Auto-On feature. */
24 @SysUISingleton
25 class BluetoothAutoOnInteractor
26 @Inject
27 constructor(
28     private val bluetoothAutoOnRepository: BluetoothAutoOnRepository,
29 ) {
30 
31     val isEnabled = bluetoothAutoOnRepository.isAutoOn
32 
33     /** Checks if the auto on feature is supported. */
isAutoOnSupportednull34     suspend fun isAutoOnSupported(): Boolean = bluetoothAutoOnRepository.isAutoOnSupported()
35 
36     /**
37      * Sets enabled or disabled based on the provided value.
38      *
39      * @param value `true` to enable the feature, `false` to disable it.
40      */
41     suspend fun setEnabled(value: Boolean) {
42         if (!isAutoOnSupported()) {
43             Log.e(TAG, "Trying to set toggle value while feature not available.")
44         } else {
45             bluetoothAutoOnRepository.setAutoOn(value)
46         }
47     }
48 
49     companion object {
50         private const val TAG = "BluetoothAutoOnInteractor"
51     }
52 }
53