From 8b5b646fb811db5d3b16f8641907b98590f2d3ec Mon Sep 17 00:00:00 2001 From: Jeff Irion Date: Thu, 14 Nov 2019 07:45:12 -0800 Subject: [PATCH] Improve logging and managing of ADB connection --- androidtv/adb_manager.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/androidtv/adb_manager.py b/androidtv/adb_manager.py index b8539203..c708dd12 100644 --- a/androidtv/adb_manager.py +++ b/androidtv/adb_manager.py @@ -116,7 +116,7 @@ def connect(self, always_log_errors=True, auth_timeout_s=DEFAULT_AUTH_TIMEOUT_S) _LOGGER.warning("Couldn't connect to host %s. %s: %s", self.host, exc.__class__.__name__, exc.strerror) # ADB connection attempt failed - self._adb.close() + self.close() self._available = False except Exception as exc: # pylint: disable=broad-except @@ -124,7 +124,7 @@ def connect(self, always_log_errors=True, auth_timeout_s=DEFAULT_AUTH_TIMEOUT_S) _LOGGER.warning("Couldn't connect to host %s. %s: %s", self.host, exc.__class__.__name__, exc) # ADB connection attempt failed - self._adb.close() + self.close() self._available = False finally: @@ -134,6 +134,8 @@ def connect(self, always_log_errors=True, auth_timeout_s=DEFAULT_AUTH_TIMEOUT_S) self._adb_lock.release() # Lock could not be acquired + _LOGGER.warning("Couldn't connect to host %s because adb-shell lock not acquired.", self.host) + self.close() self._available = False return False @@ -163,7 +165,7 @@ def shell(self, cmd): self._adb_lock.release() # Lock could not be acquired - _LOGGER.debug("ADB command not sent to %s because adb-shell lock not acquired: %s", self.host, cmd) + _LOGGER.warning("ADB command not sent to %s because adb-shell lock not acquired: %s", self.host, cmd) return None @@ -291,6 +293,8 @@ def connect(self, always_log_errors=True): self._adb_lock.release() # Lock could not be acquired + _LOGGER.warning("Couldn't connect to host %s via ADB server %s:%s because pure-python-adb lock not acquired.", self.host, self.adb_server_ip, self.adb_server_port) + self.close() self._available = False return False @@ -320,5 +324,5 @@ def shell(self, cmd): self._adb_lock.release() # Lock could not be acquired - _LOGGER.debug("ADB command not sent to %s via ADB server %s:%s because pure-python-adb lock not acquired: %s", self.host, self.adb_server_ip, self.adb_server_port, cmd) + _LOGGER.warning("ADB command not sent to %s via ADB server %s:%s because pure-python-adb lock not acquired: %s", self.host, self.adb_server_ip, self.adb_server_port, cmd) return None