Show all devices, including connected ones, into "Previously connected" page

-Add connected devices in "Previously connected" page
-Set active when clicking a connected device

Bug: 147150246
Test: make -j50 RunSettingsRoboTests
Change-Id: I4422cd63c360a4387cedc4f80f34474b42f82a1f
This commit is contained in:
timhypeng
2020-08-05 16:13:40 +08:00
committed by tim peng
parent d0a493be2a
commit 9743fed57d
2 changed files with 18 additions and 2 deletions

View File

@@ -24,6 +24,7 @@ import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.android.settings.connecteddevice.DevicePreferenceCallback; import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.connecteddevice.PreviouslyConnectedDeviceDashboardFragment;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
@@ -42,13 +43,15 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
private static final String PREF_KEY = "saved_bt"; private static final String PREF_KEY = "saved_bt";
private final boolean mDisplayConnected;
@VisibleForTesting @VisibleForTesting
BluetoothAdapter mBluetoothAdapter; BluetoothAdapter mBluetoothAdapter;
public SavedBluetoothDeviceUpdater(Context context, DashboardFragment fragment, public SavedBluetoothDeviceUpdater(Context context, DashboardFragment fragment,
DevicePreferenceCallback devicePreferenceCallback) { DevicePreferenceCallback devicePreferenceCallback) {
super(context, fragment, devicePreferenceCallback); super(context, fragment, devicePreferenceCallback);
mDisplayConnected = (fragment instanceof PreviouslyConnectedDeviceDashboardFragment);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
} }
@@ -101,7 +104,8 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
", is connected : " + device.isConnected() + ", is profile connected : " ", is connected : " + device.isConnected() + ", is profile connected : "
+ cachedDevice.isConnected()); + cachedDevice.isConnected());
} }
return device.getBondState() == BluetoothDevice.BOND_BONDED && !device.isConnected(); return device.getBondState() == BluetoothDevice.BOND_BONDED
&& (mDisplayConnected || !device.isConnected());
} }
@Override @Override
@@ -109,6 +113,9 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
mMetricsFeatureProvider.logClickedPreference(preference, mFragment.getMetricsCategory()); mMetricsFeatureProvider.logClickedPreference(preference, mFragment.getMetricsCategory());
final CachedBluetoothDevice device = ((BluetoothDevicePreference) preference) final CachedBluetoothDevice device = ((BluetoothDevicePreference) preference)
.getBluetoothDevice(); .getBluetoothDevice();
if (device.isConnected()) {
return device.setActive();
}
device.connect(); device.connect();
return true; return true;
} }

View File

@@ -144,6 +144,15 @@ public class SavedBluetoothDeviceUpdaterTest {
verify(mCachedBluetoothDevice).connect(); verify(mCachedBluetoothDevice).connect();
} }
@Test
public void onClick_Preference_connected_setActive() {
when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
mBluetoothDeviceUpdater.onPreferenceClick(mPreference);
verify(mCachedBluetoothDevice).setActive();
}
@Test @Test
public void forceUpdate_findCachedBluetoothDeviceIsMatched_addPreference() { public void forceUpdate_findCachedBluetoothDeviceIsMatched_addPreference() {
final List<BluetoothDevice> bluetoothDevices = new ArrayList<>(); final List<BluetoothDevice> bluetoothDevices = new ArrayList<>();