如何抑制BluetoothLeScanner日志?

时间:2016-11-17 09:04:42

标签: android bluetooth

我正试图摆脱那些讨厌的日志

11-17 09:56:46.102 24862-29194/my.app D/BluetoothLeScanner: onScanResult() - ScanResult{mDevice=68:F7:F1:66:7F:58, mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=null, mManufacturerSpecificData={76=[12, 14, 0, -33, 112, -93, -94, 51, 81, -23, 24, 31, -110, 121, 116, -12]}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=null], mRssi=-59, mTimestampNanos=7365019329223}

查看BluetoothLeScanner内部显示此行为是通过DBG变量控制的。

    /**
     * Callback reporting an LE scan result.
     *
     * @hide
     */
    @Override
    public void onScanResult(final ScanResult scanResult) {
        if (DBG) Log.d(TAG, "onScanResult() - " + scanResult.toString());

        // Check null in case the scan has been stopped
        synchronized (this) {
            if (mClientIf <= 0) return;
        }
        Handler handler = new Handler(Looper.getMainLooper());
        handler.post(new Runnable() {
            @Override
            public void run() {
                mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES, scanResult);
            }
        });

    }

所以我尝试使用反射来改变这个参数,但没有运气。

try {
        Field dbg = BluetoothLeScanner.class.getDeclaredField("DBG");
        dbg.setAccessible(true);
        System.out.println("dbg = " + dbg.getBoolean(null));
        dbg.setBoolean(null, false);

        Field vdbg = BluetoothLeScanner.class.getDeclaredField("VDBG");
        vdbg.setAccessible(true);
        System.out.println("vdbg = " + vdbg.getBoolean(null));
        vdbg.setBoolean(null, false);

    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

但看起来这根本没有效果。事件调试器无法在onScanResult方法中命中断点。有没有人有一些线索为什么这不起作用?我自己的怀疑是,这个代码可能在不同的classLoader或进程中执行,而不是主应用程序。

0 个答案:

没有答案