Android 8 蓝牙 扫描流程
记录android 8 蓝牙扫描设备的流程
src/com/android/settings/bluetooth/BluetoothSettings.java
@Override
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
final Lifecycle lifecycle = getLifecycle();
mDeviceNamePrefController = new BluetoothDeviceNamePreferenceController(context, lifecycle);
mPairingPrefController = new BluetoothPairingPreferenceController(context, this,
(SettingsActivity) getActivity());
controllers.add(mDeviceNamePrefController);
controllers.add(mPairingPrefController);
controllers.add(new BluetoothFilesPreferenceController(context));
controllers.add(new BluetoothDeviceRenamePreferenceController(context, this, lifecycle));
return controllers;
}
src/com/android/settings/bluetooth/BluetoothPairingPreferenceController.java
public boolean handlePreferenceTreeClick(Preference preference) {
if (KEY_PAIRING.equals(preference.getKey())) {
mActivity.startPreferencePanelAsUser(mFragment, BluetoothPairingDetail.class.getName(),
null, R.string.bluetooth_pairing_page_title, null,
new UserHandle(UserHandle.myUserId()));
return true;
}
return false;
}
src/com/android/settings/bluetooth/BluetoothPairingDetail.java
@VisibleForTesting
void updateContent(int bluetoothState) {
switch (bluetoothState) {
case BluetoothAdapter.STATE_ON:
mDevicePreferenceMap.clear();
mLocalAdapter.setBluetoothEnabled(true);
addDeviceCategory(mAvailableDevicesCategory,
R.string.bluetooth_preference_found_devices,
BluetoothDeviceFilter.UNBONDED_DEVICE_FILTER, mInitialScanStarted);
updateFooterPreference(mFooterPreference);
mAlwaysDiscoverable.start();
enableScanning(); // 扫描
break;
case BluetoothAdapter.STATE_OFF:
finish();
break;
}
}
@Override
void enableScanning() {
// Clear all device states before first scan
if (!mInitialScanStarted) {
if (mAvailableDevicesCategory != null) {
removeAllDevices();
}
mLocalManager.getCachedDeviceManager().clearNonBondedDevices();
mInitialScanStarted = true;
}
super.enableScanning();
}
packages/apps/Settings/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
@VisibleForTesting
void enableScanning() {
// LocalBluetoothAdapter already handles repeated scan requests
mLocalAdapter.startScanning(true);
mScanEnabled = true;
}
frameworks\base\packages\SettingsLib\src\com\android\settingslib\bluetooth\LocalBluetoothAdapter.java
public void startScanning(boolean force) {
// Only start if we're not already scanning
if (!mAdapter.isDiscovering()) { // 判断是否正在扫描
if (!force) {
// Don't scan more than frequently than SCAN_EXPIRATION_MS,
// unless forced
if (mLastScan + SCAN_EXPIRATION_MS > System.currentTimeMillis()) {
return;
}
// 放音乐的时候不进行扫描,除非强制
// If we are playing music, don't scan unless forced.
A2dpProfile a2dp = mProfileManager.getA2dpProfile();
if (a2dp != null && a2dp.isA2dpPlaying()) {
return;
}
A2dpSinkProfile a2dpSink = mProfileManager.getA2dpSinkProfile();
if ((a2dpSink != null) && (a2dpSink.isA2dpPlaying())){
return;
}
}
if (mAdapter.startDiscovery()) {
mLastScan = System.currentTimeMillis();
}
}
}
frameworks\base\core\java\android\bluetooth\BluetoothAdapter.java
public boolean startDiscovery() {
android.util.SeempLog.record(58);
if (getState() != STATE_ON) return false;
try {
mServiceLock.readLock().lock();
if (mService != null) return mService.startDiscovery();
} catch (RemoteException e) {
Log.e(TAG, "", e);
} finally {
mServiceLock.readLock().unlock();
}
return false;
}
packages\apps\Bluetooth\src\com\android\bluetooth\btservice\AdapterService.java
private static class AdapterServiceBinder extends IBluetooth.Stub {
public boolean startDiscovery() {
if (!Utils.checkCaller()) {
Log.w(TAG, "startDiscovery() - Not allowed for non-active user");
return false;
}
AdapterService service = getService();
if (service == null) return false;
return service.startDiscovery();
}
boolean startDiscovery() {
debugLog("startDiscovery");
enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
"Need BLUETOOTH ADMIN permission");
//do not allow new connections with active multicast
A2dpService a2dpService = A2dpService.getA2dpService();
if (a2dpService != null &&
a2dpService.isMulticastFeatureEnabled() &&
a2dpService.isMulticastOngoing(null)) {
Log.i(TAG,"A2dp Multicast is Ongoing, ignore discovery");
return false;
}
if (mAdapterProperties.isDiscovering()) {
Log.i(TAG,"discovery already active, ignore startDiscovery");
return false;
}
return startDiscoveryNative();
}
Liu Tao
2019-3-27
Android 8 蓝牙 扫描流程的更多相关文章
- Android 8 蓝牙 A2DP流程
记录一下蓝牙A2DP的流程 packages\apps\Settings\src\com\android\settings\bluetooth\BluetoothPairingDetail.java ...
- 【转】Android bluetooth介绍(三): 蓝牙扫描(scan)设备分析
原文网址:http://blog.csdn.net/xubin341719/article/details/38584469 关键词:蓝牙blueZ A2DP.SINK.sink_connect.s ...
- 【转】Android bluetooth介绍(二): android blueZ蓝牙代码架构及其uart 到rfcomm流程
原文网址:http://blog.sina.com.cn/s/blog_602c72c50102uzoj.html 关键词:蓝牙blueZ UART HCI_UART H4 HCI L2CAP ...
- Android bluetooth介绍(三): 蓝牙扫描(scan)设备分析
关键词:蓝牙blueZ A2DP.SINK.sink_connect.sink_disconnect.sink_suspend.sink_resume.sink_is_connected.sink_ ...
- 深入Android媒体存储服务(二):磁盘扫描流程
简介: 本文是<深入Android媒体存储服务>系列第二篇,简要介绍媒体存储服务扫描文件的流程.文中介绍的是 Android 4.2. Android 有一套媒体存储服务,进程名是 and ...
- android BluetoothAdapter蓝牙BLE扫描总结
1.android 4.3.1(Build.VERSION_CODES.JELLY_BEAN_MR2)增加的startLeScan(callback)方法,官方在5.0之后不建议使用,实测此方法,4. ...
- Android 6.0 Kotlin 蓝牙扫描
package com.arci.myapplication import android.app.Activityimport android.os.Bundleimport android.sup ...
- Android WiFi 扫描流程分析(wpa_supplicant选择网络)
扫描流程 1.如果之前就已经有相关记录,优化扫描,扫描记录部分的频率信道. 2.如果1中的扫描没有结果,清除黑名单中的进行选择. 3.如果2中没有结果,进行所有频率的信道进行扫描 相关log参考: h ...
- Android 开发 蓝牙开发
前言 蓝牙开发其实分2个部分,一个是正常蓝牙功能的开发(比如Android蓝牙的互相连接.读取蓝牙列表.文件传输.蓝牙耳机等等).另外一个是BLE蓝牙开发(属于低功耗蓝牙设备,设备大多是血糖仪.蓝牙手 ...
随机推荐
- Ubuntu环境中的Android源代码下载
跟随“老罗的Android之旅”学习Android系统,首先得学会创建能用于编译Android源代码的环境. 文章参考:http://0xcc0xcd.com/p/books/978-7-121-18 ...
- CC2431 代码分析①-CC2431 喊出第一声
CC2431 是一款可以基于RSSI 定位的 芯片. 定位原理,通过RSSI 强度换算距离. 可以打个类似的比方,一个人站在群山之间,每个山头都有一个地理坐标,然后大喊一声,各个方向会返回回声,通过回 ...
- vue父页面给子页面传递数据
父页面: <template> <div>{{msg}} <Son title='向子文件传递数据' :data='data' :lifemsg ='lifemsg' : ...
- C++知识点:拷贝构造函数例子
//拷贝构造函数: //函数参数传递时调用一次拷贝构造函数,给对象赋值时调用一次拷贝构造函数,对象作为参数传递后会被及时销毁. #include <fstream> #include &l ...
- 2017.08.06【NOIP提高组】模拟赛B组
Summary 今天的比赛60+100+100=260分,没有想到第一题正解是搜索,我与AK差一段距离,这段距离,叫倒着搜.总的来说不是很难. Problem T1 天平 题目大意 给你N个排序好的砝 ...
- windows安装并使用Anaconda
前言 本意是要使用Jupyter(Jupyter官网地址),在Jupyter官网上看到,强烈建议新手使用Anaconda,于是开始下载Anaconda使用.Anaconda是用于管理开源包(packa ...
- PAT Basic 1004
1004 成绩排名 (20 分) 读入 n(>0)名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式: 每个测试输入包含 1 个测试用例,格式为 第 1 行:正整数 ...
- Ubunut操作系统下nDPI的部署及简单使用
[系统:Ubuntu16.04LTS ] [ nDPI版本:2.5.0] [ 内核:4.15.0-39-generic] 前期准备工作--依赖安装 所需依赖包(前两个ubuntu16已有不需安装) g ...
- ARM 技术文档
1. 相关链接 ARM官网: http://infocenter.arm.com/ 比较有用的几个目录: ARM Technical Support Knowledge Articles 一些关于A ...
- Visual Studio 2015编译Lua 5.3.4遇到的坑
被坑的不浅,遇到错误:" LNK1561:必须定义入口点",解决方案删除再建,步骤一遍一遍操作,还是报错.如下图所示: 首先,它必须要改成DLL或者LIB(动态/静态库),如果是应 ...