1 /* 2 * Copyright (C) 2017 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 static com.google.common.truth.Truth.assertThat; 19 20 import static org.mockito.ArgumentMatchers.any; 21 import static org.mockito.Mockito.doNothing; 22 import static org.mockito.Mockito.doReturn; 23 import static org.mockito.Mockito.doThrow; 24 import static org.mockito.Mockito.never; 25 import static org.mockito.Mockito.spy; 26 import static org.mockito.Mockito.verify; 27 import static org.mockito.Mockito.when; 28 29 import android.bluetooth.BluetoothAdapter; 30 import android.bluetooth.BluetoothDevice; 31 import android.bluetooth.BluetoothProfile; 32 import android.content.Context; 33 import android.content.pm.ApplicationInfo; 34 import android.content.pm.PackageManager; 35 import android.graphics.drawable.Drawable; 36 import android.media.AudioManager; 37 import android.util.Pair; 38 39 import com.android.settings.connecteddevice.DevicePreferenceCallback; 40 import com.android.settings.dashboard.DashboardFragment; 41 import com.android.settings.testutils.shadow.ShadowAudioManager; 42 import com.android.settings.testutils.shadow.ShadowBluetoothAdapter; 43 import com.android.settings.testutils.shadow.ShadowCachedBluetoothDeviceManager; 44 import com.android.settingslib.bluetooth.CachedBluetoothDevice; 45 46 import org.junit.Before; 47 import org.junit.Test; 48 import org.junit.runner.RunWith; 49 import org.mockito.Mock; 50 import org.mockito.MockitoAnnotations; 51 import org.robolectric.RobolectricTestRunner; 52 import org.robolectric.RuntimeEnvironment; 53 import org.robolectric.annotation.Config; 54 import org.robolectric.shadow.api.Shadow; 55 56 import java.util.ArrayList; 57 import java.util.Collection; 58 59 @RunWith(RobolectricTestRunner.class) 60 @Config(shadows = {ShadowAudioManager.class, ShadowBluetoothAdapter.class, 61 ShadowCachedBluetoothDeviceManager.class}) 62 public class ConnectedBluetoothDeviceUpdaterTest { 63 64 private static final String MAC_ADDRESS = "04:52:C7:0B:D8:3C"; 65 private static final String TEST_EXCLUSIVE_MANAGER = "com.test.manager"; 66 67 @Mock 68 private DashboardFragment mDashboardFragment; 69 @Mock 70 private DevicePreferenceCallback mDevicePreferenceCallback; 71 @Mock 72 private CachedBluetoothDevice mCachedBluetoothDevice; 73 @Mock 74 private BluetoothDevice mBluetoothDevice; 75 @Mock 76 private Drawable mDrawable; 77 @Mock 78 private PackageManager mPackageManager; 79 80 private Context mContext; 81 private ConnectedBluetoothDeviceUpdater mBluetoothDeviceUpdater; 82 private Collection<CachedBluetoothDevice> mCachedDevices; 83 private AudioManager mAudioManager; 84 private ShadowBluetoothAdapter mShadowBluetoothAdapter; 85 private ShadowCachedBluetoothDeviceManager mShadowCachedBluetoothDeviceManager; 86 87 @Before setUp()88 public void setUp() { 89 MockitoAnnotations.initMocks(this); 90 91 Pair<Drawable, String> pairs = new Pair<>(mDrawable, "fake_device"); 92 mContext = spy(RuntimeEnvironment.application); 93 mAudioManager = mContext.getSystemService(AudioManager.class); 94 mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); 95 mShadowBluetoothAdapter.setEnabled(true); 96 mShadowCachedBluetoothDeviceManager = Shadow.extract( 97 Utils.getLocalBtManager(mContext).getCachedDeviceManager()); 98 doReturn(mContext).when(mDashboardFragment).getContext(); 99 mCachedDevices = new ArrayList<>(); 100 mCachedDevices.add(mCachedBluetoothDevice); 101 102 when(mContext.getPackageManager()).thenReturn(mPackageManager); 103 when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); 104 when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS); 105 when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs); 106 mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices); 107 } 108 109 @Test onAudioModeChanged_hfpDeviceConnected_notInCall_addPreference()110 public void onAudioModeChanged_hfpDeviceConnected_notInCall_addPreference() { 111 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 112 when(mBluetoothDeviceUpdater. 113 isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 114 when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); 115 116 mBluetoothDeviceUpdater.onAudioModeChanged(); 117 118 verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice); 119 } 120 121 @Test onAudioModeChanged_hfpDeviceConnected_inCall_removePreference()122 public void onAudioModeChanged_hfpDeviceConnected_inCall_removePreference() { 123 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL); 124 when(mBluetoothDeviceUpdater. 125 isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 126 when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); 127 128 mBluetoothDeviceUpdater.onAudioModeChanged(); 129 130 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 131 } 132 133 @Test onAudioModeChanged_a2dpDeviceConnected_notInCall_removePreference()134 public void onAudioModeChanged_a2dpDeviceConnected_notInCall_removePreference() { 135 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 136 when(mBluetoothDeviceUpdater. 137 isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 138 when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); 139 140 mBluetoothDeviceUpdater.onAudioModeChanged(); 141 142 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 143 } 144 145 @Test onAudioModeChanged_a2dpDeviceConnected_inCall_addPreference()146 public void onAudioModeChanged_a2dpDeviceConnected_inCall_addPreference() { 147 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL); 148 when(mBluetoothDeviceUpdater. 149 isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 150 when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); 151 152 mBluetoothDeviceUpdater.onAudioModeChanged(); 153 154 verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice); 155 } 156 157 @Test onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_addPreference()158 public void onProfileConnectionStateChanged_a2dpDeviceConnected_inCall_addPreference() { 159 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL); 160 when(mBluetoothDeviceUpdater. 161 isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 162 when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); 163 164 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 165 BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP); 166 167 verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice); 168 } 169 170 @Test onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovePreference()171 public void onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovePreference() { 172 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL); 173 when(mBluetoothDeviceUpdater. 174 isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 175 when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); 176 mCachedDevices.clear(); 177 178 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 179 BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP); 180 181 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 182 } 183 184 @Test onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference()185 public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() { 186 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 187 when(mBluetoothDeviceUpdater. 188 isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 189 when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true); 190 191 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 192 BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP); 193 194 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 195 } 196 197 @Test onProfileConnectionStateChanged_hfpDeviceConnected_inCall_removePreference()198 public void onProfileConnectionStateChanged_hfpDeviceConnected_inCall_removePreference() { 199 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL); 200 when(mBluetoothDeviceUpdater. 201 isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 202 when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); 203 204 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 205 BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP); 206 207 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 208 } 209 210 @Test onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_addPreference()211 public void onProfileConnectionStateChanged_hfpDeviceConnected_notInCall_addPreference() { 212 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 213 when(mBluetoothDeviceUpdater. 214 isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 215 when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); 216 217 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 218 BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP); 219 220 verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice); 221 } 222 223 @Test onProfileConnectionStateChanged_ashaHearingAidConnected_inCall_removePreference()224 public void onProfileConnectionStateChanged_ashaHearingAidConnected_inCall_removePreference() 225 { 226 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL); 227 when(mBluetoothDeviceUpdater. 228 isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 229 when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true); 230 231 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 232 BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID); 233 234 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 235 } 236 237 @Test onProfileConnectionStateChanged_ashaHearingAidConnected_notInCall_removePreference()238 public void onProfileConnectionStateChanged_ashaHearingAidConnected_notInCall_removePreference() 239 { 240 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 241 when(mBluetoothDeviceUpdater. 242 isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 243 when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true); 244 245 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 246 BluetoothProfile.STATE_CONNECTED, BluetoothProfile.HEARING_AID); 247 248 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 249 } 250 251 @Test onProfileConnectionStateChanged_leAudioDeviceConnected_inCall_removesPreference()252 public void onProfileConnectionStateChanged_leAudioDeviceConnected_inCall_removesPreference() { 253 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL); 254 when(mBluetoothDeviceUpdater 255 .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 256 when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true); 257 258 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 259 BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO); 260 261 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 262 } 263 264 @Test onProfileConnectionStateChanged_hasLeaMemberConnected_inCall_removesPreference()265 public void onProfileConnectionStateChanged_hasLeaMemberConnected_inCall_removesPreference() { 266 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL); 267 when(mBluetoothDeviceUpdater 268 .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 269 when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(false); 270 when(mCachedBluetoothDevice.hasConnectedLeAudioMemberDevice()).thenReturn(true); 271 272 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 273 BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO); 274 275 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 276 } 277 278 @Test onProfileConnectionStateChanged_leAudioDeviceConnected_notInCall_removesPreference()279 public void onProfileConnectionStateChanged_leAudioDeviceConnected_notInCall_removesPreference() 280 { 281 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 282 when(mBluetoothDeviceUpdater 283 .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 284 when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true); 285 286 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 287 BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO); 288 289 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 290 } 291 292 @Test 293 public void onProfileConnectionStateChanged_hasLeaMemberConnected_notInCall_removesPreference()294 onProfileConnectionStateChanged_hasLeaMemberConnected_notInCall_removesPreference() { 295 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 296 when(mBluetoothDeviceUpdater 297 .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 298 when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(false); 299 when(mCachedBluetoothDevice.hasConnectedLeAudioMemberDevice()).thenReturn(true); 300 301 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 302 BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO); 303 304 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 305 } 306 307 @Test onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovesPreference()308 public void onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovesPreference() 309 { 310 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL); 311 when(mBluetoothDeviceUpdater 312 .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 313 when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true); 314 mCachedDevices.clear(); 315 316 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 317 BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO); 318 319 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 320 } 321 322 @Test onProfileConnectionStateChanged_deviceIsNotInList_notInCall_invokesRemovesPreference()323 public void onProfileConnectionStateChanged_deviceIsNotInList_notInCall_invokesRemovesPreference 324 () { 325 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 326 when(mBluetoothDeviceUpdater 327 .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 328 when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true); 329 mCachedDevices.clear(); 330 331 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 332 BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO); 333 334 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 335 } 336 337 @Test onProfileConnectionStateChanged_deviceDisconnected_removePreference()338 public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() { 339 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 340 mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, 341 BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.A2DP); 342 343 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 344 } 345 346 @Test addPreference_addPreference_shouldHideSecondTarget()347 public void addPreference_addPreference_shouldHideSecondTarget() { 348 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 349 BluetoothDevicePreference btPreference = 350 new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, 351 true, BluetoothDevicePreference.SortType.TYPE_DEFAULT); 352 mBluetoothDeviceUpdater.mPreferenceMap.put(mBluetoothDevice, btPreference); 353 354 mBluetoothDeviceUpdater.addPreference(mCachedBluetoothDevice); 355 356 assertThat(btPreference.shouldHideSecondTarget()).isTrue(); 357 } 358 359 @Test update_notExclusiveManagedDevice_addDevice()360 public void update_notExclusiveManagedDevice_addDevice() { 361 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 362 when(mBluetoothDeviceUpdater 363 .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 364 when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); 365 when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn( 366 null); 367 368 mBluetoothDeviceUpdater.update(mCachedBluetoothDevice); 369 370 verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice); 371 } 372 373 @Test update_exclusivelyManagedDevice_packageNotInstalled_addDevice()374 public void update_exclusivelyManagedDevice_packageNotInstalled_addDevice() 375 throws Exception { 376 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 377 when(mBluetoothDeviceUpdater 378 .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 379 when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); 380 when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn( 381 TEST_EXCLUSIVE_MANAGER.getBytes()); 382 doThrow(new PackageManager.NameNotFoundException()).when(mPackageManager) 383 .getApplicationInfo(TEST_EXCLUSIVE_MANAGER, 0); 384 385 mBluetoothDeviceUpdater.update(mCachedBluetoothDevice); 386 387 verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice); 388 } 389 390 @Test update_exclusivelyManagedDevice_packageNotEnabled_addDevice()391 public void update_exclusivelyManagedDevice_packageNotEnabled_addDevice() 392 throws Exception { 393 ApplicationInfo appInfo = new ApplicationInfo(); 394 appInfo.enabled = false; 395 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 396 when(mBluetoothDeviceUpdater 397 .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 398 when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); 399 when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn( 400 TEST_EXCLUSIVE_MANAGER.getBytes()); 401 doReturn(appInfo).when(mPackageManager).getApplicationInfo(TEST_EXCLUSIVE_MANAGER, 0); 402 403 mBluetoothDeviceUpdater.update(mCachedBluetoothDevice); 404 405 verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice); 406 } 407 408 @Test update_exclusivelyManagedDevice_packageInstalledAndEnabled_removePreference()409 public void update_exclusivelyManagedDevice_packageInstalledAndEnabled_removePreference() 410 throws Exception { 411 setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); 412 when(mBluetoothDeviceUpdater 413 .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); 414 when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true); 415 when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_EXCLUSIVE_MANAGER)).thenReturn( 416 TEST_EXCLUSIVE_MANAGER.getBytes()); 417 doReturn(new ApplicationInfo()).when(mPackageManager).getApplicationInfo( 418 TEST_EXCLUSIVE_MANAGER, 0); 419 420 mBluetoothDeviceUpdater.update(mCachedBluetoothDevice); 421 422 verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); 423 verify(mBluetoothDeviceUpdater, never()).addPreference(mCachedBluetoothDevice); 424 } 425 setUpDeviceUpdaterWithAudioMode(int audioMode)426 private void setUpDeviceUpdaterWithAudioMode(int audioMode) { 427 mAudioManager.setMode(audioMode); 428 mBluetoothDeviceUpdater = spy(new ConnectedBluetoothDeviceUpdater(mContext, 429 mDevicePreferenceCallback, /* metricsCategory= */ 0)); 430 mBluetoothDeviceUpdater.setPrefContext(mContext); 431 doNothing().when(mBluetoothDeviceUpdater).addPreference(any()); 432 doNothing().when(mBluetoothDeviceUpdater).removePreference( 433 any(CachedBluetoothDevice.class)); 434 } 435 } 436