You need to enable JavaScript to run this app. Redmi手机调用removeBond解绑蓝牙失效 其他安卓设备可正常运行
优惠活动
大模型
产品
解决方案
定价
更多

Redmi手机调用removeBond解绑蓝牙失效 其他安卓设备可正常运行

Redmi设备反射调用蓝牙解绑接口失效适配方案

现有实现

目前项目中通过反射调用隐藏removeBond方法实现蓝牙解绑的扩展函数如下:

fun BluetoothDevice.removeBond() {
    try {
        javaClass.getMethod("removeBond").invoke(this)
    } catch (e: Exception) {
        Timber.i("Removing bond has been failed. ${e.message}")
    }
}

该实现除Redmi设备外,可在其他安卓品牌设备上正常完成解绑操作。

问题根因

从运行日志可直接定位拦截原因:

1610017762.258 ? I/BluetoothDevice: removeBond() for device #### called by pid: 2027 tid: 2027
1610017762.268 ? E/BluetoothUtils: checkCallerAllowedToTouchBondDevices: the BT device is attached to 1000, can't be touched by 10211
1610017762.268 ? W/BluetoothAdapterService: removeBond() - Not allowed ownerUid to remove bond unless callerUid is system uid.

Redmi搭载的MIUI系统在原生Android蓝牙逻辑之上,新增了自研的校验规则:

  • 对所有调用removeBond的请求,校验调用方的真实UID
  • 仅系统UID(值为1000)的应用可以直接操作已绑定蓝牙设备的解绑流程
  • 普通第三方应用(日志中UID为10211)哪怕通过反射拿到了隐藏方法的调用权限,请求也会被直接拦截,不会执行实际解绑逻辑

落地适配方案

  • 保留现有反射解绑逻辑作为非MIUI设备的默认实现
    原有的removeBond扩展函数在其他安卓品牌设备上可正常运行,不需要做修改,避免增加不必要的兼容成本
  • 针对MIUI设备增加自动兜底逻辑
    在反射调用捕获到MIUI特有的权限拦截异常时,直接拉起系统蓝牙设置的对应设备详情页,引导用户手动完成解绑,这是目前MIUI上最稳定、无合规风险的实现路径
    拉起系统设备详情页的参考实现:
    fun jumpToBluetoothDeviceDetail(context: Context, device: BluetoothDevice) {
        val intent = Intent().apply {
            component = ComponentName(
                "com.android.settings",
                "com.android.settings.bluetooth.SubDeviceSettings"
            )
            putExtra("extra_device", device)
            flags = Intent.FLAG_ACTIVITY_NEW_TASK
        }
        context.startActivity(intent)
    }
    
  • 可尝试适配MIUI特殊权限申请
    部分MIUI版本开放了「允许应用修改已配对蓝牙设备」的特殊权限,引导用户在应用权限管理页为当前应用开启该权限后,可绕过自研的UID校验,直接执行解绑逻辑
    跳转MIUI权限编辑页的参考实现:
    fun jumpToMiuiAppPermissionSetting(context: Context) {
        val intent = Intent("miui.intent.action.APP_PERM_EDITOR").apply {
            setClassName(
                "com.miui.securitycenter",
                "com.miui.permcenter.permissions.PermissionsEditorActivity"
            )
            putExtra("extra_pkgname", context.packageName)
            flags = Intent.FLAG_ACTIVITY_NEW_TASK
        }
        context.startActivity(intent)
    }
    

避坑提示

  • 不要尝试通过伪造调用栈、提权申请、反射跨进程调用系统服务的方式绕过MIUI校验,这类方案会在后续MIUI版本中被持续封堵,且存在应用市场合规审核风险
  • 不要强制要求用户开启未在系统权限列表中明示的隐藏权限,会导致用户体验下降

内容的提问来源于stack exchange,提问作者komal mane

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.09 09:15:04