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

Commit 655765e3 authored by Prerepa Viswanadham's avatar Prerepa Viswanadham
Browse files

Use controller provided information about it BLE L feature capabilities

Change-Id: Ia3099c1df2664b79392b2a4f7e3e47d1507a9efe
parent ba865948
Loading
Loading
Loading
Loading
+54 −13
Original line number Diff line number Diff line
@@ -57,6 +57,12 @@ class AdapterProperties {
    private boolean mDiscovering;
    private RemoteDevices mRemoteDevices;
    private BluetoothAdapter mAdapter;
    //TODO - all hw capabilities to be exposed as a class
    private int mNumOfAdvertisementInstancesSupported;
    private boolean mRpaOffloadSupported;
    private int mNumOfOffloadedIrkSupported;
    private int mNumOfOffloadedScanFilterSupported;
    private int mOffloadedScanResultStorageBytes;

    // Lock for all getters and setters.
    // If finer grained locking is needer, more locks
@@ -208,6 +214,41 @@ class AdapterProperties {
        return mState;
    }

    /**
     * @return the mNumOfAdvertisementInstancesSupported
     */
    int getNumOfAdvertisementInstancesSupported() {
        return mNumOfAdvertisementInstancesSupported;
    }

    /**
     * @return the mRpaOffloadSupported
     */
    boolean isRpaOffloadSupported() {
        return mRpaOffloadSupported;
    }

    /**
     * @return the mNumOfOffloadedIrkSupported
     */
    int getNumOfOffloadedIrkSupported() {
        return mNumOfOffloadedIrkSupported;
    }

    /**
     * @return the mNumOfOffloadedScanFilterSupported
     */
    int getNumOfOffloadedScanFilterSupported() {
        return mNumOfOffloadedScanFilterSupported;
    }

    /**
     * @return the mOffloadedScanResultStorageBytes
     */
    int getOffloadedScanResultStorage() {
        return mOffloadedScanResultStorageBytes;
    }

    /**
     * @return the mBondedDevices
     */
@@ -489,19 +530,19 @@ class AdapterProperties {
                        break;

                    case AbstractionLayer.BT_PROPERTY_LOCAL_LE_FEATURES:
                        int local_privacy_enabled = val[0];
                        int max_adv_instance = val [1];
                        int rpa_offload_supported = val [2];
                        int max_irk_list_size = val [3];
                        int max_adv_filter_supported = val[4];
                        int scan_result_storage_size = val[5];

                        debugLog("BT_PROPERTY_LOCAL_LE_FEATURES: privacy = " +local_privacy_enabled
                                      + " max adv instance = " + max_adv_instance
                                      + " rpa_offload_supported = " + rpa_offload_supported
                                      + " max_irk_list_size = " + max_irk_list_size
                                      + " max_adv_filter_supported = " + max_adv_filter_supported
                                      + " scan_result_storage_size = " + scan_result_storage_size);
                        mNumOfAdvertisementInstancesSupported = val[1];
                        mRpaOffloadSupported = (val[2] != 0);
                        mNumOfOffloadedIrkSupported = val[3];
                        mNumOfOffloadedScanFilterSupported = val[4];
                        mOffloadedScanResultStorageBytes = val[5];

                        Log.d(TAG, "BT_PROPERTY_LOCAL_LE_FEATURES: update from BT controller"
                                      + " mNumOfAdvertisementInstancesSupported = " + mNumOfAdvertisementInstancesSupported
                                      + " mRpaOffloadSupported = " + mRpaOffloadSupported
                                      + " mNumOfOffloadedIrkSupported = " + mNumOfOffloadedIrkSupported
                                      + " mNumOfOffloadedScanFilterSupported = "
                                      + mNumOfOffloadedScanFilterSupported
                                      + " mOffloadedScanResultStorageBytes = " + mOffloadedScanResultStorageBytes);
                        break;

                    default:
+25 −0
Original line number Diff line number Diff line
@@ -1410,6 +1410,31 @@ public class AdapterService extends Service {
         mCallbacks.unregister(cb);
      }

    public int getNumOfAdvertisementInstancesSupported() {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        return mAdapterProperties.getNumOfAdvertisementInstancesSupported();
    }

    public boolean isRpaOffloadSupported() {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        return mAdapterProperties.isRpaOffloadSupported();
    }

    public int getNumOfOffloadedIrkSupported() {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        return mAdapterProperties.getNumOfOffloadedIrkSupported();
    }

    public int getNumOfOffloadedScanFilterSupported() {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
        return mAdapterProperties.getNumOfOffloadedScanFilterSupported();
    }

      public int getOffloadedScanResultStorage() {
          enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
          return mAdapterProperties.getOffloadedScanResultStorage();
      }

    private static int convertScanModeToHal(int mode) {
        switch (mode) {
            case BluetoothAdapter.SCAN_MODE_NONE:
+8 −6
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.os.RemoteException;
import android.os.SystemClock;
import android.util.Log;

import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.internal.R;

@@ -121,7 +122,6 @@ public class GattService extends ProfileService {
    private Integer mAdvertisingState = BluetoothAdapter.STATE_ADVERTISE_STOPPED;
    private final Object mLock = new Object();
    private static int lastConfiguredDutyCycle = 0;
    private int mMaxScanFilters;

    /**
     * Pending service declaration queue
@@ -204,7 +204,6 @@ public class GattService extends ProfileService {
        if (DBG) Log.d(TAG, "start()");
        initializeNative();
        mStateMachine = GattServiceStateMachine.make(this);
        mMaxScanFilters = getResources().getInteger(R.integer.config_bluetooth_max_scan_filters);
        return true;
    }

@@ -1326,9 +1325,11 @@ public class GattService extends ProfileService {
            }
            filters.addAll(client.filters);
        }
        // TODO: find a better way to handle too many filters.
        if (filters.size() > mMaxScanFilters) {
            if (DBG) Log.d(TAG, "filters size > " + mMaxScanFilters + ", clearing filters");

        AdapterService adapter = AdapterService.getAdapterService();
        if (filters.size() > adapter.getNumOfOffloadedScanFilterSupported()) {
            if (DBG) Log.d(TAG, "filters size > " + adapter.getNumOfOffloadedScanFilterSupported()
                    + ", clearing filters");
            filters = new HashSet<ScanFilter>();
        }
        return filters;
@@ -1338,7 +1339,8 @@ public class GattService extends ProfileService {
     * Returns whether scan filter is supported.
     */
    boolean isScanFilterSupported() {
        return mMaxScanFilters > 0;
        AdapterService adapter = AdapterService.getAdapterService();
        return adapter.getNumOfOffloadedScanFilterSupported() > 0;
    }

    private void sendStartScanMessage(Set<ScanFilter> filters) {
+4 −5
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ import android.os.Message;
import android.os.ParcelUuid;
import android.os.RemoteException;

import com.android.internal.R;
import com.android.bluetooth.btservice.AdapterService;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;

@@ -98,7 +98,6 @@ final class GattServiceStateMachine extends StateMachine {
    private final Idle mIdle;
    private final ScanStarting mScanStarting;
    private final AdvertiseStarting mAdvertiseStarting;
    private final int mMaxAdvertisers;

    private GattServiceStateMachine(GattService context) {
        super(TAG);
@@ -117,8 +116,6 @@ final class GattServiceStateMachine extends StateMachine {

        // Initial state is idle.
        setInitialState(mIdle);
        mMaxAdvertisers = mService.getResources().getInteger(
                R.integer.config_bluetooth_max_advertisers);
    }

    /**
@@ -188,7 +185,9 @@ final class GattServiceStateMachine extends StateMachine {
                        transitionTo(mIdle);
                        break;
                    }
                    if (mAdvertiseClients.size() >= mMaxAdvertisers) {
                    AdapterService adapter = AdapterService.getAdapterService();
                    int numOfAdvtInstances = adapter.getNumOfAdvertisementInstancesSupported();
                    if (mAdvertiseClients.size() >= numOfAdvtInstances) {
                        loge("too many advertisier, current size : " + mAdvertiseClients.size());
                        try {
                            mService.onMultipleAdvertiseCallback(client.clientIf,