Function: tramp-adb-get-device

tramp-adb-get-device is a byte-compiled function defined in tramp-adb.el.gz.

Signature

(tramp-adb-get-device VEC)

Documentation

Return full host name from VEC to be used in shell execution.

E.g. a host name "192.168.1.1#5555" returns "192.168.1.1:5555"
     a host name "R38273882DE" returns "R38273882DE".

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-adb.el.gz
(defun tramp-adb-get-device (vec)
  "Return full host name from VEC to be used in shell execution.
E.g. a host name \"192.168.1.1#5555\" returns \"192.168.1.1:5555\"
     a host name \"R38273882DE\" returns \"R38273882DE\"."
  (with-tramp-connection-property (tramp-get-process vec) "device"
    (let* ((host (tramp-file-name-host vec))
	   (port (tramp-file-name-port-or-default vec))
	   (devices (mapcar #'cadr (tramp-adb-parse-device-names nil))))
      (tramp-compat-string-replace
       tramp-prefix-port-format ":"
       (cond ((member host devices) host)
	     ;; This is the case when the host is connected to the default port.
	     ((member (format "%s%s%s" host tramp-prefix-port-format port)
		      devices)
	      (format "%s:%s" host port))
	     ;; An empty host name shall be mapped as well, when there
	     ;; is exactly one entry in `devices'.
	     ((and (tramp-string-empty-or-nil-p host)
		   (tramp-compat-length= devices 1))
	      (car devices))
	     ;; Try to connect device.
	     ((and tramp-adb-connect-if-not-connected
		   (tramp-compat-length> host 0)
		   (tramp-adb-execute-adb-command
                    vec "connect"
                    (tramp-compat-string-replace
		     tramp-prefix-port-format ":" host)))
	      ;; When new device connected, running other adb command (e.g.
	      ;; adb shell) immediately will fail.  To get around this
	      ;; problem, add sleep 0.1 second here.
	      (sleep-for 0.1)
	      host)
	     (t (tramp-error
		 vec 'file-error "Could not find device %s" host)))))))