1 /*
2  * Copyright (C) 2018 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 package com.android.settings.bluetooth
17 
18 import android.bluetooth.BluetoothAdapter
19 import android.bluetooth.BluetoothDevice
20 import android.content.ComponentName
21 import android.content.Context
22 import android.media.AudioManager
23 import android.media.Spatializer
24 import android.net.Uri
25 import androidx.preference.Preference
26 import com.android.settings.bluetooth.ui.view.DeviceDetailsFragmentFormatter
27 import com.android.settings.bluetooth.ui.view.DeviceDetailsFragmentFormatterImpl
28 import com.android.settings.dashboard.DashboardFragment
29 import com.android.settingslib.bluetooth.BluetoothUtils
30 import com.android.settingslib.bluetooth.CachedBluetoothDevice
31 import com.android.settingslib.bluetooth.devicesettings.data.repository.DeviceSettingRepository
32 import com.android.settingslib.bluetooth.devicesettings.data.repository.DeviceSettingRepositoryImpl
33 import com.android.settingslib.core.AbstractPreferenceController
34 import com.google.common.collect.ImmutableList
35 import com.google.common.collect.ImmutableSet
36 import kotlinx.coroutines.CoroutineScope
37 import kotlinx.coroutines.Dispatchers
38 
39 /** Impl of [BluetoothFeatureProvider] */
40 open class BluetoothFeatureProviderImpl : BluetoothFeatureProvider {
getBluetoothDeviceSettingsUrinull41     override fun getBluetoothDeviceSettingsUri(bluetoothDevice: BluetoothDevice): Uri? {
42         val uriByte = bluetoothDevice.getMetadata(BluetoothDevice.METADATA_ENHANCED_SETTINGS_UI_URI)
43         return uriByte?.let { Uri.parse(String(it)) }
44     }
45 
getBluetoothDeviceControlUrinull46     override fun getBluetoothDeviceControlUri(bluetoothDevice: BluetoothDevice): String? {
47         return BluetoothUtils.getControlUriMetaData(bluetoothDevice)
48     }
49 
getRelatedToolsnull50     override fun getRelatedTools(): List<ComponentName>? {
51         return null
52     }
53 
getSpatializernull54     override fun getSpatializer(context: Context): Spatializer {
55         val audioManager = context.getSystemService(AudioManager::class.java)
56         return audioManager.spatializer
57     }
58 
getBluetoothExtraOptionsnull59     override fun getBluetoothExtraOptions(
60         context: Context,
61         device: CachedBluetoothDevice
62     ): List<Preference>? {
63         return ImmutableList.of<Preference>()
64     }
65 
getInvisibleProfilePreferenceKeysnull66     override fun getInvisibleProfilePreferenceKeys(
67         context: Context,
68         bluetoothDevice: BluetoothDevice
69     ): Set<String> {
70         return ImmutableSet.of()
71     }
72 
getDeviceSettingRepositorynull73     override fun getDeviceSettingRepository(
74         context: Context,
75         bluetoothAdapter: BluetoothAdapter,
76         scope: CoroutineScope
77     ): DeviceSettingRepository =
78         DeviceSettingRepositoryImpl(context, bluetoothAdapter, scope, Dispatchers.IO)
79 
80     override fun getDeviceDetailsFragmentFormatter(
81         context: Context,
82         fragment: DashboardFragment,
83         bluetoothAdapter: BluetoothAdapter,
84         cachedDevice: CachedBluetoothDevice,
85         controllers: List<AbstractPreferenceController>,
86     ): DeviceDetailsFragmentFormatter {
87         return DeviceDetailsFragmentFormatterImpl(
88             context,
89             fragment,
90             controllers,
91             bluetoothAdapter,
92             cachedDevice,
93             Dispatchers.IO
94         )
95     }
96 }
97