From 0d59132c47db2cbaf4fd04c4857ef67984d8bd51 Mon Sep 17 00:00:00 2001 From: Dariusz Seweryn Date: Thu, 3 Aug 2017 11:38:09 +0200 Subject: [PATCH] Thread calling the Native API changed from main to background. (#255 #41) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Initially when working with the Android Bluetooth API (18 / Android 4.3) it was found that specific implementations (Samsung’s) cannot work correctly if called directly in callbacks from other calls. To mitigate the problem the next interaction was routed to Android main thread. Now when investigating the issue it turned out that it may be any other thread as long as it is not the callback thread. --- rxandroidble/build.gradle | 1 - .../polidea/rxandroidble/ClientComponent.java | 59 +++++++++++++------ .../polidea/rxandroidble/RxBleClientImpl.java | 17 +++--- .../RxBleRadioOperationCustom.java | 2 - .../connection/RxBleConnectionImpl.java | 5 +- .../connection/RxBleGattCallback.java | 2 +- .../operations/OperationsProviderImpl.java | 8 +-- ...RadioOperationCharacteristicLongWrite.java | 8 +-- .../RxBleRadioOperationDisconnect.java | 57 ++++++++---------- .../internal/radio/RxBleRadioImpl.java | 3 +- .../rxandroidble/RxBleClientTest.groovy | 5 +- .../connection/RxBleConnectionTest.groovy | 2 + .../RxBleRadioOperationDisconnectTest.groovy | 23 -------- 13 files changed, 93 insertions(+), 99 deletions(-) diff --git a/rxandroidble/build.gradle b/rxandroidble/build.gradle index 96b8595e6..404ae754b 100644 --- a/rxandroidble/build.gradle +++ b/rxandroidble/build.gradle @@ -46,7 +46,6 @@ android { dependencies { compile rootProject.ext.libs.rxjava - compile rootProject.ext.libs.rxandroid compile rootProject.ext.libs.rxrelay compile rootProject.ext.libs.support_annotations compile rootProject.ext.libs.dagger diff --git a/rxandroidble/src/main/java/com/polidea/rxandroidble/ClientComponent.java b/rxandroidble/src/main/java/com/polidea/rxandroidble/ClientComponent.java index 6aedac3a3..65aac7e66 100644 --- a/rxandroidble/src/main/java/com/polidea/rxandroidble/ClientComponent.java +++ b/rxandroidble/src/main/java/com/polidea/rxandroidble/ClientComponent.java @@ -9,6 +9,7 @@ import android.location.LocationManager; import android.os.Build; import android.support.annotation.Nullable; +import android.support.annotation.RestrictTo; import com.polidea.rxandroidble.helpers.LocationServicesOkObservable; import com.polidea.rxandroidble.internal.DeviceComponent; import com.polidea.rxandroidble.internal.scan.InternalToExternalScanResultConverter; @@ -33,7 +34,6 @@ import javax.inject.Provider; import rx.Observable; import rx.Scheduler; -import rx.android.schedulers.AndroidSchedulers; import rx.functions.Func1; import rx.schedulers.Schedulers; @@ -43,11 +43,10 @@ public interface ClientComponent { class NamedSchedulers { - public static final String MAIN_THREAD = "main-thread"; public static final String COMPUTATION = "computation"; - public static final String RADIO_OPERATIONS = "callback-emitter"; public static final String TIMEOUT = "timeout"; - public static final String GATT_CALLBACK = "callback"; + public static final String BLUETOOTH_INTERACTION = "bluetooth_interaction"; + public static final String BLUETOOTH_CALLBACKS = "bluetooth_callbacks"; private NamedSchedulers() { } @@ -119,28 +118,50 @@ static int provideDeviceSdk() { } @Provides - @Named(NamedSchedulers.GATT_CALLBACK) + @Named(NamedSchedulers.BLUETOOTH_INTERACTION) @ClientScope - static ExecutorService provideGattCallbackExecutorService() { + static ExecutorService provideBluetoothInteractionExecutorService() { return Executors.newSingleThreadExecutor(); } @Provides - @Named(NamedSchedulers.GATT_CALLBACK) + @Named(NamedSchedulers.BLUETOOTH_CALLBACKS) @ClientScope - static Scheduler provideGattCallbackScheduler(@Named(NamedSchedulers.GATT_CALLBACK) ExecutorService executorService) { - return Schedulers.from(executorService); + static ExecutorService provideBluetoothCallbacksExecutorService() { + return Executors.newSingleThreadExecutor(); } @Provides - LocationManager provideLocationManager() { - return (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); + @Named(NamedSchedulers.BLUETOOTH_INTERACTION) + @ClientScope + static Scheduler provideBluetoothInteractionScheduler(@Named(NamedSchedulers.BLUETOOTH_INTERACTION) ExecutorService service) { + return Schedulers.from(service); + } + + @Provides + @Named(NamedSchedulers.BLUETOOTH_CALLBACKS) + @ClientScope + static Scheduler provideBluetoothCallbacksScheduler(@Named(NamedSchedulers.BLUETOOTH_CALLBACKS) ExecutorService service) { + return Schedulers.from(service); } @Provides - @Named(NamedSchedulers.MAIN_THREAD) - static Scheduler provideMainThreadScheduler() { - return AndroidSchedulers.mainThread(); + static ClientComponentFinalizer provideFinalizationCloseable( + @Named(NamedSchedulers.BLUETOOTH_INTERACTION) final ExecutorService interactionExecutorService, + @Named(NamedSchedulers.BLUETOOTH_CALLBACKS) final ExecutorService callbacksExecutorService + ) { + return new ClientComponentFinalizer() { + @Override + public void onFinalize() { + interactionExecutorService.shutdown(); + callbacksExecutorService.shutdown(); + } + }; + } + + @Provides + LocationManager provideLocationManager() { + return (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); } @Provides @@ -227,10 +248,6 @@ abstract class ClientModuleBinder { @ClientScope abstract RxBleRadio bindRxBleRadio(RxBleRadioImpl rxBleRadio); - @Binds - @Named(NamedSchedulers.RADIO_OPERATIONS) - abstract Scheduler bindCallbackScheduler(@Named(NamedSchedulers.MAIN_THREAD) Scheduler mainThreadScheduler); - @Binds @Named(NamedSchedulers.TIMEOUT) abstract Scheduler bindTimeoutScheduler(@Named(NamedSchedulers.COMPUTATION) Scheduler computationScheduler); @@ -242,4 +259,10 @@ abstract class ClientModuleBinder { LocationServicesOkObservable locationServicesOkObservable(); RxBleClient rxBleClient(); + + @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) + interface ClientComponentFinalizer { + + void onFinalize(); + } } diff --git a/rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleClientImpl.java b/rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleClientImpl.java index ee23612a3..69c04879b 100644 --- a/rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleClientImpl.java +++ b/rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleClientImpl.java @@ -31,7 +31,6 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -import java.util.concurrent.ExecutorService; import javax.inject.Inject; import javax.inject.Named; @@ -50,8 +49,8 @@ class RxBleClientImpl extends RxBleClient { private final ScanSetupBuilder scanSetupBuilder; private final ScanPreconditionsVerifier scanPreconditionVerifier; private final Func1 internalToExternalScanResultMapFunction; - private final ExecutorService executorService; - private final Scheduler mainThreadScheduler; + private final ClientComponent.ClientComponentFinalizer clientComponentFinalizer; + private final Scheduler bluetoothInteractionScheduler; private final Map, Observable> queuedScanOperations = new HashMap<>(); private final RxBleAdapterWrapper rxBleAdapterWrapper; private final Observable rxBleAdapterStateObservable; @@ -69,8 +68,8 @@ class RxBleClientImpl extends RxBleClient { ScanSetupBuilder scanSetupBuilder, ScanPreconditionsVerifier scanPreconditionVerifier, Func1 internalToExternalScanResultMapFunction, - @Named(ClientComponent.NamedSchedulers.GATT_CALLBACK) ExecutorService executorService, - @Named(ClientComponent.NamedSchedulers.MAIN_THREAD) Scheduler mainThreadScheduler) { + @Named(ClientComponent.NamedSchedulers.BLUETOOTH_INTERACTION) Scheduler bluetoothInteractionScheduler, + ClientComponent.ClientComponentFinalizer clientComponentFinalizer) { this.uuidUtil = uuidUtil; this.rxBleRadio = rxBleRadio; this.rxBleAdapterWrapper = rxBleAdapterWrapper; @@ -81,14 +80,14 @@ class RxBleClientImpl extends RxBleClient { this.scanSetupBuilder = scanSetupBuilder; this.scanPreconditionVerifier = scanPreconditionVerifier; this.internalToExternalScanResultMapFunction = internalToExternalScanResultMapFunction; - this.executorService = executorService; - this.mainThreadScheduler = mainThreadScheduler; + this.bluetoothInteractionScheduler = bluetoothInteractionScheduler; + this.clientComponentFinalizer = clientComponentFinalizer; } @Override protected void finalize() throws Throwable { + clientComponentFinalizer.onFinalize(); super.finalize(); - executorService.shutdown(); } @Override @@ -118,7 +117,7 @@ public Observable call() { final ScanSetup scanSetup = scanSetupBuilder.build(scanSettings, scanFilters); final Operation scanOperation = scanSetup.scanOperation; return rxBleRadio.queue(scanOperation) - .unsubscribeOn(mainThreadScheduler) + .unsubscribeOn(bluetoothInteractionScheduler) .compose(scanSetup.scanOperationBehaviourEmulatorTransformer) .map(internalToExternalScanResultMapFunction) .mergeWith(RxBleClientImpl.this.bluetoothAdapterOffExceptionObservable()); diff --git a/rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleRadioOperationCustom.java b/rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleRadioOperationCustom.java index 03c2e5f8c..46a99638f 100644 --- a/rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleRadioOperationCustom.java +++ b/rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleRadioOperationCustom.java @@ -9,7 +9,6 @@ import rx.Observable; import rx.Observer; import rx.Scheduler; -import rx.android.schedulers.AndroidSchedulers; /** * Represents a custom operation that will be enqueued for future execution within the client instance. @@ -41,7 +40,6 @@ public interface RxBleRadioOperationCustom { * @param bluetoothGatt The Android API GATT instance * @param rxBleGattCallback The internal Rx ready bluetooth gatt callback to be notified of GATT operations * @param scheduler The RxBleRadio scheduler used to asObservable operation - * (currently {@link AndroidSchedulers#mainThread()} * @throws Throwable Any exception that your custom operation might throw */ @NonNull diff --git a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/connection/RxBleConnectionImpl.java b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/connection/RxBleConnectionImpl.java index 733686fae..ac4802572 100644 --- a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/connection/RxBleConnectionImpl.java +++ b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/connection/RxBleConnectionImpl.java @@ -70,8 +70,9 @@ public RxBleConnectionImpl( DescriptorWriter descriptorWriter, OperationsProvider operationProvider, Provider longWriteOperationBuilderProvider, - @Named(ClientComponent.NamedSchedulers.RADIO_OPERATIONS) Scheduler callbackScheduler, - IllegalOperationChecker illegalOperationChecker) { + @Named(ClientComponent.NamedSchedulers.BLUETOOTH_INTERACTION) Scheduler callbackScheduler, + IllegalOperationChecker illegalOperationChecker + ) { this.rxBleRadio = rxBleRadio; this.gattCallback = gattCallback; this.bluetoothGatt = bluetoothGatt; diff --git a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/connection/RxBleGattCallback.java b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/connection/RxBleGattCallback.java index a1023c6e1..f9d39cab0 100644 --- a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/connection/RxBleGattCallback.java +++ b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/connection/RxBleGattCallback.java @@ -69,7 +69,7 @@ public Object call(Pair bluetoothGattRxBleC .autoConnect(0); @Inject - public RxBleGattCallback(@Named(ClientComponent.NamedSchedulers.GATT_CALLBACK) Scheduler callbackScheduler, + public RxBleGattCallback(@Named(ClientComponent.NamedSchedulers.BLUETOOTH_CALLBACKS) Scheduler callbackScheduler, BluetoothGattProvider bluetoothGattProvider, NativeCallbackDispatcher nativeCallbackDispatcher) { this.callbackScheduler = callbackScheduler; diff --git a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/operations/OperationsProviderImpl.java b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/operations/OperationsProviderImpl.java index 13b1d620b..f3b22bff9 100644 --- a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/operations/OperationsProviderImpl.java +++ b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/operations/OperationsProviderImpl.java @@ -25,7 +25,7 @@ public class OperationsProviderImpl implements OperationsProvider { private final RxBleGattCallback rxBleGattCallback; private final BluetoothGatt bluetoothGatt; private final TimeoutConfiguration timeoutConfiguration; - private final Scheduler mainThreadScheduler; + private final Scheduler bluetoothInteractionScheduler; private final Scheduler timeoutScheduler; private final Provider rssiReadOperationProvider; @@ -34,13 +34,13 @@ public class OperationsProviderImpl implements OperationsProvider { RxBleGattCallback rxBleGattCallback, BluetoothGatt bluetoothGatt, @Named(DeviceModule.OPERATION_TIMEOUT) TimeoutConfiguration timeoutConfiguration, - @Named(ClientComponent.NamedSchedulers.MAIN_THREAD) Scheduler mainThreadScheduler, + @Named(ClientComponent.NamedSchedulers.BLUETOOTH_INTERACTION) Scheduler bluetoothInteractionScheduler, @Named(ClientComponent.NamedSchedulers.TIMEOUT) Scheduler timeoutScheduler, Provider rssiReadOperationProvider) { this.rxBleGattCallback = rxBleGattCallback; this.bluetoothGatt = bluetoothGatt; this.timeoutConfiguration = timeoutConfiguration; - this.mainThreadScheduler = mainThreadScheduler; + this.bluetoothInteractionScheduler = bluetoothInteractionScheduler; this.timeoutScheduler = timeoutScheduler; this.rssiReadOperationProvider = rssiReadOperationProvider; } @@ -54,7 +54,7 @@ public RxBleRadioOperationCharacteristicLongWrite provideLongWriteOperation( return new RxBleRadioOperationCharacteristicLongWrite(bluetoothGatt, rxBleGattCallback, - mainThreadScheduler, + bluetoothInteractionScheduler, timeoutConfiguration, bluetoothGattCharacteristic, maxBatchSizeProvider, diff --git a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/operations/RxBleRadioOperationCharacteristicLongWrite.java b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/operations/RxBleRadioOperationCharacteristicLongWrite.java index 6ca9138e3..384eaf060 100644 --- a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/operations/RxBleRadioOperationCharacteristicLongWrite.java +++ b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/operations/RxBleRadioOperationCharacteristicLongWrite.java @@ -38,7 +38,7 @@ public class RxBleRadioOperationCharacteristicLongWrite extends RxBleRadioOperat private final BluetoothGatt bluetoothGatt; private final RxBleGattCallback rxBleGattCallback; - private final Scheduler mainThreadScheduler; + private final Scheduler bluetoothInteractionScheduler; private final TimeoutConfiguration timeoutConfiguration; private final BluetoothGattCharacteristic bluetoothGattCharacteristic; private final PayloadSizeLimitProvider batchSizeProvider; @@ -49,7 +49,7 @@ public class RxBleRadioOperationCharacteristicLongWrite extends RxBleRadioOperat RxBleRadioOperationCharacteristicLongWrite( BluetoothGatt bluetoothGatt, RxBleGattCallback rxBleGattCallback, - @Named(ClientComponent.NamedSchedulers.MAIN_THREAD) Scheduler mainThreadScheduler, + @Named(ClientComponent.NamedSchedulers.BLUETOOTH_INTERACTION) Scheduler bluetoothInteractionScheduler, @Named(DeviceModule.OPERATION_TIMEOUT) TimeoutConfiguration timeoutConfiguration, BluetoothGattCharacteristic bluetoothGattCharacteristic, PayloadSizeLimitProvider batchSizeProvider, @@ -57,7 +57,7 @@ public class RxBleRadioOperationCharacteristicLongWrite extends RxBleRadioOperat byte[] bytesToWrite) { this.bluetoothGatt = bluetoothGatt; this.rxBleGattCallback = rxBleGattCallback; - this.mainThreadScheduler = mainThreadScheduler; + this.bluetoothInteractionScheduler = bluetoothInteractionScheduler; this.timeoutConfiguration = timeoutConfiguration; this.bluetoothGattCharacteristic = bluetoothGattCharacteristic; this.batchSizeProvider = batchSizeProvider; @@ -79,7 +79,7 @@ protected void protectedRun(final Emitter emitter, final RadioReleaseInt final RadioReleasingEmitterWrapper emitterWrapper = new RadioReleasingEmitterWrapper<>(emitter, radioReleaseInterface); writeBatchAndObserve(batchSize, byteBuffer) - .subscribeOn(mainThreadScheduler) + .subscribeOn(bluetoothInteractionScheduler) .takeFirst(writeResponseForMatchingCharacteristic(bluetoothGattCharacteristic)) .timeout( timeoutConfiguration.timeout, diff --git a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/operations/RxBleRadioOperationDisconnect.java b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/operations/RxBleRadioOperationDisconnect.java index c853c8b76..30795bc10 100644 --- a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/operations/RxBleRadioOperationDisconnect.java +++ b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/operations/RxBleRadioOperationDisconnect.java @@ -22,10 +22,10 @@ import rx.Emitter; import rx.Observable; +import rx.Observer; import rx.Scheduler; import rx.Subscriber; import rx.functions.Action0; -import rx.functions.Action1; import rx.functions.Func1; import static com.polidea.rxandroidble.RxBleConnection.RxBleConnectionState.DISCONNECTED; @@ -38,7 +38,7 @@ public class RxBleRadioOperationDisconnect extends RxBleRadioOperation { private final BluetoothGattProvider bluetoothGattProvider; private final String macAddress; private final BluetoothManager bluetoothManager; - private final Scheduler mainThreadScheduler; + private final Scheduler bluetoothInteractionScheduler; private final TimeoutConfiguration timeoutConfiguration; private final ConnectionStateChangeListener connectionStateChangeListener; @@ -48,14 +48,14 @@ public class RxBleRadioOperationDisconnect extends RxBleRadioOperation { BluetoothGattProvider bluetoothGattProvider, @Named(DeviceModule.MAC_ADDRESS) String macAddress, BluetoothManager bluetoothManager, - @Named(ClientComponent.NamedSchedulers.MAIN_THREAD) Scheduler mainThreadScheduler, + @Named(ClientComponent.NamedSchedulers.BLUETOOTH_INTERACTION) Scheduler bluetoothInteractionScheduler, @Named(DeviceModule.DISCONNECT_TIMEOUT) TimeoutConfiguration timeoutConfiguration, ConnectionStateChangeListener connectionStateChangeListener) { this.rxBleGattCallback = rxBleGattCallback; this.bluetoothGattProvider = bluetoothGattProvider; this.macAddress = macAddress; this.bluetoothManager = bluetoothManager; - this.mainThreadScheduler = mainThreadScheduler; + this.bluetoothInteractionScheduler = bluetoothInteractionScheduler; this.timeoutConfiguration = timeoutConfiguration; this.connectionStateChangeListener = connectionStateChangeListener; } @@ -71,30 +71,26 @@ protected void protectedRun(final Emitter emitter, final RadioReleaseInter emitter.onCompleted(); } else { (isDisconnected(bluetoothGatt) ? just(bluetoothGatt) : disconnect(bluetoothGatt)) - .observeOn(mainThreadScheduler) - .subscribe( - new Action1() { - @Override - public void call(BluetoothGatt bluetoothGatt) { - bluetoothGatt.close(); - } - }, - new Action1() { - @Override - public void call(Throwable throwable) { - radioReleaseInterface.release(); - emitter.onError(throwable); - } - }, - new Action0() { - @Override - public void call() { - connectionStateChangeListener.onConnectionStateChange(DISCONNECTED); - radioReleaseInterface.release(); - emitter.onCompleted(); - } - } - ); + .observeOn(bluetoothInteractionScheduler) + .subscribe(new Observer() { + @Override + public void onNext(BluetoothGatt bluetoothGatt) { + bluetoothGatt.close(); + } + + @Override + public void onError(Throwable throwable) { + radioReleaseInterface.release(); + emitter.onError(throwable); + } + + @Override + public void onCompleted() { + connectionStateChangeListener.onConnectionStateChange(DISCONNECTED); + radioReleaseInterface.release(); + emitter.onCompleted(); + } + }); } } @@ -109,7 +105,7 @@ private boolean isDisconnected(BluetoothGatt bluetoothGatt) { * 2. The same BluetoothGatt - in this situation we should probably cancel the pending BluetoothGatt.close() call */ private Observable disconnect(BluetoothGatt bluetoothGatt) { - return new DisconnectGattObservable(bluetoothGatt, rxBleGattCallback, mainThreadScheduler) + return new DisconnectGattObservable(bluetoothGatt, rxBleGattCallback, bluetoothInteractionScheduler) .timeout(timeoutConfiguration.timeout, timeoutConfiguration.timeoutTimeUnit, just(bluetoothGatt), timeoutConfiguration.timeoutScheduler); } @@ -126,13 +122,12 @@ private static class DisconnectGattObservable extends Observable public void call(Subscriber subscriber) { rxBleGattCallback .getOnConnectionStateChange() - .filter(new Func1() { + .takeFirst(new Func1() { @Override public Boolean call(RxBleConnection.RxBleConnectionState rxBleConnectionState) { return rxBleConnectionState == DISCONNECTED; } }) - .take(1) .map(new Func1() { @Override public BluetoothGatt call(RxBleConnection.RxBleConnectionState rxBleConnectionState) { diff --git a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/radio/RxBleRadioImpl.java b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/radio/RxBleRadioImpl.java index 2c8651d28..040f1dd29 100644 --- a/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/radio/RxBleRadioImpl.java +++ b/rxandroidble/src/main/java/com/polidea/rxandroidble/internal/radio/RxBleRadioImpl.java @@ -19,7 +19,7 @@ public class RxBleRadioImpl implements RxBleRadio { private OperationPriorityFifoBlockingQueue queue = new OperationPriorityFifoBlockingQueue(); @Inject - public RxBleRadioImpl(@Named(ClientComponent.NamedSchedulers.RADIO_OPERATIONS) final Scheduler callbackScheduler) { + public RxBleRadioImpl(@Named(ClientComponent.NamedSchedulers.BLUETOOTH_INTERACTION) final Scheduler callbackScheduler) { new Thread(new Runnable() { @Override public void run() { @@ -73,6 +73,7 @@ public void cancel() throws Exception { }, Emitter.BackpressureMode.NONE); } + @RestrictTo(RestrictTo.Scope.SUBCLASSES) void log(String prefix, Operation rxBleRadioOperation) { if (RxBleLog.isAtLeast(RxBleLog.DEBUG)) { diff --git a/rxandroidble/src/test/groovy/com/polidea/rxandroidble/RxBleClientTest.groovy b/rxandroidble/src/test/groovy/com/polidea/rxandroidble/RxBleClientTest.groovy index 166f90219..e768298a0 100644 --- a/rxandroidble/src/test/groovy/com/polidea/rxandroidble/RxBleClientTest.groovy +++ b/rxandroidble/src/test/groovy/com/polidea/rxandroidble/RxBleClientTest.groovy @@ -9,7 +9,6 @@ import com.polidea.rxandroidble.internal.scan.InternalToExternalScanResultConver import com.polidea.rxandroidble.internal.scan.ScanSetup import com.polidea.rxandroidble.internal.scan.ScanSetupBuilder import com.polidea.rxandroidble.scan.ScanSettings -import java.util.concurrent.Executors import static com.polidea.rxandroidble.exceptions.BleScanException.BLUETOOTH_CANNOT_START import static com.polidea.rxandroidble.exceptions.BleScanException.BLUETOOTH_DISABLED @@ -89,8 +88,8 @@ class RxBleClientTest extends Specification { mockScanSetupBuilder, mockScanPreconditionVerifier, mockMapper, - Executors.newSingleThreadExecutor(), - ImmediateScheduler.INSTANCE + ImmediateScheduler.INSTANCE, + Mock(ClientComponent.ClientComponentFinalizer) ) } diff --git a/rxandroidble/src/test/groovy/com/polidea/rxandroidble/internal/connection/RxBleConnectionTest.groovy b/rxandroidble/src/test/groovy/com/polidea/rxandroidble/internal/connection/RxBleConnectionTest.groovy index 6f906b80c..02db9554d 100644 --- a/rxandroidble/src/test/groovy/com/polidea/rxandroidble/internal/connection/RxBleConnectionTest.groovy +++ b/rxandroidble/src/test/groovy/com/polidea/rxandroidble/internal/connection/RxBleConnectionTest.groovy @@ -336,6 +336,7 @@ class RxBleConnectionTest extends Specification { def nativeCallback = Mock BluetoothGattCallback def radioOperationCustom = new RxBleRadioOperationCustom() { + @NonNull @Override Observable asObservable(BluetoothGatt bluetoothGatt, RxBleGattCallback rxBleGattCallback, @@ -357,6 +358,7 @@ class RxBleConnectionTest extends Specification { def nativeCallback = Mock BluetoothGattCallback def radioOperationCustom = new RxBleRadioOperationCustom() { + @NonNull @Override Observable asObservable(BluetoothGatt bluetoothGatt, RxBleGattCallback rxBleGattCallback, diff --git a/rxandroidble/src/test/groovy/com/polidea/rxandroidble/internal/operations/RxBleRadioOperationDisconnectTest.groovy b/rxandroidble/src/test/groovy/com/polidea/rxandroidble/internal/operations/RxBleRadioOperationDisconnectTest.groovy index 94a013fa7..c8557a928 100644 --- a/rxandroidble/src/test/groovy/com/polidea/rxandroidble/internal/operations/RxBleRadioOperationDisconnectTest.groovy +++ b/rxandroidble/src/test/groovy/com/polidea/rxandroidble/internal/operations/RxBleRadioOperationDisconnectTest.groovy @@ -19,10 +19,6 @@ import com.polidea.rxandroidble.internal.connection.ConnectionStateChangeListene import com.polidea.rxandroidble.internal.util.MockOperationTimeoutConfiguration import com.polidea.rxandroidble.internal.RadioReleaseInterface import com.polidea.rxandroidble.internal.connection.RxBleGattCallback -import rx.Scheduler -import rx.android.plugins.RxAndroidPlugins -import rx.android.plugins.RxAndroidSchedulersHook -import rx.android.schedulers.AndroidSchedulers import rx.internal.schedulers.ImmediateScheduler import rx.observers.TestSubscriber import rx.schedulers.Schedulers @@ -45,25 +41,6 @@ public class RxBleRadioOperationDisconnectTest extends Specification { BluetoothGattProvider mockBluetoothGattProvider RxBleRadioOperationDisconnect objectUnderTest - def setupSpec() { - AndroidSchedulers.reset() - RxAndroidPlugins.getInstance().reset() - RxAndroidPlugins.getInstance().registerSchedulersHook( - new RxAndroidSchedulersHook() { - - @Override - Scheduler getMainThreadScheduler() { - return Schedulers.immediate() - } - } - ) - } - - def teardownSpec() { - AndroidSchedulers.reset() - RxAndroidPlugins.getInstance().reset() - } - private def testWithGattProviderReturning(BluetoothGatt providedBluetoothGatt) { mockBluetoothGattProvider = Mock(BluetoothGattProvider) mockBluetoothGattProvider.getBluetoothGatt() >> providedBluetoothGatt