当前位置: 首页 > news >正文

定制网站模板聊城微信推广网站

定制网站模板,聊城微信推广网站,长春做网站公司,外贸网站建设wordpressAndroid14 蓝牙 BluetoothService 启动和相关代码 文章目录 Android14 蓝牙 BluetoothService 启动和相关代码一、前言二、代码分析介绍1、蓝牙 BluetoothService 启动和相关代码#xff08;1#xff09;蓝牙服务相关的有几个类有#xff1a;#xff08;2#xff09;几个蓝…Android14 蓝牙 BluetoothService 启动和相关代码 文章目录 Android14 蓝牙 BluetoothService 启动和相关代码一、前言二、代码分析介绍1、蓝牙 BluetoothService 启动和相关代码1蓝牙服务相关的有几个类有2几个蓝牙类对象的关系 2、几个蓝牙类对象的主要关联代码1SystemServer.java2BluetoothService.kt3BluetoothManagerService.java4BluetoothManager.java5BluetoothAdapter.java6应用获取 BluetoothManager 和 BluetoothAdapter 对象示例 三、其他1、蓝牙配对和断开、连接的代码2、Android 蓝牙相关广播介绍3、Android无线蓝牙开发总结4、Android 蓝牙设备类型判断代码介绍 5、蓝牙开关日志1蓝牙开启2蓝牙关闭日志3开机前蓝牙开启的开机日志4开机前蓝牙关闭的开机日志 祝各位中秋节日快乐。 一、前言 蓝牙开关和使能开发主要用到BluetoothService、BluetoothManagerService、BluetoothManager、BluetoothAdapter 这几个系统相关类。 某个蓝牙的配对、连接、断开 使用的是 BluetoothDevice 对象。 蓝牙开关状态不记忆或者打开异常就可以看看BluetoothManagerService的日志 里面有打开关闭相关过程日志和时间点这个对问题分析有一定的帮助。 本文主要介绍一下 framework 相关的几个类 对于蓝牙应用的开发和分析解决系统上层的需求和简单问题有一定的作用有兴趣的可以收藏看看。 本文的代码和日志是基于Android14 的设备上的。 二、代码分析介绍 1、蓝牙 BluetoothService 启动和相关代码 1蓝牙服务相关的有几个类有 BluetoothService、BluetoothManagerService、BluetoothManager、BluetoothAdapter 估计没几个人熟悉这个关系的这里简单梳理一下。 2几个蓝牙类对象的关系 这里先公布一下简单关系 1、BluetoothService 是上层蓝牙最开始的服务是在SystemServer 拉起系统其他应用的时候拉起的2、BluetoothManagerService 是BluetoothService 创建的时候创建的服务服务对象 具体实现是在 BluetoothManagerService 里面3、BluetoothManager 是暴露的蓝牙Manager但是这个Manager并不是绑定 BluetoothManagerService BluetoothManager 只有简单的几个暴露方法里面就有获取BluetoothAdapter对象的方法 getAdapter()4、BluetoothAdapter 是才是操作蓝牙的主要功能暴露类 BluetoothAdapter的大部分实现都是调用到 BluetoothManagerService 里面的。 蓝牙实现的功能基本都是要System api都是要系统应用正常才能调用到相关实现。 BluetoothManager 和 BluetoothAdapter 都是应用能正常获取到的对象。 所以看Settings那些系统应用都是直接获取和使用的 BluetoothAdapter 进行蓝牙开关设置蓝牙名称获取蓝牙状态等实现。 上面只是对这几个系统中蓝牙的控制类有一定的了解想要更深入的了解还是要看看代码。 2、几个蓝牙类对象的主要关联代码 具体代码关联 1SystemServer.java framework\base\services\java\com\android\server\SystemServer.java /*** Entry point to {code system_server}.*/ public final class SystemServer implements Dumpable {private static final String TAG SystemServer;//蓝牙服务字符串定义private static final String BLUETOOTH_SERVICE_CLASS com.android.server.bluetooth.BluetoothService;//启动其他服务蓝牙手机网络、输入法等系统服务都是这里private void startOtherServices(NonNull TimingsTraceAndSlog t) {t.traceBegin(startOtherServices);//启动蓝牙服务if (mFactoryTestMode FactoryTest.FACTORY_TEST_LOW_LEVEL) {Slog.i(TAG, No Bluetooth Service (factory test));} else if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {Slog.i(TAG, No Bluetooth Service (Bluetooth Hardware Not Present));} else { //底层hal 没问题才启动上层蓝牙服务t.traceBegin(StartBluetoothService);mSystemServiceManager.startServiceFromJar(BLUETOOTH_SERVICE_CLASS,BLUETOOTH_APEX_SERVICE_JAR_PATH);t.traceEnd();}。。。}} SystemServer.java 这个类系统开发的都比较熟悉了可以拉起各种上层服务的类执行相应的初始化 如果是定义的服务类要比较早拉起来可以加入到这里。 2BluetoothService.kt package\modules\Bluetooth\service\src\com\android\server\bluetooth\BluetoothService.kt class BluetoothService(context: Context) : SystemService(context) {private val mBluetoothManagerService BluetoothManagerService(context)private var mInitialized falseprivate fun initialize() {if (!mInitialized) {mBluetoothManagerService.handleOnBootPhase() //初始化mInitialized true}}override fun onStart() {}override fun onBootPhase(phase: Int) {if (phase SystemService.PHASE_SYSTEM_SERVICES_READY) {publishBinderService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE,mBluetoothManagerService)}}override fun onUserStarting(user: TargetUser) {if (!UserManager.isHeadlessSystemUserMode()) {initialize()}} }BluetoothService 怎么使用kotlin写的 这个是Android14 才这样写的Android13 上看了下还是 BluetoothService.java 不过这个没啥影响只有几十行代码没啥打印 理解起来也是比较简单的主要作用就是在系统起来后拉起 BluetoothManagerService。 所以到这里你就明白了BluetoothManagerService 才是重头戏BluetoothService只是一个简单的架子。 3BluetoothManagerService.java package\modules\Bluetooth\service\src\com\android\server\bluetooth\BluetoothManagerService.java public class BluetoothManagerService extends IBluetoothManager.Stub {private static final String TAG BluetoothManagerService;private static final boolean DBG true;BluetoothManagerService(Context context) {//基础设置广播监听等}//初始化public void handleOnBootPhase() {if (DBG) {Log.d(TAG, Bluetooth boot completed);}}//获取蓝牙是否打开public boolean isEnabled() {return getState() BluetoothAdapter.STATE_ON;}//打开蓝牙public boolean enable(AttributionSource attributionSource) throws RemoteException {}//关闭蓝牙persist 表示是否记忆蓝牙状态普通蓝牙关闭都是记忆状态public boolean disable(AttributionSource attributionSource, boolean persist)throws RemoteException {if (persist) {persistBluetoothSetting(BLUETOOTH_OFF);}}。。。 } 其实蓝牙功能使用的就上面几个接口方法还有一些是gatt 低功耗的判断。 看起来实际功能的类也不多主要是控制蓝牙开关的。 4BluetoothManager.java package\modules\Bluetooth\framework\java\android\bluetooth\BluetoothManager.java /*** High level manager used to obtain an instance of an {link BluetoothAdapter}* and to conduct overall Bluetooth Management.* see Context#getSystemService* see BluetoothAdapter#getDefaultAdapter()*/ SystemService(Context.BLUETOOTH_SERVICE) RequiresFeature(PackageManager.FEATURE_BLUETOOTH) public final class BluetoothManager {/*** hide , 1、私有的需要SystemService 方式获取*/public BluetoothManager(Context context) {mAttributionSource (context ! null) ? context.getAttributionSource() :AttributionSource.myAttributionSource();mAdapter BluetoothAdapter.createAdapter(mAttributionSource);}//2、获取BluetoothAdapter进行蓝牙开关控制等功能RequiresNoPermissionpublic BluetoothAdapter getAdapter() {return mAdapter;}//3、获取某个蓝牙对象的连接状态public int getConnectionState(BluetoothDevice device, int profile) {if (DBG) Log.d(TAG, getConnectionState());ListBluetoothDevice connectedDevices getConnectedDevices(profile);for (BluetoothDevice connectedDevice : connectedDevices) {if (device.equals(connectedDevice)) {return BluetoothProfile.STATE_CONNECTED;}}return BluetoothProfile.STATE_DISCONNECTED;}//4、获取已连接的蓝牙列表 系统上没看到有用这个的。public ListBluetoothDevice getConnectedDevices(int profile) {if (DBG) Log.d(TAG, getConnectedDevices);return getDevicesMatchingConnectionStates(profile, new int[] {BluetoothProfile.STATE_CONNECTED});}//5、打开低功耗蓝牙 public BluetoothGattServer openGattServer(Context context,BluetoothGattServerCallback callback) {return (openGattServer(context, callback, BluetoothDevice.TRANSPORT_AUTO));}} 其实没看到有啥大作用的方法只有个 获取BluetoothAdapter对象方法是比较有用的 但是 BluetoothAdapter 是可以直接获取的。 所以 BluetoothManager 在开发场景中是没啥作用的。 类定义的最开头的备注也写了高版本用 BluetoothAdapter 即可。 5BluetoothAdapter.java package\modules\Bluetooth\framework\java\android\bluetooth\BluetoothAdapter.java public final class BluetoothAdapter {private static final String TAG BluetoothAdapter;private static final String DESCRIPTOR android.bluetooth.BluetoothAdapter;private static final boolean DBG true;private static final boolean VDBG false;private final IBluetoothManager mManagerService;private IBluetooth mService;//1、获取 BluetoothAdapter 的暴露的静态方法RequiresNoPermissionpublic static synchronized BluetoothAdapter getDefaultAdapter() {if (sAdapter null) {sAdapter createAdapter(AttributionSource.myAttributionSource());}return sAdapter;}//2、打开蓝牙的暴露方法RequiresLegacyBluetoothAdminPermissionRequiresBluetoothConnectPermissionRequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)public boolean enable() {if (isEnabled()) {if (DBG) {Log.d(TAG, enable(): BT already enabled!);}return true;}try {return mManagerService.enable(mAttributionSource);} catch (RemoteException e) {Log.e(TAG, , e);}return false;}//2、判断蓝牙是否打开的暴露方法public boolean isEnabled() {return getState() BluetoothAdapter.STATE_ON;}//3、设置蓝牙关闭的暴露方法默认记忆状态public boolean disable() {return disable(true);}//4、设置蓝牙关闭的暴露方法参数表示是否记忆true 为记忆public boolean disable(boolean persist) {try {return mManagerService.disable(mAttributionSource, persist);} catch (RemoteException e) {Log.e(TAG, , e);}return false;}//5、获取蓝牙mac地址public String getAddress() {try {return mManagerService.getAddress(mAttributionSource);} catch (RemoteException e) {Log.e(TAG, , e);}return null;}//6、获取当前设备蓝牙名称public String getName() {try {return mManagerService.getName(mAttributionSource);} catch (RemoteException e) {Log.e(TAG, , e);}return null;}下面这些api都是和硬件比较相关的具体实现都是用 IBluetooth//7、设置当前设备蓝牙名称public boolean setName(String name) {if (getState() ! STATE_ON) {return false;}mServiceLock.readLock().lock();mService.setName(name, mAttributionSource, recv);。。。return false;}//8、获取当前设备蓝牙模式是否被其他应用发现和连接的模式public int getScanMode() {if (getState() ! STATE_ON) {return SCAN_MODE_NONE;}mServiceLock.readLock().lock();。。。return SCAN_MODE_NONE;}//9、设置当前设备蓝牙模式//20无21可以连接不可搜索到,23 可被连接可被搜索到public int setScanMode(ScanMode int mode) {if (getState() ! STATE_ON) {return BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED;}。。。return BluetoothStatusCodes.ERROR_UNKNOWN;}//10、开始蓝牙扫描public boolean startDiscovery() {if (getState() ! STATE_ON) {return false;}mServiceLock.readLock().lock();。。。return false;}//11、取消蓝牙扫描public boolean cancelDiscovery() {if (getState() ! STATE_ON) {return false;}mServiceLock.readLock().lock();。。。return false;}//12、判断是否正在进行蓝牙扫描public boolean isDiscovering() {if (getState() ! STATE_ON) {return false;}。。。return false;}//13、获取一次蓝牙被扫描发现的时间对应的是ScanMode为23的情况public Nullable Duration getDiscoverableTimeout() {if (getState() ! STATE_ON) {return null;}。。。return null;}//14、获取一次蓝牙被扫描发现的时间还剩下多少时间public long getDiscoveryEndMillis() {mServiceLock.readLock().lock();。。。return -1;}//15、设置被其他设备发现的时间长度单位秒public int setDiscoverableTimeout(NonNull Duration timeout) {if (getState() ! STATE_ON) {return BluetoothStatusCodes.ERROR_BLUETOOTH_NOT_ENABLED;}。。。return BluetoothStatusCodes.ERROR_UNKNOWN;}//16、获取当前设备保存的蓝牙列表配对过的public SetBluetoothDevice getBondedDevices() {if (getState() ! STATE_ON) {return toDeviceSet(Arrays.asList());}mServiceLock.readLock().lock();。。。return null;}} 看一下上面这里api 方法常用的就是上面的这些方法。 IBluetooth 再往下到 AdapterService 和 AdapterProperties距离底层代码还有一段距离 AdapterService 和 AdapterProperties 的源码位置 package\modules\Bluetooth\android\app\src\com\android\bluetooth\btservice\AdapterService.javapackage\modules\Bluetooth\android\app\src\com\android\bluetooth\btservice\AdapterProperties.java有兴趣的可以自己看看。 6应用获取 BluetoothManager 和 BluetoothAdapter 对象示例 //BluetoothManager 的获取 BluetoothManager bluetoothManager context.getSystemService(BluetoothManager.class);//BluetoothAdapter 的获取 BluetoothAdapter bluetoothAdapter BluetoothAdapter.getDefaultAdapter();看起来还是 BluetoothAdapter 获取比较简单并且实用。 三、其他 上面的代码都是开关和扫描控制相关下面介绍一下断开、连接的代码。 1、蓝牙配对和断开、连接的代码 //蓝牙配对连接 BluetoothDevice.createBond()//蓝牙断开 BluetoothAdapter.disconnectAllEnabledProfiles(BluetoothDevice) //蓝牙忘记 BluetoothDevice.removeBond();这个 BluetoothDevice 怎么得来的 就是通过蓝牙扫描收集起来的或者通过 SettingsLib 库的api或者到当前扫描到的蓝牙列表。 CollectionCachedBluetoothDevice cachedDevices LocalBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy(); LocalBluetoothManager 是 SettingsLib 里面的类里面应该也是有服务一直在监听蓝牙广播收集蓝牙列表。 2、Android 蓝牙相关广播介绍 主要介绍Android 蓝牙相关的广播并非硬件相关的蓝牙广播信号而是蓝牙app中的广播接收器onReceive 的蓝牙相关广播。 最近刚好开发了一下蓝牙相关的功能所以进行一些知识总结和介绍本文应该是全网最面的接收Android广播介绍知识的文章。 Android 蓝牙广播是系统应用或者蓝牙功能应用必备知识。 https://blog.csdn.net/wenzhi20102321/article/details/134956116 3、Android无线蓝牙开发总结 早期写的普通应用端的蓝牙开发 https://blog.csdn.net/wenzhi20102321/article/details/53870789 4、Android 蓝牙设备类型判断代码介绍 Android 蓝牙设备有各种类型比如蓝牙手机蓝牙耳机蓝牙手环蓝牙鼠标键盘蓝牙玩具健康检测设备等等。 有些场景需要具体区分就需要进行判断了。一个是扫描到后图标显示设备类型还是可能是具体处理的区别。 这些设备的类型硬件设备本身其实是有定义的 但是也不排除有些设备定义不正确这些都是要我们开发者进行调试才清楚的。 https://blog.csdn.net/wenzhi20102321/article/details/133777224 5、蓝牙开关日志 通过logcat通过grep “BluetoothManagerService” 可以看到蓝牙相关日志 这个在开关机过程可以看到主要日志判断设备是否进行开蓝牙的开关控制。 下面主要是展示 BluetoothManagerService 的相关日志 1蓝牙开启 130|console:/ # logcat | grep -i BluetoothManagerService 09-14 17:32:17.558 643 741 D BluetoothManagerService: Trying to bind to profile: 21, while Bluetooth was disabled //等待蓝牙打开 09-14 17:32:18.448 643 740 D BluetoothManagerService: enable(com.skg.settings): mBluetooth null mBinding false mState OFF 09-14 17:32:18.449 643 771 D BluetoothManagerService: MESSAGE_ENABLE(0): mBluetooth null 09-14 17:32:18.449 643 771 D BluetoothManagerService: Persisting Bluetooth Setting: 1 09-14 17:32:18.449 643 740 D BluetoothManagerService: enable returning 09-14 17:32:18.450 643 771 D BluetoothManagerService: binding Bluetooth service 09-14 17:32:18.585 643 643 D BluetoothManagerService: BluetoothServiceConnection: com.android.bluetooth.btservice.AdapterService 09-14 17:32:18.585 643 771 D BluetoothManagerService: MESSAGE_BLUETOOTH_SERVICE_CONNECTED: 1 09-14 17:32:18.587 643 771 D BluetoothManagerService: Broadcasting onBluetoothServiceUp() to 7 receivers. 09-14 17:32:18.589 643 771 D BluetoothManagerService: MESSAGE_GET_NAME_AND_ADDRESS 09-14 17:32:18.591 643 771 D BluetoothManagerService: MESSAGE_BLUETOOTH_STATE_CHANGE: OFF BLE_TURNING_ON 09-14 17:32:18.591 643 771 D BluetoothManagerService: Sending BLE State Change: OFF BLE_TURNING_ON 09-14 17:32:20.506 643 643 D BluetoothManagerService: Bluetooth Adapter address changed to 22:22:76:B0:09:00 09-14 17:32:20.506 643 643 D BluetoothManagerService: Stored Bluetoothaddress: 22:22:76:B0:09:00 09-14 17:32:20.507 643 643 D BluetoothManagerService: Bluetooth Adapter name changed to W81B by android 09-14 17:32:20.507 643 643 D BluetoothManagerService: Stored Bluetooth name: W81B 09-14 17:32:20.508 643 643 D BluetoothManagerService: Bluetooth Adapter address changed to 22:22:76:B0:09:00 09-14 17:32:20.509 643 643 D BluetoothManagerService: Stored Bluetoothaddress: 22:22:76:B0:09:00 09-14 17:32:20.509 643 771 D BluetoothManagerService: MESSAGE_BLUETOOTH_STATE_CHANGE: BLE_TURNING_ON BLE_ON 09-14 17:32:20.509 643 771 D BluetoothManagerService: Bluetooth is in LE only mode 09-14 17:32:20.509 643 771 D BluetoothManagerService: Binding Bluetooth GATT service 09-14 17:32:20.510 643 771 D BluetoothManagerService: Sending BLE State Change: BLE_TURNING_ON BLE_ON 09-14 17:32:20.511 643 643 D BluetoothManagerService: BluetoothServiceConnection: com.android.bluetooth.gatt.GattService 09-14 17:32:20.511 643 771 D BluetoothManagerService: MESSAGE_BLUETOOTH_SERVICE_CONNECTED: 2 09-14 17:32:20.511 643 771 D BluetoothManagerService: continueFromBleOnState() 09-14 17:32:20.513 643 771 D BluetoothManagerService: Persisting Bluetooth Setting: 1 //设置了蓝牙的settings属性 bluetooth_on 为 1 09-14 17:32:20.513 643 771 D BluetoothManagerService: MESSAGE_BLUETOOTH_STATE_CHANGE: BLE_ON TURNING_ON 09-14 17:32:20.513 643 771 D BluetoothManagerService: Sending BLE State Change: BLE_ON TURNING_ON 09-14 17:32:20.514 643 771 D BluetoothManagerService: Sending State Change: OFF TURNING_ON 09-14 17:32:20.665 643 771 D BluetoothManagerService: MESSAGE_BLUETOOTH_STATE_CHANGE: TURNING_ON ON 09-14 17:32:20.665 643 771 D BluetoothManagerService: Broadcasting onBluetoothStateChange(true) to 20 receivers. 09-14 17:32:20.671 643 771 D BluetoothManagerService: Sending State Change: TURNING_ON ON 09-14 17:32:20.705 643 643 D BluetoothManagerService: Bluetooth Adapter name changed to IWB by android 09-14 17:32:20.705 643 643 D BluetoothManagerService: Stored Bluetooth name: IWB//查看蓝牙开启状态为1开启 130|console:/ # settings get global bluetooth_on 1 console:/ # 手动打开蓝牙就会有上面的 BluetoothManagerService 相关日志 2蓝牙关闭日志 09-14 17:32:28.422 643 1125 D BluetoothManagerService: disable(): mBluetooth android.bluetooth.IBluetooth$Stub$Proxyd9debac mBinding false 09-14 17:32:28.422 643 1125 D BluetoothManagerService: Persisting Bluetooth Setting: 0 //设置了蓝牙的settings属性 bluetooth_on 为 0 09-14 17:32:28.423 643 771 D BluetoothManagerService: MESSAGE_DISABLE: mBluetooth android.bluetooth.IBluetooth$Stub$Proxyd9debac, mBinding false 09-14 17:32:28.724 643 771 D BluetoothManagerService: MESSAGE_HANDLE_DISABLE_DELAYED: disabling:false 09-14 17:32:28.724 643 771 D BluetoothManagerService: Sending off request. 09-14 17:32:28.727 643 771 D BluetoothManagerService: MESSAGE_BLUETOOTH_STATE_CHANGE: ON TURNING_OFF 09-14 17:32:28.727 643 771 D BluetoothManagerService: Sending BLE State Change: ON TURNING_OFF 09-14 17:32:28.727 643 771 D BluetoothManagerService: Sending State Change: ON TURNING_OFF 09-14 17:32:28.775 643 771 D BluetoothManagerService: MESSAGE_BLUETOOTH_STATE_CHANGE: TURNING_OFF BLE_ON 09-14 17:32:28.775 643 771 D BluetoothManagerService: Intermediate off, back to LE only mode 09-14 17:32:28.775 643 771 D BluetoothManagerService: Sending BLE State Change: TURNING_OFF BLE_ON 09-14 17:32:28.775 643 771 D BluetoothManagerService: Broadcasting onBluetoothStateChange(false) to 36 receivers. 09-14 17:32:28.776 643 771 D BluetoothManagerService: Calling sendBrEdrDownCallback callbacks 09-14 17:32:28.776 643 771 D BluetoothManagerService: isBleAppPresent() count: 0 09-14 17:32:28.778 643 771 D BluetoothManagerService: Sending State Change: TURNING_OFF OFF 09-14 17:32:28.779 643 771 D BluetoothManagerService: MESSAGE_BLUETOOTH_STATE_CHANGE: BLE_ON BLE_TURNING_OFF 09-14 17:32:28.779 643 771 D BluetoothManagerService: Sending BLE State Change: BLE_ON BLE_TURNING_OFF 09-14 17:32:29.026 643 771 D BluetoothManagerService: MESSAGE_HANDLE_DISABLE_DELAYED: disabling:true 09-14 17:32:29.026 643 771 D BluetoothManagerService: Handle disable is finished 09-14 17:32:29.060 643 771 D BluetoothManagerService: MESSAGE_BLUETOOTH_STATE_CHANGE: BLE_TURNING_OFF OFF 09-14 17:32:29.060 643 771 D BluetoothManagerService: Bluetooth is complete send Service Down 09-14 17:32:29.060 643 771 D BluetoothManagerService: Broadcasting onBluetoothServiceDown() to 7 receivers. 09-14 17:32:29.061 643 771 D BluetoothManagerService: unbindAndFinish(): android.bluetooth.IBluetooth$Stub$Proxyd9debac mBinding false mUnbinding false 09-14 17:32:29.065 643 771 D BluetoothManagerService: Sending BLE State Change: BLE_TURNING_OFF OFF//查看蓝牙开启状态为0关闭 130|console:/ # settings get global bluetooth_on 0 console:/ # 上面是手动关闭蓝牙的日志。 3开机前蓝牙开启的开机日志 console:/ # logcat | grep BluetoothManagerService 09-11 17:52:32.516 810 1200 D BluetoothManagerService: Trying to bind to profile: 21, while Bluetooth was disabled 09-11 17:52:32.620 810 810 D BluetoothManagerService: Trying to bind to profile: 1, while Bluetooth was disabled ... 09-11 17:52:32.943 810 810 V BluetoothManagerService: Checking activity com.android.bluetooth.opp.BluetoothOppLauncherActivity 09-11 17:52:33.033 810 827 D BluetoothManagerService: Trying to bind to profile: 1, while Bluetooth was disabled 09-11 17:52:33.879 810 844 D BluetoothManagerService: User UserHandle{0} unlocked 09-11 17:52:33.879 810 939 D BluetoothManagerService: MESSAGE_USER_UNLOCKED 09-11 17:52:34.947 810 810 D BluetoothManagerService: Bluetooth Adapter name changed to tt by android //蓝牙名称 09-11 17:52:34.947 810 810 D BluetoothManagerService: Stored Bluetooth name: tt 09-11 17:52:34.965 810 810 D BluetoothManagerService: BluetoothServiceConnection: com.android.bluetooth.btservice.AdapterService 09-11 17:52:34.965 810 939 D BluetoothManagerService: MESSAGE_BLUETOOTH_SERVICE_CONNECTED: 1 09-11 17:52:34.973 810 939 D BluetoothManagerService: Broadcasting onBluetoothServiceUp() to 8 receivers. 09-11 17:52:34.977 810 939 D BluetoothManagerService: MESSAGE_BLUETOOTH_STATE_CHANGE: OFF BLE_TURNING_ON 09-11 17:52:34.977 810 939 D BluetoothManagerService: Sending BLE State Change: OFF BLE_TURNING_ON 09-11 17:52:34.977 810 939 W BroadcastLoopers: Found previously unknown looper Thread[BluetoothManagerService,5,main] 09-11 17:52:35.018 810 810 D BluetoothManagerService: Bluetooth Adapter address changed to 22:22:4B:FA:0C:00 09-11 17:52:35.019 810 810 D BluetoothManagerService: Stored Bluetoothaddress: 22:22:4B:FA:0C:00 09-11 17:52:35.023 810 810 D BluetoothManagerService: Bluetooth Adapter name changed to tt by android 09-11 17:52:35.023 810 810 D BluetoothManagerService: Stored Bluetooth name: tt 09-11 17:52:35.033 810 939 D BluetoothManagerService: MESSAGE_BLUETOOTH_STATE_CHANGE: BLE_TURNING_ON BLE_ON 09-11 17:52:35.033 810 939 D BluetoothManagerService: Bluetooth is in LE only mode 09-11 17:52:35.033 810 939 D BluetoothManagerService: Binding Bluetooth GATT service 09-11 17:52:35.035 810 939 D BluetoothManagerService: Sending BLE State Change: BLE_TURNING_ON BLE_ON 09-11 17:52:35.036 810 810 D BluetoothManagerService: BluetoothServiceConnection: com.android.bluetooth.gatt.GattService 09-11 17:52:35.036 810 939 D BluetoothManagerService: MESSAGE_BLUETOOTH_SERVICE_CONNECTED: 2 09-11 17:52:35.041 810 939 D BluetoothManagerService: continueFromBleOnState() 09-11 17:52:35.042 810 939 D BluetoothManagerService: Persisting Bluetooth Setting: 1 09-11 17:52:35.043 810 939 D BluetoothManagerService: MESSAGE_BLUETOOTH_STATE_CHANGE: BLE_ON TURNING_ON 09-11 17:52:35.043 810 939 D BluetoothManagerService: Sending BLE State Change: BLE_ON TURNING_ON 09-11 17:52:35.044 810 939 D BluetoothManagerService: Sending State Change: OFF TURNING_ON 09-11 17:52:35.163 810 939 D BluetoothManagerService: MESSAGE_BLUETOOTH_STATE_CHANGE: TURNING_ON ON 09-11 17:52:35.163 810 939 D BluetoothManagerService: Broadcasting onBluetoothStateChange(true) to 17 receivers. 09-11 17:52:35.163 810 939 D BluetoothManagerService: Creating new ProfileServiceConnections object for profile: 1 ... 09-11 17:52:35.175 810 939 D BluetoothManagerService: Sending BLE State Change: TURNING_ON ON 09-11 17:52:35.176 810 939 D BluetoothManagerService: Sending State Change: TURNING_ON ON 这个是开机后打印的日志可以看到有蓝牙从关闭到开启的状态过程打印。 还有蓝牙名称打印。 4开机前蓝牙关闭的开机日志 console:/ # logcat | grep BluetoothManagerService 09-11 17:52:32.098 811 1015 D BluetoothManagerService: Trying to bind to profile: 1, while Bluetooth was disabled 09-11 17:52:32.102 811 1015 D BluetoothManagerService: Trying to bind to profile: 2, while Bluetooth was disabled 09-11 17:52:32.104 811 1015 D BluetoothManagerService: Trying to bind to profile: 11, while Bluetooth was disabled 09-11 17:52:32.107 811 1015 D BluetoothManagerService: Trying to bind to profile: 21, while Bluetooth was disabled 09-11 17:52:32.111 811 1015 D BluetoothManagerService: Trying to bind to profile: 22, while Bluetooth was disabled 09-11 17:52:32.116 811 1015 D BluetoothManagerService: Trying to bind to profile: 26, while Bluetooth was disabled 09-11 17:52:32.294 811 811 D BluetoothManagerService: Bluetooth boot completed 09-11 17:52:32.295 811 811 D BluetoothManagerService: Trying to bind to profile: 2, while Bluetooth was disabled ... 09-11 17:52:32.871 811 811 V BluetoothManagerService: Searching package com.android.bluetooth 09-11 17:52:32.872 811 811 V BluetoothManagerService: Checking activity com.android.bluetooth.BluetoothPrefs 09-11 17:52:32.872 811 811 V BluetoothManagerService: Checking activity com.android.bluetooth.map.BluetoothMapSettings 09-11 17:52:32.872 811 811 V BluetoothManagerService: Checking activity com.android.bluetooth.opp.BluetoothOppLauncherActivity 09-11 17:52:32.934 811 828 D BluetoothManagerService: Trying to bind to profile: 1, while Bluetooth was disabled 09-11 21:12:06.753 811 846 D BluetoothManagerService: User UserHandle{0} unlocked 09-11 21:12:06.754 811 943 D BluetoothManagerService: MESSAGE_USER_UNLOCKED 蓝牙关闭的情况 从上面代码是看不到蓝牙打开的过程的 但是也有一些蓝牙准备的过程蓝牙一些服务绑定需要等待底层初始化OK才能正常绑定。 上面的日志比较多可能不一定全部有用 只需要知道蓝牙开关过程中 BluetoothManagerService 都会有一些打印就可以了。 祝各位中秋节日快乐。
http://www.w-s-a.com/news/685501/

相关文章:

  • 网络公司如何建网站网站的建设需要多少钱
  • 代刷网站推广快速泉州网页定制
  • 网站优秀网站地址做宣传册的公司
  • 苏州高端网站建设咨询wordpress云图插件
  • 河北省建设厅网站重新安装优秀中文网页设计
  • 如何在腾讯云做网站开源站群cms
  • 公司网站建设的意义网易做网站
  • 网络营销案例分析与实践搜外seo
  • 手机建网站挣钱吗wordpress面包屑
  • 淘客做网站怎么备案网站开发工具的是什么
  • 提供大良网站建设郑州网站建设网站开发
  • 邢台做wap网站价格wordpress评论滑动
  • 绝味鸭脖网站建设规划书江苏建设人才网 官网
  • 网站源码授权破解centos wordpress 整站
  • 建设一个私人视频网站wordpress js
  • 手机企业网站制作流程3d建模自学
  • 网站优化方案和实施wordpress的归档
  • 建设事业单位网站多少钱集艾设计公司官网
  • 网站建设与管理方案书图片的制作方法
  • 中文建网站美发网站模板带手机版
  • 免费聊天不充值软件windows优化大师下载安装
  • 网站优化的关键词自己怎么做外贸网站空间
  • 现在建设的网站有什么劣势温州互联网公司
  • 重庆自助企业建站模板淘宝关键词top排行榜
  • 平邑网站制作买高端品牌网站
  • 深圳建网站三千网站安全代维
  • 西宁市精神文明建设网站装饰设计甲级资质
  • 做教育行业营销类型的网站徐州做网站多少钱
  • 临沂品牌网站制作企业网站建设搜集资料
  • wordpress注册验证码手机网站优化