Merge "[BT LE unicast] clear the GroupId when user click 'Forget'" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
fcad8a9b14
@@ -367,8 +367,14 @@ public class BluetoothEventManager {
|
|||||||
if (bondState == BluetoothDevice.BOND_NONE) {
|
if (bondState == BluetoothDevice.BOND_NONE) {
|
||||||
// Check if we need to remove other Coordinated set member devices / Hearing Aid
|
// Check if we need to remove other Coordinated set member devices / Hearing Aid
|
||||||
// devices
|
// devices
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "BondStateChangedHandler: cachedDevice.getGroupId() = "
|
||||||
|
+ cachedDevice.getGroupId() + ", cachedDevice.getHiSyncId()= "
|
||||||
|
+ cachedDevice.getHiSyncId());
|
||||||
|
}
|
||||||
if (cachedDevice.getGroupId() != BluetoothCsipSetCoordinator.GROUP_ID_INVALID
|
if (cachedDevice.getGroupId() != BluetoothCsipSetCoordinator.GROUP_ID_INVALID
|
||||||
|| cachedDevice.getHiSyncId() != BluetoothHearingAid.HI_SYNC_ID_INVALID) {
|
|| cachedDevice.getHiSyncId() != BluetoothHearingAid.HI_SYNC_ID_INVALID) {
|
||||||
|
Log.d(TAG, "BondStateChangedHandler: Start onDeviceUnpaired");
|
||||||
mDeviceManager.onDeviceUnpaired(cachedDevice);
|
mDeviceManager.onDeviceUnpaired(cachedDevice);
|
||||||
}
|
}
|
||||||
int reason = intent.getIntExtra(BluetoothDevice.EXTRA_UNBOND_REASON,
|
int reason = intent.getIntExtra(BluetoothDevice.EXTRA_UNBOND_REASON,
|
||||||
|
|||||||
@@ -1431,11 +1431,10 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
* first connected device in the coordinated set, and then switch the content of the main
|
* first connected device in the coordinated set, and then switch the content of the main
|
||||||
* device and member devices.
|
* device and member devices.
|
||||||
*
|
*
|
||||||
* @param prevMainDevice the previous Main device, it will be added into the member device set.
|
* @param newMainDevice the new Main device which is from the previous main device's member
|
||||||
* @param newMainDevice the new Main device, it will be removed from the member device set.
|
* list.
|
||||||
*/
|
*/
|
||||||
public void switchMemberDeviceContent(CachedBluetoothDevice prevMainDevice,
|
public void switchMemberDeviceContent(CachedBluetoothDevice newMainDevice) {
|
||||||
CachedBluetoothDevice newMainDevice) {
|
|
||||||
// Backup from main device
|
// Backup from main device
|
||||||
final BluetoothDevice tmpDevice = mDevice;
|
final BluetoothDevice tmpDevice = mDevice;
|
||||||
final short tmpRssi = mRssi;
|
final short tmpRssi = mRssi;
|
||||||
@@ -1444,8 +1443,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
|
|||||||
mDevice = newMainDevice.mDevice;
|
mDevice = newMainDevice.mDevice;
|
||||||
mRssi = newMainDevice.mRssi;
|
mRssi = newMainDevice.mRssi;
|
||||||
mJustDiscovered = newMainDevice.mJustDiscovered;
|
mJustDiscovered = newMainDevice.mJustDiscovered;
|
||||||
addMemberDevice(prevMainDevice);
|
|
||||||
mMemberDevices.remove(newMainDevice);
|
|
||||||
// Set sub device from backup
|
// Set sub device from backup
|
||||||
newMainDevice.mDevice = tmpDevice;
|
newMainDevice.mDevice = tmpDevice;
|
||||||
newMainDevice.mRssi = tmpRssi;
|
newMainDevice.mRssi = tmpRssi;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settingslib.bluetooth;
|
package com.android.settingslib.bluetooth;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.bluetooth.BluetoothCsipSetCoordinator;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -317,12 +318,14 @@ public class CachedBluetoothDeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void onDeviceUnpaired(CachedBluetoothDevice device) {
|
public synchronized void onDeviceUnpaired(CachedBluetoothDevice device) {
|
||||||
|
device.setGroupId(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||||
CachedBluetoothDevice mainDevice = mCsipDeviceManager.findMainDevice(device);
|
CachedBluetoothDevice mainDevice = mCsipDeviceManager.findMainDevice(device);
|
||||||
final Set<CachedBluetoothDevice> memberDevices = device.getMemberDevice();
|
final Set<CachedBluetoothDevice> memberDevices = device.getMemberDevice();
|
||||||
if (!memberDevices.isEmpty()) {
|
if (!memberDevices.isEmpty()) {
|
||||||
// Main device is unpaired, to unpair the member device
|
// Main device is unpaired, to unpair the member device
|
||||||
for (CachedBluetoothDevice memberDevice : memberDevices) {
|
for (CachedBluetoothDevice memberDevice : memberDevices) {
|
||||||
memberDevice.unpair();
|
memberDevice.unpair();
|
||||||
|
memberDevice.setGroupId(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||||
device.removeMemberDevice(memberDevice);
|
device.removeMemberDevice(memberDevice);
|
||||||
}
|
}
|
||||||
} else if (mainDevice != null) {
|
} else if (mainDevice != null) {
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ public class CsipDeviceManager {
|
|||||||
// When both LE Audio devices are disconnected, receiving member device
|
// When both LE Audio devices are disconnected, receiving member device
|
||||||
// connection. To switch content and dispatch to notify UI change
|
// connection. To switch content and dispatch to notify UI change
|
||||||
mBtManager.getEventManager().dispatchDeviceRemoved(mainDevice);
|
mBtManager.getEventManager().dispatchDeviceRemoved(mainDevice);
|
||||||
mainDevice.switchMemberDeviceContent(mainDevice, cachedDevice);
|
mainDevice.switchMemberDeviceContent(cachedDevice);
|
||||||
mainDevice.refresh();
|
mainDevice.refresh();
|
||||||
// It is necessary to do remove and add for updating the mapping on
|
// It is necessary to do remove and add for updating the mapping on
|
||||||
// preference and device
|
// preference and device
|
||||||
@@ -255,10 +255,11 @@ public class CsipDeviceManager {
|
|||||||
|
|
||||||
for (CachedBluetoothDevice device: memberSet) {
|
for (CachedBluetoothDevice device: memberSet) {
|
||||||
if (device.isConnected()) {
|
if (device.isConnected()) {
|
||||||
|
log("set device: " + device + " as the main device");
|
||||||
// Main device is disconnected and sub device is connected
|
// Main device is disconnected and sub device is connected
|
||||||
// To copy data from sub device to main device
|
// To copy data from sub device to main device
|
||||||
mBtManager.getEventManager().dispatchDeviceRemoved(cachedDevice);
|
mBtManager.getEventManager().dispatchDeviceRemoved(cachedDevice);
|
||||||
cachedDevice.switchMemberDeviceContent(device, cachedDevice);
|
cachedDevice.switchMemberDeviceContent(device);
|
||||||
cachedDevice.refresh();
|
cachedDevice.refresh();
|
||||||
// It is necessary to do remove and add for updating the mapping on
|
// It is necessary to do remove and add for updating the mapping on
|
||||||
// preference and device
|
// preference and device
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.verify;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothClass;
|
import android.bluetooth.BluetoothClass;
|
||||||
|
import android.bluetooth.BluetoothCsipSetCoordinator;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothUuid;
|
import android.bluetooth.BluetoothUuid;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -518,7 +519,8 @@ public class CachedBluetoothDeviceManagerTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void onDeviceUnpaired_unpairCsipMainDevice() {
|
public void onDeviceUnpaired_unpairCsipMainDevice() {
|
||||||
when(mDevice1.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
when(mDevice1.getBondState()).thenReturn(BluetoothDevice.BOND_NONE);
|
||||||
|
when(mDevice2.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||||
CachedBluetoothDevice cachedDevice1 = mCachedDeviceManager.addDevice(mDevice1);
|
CachedBluetoothDevice cachedDevice1 = mCachedDeviceManager.addDevice(mDevice1);
|
||||||
CachedBluetoothDevice cachedDevice2 = mCachedDeviceManager.addDevice(mDevice2);
|
CachedBluetoothDevice cachedDevice2 = mCachedDeviceManager.addDevice(mDevice2);
|
||||||
cachedDevice1.setGroupId(1);
|
cachedDevice1.setGroupId(1);
|
||||||
@@ -527,7 +529,12 @@ public class CachedBluetoothDeviceManagerTest {
|
|||||||
|
|
||||||
// Call onDeviceUnpaired for the one in mCachedDevices.
|
// Call onDeviceUnpaired for the one in mCachedDevices.
|
||||||
mCachedDeviceManager.onDeviceUnpaired(cachedDevice1);
|
mCachedDeviceManager.onDeviceUnpaired(cachedDevice1);
|
||||||
|
|
||||||
verify(mDevice2).removeBond();
|
verify(mDevice2).removeBond();
|
||||||
|
assertThat(cachedDevice1.getGroupId()).isEqualTo(
|
||||||
|
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||||
|
assertThat(cachedDevice2.getGroupId()).isEqualTo(
|
||||||
|
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -536,6 +543,7 @@ public class CachedBluetoothDeviceManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onDeviceUnpaired_unpairCsipSubDevice() {
|
public void onDeviceUnpaired_unpairCsipSubDevice() {
|
||||||
when(mDevice1.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
when(mDevice1.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||||
|
when(mDevice2.getBondState()).thenReturn(BluetoothDevice.BOND_NONE);
|
||||||
CachedBluetoothDevice cachedDevice1 = mCachedDeviceManager.addDevice(mDevice1);
|
CachedBluetoothDevice cachedDevice1 = mCachedDeviceManager.addDevice(mDevice1);
|
||||||
CachedBluetoothDevice cachedDevice2 = mCachedDeviceManager.addDevice(mDevice2);
|
CachedBluetoothDevice cachedDevice2 = mCachedDeviceManager.addDevice(mDevice2);
|
||||||
cachedDevice1.setGroupId(1);
|
cachedDevice1.setGroupId(1);
|
||||||
@@ -544,7 +552,10 @@ public class CachedBluetoothDeviceManagerTest {
|
|||||||
|
|
||||||
// Call onDeviceUnpaired for the one in mCachedDevices.
|
// Call onDeviceUnpaired for the one in mCachedDevices.
|
||||||
mCachedDeviceManager.onDeviceUnpaired(cachedDevice2);
|
mCachedDeviceManager.onDeviceUnpaired(cachedDevice2);
|
||||||
|
|
||||||
verify(mDevice1).removeBond();
|
verify(mDevice1).removeBond();
|
||||||
|
assertThat(cachedDevice2.getGroupId()).isEqualTo(
|
||||||
|
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1050,4 +1050,23 @@ public class CachedBluetoothDeviceTest {
|
|||||||
|
|
||||||
assertThat(mCachedDevice.mDrawableCache.size()).isEqualTo(0);
|
assertThat(mCachedDevice.mDrawableCache.size()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void switchMemberDeviceContent_switchMainDevice_switchesSuccessful() {
|
||||||
|
mCachedDevice.mRssi = RSSI_1;
|
||||||
|
mCachedDevice.mJustDiscovered = JUSTDISCOVERED_1;
|
||||||
|
mSubCachedDevice.mRssi = RSSI_2;
|
||||||
|
mSubCachedDevice.mJustDiscovered = JUSTDISCOVERED_2;
|
||||||
|
mCachedDevice.addMemberDevice(mSubCachedDevice);
|
||||||
|
|
||||||
|
mCachedDevice.switchMemberDeviceContent(mSubCachedDevice);
|
||||||
|
|
||||||
|
assertThat(mCachedDevice.mRssi).isEqualTo(RSSI_2);
|
||||||
|
assertThat(mCachedDevice.mJustDiscovered).isEqualTo(JUSTDISCOVERED_2);
|
||||||
|
assertThat(mCachedDevice.mDevice).isEqualTo(mSubDevice);
|
||||||
|
assertThat(mSubCachedDevice.mRssi).isEqualTo(RSSI_1);
|
||||||
|
assertThat(mSubCachedDevice.mJustDiscovered).isEqualTo(JUSTDISCOVERED_1);
|
||||||
|
assertThat(mSubCachedDevice.mDevice).isEqualTo(mDevice);
|
||||||
|
assertThat(mCachedDevice.getMemberDevice().contains(mSubCachedDevice)).isTrue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user