本文详细的将Android 蓝牙扫描周围设备流程进行了梳理,从UI开始扫描到协议栈发送扫描命令到controller,进行了源码分析。
蓝牙UI开始扫描位于setting的 /packages/apps/Settings/src/com/android/settings/bluetooth/BluetoothPairingDetail.java 中。
BluetoothPairingDetail 是扫描蓝牙设备并配对它们的页面。
void enableScanning() {
120 // Clear all device states before first scan 清楚所有的设备状态第一次扫描时候
121 if (!mInitialScanStarted) {
122 if (mAvailableDevicesCategory != null) {
123 removeAllDevices(); //移除所有的设备
124 }
125 mLocalManager.getCachedDeviceManager().clearNonBondedDevices();
126 mInitialScanStarted = true;
127 }
128 super.enableScanning();//调用父类 DeviceListPreferenceFragment中的函数
129 }
接下来,调用到父类中DeviceListPreferenceFragment的扫描函数:
/