RK3562 安卓14 优化 Settings 蓝牙搜索报错的问题(只能搜索50个设备)

diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePairingDetailBase.java b/src/com/android/settings/bluetooth/BluetoothDevicePairingDetailBase.java
index 7ee61ee249..db5af0f02c 100644
--- a/src/com/android/settings/bluetooth/BluetoothDevicePairingDetailBase.java
+++ b/src/com/android/settings/bluetooth/BluetoothDevicePairingDetailBase.java
@@ -35,6 +35,9 @@ import com.android.settings.accessibility.AccessibilityStatsLogUtils;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
 import com.android.settingslib.bluetooth.HearingAidStatsLogUtils;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
 
 /**
  * Abstract class for providing basic interaction for a list of Bluetooth devices in bluetooth
@@ -60,6 +63,22 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
         mInitialScanStarted = false;
         super.onViewCreated(view, savedInstanceState);
     }
+	
+	private static final int MSG_BLUETOOT_UPDATE =99;
+    private BluetoothHandler mHander =new BluetoothHandler(Looper.getMainLooper());
+    private class BluetoothHandler extends Handler{
+        BluetoothHandler(Looper looper){
+            super(looper);
+        }
+        @Override
+        public void handleMessage(@NonNull Message msg) {
+            switch (msg.what){
+                case MSG_BLUETOOT_UPDATE:
+                    updateBluetooth();
+                    break;
+            }
+        }
+    }
 
     @Override
     public void onStart() {
@@ -68,7 +87,8 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
             Log.e(getLogTag(), "Bluetooth is not supported on this device");
             return;
         }
-        updateBluetooth();
+	mHander.sendEmptyMessageDelayed(MSG_BLUETOOT_UPDATE,1500);
+        //updateBluetooth();
     }
 
     @Override
@@ -78,6 +98,7 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
             Log.e(getLogTag(), "Bluetooth is not supported on this device");
             return;
         }
+		mHander.removeMessages(MSG_BLUETOOT_UPDATE);
         disableScanning();
     }
 
diff --git a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
index a4a9891797..67af43fe65 100644
--- a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
+++ b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
@@ -45,6 +45,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
+import android.text.TextUtils;
 
 /**
  * Parent class for settings fragments that contain a list of Bluetooth
@@ -147,6 +148,7 @@ public abstract class DeviceListPreferenceFragment extends
         if (mLocalManager == null || isUiRestricted()) {
             return;
         }
+	stopClassicScanning();
 
         removeAllDevices();
         mLocalManager.setForegroundActivity(null);
@@ -199,6 +201,11 @@ public abstract class DeviceListPreferenceFragment extends
         if (mBluetoothAdapter.getState() != BluetoothAdapter.STATE_ON) {
             return;
         }
+		String name = cachedDevice.getDevice().getName();
+        if (TextUtils.isEmpty(name)){
+            return;
+        }
+		
 
         if (mFilter != null && mFilter.matches(cachedDevice.getDevice())) {
             createDevicePreference(cachedDevice);
@@ -223,13 +230,24 @@ public abstract class DeviceListPreferenceFragment extends
             preference.hideSecondTarget(true);
             mDeviceListGroup.addPreference(preference);
         }
-
+	android.util.Log.d(TAG, "find bt devices: =========="+mDevicePreferenceMap.size());
         initDevicePreference(preference);
         mDevicePreferenceMap.put(cachedDevice, preference);
+	
     }
 
+	boolean is50 = false;
     protected void initDevicePreference(BluetoothDevicePreference preference) {
         // Does nothing by default
+	// liujunjie add size > 50 stop 
+	if(mDevicePreferenceMap.size() >= 50 ){
+	android.util.Log.d(TAG, "size >= 50 stopClassicScanning : =========="+mDevicePreferenceMap);
+	is50 = true;
+	//stopScanning();
+	}else{
+		is50 = false;
+	}
+	
     }
 
     @VisibleForTesting
@@ -284,10 +302,12 @@ public abstract class DeviceListPreferenceFragment extends
 
     @VisibleForTesting
     void startScanning() {
-        if (mFilter != null) {
+        if (mFilter != null && !is50) {
             startClassicScanning();
+			android.util.Log.d("liujunjie55","startScanning  ====startClassicScanning ");
         } else if (mLeScanFilters != null) {
             startLeScanning();
+			android.util.Log.d("liujunjie55","startScanning  ====startLeScanning ");
         }
 
     }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值