blob: 7863fc5887789cb65737fff648142fcc070a2ef9 [file] [log] [blame]
Jack He6258aae2017-06-29 17:01:23 -07001/*
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 */
16package com.android.settingslib.bluetooth;
17
18import static com.google.common.truth.Truth.assertThat;
Jack Hec219bc92017-07-24 14:55:59 -070019import static org.mockito.Matchers.any;
20import static org.mockito.Matchers.anyString;
Jack He6258aae2017-06-29 17:01:23 -070021import static org.mockito.Mockito.doAnswer;
Jack Hec219bc92017-07-24 14:55:59 -070022import static org.mockito.Mockito.never;
Jack He6258aae2017-06-29 17:01:23 -070023import static org.mockito.Mockito.spy;
Jack Hec219bc92017-07-24 14:55:59 -070024import static org.mockito.Mockito.verify;
Jack He6258aae2017-06-29 17:01:23 -070025import static org.mockito.Mockito.when;
26
27import android.bluetooth.BluetoothAdapter;
28import android.bluetooth.BluetoothDevice;
29import android.bluetooth.BluetoothProfile;
30import android.content.Context;
31
Jack He6258aae2017-06-29 17:01:23 -070032import org.junit.Before;
33import org.junit.Test;
34import org.junit.runner.RunWith;
35import org.mockito.Mock;
36import org.mockito.MockitoAnnotations;
37import org.robolectric.RobolectricTestRunner;
38import org.robolectric.RuntimeEnvironment;
39import org.robolectric.annotation.Config;
40
41@RunWith(RobolectricTestRunner.class)
James Lemieux5c50dc12018-02-12 01:30:32 -080042@Config(resourceDir = "../../res")
Jack He6258aae2017-06-29 17:01:23 -070043public class CachedBluetoothDeviceTest {
Jack Hec219bc92017-07-24 14:55:59 -070044 private final static String DEVICE_NAME = "TestName";
45 private final static String DEVICE_ALIAS = "TestAlias";
46 private final static String DEVICE_ADDRESS = "AA:BB:CC:DD:EE:FF";
47 private final static String DEVICE_ALIAS_NEW = "TestAliasNew";
Jack He6258aae2017-06-29 17:01:23 -070048 @Mock
49 private LocalBluetoothAdapter mAdapter;
50 @Mock
51 private LocalBluetoothProfileManager mProfileManager;
52 @Mock
53 private HeadsetProfile mHfpProfile;
54 @Mock
55 private A2dpProfile mA2dpProfile;
56 @Mock
Hansong Zhang1c1bc252017-10-30 16:38:16 -070057 private PanProfile mPanProfile;
Jack He6258aae2017-06-29 17:01:23 -070058 @Mock
Hansong Zhangd7b35912018-03-16 09:15:48 -070059 private HearingAidProfile mHearingAidProfile;
60 @Mock
Jack He6258aae2017-06-29 17:01:23 -070061 private BluetoothDevice mDevice;
62 private CachedBluetoothDevice mCachedDevice;
63 private Context mContext;
64 private int mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
65
66 @Before
67 public void setUp() {
68 MockitoAnnotations.initMocks(this);
69 mContext = RuntimeEnvironment.application;
Jack Hec219bc92017-07-24 14:55:59 -070070 when(mDevice.getAddress()).thenReturn(DEVICE_ADDRESS);
Jack He6258aae2017-06-29 17:01:23 -070071 when(mAdapter.getBluetoothState()).thenReturn(BluetoothAdapter.STATE_ON);
72 when(mHfpProfile.isProfileReady()).thenReturn(true);
73 when(mA2dpProfile.isProfileReady()).thenReturn(true);
Hansong Zhang1c1bc252017-10-30 16:38:16 -070074 when(mPanProfile.isProfileReady()).thenReturn(true);
Hansong Zhangd7b35912018-03-16 09:15:48 -070075 when(mHearingAidProfile.isProfileReady()).thenReturn(true);
Jack He6258aae2017-06-29 17:01:23 -070076 mCachedDevice = spy(
77 new CachedBluetoothDevice(mContext, mAdapter, mProfileManager, mDevice));
78 doAnswer((invocation) -> mBatteryLevel).when(mCachedDevice).getBatteryLevel();
79 }
80
Jack He6258aae2017-06-29 17:01:23 -070081 @Test
82 public void testGetConnectionSummary_testSingleProfileConnectDisconnect() {
83 // Test without battery level
Hansong Zhang1c1bc252017-10-30 16:38:16 -070084 // Set PAN profile to be connected and test connection state summary
85 mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_CONNECTED);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -080086 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected");
Jack He6258aae2017-06-29 17:01:23 -070087
Hansong Zhang1c1bc252017-10-30 16:38:16 -070088 // Set PAN profile to be disconnected and test connection state summary
89 mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_DISCONNECTED);
Jack He6258aae2017-06-29 17:01:23 -070090 assertThat(mCachedDevice.getConnectionSummary()).isNull();
91
92 // Test with battery level
93 mBatteryLevel = 10;
Hansong Zhang1c1bc252017-10-30 16:38:16 -070094 // Set PAN profile to be connected and test connection state summary
95 mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_CONNECTED);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -080096 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, battery 10%");
Jack He6258aae2017-06-29 17:01:23 -070097
Hansong Zhang1c1bc252017-10-30 16:38:16 -070098 // Set PAN profile to be disconnected and test connection state summary
99 mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_DISCONNECTED);
Jack He6258aae2017-06-29 17:01:23 -0700100 assertThat(mCachedDevice.getConnectionSummary()).isNull();
101
102 // Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level
103 mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
104
Hansong Zhang1c1bc252017-10-30 16:38:16 -0700105 // Set PAN profile to be connected and test connection state summary
106 mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_CONNECTED);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800107 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected");
Jack He6258aae2017-06-29 17:01:23 -0700108
Hansong Zhang1c1bc252017-10-30 16:38:16 -0700109 // Set PAN profile to be disconnected and test connection state summary
110 mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_DISCONNECTED);
Jack He6258aae2017-06-29 17:01:23 -0700111 assertThat(mCachedDevice.getConnectionSummary()).isNull();
112 }
113
114 @Test
115 public void testGetConnectionSummary_testMultipleProfileConnectDisconnect() {
116 mBatteryLevel = 10;
117
Hansong Zhang1c1bc252017-10-30 16:38:16 -0700118 // Set HFP, A2DP and PAN profile to be connected and test connection state summary
Jack He6258aae2017-06-29 17:01:23 -0700119 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
120 mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
Hansong Zhang1c1bc252017-10-30 16:38:16 -0700121 mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_CONNECTED);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800122 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, battery 10%");
Jack He6258aae2017-06-29 17:01:23 -0700123
124 // Disconnect HFP only and test connection state summary
125 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800126 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
127 "Connected (no phone), battery 10%");
Jack He6258aae2017-06-29 17:01:23 -0700128
129 // Disconnect A2DP only and test connection state summary
130 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
131 mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800132 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
133 "Connected (no media), battery 10%");
Jack He6258aae2017-06-29 17:01:23 -0700134
135 // Disconnect both HFP and A2DP and test connection state summary
136 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800137 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
138 "Connected (no phone or media), battery 10%");
Jack He6258aae2017-06-29 17:01:23 -0700139
140 // Disconnect all profiles and test connection state summary
Hansong Zhang1c1bc252017-10-30 16:38:16 -0700141 mCachedDevice.onProfileStateChanged(mPanProfile, BluetoothProfile.STATE_DISCONNECTED);
Jack He6258aae2017-06-29 17:01:23 -0700142 assertThat(mCachedDevice.getConnectionSummary()).isNull();
143 }
Jack Hec219bc92017-07-24 14:55:59 -0700144
145 @Test
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800146 public void testGetConnectionSummary_testSingleProfileActiveDeviceA2dp() {
147 // Test without battery level
148 // Set A2DP profile to be connected and test connection state summary
149 mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
150 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected");
151
152 // Set device as Active for A2DP and test connection state summary
Pavlin Radoslavovc285d552018-02-06 16:14:00 -0800153 mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800154 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, active(media)");
155
156 // Test with battery level
157 mBatteryLevel = 10;
158 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
159 "Connected, battery 10%, active(media)");
160
161 // Set A2DP profile to be disconnected and test connection state summary
162 mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED);
163 assertThat(mCachedDevice.getConnectionSummary()).isNull();
164
165 // Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level
166 mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
167 // Set A2DP profile to be connected, Active and test connection state summary
168 mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
Pavlin Radoslavovc285d552018-02-06 16:14:00 -0800169 mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800170 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, active(media)");
171
172 // Set A2DP profile to be disconnected and test connection state summary
173 mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED);
174 assertThat(mCachedDevice.getConnectionSummary()).isNull();
175 }
176
177 @Test
178 public void testGetConnectionSummary_testSingleProfileActiveDeviceHfp() {
179 // Test without battery level
180 // Set HFP profile to be connected and test connection state summary
181 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
182 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected");
183
184 // Set device as Active for HFP and test connection state summary
Pavlin Radoslavovc285d552018-02-06 16:14:00 -0800185 mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEADSET);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800186 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, active(phone)");
187
188 // Test with battery level
189 mBatteryLevel = 10;
190 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
191 "Connected, battery 10%, active(phone)");
192
193 // Set HFP profile to be disconnected and test connection state summary
194 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
195 assertThat(mCachedDevice.getConnectionSummary()).isNull();
196
197 // Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level
198 mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
199 // Set HFP profile to be connected, Active and test connection state summary
200 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
Pavlin Radoslavovc285d552018-02-06 16:14:00 -0800201 mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEADSET);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800202 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, active(phone)");
203
204 // Set HFP profile to be disconnected and test connection state summary
205 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
206 assertThat(mCachedDevice.getConnectionSummary()).isNull();
207 }
208
209 @Test
Hansong Zhangd7b35912018-03-16 09:15:48 -0700210 public void testGetConnectionSummary_testSingleProfileActiveDeviceHearingAid() {
211 // Test without battery level
212 // Set Hearing Aid profile to be connected and test connection state summary
213 mCachedDevice.onProfileStateChanged(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED);
214 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected");
215
216 // Set device as Active for Hearing Aid and test connection state summary
217 mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEARING_AID);
218 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, active");
219
220 // Set Hearing Aid profile to be disconnected and test connection state summary
221 mCachedDevice.onActiveDeviceChanged(false, BluetoothProfile.HEARING_AID);
222 mCachedDevice.onProfileStateChanged(mHearingAidProfile, BluetoothProfile.STATE_DISCONNECTED);
223 assertThat(mCachedDevice.getConnectionSummary()).isNull();
224 }
225
226 @Test
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800227 public void testGetConnectionSummary_testMultipleProfilesActiveDevice() {
228 // Test without battery level
229 // Set A2DP and HFP profiles to be connected and test connection state summary
230 mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
231 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
232 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected");
233
234 // Set device as Active for A2DP and HFP and test connection state summary
Pavlin Radoslavovc285d552018-02-06 16:14:00 -0800235 mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP);
236 mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEADSET);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800237 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, active");
238
239 // Test with battery level
240 mBatteryLevel = 10;
241 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
242 "Connected, battery 10%, active");
243
244 // Disconnect A2DP only and test connection state summary
Pavlin Radoslavovc285d552018-02-06 16:14:00 -0800245 mCachedDevice.onActiveDeviceChanged(false, BluetoothProfile.A2DP);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800246 mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED);
247 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
248 "Connected (no media), battery 10%, active(phone)");
249
250 // Disconnect HFP only and test connection state summary
Pavlin Radoslavovc285d552018-02-06 16:14:00 -0800251 mCachedDevice.onActiveDeviceChanged(false, BluetoothProfile.HEADSET);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800252 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
253 mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
Pavlin Radoslavovc285d552018-02-06 16:14:00 -0800254 mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800255 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo(
256 "Connected (no phone), battery 10%, active(media)");
257
258 // Test with BluetoothDevice.BATTERY_LEVEL_UNKNOWN battery level
259 mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN;
260 // Set A2DP and HFP profiles to be connected, Active and test connection state summary
261 mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
262 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
Pavlin Radoslavovc285d552018-02-06 16:14:00 -0800263 mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.A2DP);
264 mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.HEADSET);
Pavlin Radoslavove6e080f2018-02-06 12:21:34 -0800265 assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Connected, active");
266
267 // Set A2DP and HFP profiles to be disconnected and test connection state summary
268 mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED);
269 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
270 assertThat(mCachedDevice.getConnectionSummary()).isNull();
271 }
272
273 @Test
Jack Hec219bc92017-07-24 14:55:59 -0700274 public void testDeviceName_testAliasNameAvailable() {
275 when(mDevice.getAliasName()).thenReturn(DEVICE_ALIAS);
276 when(mDevice.getName()).thenReturn(DEVICE_NAME);
277 CachedBluetoothDevice cachedBluetoothDevice =
278 new CachedBluetoothDevice(mContext, mAdapter, mProfileManager, mDevice);
279 // Verify alias is returned on getName
280 assertThat(cachedBluetoothDevice.getName()).isEqualTo(DEVICE_ALIAS);
281 // Verify device is visible
282 assertThat(cachedBluetoothDevice.hasHumanReadableName()).isTrue();
283 }
284
285 @Test
286 public void testDeviceName_testNameNotAvailable() {
287 CachedBluetoothDevice cachedBluetoothDevice =
288 new CachedBluetoothDevice(mContext, mAdapter, mProfileManager, mDevice);
289 // Verify device address is returned on getName
290 assertThat(cachedBluetoothDevice.getName()).isEqualTo(DEVICE_ADDRESS);
291 // Verify device is not visible
292 assertThat(cachedBluetoothDevice.hasHumanReadableName()).isFalse();
293 }
294
295 @Test
296 public void testDeviceName_testRenameDevice() {
297 final String[] alias = {DEVICE_ALIAS};
298 doAnswer(invocation -> alias[0]).when(mDevice).getAliasName();
299 doAnswer(invocation -> {
300 alias[0] = (String) invocation.getArguments()[0];
301 return true;
302 }).when(mDevice).setAlias(anyString());
303 when(mDevice.getName()).thenReturn(DEVICE_NAME);
304 CachedBluetoothDevice cachedBluetoothDevice =
305 new CachedBluetoothDevice(mContext, mAdapter, mProfileManager, mDevice);
306 // Verify alias is returned on getName
307 assertThat(cachedBluetoothDevice.getName()).isEqualTo(DEVICE_ALIAS);
308 // Verify null name does not get set
309 cachedBluetoothDevice.setName(null);
310 verify(mDevice, never()).setAlias(any());
311 // Verify new name is set properly
312 cachedBluetoothDevice.setName(DEVICE_ALIAS_NEW);
313 verify(mDevice).setAlias(DEVICE_ALIAS_NEW);
314 // Verify new alias is returned on getName
315 assertThat(cachedBluetoothDevice.getName()).isEqualTo(DEVICE_ALIAS_NEW);
316 }
Hansong Zhang6a416322018-03-19 18:20:38 -0700317
318 @Test
319 public void testSetActive() {
320 when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
321 when(mProfileManager.getHeadsetProfile()).thenReturn(mHfpProfile);
322 when(mA2dpProfile.setActiveDevice(any(BluetoothDevice.class))).thenReturn(true);
323 when(mHfpProfile.setActiveDevice(any(BluetoothDevice.class))).thenReturn(true);
324
325 assertThat(mCachedDevice.setActive()).isFalse();
326
327 mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_CONNECTED);
328 assertThat(mCachedDevice.setActive()).isTrue();
329
330 mCachedDevice.onProfileStateChanged(mA2dpProfile, BluetoothProfile.STATE_DISCONNECTED);
331 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_CONNECTED);
332 assertThat(mCachedDevice.setActive()).isTrue();
333
334 mCachedDevice.onProfileStateChanged(mHfpProfile, BluetoothProfile.STATE_DISCONNECTED);
335 assertThat(mCachedDevice.setActive()).isFalse();
336 }
hughchen23b947e2018-03-31 17:32:53 +0800337
338 @Test
339 public void testIsA2dpDevice_isA2dpDevice() {
340 when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
341 when(mA2dpProfile.getConnectionStatus(mDevice)).
342 thenReturn(BluetoothProfile.STATE_CONNECTED);
343
344 assertThat(mCachedDevice.isA2dpDevice()).isTrue();
345 }
346
347 @Test
348 public void testIsA2dpDevice_isNotA2dpDevice() {
349 when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
350 when(mA2dpProfile.getConnectionStatus(mDevice)).
351 thenReturn(BluetoothProfile.STATE_DISCONNECTING);
352
353 assertThat(mCachedDevice.isA2dpDevice()).isFalse();
354 }
355
356 @Test
357 public void testIsHfpDevice_isHfpDevice() {
358 when(mProfileManager.getHeadsetProfile()).thenReturn(mHfpProfile);
359 when(mHfpProfile.getConnectionStatus(mDevice)).
360 thenReturn(BluetoothProfile.STATE_CONNECTED);
361
362 assertThat(mCachedDevice.isHfpDevice()).isTrue();
363 }
364
365 @Test
366 public void testIsHfpDevice_isNotHfpDevice() {
367 when(mProfileManager.getHeadsetProfile()).thenReturn(mHfpProfile);
368 when(mHfpProfile.getConnectionStatus(mDevice)).
369 thenReturn(BluetoothProfile.STATE_DISCONNECTING);
370
371 assertThat(mCachedDevice.isHfpDevice()).isFalse();
372 }
Jack He6258aae2017-06-29 17:01:23 -0700373}