[Pair hearing devices] Add "Saved devices" to show bonded but not connected hearing devices

* BaseHearingDevicePreferenceController will also be used in "Hearing devices", so extract to parent class first.

Bug: 237625815
Test: make RunSettingsRoboTests ROBOTEST_FILTER="(SavedHearingDeviceUpdaterTest|BaseBluetoothDevicePreferenceControllerTest|BluetoothDeviceUpdaterTest|AvailableMediaBluetoothDeviceUpdaterTest|ConnectedBluetoothDeviceUpdaterTest|SavedBluetoothDeviceUpdaterTest)"
Change-Id: I8a492866f48e3a664b9ff78bce5a4f082c0dc465
This commit is contained in:
jasonwshsu
2022-12-30 03:11:48 +08:00
parent 48d56420ce
commit c1fb0ae240
20 changed files with 573 additions and 66 deletions

View File

@@ -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";
}
}
}