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

Commit a076e798 authored by Kai Shi's avatar Kai Shi
Browse files

Scan parameter optimization

1) Adjust balanced/low power scan parameter based on the lab results.
2) Make screen off mode parameters configurable.
3) Reduce low latency mode scan interval to 100ms for the better channel
   diversity. Test results indicate there is no change of discovery
   latency with the small scan interval in the home environment.

Bug: 214595841
Test: manual with BLE scan app to ensure scan parameters are set
correctly.

Change-Id: I71f27621b5fe6e36203d8b78d44b9e21f0fa7ec5
parent fb2277f3
Loading
Loading
Loading
Loading
+69 −0
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.btservice.storage.MetadataDatabase;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
import com.android.bluetooth.gatt.GattService;
import com.android.bluetooth.gatt.ScanManager;
import com.android.bluetooth.hap.HapClientService;
import com.android.bluetooth.hearingaid.HearingAidService;
import com.android.bluetooth.hfp.HeadsetService;
@@ -5110,6 +5111,18 @@ public class AdapterService extends Service {
    @GuardedBy("mDeviceConfigLock")
    private int mScanUpgradeDurationMillis =
            DeviceConfigListener.DEFAULT_SCAN_UPGRADE_DURATION_MILLIS;
    @GuardedBy("mDeviceConfigLock")
    private int mScreenOffLowPowerWindowMillis =
            ScanManager.SCAN_MODE_SCREEN_OFF_LOW_POWER_WINDOW_MS;
    @GuardedBy("mDeviceConfigLock")
    private int mScreenOffLowPowerIntervalMillis =
            ScanManager.SCAN_MODE_SCREEN_OFF_LOW_POWER_INTERVAL_MS;
    @GuardedBy("mDeviceConfigLock")
    private int mScreenOffBalancedWindowMillis =
            ScanManager.SCAN_MODE_SCREEN_OFF_BALANCED_WINDOW_MS;
    @GuardedBy("mDeviceConfigLock")
    private int mScreenOffBalancedIntervalMillis =
            ScanManager.SCAN_MODE_SCREEN_OFF_BALANCED_INTERVAL_MS;

    public @NonNull Predicate<String> getLocationDenylistName() {
        synchronized (mDeviceConfigLock) {
@@ -5156,6 +5169,42 @@ public class AdapterService extends Service {
        }
    }

    /**
     * Returns SCREEN_OFF_BALANCED scan window in millis.
     */
    public int getScreenOffBalancedWindowMillis() {
        synchronized (mDeviceConfigLock) {
            return mScreenOffBalancedWindowMillis;
        }
    }

    /**
     * Returns SCREEN_OFF_BALANCED scan interval in millis.
     */
    public int getScreenOffBalancedIntervalMillis() {
        synchronized (mDeviceConfigLock) {
            return mScreenOffBalancedIntervalMillis;
        }
    }

    /**
     * Returns SCREEN_OFF low power scan window in millis.
     */
    public int getScreenOffLowPowerWindowMillis() {
        synchronized (mDeviceConfigLock) {
            return mScreenOffLowPowerWindowMillis;
        }
    }

    /**
     * Returns SCREEN_OFF low power scan interval in millis.
     */
    public int getScreenOffLowPowerIntervalMillis() {
        synchronized (mDeviceConfigLock) {
            return mScreenOffLowPowerIntervalMillis;
        }
    }

    private final DeviceConfigListener mDeviceConfigListener = new DeviceConfigListener();

    private class DeviceConfigListener implements DeviceConfig.OnPropertiesChangedListener {
@@ -5173,6 +5222,14 @@ public class AdapterService extends Service {
                "scan_timeout_millis";
        private static final String SCAN_UPGRADE_DURATION_MILLIS =
                "scan_upgrade_duration_millis";
        private static final String SCREEN_OFF_LOW_POWER_WINDOW_MILLIS =
                "screen_off_low_power_window_millis";
        private static final String SCREEN_OFF_LOW_POWER_INTERVAL_MILLIS =
                "screen_off_low_power_interval_millis";
        private static final String SCREEN_OFF_BALANCED_WINDOW_MILLIS =
                "screen_off_balanced_window_millis";
        private static final String SCREEN_OFF_BALANCED_INTERVAL_MILLIS =
                "screen_off_balanced_interval_millis";

        /**
         * Default denylist which matches Eddystone and iBeacon payloads.
@@ -5211,6 +5268,18 @@ public class AdapterService extends Service {
                        DEFAULT_SCAN_TIMEOUT_MILLIS);
                mScanUpgradeDurationMillis = properties.getInt(SCAN_UPGRADE_DURATION_MILLIS,
                        DEFAULT_SCAN_UPGRADE_DURATION_MILLIS);
                mScreenOffLowPowerWindowMillis = properties.getInt(
                        SCREEN_OFF_LOW_POWER_WINDOW_MILLIS,
                        ScanManager.SCAN_MODE_SCREEN_OFF_LOW_POWER_WINDOW_MS);
                mScreenOffLowPowerIntervalMillis = properties.getInt(
                        SCREEN_OFF_LOW_POWER_INTERVAL_MILLIS,
                        ScanManager.SCAN_MODE_SCREEN_OFF_LOW_POWER_INTERVAL_MS);
                mScreenOffBalancedWindowMillis = properties.getInt(
                        SCREEN_OFF_BALANCED_WINDOW_MILLIS,
                        ScanManager.SCAN_MODE_SCREEN_OFF_BALANCED_WINDOW_MS);
                mScreenOffBalancedIntervalMillis = properties.getInt(
                        SCREEN_OFF_BALANCED_INTERVAL_MILLIS,
                        ScanManager.SCAN_MODE_SCREEN_OFF_BALANCED_INTERVAL_MS);
            }
        }
    }
+36 −21
Original line number Diff line number Diff line
@@ -67,6 +67,20 @@ public class ScanManager {
    private static final boolean DBG = GattServiceConfig.DBG;
    private static final String TAG = GattServiceConfig.TAG_PREFIX + "ScanManager";

    /**
     * Scan params corresponding to regular scan setting
     */
    private static final int SCAN_MODE_LOW_POWER_WINDOW_MS = 140;
    private static final int SCAN_MODE_LOW_POWER_INTERVAL_MS = 1400;
    private static final int SCAN_MODE_BALANCED_WINDOW_MS = 183;
    private static final int SCAN_MODE_BALANCED_INTERVAL_MS = 730;
    private static final int SCAN_MODE_LOW_LATENCY_WINDOW_MS = 100;
    private static final int SCAN_MODE_LOW_LATENCY_INTERVAL_MS = 100;
    public static final int SCAN_MODE_SCREEN_OFF_LOW_POWER_WINDOW_MS = 512;
    public static final int SCAN_MODE_SCREEN_OFF_LOW_POWER_INTERVAL_MS = 10240;
    public static final int SCAN_MODE_SCREEN_OFF_BALANCED_WINDOW_MS = 183;
    public static final int SCAN_MODE_SCREEN_OFF_BALANCED_INTERVAL_MS = 730;

    // Result type defined in bt stack. Need to be accessed by GattService.
    static final int SCAN_RESULT_TYPE_TRUNCATED = 1;
    static final int SCAN_RESULT_TYPE_FULL = 2;
@@ -695,19 +709,6 @@ public class ScanManager {

        private static final int DISCARD_OLDEST_WHEN_BUFFER_FULL = 0;

        /**
         * Scan params corresponding to regular scan setting
         */
        private static final int SCAN_MODE_LOW_POWER_WINDOW_MS = 35;
        private static final int SCAN_MODE_LOW_POWER_INTERVAL_MS = 350;
        private static final int SCAN_MODE_BALANCED_WINDOW_MS = 35;
        private static final int SCAN_MODE_BALANCED_INTERVAL_MS = 175;
        private static final int SCAN_MODE_LOW_LATENCY_WINDOW_MS = 4096;
        private static final int SCAN_MODE_LOW_LATENCY_INTERVAL_MS = 4096;
        private static final int SCAN_MODE_SCREEN_OFF_WINDOW_MS = 512;
        private static final int SCAN_MODE_SCREEN_OFF_INTERVAL_MS = 10240;
        private static final int SCAN_MODE_SCREEN_OFF_BALANCED_WINDOW_MS = 128;
        private static final int SCAN_MODE_SCREEN_OFF_BALANCED_INTERVAL_MS = 640;

        /**
         * Onfound/onlost for scan settings
@@ -964,20 +965,34 @@ public class ScanManager {
        // infrequently anyway. To avoid redefining paramete sets, map to the low duty cycle
        // parameter set as follows.
        private int getBatchScanWindowMillis(int scanMode) {
            ContentResolver resolver = mService.getContentResolver();
            switch (scanMode) {
                case ScanSettings.SCAN_MODE_LOW_LATENCY:
                    return SCAN_MODE_BALANCED_WINDOW_MS;
                    return Settings.Global.getInt(
                        resolver,
                        Settings.Global.BLE_SCAN_BALANCED_WINDOW_MS,
                        SCAN_MODE_BALANCED_WINDOW_MS);
                default:
                    return SCAN_MODE_LOW_POWER_WINDOW_MS;
                    return Settings.Global.getInt(
                        resolver,
                        Settings.Global.BLE_SCAN_LOW_POWER_WINDOW_MS,
                        SCAN_MODE_LOW_POWER_WINDOW_MS);
            }
        }

        private int getBatchScanIntervalMillis(int scanMode) {
            ContentResolver resolver = mService.getContentResolver();
            switch (scanMode) {
                case ScanSettings.SCAN_MODE_LOW_LATENCY:
                    return SCAN_MODE_BALANCED_INTERVAL_MS;
                    return Settings.Global.getInt(
                        resolver,
                        Settings.Global.BLE_SCAN_BALANCED_INTERVAL_MS,
                        SCAN_MODE_BALANCED_INTERVAL_MS);
                default:
                    return SCAN_MODE_LOW_POWER_INTERVAL_MS;
                    return Settings.Global.getInt(
                        resolver,
                        Settings.Global.BLE_SCAN_LOW_POWER_INTERVAL_MS,
                        SCAN_MODE_LOW_POWER_INTERVAL_MS);
            }
        }

@@ -1343,9 +1358,9 @@ public class ScanManager {
                        Settings.Global.BLE_SCAN_LOW_POWER_WINDOW_MS,
                        SCAN_MODE_LOW_POWER_WINDOW_MS);
                case ScanSettings.SCAN_MODE_SCREEN_OFF:
                    return SCAN_MODE_SCREEN_OFF_WINDOW_MS;
                    return mAdapterService.getScreenOffLowPowerWindowMillis();
                case ScanSettings.SCAN_MODE_SCREEN_OFF_BALANCED:
                    return SCAN_MODE_SCREEN_OFF_BALANCED_WINDOW_MS;
                    return mAdapterService.getScreenOffBalancedWindowMillis();
                default:
                    return Settings.Global.getInt(
                        resolver,
@@ -1380,9 +1395,9 @@ public class ScanManager {
                        Settings.Global.BLE_SCAN_LOW_POWER_INTERVAL_MS,
                        SCAN_MODE_LOW_POWER_INTERVAL_MS);
                case ScanSettings.SCAN_MODE_SCREEN_OFF:
                    return SCAN_MODE_SCREEN_OFF_INTERVAL_MS;
                    return mAdapterService.getScreenOffLowPowerIntervalMillis();
                case ScanSettings.SCAN_MODE_SCREEN_OFF_BALANCED:
                    return SCAN_MODE_SCREEN_OFF_BALANCED_INTERVAL_MS;
                    return mAdapterService.getScreenOffBalancedIntervalMillis();
                default:
                    return Settings.Global.getInt(
                        resolver,