def _RestartHttpServerForwarderIfNecessary(self):
   """Restarts the forwarder if it's not open."""
   # Checks to see if the http server port is being used.  If not forwards the
   # request.
   # TODO(dtrainor): This is not always reliable because sometimes the port
   # will be left open even after the forwarder has been killed.
   if not ports.IsDevicePortUsed(self.adb, self._forwarder_device_port):
     self._ForwardPortsForHttpServer()
def _CheckDevicePortStatus(adb, port):
    """Returns whether the provided port is used."""
    return _WaitUntil(lambda: ports.IsDevicePortUsed(adb, port))