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

Commit 9e60546a authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Added internal API getMaxConnectedAudioDevices()

The API can be used to obtain the maximum number of connected
devices for A2DP or HFP.

Test: Manual
Bug: 64767509

Change-Id: I20242585f6343ecfac21353d3c6194641d1f63af
parent 6a8ef37a
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.ParcelUuid;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.util.Log;
import android.util.Pair;
@@ -53,6 +54,10 @@ class AdapterProperties {
    private static final boolean VDBG = false;
    private static final String TAG = "BluetoothAdapterProperties";

    private static final String MAX_CONNECTED_AUDIO_DEVICES_PROPERTY =
            "persist.bluetooth.maxconnectedaudiodevices";
    static final int MIN_CONNECTED_AUDIO_DEVICES = 1;

    private static final long DEFAULT_DISCOVERY_TIMEOUT_MS = 12800;
    private static final int BD_ADDR_LEN = 6; // in bytes

@@ -71,6 +76,7 @@ class AdapterProperties {

    private volatile int mConnectionState = BluetoothAdapter.STATE_DISCONNECTED;
    private volatile int mState = BluetoothAdapter.STATE_OFF;
    private int mMaxConnectedAudioDevices = 1;

    private AdapterService mService;
    private boolean mDiscovering;
@@ -164,6 +170,9 @@ class AdapterProperties {
        mProfileConnectionState.clear();
        mRemoteDevices = remoteDevices;

        mMaxConnectedAudioDevices = SystemProperties.getInt(
                MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, MIN_CONNECTED_AUDIO_DEVICES);

        IntentFilter filter = new IntentFilter();
        filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED);
@@ -397,6 +406,13 @@ class AdapterProperties {
        return mTotNumOfTrackableAdv;
    }

    /**
     * @return the maximum number of connected audio devices
     */
    int getMaxConnectedAudioDevices() {
        return mMaxConnectedAudioDevices;
    }

    /**
     * @return the mBondedDevices
     */
+16 −0
Original line number Diff line number Diff line
@@ -1495,6 +1495,16 @@ public class AdapterService extends Service {
            return service.getBatteryLevel(device);
        }

        @Override
        public int getMaxConnectedAudioDevices() {
            // don't check caller, may be called from system UI
            AdapterService service = getService();
            if (service == null) {
                return AdapterProperties.MIN_CONNECTED_AUDIO_DEVICES;
            }
            return service.getMaxConnectedAudioDevices();
        }

        @Override
        public boolean factoryReset() {
            AdapterService service = getService();
@@ -2008,6 +2018,12 @@ public class AdapterService extends Service {
        return deviceProp.getBatteryLevel();
    }

    int getMaxConnectedAudioDevices() {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");

        return mAdapterProperties.getMaxConnectedAudioDevices();
    }

    boolean setPin(BluetoothDevice device, boolean accept, int len, byte[] pinCode) {
        enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH ADMIN permission");
        DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device);