@Test public void testScannerStartMethodIsNotCrashingTheAppIfItIsRunningInKnoxContainer() { when(adapter.isEnabled()).thenThrow(SecurityException.class); shadowOf(packageManager).setSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE, true); device.startScans(scanCallback); verify(adapter).isEnabled(); verifyNoMoreInteractions(adapter); }
@Override public void startScans(@NonNull ScanCallback scanCallback) { if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { BeaconLogger.e( "BLE is missing on that device; BLE scans won't be started" ); return; } try { if (!bluetoothAdapter.isEnabled()) { BeaconLogger.e( "BluetoothAdapter is not enabled, scans will not be started (check if " + "Bluetooth is turned on)" ); return; } final BluetoothLeScanner bleScanner = bluetoothAdapter.getBluetoothLeScanner(); if (bleScanner == null) { BeaconLogger.e( "BluetoothLeScanner is missing, scans will not be started " + "(check if Bluetooth is turned on)" ); return; } bleScanner .startScan( scanFilters, scanSettings, scanCallback ); } catch (SecurityException e) { BeaconLogger.e( "Can't start the BLE scans since it results in SecurityException (check if the " + "is running in the Samsung's Knox container or something similar)" ); } }
SystemBleDevice implements IBleDevice { @Override public void startScans(@NonNull ScanCallback scanCallback) { if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { BeaconLogger.e( "BLE is missing on that device; BLE scans won't be started" ); return; } try { if (!bluetoothAdapter.isEnabled()) { BeaconLogger.e( "BluetoothAdapter is not enabled, scans will not be started (check if " + "Bluetooth is turned on)" ); return; } final BluetoothLeScanner bleScanner = bluetoothAdapter.getBluetoothLeScanner(); if (bleScanner == null) { BeaconLogger.e( "BluetoothLeScanner is missing, scans will not be started " + "(check if Bluetooth is turned on)" ); return; } bleScanner .startScan( scanFilters, scanSettings, scanCallback ); } catch (SecurityException e) { BeaconLogger.e( "Can't start the BLE scans since it results in SecurityException (check if the " + "is running in the Samsung's Knox container or something similar)" ); } } }
SystemBleDevice implements IBleDevice { @Override public void startScans(@NonNull ScanCallback scanCallback) { if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { BeaconLogger.e( "BLE is missing on that device; BLE scans won't be started" ); return; } try { if (!bluetoothAdapter.isEnabled()) { BeaconLogger.e( "BluetoothAdapter is not enabled, scans will not be started (check if " + "Bluetooth is turned on)" ); return; } final BluetoothLeScanner bleScanner = bluetoothAdapter.getBluetoothLeScanner(); if (bleScanner == null) { BeaconLogger.e( "BluetoothLeScanner is missing, scans will not be started " + "(check if Bluetooth is turned on)" ); return; } bleScanner .startScan( scanFilters, scanSettings, scanCallback ); } catch (SecurityException e) { BeaconLogger.e( "Can't start the BLE scans since it results in SecurityException (check if the " + "is running in the Samsung's Knox container or something similar)" ); } } SystemBleDevice(Context context,
                    BluetoothAdapter bluetoothAdapter,
                    ScanSettings scanSettings,
                    List<ScanFilter> scanFilters); }
SystemBleDevice implements IBleDevice { @Override public void startScans(@NonNull ScanCallback scanCallback) { if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { BeaconLogger.e( "BLE is missing on that device; BLE scans won't be started" ); return; } try { if (!bluetoothAdapter.isEnabled()) { BeaconLogger.e( "BluetoothAdapter is not enabled, scans will not be started (check if " + "Bluetooth is turned on)" ); return; } final BluetoothLeScanner bleScanner = bluetoothAdapter.getBluetoothLeScanner(); if (bleScanner == null) { BeaconLogger.e( "BluetoothLeScanner is missing, scans will not be started " + "(check if Bluetooth is turned on)" ); return; } bleScanner .startScan( scanFilters, scanSettings, scanCallback ); } catch (SecurityException e) { BeaconLogger.e( "Can't start the BLE scans since it results in SecurityException (check if the " + "is running in the Samsung's Knox container or something similar)" ); } } SystemBleDevice(Context context,
                    BluetoothAdapter bluetoothAdapter,
                    ScanSettings scanSettings,
                    List<ScanFilter> scanFilters); @Override void startScans(@NonNull ScanCallback scanCallback); @Override void stopScans(@NonNull ScanCallback scanCallback); }
SystemBleDevice implements IBleDevice { @Override public void startScans(@NonNull ScanCallback scanCallback) { if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { BeaconLogger.e( "BLE is missing on that device; BLE scans won't be started" ); return; } try { if (!bluetoothAdapter.isEnabled()) { BeaconLogger.e( "BluetoothAdapter is not enabled, scans will not be started (check if " + "Bluetooth is turned on)" ); return; } final BluetoothLeScanner bleScanner = bluetoothAdapter.getBluetoothLeScanner(); if (bleScanner == null) { BeaconLogger.e( "BluetoothLeScanner is missing, scans will not be started " + "(check if Bluetooth is turned on)" ); return; } bleScanner .startScan( scanFilters, scanSettings, scanCallback ); } catch (SecurityException e) { BeaconLogger.e( "Can't start the BLE scans since it results in SecurityException (check if the " + "is running in the Samsung's Knox container or something similar)" ); } } SystemBleDevice(Context context,
                    BluetoothAdapter bluetoothAdapter,
                    ScanSettings scanSettings,
                    List<ScanFilter> scanFilters); @Override void startScans(@NonNull ScanCallback scanCallback); @Override void stopScans(@NonNull ScanCallback scanCallback);  }