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

Commit e593d0ae authored by Prerepa Viswanadham's avatar Prerepa Viswanadham
Browse files

Onfound onlost feature.



Change-Id: I5475cb21183abab8cf04af486ff7692396801b92
Signed-off-by: default avatarPrerepa Viswanadham <dham@google.com>
parent 0326f585
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -997,6 +997,24 @@ public final class BluetoothAdapter {
        return false;
    }

    /**
     * Return true if hardware has entries available for matching beacons
     *
     * @return true if there are hw entries available for matching beacons
     * @hide
     */
    public boolean isHardwareTrackingFiltersAvailable() {
        if (getState() != STATE_ON) return false;
        try {
            synchronized(mManagerCallback) {
                if(mService != null) return (mService.numOfHwTrackFiltersAvailable() != 0);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
        return false;
    }

    /**
     * Return the record of {@link BluetoothActivityEnergyInfo} object that
     * has the activity and energy info. This can be used to ascertain what
+1 −0
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ interface IBluetooth
    boolean isActivityAndEnergyReportingSupported();
    void getActivityEnergyInfoFromController();
    BluetoothActivityEnergyInfo reportActivityInfo();
    int numOfHwTrackFiltersAvailable();

    // for dumpsys support
    String dump();
+39 −0
Original line number Diff line number Diff line
@@ -128,6 +128,16 @@ public final class BluetoothLeScanner {
                        ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED);
                return;
            }
            if (!isHardwareResourcesAvailableForScan(settings)) {
                postCallbackError(callback,
                        ScanCallback.SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES);
                return;
            }
            if (!isSettingsAndFilterComboAllowed(settings, filters)) {
                postCallbackError(callback,
                        ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED);
                return;
            }
            BleScanCallbackWrapper wrapper = new BleScanCallbackWrapper(gatt, filters,
                    settings, callback, resultStorages);
            wrapper.startRegisteration();
@@ -394,4 +404,33 @@ public final class BluetoothLeScanner {
        }
        return false;
    }

    private boolean isSettingsAndFilterComboAllowed(ScanSettings settings,
                        List <ScanFilter> filterList) {
        final int callbackType = settings.getCallbackType();
        // If onlost/onfound is requested, a non-empty filter is expected
        if ((callbackType & ScanSettings.CALLBACK_TYPE_FIRST_MATCH
                        | ScanSettings.CALLBACK_TYPE_MATCH_LOST) != 0) {
            if (filterList == null) {
                return false;
            }
            for (ScanFilter filter : filterList) {
                if (filter.isAllFieldsEmpty()) {
                    return false;
                }
            }
        }
        return true;
    }

    private boolean isHardwareResourcesAvailableForScan(ScanSettings settings) {
        final int callbackType = settings.getCallbackType();
        if ((callbackType & ScanSettings.CALLBACK_TYPE_FIRST_MATCH) != 0
                || (callbackType & ScanSettings.CALLBACK_TYPE_MATCH_LOST) != 0) {
            // For onlost/onfound, we required hw support be available
            return (mBluetoothAdapter.isOffloadedFilteringSupported() &&
                    mBluetoothAdapter.isHardwareTrackingFiltersAvailable());
        }
        return true;
    }
}
+8 −2
Original line number Diff line number Diff line
@@ -44,11 +44,17 @@ public abstract class ScanCallback {
     */
    public static final int SCAN_FAILED_FEATURE_UNSUPPORTED = 4;

    /**
     * Fails to start scan as it is out of hardware resources.
     * @hide
     */
    public static final int SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES = 5;

    /**
     * Callback when a BLE advertisement has been found.
     *
     * @param callbackType Determines how this callback was triggered. Currently could only be
     *            {@link ScanSettings#CALLBACK_TYPE_ALL_MATCHES}.
     * @param callbackType Determines how this callback was triggered. Could be of
     *            {@link ScanSettings#CALLBACK_TYPE_ALL_MATCHES}
     * @param result A Bluetooth LE scan result.
     */
    public void onScanResult(int callbackType, ScanResult result) {
+10 −0
Original line number Diff line number Diff line
@@ -67,6 +67,8 @@ public final class ScanFilter implements Parcelable {
    private final byte[] mManufacturerData;
    @Nullable
    private final byte[] mManufacturerDataMask;
    private static final ScanFilter EMPTY = new ScanFilter.Builder().build() ;


    private ScanFilter(String name, String deviceAddress, ParcelUuid uuid,
            ParcelUuid uuidMask, ParcelUuid serviceDataUuid,
@@ -409,6 +411,14 @@ public final class ScanFilter implements Parcelable {
                Objects.equals(mServiceUuidMask, other.mServiceUuidMask);
    }

    /**
     * Checks if the scanfilter is empty
     * @hide
     */
    public boolean isAllFieldsEmpty() {
        return EMPTY.equals(this);
    }

    /**
     * Builder class for {@link ScanFilter}.
     */
Loading