Merge changes I13495cad,I3a44c4c4,I15bff230,I8a492866,Ia7ffe34a
* changes: [Pair hearing devices] Add pair hearing device functionality [Pair hearing devices] Extract common behavior in BluetoothPairingDetail into Base class [Pair hearing devices] Add "Hearing devices" to show connected hearing devices [Pair hearing devices] Add "Saved devices" to show bonded but not connected hearing devices [Audio routing] Setup basic structure for audio routing page
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Tests for {@link AvailableHearingDeviceUpdater}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothUtils.class})
|
||||
public class AvailableHearingDeviceUpdaterTest {
|
||||
@Rule
|
||||
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Mock
|
||||
private DevicePreferenceCallback mDevicePreferenceCallback;
|
||||
@Mock
|
||||
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||
@Mock
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
@Mock
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
private AvailableHearingDeviceUpdater mUpdater;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
mUpdater = new AvailableHearingDeviceUpdater(mContext,
|
||||
mDevicePreferenceCallback, /* metricsCategory= */ 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFilterMatch_connectedHearingDevice_returnTrue() {
|
||||
CachedBluetoothDevice connectedHearingDevice = mCachedBluetoothDevice;
|
||||
when(connectedHearingDevice.isConnectedHearingAidDevice()).thenReturn(true);
|
||||
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
|
||||
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(
|
||||
new ArrayList<>(List.of(connectedHearingDevice)));
|
||||
|
||||
assertThat(mUpdater.isFilterMatched(connectedHearingDevice)).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFilterMatch_nonConnectedHearingDevice_returnFalse() {
|
||||
CachedBluetoothDevice nonConnectedHearingDevice = mCachedBluetoothDevice;
|
||||
when(nonConnectedHearingDevice.isConnectedHearingAidDevice()).thenReturn(false);
|
||||
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
|
||||
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(
|
||||
new ArrayList<>(List.of(nonConnectedHearingDevice)));
|
||||
|
||||
assertThat(mUpdater.isFilterMatched(nonConnectedHearingDevice)).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFilterMatch_connectedBondingHearingDevice_returnFalse() {
|
||||
CachedBluetoothDevice connectedBondingHearingDevice = mCachedBluetoothDevice;
|
||||
when(connectedBondingHearingDevice.isHearingAidDevice()).thenReturn(true);
|
||||
doReturn(BluetoothDevice.BOND_BONDING).when(mBluetoothDevice).getBondState();
|
||||
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(
|
||||
new ArrayList<>(List.of(connectedBondingHearingDevice)));
|
||||
|
||||
assertThat(mUpdater.isFilterMatched(connectedBondingHearingDevice)).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFilterMatch_hearingDeviceNotInCachedDevicesList_returnFalse() {
|
||||
CachedBluetoothDevice notInCachedDevicesListDevice = mCachedBluetoothDevice;
|
||||
when(notInCachedDevicesListDevice.isHearingAidDevice()).thenReturn(true);
|
||||
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
|
||||
doReturn(false).when(mBluetoothDevice).isConnected();
|
||||
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(new ArrayList<>());
|
||||
|
||||
assertThat(mUpdater.isFilterMatched(notInCachedDevicesListDevice)).isEqualTo(false);
|
||||
}
|
||||
}
|
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
/** Tests for {@link BaseBluetoothDevicePreferenceController}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothUtils.class})
|
||||
public class BaseBluetoothDevicePreferenceControllerTest {
|
||||
@Rule
|
||||
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
|
||||
private static final String FAKE_KEY = "fake_key";
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Mock
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
private PreferenceManager mPreferenceManager;
|
||||
private PreferenceScreen mScreen;
|
||||
private TestBaseBluetoothDevicePreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
FakeFeatureFactory.setupForTest();
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||
mPreferenceCategory = new PreferenceCategory(mContext);
|
||||
mPreferenceCategory.setKey(FAKE_KEY);
|
||||
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
|
||||
mPreferenceManager = new PreferenceManager(mContext);
|
||||
mScreen = mPreferenceManager.createPreferenceScreen(mContext);
|
||||
mScreen.addPreference(mPreferenceCategory);
|
||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||
mController = new TestBaseBluetoothDevicePreferenceController(mContext, FAKE_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_hasBluetoothFeature_available() {
|
||||
doReturn(true).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_noBluetoothFeature_conditionallyUnavailalbe() {
|
||||
doReturn(false).when(mPackageManager).hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_preferenceCategoryInVisible() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreferenceCategory.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceAdded_preferenceCategoryVisible() {
|
||||
Preference preference = new Preference(mContext);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mController.onDeviceAdded(preference);
|
||||
|
||||
assertThat(mPreferenceCategory.isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceRemoved_addedPreferenceFirst_preferenceCategoryInVisible() {
|
||||
Preference preference = new Preference(mContext);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mController.onDeviceAdded(preference);
|
||||
mController.onDeviceRemoved(preference);
|
||||
|
||||
assertThat(mPreferenceCategory.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
public static class TestBaseBluetoothDevicePreferenceController extends
|
||||
BaseBluetoothDevicePreferenceController {
|
||||
|
||||
public TestBaseBluetoothDevicePreferenceController(Context context,
|
||||
String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.bluetooth.BluetoothProgressCategory;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
|
||||
/** Tests for {@link HearingDevicePairingDetail}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothAdapter.class})
|
||||
public class HearingDevicePairingDetailTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
private BluetoothProgressCategory mProgressCategory;
|
||||
private TestHearingDevicePairingDetail mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
final BluetoothAdapter bluetoothAdapter = spy(BluetoothAdapter.getDefaultAdapter());
|
||||
final ShadowBluetoothAdapter shadowBluetoothAdapter = Shadow.extract(
|
||||
BluetoothAdapter.getDefaultAdapter());
|
||||
shadowBluetoothAdapter.setEnabled(true);
|
||||
|
||||
mProgressCategory = spy(new BluetoothProgressCategory(mContext));
|
||||
mFragment = spy(new TestHearingDevicePairingDetail());
|
||||
when(mFragment.getContext()).thenReturn(mContext);
|
||||
when(mFragment.findPreference(
|
||||
HearingDevicePairingDetail.KEY_AVAILABLE_HEARING_DEVICES)).thenReturn(
|
||||
mProgressCategory);
|
||||
mFragment.setBluetoothAdapter(bluetoothAdapter);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDeviceListKey_expectedKey() {
|
||||
assertThat(mFragment.getDeviceListKey()).isEqualTo(
|
||||
HearingDevicePairingDetail.KEY_AVAILABLE_HEARING_DEVICES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceBondStateChanged_bondNone_setProgressFalse() {
|
||||
mFragment.initPreferencesFromPreferenceScreen();
|
||||
|
||||
mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_NONE);
|
||||
|
||||
verify(mProgressCategory).setProgress(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onDeviceBondStateChanged_bonding_setProgressTrue() {
|
||||
mFragment.initPreferencesFromPreferenceScreen();
|
||||
|
||||
mFragment.onDeviceBondStateChanged(mCachedBluetoothDevice, BluetoothDevice.BOND_BONDING);
|
||||
|
||||
verify(mProgressCategory).setProgress(false);
|
||||
}
|
||||
|
||||
private static class TestHearingDevicePairingDetail extends HearingDevicePairingDetail {
|
||||
TestHearingDevicePairingDetail() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void setBluetoothAdapter(BluetoothAdapter bluetoothAdapter) {
|
||||
this.mBluetoothAdapter = bluetoothAdapter;
|
||||
}
|
||||
|
||||
public void enableScanning() {
|
||||
super.enableScanning();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Tests for {@link SavedHearingDeviceUpdater}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothUtils.class})
|
||||
public class SavedHearingDeviceUpdaterTest {
|
||||
@Rule
|
||||
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Mock
|
||||
private DevicePreferenceCallback mDevicePreferenceCallback;
|
||||
@Mock
|
||||
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||
@Mock
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
@Mock
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
private SavedHearingDeviceUpdater mUpdater;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
mUpdater = new SavedHearingDeviceUpdater(mContext,
|
||||
mDevicePreferenceCallback, /* metricsCategory= */ 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFilterMatch_savedHearingDevice_returnTrue() {
|
||||
CachedBluetoothDevice savedHearingDevice = mCachedBluetoothDevice;
|
||||
when(savedHearingDevice.isHearingAidDevice()).thenReturn(true);
|
||||
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
|
||||
doReturn(false).when(mBluetoothDevice).isConnected();
|
||||
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(
|
||||
new ArrayList<>(List.of(savedHearingDevice)));
|
||||
|
||||
assertThat(mUpdater.isFilterMatched(savedHearingDevice)).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFilterMatch_savedNonHearingDevice_returnFalse() {
|
||||
CachedBluetoothDevice savedNonHearingDevice = mCachedBluetoothDevice;
|
||||
when(savedNonHearingDevice.isHearingAidDevice()).thenReturn(false);
|
||||
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
|
||||
doReturn(false).when(mBluetoothDevice).isConnected();
|
||||
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(
|
||||
new ArrayList<>(List.of(savedNonHearingDevice)));
|
||||
|
||||
assertThat(mUpdater.isFilterMatched(savedNonHearingDevice)).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFilterMatch_savedBondingHearingDevice_returnFalse() {
|
||||
CachedBluetoothDevice savedBondingHearingDevice = mCachedBluetoothDevice;
|
||||
when(savedBondingHearingDevice.isHearingAidDevice()).thenReturn(true);
|
||||
doReturn(BluetoothDevice.BOND_BONDING).when(mBluetoothDevice).getBondState();
|
||||
doReturn(false).when(mBluetoothDevice).isConnected();
|
||||
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(
|
||||
new ArrayList<>(List.of(savedBondingHearingDevice)));
|
||||
|
||||
assertThat(mUpdater.isFilterMatched(savedBondingHearingDevice)).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFilterMatch_connectedHearingDevice_returnFalse() {
|
||||
CachedBluetoothDevice connectdHearingDevice = mCachedBluetoothDevice;
|
||||
when(connectdHearingDevice.isHearingAidDevice()).thenReturn(true);
|
||||
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
|
||||
doReturn(true).when(mBluetoothDevice).isConnected();
|
||||
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(
|
||||
new ArrayList<>(List.of(connectdHearingDevice)));
|
||||
|
||||
assertThat(mUpdater.isFilterMatched(connectdHearingDevice)).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFilterMatch_hearingDeviceNotInCachedDevicesList_returnFalse() {
|
||||
CachedBluetoothDevice notInCachedDevicesListDevice = mCachedBluetoothDevice;
|
||||
when(notInCachedDevicesListDevice.isHearingAidDevice()).thenReturn(true);
|
||||
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState();
|
||||
doReturn(false).when(mBluetoothDevice).isConnected();
|
||||
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(new ArrayList<>());
|
||||
|
||||
assertThat(mUpdater.isFilterMatched(notInCachedDevicesListDevice)).isEqualTo(false);
|
||||
}
|
||||
}
|
@@ -96,7 +96,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
||||
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
|
||||
|
||||
mBluetoothDeviceUpdater = spy(new AvailableMediaBluetoothDeviceUpdater(mContext,
|
||||
mDashboardFragment, mDevicePreferenceCallback));
|
||||
mDevicePreferenceCallback, /* metricsCategory= */ 0));
|
||||
mBluetoothDeviceUpdater.setPrefContext(mContext);
|
||||
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false,
|
||||
BluetoothDevicePreference.SortType.TYPE_DEFAULT);
|
||||
|
@@ -16,12 +16,17 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.android.settings.bluetooth.BluetoothDetailsAudioRoutingController.KEY_AUDIO_ROUTING;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.util.FeatureFlagUtils;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -36,6 +41,8 @@ public class BluetoothDetailsAudioRoutingControllerTest extends
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
private static final String TEST_ADDRESS = "55:66:77:88:99:AA";
|
||||
|
||||
private BluetoothDetailsAudioRoutingController mController;
|
||||
|
||||
@Override
|
||||
@@ -44,7 +51,9 @@ public class BluetoothDetailsAudioRoutingControllerTest extends
|
||||
|
||||
mController = new BluetoothDetailsAudioRoutingController(mContext, mFragment, mCachedDevice,
|
||||
mLifecycle);
|
||||
mController.init(mScreen);
|
||||
final PreferenceCategory preferenceCategory = new PreferenceCategory(mContext);
|
||||
preferenceCategory.setKey(mController.getPreferenceKey());
|
||||
mScreen.addPreference(preferenceCategory);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,4 +73,20 @@ public class BluetoothDetailsAudioRoutingControllerTest extends
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void init_isHearingAidDevice_expectedAudioRoutingPreference() {
|
||||
when(mCachedDevice.isHearingAidDevice()).thenReturn(true);
|
||||
when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
|
||||
|
||||
mController.init(mScreen);
|
||||
final Preference preference = mScreen.findPreference(KEY_AUDIO_ROUTING);
|
||||
final String address = preference.getExtras().getString(
|
||||
BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS);
|
||||
final String fragment = preference.getFragment();
|
||||
|
||||
assertThat(address).isEqualTo(TEST_ADDRESS);
|
||||
assertThat(fragment).isEqualTo(BluetoothDetailsAudioRoutingFragment.class.getName());
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** Tests for {@link BluetoothDetailsAudioRoutingFragment}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothUtils.class})
|
||||
public class BluetoothDetailsAudioRoutingFragmentTest {
|
||||
|
||||
@Rule
|
||||
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
|
||||
private static final String TEST_ADDRESS = "55:66:77:88:99:AA";
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
private BluetoothDetailsAudioRoutingFragment mFragment;
|
||||
@Mock
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
@Mock
|
||||
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||
@Mock
|
||||
private LocalBluetoothAdapter mLocalBluetoothAdapter;
|
||||
@Mock
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedDevice;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
setupEnvironment();
|
||||
|
||||
when(mLocalBluetoothAdapter.getRemoteDevice(TEST_ADDRESS)).thenReturn(mBluetoothDevice);
|
||||
when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
|
||||
when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedDevice);
|
||||
|
||||
mFragment = new BluetoothDetailsAudioRoutingFragment();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAttach_setArgumentsWithAddress_expectedCachedDeviceWithAddress() {
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, TEST_ADDRESS);
|
||||
mFragment.setArguments(args);
|
||||
|
||||
mFragment.onAttach(mContext);
|
||||
|
||||
assertThat(mFragment.mCachedDevice.getAddress()).isEqualTo(TEST_ADDRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonIndexableKeys_existInXmlLayout() {
|
||||
final List<String> niks = BluetoothDetailsAudioRoutingFragment.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(mContext);
|
||||
final List<String> keys =
|
||||
XmlTestUtils.getKeysFromPreferenceXml(mContext,
|
||||
R.xml.bluetooth_audio_routing_fragment);
|
||||
|
||||
assertThat(keys).containsAtLeastElementsIn(niks);
|
||||
}
|
||||
|
||||
private void setupEnvironment() {
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
when(mLocalBluetoothManager.getBluetoothAdapter()).thenReturn(mLocalBluetoothAdapter);
|
||||
}
|
||||
}
|
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
|
||||
/** Tests for {@link BluetoothDevicePairingDetailBase}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothAdapter.class})
|
||||
public class BluetoothDevicePairingDetailBaseTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
public static final String KEY_DEVICE_LIST_GROUP = "test_key";
|
||||
|
||||
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
||||
private static final String TEST_DEVICE_ADDRESS_B = "00:B1:B1:B1:B1:B1";
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Mock
|
||||
private Resources mResource;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private LocalBluetoothManager mLocalManager;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
@Mock
|
||||
private Drawable mDrawable;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||
private BluetoothProgressCategory mAvailableDevicesCategory;
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
private TestBluetoothDevicePairingDetailBase mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mAvailableDevicesCategory = spy(new BluetoothProgressCategory(mContext));
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
|
||||
final Pair<Drawable, String> pairs = new Pair<>(mDrawable, "fake_device");
|
||||
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
|
||||
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
|
||||
|
||||
mFragment = spy(new TestBluetoothDevicePairingDetailBase());
|
||||
when(mFragment.findPreference(KEY_DEVICE_LIST_GROUP)).thenReturn(mAvailableDevicesCategory);
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
doReturn(mResource).when(mFragment).getResources();
|
||||
mFragment.mDeviceListGroup = mAvailableDevicesCategory;
|
||||
mFragment.mLocalManager = mLocalManager;
|
||||
mFragment.mBluetoothAdapter = mBluetoothAdapter;
|
||||
mFragment.initPreferencesFromPreferenceScreen();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startScanning_startScanAndRemoveDevices() {
|
||||
mFragment.enableScanning();
|
||||
|
||||
verify(mFragment).startScanning();
|
||||
verify(mAvailableDevicesCategory).removeAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateContent_stateOn() {
|
||||
mFragment.updateContent(BluetoothAdapter.STATE_ON);
|
||||
|
||||
assertThat(mBluetoothAdapter.isEnabled()).isTrue();
|
||||
verify(mFragment).enableScanning();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateContent_stateOff_finish() {
|
||||
mFragment.updateContent(BluetoothAdapter.STATE_OFF);
|
||||
|
||||
verify(mFragment).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBluetooth_bluetoothOff_turnOnBluetooth() {
|
||||
mShadowBluetoothAdapter.setEnabled(false);
|
||||
|
||||
mFragment.updateBluetooth();
|
||||
|
||||
assertThat(mBluetoothAdapter.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBluetooth_bluetoothOn_updateState() {
|
||||
mShadowBluetoothAdapter.setEnabled(true);
|
||||
doNothing().when(mFragment).updateContent(anyInt());
|
||||
|
||||
mFragment.updateBluetooth();
|
||||
|
||||
verify(mFragment).updateContent(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBluetoothStateChanged_whenTurnedOnBTShowToast() {
|
||||
doNothing().when(mFragment).updateContent(anyInt());
|
||||
|
||||
mFragment.onBluetoothStateChanged(BluetoothAdapter.STATE_ON);
|
||||
|
||||
verify(mFragment).showBluetoothTurnedOnToast();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceInSelectedListAndConnected_finish() {
|
||||
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_B);
|
||||
mFragment.mSelectedList.add(mBluetoothDevice);
|
||||
mFragment.mSelectedList.add(device);
|
||||
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(device);
|
||||
|
||||
mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.A2DP, BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
verify(mFragment).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceNotInSelectedList_doNothing() {
|
||||
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_B);
|
||||
mFragment.mSelectedList.add(device);
|
||||
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
|
||||
mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.A2DP, BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
// not crash
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceDisconnected_doNothing() {
|
||||
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_B);
|
||||
mFragment.mSelectedList.add(mBluetoothDevice);
|
||||
mFragment.mSelectedList.add(device);
|
||||
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(false);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(device);
|
||||
|
||||
mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.A2DP, BluetoothAdapter.STATE_DISCONNECTED);
|
||||
|
||||
// not crash
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceInPreferenceMapAndConnected_removed() {
|
||||
final BluetoothDevicePreference preference =
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
true, BluetoothDevicePreference.SortType.TYPE_FIFO);
|
||||
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
|
||||
mFragment.mDevicePreferenceMap.put(mCachedBluetoothDevice, preference);
|
||||
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(device);
|
||||
|
||||
mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.A2DP, BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
assertThat(mFragment.mDevicePreferenceMap.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceNotInPreferenceMap_doNothing() {
|
||||
final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
|
||||
final BluetoothDevicePreference preference =
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
true, BluetoothDevicePreference.SortType.TYPE_FIFO);
|
||||
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
|
||||
final BluetoothDevice device2 = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_B);
|
||||
mFragment.mDevicePreferenceMap.put(mCachedBluetoothDevice, preference);
|
||||
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(device);
|
||||
when(cachedDevice.isConnected()).thenReturn(true);
|
||||
when(cachedDevice.getDevice()).thenReturn(device2);
|
||||
when(cachedDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS_B);
|
||||
when(cachedDevice.getIdentityAddress()).thenReturn(TEST_DEVICE_ADDRESS_B);
|
||||
|
||||
mFragment.onProfileConnectionStateChanged(cachedDevice, BluetoothProfile.A2DP,
|
||||
BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
// not crash
|
||||
}
|
||||
|
||||
private static class TestBluetoothDevicePairingDetailBase extends
|
||||
BluetoothDevicePairingDetailBase {
|
||||
|
||||
TestBluetoothDevicePairingDetailBase() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDeviceListKey() {
|
||||
return KEY_DEVICE_LIST_GROUP;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return "test_tag";
|
||||
}
|
||||
}
|
||||
}
|
@@ -34,7 +34,6 @@ import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.connecteddevice.DevicePreferenceCallback;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
@@ -62,8 +61,6 @@ public class BluetoothDeviceUpdaterTest {
|
||||
private static final String SUB_MAC_ADDRESS = "05:52:C7:0B:D8:3C";
|
||||
private static final String TEST_NAME = "test_name";
|
||||
|
||||
@Mock
|
||||
private DashboardFragment mDashboardFragment;
|
||||
@Mock
|
||||
private DevicePreferenceCallback mDevicePreferenceCallback;
|
||||
@Mock
|
||||
@@ -84,7 +81,7 @@ public class BluetoothDeviceUpdaterTest {
|
||||
private Drawable mDrawable;
|
||||
|
||||
private Context mContext;
|
||||
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
||||
private TestBluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
||||
private BluetoothDevicePreference mPreference;
|
||||
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||
private List<CachedBluetoothDevice> mCachedDevices = new ArrayList<>();
|
||||
@@ -97,7 +94,6 @@ public class BluetoothDeviceUpdaterTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||
mCachedDevices.add(mCachedBluetoothDevice);
|
||||
doReturn(mContext).when(mDashboardFragment).getContext();
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
when(mSubCachedBluetoothDevice.getDevice()).thenReturn(mSubBluetoothDevice);
|
||||
when(mLocalManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
@@ -107,20 +103,10 @@ public class BluetoothDeviceUpdaterTest {
|
||||
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
|
||||
|
||||
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
false, BluetoothDevicePreference.SortType.TYPE_DEFAULT);
|
||||
mBluetoothDeviceUpdater =
|
||||
new BluetoothDeviceUpdater(mContext, mDashboardFragment, mDevicePreferenceCallback,
|
||||
mLocalManager) {
|
||||
@Override
|
||||
public boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPreferenceKey() {
|
||||
return "test_bt";
|
||||
}
|
||||
};
|
||||
/* showDeviceWithoutNames= */ false,
|
||||
BluetoothDevicePreference.SortType.TYPE_DEFAULT);
|
||||
mBluetoothDeviceUpdater = new TestBluetoothDeviceUpdater(mContext,
|
||||
mDevicePreferenceCallback, mLocalManager, /* metricsCategory= */ 0);
|
||||
mBluetoothDeviceUpdater.setPrefContext(mContext);
|
||||
}
|
||||
|
||||
@@ -185,7 +171,8 @@ public class BluetoothDeviceUpdaterTest {
|
||||
|
||||
@Test
|
||||
public void testDeviceProfilesListener_click_startBluetoothDeviceDetailPage() {
|
||||
doReturn(mSettingsActivity).when(mDashboardFragment).getContext();
|
||||
mBluetoothDeviceUpdater = new TestBluetoothDeviceUpdater(mSettingsActivity,
|
||||
mDevicePreferenceCallback, mLocalManager, /* metricsCategory= */ 0);
|
||||
|
||||
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
mBluetoothDeviceUpdater.mDeviceProfilesListener.onGearClick(mPreference);
|
||||
@@ -274,4 +261,22 @@ public class BluetoothDeviceUpdaterTest {
|
||||
|
||||
assertThat(mPreference.getTitle()).isEqualTo(TEST_NAME);
|
||||
}
|
||||
|
||||
public static class TestBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
|
||||
public TestBluetoothDeviceUpdater(Context context,
|
||||
DevicePreferenceCallback devicePreferenceCallback,
|
||||
LocalBluetoothManager localManager, int metricsCategory) {
|
||||
super(context, devicePreferenceCallback, localManager, metricsCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPreferenceKey() {
|
||||
return "test_bt";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,166 +18,86 @@ package com.android.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Pair;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothAdapter.class})
|
||||
public class BluetoothPairingDetailTest {
|
||||
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
||||
private static final String TEST_DEVICE_ADDRESS_B = "00:B1:B1:B1:B1:B1";
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Mock
|
||||
private Resources mResource;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private LocalBluetoothManager mLocalManager;
|
||||
@Mock
|
||||
private PreferenceGroup mPreferenceGroup;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||
@Mock
|
||||
private Drawable mDrawable;
|
||||
|
||||
private BluetoothPairingDetail mFragment;
|
||||
private Context mContext;
|
||||
private BluetoothProgressCategory mAvailableDevicesCategory;
|
||||
private FooterPreference mFooterPreference;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
Pair<Drawable, String> pairs = new Pair<>(mDrawable, "fake_device");
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mFragment = spy(new BluetoothPairingDetail());
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
doReturn(mResource).when(mFragment).getResources();
|
||||
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
|
||||
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
|
||||
|
||||
mAvailableDevicesCategory = spy(new BluetoothProgressCategory(mContext));
|
||||
mFooterPreference = new FooterPreference(mContext);
|
||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
|
||||
|
||||
doReturn(mAvailableDevicesCategory).when(mFragment)
|
||||
.findPreference(BluetoothPairingDetail.KEY_AVAIL_DEVICES);
|
||||
doReturn(mFooterPreference).when(mFragment)
|
||||
.findPreference(BluetoothPairingDetail.KEY_FOOTER_PREF);
|
||||
|
||||
mFragment.mBluetoothAdapter = mBluetoothAdapter;
|
||||
mFragment.mLocalManager = mLocalManager;
|
||||
mFragment.mDeviceListGroup = mPreferenceGroup;
|
||||
mFragment.mAlwaysDiscoverable = new AlwaysDiscoverable(mContext);
|
||||
mFragment.mDeviceListGroup = mAvailableDevicesCategory;
|
||||
mFragment.onViewCreated(mFragment.getView(), Bundle.EMPTY);
|
||||
}
|
||||
|
||||
//
|
||||
@Test
|
||||
public void initPreferencesFromPreferenceScreen_findPreferences() {
|
||||
doReturn(mAvailableDevicesCategory).when(mFragment)
|
||||
.findPreference(BluetoothPairingDetail.KEY_AVAIL_DEVICES);
|
||||
doReturn(mFooterPreference).when(mFragment)
|
||||
.findPreference(BluetoothPairingDetail.KEY_FOOTER_PREF);
|
||||
|
||||
mFragment.initPreferencesFromPreferenceScreen();
|
||||
|
||||
assertThat(mFragment.mAvailableDevicesCategory).isEqualTo(mAvailableDevicesCategory);
|
||||
assertThat(mFragment.mFooterPreference).isEqualTo(mFooterPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startScanning_startScanAndRemoveDevices() {
|
||||
mFragment.mAvailableDevicesCategory = mAvailableDevicesCategory;
|
||||
mFragment.mDeviceListGroup = mAvailableDevicesCategory;
|
||||
|
||||
mFragment.enableScanning();
|
||||
|
||||
verify(mFragment).startScanning();
|
||||
verify(mAvailableDevicesCategory).removeAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateContent_stateOn_addDevices() {
|
||||
mFragment.mAvailableDevicesCategory = mAvailableDevicesCategory;
|
||||
mFragment.mFooterPreference = mFooterPreference;
|
||||
doNothing().when(mFragment).addDeviceCategory(any(), anyInt(), any(), anyBoolean());
|
||||
mFragment.initPreferencesFromPreferenceScreen();
|
||||
|
||||
mFragment.updateContent(BluetoothAdapter.STATE_ON);
|
||||
|
||||
verify(mFragment).addDeviceCategory(mAvailableDevicesCategory,
|
||||
R.string.bluetooth_preference_found_media_devices,
|
||||
BluetoothDeviceFilter.ALL_FILTER, false);
|
||||
assertThat(mFragment.mAlwaysDiscoverable.mStarted).isEqualTo(true);
|
||||
assertThat(mBluetoothAdapter.getScanMode())
|
||||
.isEqualTo(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateContent_stateOff_finish() {
|
||||
mFragment.updateContent(BluetoothAdapter.STATE_OFF);
|
||||
|
||||
verify(mFragment).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBluetooth_bluetoothOff_turnOnBluetooth() {
|
||||
mShadowBluetoothAdapter.setEnabled(false);
|
||||
|
||||
mFragment.updateBluetooth();
|
||||
|
||||
assertThat(mBluetoothAdapter.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBluetooth_bluetoothOn_updateState() {
|
||||
mShadowBluetoothAdapter.setEnabled(true);
|
||||
doNothing().when(mFragment).updateContent(anyInt());
|
||||
|
||||
mFragment.updateBluetooth();
|
||||
|
||||
verify(mFragment).updateContent(anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onScanningStateChanged_restartScanAfterInitialScanning() {
|
||||
mFragment.mAvailableDevicesCategory = mAvailableDevicesCategory;
|
||||
mFragment.mFooterPreference = mFooterPreference;
|
||||
mFragment.mDeviceListGroup = mAvailableDevicesCategory;
|
||||
doNothing().when(mFragment).addDeviceCategory(any(), anyInt(), any(), anyBoolean());
|
||||
mFragment.initPreferencesFromPreferenceScreen();
|
||||
|
||||
// Initial Bluetooth ON will trigger scan enable, list clear and scan start
|
||||
mFragment.updateContent(BluetoothAdapter.STATE_ON);
|
||||
@@ -219,97 +139,4 @@ public class BluetoothPairingDetailTest {
|
||||
// Verify that clean up only happen once at initialization
|
||||
verify(mAvailableDevicesCategory, times(1)).removeAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBluetoothStateChanged_whenTurnedOnBTShowToast() {
|
||||
doNothing().when(mFragment).updateContent(anyInt());
|
||||
|
||||
mFragment.onBluetoothStateChanged(BluetoothAdapter.STATE_ON);
|
||||
|
||||
verify(mFragment).showBluetoothTurnedOnToast();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceInSelectedListAndConnected_finish() {
|
||||
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_B);
|
||||
mFragment.mSelectedList.add(mBluetoothDevice);
|
||||
mFragment.mSelectedList.add(device);
|
||||
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(device);
|
||||
|
||||
mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.A2DP, BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
verify(mFragment).finish();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceNotInSelectedList_doNothing() {
|
||||
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_B);
|
||||
mFragment.mSelectedList.add(device);
|
||||
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
|
||||
mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.A2DP, BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
// not crash
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceDisconnected_doNothing() {
|
||||
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_B);
|
||||
mFragment.mSelectedList.add(mBluetoothDevice);
|
||||
mFragment.mSelectedList.add(device);
|
||||
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(false);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(device);
|
||||
|
||||
mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.A2DP, BluetoothAdapter.STATE_DISCONNECTED);
|
||||
|
||||
// not crash
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceInPreferenceMapAndConnected_removed() {
|
||||
final BluetoothDevicePreference preference =
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
true, BluetoothDevicePreference.SortType.TYPE_FIFO);
|
||||
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
|
||||
mFragment.mDevicePreferenceMap.put(mCachedBluetoothDevice, preference);
|
||||
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(device);
|
||||
|
||||
mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.A2DP, BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
assertThat(mFragment.mDevicePreferenceMap.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceNotInPreferenceMap_doNothing() {
|
||||
final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
|
||||
final BluetoothDevicePreference preference =
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
true, BluetoothDevicePreference.SortType.TYPE_FIFO);
|
||||
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
|
||||
final BluetoothDevice device2 = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_B);
|
||||
mFragment.mDevicePreferenceMap.put(mCachedBluetoothDevice, preference);
|
||||
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(device);
|
||||
when(cachedDevice.isConnected()).thenReturn(true);
|
||||
when(cachedDevice.getDevice()).thenReturn(device2);
|
||||
when(cachedDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS_B);
|
||||
when(cachedDevice.getIdentityAddress()).thenReturn(TEST_DEVICE_ADDRESS_B);
|
||||
|
||||
mFragment.onProfileConnectionStateChanged(cachedDevice, BluetoothProfile.A2DP,
|
||||
BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
// not crash
|
||||
}
|
||||
}
|
@@ -97,7 +97,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
||||
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
|
||||
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
|
||||
mBluetoothDeviceUpdater = spy(new ConnectedBluetoothDeviceUpdater(mContext,
|
||||
mDashboardFragment, mDevicePreferenceCallback));
|
||||
mDevicePreferenceCallback, /* metricsCategory= */ 0));
|
||||
mBluetoothDeviceUpdater.setPrefContext(mContext);
|
||||
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
|
||||
doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
|
||||
|
@@ -26,6 +26,11 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothUuid;
|
||||
import android.bluetooth.le.BluetoothLeScanner;
|
||||
import android.bluetooth.le.ScanCallback;
|
||||
import android.bluetooth.le.ScanFilter;
|
||||
import android.bluetooth.le.ScanSettings;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
@@ -45,6 +50,7 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@@ -57,10 +63,14 @@ public class DeviceListPreferenceFragmentTest {
|
||||
private Resources mResource;
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private BluetoothLeScanner mBluetoothLeScanner;
|
||||
|
||||
private TestFragment mFragment;
|
||||
private Preference mMyDevicePreference;
|
||||
|
||||
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
@@ -68,7 +78,8 @@ public class DeviceListPreferenceFragmentTest {
|
||||
mFragment = spy(new TestFragment());
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
doReturn(mResource).when(mFragment).getResources();
|
||||
mFragment.mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
mBluetoothAdapter = spy(BluetoothAdapter.getDefaultAdapter());
|
||||
mFragment.mBluetoothAdapter = mBluetoothAdapter;
|
||||
|
||||
mMyDevicePreference = new Preference(RuntimeEnvironment.application);
|
||||
}
|
||||
@@ -169,6 +180,20 @@ public class DeviceListPreferenceFragmentTest {
|
||||
verify(mFragment, times(1)).startScanning();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startScanning_setLeScanFilter_shouldStartLeScan() {
|
||||
final ScanFilter leScanFilter = new ScanFilter.Builder()
|
||||
.setServiceData(BluetoothUuid.HEARING_AID, new byte[]{0}, new byte[]{0})
|
||||
.build();
|
||||
doReturn(mBluetoothLeScanner).when(mBluetoothAdapter).getBluetoothLeScanner();
|
||||
|
||||
mFragment.setFilter(Collections.singletonList(leScanFilter));
|
||||
mFragment.startScanning();
|
||||
|
||||
verify(mBluetoothLeScanner).startScan(eq(Collections.singletonList(leScanFilter)),
|
||||
any(ScanSettings.class), any(ScanCallback.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fragment to test since {@code DeviceListPreferenceFragment} is abstract
|
||||
*/
|
||||
@@ -187,7 +212,7 @@ public class DeviceListPreferenceFragmentTest {
|
||||
public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {}
|
||||
|
||||
@Override
|
||||
void initPreferencesFromPreferenceScreen() {}
|
||||
protected void initPreferencesFromPreferenceScreen() {}
|
||||
|
||||
@Override
|
||||
public String getDeviceListKey() {
|
||||
|
@@ -91,8 +91,8 @@ public class SavedBluetoothDeviceUpdaterTest {
|
||||
when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||
when(mCachedBluetoothDevice.getDrawableWithDescription()).thenReturn(pairs);
|
||||
|
||||
mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mContext, mDashboardFragment,
|
||||
mDevicePreferenceCallback));
|
||||
mBluetoothDeviceUpdater = spy(new SavedBluetoothDeviceUpdater(mContext,
|
||||
mDevicePreferenceCallback, false, /* metricsCategory= */ 0));
|
||||
mBluetoothDeviceUpdater.setPrefContext(mContext);
|
||||
mBluetoothDeviceUpdater.mBluetoothAdapter = mBluetoothAdapter;
|
||||
mBluetoothDeviceUpdater.mLocalManager = mBluetoothManager;
|
||||
|
Reference in New Issue
Block a user