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

Commit 8e5270fd authored by Prerepa Viswanadham's avatar Prerepa Viswanadham
Browse files

Tie in BLE hw capabilities with api invocation and support.

Change-Id: Ic1f0b3f156cf2fdde8f04b5c4384e4fd3d79623a
parent 521e86f4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6374,6 +6374,7 @@ package android.bluetooth.le {
    method public abstract void onSuccess(android.bluetooth.le.AdvertiseSettings);
    field public static final int ADVERTISE_FAILED_ALREADY_STARTED = 3; // 0x3
    field public static final int ADVERTISE_FAILED_CONTROLLER_FAILURE = 5; // 0x5
    field public static final int ADVERTISE_FAILED_FEATURE_UNSUPPORTED = 7; // 0x7
    field public static final int ADVERTISE_FAILED_NOT_STARTED = 4; // 0x4
    field public static final int ADVERTISE_FAILED_SERVICE_UNKNOWN = 1; // 0x1
    field public static final int ADVERTISE_FAILED_TOO_MANY_ADVERTISERS = 2; // 0x2
@@ -6445,6 +6446,7 @@ package android.bluetooth.le {
    field public static final int SCAN_FAILED_ALREADY_STARTED = 1; // 0x1
    field public static final int SCAN_FAILED_APPLICATION_REGISTRATION_FAILED = 2; // 0x2
    field public static final int SCAN_FAILED_CONTROLLER_FAILURE = 4; // 0x4
    field public static final int SCAN_FAILED_FEATURE_UNSUPPORTED = 5; // 0x5
    field public static final int SCAN_FAILED_GATT_SERVICE_FAILURE = 3; // 0x3
  }
+6 −0
Original line number Diff line number Diff line
@@ -57,6 +57,12 @@ public abstract class AdvertiseCallback {
     */
    public static final int ADVERTISE_FAILED_GATT_SERVICE_FAILURE = 6;

    /**
     * Operation fails as this feature is not supported
     */
    public static final int ADVERTISE_FAILED_FEATURE_UNSUPPORTED = 7;


    /**
     * Callback when advertising operation succeeds.
     *
+6 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ public final class BluetoothLeAdvertiser {

    private final IBluetoothManager mBluetoothManager;
    private final Handler mHandler;
    private BluetoothAdapter mBluetoothAdapter;
    private final Map<AdvertiseCallback, AdvertiseCallbackWrapper>
            mLeAdvertisers = new HashMap<AdvertiseCallback, AdvertiseCallbackWrapper>();

@@ -62,6 +63,7 @@ public final class BluetoothLeAdvertiser {
     */
    public BluetoothLeAdvertiser(IBluetoothManager bluetoothManager) {
        mBluetoothManager = bluetoothManager;
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        mHandler = new Handler(Looper.getMainLooper());
    }

@@ -112,6 +114,10 @@ public final class BluetoothLeAdvertiser {
            postCallbackFailure(callback, AdvertiseCallback.ADVERTISE_FAILED_CONTROLLER_FAILURE);
            return;
        }
        if (!mBluetoothAdapter.isMultipleAdvertisementSupported()) {
            postCallbackFailure(callback, AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED);
            return;
        }
        AdvertiseCallbackWrapper wrapper = new AdvertiseCallbackWrapper(callback, advertiseData,
                scanResponse, settings, gatt);
        UUID uuid = UUID.randomUUID();
+22 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ public final class BluetoothLeScanner {

    private final IBluetoothManager mBluetoothManager;
    private final Handler mHandler;
    private BluetoothAdapter mBluetoothAdapter;
    private final Map<ScanCallback, BleScanCallbackWrapper> mLeScanClients;

    /**
@@ -61,6 +62,7 @@ public final class BluetoothLeScanner {
     */
    public BluetoothLeScanner(IBluetoothManager bluetoothManager) {
        mBluetoothManager = bluetoothManager;
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        mHandler = new Handler(Looper.getMainLooper());
        mLeScanClients = new HashMap<ScanCallback, BleScanCallbackWrapper>();
    }
@@ -95,6 +97,11 @@ public final class BluetoothLeScanner {
                postCallbackError(callback, ScanCallback.SCAN_FAILED_GATT_SERVICE_FAILURE);
                return;
            }
            if (!isSettingsConfigAllowedForScan(settings)) {
                postCallbackError(callback,
                        ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED);
                return;
            }
            BleScanCallbackWrapper wrapper = new BleScanCallbackWrapper(gatt, filters,
                    settings, callback);
            try {
@@ -424,4 +431,19 @@ public final class BluetoothLeScanner {
            }
        });
    }

    private boolean isSettingsConfigAllowedForScan(ScanSettings settings) {
        boolean ret = true;
        int callbackType;

        callbackType = settings.getCallbackType();
        if (((callbackType == ScanSettings.CALLBACK_TYPE_ON_LOST) ||
                (callbackType == ScanSettings.CALLBACK_TYPE_ON_FOUND) ||
                (callbackType == ScanSettings.CALLBACK_TYPE_ON_UPDATE &&
                settings.getReportDelayNanos() > 0) &&
                (!mBluetoothAdapter.isOffloadedFilteringSupported()))) {
            ret = false;
        }
        return ret;
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -40,6 +40,11 @@ public abstract class ScanCallback {
     */
    public static final int SCAN_FAILED_CONTROLLER_FAILURE = 4;

    /**
     * Fails to start power optimized scan as this feature is not supported.
     */
    public static final int SCAN_FAILED_FEATURE_UNSUPPORTED = 5;

    /**
     * Callback when a BLE advertisement is found.
     *