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

Commit 3ee2428e authored by Prerepa Viswanadham's avatar Prerepa Viswanadham
Browse files

OnFound/Lost reporting: s/w detects the first match and

hw signal is used to report onlost.

Bug 16733710

Change-Id: I4d1d0320b6894fe1af59192eb56a4a801609049a
parent c11d8485
Loading
Loading
Loading
Loading
+37 −11
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ public class GattService extends ProfileService {
    private List<UUID> mAdvertisingServiceUuids = new ArrayList<UUID>();

    private int mMaxScanFilters;
    private Map<ScanClient, ScanResult> mOnFoundResults = new HashMap<ScanClient, ScanResult>();

    /**
     * Pending service declaration queue
@@ -579,7 +580,22 @@ public class GattService extends ProfileService {
                            rssi, scanTimeNanos);
                    if (matchesFilters(client, result)) {
                        try {
                            ScanSettings settings = client.settings;
                            // framework detects the first match, hw signal is
                            // used to detect the onlost
                            // ToDo: make scanClient+result, 1 to many when hw
                            // support is available
                            if ((settings.getCallbackType() &
                                    ScanSettings.CALLBACK_TYPE_FIRST_MATCH) != 0) {
                                synchronized (mOnFoundResults) {
                                    mOnFoundResults.put(client, result);
                                }
                                app.callback.onFoundOrLost(true, result);
                            }
                            if ((settings.getCallbackType() &
                                    ScanSettings.CALLBACK_TYPE_ALL_MATCHES) != 0) {
                                app.callback.onScanResult(result);
                            }
                        } catch (RemoteException e) {
                            Log.e(TAG, "Exception: " + e);
                            mClientMap.remove(client.clientIf);
@@ -1107,17 +1123,27 @@ public class GattService extends ProfileService {
            Log.e(TAG, "app or callback is null");
            return;
        }
        if (advState == ADVT_STATE_ONFOUND || advState == ADVT_STATE_ONLOST) {
            int rssi = 0;
            byte [] advData = new byte[0];
            boolean found;
            if (advState == ADVT_STATE_ONFOUND) {
                found = true;
            } else {
                found = false;

        // use hw signal for only onlost reporting
        if (advState != ADVT_STATE_ONLOST) {
            return;
        }

        for (ScanClient client : mScanManager.scanQueue()) {
            if (client.clientIf == clientIf) {
                ScanSettings settings = client.settings;
                if ((settings.getCallbackType() &
                            ScanSettings.CALLBACK_TYPE_MATCH_LOST) != 0) {

                    while (!mOnFoundResults.isEmpty()) {
                        ScanResult result = mOnFoundResults.get(client);
                        app.callback.onFoundOrLost(false, result);
                        synchronized (mOnFoundResults) {
                            mOnFoundResults.remove(client);
                        }
                    }
                }
            }
            //ToDo: Address reporting format and content and then enable
            app.callback.onFoundOrLost(found, address, rssi, advData);
        }
    }

+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import java.util.UUID;
    UUID[] uuids;
    ScanSettings settings;
    List<ScanFilter> filters;

    private static final ScanSettings DEFAULT_SCAN_SETTINGS = new ScanSettings.Builder()
            .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();

+19 −5
Original line number Diff line number Diff line
@@ -240,9 +240,12 @@ public class ScanManager {

        // Delivery mode defined in bt stack.
        private static final int DELIVERY_MODE_IMMEDIATE = 0;
        private static final int DELIVERY_MODE_ON_FOUND = 1;
        private static final int DELIVERY_MODE_ON_FOUND_LOST = 1;
        private static final int DELIVERY_MODE_BATCH = 2;

        private static final int DEFAULT_ONLOST_ONFOUND_TIMEOUT_MILLIS = 1000;
        private static final int ONFOUND_SIGHTINGS = 2;

        private static final int ALLOW_ALL_FILTER_INDEX = 1;
        private static final int ALLOW_ALL_FILTER_SELECTION = 0;

@@ -594,10 +597,11 @@ public class ScanManager {
                int filterIndex) {
            int deliveryMode = getDeliveryMode(client);
            int rssiThreshold = Byte.MIN_VALUE;
            int timeout = getOnfoundLostTimeout(client);
            gattClientScanFilterParamAddNative(
                    clientIf, filterIndex, featureSelection, LIST_LOGIC_TYPE,
                    FILTER_LOGIC_TYPE, rssiThreshold, rssiThreshold, deliveryMode,
                    0, 0, 0);
                    timeout, timeout, ONFOUND_SIGHTINGS);
        }

        // Get delivery mode based on scan settings.
@@ -609,16 +613,26 @@ public class ScanManager {
            if (settings == null) {
                return DELIVERY_MODE_IMMEDIATE;
            }
            // TODO: double check whether it makes sense to use the same delivery mode for found and
            // lost.
            if ((settings.getCallbackType() & ScanSettings.CALLBACK_TYPE_FIRST_MATCH) != 0
                    || (settings.getCallbackType() & ScanSettings.CALLBACK_TYPE_MATCH_LOST) != 0) {
                return DELIVERY_MODE_ON_FOUND;
                return DELIVERY_MODE_ON_FOUND_LOST;
            }
            return settings.getReportDelayMillis() == 0 ? DELIVERY_MODE_IMMEDIATE
                    : DELIVERY_MODE_BATCH;
        }

        //Get onfound and onlost timeouts in ms
        private int getOnfoundLostTimeout(ScanClient client) {
            if (client == null) {
                return DEFAULT_ONLOST_ONFOUND_TIMEOUT_MILLIS;
            }
            ScanSettings settings = client.settings;
            if (settings == null) {
                return DEFAULT_ONLOST_ONFOUND_TIMEOUT_MILLIS;
            }
            return (int)settings.getReportDelayMillis();
        }

        /************************** Regular scan related native methods **************************/
        private native void gattClientScanNative(boolean start);