disconnect method

Future<bool> disconnect()

Implementation

Future<bool> disconnect() async {
  if (_socket == null) {
    return true;
  }
  _socketConnected = false;
  _adbConnected = false;
  _sentSignature = false;
  _tlsEnabled = false;
  _socketConnectedController.add(_socketConnected);

  await _adbMessageSubscription?.cancel();
  await _socketConnectedSubscription?.cancel();
  await _socketDataSubscription?.cancel();
  _adbMessageSubscription = null;
  _socketConnectedSubscription = null;
  _socketDataSubscription = null;

  for (var stream in openStreams.values) {
    stream.close();
  }
  openStreams.clear();

  _sendLock = null;

  try {
    await _socket!.flush();
    _socket!.destroy();
  } catch (_) {}
  _socket = null;

  return true;
}