1 /* 2 * Copyright (C) 2023 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.settings.connecteddevice.audiosharing; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.util.Log; 22 23 import androidx.annotation.Nullable; 24 import androidx.preference.Preference; 25 26 import com.android.settings.bluetooth.BluetoothDeviceUpdater; 27 import com.android.settings.bluetooth.Utils; 28 import com.android.settings.connecteddevice.DevicePreferenceCallback; 29 import com.android.settingslib.bluetooth.BluetoothUtils; 30 import com.android.settingslib.bluetooth.CachedBluetoothDevice; 31 import com.android.settingslib.bluetooth.LocalBluetoothManager; 32 33 public class AudioSharingBluetoothDeviceUpdater extends BluetoothDeviceUpdater 34 implements Preference.OnPreferenceClickListener { 35 36 private static final String TAG = "AudioSharingBluetoothDeviceUpdater"; 37 38 private static final String PREF_KEY = "audio_sharing_bt"; 39 40 @Nullable private LocalBluetoothManager mLocalBtManager; 41 AudioSharingBluetoothDeviceUpdater( Context context, DevicePreferenceCallback devicePreferenceCallback, int metricsCategory)42 public AudioSharingBluetoothDeviceUpdater( 43 Context context, 44 DevicePreferenceCallback devicePreferenceCallback, 45 int metricsCategory) { 46 super(context, devicePreferenceCallback, metricsCategory); 47 mLocalBtManager = Utils.getLocalBluetoothManager(context); 48 } 49 50 @Override isFilterMatched(CachedBluetoothDevice cachedDevice)51 public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) { 52 boolean isFilterMatched = false; 53 if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) { 54 // If device is LE audio device and has a broadcast source, 55 // it would show in audio sharing devices group. 56 if (AudioSharingUtils.isFeatureEnabled() 57 && cachedDevice.isConnectedLeAudioDevice() 58 && BluetoothUtils.hasConnectedBroadcastSource(cachedDevice, mLocalBtManager)) { 59 isFilterMatched = true; 60 } 61 } 62 Log.d( 63 TAG, 64 "isFilterMatched() device : " 65 + cachedDevice.getName() 66 + ", isFilterMatched : " 67 + isFilterMatched); 68 return isFilterMatched; 69 } 70 71 @Override onPreferenceClick(Preference preference)72 public boolean onPreferenceClick(Preference preference) { 73 mMetricsFeatureProvider.logClickedPreference(preference, mMetricsCategory); 74 mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_AUDIO_SHARING_DEVICE_CLICK); 75 return true; 76 } 77 78 @Override getPreferenceKey()79 protected String getPreferenceKey() { 80 return PREF_KEY; 81 } 82 83 @Override getLogTag()84 protected String getLogTag() { 85 return TAG; 86 } 87 88 @Override update(CachedBluetoothDevice cachedBluetoothDevice)89 protected void update(CachedBluetoothDevice cachedBluetoothDevice) { 90 super.update(cachedBluetoothDevice); 91 Log.d(TAG, "Map : " + mPreferenceMap); 92 } 93 } 94