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蓝牙开发(属于低功耗蓝牙设备,设备大多是血糖仪.蓝牙手 ...
随机推荐
- linux修改文件为可执行文件
修改shell为可执行文件 chmod +x test2.sh chmod 751 file 给file的属主分配读.写.执行(7)的权限,给file的所在组分配读.执行(5)的权限,给其他用户分 ...
- SourceTree安装教程和破解教程
SourceTree破解版是一款非常实用的编程工具,这是一款专业的Git和Hg客户端,界面简洁,操作简单易上手,是开发者的必备工具,欢迎大家来绿色资源网下载体验!SourceTree是一款免费的Git ...
- Redis、Memcache、MongoDb的优缺点
Redis.Memcache.MongoDb的优缺点 Redis优点 支持多种数据结构,如 string(字符串). list(双向链表).dict(hash表).set(集合).zset(排序set ...
- 微信小程序-添加手机联系人
仅供参考 1,wxml: <view bindlongtap="phoneNumTap">{{phoneNum}}</view> 2,js: data = ...
- PHP06
PHP06 1. 2.可视化工具navicat: 1)查询 : select 字段名1,字段名2- from 表名; 对于可能与关键词重名的名称,建议使用反引号`括起来 可用*通配符代替字段名 sel ...
- Sqoop找不到主类 Error: Could not find or load main class org.apache.sqoop.Sqoop
最近由于要使用Sqoop来到出数据到hdfs,可是发现Sqoop1.4.5跟hadoop2.X不兼容,需要对Sqoop1.4.5进行编译,编译的具体方法见:http://my.codeweblog.c ...
- idea的debug模式启动运行慢
今天发现idea的debug模式启动运行特别慢,查找原因是因为在多个方法上打了断点导致,关闭断点问题解决. 关闭断点方法为:
- jquery-卡片翻转
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 关于bazel使用笔记
当我们在build一个文件时,需要另外的放置cache时,我们需要: bazel --output_user_root=/path/to/directory build //foo:bar
- MySQL 服务常用操作命令
1.MySQL 服务设置 在使用 mysql.server 命令之前需要将路径 /usr/local/mysql/support-files 添加到系统环境变量中. export PATH=$PATH ...