From 655ef5b95b3c2fc2c73fe311a65810d47b24a4cd Mon Sep 17 00:00:00 2001 From: Se Hoon Bang Date: Mon, 22 Aug 2022 21:10:50 +0000 Subject: [PATCH] updating FitbitGatt to meet coding standards --- .../fitbit/bluetooth/fbgatt/FitbitGatt.java | 287 +++++++++++------- 1 file changed, 174 insertions(+), 113 deletions(-) diff --git a/src/main/java/com/fitbit/bluetooth/fbgatt/FitbitGatt.java b/src/main/java/com/fitbit/bluetooth/fbgatt/FitbitGatt.java index d86ecb60..63640474 100644 --- a/src/main/java/com/fitbit/bluetooth/fbgatt/FitbitGatt.java +++ b/src/main/java/com/fitbit/bluetooth/fbgatt/FitbitGatt.java @@ -126,8 +126,9 @@ public class FitbitGatt implements PeripheralScanner.TrackerScannerListener, Blu private Handler connectionCleanup; @Nullable private LooperWatchdog asyncOperationThreadWatchdog; - // this should be max priority so as to not affect performance - private HandlerThread fitbitGattAsyncOperationThread = new HandlerThread("FitbitGatt Async Operation Thread", Thread.MAX_PRIORITY); + // this should be max priority so as to not affect performance + private HandlerThread fitbitGattAsyncOperationThread = + new HandlerThread("FitbitGatt Async Operation Thread", Thread.MAX_PRIORITY); private Handler fitbitGattAsyncOperationHandler; private BluetoothRadioStatusListener radioStatusListener; @VisibleForTesting @@ -386,7 +387,8 @@ void setStarted() { Timber.i("Initalization complete, internalInitialize finished"); boolean success = isInitialized.compareAndSet(false, true); if (!success) { - Timber.w("There was a problem updating the started state, are you starting from two threads?"); + Timber.w( + "There was a problem updating the started state, are you starting from two threads?"); } } @@ -412,11 +414,13 @@ void setStarted() { public boolean startHighPriorityScan(Context context) { if (alwaysConnectedScanner.isAlwaysConnectedScannerEnabled()) { - Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); + Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); return false; } if (peripheralScanner == null) { - Timber.w("You are trying to start a high-priority scan, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to start a high-priority scan, but the scanner isn't set-up, did you call" + + " FitbitGatt#initializeScanner?"); return false; } return peripheralScanner.startHighPriorityScan(context); @@ -432,11 +436,13 @@ public boolean startHighPriorityScan(Context context) { @SuppressWarnings({"unused", "WeakerAccess"}) // API Method public boolean startPeriodicScan(Context context) { if (alwaysConnectedScanner.isAlwaysConnectedScannerEnabled()) { - Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); + Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); return false; } if (peripheralScanner == null) { - Timber.w("You are trying to start a periodical scan, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to start a periodical scan, but the scanner isn't set-up, did you call" + + " FitbitGatt#initializeScanner?"); return false; } return peripheralScanner.startPeriodicScan(context); @@ -451,11 +457,13 @@ public boolean startPeriodicScan(Context context) { */ public void cancelScan(@Nullable Context context) { if (alwaysConnectedScanner.isAlwaysConnectedScannerEnabled()) { - Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); + Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); return; } if (peripheralScanner == null) { - Timber.w("You are trying to cancel a scan, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to cancel a scan, but the scanner isn't set-up, did you call" + + " FitbitGatt#initializeScanner?"); return; } peripheralScanner.cancelScan(context); @@ -470,11 +478,13 @@ public void cancelScan(@Nullable Context context) { @SuppressWarnings({"unused", "WeakerAccess"}) // API Method public void cancelPeriodicalScan(@Nullable Context context) { if (alwaysConnectedScanner.isAlwaysConnectedScannerEnabled()) { - Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); + Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); return; } if (peripheralScanner == null) { - Timber.w("You are trying to cancel a scan, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to cancel a scan, but the scanner isn't set-up, did you call" + + " FitbitGatt#initializeScanner?"); return; } peripheralScanner.cancelPeriodicalScan(context); @@ -489,11 +499,13 @@ public void cancelPeriodicalScan(@Nullable Context context) { @SuppressWarnings({"unused", "WeakerAccess"}) // API Method public void cancelHighPriorityScan(@Nullable Context context) { if (alwaysConnectedScanner.isAlwaysConnectedScannerEnabled()) { - Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); + Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); return; } if (peripheralScanner == null) { - Timber.w("You are trying to cancel a scan, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to cancel a scan, but the scanner isn't set-up, did you call" + + " FitbitGatt#initializeScanner?"); return; } peripheralScanner.cancelHighPriorityScan(context); @@ -508,7 +520,9 @@ public void cancelHighPriorityScan(@Nullable Context context) { @SuppressWarnings({"unused", "WeakerAccess"}) // API Method public void setScannerMockMode(boolean mockMode) { if (peripheralScanner == null) { - Timber.w("You are trying to put the scanner into mock mode, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to put the scanner into mock mode, but the scanner isn't set-up, did you" + + " call FitbitGatt#initializeScanner?"); return; } alwaysConnectedScanner.setTestMode(mockMode); @@ -523,7 +537,9 @@ public void setScannerMockMode(boolean mockMode) { @SuppressWarnings({"unused", "WeakerAccess"}) // API Method// API Method public void setDeviceNameScanFilters(List deviceNameFilters) { if (peripheralScanner == null) { - Timber.w("You are trying to set device name filters on the scanner, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to set device name filters on the scanner, but the scanner isn't set-up," + + " did you call FitbitGatt#initializeScanner?"); return; } peripheralScanner.setDeviceNameFilters(deviceNameFilters); @@ -539,7 +555,9 @@ public void setDeviceNameScanFilters(List deviceNameFilters) { @SuppressWarnings({"unused", "WeakerAccess"}) // API Method public void addDeviceNameScanFilter(String deviceName) { if (peripheralScanner == null) { - Timber.w("You are trying to add a device name filter onto the scanner, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to add a device name filter onto the scanner, but the scanner isn't" + + " set-up, did you call FitbitGatt#initializeScanner?"); return; } peripheralScanner.addDeviceNameFilter(deviceName); @@ -556,7 +574,9 @@ public void addDeviceNameScanFilter(String deviceName) { public void setScanServiceUuidFilters(List uuidFilters) { if (peripheralScanner == null) { - Timber.w("You are trying to set service uuid filters on the scanner, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to set service uuid filters on the scanner, but the scanner isn't set-up," + + " did you call FitbitGatt#initializeScanner?"); return; } peripheralScanner.setServiceUuidFilters(uuidFilters); @@ -573,7 +593,9 @@ public void setScanServiceUuidFilters(List uuidFilters) { @SuppressWarnings({"unused", "WeakerAccess"}) // API Method public void addScanServiceUUIDWithMaskFilter(ParcelUuid service, ParcelUuid mask) { if (peripheralScanner == null) { - Timber.w("You are trying to set service uuid with mask filters on the scanner, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to set service uuid with mask filters on the scanner, but the scanner" + + " isn't set-up, did you call FitbitGatt#initializeScanner?"); return; } peripheralScanner.addServiceUUIDWithMask(service, mask); @@ -590,7 +612,9 @@ public void addScanServiceUUIDWithMaskFilter(ParcelUuid service, ParcelUuid mask @SuppressWarnings({"unused", "WeakerAccess"}) // API Method public void addFilterUsingServiceData(ParcelUuid serviceUUID, byte[] serviceData, byte[] serviceDataMask) { if (peripheralScanner == null) { - Timber.w("You are trying to add a filter using service data to the scanner, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to add a filter using service data to the scanner, but the scanner isn't" + + " set-up, did you call FitbitGatt#initializeScanner?"); return; } peripheralScanner.addFilterUsingServiceData(serviceUUID, serviceData, serviceDataMask); @@ -606,7 +630,9 @@ public void addFilterUsingServiceData(ParcelUuid serviceUUID, byte[] serviceData @SuppressWarnings({"unused", "WeakerAccess"}) // API Method public void addScanRssiFilter(int minRssi) { if (peripheralScanner == null) { - Timber.w("You are trying to set rssi filters on the scanner, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to set rssi filters on the scanner, but the scanner isn't set-up, did you" + + " call FitbitGatt#initializeScanner?"); return; } peripheralScanner.addRssiFilter(minRssi); @@ -625,7 +651,9 @@ public void addScanRssiFilter(int minRssi) { @SuppressWarnings("WeakerAccess") // API Method public void addDeviceAddressFilter(String deviceAddress) { if (peripheralScanner == null) { - Timber.w("You are trying to add a device address filter onto the scanner, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to add a device address filter onto the scanner, but the scanner isn't" + + " set-up, did you call FitbitGatt#initializeScanner?"); return; } peripheralScanner.addDeviceAddressFilter(deviceAddress); @@ -639,7 +667,9 @@ public void addDeviceAddressFilter(String deviceAddress) { @SuppressWarnings("WeakerAccess") // API Method public List getScanFilters() { if (peripheralScanner == null) { - Timber.w("You are trying to get scan filters, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to get scan filters, but the scanner isn't set-up, did you call" + + " FitbitGatt#initializeScanner?"); return Collections.emptyList(); } return peripheralScanner.getScanFilters(); @@ -651,7 +681,9 @@ public List getScanFilters() { @SuppressWarnings("WeakerAccess") // API Method public void resetScanFilters() { if (peripheralScanner == null) { - Timber.w("You are trying to reset the scan filters on the scanner, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to reset the scan filters on the scanner, but the scanner isn't set-up," + + " did you call FitbitGatt#initializeScanner?"); return; } peripheralScanner.resetFilters(); @@ -664,7 +696,9 @@ public void resetScanFilters() { */ public boolean isScanning() { if (peripheralScanner == null) { - Timber.w("You are trying to determine the scan state, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to determine the scan state, but the scanner isn't set-up, did you call" + + " FitbitGatt#initializeScanner?"); return false; } return peripheralScanner.isScanning(); @@ -679,7 +713,9 @@ public boolean isScanning() { // API Method public boolean isPendingIntentScanning() { if (peripheralScanner == null) { - Timber.w("You are trying to determine the scan state, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to determine the scan state, but the scanner isn't set-up, did you call" + + " FitbitGatt#initializeScanner?"); return false; } return peripheralScanner.isPendingIntentScanning(); @@ -694,7 +730,9 @@ public boolean isPendingIntentScanning() { // API Method public boolean isPeriodicalScanEnabled() { if (peripheralScanner == null) { - Timber.w("You are trying to determine the scan state, but the scanner isn't set-up, did you call FitbitGatt#initializeScanner?"); + Timber.w( + "You are trying to determine the scan state, but the scanner isn't set-up, did you call" + + " FitbitGatt#initializeScanner?"); return false; } return peripheralScanner.isPeriodicalScanEnabled(); @@ -821,7 +859,9 @@ void addConnectedDeviceToConnectionMap(Context context, FitbitBluetoothDevice de BluetoothAdapter adapter = dependencyProvider.getBluetoothUtils().getBluetoothAdapter(context); if (adapter != null) { if (null == connectionMap.get(device)) { - Timber.v("Adding connected device named %s, with address %s", device.getName(), device.getAddress()); + Timber.v( + "Adding connected device named %s, with address %s", + device.getName(), device.getAddress()); if (context != null) { GattConnection conn = new GattConnection(device, context.getMainLooper()); conn.setState(GattState.CONNECTED); @@ -902,25 +942,26 @@ public void setScanSettings(ScanSettings scanSettings) { @NonNull @VisibleForTesting OpenGattServerCallback getOpenGattServerCallback(@Nullable List services) { - return started -> { - - if (!started) { - Timber.w("Could not get an instance of a gatt server, if you keep trying without fixing the issue, you might end up with too many server_if"); - notifyGattStartServerException(new MissingGattServerErrorException()); - return; - } - if (services != null) { - Timber.v("Starting to add services, will set to started after complete"); - // usually the android stack will add the service setup to the bt stack, if this stack - // is busy, this can take a while, so we'll need to wait until we get the callbacks - // for all of the expected services. - if (!services.isEmpty()) { - servicesToAdd.clear(); - servicesToAdd.addAll(services); - addServicesToGattServerOnStart(); - } - } - }; + return started -> { + if (!started) { + Timber.w( + "Could not get an instance of a gatt server, if you keep trying without fixing the" + + " issue, you might end up with too many server_if"); + notifyGattStartServerException(new MissingGattServerErrorException()); + return; + } + if (services != null) { + Timber.v("Starting to add services, will set to started after complete"); + // usually the android stack will add the service setup to the bt stack, if this stack + // is busy, this can take a while, so we'll need to wait until we get the callbacks + // for all of the expected services. + if (!services.isEmpty()) { + servicesToAdd.clear(); + servicesToAdd.addAll(services); + addServicesToGattServerOnStart(); + } + } + }; } private synchronized void initialize(Context context) { @@ -930,7 +971,9 @@ private synchronized void initialize(Context context) { peripheralScanner = dependencyProvider.getNewPeripheralScanner(this, this); connectionCleanup = new Handler(context.getMainLooper()); - Timber.v("Initializing the always connected scanner for one device, and that it should stop scanning when it finds one, if you wish to change this, please configure it."); + Timber.v( + "Initializing the always connected scanner for one device, and that it should stop" + + " scanning when it finds one, if you wish to change this, please configure it."); if (radioStatusListener == null) { radioStatusListener = dependencyProvider.getNewBluetoothRadioStatusListener(this.appContext, false); radioStatusListener.startListening(); @@ -1187,7 +1230,7 @@ void connectToScannedDevice(FitbitBluetoothDevice fitDevice, boolean shouldMock, GattConnection conn = connectionMap.get(fitDevice); if (conn == null) { if (appContext == null) { - Timber.w("[%s] Bitgatt client must not be started, please start bitgatt client", fitDevice); + Timber.w("[%s] Bitgatt client must not be started, please start bitgatt client", fitDevice); return; } conn = new GattConnection(fitDevice, appContext.getMainLooper()); @@ -1239,7 +1282,7 @@ private void decrementAndInvalidateClosedConnections() { @VisibleForTesting void doDecrementAndInvalidateClosedConnections() { if (this.appContext == null) { - Timber.w("[%s] Bitgatt must not be started, please start bitgatt client.", Build.DEVICE); + Timber.w("[%s] Bitgatt must not be started, please start bitgatt client.", Build.DEVICE); return; } addConnectedDevices(); @@ -1257,7 +1300,7 @@ void doDecrementAndInvalidateClosedConnections() { GattConnection connection = getConnectionMap().remove(fitbitBluetoothDevice); if (connection != null) { notifyListenersOfConnectionDisconnected(connection); - Timber.v("Connection for %s is disconnected and pruned", connection.getDevice()); + Timber.v("Connection for %s is disconnected and pruned", connection.getDevice()); } } else { conn.setDisconnectedTTL(currentTtl - CLEANUP_INTERVAL); @@ -1291,7 +1334,10 @@ synchronized void addScannedDevice(FitbitBluetoothDevice device) { ScanRecord previousScanRecord = oldDevice.getScanRecord(); int previousRssi = oldDevice.getRssi(); if (!previousDeviceName.equals(device.getName())) { - Timber.w("This device has the same mac (bluetooth ID) as a known device, but has changed it's BT name, IRL be careful this can break upstream logic, or have security implications."); + Timber.w( + "This device has the same mac (bluetooth ID) as a known device, but has changed it's BT" + + " name, IRL be careful this can break upstream logic, or have security" + + " implications."); } oldDevice.origin = FitbitBluetoothDevice.DeviceOrigin.SCANNED; if (!previousDeviceName.equals(device.getName()) || @@ -1410,7 +1456,7 @@ GattConnection getConnectionForBluetoothAddress(Context context, String bluetoot BluetoothDevice bluetoothDevice = adp.getRemoteDevice(bluetoothAddress); return getConnection(bluetoothDevice); } else { - Timber.e("Couldn't fetch the connection because we couldn't initialize the adapter"); + Timber.e("Couldn't fetch the connection because we couldn't initialize the adapter"); return null; } } else { @@ -1451,40 +1497,45 @@ Runnable tryAndStartGattServer(Context context, OpenGattServerCallback callback, @VisibleForTesting Runnable tryAndStartGattServer(Context context, OpenGattServerCallback callback, BluetoothManagerFacade manager, GattServerCallback serverCallback) { - return () -> { - synchronized (FitbitGatt.this) { - //may have been started already in another thread in parallel trough another post - //We observed this behaviour inside the FitbitGattTest instrumentation test - //when trying to start the gatt server multiple times - Timber.tag("FitbitGattServer").d("Trying to start the gatt server"); - if (gattServer != null) { - gattServer.close(); - } - for (int openServerRetryCount = 0; openServerRetryCount < OPEN_GATT_SERVER_RETRY_COUNT; openServerRetryCount++) { - gattServer = manager.openGattServer(context, serverCallback); - if (gattServer != null) { - if(gattServer.getServices().size() != 0) { - Timber.w("We have services on a fresh gatt server instance"); - gattServer.clearServices(); - } - if (serverConnection != null) { - // We have a new server instance we need to replace it in the GattServerConnection - serverConnection.close(); - serverConnection.resetState(); - } - setGattServerConnection(new GattServerConnection(gattServer, context.getMainLooper())); - serverConnection.resetState(); - callback.onGattServerStatus(true); - isGattServerStarting.set(false); - Timber.tag("FitbitGattServer").v("Gatt server successfully opened"); - return; - } - } - isGattServerStarting.set(false); - Timber.tag("FitbitGattServer").w("Exhausted retries to open gatt server, recommend that you tell your user to clear bluetooth share in the apps list, the GATT db is probably corrupt"); - callback.onGattServerStatus(false); + return () -> { + synchronized (FitbitGatt.this) { + // may have been started already in another thread in parallel trough another post + // We observed this behaviour inside the FitbitGattTest instrumentation test + // when trying to start the gatt server multiple times + Timber.tag("FitbitGattServer").d("Trying to start the gatt server"); + if (gattServer != null) { + gattServer.close(); + } + for (int openServerRetryCount = 0; + openServerRetryCount < OPEN_GATT_SERVER_RETRY_COUNT; + openServerRetryCount++) { + gattServer = manager.openGattServer(context, serverCallback); + if (gattServer != null) { + if (gattServer.getServices().size() != 0) { + Timber.w("We have services on a fresh gatt server instance"); + gattServer.clearServices(); } - }; + if (serverConnection != null) { + // We have a new server instance we need to replace it in the GattServerConnection + serverConnection.close(); + serverConnection.resetState(); + } + setGattServerConnection(new GattServerConnection(gattServer, context.getMainLooper())); + serverConnection.resetState(); + callback.onGattServerStatus(true); + isGattServerStarting.set(false); + Timber.tag("FitbitGattServer").v("Gatt server successfully opened"); + return; + } + } + isGattServerStarting.set(false); + Timber.tag("FitbitGattServer") + .w( + "Exhausted retries to open gatt server, recommend that you tell your user to clear" + + " bluetooth share in the apps list, the GATT db is probably corrupt"); + callback.onGattServerStatus(false); + } + }; } @@ -1545,13 +1596,13 @@ public synchronized void addBackgroundScannedDeviceConnection(@Nullable ScanResu @SuppressWarnings({"WeakerAccess", "unused"}) // API Method public PendingIntent startBackgroundScan(@NonNull Context context, @NonNull Intent broadcastIntent, @NonNull List macAddresses) { if (alwaysConnectedScanner.isAlwaysConnectedScannerEnabled()) { - Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); + Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); return null; } if (isInitialized() && peripheralScanner != null) { return peripheralScanner.startBackgroundScan(macAddresses, broadcastIntent, context); } else { - Timber.w("The FitbitGatt must have been started in order to use the background scanner."); + Timber.w("The FitbitGatt must have been started in order to use the background scanner."); return null; } } @@ -1581,7 +1632,7 @@ public PendingIntent startBackgroundScan(@NonNull Context context, @NonNull Inte */ public boolean startSystemManagedPendingIntentScan(@NonNull Context context, @NonNull List scanFilters) { if (alwaysConnectedScanner.isAlwaysConnectedScannerEnabled()) { - Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); + Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); return false; } if (isInitialized() && peripheralScanner != null) { @@ -1597,14 +1648,16 @@ public boolean startSystemManagedPendingIntentScan(@NonNull Context context, @No */ public void stopSystemManagedPendingIntentScan() { if (alwaysConnectedScanner.isAlwaysConnectedScannerEnabled()) { - Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); + Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); return; } if (isInitialized() && peripheralScanner != null) { try { peripheralScanner.cancelPendingIntentBasedBackgroundScan(); } catch (NoSuchMethodError error) { - Timber.i(error, "There was a no such method error stopping the pending intent scan, assuming stopped."); + Timber.i( + error, + "There was a no such method error stopping the pending intent scan, assuming stopped."); } } else { Timber.i("Can't stop because we aren't started, or the scanner is null"); @@ -1619,7 +1672,7 @@ public void stopSystemManagedPendingIntentScan() { @SuppressWarnings({"unused", "WeakerAccess"}) // API Method public void stopBackgroundScan(@Nullable PendingIntent pendingIntent) { if (alwaysConnectedScanner.isAlwaysConnectedScannerEnabled()) { - Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); + Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); return; } if (pendingIntent == null) { @@ -1628,7 +1681,8 @@ public void stopBackgroundScan(@Nullable PendingIntent pendingIntent) { if (peripheralScanner != null) { peripheralScanner.stopBackgroundScan(pendingIntent); } else { - Timber.w("Peripheral scanner was null, did you forget to call FitbitGatt#initializeScanner?"); + Timber.w( + "Peripheral scanner was null, did you forget to call FitbitGatt#initializeScanner?"); } } } @@ -1642,7 +1696,7 @@ public void stopBackgroundScan(@Nullable PendingIntent pendingIntent) { @SuppressWarnings({"unused", "WeakerAccess"}) // API Method public void stopBackgroundScanWithRegularIntent(Context context, @Nullable Intent regularIntent) { if (alwaysConnectedScanner.isAlwaysConnectedScannerEnabled()) { - Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); + Timber.i("You are using the always connected scanner, stop it first before ad-hoc scanning"); return; } if (regularIntent == null) { @@ -1652,19 +1706,24 @@ public void stopBackgroundScanWithRegularIntent(Context context, @Nullable Inten try { pending = dependencyProvider.getNewScanPendingIntent(context, regularIntent); } catch (NoSuchMethodError error) { - Timber.i(error, "There was a no such method error stopping the pending intent scan, assuming stopped"); + Timber.i( + error, + "There was a no such method error stopping the pending intent scan, assuming stopped"); return; } if (peripheralScanner != null && pending != null) { peripheralScanner.stopBackgroundScan(pending); } else { - Timber.w("Peripheral scanner was null, did you forget to call FitbitGatt#initializeScanner?"); + Timber.w( + "Peripheral scanner was null, did you forget to call FitbitGatt#initializeScanner?"); } } } - @Nullable - public GattServerConnection getServer() { + // TODO: Temporarily disabling changes that break MFA in G3, nullability annotation can be added + // in next sync + @Nullable + public GattServerConnection getServer() { return serverConnection; } @@ -1876,7 +1935,8 @@ public void bluetoothOn() { * */ if (!isInitialized() || this.appContext == null) { - Timber.e("Refreshing the gatt server after BT was enabled failed. Bitgatt has not been started"); + Timber.e( + "Refreshing the gatt server after BT was enabled failed. Bitgatt has not been started"); return; } if (isGattServerStarted.get()) { @@ -1893,26 +1953,26 @@ public void bluetoothOn() { @NonNull @VisibleForTesting OpenGattServerCallback getOpenGattServerCallbackOnBluetoothOn() { - return started -> { - if (started) { - Timber.v("Gatt server up and ready"); - } else { - Timber.w("After several attempts the gatt server could not be re-opened, tread lightly"); - } - if (servicesToAdd != null && !servicesToAdd.isEmpty()) { - addServicesToGattServerOnStart(); - } - Timber.v("Bluetooth is on"); - }; + return started -> { + if (started) { + Timber.v("Gatt server up and ready"); + } else { + Timber.w("After several attempts the gatt server could not be re-opened, tread lightly"); + } + if (servicesToAdd != null && !servicesToAdd.isEmpty()) { + addServicesToGattServerOnStart(); + } + Timber.v("Bluetooth is on"); + }; } @Override public void bluetoothTurningOff() { isBluetoothOn = false; - // let's try to clean up the gatt server on devices that are likely to duplicate or host - // no services after add on startup due to queueing issues, almost all Samsung devices - // seem to behave in this way - AndroidDevice strategyDevice = new AndroidDevice.Builder().manufacturerName("Samsung").build(); + // let's try to clean up the gatt server on devices that are likely to duplicate or host + // no services after add on startup due to queueing issues, almost all Samsung devices + // seem to behave in this way + AndroidDevice strategyDevice = new AndroidDevice.Builder().manufacturerName("Samsung").build(); Strategy executableStrategy = new StrategyProvider() .getStrategyForPhoneAndGattConnection(strategyDevice, null, @@ -1961,3 +2021,4 @@ public void setSlowLoggingEnabled(boolean newValue) { slowLoggingEnabled = newValue; } } +