use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project android_packages_apps_Settings by omnirom.
the class SavedBluetoothDeviceUpdater method onPreferenceClick.
@Override
public boolean onPreferenceClick(Preference preference) {
mMetricsFeatureProvider.logClickedPreference(preference, mFragment.getMetricsCategory());
final CachedBluetoothDevice device = ((BluetoothDevicePreference) preference).getBluetoothDevice();
if (device.isConnected()) {
return device.setActive();
}
device.connect();
return true;
}
use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project android_packages_apps_Settings by omnirom.
the class SavedBluetoothDeviceUpdater method forceUpdate.
@Override
public void forceUpdate() {
if (mBluetoothAdapter.isEnabled()) {
final CachedBluetoothDeviceManager cachedManager = mLocalManager.getCachedDeviceManager();
final List<BluetoothDevice> bluetoothDevices = mBluetoothAdapter.getMostRecentlyConnectedDevices();
removePreferenceIfNecessary(bluetoothDevices, cachedManager);
for (BluetoothDevice device : bluetoothDevices) {
final CachedBluetoothDevice cachedDevice = cachedManager.findDevice(device);
if (cachedDevice != null) {
update(cachedDevice);
}
}
} else {
removeAllDevicesFromPreference();
}
}
use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project android_packages_apps_Settings by omnirom.
the class BluetoothDeviceUpdater method removePreference.
/**
* Remove the {@link Preference} that represents the {@code cachedDevice}
*/
protected void removePreference(CachedBluetoothDevice cachedDevice) {
final BluetoothDevice device = cachedDevice.getDevice();
final CachedBluetoothDevice subCachedDevice = cachedDevice.getSubDevice();
if (mPreferenceMap.containsKey(device)) {
mDevicePreferenceCallback.onDeviceRemoved(mPreferenceMap.get(device));
mPreferenceMap.remove(device);
} else if (subCachedDevice != null) {
// When doing remove, to check if preference maps to sub device.
// This would happen when connection state is changed in detail page that there is no
// callback from SettingsLib.
final BluetoothDevice subDevice = subCachedDevice.getDevice();
if (mPreferenceMap.containsKey(subDevice)) {
mDevicePreferenceCallback.onDeviceRemoved(mPreferenceMap.get(subDevice));
mPreferenceMap.remove(subDevice);
}
}
}
use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project android_packages_apps_Settings by omnirom.
the class BluetoothPairingDetailTest method onProfileConnectionStateChanged_deviceNotInPreferenceMap_doNothing.
@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);
mFragment.onProfileConnectionStateChanged(cachedDevice, BluetoothProfile.A2DP, BluetoothAdapter.STATE_CONNECTED);
// not crash
}
use of com.android.settingslib.bluetooth.CachedBluetoothDevice in project android_packages_apps_Settings by omnirom.
the class SavedBluetoothDeviceUpdaterTest method forceUpdate_deviceNotContain_removePreference.
@Test
public void forceUpdate_deviceNotContain_removePreference() {
final List<BluetoothDevice> bluetoothDevices = new ArrayList<>();
bluetoothDevices.add(mBluetoothDevice);
final BluetoothDevice device2 = mock(BluetoothDevice.class);
final CachedBluetoothDevice cachedDevice2 = mock(CachedBluetoothDevice.class);
mBluetoothDeviceUpdater.mPreferenceMap.put(device2, mPreference);
when(cachedDevice2.getDevice()).thenReturn(device2);
when(cachedDevice2.getAddress()).thenReturn("04:52:C7:0B:D8:3S");
when(mDeviceManager.findDevice(device2)).thenReturn(cachedDevice2);
when(mBluetoothAdapter.isEnabled()).thenReturn(true);
when(mBluetoothAdapter.getMostRecentlyConnectedDevices()).thenReturn(bluetoothDevices);
when(mBluetoothManager.getCachedDeviceManager()).thenReturn(mDeviceManager);
when(mDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
when(mBluetoothDevice.isConnected()).thenReturn(false);
mBluetoothDeviceUpdater.forceUpdate();
verify(mBluetoothDeviceUpdater).removePreference(cachedDevice2);
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice, BluetoothDevicePreference.SortType.TYPE_NO_SORT);
}
Aggregations