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

Commit 26ecf9b8 authored by Yuyang Huang's avatar Yuyang Huang
Browse files

Remove the limit of state machines in Bluetooth BLE profiles

The limit of state machines was added to avoid DoS attack. However, it is not necessary because the state machines are created only when a device is connected. The number of connected BLE devices is limited by the Bluetooth controller and system property. Therefore, the limit of state machines is not necessary.
This CL removes the limit of state machines in Bluetooth BLE profiles.

Bug: 316982710
Change-Id: I93322aa5982a2f5a72fb9fa37926ee4164461cb8
Flag: Exempt, max number of BLE devices are guarded by the controller
Test: m packages/modules/Bluetooth
parent 0a72614a
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ public class BatteryService extends ProfileService {
    // Timeout for state machine thread join, to prevent potential ANR.
    private static final int SM_THREAD_JOIN_TIMEOUT_MS = 1_000;

    private static final int MAX_BATTERY_STATE_MACHINES = 10;
    private static BatteryService sBatteryService;
    private AdapterService mAdapterService;
    private DatabaseManager mDatabaseManager;
@@ -411,14 +410,7 @@ public class BatteryService extends ProfileService {
            if (sm != null) {
                return sm;
            }
            // Limit the maximum number of state machines to avoid DoS attack
            if (mStateMachines.size() >= MAX_BATTERY_STATE_MACHINES) {
                Log.e(
                        TAG,
                        "Maximum number of Battery state machines reached: "
                                + MAX_BATTERY_STATE_MACHINES);
                return null;
            }

            Log.d(TAG, "Creating a new state machine for " + device);
            sm = BatteryStateMachine.make(device, this, mStateMachinesThread.getLooper());
            mStateMachines.put(device, sm);
+1 −9
Original line number Diff line number Diff line
@@ -98,7 +98,6 @@ import java.util.concurrent.ConcurrentHashMap;
/** Broacast Assistant Scan Service */
public class BassClientService extends ProfileService {
    private static final String TAG = BassClientService.class.getSimpleName();
    private static final int MAX_BASS_CLIENT_STATE_MACHINES = 10;
    private static final int MAX_ACTIVE_SYNCED_SOURCES_NUM = 4;
    private static final int MAX_BIS_DISCOVERY_TRIES_NUM = 5;

@@ -1159,14 +1158,7 @@ public class BassClientService extends ProfileService {
            if (stateMachine != null) {
                return stateMachine;
            }
            // Limit the maximum number of state machines to avoid DoS attack
            if (mStateMachines.size() >= MAX_BASS_CLIENT_STATE_MACHINES) {
                Log.e(
                        TAG,
                        "Maximum number of Bassclient state machines reached: "
                                + MAX_BASS_CLIENT_STATE_MACHINES);
                return null;
            }

            log("Creating a new state machine for " + device);
            stateMachine =
                    BassObjectsFactory.getInstance()
+1 −10
Original line number Diff line number Diff line
@@ -73,8 +73,6 @@ public class CsipSetCoordinatorService extends ProfileService {
    // Timeout for state machine thread join, to prevent potential ANR.
    private static final int SM_THREAD_JOIN_TIMEOUT_MS = 1000;

    // Upper limit of all CSIP devices: Bonded or Connected
    private static final int MAX_CSIS_STATE_MACHINES = 10;
    private static CsipSetCoordinatorService sCsipSetCoordinatorService;

    private Handler mHandler = null;
@@ -904,14 +902,7 @@ public class CsipSetCoordinatorService extends ProfileService {
            if (sm != null) {
                return sm;
            }
            // Limit the maximum number of state machines to avoid DoS attack
            if (mStateMachines.size() >= MAX_CSIS_STATE_MACHINES) {
                Log.e(
                        TAG,
                        "Maximum number of CSIS state machines reached: "
                                + MAX_CSIS_STATE_MACHINES);
                return null;
            }

            Log.d(TAG, "Creating a new state machine for " + device);
            sm =
                    CsipSetCoordinatorStateMachine.make(
+1 −10
Original line number Diff line number Diff line
@@ -75,8 +75,6 @@ public class VolumeControlService extends ProfileService {
    // Timeout for state machine thread join, to prevent potential ANR.
    private static final int SM_THREAD_JOIN_TIMEOUT_MS = 1000;

    // Upper limit of all VolumeControl devices: Bonded or Connected
    private static final int MAX_VC_STATE_MACHINES = 10;
    private static final int LE_AUDIO_MAX_VOL = 255;

    private static VolumeControlService sVolumeControlService;
@@ -1209,14 +1207,7 @@ public class VolumeControlService extends ProfileService {
            if (sm != null) {
                return sm;
            }
            // Limit the maximum number of state machines to avoid DoS attack
            if (mStateMachines.size() >= MAX_VC_STATE_MACHINES) {
                Log.e(
                        TAG,
                        "Maximum number of VolumeControl state machines reached: "
                                + MAX_VC_STATE_MACHINES);
                return null;
            }

            Log.d(TAG, "Creating a new state machine for " + device);
            sm =
                    VolumeControlStateMachine.make(