打开蓝牙开关,连接一个之前连接过的设备(该设备不在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 }