Skip to content

Commit

Permalink
Suppress disconnect warnings before stopping the bridge
Browse files Browse the repository at this point in the history
After a refactoring, stopping the bridge triggers disconnect callbacks
synchronously.

Issue: #326
  • Loading branch information
mlopatkin committed Jan 2, 2024
1 parent f851065 commit 41b31f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ private Consumer<Throwable> adbErrorHandler() {
* Restarts ADB services (or starts one if it is not yet running).
*/
public void restartAdb() {
// Stopping ADB trigger disconnect dialogs now
deviceDisconnectedHandler.suppressDialogs();
bridge.stopAdb();
hasShownErrorMessage = false;
deviceDisconnectedHandler.suppressDialogs();
withAdbServicesInteractive(
adbServices -> deviceDisconnectedHandler.resumeDialogs(),
failure -> deviceDisconnectedHandler.resumeDialogs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
Expand All @@ -29,6 +30,7 @@
import name.mlopatkin.andlogview.base.concurrent.TestExecutor;
import name.mlopatkin.andlogview.device.AdbDeviceList;
import name.mlopatkin.andlogview.device.AdbException;
import name.mlopatkin.andlogview.liblogcat.ddmlib.DeviceDisconnectedHandler;
import name.mlopatkin.andlogview.test.ThreadTestUtils;
import name.mlopatkin.andlogview.utils.Cancellable;
import name.mlopatkin.andlogview.utils.MyFutures;
Expand Down Expand Up @@ -68,6 +70,9 @@ class AdbServicesInitializationPresenterTest {
@Mock(answer = Answers.CALLS_REAL_METHODS)
Consumer<Throwable> errorConsumer;

@Mock
DeviceDisconnectedHandler disconnectedHandler;

private AdbServicesInitializationPresenter presenter;

@BeforeEach
Expand Down Expand Up @@ -426,6 +431,16 @@ void afterCancellingProgressDialogNewRequestCanFail() {
thenErrorIsShown();
}

@Test
void stopsBridgeWithDisconnectMessagesSuppressed() {
whenRequestedAdbWith(restartRequest());

var inOrder = inOrder(mockBridge, disconnectedHandler);
inOrder.verify(disconnectedHandler).suppressDialogs();
inOrder.verify(disconnectedHandler, never()).resumeDialogs();
inOrder.verify(mockBridge).stopAdb();
}

private AdbServicesInitializationPresenter createPresenter() {
return createPresenter(MoreExecutors.directExecutor());
}
Expand All @@ -441,7 +456,7 @@ private AdbServicesInitializationPresenter createPresenter(Executor uiExecutor)
.exceptionally(MyFutures::uncaughtException);
return mock(AdbDeviceList.class);
});
return new AdbServicesInitializationPresenter(view, mockBridge, uiExecutor, mock());
return new AdbServicesInitializationPresenter(view, mockBridge, uiExecutor, disconnectedHandler);
}

private void withNewResultAfterReload() {
Expand Down

0 comments on commit 41b31f7

Please sign in to comment.