Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e17229ac authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Prevent profiles from initiating connection while the device is removed

Initiating profile connections while the removeBond() API is being serviced may leave the profiles and native modules in a bad state.
This change ensures that new service connections would not be initiated after removeBond() request has been accepted.

Test: mmm packages/modules/Bluetooth
Test: atest BumbleBluetoothTests:PairingTest
Flag: com.android.bluetooth.flags.prevent_service_connections_on_remove_bond
Bug: 374240155
Bug: 378736590

Change-Id: I0df38d5557f5b1f4747b36ae12187135fe8bf583
parent bffb1134
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2698,6 +2698,7 @@ public class AdapterService extends Service {
                return false;
            }
            service.mBondAttemptCallerInfo.remove(device.getAddress());
            service.mPhonePolicy.onRemoveBondRequest(device);
            deviceProp.setBondingInitiatedLocally(false);

            Message msg = service.mBondStateMachine.obtainMessage(BondStateMachine.REMOVE_BOND);
+26 −0
Original line number Diff line number Diff line
@@ -1148,6 +1148,32 @@ public class PhonePolicy implements AdapterService.BluetoothStateCallback {
        }
    }

    /**
     * Resets the service connection policies for the device. This is called when the {@link
     * BluetoothDevice#removeBond} is requested for the device.
     *
     * @param device is the remote device whose services have been discovered
     */
    void onRemoveBondRequest(BluetoothDevice device) {
        if (!Flags.preventServiceConnectionsOnRemoveBond()) {
            return;
        }

        debugLog("onRemoveBondRequest: Disabling all profiles for " + device);
        // Don't allow any profiles to connect to the device.
        for (int profileId = BluetoothProfile.HEADSET;
                profileId < BluetoothProfile.MAX_PROFILE_ID;
                profileId++) {
            if (mAdapterService.getDatabase().getProfileConnectionPolicy(device, profileId)
                    == BluetoothProfile.CONNECTION_POLICY_ALLOWED) {
                mAdapterService
                        .getDatabase()
                        .setProfileConnectionPolicy(
                                device, profileId, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
            }
        }
    }

    private static void debugLog(String msg) {
        Log.d(TAG, msg);
    }
+0 −1
Original line number Diff line number Diff line
@@ -349,7 +349,6 @@ public class DatabaseManager {
     *     BluetoothProfile.CONNECTION_POLICY_FORBIDDEN}, {@link
     *     BluetoothProfile.CONNECTION_POLICY_ALLOWED}
     */
    @VisibleForTesting
    public boolean setProfileConnectionPolicy(
            BluetoothDevice device, int profile, int newConnectionPolicy) {
        if (device == null) {