'Decorator which automatically closes the connection to the ADB server
after calling the decorated function.'

def _autoclose(fn):

    @functools.wraps(fn)
    def wrapper(self, *a, **kw):
        rv = fn(self, *a, **kw)
        if self._c:
            self._c.close()
            self._c = None
        return rv
    return wrapper
