Search in sources :

Example 46 with CachedBluetoothDevice

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;
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 47 with CachedBluetoothDevice

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();
    }
}
Also used : CachedBluetoothDeviceManager(com.android.settingslib.bluetooth.CachedBluetoothDeviceManager) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 48 with CachedBluetoothDevice

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);
        }
    }
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice)

Example 49 with CachedBluetoothDevice

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
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) Test(org.junit.Test)

Example 50 with CachedBluetoothDevice

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);
}
Also used : CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) BluetoothDevice(android.bluetooth.BluetoothDevice) CachedBluetoothDevice(com.android.settingslib.bluetooth.CachedBluetoothDevice) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

CachedBluetoothDevice (com.android.settingslib.bluetooth.CachedBluetoothDevice)104 BluetoothDevice (android.bluetooth.BluetoothDevice)38 LocalBluetoothManager (com.android.settingslib.bluetooth.LocalBluetoothManager)30 CachedBluetoothDeviceManager (com.android.settingslib.bluetooth.CachedBluetoothDeviceManager)15 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)12 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 DialogInterface (android.content.DialogInterface)7 OnClickListener (android.view.View.OnClickListener)7 MapProfile (com.android.settingslib.bluetooth.MapProfile)7 VisibleForTesting (androidx.annotation.VisibleForTesting)6 Intent (android.content.Intent)5 Preference (androidx.preference.Preference)4 Bundle (android.os.Bundle)2 ListBuilder (androidx.slice.builders.ListBuilder)2 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)2 GearPreference (com.android.settings.widget.GearPreference)2 LocalBluetoothProfile (com.android.settingslib.bluetooth.LocalBluetoothProfile)2 Iterator (java.util.Iterator)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2