Loading framework/java/android/bluetooth/BluetoothAdapter.java +33 −5 Original line number Diff line number Diff line Loading @@ -2819,12 +2819,21 @@ public final class BluetoothAdapter { return false; } try { if (Flags.scanManagerRefactor()) { IBluetoothScan scan = getBluetoothScan(); if (scan == null) { // BLE is not supported return false; } return scan.numHwTrackFiltersAvailable(mAttributionSource) != 0; } else { IBluetoothGatt iGatt = getBluetoothGatt(); if (iGatt == null) { // BLE is not supported return false; } return iGatt.numHwTrackFiltersAvailable(mAttributionSource) != 0; } } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -4242,6 +4251,25 @@ public final class BluetoothAdapter { return null; } /** * Return a binder to BluetoothScan * * @hide */ public @Nullable IBluetoothScan getBluetoothScan() { mServiceLock.readLock().lock(); try { if (mService != null) { return IBluetoothScan.Stub.asInterface(mService.getBluetoothScan()); } } catch (RemoteException e) { Log.e(TAG, e + "\n" + Log.getStackTraceString(new Throwable())); } finally { mServiceLock.readLock().unlock(); } return null; } /** Return a binder to a Profile service */ private @Nullable IBinder getProfile(int profile) { mServiceLock.readLock().lock(); Loading framework/java/android/bluetooth/le/BluetoothLeScanner.java +74 −20 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.bluetooth.Attributable; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothGatt; import android.bluetooth.IBluetoothGatt; import android.bluetooth.IBluetoothScan; import android.bluetooth.annotations.RequiresBluetoothLocationPermission; import android.bluetooth.annotations.RequiresBluetoothScanPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission; Loading @@ -37,6 +38,8 @@ import android.os.RemoteException; import android.os.WorkSource; import android.util.Log; import com.android.bluetooth.flags.Flags; import java.util.ArrayList; import java.util.HashMap; import java.util.List; Loading Loading @@ -253,9 +256,20 @@ public final class BluetoothLeScanner { return postCallbackErrorOrReturn( callback, ScanCallback.SCAN_FAILED_ALREADY_STARTED); } IBluetoothGatt gatt = mBluetoothAdapter.getBluetoothGatt(); IBluetoothScan scan = null; IBluetoothGatt gatt = null; if (Flags.scanManagerRefactor()) { scan = mBluetoothAdapter.getBluetoothScan(); if (scan == null) { return postCallbackErrorOrReturn( callback, ScanCallback.SCAN_FAILED_INTERNAL_ERROR); } } else { gatt = mBluetoothAdapter.getBluetoothGatt(); if (gatt == null) { return postCallbackErrorOrReturn(callback, ScanCallback.SCAN_FAILED_INTERNAL_ERROR); return postCallbackErrorOrReturn( callback, ScanCallback.SCAN_FAILED_INTERNAL_ERROR); } } if (!isSettingsConfigAllowedForScan(settings)) { return postCallbackErrorOrReturn( Loading @@ -271,11 +285,18 @@ public final class BluetoothLeScanner { } if (callback != null) { BleScanCallbackWrapper wrapper = new BleScanCallbackWrapper(gatt, filters, settings, workSource, callback); new BleScanCallbackWrapper( gatt, scan, filters, settings, workSource, callback); wrapper.startRegistration(); } else { try { gatt.startScanForIntent(callbackIntent, settings, filters, mAttributionSource); if (Flags.scanManagerRefactor()) { scan.startScanForIntent( callbackIntent, settings, filters, mAttributionSource); } else { gatt.startScanForIntent( callbackIntent, settings, filters, mAttributionSource); } } catch (RemoteException e) { return ScanCallback.SCAN_FAILED_INTERNAL_ERROR; } Loading @@ -284,9 +305,7 @@ public final class BluetoothLeScanner { return ScanCallback.NO_ERROR; } /** * Stops an ongoing Bluetooth LE scan. */ /** Stops an ongoing Bluetooth LE scan. */ @RequiresLegacyBluetoothAdminPermission @RequiresBluetoothScanPermission @RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN) Loading Loading @@ -316,12 +335,21 @@ public final class BluetoothLeScanner { public void stopScan(PendingIntent callbackIntent) { BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter); try { if (Flags.scanManagerRefactor()) { IBluetoothScan scan = mBluetoothAdapter.getBluetoothScan(); if (scan == null) { Log.w(TAG, "stopScan called after bluetooth has been turned off"); return; } scan.stopScanForIntent(callbackIntent, mAttributionSource); } else { IBluetoothGatt gatt = mBluetoothAdapter.getBluetoothGatt(); if (gatt == null) { Log.w(TAG, "stopScan called after bluetooth has been turned off"); return; } gatt.stopScanForIntent(callbackIntent, mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "Failed to stop scan", e); } Loading Loading @@ -394,6 +422,7 @@ public final class BluetoothLeScanner { private final WorkSource mWorkSource; private ScanSettings mSettings; private IBluetoothGatt mBluetoothGatt; private IBluetoothScan mBluetoothScan; // mLeHandle 0: not registered // -2: registration failed because app is scanning to frequently Loading @@ -403,11 +432,13 @@ public final class BluetoothLeScanner { public BleScanCallbackWrapper( IBluetoothGatt bluetoothGatt, IBluetoothScan bluetoothScan, List<ScanFilter> filters, ScanSettings settings, WorkSource workSource, ScanCallback scanCallback) { mBluetoothGatt = bluetoothGatt; mBluetoothScan = bluetoothScan; mFilters = filters; mSettings = settings; mWorkSource = workSource; Loading @@ -421,7 +452,11 @@ public final class BluetoothLeScanner { // Scan stopped. if (mScannerId == -1 || mScannerId == -2) return; try { if (Flags.scanManagerRefactor()) { mBluetoothScan.registerScanner(this, mWorkSource, mAttributionSource); } else { mBluetoothGatt.registerScanner(this, mWorkSource, mAttributionSource); } wait(REGISTRATION_CALLBACK_TIMEOUT_MILLIS); } catch (InterruptedException | RemoteException e) { Log.e(TAG, "application registration exception", e); Loading Loading @@ -452,9 +487,15 @@ public final class BluetoothLeScanner { return; } try { if (Flags.scanManagerRefactor()) { mBluetoothScan.stopScan(mScannerId, mAttributionSource); mBluetoothScan.unregisterScanner(mScannerId, mAttributionSource); } else { mBluetoothGatt.stopScan(mScannerId, mAttributionSource); mBluetoothGatt.unregisterScanner(mScannerId, mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "Failed to stop scan and unregister", e); } Loading @@ -470,7 +511,11 @@ public final class BluetoothLeScanner { return; } try { if (Flags.scanManagerRefactor()) { mBluetoothScan.flushPendingBatchResults(mScannerId, mAttributionSource); } else { mBluetoothGatt.flushPendingBatchResults(mScannerId, mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "Failed to get pending scan results", e); } Loading @@ -493,12 +538,21 @@ public final class BluetoothLeScanner { try { if (mScannerId == -1) { // Registration succeeds after timeout, unregister scanner. if (Flags.scanManagerRefactor()) { mBluetoothScan.unregisterScanner(scannerId, mAttributionSource); } else { mBluetoothGatt.unregisterScanner(scannerId, mAttributionSource); } } else { mScannerId = scannerId; if (Flags.scanManagerRefactor()) { mBluetoothScan.startScan( mScannerId, mSettings, mFilters, mAttributionSource); } else { mBluetoothGatt.startScan( mScannerId, mSettings, mFilters, mAttributionSource); } } } catch (RemoteException e) { Log.e(TAG, "fail to start le scan: " + e); mScannerId = -1; Loading Loading
framework/java/android/bluetooth/BluetoothAdapter.java +33 −5 Original line number Diff line number Diff line Loading @@ -2819,12 +2819,21 @@ public final class BluetoothAdapter { return false; } try { if (Flags.scanManagerRefactor()) { IBluetoothScan scan = getBluetoothScan(); if (scan == null) { // BLE is not supported return false; } return scan.numHwTrackFiltersAvailable(mAttributionSource) != 0; } else { IBluetoothGatt iGatt = getBluetoothGatt(); if (iGatt == null) { // BLE is not supported return false; } return iGatt.numHwTrackFiltersAvailable(mAttributionSource) != 0; } } catch (RemoteException e) { Log.e(TAG, "", e); } Loading Loading @@ -4242,6 +4251,25 @@ public final class BluetoothAdapter { return null; } /** * Return a binder to BluetoothScan * * @hide */ public @Nullable IBluetoothScan getBluetoothScan() { mServiceLock.readLock().lock(); try { if (mService != null) { return IBluetoothScan.Stub.asInterface(mService.getBluetoothScan()); } } catch (RemoteException e) { Log.e(TAG, e + "\n" + Log.getStackTraceString(new Throwable())); } finally { mServiceLock.readLock().unlock(); } return null; } /** Return a binder to a Profile service */ private @Nullable IBinder getProfile(int profile) { mServiceLock.readLock().lock(); Loading
framework/java/android/bluetooth/le/BluetoothLeScanner.java +74 −20 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.bluetooth.Attributable; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothGatt; import android.bluetooth.IBluetoothGatt; import android.bluetooth.IBluetoothScan; import android.bluetooth.annotations.RequiresBluetoothLocationPermission; import android.bluetooth.annotations.RequiresBluetoothScanPermission; import android.bluetooth.annotations.RequiresLegacyBluetoothAdminPermission; Loading @@ -37,6 +38,8 @@ import android.os.RemoteException; import android.os.WorkSource; import android.util.Log; import com.android.bluetooth.flags.Flags; import java.util.ArrayList; import java.util.HashMap; import java.util.List; Loading Loading @@ -253,9 +256,20 @@ public final class BluetoothLeScanner { return postCallbackErrorOrReturn( callback, ScanCallback.SCAN_FAILED_ALREADY_STARTED); } IBluetoothGatt gatt = mBluetoothAdapter.getBluetoothGatt(); IBluetoothScan scan = null; IBluetoothGatt gatt = null; if (Flags.scanManagerRefactor()) { scan = mBluetoothAdapter.getBluetoothScan(); if (scan == null) { return postCallbackErrorOrReturn( callback, ScanCallback.SCAN_FAILED_INTERNAL_ERROR); } } else { gatt = mBluetoothAdapter.getBluetoothGatt(); if (gatt == null) { return postCallbackErrorOrReturn(callback, ScanCallback.SCAN_FAILED_INTERNAL_ERROR); return postCallbackErrorOrReturn( callback, ScanCallback.SCAN_FAILED_INTERNAL_ERROR); } } if (!isSettingsConfigAllowedForScan(settings)) { return postCallbackErrorOrReturn( Loading @@ -271,11 +285,18 @@ public final class BluetoothLeScanner { } if (callback != null) { BleScanCallbackWrapper wrapper = new BleScanCallbackWrapper(gatt, filters, settings, workSource, callback); new BleScanCallbackWrapper( gatt, scan, filters, settings, workSource, callback); wrapper.startRegistration(); } else { try { gatt.startScanForIntent(callbackIntent, settings, filters, mAttributionSource); if (Flags.scanManagerRefactor()) { scan.startScanForIntent( callbackIntent, settings, filters, mAttributionSource); } else { gatt.startScanForIntent( callbackIntent, settings, filters, mAttributionSource); } } catch (RemoteException e) { return ScanCallback.SCAN_FAILED_INTERNAL_ERROR; } Loading @@ -284,9 +305,7 @@ public final class BluetoothLeScanner { return ScanCallback.NO_ERROR; } /** * Stops an ongoing Bluetooth LE scan. */ /** Stops an ongoing Bluetooth LE scan. */ @RequiresLegacyBluetoothAdminPermission @RequiresBluetoothScanPermission @RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN) Loading Loading @@ -316,12 +335,21 @@ public final class BluetoothLeScanner { public void stopScan(PendingIntent callbackIntent) { BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter); try { if (Flags.scanManagerRefactor()) { IBluetoothScan scan = mBluetoothAdapter.getBluetoothScan(); if (scan == null) { Log.w(TAG, "stopScan called after bluetooth has been turned off"); return; } scan.stopScanForIntent(callbackIntent, mAttributionSource); } else { IBluetoothGatt gatt = mBluetoothAdapter.getBluetoothGatt(); if (gatt == null) { Log.w(TAG, "stopScan called after bluetooth has been turned off"); return; } gatt.stopScanForIntent(callbackIntent, mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "Failed to stop scan", e); } Loading Loading @@ -394,6 +422,7 @@ public final class BluetoothLeScanner { private final WorkSource mWorkSource; private ScanSettings mSettings; private IBluetoothGatt mBluetoothGatt; private IBluetoothScan mBluetoothScan; // mLeHandle 0: not registered // -2: registration failed because app is scanning to frequently Loading @@ -403,11 +432,13 @@ public final class BluetoothLeScanner { public BleScanCallbackWrapper( IBluetoothGatt bluetoothGatt, IBluetoothScan bluetoothScan, List<ScanFilter> filters, ScanSettings settings, WorkSource workSource, ScanCallback scanCallback) { mBluetoothGatt = bluetoothGatt; mBluetoothScan = bluetoothScan; mFilters = filters; mSettings = settings; mWorkSource = workSource; Loading @@ -421,7 +452,11 @@ public final class BluetoothLeScanner { // Scan stopped. if (mScannerId == -1 || mScannerId == -2) return; try { if (Flags.scanManagerRefactor()) { mBluetoothScan.registerScanner(this, mWorkSource, mAttributionSource); } else { mBluetoothGatt.registerScanner(this, mWorkSource, mAttributionSource); } wait(REGISTRATION_CALLBACK_TIMEOUT_MILLIS); } catch (InterruptedException | RemoteException e) { Log.e(TAG, "application registration exception", e); Loading Loading @@ -452,9 +487,15 @@ public final class BluetoothLeScanner { return; } try { if (Flags.scanManagerRefactor()) { mBluetoothScan.stopScan(mScannerId, mAttributionSource); mBluetoothScan.unregisterScanner(mScannerId, mAttributionSource); } else { mBluetoothGatt.stopScan(mScannerId, mAttributionSource); mBluetoothGatt.unregisterScanner(mScannerId, mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "Failed to stop scan and unregister", e); } Loading @@ -470,7 +511,11 @@ public final class BluetoothLeScanner { return; } try { if (Flags.scanManagerRefactor()) { mBluetoothScan.flushPendingBatchResults(mScannerId, mAttributionSource); } else { mBluetoothGatt.flushPendingBatchResults(mScannerId, mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "Failed to get pending scan results", e); } Loading @@ -493,12 +538,21 @@ public final class BluetoothLeScanner { try { if (mScannerId == -1) { // Registration succeeds after timeout, unregister scanner. if (Flags.scanManagerRefactor()) { mBluetoothScan.unregisterScanner(scannerId, mAttributionSource); } else { mBluetoothGatt.unregisterScanner(scannerId, mAttributionSource); } } else { mScannerId = scannerId; if (Flags.scanManagerRefactor()) { mBluetoothScan.startScan( mScannerId, mSettings, mFilters, mAttributionSource); } else { mBluetoothGatt.startScan( mScannerId, mSettings, mFilters, mAttributionSource); } } } catch (RemoteException e) { Log.e(TAG, "fail to start le scan: " + e); mScannerId = -1; Loading