Loading src/com/android/bluetooth/a2dp/A2dpService.java +16 −10 Original line number Diff line number Diff line Loading @@ -351,18 +351,24 @@ public class A2dpService extends ProfileService { return false; } // Check priority and accept or reject the connection. // Note: Logic can be simplified, but keeping it this way for readability int priority = getPriority(device); int bondState = mAdapterService.getBondState(device); // Allow this connection only if the device is bonded. Any attempt to connect while // bonding would potentially lead to an unauthorized connection. if (bondState != BluetoothDevice.BOND_BONDED) { Log.w(TAG, "okToConnect: return false, bondState=" + bondState); return false; } else if (priority != BluetoothProfile.PRIORITY_UNDEFINED && priority != BluetoothProfile.PRIORITY_ON && priority != BluetoothProfile.PRIORITY_AUTO_CONNECT) { // Otherwise, reject the connection if priority is not valid. Log.w(TAG, "okToConnect: return false, priority=" + priority); // If priority is undefined, it is likely that service discovery has not completed and peer // initiated the connection. Allow this connection only if the device is bonded or bonding boolean serviceDiscoveryPending = (priority == BluetoothProfile.PRIORITY_UNDEFINED) && (bondState == BluetoothDevice.BOND_BONDING || bondState == BluetoothDevice.BOND_BONDED); // Also allow connection when device is bonded/bonding and priority is ON/AUTO_CONNECT. boolean isEnabled = (priority == BluetoothProfile.PRIORITY_ON || priority == BluetoothProfile.PRIORITY_AUTO_CONNECT) && (bondState == BluetoothDevice.BOND_BONDED || bondState == BluetoothDevice.BOND_BONDING); if (!serviceDiscoveryPending && !isEnabled) { // Otherwise, reject the connection if no service discovery is pending and priority is // neither PRIORITY_ON nor PRIORITY_AUTO_CONNECT Log.w(TAG, "okToConnect: return false, priority=" + priority + ", bondState=" + bondState); return false; } return true; Loading src/com/android/bluetooth/btservice/AdapterProperties.java +0 −1 Original line number Diff line number Diff line Loading @@ -511,7 +511,6 @@ class AdapterProperties { // This function shall be invoked from BondStateMachine whenever the bond // state changes. @VisibleForTesting void onBondStateChanged(BluetoothDevice device, int state) { if (device == null) { Log.w(TAG, "onBondStateChanged, device is null"); Loading src/com/android/bluetooth/btservice/AdapterService.java +0 −12 Original line number Diff line number Diff line Loading @@ -2046,18 +2046,6 @@ public class AdapterService extends Service { } } /** * Update device UUID changed to {@link BondStateMachine} * * @param device remote device of interest */ public void deviceUuidUpdated(BluetoothDevice device) { // Notify BondStateMachine for SDP complete / UUID changed. Message msg = mBondStateMachine.obtainMessage(BondStateMachine.UUID_UPDATE); msg.obj = device; mBondStateMachine.sendMessage(msg); } boolean cancelBondProcess(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission"); byte[] addr = Utils.getBytesFromAddress(device.getAddress()); Loading src/com/android/bluetooth/btservice/BondStateMachine.java +2 −44 Original line number Diff line number Diff line Loading @@ -36,7 +36,6 @@ import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.hfpclient.HeadsetClientService; import com.android.bluetooth.hid.HidHostService; import com.android.bluetooth.pbapclient.PbapClientService; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.State; import com.android.internal.util.StateMachine; Loading @@ -63,7 +62,6 @@ final class BondStateMachine extends StateMachine { static final int BONDING_STATE_CHANGE = 4; static final int SSP_REQUEST = 5; static final int PIN_REQUEST = 6; static final int UUID_UPDATE = 10; static final int BOND_STATE_NONE = 0; static final int BOND_STATE_BONDING = 1; static final int BOND_STATE_BONDED = 2; Loading @@ -78,8 +76,6 @@ final class BondStateMachine extends StateMachine { public static final String OOBDATA = "oobdata"; @VisibleForTesting Set<BluetoothDevice> mPendingBondedDevices = new HashSet<>(); private BondStateMachine(AdapterService service, AdapterProperties prop, RemoteDevices remoteDevices) { super("BondStateMachine:"); Loading Loading @@ -153,11 +149,7 @@ final class BondStateMachine extends StateMachine { + state2str(newState)); } break; case UUID_UPDATE: if (mPendingBondedDevices.contains(dev)) { sendIntent(dev, BluetoothDevice.BOND_BONDED, 0); } break; case CANCEL_BOND: default: Log.e(TAG, "Received unhandled state: " + msg.what); Loading Loading @@ -358,31 +350,12 @@ final class BondStateMachine extends StateMachine { mAdapterService.sendOrderedBroadcast(intent, mAdapterService.BLUETOOTH_ADMIN_PERM); } @VisibleForTesting void sendIntent(BluetoothDevice device, int newState, int reason) { private void sendIntent(BluetoothDevice device, int newState, int reason) { DeviceProperties devProp = mRemoteDevices.getDeviceProperties(device); int oldState = BluetoothDevice.BOND_NONE; if (newState != BluetoothDevice.BOND_NONE && newState != BluetoothDevice.BOND_BONDING && newState != BluetoothDevice.BOND_BONDED) { infoLog("Invalid bond state " + newState); return; } if (devProp != null) { oldState = devProp.getBondState(); } if (mPendingBondedDevices.contains(device)) { mPendingBondedDevices.remove(device); if (oldState == BluetoothDevice.BOND_BONDED) { if (newState == BluetoothDevice.BOND_BONDING) { mAdapterProperties.onBondStateChanged(device, newState); } oldState = BluetoothDevice.BOND_BONDING; } else { // Should not enter here. throw new IllegalArgumentException("Invalid old state " + oldState); } } if (oldState == newState) { return; } Loading @@ -391,21 +364,6 @@ final class BondStateMachine extends StateMachine { newState, BluetoothProtoEnums.BOND_SUB_STATE_UNKNOWN, reason); mAdapterProperties.onBondStateChanged(device, newState); if ((devProp.getDeviceType() == BluetoothDevice.DEVICE_TYPE_CLASSIC || devProp.getDeviceType() == BluetoothDevice.DEVICE_TYPE_DUAL) && newState == BluetoothDevice.BOND_BONDED && devProp.getUuids() == null) { infoLog(device + " is bonded, wait for SDP complete to broadcast bonded intent"); if (!mPendingBondedDevices.contains(device)) { mPendingBondedDevices.add(device); } if (oldState == BluetoothDevice.BOND_NONE) { // Broadcast NONE->BONDING for NONE->BONDED case. newState = BluetoothDevice.BOND_BONDING; } else { return; } } Intent intent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, newState); Loading src/com/android/bluetooth/btservice/RemoteDevices.java +4 −5 Original line number Diff line number Diff line Loading @@ -179,7 +179,6 @@ final class RemoteDevices { return prop.getDevice(); } @VisibleForTesting DeviceProperties addDeviceProperties(byte[] address) { synchronized (mDevices) { DeviceProperties prop = new DeviceProperties(); Loading Loading @@ -210,13 +209,13 @@ final class RemoteDevices { private byte[] mAddress; private int mBluetoothClass = BluetoothClass.Device.Major.UNCATEGORIZED; private short mRssi; private ParcelUuid[] mUuids; private int mDeviceType; private String mAlias; private int mBondState; private BluetoothDevice mDevice; private boolean mIsBondingInitiatedLocally; private int mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN; @VisibleForTesting int mBondState; @VisibleForTesting int mDeviceType; @VisibleForTesting ParcelUuid[] mUuids; DeviceProperties() { mBondState = BluetoothDevice.BOND_NONE; Loading Loading @@ -275,6 +274,7 @@ final class RemoteDevices { return mRssi; } } /** * @return mDeviceType */ Loading Loading @@ -547,7 +547,6 @@ final class RemoteDevices { } device.mUuids = newUuids; if (sAdapterService.getState() == BluetoothAdapter.STATE_ON) { sAdapterService.deviceUuidUpdated(bdDevice); sendUuidIntent(bdDevice, device); } break; Loading Loading
src/com/android/bluetooth/a2dp/A2dpService.java +16 −10 Original line number Diff line number Diff line Loading @@ -351,18 +351,24 @@ public class A2dpService extends ProfileService { return false; } // Check priority and accept or reject the connection. // Note: Logic can be simplified, but keeping it this way for readability int priority = getPriority(device); int bondState = mAdapterService.getBondState(device); // Allow this connection only if the device is bonded. Any attempt to connect while // bonding would potentially lead to an unauthorized connection. if (bondState != BluetoothDevice.BOND_BONDED) { Log.w(TAG, "okToConnect: return false, bondState=" + bondState); return false; } else if (priority != BluetoothProfile.PRIORITY_UNDEFINED && priority != BluetoothProfile.PRIORITY_ON && priority != BluetoothProfile.PRIORITY_AUTO_CONNECT) { // Otherwise, reject the connection if priority is not valid. Log.w(TAG, "okToConnect: return false, priority=" + priority); // If priority is undefined, it is likely that service discovery has not completed and peer // initiated the connection. Allow this connection only if the device is bonded or bonding boolean serviceDiscoveryPending = (priority == BluetoothProfile.PRIORITY_UNDEFINED) && (bondState == BluetoothDevice.BOND_BONDING || bondState == BluetoothDevice.BOND_BONDED); // Also allow connection when device is bonded/bonding and priority is ON/AUTO_CONNECT. boolean isEnabled = (priority == BluetoothProfile.PRIORITY_ON || priority == BluetoothProfile.PRIORITY_AUTO_CONNECT) && (bondState == BluetoothDevice.BOND_BONDED || bondState == BluetoothDevice.BOND_BONDING); if (!serviceDiscoveryPending && !isEnabled) { // Otherwise, reject the connection if no service discovery is pending and priority is // neither PRIORITY_ON nor PRIORITY_AUTO_CONNECT Log.w(TAG, "okToConnect: return false, priority=" + priority + ", bondState=" + bondState); return false; } return true; Loading
src/com/android/bluetooth/btservice/AdapterProperties.java +0 −1 Original line number Diff line number Diff line Loading @@ -511,7 +511,6 @@ class AdapterProperties { // This function shall be invoked from BondStateMachine whenever the bond // state changes. @VisibleForTesting void onBondStateChanged(BluetoothDevice device, int state) { if (device == null) { Log.w(TAG, "onBondStateChanged, device is null"); Loading
src/com/android/bluetooth/btservice/AdapterService.java +0 −12 Original line number Diff line number Diff line Loading @@ -2046,18 +2046,6 @@ public class AdapterService extends Service { } } /** * Update device UUID changed to {@link BondStateMachine} * * @param device remote device of interest */ public void deviceUuidUpdated(BluetoothDevice device) { // Notify BondStateMachine for SDP complete / UUID changed. Message msg = mBondStateMachine.obtainMessage(BondStateMachine.UUID_UPDATE); msg.obj = device; mBondStateMachine.sendMessage(msg); } boolean cancelBondProcess(BluetoothDevice device) { enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission"); byte[] addr = Utils.getBytesFromAddress(device.getAddress()); Loading
src/com/android/bluetooth/btservice/BondStateMachine.java +2 −44 Original line number Diff line number Diff line Loading @@ -36,7 +36,6 @@ import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.hfpclient.HeadsetClientService; import com.android.bluetooth.hid.HidHostService; import com.android.bluetooth.pbapclient.PbapClientService; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.State; import com.android.internal.util.StateMachine; Loading @@ -63,7 +62,6 @@ final class BondStateMachine extends StateMachine { static final int BONDING_STATE_CHANGE = 4; static final int SSP_REQUEST = 5; static final int PIN_REQUEST = 6; static final int UUID_UPDATE = 10; static final int BOND_STATE_NONE = 0; static final int BOND_STATE_BONDING = 1; static final int BOND_STATE_BONDED = 2; Loading @@ -78,8 +76,6 @@ final class BondStateMachine extends StateMachine { public static final String OOBDATA = "oobdata"; @VisibleForTesting Set<BluetoothDevice> mPendingBondedDevices = new HashSet<>(); private BondStateMachine(AdapterService service, AdapterProperties prop, RemoteDevices remoteDevices) { super("BondStateMachine:"); Loading Loading @@ -153,11 +149,7 @@ final class BondStateMachine extends StateMachine { + state2str(newState)); } break; case UUID_UPDATE: if (mPendingBondedDevices.contains(dev)) { sendIntent(dev, BluetoothDevice.BOND_BONDED, 0); } break; case CANCEL_BOND: default: Log.e(TAG, "Received unhandled state: " + msg.what); Loading Loading @@ -358,31 +350,12 @@ final class BondStateMachine extends StateMachine { mAdapterService.sendOrderedBroadcast(intent, mAdapterService.BLUETOOTH_ADMIN_PERM); } @VisibleForTesting void sendIntent(BluetoothDevice device, int newState, int reason) { private void sendIntent(BluetoothDevice device, int newState, int reason) { DeviceProperties devProp = mRemoteDevices.getDeviceProperties(device); int oldState = BluetoothDevice.BOND_NONE; if (newState != BluetoothDevice.BOND_NONE && newState != BluetoothDevice.BOND_BONDING && newState != BluetoothDevice.BOND_BONDED) { infoLog("Invalid bond state " + newState); return; } if (devProp != null) { oldState = devProp.getBondState(); } if (mPendingBondedDevices.contains(device)) { mPendingBondedDevices.remove(device); if (oldState == BluetoothDevice.BOND_BONDED) { if (newState == BluetoothDevice.BOND_BONDING) { mAdapterProperties.onBondStateChanged(device, newState); } oldState = BluetoothDevice.BOND_BONDING; } else { // Should not enter here. throw new IllegalArgumentException("Invalid old state " + oldState); } } if (oldState == newState) { return; } Loading @@ -391,21 +364,6 @@ final class BondStateMachine extends StateMachine { newState, BluetoothProtoEnums.BOND_SUB_STATE_UNKNOWN, reason); mAdapterProperties.onBondStateChanged(device, newState); if ((devProp.getDeviceType() == BluetoothDevice.DEVICE_TYPE_CLASSIC || devProp.getDeviceType() == BluetoothDevice.DEVICE_TYPE_DUAL) && newState == BluetoothDevice.BOND_BONDED && devProp.getUuids() == null) { infoLog(device + " is bonded, wait for SDP complete to broadcast bonded intent"); if (!mPendingBondedDevices.contains(device)) { mPendingBondedDevices.add(device); } if (oldState == BluetoothDevice.BOND_NONE) { // Broadcast NONE->BONDING for NONE->BONDED case. newState = BluetoothDevice.BOND_BONDING; } else { return; } } Intent intent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothDevice.EXTRA_BOND_STATE, newState); Loading
src/com/android/bluetooth/btservice/RemoteDevices.java +4 −5 Original line number Diff line number Diff line Loading @@ -179,7 +179,6 @@ final class RemoteDevices { return prop.getDevice(); } @VisibleForTesting DeviceProperties addDeviceProperties(byte[] address) { synchronized (mDevices) { DeviceProperties prop = new DeviceProperties(); Loading Loading @@ -210,13 +209,13 @@ final class RemoteDevices { private byte[] mAddress; private int mBluetoothClass = BluetoothClass.Device.Major.UNCATEGORIZED; private short mRssi; private ParcelUuid[] mUuids; private int mDeviceType; private String mAlias; private int mBondState; private BluetoothDevice mDevice; private boolean mIsBondingInitiatedLocally; private int mBatteryLevel = BluetoothDevice.BATTERY_LEVEL_UNKNOWN; @VisibleForTesting int mBondState; @VisibleForTesting int mDeviceType; @VisibleForTesting ParcelUuid[] mUuids; DeviceProperties() { mBondState = BluetoothDevice.BOND_NONE; Loading Loading @@ -275,6 +274,7 @@ final class RemoteDevices { return mRssi; } } /** * @return mDeviceType */ Loading Loading @@ -547,7 +547,6 @@ final class RemoteDevices { } device.mUuids = newUuids; if (sAdapterService.getState() == BluetoothAdapter.STATE_ON) { sAdapterService.deviceUuidUpdated(bdDevice); sendUuidIntent(bdDevice, device); } break; Loading