GAP,Timeout问题:打开蓝牙开关,连接一个之前连接过的设备(该设备不在Inquiry的范围内),尝试连接,时间过长。

本文讨论了蓝牙连接过程中出现的超时问题,详细分析了MTK底层FW设计的PageTimeout时间设置过长导致的问题,并提供了具体的修改步骤,包括在AdapterState.java和CachedBluetoothDevice.java文件中注释掉特定行,以优化连接流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

打开蓝牙开关,连接一个之前连接过的设备(该设备不在Inquiry的范围内),尝试连接,时间过长。

操作步骤:
a. 打开蓝牙,连接一个耳机设备
b. 关闭蓝牙,关闭耳机
c. 再打开蓝牙,自动连接耳机(设备已关闭),Timeout时间过长
问题原因:
MTK底层FW设计的PageTimeout时间是18s
8.96s X 2 ,inquiry and page 共存
多个Profile(HFP,A2DP,HID)尝试连接,Timeout时间积累,导致Timeout时间太长。
修改步骤 1

packages/apps/Bluetooth/src/com/android/bluetooth/btservice/AdapterState.java

注释掉168行

147 private abstract class BaseAdapterState extends State {
148 
149    abstract int getStateValue();
150 
151     @Override
152     public void enter() {
153         int currState = getStateValue();
154         infoLog("entered ");
155         mAdapterService.updateAdapterState(mPrevState, currState);
156         mPrevState = currState;
157     }
158 
159     void infoLog(String msg) {
160         if (DBG) {
161         Log.i(TAG, BluetoothAdapter.nameForState(getStateValue()) + " : " + msg);
162     }
163 }
164 
165     void errorLog(String msg) {
166     Log.e(TAG, BluetoothAdapter.nameForState(getStateValue()) + " : " + msg);
167     }
168 	 //mAdapterServiceService.autoConnect( );
169 }

修改步骤 2

frameworks/base/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java

注释掉629行

604 /**
605 * Refreshes the UI when framework alerts us of a UUID change.
606 */
607 void onUuidChanged() {
608    updateProfiles();
609    ParcelUuid[] uuids = mDevice.getUuids();
610 
611    long timeout = MAX_UUID_DELAY_FOR_AUTO_CONNECT;
612    if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.Hogp)) {
613       timeout = MAX_HOGP_DELAY_FOR_AUTO_CONNECT;
614    } else if (BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.HearingAid)) {
615       timeout = MAX_HEARING_AIDS_DELAY_FOR_AUTO_CONNECT;
616    }
617 
618    if (BluetoothUtils.D) {
619       Log.d(TAG, "onUuidChanged: Time since last connect="
620       + (SystemClock.elapsedRealtime() - mConnectAttempted));
621    }
622 
623    /*
624    * If a connect was attempted earlier without any UUID, we will do the connect now.
625    * Otherwise, allow the connect on UUID change.
626    */
627    if (!mProfiles.isEmpty()
628       && ((mConnectAttempted + timeout) > SystemClock.elapsedRealtime())) {
629     //  connectWithoutResettingTimer(false);          //注释掉这行
630    }
631 
632    dispatchAttributesChanged();
633 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值