频繁扫描,导致扫描蓝牙失败

App 'com.xxx.xxx' is scanning too frequently

2019-07-22 10:29:04.896 8905-12052/? E/gatt-GattService: App 'com.realsil.demo.fastpair' is scanning too frequently
2019-07-22 10:29:04.896 17824-17848/com.realsil.demo.fastpair D/BluetoothLeScanner: onScannerRegistered() - status=6 scannerId=-1 mScannerId=0
2019-07-22 10:29:04.933 1874-18015/? D/HwRecentsTaskUtils: refreshToCache
2019-07-22 10:29:04.933 1874-18015/? D/HwRecentsTaskUtils: searchFromDate
2019-07-22 10:29:04.936 1732-22798/? E/HsmCoreServiceImpl: onTransact in code is: 103
2019-07-22 10:29:04.936 1732-22798/? I/MediaProcessHandler: playingUids: 
2019-07-22 10:29:04.937 1874-18015/? I/RecentsTaskLoadPlan: to show tasks size is 2
2019-07-22 10:29:05.048 1282-1419/? V/WindowManager: Exit animation finished in Window{6deacbb u0 com.realsil.demo.fastpair/com.realsil.sdk.fastpair.FastPairDialog EXITING}: remove=true
2019-07-22 10:29:05.048 1282-1419/? E/WindowManager: win=Window{6deacbb u0 com.realsil.demo.fastpair/com.realsil.sdk.fastpair.FastPairDialog EXITING} destroySurfaces: appStopped=false win.mWindowRemovalAllowed=true win.mRemoveOnExit=true

/Users/bingshanguxue/workspace/googlesource/android/platform/packages/apps/Bluetooth/src/com/android/bluetooth/gatt/GattService.java


void registerScanner(IScannerCallback callback, WorkSource workSource) throws RemoteException {
        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");

        UUID uuid = UUID.randomUUID();
        if (DBG) {
            Log.d(TAG, "registerScanner() - UUID=" + uuid);
        }

        if (workSource != null) {
            enforceImpersonatationPermission();
        }

        AppScanStats app = mScannerMap.getAppScanStatsByUid(Binder.getCallingUid());
        if (app != null && app.isScanningTooFrequently()
                && checkCallingOrSelfPermission(BLUETOOTH_PRIVILEGED) != PERMISSION_GRANTED) {
            Log.e(TAG, "App '" + app.appName + "' is scanning too frequently");
            callback.onScannerRegistered(ScanCallback.SCAN_FAILED_SCANNING_TOO_FREQUENTLY, -1);
            return;
        }

        mScannerMap.add(uuid, workSource, callback, null, this);
        mScanManager.registerScanner(uuid);
    }

/Users/bingshanguxue/workspace/googlesource/android/platform/packages/apps/Bluetooth/src/com/android/bluetooth/gatt/AppScanStats.java

// This constant defines the time window an app can scan multiple times.
    // Any single app can scan up to |NUM_SCAN_DURATIONS_KEPT| times during
    // this window. Once they reach this limit, they must wait until their
    // earliest recorded scan exits this window.
    static final long EXCESSIVE_SCANNING_PERIOD_MS = 30 * 1000;

synchronized boolean isScanningTooFrequently() {
        if (mLastScans.size() < NUM_SCAN_DURATIONS_KEPT) {
            return false;
        }

        return (SystemClock.elapsedRealtime() - mLastScans.get(0).timestamp)
                < EXCESSIVE_SCANNING_PERIOD_MS;
    }

你可能感兴趣的:(频繁扫描,导致扫描蓝牙失败)