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