Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +17 −0 Original line number Diff line number Diff line Loading @@ -4012,6 +4012,9 @@ public class AdapterService extends Service { private long mScanQuotaWindowMillis = DeviceConfigListener.DEFAULT_SCAN_QUOTA_WINDOW_MILLIS; @GuardedBy("mDeviceConfigLock") private long mScanTimeoutMillis = DeviceConfigListener.DEFAULT_SCAN_TIMEOUT_MILLIS; @GuardedBy("mDeviceConfigLock") private int mScanUpgradeDurationMillis = DeviceConfigListener.DEFAULT_SCAN_UPGRADE_DURATION_MILLIS; public @NonNull Predicate<String> getLocationDenylistName() { synchronized (mDeviceConfigLock) { Loading Loading @@ -4049,6 +4052,15 @@ public class AdapterService extends Service { } } /** * Returns scan upgrade duration in millis. */ public long getScanUpgradeDurationMillis() { synchronized (mDeviceConfigLock) { return mScanUpgradeDurationMillis; } } private final DeviceConfigListener mDeviceConfigListener = new DeviceConfigListener(); private class DeviceConfigListener implements DeviceConfig.OnPropertiesChangedListener { Loading @@ -4064,6 +4076,8 @@ public class AdapterService extends Service { "scan_quota_window_millis"; private static final String SCAN_TIMEOUT_MILLIS = "scan_timeout_millis"; private static final String SCAN_UPGRADE_DURATION_MILLIS = "scan_upgrade_duration_millis"; /** * Default denylist which matches Eddystone and iBeacon payloads. Loading @@ -4074,6 +4088,7 @@ public class AdapterService extends Service { private static final int DEFAULT_SCAN_QUOTA_COUNT = 5; private static final long DEFAULT_SCAN_QUOTA_WINDOW_MILLIS = 30 * SECOND_IN_MILLIS; private static final long DEFAULT_SCAN_TIMEOUT_MILLIS = 30 * MINUTE_IN_MILLIS; private static final int DEFAULT_SCAN_UPGRADE_DURATION_MILLIS = (int) SECOND_IN_MILLIS * 6; public void start() { DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_BLUETOOTH, Loading @@ -4099,6 +4114,8 @@ public class AdapterService extends Service { DEFAULT_SCAN_QUOTA_WINDOW_MILLIS); mScanTimeoutMillis = properties.getLong(SCAN_TIMEOUT_MILLIS, DEFAULT_SCAN_TIMEOUT_MILLIS); mScanUpgradeDurationMillis = properties.getInt(SCAN_UPGRADE_DURATION_MILLIS, DEFAULT_SCAN_UPGRADE_DURATION_MILLIS); } } } Loading android/app/src/com/android/bluetooth/gatt/AppScanStats.java +16 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,8 @@ import java.util.Objects; static final int BALANCED_WEIGHT = 25; static final int LOW_LATENCY_WEIGHT = 100; static final int LARGE_SCAN_TIME_GAP_MS = 24000; // ContextMap here is needed to grab Apps and Connections ContextMap mContextMap; Loading Loading @@ -119,6 +121,11 @@ import java.util.Objects; return AdapterService.getAdapterService().getScanTimeoutMillis(); } // Scan mode upgrade duration after scanStart() static long getScanUpgradeDurationMillis() { return AdapterService.getAdapterService().getScanUpgradeDurationMillis(); } public String appName; public WorkSource mWorkSource; // Used for BatteryStatsManager public final WorkSourceUtil mWorkSourceUtil; // Used for BluetoothStatsLog Loading Loading @@ -363,6 +370,15 @@ import java.util.Objects; return (SystemClock.elapsedRealtime() - mScanStartTime) > getScanTimeoutMillis(); } synchronized boolean hasRecentScan() { if (!isScanning() || mLastScans.isEmpty()) { return false; } LastScan lastScan = mLastScans.get(mLastScans.size() - 1); return ((SystemClock.elapsedRealtime() - lastScan.duration - lastScan.timestamp) < LARGE_SCAN_TIME_GAP_MS); } // This function truncates the app name for privacy reasons. Apps with // four part package names or more get truncated to three parts, and apps // with three part package names names get truncated to two. Apps with two Loading android/app/src/com/android/bluetooth/gatt/ScanClient.java +36 −2 Original line number Diff line number Diff line Loading @@ -32,7 +32,8 @@ import java.util.Objects; /* package */class ScanClient { public int scannerId; public ScanSettings settings; public ScanSettings passiveSettings; public int scanModeApp; public boolean started = false; public int appUid; public List<ScanFilter> filters; // App associated with the scan client died. Loading @@ -59,7 +60,7 @@ import java.util.Objects; ScanClient(int scannerId, ScanSettings settings, List<ScanFilter> filters) { this.scannerId = scannerId; this.settings = settings; this.passiveSettings = null; this.scanModeApp = settings.getScanMode(); this.filters = filters; this.appUid = Binder.getCallingUid(); } Loading @@ -80,4 +81,37 @@ import java.util.Objects; public int hashCode() { return Objects.hash(scannerId); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(" [ScanClient") .append(" scanModeApp ").append(scanModeApp) .append(" scanModeUsed ").append(settings.getScanMode()); if (stats != null && stats.appName != null) { sb.append(" [appScanStats ").append(stats.appName).append("]"); } sb.append("]"); return sb.toString(); } /** * Update scan settings with the new scan mode. * @param newScanMode * @return true if scan settings are updated, false otherwise. */ public boolean updateScanMode(int newScanMode) { if (settings.getScanMode() == newScanMode) { return false; } ScanSettings.Builder builder = new ScanSettings.Builder(); settings = builder.setScanMode(newScanMode) .setCallbackType(settings.getCallbackType()) .setScanResultType(settings.getScanResultType()) .setReportDelay(settings.getReportDelayMillis()) .setNumOfMatches(settings.getNumOfMatches()) .build(); return true; } } android/app/src/com/android/bluetooth/gatt/ScanManager.java +261 −84 File changed.Preview size limit exceeded, changes collapsed. Show changes framework/java/android/bluetooth/le/ScanSettings.java +19 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,23 @@ public final class ScanSettings implements Parcelable { @SystemApi public static final int SCAN_MODE_AMBIENT_DISCOVERY = 3; /** * Default Bluetooth LE scan mode when the screen is off. * This mode has the low duty cycle and long scan interval which results in the lowest * power consumption among all modes. It is for the framework internal use only. * * @hide */ public static final int SCAN_MODE_SCREEN_OFF = 4; /** * Balanced Bluetooth LE scan mode for foreground service when the screen is off. * It is for the framework internal use only. * * @hide */ public static final int SCAN_MODE_SCREEN_OFF_BALANCED = 5; /** * Trigger a callback for every Bluetooth advertisement found that matches the filter criteria. * If no filter is active, all advertisement packets are reported. Loading Loading @@ -292,6 +309,8 @@ public final class ScanSettings implements Parcelable { case SCAN_MODE_BALANCED: case SCAN_MODE_LOW_LATENCY: case SCAN_MODE_AMBIENT_DISCOVERY: case SCAN_MODE_SCREEN_OFF: case SCAN_MODE_SCREEN_OFF_BALANCED: mScanMode = scanMode; break; default: Loading Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +17 −0 Original line number Diff line number Diff line Loading @@ -4012,6 +4012,9 @@ public class AdapterService extends Service { private long mScanQuotaWindowMillis = DeviceConfigListener.DEFAULT_SCAN_QUOTA_WINDOW_MILLIS; @GuardedBy("mDeviceConfigLock") private long mScanTimeoutMillis = DeviceConfigListener.DEFAULT_SCAN_TIMEOUT_MILLIS; @GuardedBy("mDeviceConfigLock") private int mScanUpgradeDurationMillis = DeviceConfigListener.DEFAULT_SCAN_UPGRADE_DURATION_MILLIS; public @NonNull Predicate<String> getLocationDenylistName() { synchronized (mDeviceConfigLock) { Loading Loading @@ -4049,6 +4052,15 @@ public class AdapterService extends Service { } } /** * Returns scan upgrade duration in millis. */ public long getScanUpgradeDurationMillis() { synchronized (mDeviceConfigLock) { return mScanUpgradeDurationMillis; } } private final DeviceConfigListener mDeviceConfigListener = new DeviceConfigListener(); private class DeviceConfigListener implements DeviceConfig.OnPropertiesChangedListener { Loading @@ -4064,6 +4076,8 @@ public class AdapterService extends Service { "scan_quota_window_millis"; private static final String SCAN_TIMEOUT_MILLIS = "scan_timeout_millis"; private static final String SCAN_UPGRADE_DURATION_MILLIS = "scan_upgrade_duration_millis"; /** * Default denylist which matches Eddystone and iBeacon payloads. Loading @@ -4074,6 +4088,7 @@ public class AdapterService extends Service { private static final int DEFAULT_SCAN_QUOTA_COUNT = 5; private static final long DEFAULT_SCAN_QUOTA_WINDOW_MILLIS = 30 * SECOND_IN_MILLIS; private static final long DEFAULT_SCAN_TIMEOUT_MILLIS = 30 * MINUTE_IN_MILLIS; private static final int DEFAULT_SCAN_UPGRADE_DURATION_MILLIS = (int) SECOND_IN_MILLIS * 6; public void start() { DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_BLUETOOTH, Loading @@ -4099,6 +4114,8 @@ public class AdapterService extends Service { DEFAULT_SCAN_QUOTA_WINDOW_MILLIS); mScanTimeoutMillis = properties.getLong(SCAN_TIMEOUT_MILLIS, DEFAULT_SCAN_TIMEOUT_MILLIS); mScanUpgradeDurationMillis = properties.getInt(SCAN_UPGRADE_DURATION_MILLIS, DEFAULT_SCAN_UPGRADE_DURATION_MILLIS); } } } Loading
android/app/src/com/android/bluetooth/gatt/AppScanStats.java +16 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,8 @@ import java.util.Objects; static final int BALANCED_WEIGHT = 25; static final int LOW_LATENCY_WEIGHT = 100; static final int LARGE_SCAN_TIME_GAP_MS = 24000; // ContextMap here is needed to grab Apps and Connections ContextMap mContextMap; Loading Loading @@ -119,6 +121,11 @@ import java.util.Objects; return AdapterService.getAdapterService().getScanTimeoutMillis(); } // Scan mode upgrade duration after scanStart() static long getScanUpgradeDurationMillis() { return AdapterService.getAdapterService().getScanUpgradeDurationMillis(); } public String appName; public WorkSource mWorkSource; // Used for BatteryStatsManager public final WorkSourceUtil mWorkSourceUtil; // Used for BluetoothStatsLog Loading Loading @@ -363,6 +370,15 @@ import java.util.Objects; return (SystemClock.elapsedRealtime() - mScanStartTime) > getScanTimeoutMillis(); } synchronized boolean hasRecentScan() { if (!isScanning() || mLastScans.isEmpty()) { return false; } LastScan lastScan = mLastScans.get(mLastScans.size() - 1); return ((SystemClock.elapsedRealtime() - lastScan.duration - lastScan.timestamp) < LARGE_SCAN_TIME_GAP_MS); } // This function truncates the app name for privacy reasons. Apps with // four part package names or more get truncated to three parts, and apps // with three part package names names get truncated to two. Apps with two Loading
android/app/src/com/android/bluetooth/gatt/ScanClient.java +36 −2 Original line number Diff line number Diff line Loading @@ -32,7 +32,8 @@ import java.util.Objects; /* package */class ScanClient { public int scannerId; public ScanSettings settings; public ScanSettings passiveSettings; public int scanModeApp; public boolean started = false; public int appUid; public List<ScanFilter> filters; // App associated with the scan client died. Loading @@ -59,7 +60,7 @@ import java.util.Objects; ScanClient(int scannerId, ScanSettings settings, List<ScanFilter> filters) { this.scannerId = scannerId; this.settings = settings; this.passiveSettings = null; this.scanModeApp = settings.getScanMode(); this.filters = filters; this.appUid = Binder.getCallingUid(); } Loading @@ -80,4 +81,37 @@ import java.util.Objects; public int hashCode() { return Objects.hash(scannerId); } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(" [ScanClient") .append(" scanModeApp ").append(scanModeApp) .append(" scanModeUsed ").append(settings.getScanMode()); if (stats != null && stats.appName != null) { sb.append(" [appScanStats ").append(stats.appName).append("]"); } sb.append("]"); return sb.toString(); } /** * Update scan settings with the new scan mode. * @param newScanMode * @return true if scan settings are updated, false otherwise. */ public boolean updateScanMode(int newScanMode) { if (settings.getScanMode() == newScanMode) { return false; } ScanSettings.Builder builder = new ScanSettings.Builder(); settings = builder.setScanMode(newScanMode) .setCallbackType(settings.getCallbackType()) .setScanResultType(settings.getScanResultType()) .setReportDelay(settings.getReportDelayMillis()) .setNumOfMatches(settings.getNumOfMatches()) .build(); return true; } }
android/app/src/com/android/bluetooth/gatt/ScanManager.java +261 −84 File changed.Preview size limit exceeded, changes collapsed. Show changes
framework/java/android/bluetooth/le/ScanSettings.java +19 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,23 @@ public final class ScanSettings implements Parcelable { @SystemApi public static final int SCAN_MODE_AMBIENT_DISCOVERY = 3; /** * Default Bluetooth LE scan mode when the screen is off. * This mode has the low duty cycle and long scan interval which results in the lowest * power consumption among all modes. It is for the framework internal use only. * * @hide */ public static final int SCAN_MODE_SCREEN_OFF = 4; /** * Balanced Bluetooth LE scan mode for foreground service when the screen is off. * It is for the framework internal use only. * * @hide */ public static final int SCAN_MODE_SCREEN_OFF_BALANCED = 5; /** * Trigger a callback for every Bluetooth advertisement found that matches the filter criteria. * If no filter is active, all advertisement packets are reported. Loading Loading @@ -292,6 +309,8 @@ public final class ScanSettings implements Parcelable { case SCAN_MODE_BALANCED: case SCAN_MODE_LOW_LATENCY: case SCAN_MODE_AMBIENT_DISCOVERY: case SCAN_MODE_SCREEN_OFF: case SCAN_MODE_SCREEN_OFF_BALANCED: mScanMode = scanMode; break; default: Loading