code: def restore_app_connection(self, port=None):
          
          self.host_port = port or utils.get_available_host_port()
          self._adb.forward(
              ['tcp:%d' % self.host_port,
               'tcp:%d' % self.device_port])
          try:
              self.connect()
          except:
              # Log the original error and raise AppRestoreConnectionError.
              self.log.exception('Failed to re-connect to app.')
              raise jsonrpc_client_base.AppRestoreConnectionError(
                  self._ad,
                  ('Failed to restore app connection for %s at host port %s, '
                   'device port %s') % (self.package, self.host_port,
                                        self.device_port))
  
          # Because the previous connection was lost, update self._proc
          self._proc = None
          self._restore_event_client()
docs: Restores the app after device got reconnected.
  
          Instead of creating new instance of the client:
            - Uses the given port (or find a new available host_port if none is
              given).
            - Tries to connect to remote server with selected port.
  
          Args:
            port: If given, this is the host port from which to connect to remote
                device port. If not provided, find a new available port as host
                port.
  
          Raises:
              AppRestoreConnectionError: When the app was not able to be started.