Commit 458fb496 authored by martin hou's avatar martin hou

fix: 调整过滤规则

parent 992d2444
...@@ -1699,15 +1699,35 @@ Jensen.registerHandler(BT_DEV_LIST, (msg, jensen) => { ...@@ -1699,15 +1699,35 @@ Jensen.registerHandler(BT_DEV_LIST, (msg, jensen) => {
}); });
function __is_headset_or_mic(cod) { function __is_headset_or_mic(cod) {
const SERVICE_AUDIO = 1 << 21; // Audio bit (bit 21) if (typeof cod !== 'number') return false;
const SERVICE_TELEPHONY = 1 << 22; // Telephony bit (bit 22)
const SERVICE_CAPTURING = 1 << 19; // Capturing (mic / scanner) bit (optional)
const serviceMask = cod & 0x00FFE000; // --- 定义 service-class bits (Major Service Classes) ---
// Explanation: bits 13–23 correspond to mask 0x00FFE000 (binary: 0000 0000 1111 1111 1110 0000 0000 0000) const SERVICE_RENDERING = 1 << 18; // Rendering (speaker, etc.) :contentReference[oaicite:1]{index=1}
// Alternatively you can directly mask bits 19,21,22 as above. const SERVICE_CAPTURING = 1 << 19; // Capturing (microphone / scanner) :contentReference[oaicite:2]{index=2}
const SERVICE_AUDIO = 1 << 21; // Audio (speaker, mic, headset-service, ...) :contentReference[oaicite:3]{index=3}
const SERVICE_TELEPHONY = 1 << 22; // Telephony (headset / hands-free / phone service) :contentReference[oaicite:4]{index=4}
return (serviceMask & (SERVICE_AUDIO | SERVICE_TELEPHONY | SERVICE_CAPTURING)) !== 0; // --- 提取 major device class (bits 12–8) ---
const MAJOR_DEVICE_MASK = 0x1F00; // per BluetoothClass definition :contentReference[oaicite:5]{index=5}
const major = cod & MAJOR_DEVICE_MASK;
// 常见 major classes 的定义 (值与 BluetoothClass.Device.Major 的常量一致) :contentReference[oaicite:6]{index=6}
const MAJOR_AUDIO_VIDEO = 0x0400;
const MAJOR_PHONE = 0x0200;
// 你也可以考虑 “Wearable” / “Peripheral” 等,但对于 headset/mic 最主要是 Audio/Video 或 Phone
// --- 提取 service bits ---
const serviceBits = cod & 0x00FFE000; // bits 13–23 是 service-class field :contentReference[oaicite:7]{index=7}
// --- 判断 logic ---
// 条件 A: major class 是 Audio/Video 或 Phone(这两类设备比较可能是耳机 / 耳麦 / hands-free / audio 设备)
const majorIsAudioOrPhone = (major === MAJOR_AUDIO_VIDEO) || (major === MAJOR_PHONE);
// 条件 B: service-class 中至少有 Audio / Rendering / Capturing / Telephony 中的一个 bit
const serviceIndicatesAudio =
(serviceBits & (SERVICE_AUDIO | SERVICE_RENDERING | SERVICE_CAPTURING | SERVICE_TELEPHONY)) !== 0;
return majorIsAudioOrPhone && serviceIndicatesAudio;
} }
export { Jensen }; export { Jensen };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment