Android13 安装谷歌GMS导致打开蓝牙失败解决方法

Android13 安装谷歌GMS导致打开蓝牙失败解决方法

文章目录

一、前言

Android13 上安装谷歌GMS相关服务后,无法打开蓝牙,打开蓝牙马上异常导致自动关闭蓝牙。

这个问题国内估计大部分开发者不会遇到,但是如果是面向国外用户需要安装谷歌相关服务可能会遇到。

这个问题在Android13 几个不同芯片供应商方案都有遇到,说明这个问题在Android13 上是个共性问题,Android原生代码的问题。

本文主要记录一下。

二、解决方法

该问题与BLE 蓝牙扫描相关,去除BLE蓝牙扫描操作即可解决。

1、简单的解决方法

复制代码
packages\modules\Bluetooth\system\gd\hci\le_scanning_manager.cc

  void scan(bool start) {
    //add by mychange
    if (true) {
        LOG_WARN("scan return! because have gms!");
        return ;
    }
    if (start) {
      configure_scan();
      start_scan();
    }

这里是直接在 scan 方法里面进行了 return。

去除了这里的扫描代码,并不影响蓝牙的使用,连接蓝牙耳机,蓝牙鼠标键盘和手机是没啥问题的。

2、添加属性和日志解决

复制代码
添加日志打印和属性判断的方法:

+++ b/release/release/packages/modules/Bluetooth/system/gd/hci/le_scanning_manager.cc
@@ -17,6 +17,7 @@
 
 #include <memory>
 #include <unordered_map>
+#include <cutils/properties.h>
 
 #include "hci/acl_manager.h"
 #include "hci/controller.h"
@@ -613,6 +614,15 @@ struct LeScanningManager::impl : public LeAddressManagerCallback {
   }
 
   void scan(bool start) {
+    //add by mydebug ,start
+    char value[PROPERTY_VALUE_MAX];
+    property_get("persist.mydebug.stop_le_scan", value, "");
+    LOG_WARN("scan prop persist.mydebug.stop_le_scan value =  %s", value); 
+    if (strncmp(value, "no", 2)) { //default  ture, setprop no will false.
+        LOG_WARN("scan return! because have gms!");
+        return ;
+    }
+    //add by mydebug , end
     if (start) {

这里添加了属性 persist.mydebug.stop_le_scan,默认没有,如果设置为 no 就是原本的逻辑。

添加后可以进行测试,属性修改为no的情况,无法打开蓝牙,修改为yes或者其他字符串是可以正常打开蓝牙的。

为啥去除BLE蓝牙的扫描就可以,这是同事陈旺追踪到的,具体修改涉及到C代码。

这里只能简单介绍和分析,如果需要深入研究,可以自己追一下Android13的源码。

三、分析

该问题不好分析,这里只提供相关思路。

1、查看异常日志

从日志看没有 AndroidRuntion 关键字日志,说明不存在应用崩溃。

查看 crash 关键字日志,确实可以看到不少日志,其中 "F DEBUG" 就是关键日志,是底层异常的关键日志。

复制代码
11-03 09:20:55.407  9084  9084 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
11-03 09:20:55.407  9084  9084 F DEBUG   : Build fingerprint: 'mydebug/rk3588_t/rk3588_t:13/TQ2A.230305.008.F1/eng.mydebug.20231102.190806:userdebug/release-keys'
11-03 09:20:55.407  9084  9084 F DEBUG   : Revision: '0'
11-03 09:20:55.407  9084  9084 F DEBUG   : ABI: 'arm64'
11-03 09:20:55.407  9084  9084 F DEBUG   : Timestamp: 2023-11-03 09:20:54.995416302+0800
11-03 09:20:55.407  9084  9084 F DEBUG   : Process uptime: 0s
11-03 09:20:55.407  9084  9084 F DEBUG   : Cmdline: com.android.bluetooth
11-03 09:20:55.407  9084  9084 F DEBUG   : pid: 8977, tid: 9027, name: bt_stack_manage  >>> com.android.bluetooth <<<
11-03 09:20:55.407  9084  9084 F DEBUG   : uid: 1002
11-03 09:20:55.407  9084  9084 F DEBUG   : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE)
11-03 09:20:55.407  9084  9084 F DEBUG   : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
11-03 09:20:55.407  9084  9084 F DEBUG   : Abort message: 'assertion 'status_view.GetStatus() == ErrorCode::SUCCESS' failed - Receive set extended scan enable with error code COMMAND_DISALLOWED' //错误关键
11-03 09:20:55.407  9084  9084 F DEBUG   :     x0  0000000000000000  x1  0000000000002343  x2  0000000000000006  x3  00000074f864ceb0
11-03 09:20:55.407  9084  9084 F DEBUG   :     x4  7274736073527364  x5  7274736073527364  x6  7274736073527364  x7  7f7f7f7f7f7f7f7f
11-03 09:20:55.407  9084  9084 F DEBUG   :     x8  00000000000000f0  x9  000000784035aa00  x10 0000000000000001  x11 0000007840398de4
11-03 09:20:55.407  9084  9084 F DEBUG   :     x12 00000074f864bd60  x13 0000000000000087  x14 00000074f864d0f0  x15 00000002829bb542
11-03 09:20:55.407  9084  9084 F DEBUG   :     x16 00000078403fdd58  x17 00000078403dac70  x18 00000074f7704038  x19 0000000000002311
11-03 09:20:55.407  9084  9084 F DEBUG   :     x20 0000000000002343  x21 00000000ffffffff  x22 00000074f864e000  x23 000000750d528468
11-03 09:20:55.407  9084  9084 F DEBUG   :     x24 0000007590216000  x25 0000000000000000  x26 b4000075e5b66e0c  x27 0000000000000001
11-03 09:20:55.407  9084  9084 F DEBUG   :     x28 0000000000000001  x29 00000074f864cf30
11-03 09:20:55.408  9084  9084 F DEBUG   :     lr  000000784038a968  sp  00000074f864ce90  pc  000000784038a994  pst 0000000000001000
11-03 09:20:55.408  9084  9084 F DEBUG   : backtrace:
11-03 09:20:55.408  9084  9084 F DEBUG   :       #00 pc 0000000000051994  /apex/com.android.runtime/lib64/bionic/libc.so (abort+164) (BuildId: 4e07915368c859b1910c68c84a8de75f) //具体的错误堆栈信息
11-03 09:20:55.408  9084  9084 F DEBUG   :       #01 pc 000000000060a300  /apex/com.android.art/lib64/libart.so (art::Runtime::Abort(char const*)+116) (BuildId: 499c2699a3444f5f106778c61af92356)
11-03 09:20:55.408  9084  9084 F DEBUG   :       #02 pc 0000000000016ea8  /system/lib64/libbase.so (android::base::SetAborter(std::__1::function<void (char const*)>&&)::$_3::__invoke(char const*)+80) (BuildId: b77c57f68a484ed93d5a7eda59d83bf9)
11-03 09:20:55.408  9084  9084 F DEBUG   :       #03 pc 0000000000006e10  /system/lib64/liblog.so (__android_log_assert+308) (BuildId: 6d90ed7ade4424925966905508d7e8b2)
11-03 09:20:55.408  9084  9084 F DEBUG   :       #04 pc 000000000095eb54  /apex/com.android.btservices/lib64/libbluetooth_jni.so (bluetooth::hci::LeScanningManager::impl::check_status(bluetooth::hci::CommandCompleteView)+1128) (BuildId: e3a43fbd0d5d775b82f1fcbcaffc6903)
11-03 09:20:55.408  9084  9084 F DEBUG   :       #05 pc 0000000000876eec  /apex/com.android.btservices/lib64/libbluetooth_jni.so (void base::internal::FunctorTraits<void (*)(bluetooth::hci::CommandCompleteView), void>::Invoke<void (*)(bluetooth::hci::CommandCompleteView), bluetooth::hci::CommandCompleteView>(void (*&&)(bluetooth::hci::CommandCompleteView), bluetooth::hci::CommandCompleteView&&)+268) (BuildId: e3a43fbd0d5d775b82f1fcbcaffc6903)
11-03 09:20:55.408  9084  9084 F DEBUG   :       #06 pc 00000000008e8ba4  /apex/com.android.btservices/lib64/libbluetooth_jni.so (void base::internal::FunctorTraits<base::OnceCallback<void (bluetooth::hci::CommandCompleteView)>, void>::Invoke<base::OnceCallback<void (bluetooth::hci::CommandCompleteView)>, bluetooth::hci::CommandCompleteView>(base::OnceCallback<void (bluetooth::hci::CommandCompleteView)>&&, bluetooth::hci::CommandCompleteView&&)+280) (BuildId: e3a43fbd0d5d775b82f1fcbcaffc6903)
11-03 09:20:55.408  9084  9084 F DEBUG   :       #07 pc 00000000009d38c8  /apex/com.android.btservices/lib64/libbluetooth_jni.so (bluetooth::os::Handler::handle_next_event()+236) (BuildId: e3a43fbd0d5d775b82f1fcbcaffc6903)
11-03 09:20:55.408  9084  9084 F DEBUG   :       #08 pc 0000000000a2837c  /apex/com.android.btservices/lib64/libbluetooth_jni.so (bluetooth::os::Reactor::Run()+584) (BuildId: e3a43fbd0d5d775b82f1fcbcaffc6903)
11-03 09:20:55.408  9084  9084 F DEBUG   :       #09 pc 0000000000a29078  /apex/com.android.btservices/lib64/libbluetooth_jni.so (bluetooth::os::Thread::run(bluetooth::os::Thread::Priority)+176) (BuildId: e3a43fbd0d5d775b82f1fcbcaffc6903)
11-03 09:20:55.408  9084  9084 F DEBUG   :       #10 pc 0000000000a29200  /apex/com.android.btservices/lib64/libbluetooth_jni.so (void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void (bluetooth::os::Thread::*)(bluetooth::os::Thread::Priority), bluetooth::os::Thread*, bluetooth::os::Thread::Priority> >(void*)+68) (BuildId: e3a43fbd0d5d775b82f1fcbcaffc6903)
11-03 09:20:55.408  9084  9084 F DEBUG   :       #11 pc 00000000000b63b0  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+208) (BuildId: 4e07915368c859b1910c68c84a8de75f)
11-03 09:20:55.408  9084  9084 F DEBUG   :       #12 pc 00000000000530b8  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 4e07915368c859b1910c68c84a8de75f)

通过日志可以看到具体报错是jni相关,具体到c代码的哪个类和接口,不太会分析,有兴趣的自己可以研究看看。

从上面可以看到 :Receive set extended scan enable with error code ,这个错误打印是在 le_scanning_manager.cc 文件中的。

具体流程怎么追踪到 scan 方法,从代码上未能简单看出!

2、 查看蓝牙相关日志

可以查看:BluetoothManagerService 、droid.bluetooth 、BluetoothBondStateMachine 等关键字

里面都是有蓝牙开关、蓝牙异常关闭或者蓝牙相关服务died/dead 日志。但是确认看不出是 le_scanning_manager 里面的scan方法导致报错。

这种 c 代码的问题,只能深入追踪,这里对 c/c++ 不熟悉,所以不深入介绍了。

四、总结

1、Android13 安装谷歌GMS导致打开蓝牙失败具体原因是BLE蓝牙扫描导致去除BLE蓝牙扫描即可。

2、蓝牙错误分析

查看蓝牙相关日志: BluetoothManagerService 、droid.bluetooth 、BluetoothBondStateMachine

查看 AndroidRuntime、crash 日志

如果是jni或者so相关的,基本错误都是在c/c++ 代码中,有可能需要深入分析追踪。

相关推荐
小蜜蜂嗡嗡1 小时前
Android Studio flutter项目运行、打包时间太长
android·flutter·android studio
aqi001 小时前
FFmpeg开发笔记(七十一)使用国产的QPlayer2实现双播放器观看视频
android·ffmpeg·音视频·流媒体
zhangphil3 小时前
Android理解onTrimMemory中ComponentCallbacks2的内存警戒水位线值
android
你过来啊你3 小时前
Android View的绘制原理详解
android
移动开发者1号6 小时前
使用 Android App Bundle 极致压缩应用体积
android·kotlin
移动开发者1号6 小时前
构建高可用线上性能监控体系:从原理到实战
android·kotlin
ii_best11 小时前
按键精灵支持安卓14、15系统,兼容64位环境开发辅助工具
android
美狐美颜sdk11 小时前
跨平台直播美颜SDK集成实录:Android/iOS如何适配贴纸功能
android·人工智能·ios·架构·音视频·美颜sdk·第三方美颜sdk
恋猫de小郭16 小时前
Meta 宣布加入 Kotlin 基金会,将为 Kotlin 和 Android 生态提供全新支持
android·开发语言·ios·kotlin
aqi0016 小时前
FFmpeg开发笔记(七十七)Android的开源音视频剪辑框架RxFFmpeg
android·ffmpeg·音视频·流媒体