Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +17 −0 Original line number Diff line number Diff line Loading @@ -2727,6 +2727,23 @@ public class AdapterService extends Service { return mDatabaseManager; } public byte[] getByteIdentityAddress(BluetoothDevice device) { DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device); if (deviceProp.isConsolidated()) { return Utils.getBytesFromAddress(deviceProp.getIdentityAddress()); } else { return Utils.getByteAddress(device); } } public BluetoothDevice getDeviceFromByte(byte[] address) { BluetoothDevice device = mRemoteDevices.getDevice(address); if (device == null) { device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address); } return device; } private class CallerInfo { public String callerPackageName; public UserHandle user; Loading android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +38 −2 Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ final class RemoteDevices { private static final int MESSAGE_UUID_INTENT = 1; private final HashMap<String, DeviceProperties> mDevices; private final HashMap<String, String> mDualDevicesMap; private Queue<String> mDeviceQueue; private final Handler mHandler; Loading Loading @@ -139,6 +140,7 @@ final class RemoteDevices { sAdapterService = service; sSdpTracker = new ArrayList<BluetoothDevice>(); mDevices = new HashMap<String, DeviceProperties>(); mDualDevicesMap = new HashMap<String, String>(); mDeviceQueue = new LinkedList<String>(); mHandler = new RemoteDevicesHandler(looper); } Loading Loading @@ -180,6 +182,10 @@ final class RemoteDevices { mDevices.clear(); } if (mDualDevicesMap != null) { mDualDevicesMap.clear(); } if (mDeviceQueue != null) { mDeviceQueue.clear(); } Loading @@ -197,8 +203,14 @@ final class RemoteDevices { } BluetoothDevice getDevice(byte[] address) { DeviceProperties prop = mDevices.get(Utils.getAddressStringFromByte(address)); String addressString = Utils.getAddressStringFromByte(address); DeviceProperties prop = mDevices.get(addressString); if (prop == null) { String mainAddress = mDualDevicesMap.get(addressString); if (mainAddress != null && mDevices.get(mainAddress) != null) { prop = mDevices.get(mainAddress); return prop.getDevice(); } return null; } return prop.getDevice(); Loading Loading @@ -233,6 +245,8 @@ final class RemoteDevices { class DeviceProperties { private String mName; private byte[] mAddress; private String mIdentityAddress; private boolean mIsConsolidated = false; private int mBluetoothClass = BluetoothClass.Device.Major.UNCATEGORIZED; private short mRssi; private String mAlias; Loading @@ -257,6 +271,24 @@ final class RemoteDevices { } } /** * @return the mIdentityAddress */ String getIdentityAddress() { synchronized (mObject) { return mIdentityAddress; } } /** * @return mIsConsolidated */ boolean isConsolidated() { synchronized (mObject) { return mIsConsolidated; } } /** * @return the mClass */ Loading Loading @@ -677,7 +709,11 @@ final class RemoteDevices { } Log.d(TAG, "addressConsolidateCallback device: " + device + ", secondaryAddress:" + Utils.getAddressStringFromByte(secondaryAddress)); // TODO DeviceProperties deviceProperties = getDeviceProperties(device); deviceProperties.mIsConsolidated = true; deviceProperties.mIdentityAddress = Utils.getAddressStringFromByte(secondaryAddress); mDualDevicesMap.put(deviceProperties.getIdentityAddress(), Utils.getAddressStringFromByte(mainAddress)); } void aclStateChangeCallback(int status, byte[] address, int newState, Loading android/app/src/com/android/bluetooth/pan/PanService.java +7 −4 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ public class PanService extends ProfileService { private BluetoothTetheringNetworkFactory mNetworkFactory; private boolean mStarted = false; private AdapterService mAdapterService; static { classInitNative(); Loading Loading @@ -122,6 +123,8 @@ public class PanService extends ProfileService { @Override protected boolean start() { mAdapterService = Objects.requireNonNull(AdapterService.getAdapterService(), "AdapterService cannot be null when HeadsetService starts"); mDatabaseManager = Objects.requireNonNull(AdapterService.getAdapterService().getDatabase(), "DatabaseManager cannot be null when PanService starts"); Loading @@ -146,6 +149,7 @@ public class PanService extends ProfileService { @Override protected boolean stop() { mAdapterService = null; mHandler.removeCallbacksAndMessages(null); return true; } Loading Loading @@ -185,7 +189,7 @@ public class PanService extends ProfileService { switch (msg.what) { case MESSAGE_CONNECT: { BluetoothDevice device = (BluetoothDevice) msg.obj; if (!connectPanNative(Utils.getByteAddress(device), if (!connectPanNative(mAdapterService.getByteIdentityAddress(device), BluetoothPan.LOCAL_PANU_ROLE, BluetoothPan.REMOTE_NAP_ROLE)) { handlePanDeviceStateChange(device, null, BluetoothProfile.STATE_CONNECTING, BluetoothPan.LOCAL_PANU_ROLE, BluetoothPan.REMOTE_NAP_ROLE); Loading @@ -198,7 +202,7 @@ public class PanService extends ProfileService { break; case MESSAGE_DISCONNECT: { BluetoothDevice device = (BluetoothDevice) msg.obj; if (!disconnectPanNative(Utils.getByteAddress(device))) { if (!disconnectPanNative(mAdapterService.getByteIdentityAddress(device))) { handlePanDeviceStateChange(device, mPanIfName, BluetoothProfile.STATE_DISCONNECTING, BluetoothPan.LOCAL_PANU_ROLE, BluetoothPan.REMOTE_NAP_ROLE); Loading @@ -211,8 +215,7 @@ public class PanService extends ProfileService { break; case MESSAGE_CONNECT_STATE_CHANGED: { ConnectState cs = (ConnectState) msg.obj; final BluetoothDevice device = BluetoothAdapter.getDefaultAdapter() .getRemoteDevice(cs.addr); final BluetoothDevice device = mAdapterService.getDeviceFromByte(cs.addr); // TBD get iface from the msg if (DBG) { Log.d(TAG, Loading system/btif/src/btif_dm.cc +23 −11 Original line number Diff line number Diff line Loading @@ -945,6 +945,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { bt_status_t status = BT_STATUS_FAIL; bt_bond_state_t state = BT_BOND_STATE_NONE; bool skip_sdp = false; bool enable_address_consolidate = false; // TODO remove BTIF_TRACE_DEBUG("%s: bond state=%d, success=%d, key_present=%d", __func__, pairing_cb.state, p_auth_cmpl->success, Loading Loading @@ -1008,8 +1009,19 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { } else { dev_type = p_auth_cmpl->dev_type; } bool is_crosskey = false; if (pairing_cb.state == BT_BOND_STATE_BONDING && p_auth_cmpl->bd_addr != pairing_cb.bd_addr) { LOG_INFO("bonding initiated due to cross key pairing"); is_crosskey = true; } if (!is_crosskey || !enable_address_consolidate) { btif_update_remote_properties(p_auth_cmpl->bd_addr, p_auth_cmpl->bd_name, NULL, dev_type); } pairing_cb.timeout_retries = 0; status = BT_STATUS_SUCCESS; state = BT_BOND_STATE_BONDED; Loading @@ -1032,7 +1044,6 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { invoke_remote_device_properties_cb(BT_STATUS_SUCCESS, bd_addr, 1, &prop); } else { bool is_crosskey = false; /* If bonded due to cross-key, save the static address too*/ if (pairing_cb.state == BT_BOND_STATE_BONDING && p_auth_cmpl->bd_addr != pairing_cb.bd_addr) { Loading @@ -1040,7 +1051,6 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { "%s: bonding initiated due to cross key, adding static address", __func__); pairing_cb.static_bdaddr = bd_addr; is_crosskey = true; } if (!is_crosskey || !(stack_config_get_interface()->get_pts_crosskey_sdp_disable())) { Loading @@ -1050,15 +1060,17 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { /* Trigger SDP on the device */ pairing_cb.sdp_attempts = 1; if (is_crosskey) { // If bonding occurred due to cross-key pairing, send bonding callback // for static address now LOG_INFO("%s: send bonding state update for static address %s", __func__, bd_addr.ToString().c_str()); if (is_crosskey && enable_address_consolidate) { // If bonding occurred due to cross-key pairing, send address // consolidate callback invoke_address_consolidate_cb(pairing_cb.bd_addr, bd_addr); } else if (is_crosskey && !enable_address_consolidate) { // TODO remove bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING); } bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED); } else { bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED); } btif_dm_get_remote_services(bd_addr, BT_TRANSPORT_AUTO); } } Loading Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +17 −0 Original line number Diff line number Diff line Loading @@ -2727,6 +2727,23 @@ public class AdapterService extends Service { return mDatabaseManager; } public byte[] getByteIdentityAddress(BluetoothDevice device) { DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device); if (deviceProp.isConsolidated()) { return Utils.getBytesFromAddress(deviceProp.getIdentityAddress()); } else { return Utils.getByteAddress(device); } } public BluetoothDevice getDeviceFromByte(byte[] address) { BluetoothDevice device = mRemoteDevices.getDevice(address); if (device == null) { device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address); } return device; } private class CallerInfo { public String callerPackageName; public UserHandle user; Loading
android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +38 −2 Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ final class RemoteDevices { private static final int MESSAGE_UUID_INTENT = 1; private final HashMap<String, DeviceProperties> mDevices; private final HashMap<String, String> mDualDevicesMap; private Queue<String> mDeviceQueue; private final Handler mHandler; Loading Loading @@ -139,6 +140,7 @@ final class RemoteDevices { sAdapterService = service; sSdpTracker = new ArrayList<BluetoothDevice>(); mDevices = new HashMap<String, DeviceProperties>(); mDualDevicesMap = new HashMap<String, String>(); mDeviceQueue = new LinkedList<String>(); mHandler = new RemoteDevicesHandler(looper); } Loading Loading @@ -180,6 +182,10 @@ final class RemoteDevices { mDevices.clear(); } if (mDualDevicesMap != null) { mDualDevicesMap.clear(); } if (mDeviceQueue != null) { mDeviceQueue.clear(); } Loading @@ -197,8 +203,14 @@ final class RemoteDevices { } BluetoothDevice getDevice(byte[] address) { DeviceProperties prop = mDevices.get(Utils.getAddressStringFromByte(address)); String addressString = Utils.getAddressStringFromByte(address); DeviceProperties prop = mDevices.get(addressString); if (prop == null) { String mainAddress = mDualDevicesMap.get(addressString); if (mainAddress != null && mDevices.get(mainAddress) != null) { prop = mDevices.get(mainAddress); return prop.getDevice(); } return null; } return prop.getDevice(); Loading Loading @@ -233,6 +245,8 @@ final class RemoteDevices { class DeviceProperties { private String mName; private byte[] mAddress; private String mIdentityAddress; private boolean mIsConsolidated = false; private int mBluetoothClass = BluetoothClass.Device.Major.UNCATEGORIZED; private short mRssi; private String mAlias; Loading @@ -257,6 +271,24 @@ final class RemoteDevices { } } /** * @return the mIdentityAddress */ String getIdentityAddress() { synchronized (mObject) { return mIdentityAddress; } } /** * @return mIsConsolidated */ boolean isConsolidated() { synchronized (mObject) { return mIsConsolidated; } } /** * @return the mClass */ Loading Loading @@ -677,7 +709,11 @@ final class RemoteDevices { } Log.d(TAG, "addressConsolidateCallback device: " + device + ", secondaryAddress:" + Utils.getAddressStringFromByte(secondaryAddress)); // TODO DeviceProperties deviceProperties = getDeviceProperties(device); deviceProperties.mIsConsolidated = true; deviceProperties.mIdentityAddress = Utils.getAddressStringFromByte(secondaryAddress); mDualDevicesMap.put(deviceProperties.getIdentityAddress(), Utils.getAddressStringFromByte(mainAddress)); } void aclStateChangeCallback(int status, byte[] address, int newState, Loading
android/app/src/com/android/bluetooth/pan/PanService.java +7 −4 Original line number Diff line number Diff line Loading @@ -91,6 +91,7 @@ public class PanService extends ProfileService { private BluetoothTetheringNetworkFactory mNetworkFactory; private boolean mStarted = false; private AdapterService mAdapterService; static { classInitNative(); Loading Loading @@ -122,6 +123,8 @@ public class PanService extends ProfileService { @Override protected boolean start() { mAdapterService = Objects.requireNonNull(AdapterService.getAdapterService(), "AdapterService cannot be null when HeadsetService starts"); mDatabaseManager = Objects.requireNonNull(AdapterService.getAdapterService().getDatabase(), "DatabaseManager cannot be null when PanService starts"); Loading @@ -146,6 +149,7 @@ public class PanService extends ProfileService { @Override protected boolean stop() { mAdapterService = null; mHandler.removeCallbacksAndMessages(null); return true; } Loading Loading @@ -185,7 +189,7 @@ public class PanService extends ProfileService { switch (msg.what) { case MESSAGE_CONNECT: { BluetoothDevice device = (BluetoothDevice) msg.obj; if (!connectPanNative(Utils.getByteAddress(device), if (!connectPanNative(mAdapterService.getByteIdentityAddress(device), BluetoothPan.LOCAL_PANU_ROLE, BluetoothPan.REMOTE_NAP_ROLE)) { handlePanDeviceStateChange(device, null, BluetoothProfile.STATE_CONNECTING, BluetoothPan.LOCAL_PANU_ROLE, BluetoothPan.REMOTE_NAP_ROLE); Loading @@ -198,7 +202,7 @@ public class PanService extends ProfileService { break; case MESSAGE_DISCONNECT: { BluetoothDevice device = (BluetoothDevice) msg.obj; if (!disconnectPanNative(Utils.getByteAddress(device))) { if (!disconnectPanNative(mAdapterService.getByteIdentityAddress(device))) { handlePanDeviceStateChange(device, mPanIfName, BluetoothProfile.STATE_DISCONNECTING, BluetoothPan.LOCAL_PANU_ROLE, BluetoothPan.REMOTE_NAP_ROLE); Loading @@ -211,8 +215,7 @@ public class PanService extends ProfileService { break; case MESSAGE_CONNECT_STATE_CHANGED: { ConnectState cs = (ConnectState) msg.obj; final BluetoothDevice device = BluetoothAdapter.getDefaultAdapter() .getRemoteDevice(cs.addr); final BluetoothDevice device = mAdapterService.getDeviceFromByte(cs.addr); // TBD get iface from the msg if (DBG) { Log.d(TAG, Loading
system/btif/src/btif_dm.cc +23 −11 Original line number Diff line number Diff line Loading @@ -945,6 +945,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { bt_status_t status = BT_STATUS_FAIL; bt_bond_state_t state = BT_BOND_STATE_NONE; bool skip_sdp = false; bool enable_address_consolidate = false; // TODO remove BTIF_TRACE_DEBUG("%s: bond state=%d, success=%d, key_present=%d", __func__, pairing_cb.state, p_auth_cmpl->success, Loading Loading @@ -1008,8 +1009,19 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { } else { dev_type = p_auth_cmpl->dev_type; } bool is_crosskey = false; if (pairing_cb.state == BT_BOND_STATE_BONDING && p_auth_cmpl->bd_addr != pairing_cb.bd_addr) { LOG_INFO("bonding initiated due to cross key pairing"); is_crosskey = true; } if (!is_crosskey || !enable_address_consolidate) { btif_update_remote_properties(p_auth_cmpl->bd_addr, p_auth_cmpl->bd_name, NULL, dev_type); } pairing_cb.timeout_retries = 0; status = BT_STATUS_SUCCESS; state = BT_BOND_STATE_BONDED; Loading @@ -1032,7 +1044,6 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { invoke_remote_device_properties_cb(BT_STATUS_SUCCESS, bd_addr, 1, &prop); } else { bool is_crosskey = false; /* If bonded due to cross-key, save the static address too*/ if (pairing_cb.state == BT_BOND_STATE_BONDING && p_auth_cmpl->bd_addr != pairing_cb.bd_addr) { Loading @@ -1040,7 +1051,6 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { "%s: bonding initiated due to cross key, adding static address", __func__); pairing_cb.static_bdaddr = bd_addr; is_crosskey = true; } if (!is_crosskey || !(stack_config_get_interface()->get_pts_crosskey_sdp_disable())) { Loading @@ -1050,15 +1060,17 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { /* Trigger SDP on the device */ pairing_cb.sdp_attempts = 1; if (is_crosskey) { // If bonding occurred due to cross-key pairing, send bonding callback // for static address now LOG_INFO("%s: send bonding state update for static address %s", __func__, bd_addr.ToString().c_str()); if (is_crosskey && enable_address_consolidate) { // If bonding occurred due to cross-key pairing, send address // consolidate callback invoke_address_consolidate_cb(pairing_cb.bd_addr, bd_addr); } else if (is_crosskey && !enable_address_consolidate) { // TODO remove bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING); } bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED); } else { bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED); } btif_dm_get_remote_services(bd_addr, BT_TRANSPORT_AUTO); } } Loading