Loading framework/java/android/bluetooth/BluetoothAdapter.java +12 −2 Original line number Diff line number Diff line Loading @@ -847,7 +847,8 @@ public final class BluetoothAdapter { } synchronized (mLock) { if (sBluetoothLeScanner == null) { sBluetoothLeScanner = new BluetoothLeScanner(mManagerService); sBluetoothLeScanner = new BluetoothLeScanner(mManagerService, getOpPackageName(), getFeatureId()); } } return sBluetoothLeScanner; Loading Loading @@ -1637,6 +1638,15 @@ public final class BluetoothAdapter { return ActivityThread.currentOpPackageName(); } private String getFeatureId() { // Workaround for legacy API for getting a BluetoothAdapter not // passing a context if (mContext != null) { return null; } return null; } /** * Start the remote device discovery process. * <p>The discovery process usually involves an inquiry scan of about 12 Loading Loading @@ -1674,7 +1684,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.startDiscovery(getOpPackageName()); return mService.startDiscovery(getOpPackageName(), getFeatureId()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading framework/java/android/bluetooth/BluetoothManager.java +22 −8 Original line number Diff line number Diff line Loading @@ -22,7 +22,9 @@ import android.annotation.RequiresPermission; import android.annotation.SystemService; import android.content.Context; import android.content.pm.PackageManager; import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; import android.util.Log; import java.util.ArrayList; Loading Loading @@ -60,22 +62,34 @@ public final class BluetoothManager { * @hide */ public BluetoothManager(Context context) { if (null == null) { context = context.getApplicationContext(); if (context == null) { throw new IllegalArgumentException( "context not associated with any application (using a mock context?)"); } // Legacy api - getDefaultAdapter does not take in the context mAdapter = BluetoothAdapter.getDefaultAdapter(); } else { IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE); if (b != null) { mAdapter = new BluetoothAdapter(IBluetoothManager.Stub.asInterface(b)); } else { Log.e(TAG, "Bluetooth binder is null"); mAdapter = null; } } // Context is not initialized in constructor if (mAdapter != null) { mAdapter.setContext(context); } } /** * Get the default BLUETOOTH Adapter for this device. * Get the BLUETOOTH Adapter for this device. * * @return the default BLUETOOTH Adapter * @return the BLUETOOTH Adapter */ public BluetoothAdapter getAdapter() { return mAdapter; Loading framework/java/android/bluetooth/le/BluetoothLeScanner.java +13 −7 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SystemApi; import android.app.ActivityThread; import android.app.PendingIntent; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothGatt; Loading Loading @@ -84,17 +83,25 @@ public final class BluetoothLeScanner { private BluetoothAdapter mBluetoothAdapter; private final Map<ScanCallback, BleScanCallbackWrapper> mLeScanClients; private final String mOpPackageName; private final String mFeatureId; /** * Use {@link BluetoothAdapter#getBluetoothLeScanner()} instead. * * @param bluetoothManager BluetoothManager that conducts overall Bluetooth Management. * @param opPackageName The opPackageName of the context this object was created from * @param featureId The featureId of the context this object was created from * @hide */ public BluetoothLeScanner(IBluetoothManager bluetoothManager) { public BluetoothLeScanner(IBluetoothManager bluetoothManager, @NonNull String opPackageName, @Nullable String featureId) { mBluetoothManager = bluetoothManager; mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mHandler = new Handler(Looper.getMainLooper()); mLeScanClients = new HashMap<ScanCallback, BleScanCallbackWrapper>(); mOpPackageName = opPackageName; mFeatureId = featureId; } /** Loading Loading @@ -246,8 +253,8 @@ public final class BluetoothLeScanner { wrapper.startRegistration(); } else { try { gatt.startScanForIntent(callbackIntent, settings, filters, ActivityThread.currentOpPackageName()); gatt.startScanForIntent(callbackIntent, settings, filters, mOpPackageName, mFeatureId); } catch (RemoteException e) { return ScanCallback.SCAN_FAILED_INTERNAL_ERROR; } Loading Loading @@ -288,7 +295,7 @@ public final class BluetoothLeScanner { IBluetoothGatt gatt; try { gatt = mBluetoothManager.getBluetoothGatt(); gatt.stopScanForIntent(callbackIntent, ActivityThread.currentOpPackageName()); gatt.stopScanForIntent(callbackIntent, mOpPackageName); } catch (RemoteException e) { } } Loading Loading @@ -448,8 +455,7 @@ public final class BluetoothLeScanner { } else { mScannerId = scannerId; mBluetoothGatt.startScan(mScannerId, mSettings, mFilters, mResultStorages, ActivityThread.currentOpPackageName()); mResultStorages, mOpPackageName, mFeatureId); } } catch (RemoteException e) { Log.e(TAG, "fail to start le scan: " + e); Loading Loading
framework/java/android/bluetooth/BluetoothAdapter.java +12 −2 Original line number Diff line number Diff line Loading @@ -847,7 +847,8 @@ public final class BluetoothAdapter { } synchronized (mLock) { if (sBluetoothLeScanner == null) { sBluetoothLeScanner = new BluetoothLeScanner(mManagerService); sBluetoothLeScanner = new BluetoothLeScanner(mManagerService, getOpPackageName(), getFeatureId()); } } return sBluetoothLeScanner; Loading Loading @@ -1637,6 +1638,15 @@ public final class BluetoothAdapter { return ActivityThread.currentOpPackageName(); } private String getFeatureId() { // Workaround for legacy API for getting a BluetoothAdapter not // passing a context if (mContext != null) { return null; } return null; } /** * Start the remote device discovery process. * <p>The discovery process usually involves an inquiry scan of about 12 Loading Loading @@ -1674,7 +1684,7 @@ public final class BluetoothAdapter { try { mServiceLock.readLock().lock(); if (mService != null) { return mService.startDiscovery(getOpPackageName()); return mService.startDiscovery(getOpPackageName(), getFeatureId()); } } catch (RemoteException e) { Log.e(TAG, "", e); Loading
framework/java/android/bluetooth/BluetoothManager.java +22 −8 Original line number Diff line number Diff line Loading @@ -22,7 +22,9 @@ import android.annotation.RequiresPermission; import android.annotation.SystemService; import android.content.Context; import android.content.pm.PackageManager; import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; import android.util.Log; import java.util.ArrayList; Loading Loading @@ -60,22 +62,34 @@ public final class BluetoothManager { * @hide */ public BluetoothManager(Context context) { if (null == null) { context = context.getApplicationContext(); if (context == null) { throw new IllegalArgumentException( "context not associated with any application (using a mock context?)"); } // Legacy api - getDefaultAdapter does not take in the context mAdapter = BluetoothAdapter.getDefaultAdapter(); } else { IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE); if (b != null) { mAdapter = new BluetoothAdapter(IBluetoothManager.Stub.asInterface(b)); } else { Log.e(TAG, "Bluetooth binder is null"); mAdapter = null; } } // Context is not initialized in constructor if (mAdapter != null) { mAdapter.setContext(context); } } /** * Get the default BLUETOOTH Adapter for this device. * Get the BLUETOOTH Adapter for this device. * * @return the default BLUETOOTH Adapter * @return the BLUETOOTH Adapter */ public BluetoothAdapter getAdapter() { return mAdapter; Loading
framework/java/android/bluetooth/le/BluetoothLeScanner.java +13 −7 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SystemApi; import android.app.ActivityThread; import android.app.PendingIntent; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothGatt; Loading Loading @@ -84,17 +83,25 @@ public final class BluetoothLeScanner { private BluetoothAdapter mBluetoothAdapter; private final Map<ScanCallback, BleScanCallbackWrapper> mLeScanClients; private final String mOpPackageName; private final String mFeatureId; /** * Use {@link BluetoothAdapter#getBluetoothLeScanner()} instead. * * @param bluetoothManager BluetoothManager that conducts overall Bluetooth Management. * @param opPackageName The opPackageName of the context this object was created from * @param featureId The featureId of the context this object was created from * @hide */ public BluetoothLeScanner(IBluetoothManager bluetoothManager) { public BluetoothLeScanner(IBluetoothManager bluetoothManager, @NonNull String opPackageName, @Nullable String featureId) { mBluetoothManager = bluetoothManager; mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mHandler = new Handler(Looper.getMainLooper()); mLeScanClients = new HashMap<ScanCallback, BleScanCallbackWrapper>(); mOpPackageName = opPackageName; mFeatureId = featureId; } /** Loading Loading @@ -246,8 +253,8 @@ public final class BluetoothLeScanner { wrapper.startRegistration(); } else { try { gatt.startScanForIntent(callbackIntent, settings, filters, ActivityThread.currentOpPackageName()); gatt.startScanForIntent(callbackIntent, settings, filters, mOpPackageName, mFeatureId); } catch (RemoteException e) { return ScanCallback.SCAN_FAILED_INTERNAL_ERROR; } Loading Loading @@ -288,7 +295,7 @@ public final class BluetoothLeScanner { IBluetoothGatt gatt; try { gatt = mBluetoothManager.getBluetoothGatt(); gatt.stopScanForIntent(callbackIntent, ActivityThread.currentOpPackageName()); gatt.stopScanForIntent(callbackIntent, mOpPackageName); } catch (RemoteException e) { } } Loading Loading @@ -448,8 +455,7 @@ public final class BluetoothLeScanner { } else { mScannerId = scannerId; mBluetoothGatt.startScan(mScannerId, mSettings, mFilters, mResultStorages, ActivityThread.currentOpPackageName()); mResultStorages, mOpPackageName, mFeatureId); } } catch (RemoteException e) { Log.e(TAG, "fail to start le scan: " + e); Loading