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