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

Commit 81294eef authored by Brian Delwiche's avatar Brian Delwiche Committed by Gerrit Code Review
Browse files

Merge "Fix handling for coded and all supported PHY" into main

parents d61e8dc2 e85a40e5
Loading
Loading
Loading
Loading
+44 −11
Original line number Diff line number Diff line
@@ -1038,19 +1038,33 @@ public class ScanManager {
                    // convert scanWindow and scanInterval from ms to LE scan units(0.625ms)
                    int scanWindow = Utils.millsToUnit(scanWindowMs);
                    int scanInterval = Utils.millsToUnit(scanIntervalMs);
                    int scanPhy = getScanPhy(client.settings);
                    int scanPhyMask = getScanPhyMask(client.settings);
                    mNativeInterface.gattClientScan(false);
                    if (!AppScanStats.recordScanRadioStop()) {
                        Log.w(TAG, "There is no scan radio to stop");
                    }
                    Log.d(TAG, "Start gattClientScanNative with"
                            + " old scanMode " + mLastConfiguredScanSetting
                            + " new scanMode " + curScanSetting
                            + " ( in MS: " + scanIntervalMs + " / " + scanWindowMs
                            + ", in scan unit: " + scanInterval + " / " + scanWindow + " )"
                    Log.d(
                            TAG,
                            "Start gattClientScanNative with"
                                    + " old scanMode "
                                    + mLastConfiguredScanSetting
                                    + " new scanMode "
                                    + curScanSetting
                                    + " ( in MS: "
                                    + scanIntervalMs
                                    + " / "
                                    + scanWindowMs
                                    + ", in scan unit: "
                                    + scanInterval
                                    + " / "
                                    + scanWindow
                                    + ", "
                                    + "scanPhyMask: "
                                    + scanPhyMask
                                    + " )"
                                    + client);
                    mNativeInterface.gattSetScanParameters(
                            client.scannerId, scanInterval, scanWindow, scanPhy);
                            client.scannerId, scanInterval, scanWindow, scanPhyMask);
                    mNativeInterface.gattClientScan(true);
                    if (!AppScanStats.recordScanRadioStart(curScanSetting)) {
                        Log.w(TAG, "Scan radio already started");
@@ -1722,6 +1736,25 @@ public class ScanManager {
            return settings.getPhy();
        }

        private int getScanPhyMask(ScanSettings settings) {
            int phy = getScanPhy(settings);

            switch (phy) {
                case BluetoothDevice.PHY_LE_1M:
                    return BluetoothDevice.PHY_LE_1M_MASK;
                case BluetoothDevice.PHY_LE_CODED:
                    return BluetoothDevice.PHY_LE_CODED_MASK;
                case ScanSettings.PHY_LE_ALL_SUPPORTED:
                    if (mAdapterService.isLeCodedPhySupported()) {
                        return BluetoothDevice.PHY_LE_1M_MASK | BluetoothDevice.PHY_LE_CODED_MASK;
                    } else {
                        return BluetoothDevice.PHY_LE_1M_MASK;
                    }
                default:
                    return BluetoothDevice.PHY_LE_1M_MASK;
            }
        }

        private int getOnFoundOnLostTimeoutMillis(ScanSettings settings, boolean onFound) {
            int factor;
            int timeout = ONLOST_ONFOUND_BASE_TIMEOUT_MS;
+48 −2
Original line number Diff line number Diff line
@@ -16,7 +16,11 @@

package com.android.bluetooth.le_scan;

import static android.bluetooth.BluetoothDevice.PHY_LE_CODED;
import static android.bluetooth.BluetoothDevice.PHY_LE_1M_MASK;
import static android.bluetooth.BluetoothDevice.PHY_LE_CODED_MASK;
import static android.bluetooth.le.ScanSettings.CALLBACK_TYPE_ALL_MATCHES_AUTO_BATCH;
import static android.bluetooth.le.ScanSettings.PHY_LE_ALL_SUPPORTED;
import static android.bluetooth.le.ScanSettings.SCAN_MODE_AMBIENT_DISCOVERY;
import static android.bluetooth.le.ScanSettings.SCAN_MODE_BALANCED;
import static android.bluetooth.le.ScanSettings.SCAN_MODE_LOW_LATENCY;
@@ -1547,7 +1551,7 @@ public class ScanManagerTest {
        scanModeMap.put(SCAN_MODE_AMBIENT_DISCOVERY, SCAN_MODE_AMBIENT_DISCOVERY);

        for (int i = 0; i < scanModeMap.size(); i++) {
            int phy = 2;
            int phy = PHY_LE_CODED;
            int ScanMode = scanModeMap.keyAt(i);
            int expectedScanMode = scanModeMap.get(ScanMode);
            Log.d(
@@ -1567,7 +1571,49 @@ public class ScanManagerTest {

            assertThat(client.settings.getPhy()).isEqualTo(phy);
            verify(mScanNativeInterface, atLeastOnce())
                    .gattSetScanParameters(anyInt(), anyInt(), anyInt(), eq(phy));
                    .gattSetScanParameters(anyInt(), anyInt(), anyInt(), eq(PHY_LE_CODED_MASK));
        }
    }

    @Test
    public void testSetScanPhyAllSupported() {
        final boolean isFiltered = false;
        final boolean isEmptyFilter = false;
        // Set scan mode map {original scan mode (ScanMode) : expected scan mode (expectedScanMode)}
        SparseIntArray scanModeMap = new SparseIntArray();
        scanModeMap.put(SCAN_MODE_LOW_POWER, SCAN_MODE_LOW_POWER);
        scanModeMap.put(SCAN_MODE_BALANCED, SCAN_MODE_BALANCED);
        scanModeMap.put(SCAN_MODE_LOW_LATENCY, SCAN_MODE_LOW_LATENCY);
        scanModeMap.put(SCAN_MODE_AMBIENT_DISCOVERY, SCAN_MODE_AMBIENT_DISCOVERY);

        for (int i = 0; i < scanModeMap.size(); i++) {
            int phy = PHY_LE_ALL_SUPPORTED;
            int ScanMode = scanModeMap.keyAt(i);
            boolean adapterServiceSupportsCoded = mAdapterService.isLeCodedPhySupported();
            int expectedScanMode = scanModeMap.get(ScanMode);
            int expectedPhy;

            if (adapterServiceSupportsCoded) expectedPhy = PHY_LE_1M_MASK & PHY_LE_CODED_MASK;
            else expectedPhy = PHY_LE_1M_MASK;

            Log.d(
                    TAG,
                    "ScanMode: "
                            + String.valueOf(ScanMode)
                            + " expectedScanMode: "
                            + String.valueOf(expectedScanMode));

            // Turn on screen
            sendMessageWaitForProcessed(createScreenOnOffMessage(true));
            // Create scan client
            ScanClient client =
                    createScanClientWithPhy(i, isFiltered, isEmptyFilter, ScanMode, phy);
            // Start scan
            sendMessageWaitForProcessed(createStartStopScanMessage(true, client));

            assertThat(client.settings.getPhy()).isEqualTo(phy);
            verify(mScanNativeInterface, atLeastOnce())
                    .gattSetScanParameters(anyInt(), anyInt(), anyInt(), eq(expectedPhy));
        }
    }
}