1. Background
We usually call andriod public interface when calling standard interface through Android to do the ble scan, which is the startScan method in BluetoothLeScanner. You may not pay much attention to the problem of power consumption in short-time scanning, but if the time scanning is long, it must be needed. Pay attention to the impact of power consumption. This article is mainly for this long-time scanning, no, short-term scanning should also pay attention to power consumption
2. Power consumption test
a. Scan without adding filter condition
Directly call as follows:
bleScanner!!.startScan(null, getScanSetting(ScanSettings.SCAN_MODE_LOW_LATENCY), mScanCallback)
View cpu usage:
adb shell top -m 40
It can be seen that the Bluetooth cpu usage rate reaches 46% during scanning, which is very high
b. Test to add Bluetooth name filtering
The test code is as follows:
val scanFilter = ScanFilter.Builder()
.setDeviceName(BLE_NAME)
.build()
val list = ArrayList<ScanFilter>()
list.add(scanFilter)
bleScanner!!.startScan(list, getScanSetting(ScanSettings.SCAN_MODE_LOW_LATENCY), mScanCallback)
View CPU usage:
Bluetooth occupancy at the moment of scanning is only 1.3,
and then look at the occupancy when the scan is stable: the
occupancy is very low at this time.
3. Conclusion
In the actual production and application, if you can define the filtering conditions, you must add ScanFilter during scanning, which can greatly reduce the power