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.content.Context; 20 import android.util.Log; 21 22 import androidx.annotation.Nullable; 23 import androidx.annotation.VisibleForTesting; 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 import com.android.settingslib.utils.ThreadUtils; 33 34 public class AudioSharingBluetoothDeviceUpdater extends BluetoothDeviceUpdater 35 implements Preference.OnPreferenceClickListener { 36 37 private static final String TAG = "AudioSharingBluetoothDeviceUpdater"; 38 39 @VisibleForTesting 40 static final String PREF_KEY_PREFIX = "audio_sharing_bt_"; 41 42 @Nullable private LocalBluetoothManager mLocalBtManager; 43 AudioSharingBluetoothDeviceUpdater( Context context, DevicePreferenceCallback devicePreferenceCallback, int metricsCategory)44 public AudioSharingBluetoothDeviceUpdater( 45 Context context, 46 DevicePreferenceCallback devicePreferenceCallback, 47 int metricsCategory) { 48 super(context, devicePreferenceCallback, metricsCategory); 49 mLocalBtManager = Utils.getLocalBluetoothManager(context); 50 } 51 52 @Override isFilterMatched(CachedBluetoothDevice cachedDevice)53 public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) { 54 boolean isFilterMatched = false; 55 if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) { 56 // If device is LE audio device and has a broadcast source, 57 // it would show in audio sharing devices group. 58 if (BluetoothUtils.isAudioSharingUIAvailable(mContext) 59 && (cachedDevice.isConnectedLeAudioDevice() 60 || cachedDevice.hasConnectedLeAudioMemberDevice()) 61 && BluetoothUtils.hasConnectedBroadcastSource(cachedDevice, mLocalBtManager)) { 62 isFilterMatched = true; 63 } 64 } 65 Log.d( 66 TAG, 67 "isFilterMatched() device : " 68 + cachedDevice.getName() 69 + ", isFilterMatched : " 70 + isFilterMatched); 71 return isFilterMatched; 72 } 73 74 @Override onPreferenceClick(Preference preference)75 public boolean onPreferenceClick(Preference preference) { 76 mMetricsFeatureProvider.logClickedPreference(preference, mMetricsCategory); 77 var unused = 78 ThreadUtils.postOnBackgroundThread( 79 () -> mDevicePreferenceCallback.onDeviceClick(preference)); 80 return true; 81 } 82 83 @Override getPreferenceKeyPrefix()84 protected String getPreferenceKeyPrefix() { 85 return PREF_KEY_PREFIX; 86 } 87 88 @Override getLogTag()89 protected String getLogTag() { 90 return TAG; 91 } 92 93 @Override update(CachedBluetoothDevice cachedBluetoothDevice)94 protected void update(CachedBluetoothDevice cachedBluetoothDevice) { 95 super.update(cachedBluetoothDevice); 96 Log.d(TAG, "Map : " + mPreferenceMap); 97 } 98 } 99