aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog17
-rw-r--r--lisp/net/tramp-adb.el95
2 files changed, 95 insertions, 17 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 8d7360f899c..69c9e3cbea7 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,20 @@
12015-03-04 Zhongwei Yao <ashi08104@gmail.com>
2
3 * net/tramp-adb.el (tramp-adb-connect-if-not-connected):
4 New user option.
5 (tramp-adb-ls-toolbox-regexp): Fix regexp in order to support file
6 names starting with a space.
7 (tramp-methods): Add `tramp-default-port' for "adb".
8 (tramp-adb-parse-device-names): Add traces. Return device names
9 with port, if present.
10 (tramp-adb-handle-directory-files-and-attributes): Quote all
11 remote file names.
12 (tramp-adb-get-device): New defun.
13 (tramp-adb-execute-adb-command, tramp-adb-maybe-open-connection):
14 Use it.
15 (tramp-adb-maybe-open-connection): Set `tramp-current-*'
16 variables. Remove checks for listed devices.
17
12015-03-04 Michael Albinus <michael.albinus@gmx.de> 182015-03-04 Michael Albinus <michael.albinus@gmx.de>
2 19
3 * net/tramp.el (tramp): Add :link property. 20 * net/tramp.el (tramp): Add :link property.
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index f5e201985f9..fae54520102 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -44,6 +44,13 @@
44 :version "24.4" 44 :version "24.4"
45 :type 'string) 45 :type 'string)
46 46
47(defcustom tramp-adb-connect-if-not-connected nil
48 "Try to run `adb connect' if provided device is not connected currently.
49It is used for TCP/IP devices."
50 :group 'tramp
51 :version "25.1"
52 :type 'boolean)
53
47;;;###tramp-autoload 54;;;###tramp-autoload
48(defconst tramp-adb-method "adb" 55(defconst tramp-adb-method "adb"
49 "*When this method name is used, forward all calls to Android Debug Bridge.") 56 "*When this method name is used, forward all calls to Android Debug Bridge.")
@@ -65,12 +72,13 @@
65 "[[:space:]]+\\([^[:space:]]+\\)" ; \3 group 72 "[[:space:]]+\\([^[:space:]]+\\)" ; \3 group
66 "[[:space:]]+\\([[:digit:]]+\\)" ; \4 size 73 "[[:space:]]+\\([[:digit:]]+\\)" ; \4 size
67 "[[:space:]]+\\([-[:digit:]]+[[:space:]][:[:digit:]]+\\)" ; \5 date 74 "[[:space:]]+\\([-[:digit:]]+[[:space:]][:[:digit:]]+\\)" ; \5 date
68 "[[:space:]]+\\(.*\\)$")) ; \6 filename 75 "[[:space:]]\\(.*\\)$")) ; \6 filename
69 76
70;;;###tramp-autoload 77;;;###tramp-autoload
71(add-to-list 'tramp-methods 78(add-to-list 'tramp-methods
72 `(,tramp-adb-method 79 `(,tramp-adb-method
73 (tramp-tmpdir "/data/local/tmp"))) 80 (tramp-tmpdir "/data/local/tmp")
81 (tramp-default-port 5555)))
74 82
75;;;###tramp-autoload 83;;;###tramp-autoload
76(add-to-list 'tramp-default-host-alist `(,tramp-adb-method nil "")) 84(add-to-list 'tramp-default-host-alist `(,tramp-adb-method nil ""))
@@ -182,14 +190,27 @@ pass to the OPERATION."
182 ;; That's why we use `start-process'. 190 ;; That's why we use `start-process'.
183 (let ((p (start-process 191 (let ((p (start-process
184 tramp-adb-program (current-buffer) tramp-adb-program "devices")) 192 tramp-adb-program (current-buffer) tramp-adb-program "devices"))
193 (v (vector tramp-adb-method tramp-current-user
194 tramp-current-host nil nil))
185 result) 195 result)
196 (tramp-message v 6 "%s" (mapconcat 'identity (process-command p) " "))
186 (tramp-compat-set-process-query-on-exit-flag p nil) 197 (tramp-compat-set-process-query-on-exit-flag p nil)
187 (while (eq 'run (process-status p)) 198 (while (eq 'run (process-status p))
188 (accept-process-output p 0.1)) 199 (accept-process-output p 0.1))
189 (accept-process-output p 0.1) 200 (accept-process-output p 0.1)
201 (tramp-message v 6 "\n%s" (buffer-string))
190 (goto-char (point-min)) 202 (goto-char (point-min))
191 (while (search-forward-regexp "^\\(\\S-+\\)[[:space:]]+device$" nil t) 203 (while (search-forward-regexp "^\\(\\S-+\\)[[:space:]]+device$" nil t)
192 (add-to-list 'result (list nil (match-string 1)))) 204 (add-to-list 'result (list nil (match-string 1))))
205
206 ;; Replace ":" by "#".
207 (mapc
208 (lambda (elt)
209 (setcar
210 (cdr elt)
211 (replace-regexp-in-string
212 ":" tramp-prefix-port-format (car (cdr elt)))))
213 result)
193 result)))) 214 result))))
194 215
195(defun tramp-adb-handle-expand-file-name (name &optional dir) 216(defun tramp-adb-handle-expand-file-name (name &optional dir)
@@ -383,8 +404,10 @@ pass to the OPERATION."
383 (tramp-adb-send-command 404 (tramp-adb-send-command
384 v (format "%s -d -a -l %s %s" 405 v (format "%s -d -a -l %s %s"
385 (tramp-adb-get-ls-command v) 406 (tramp-adb-get-ls-command v)
386 (concat (file-name-as-directory localname) ".") 407 (tramp-shell-quote-argument
387 (concat (file-name-as-directory localname) ".."))) 408 (concat (file-name-as-directory localname) "."))
409 (tramp-shell-quote-argument
410 (concat (file-name-as-directory localname) ".."))))
388 (widen)) 411 (widen))
389 (tramp-adb-sh-fix-ls-output) 412 (tramp-adb-sh-fix-ls-output)
390 (let ((result (tramp-do-parse-file-attributes-with-ls 413 (let ((result (tramp-do-parse-file-attributes-with-ls
@@ -989,12 +1012,51 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
989 (tramp-set-connection-property v "process-name" nil) 1012 (tramp-set-connection-property v "process-name" nil)
990 (tramp-set-connection-property v "process-buffer" nil)))))) 1013 (tramp-set-connection-property v "process-buffer" nil))))))
991 1014
992;; Helper functions. 1015(defun tramp-adb-get-device (vec)
1016 "Return full host name from VEC to be used in shell exceution.
1017E.g. a host name \"192.168.1.1#5555\" returns \"192.168.1.1:5555\"
1018 a host name \"R38273882DE\" returns \"R38273882DE\"."
1019 ;; Sometimes this is called before there is a connection process
1020 ;; yet. In order to work with the connection cache, we flush all
1021 ;; unwanted entries first.
1022 (tramp-flush-connection-property nil)
1023 (with-tramp-connection-property (tramp-get-connection-process vec) "device"
1024 (let* ((method (tramp-file-name-method vec))
1025 (host (tramp-file-name-host vec))
1026 (port (tramp-file-name-port vec))
1027 (devices (mapcar 'cadr (tramp-adb-parse-device-names nil))))
1028 (replace-regexp-in-string
1029 tramp-prefix-port-format ":"
1030 (cond ((member host devices) host)
1031 ;; This is the case when the host is connected to the default port.
1032 ((member (format "%s%s%d" host tramp-prefix-port-format port)
1033 devices)
1034 (format "%s:%d" host port))
1035 ;; An empty host name shall be mapped as well, when there
1036 ;; is exactly one entry in `devices'.
1037 ((and (zerop (length host)) (= (length devices) 1))
1038 (car devices))
1039 ;; Try to connect device.
1040 ((and tramp-adb-connect-if-not-connected
1041 (not (zerop (length host)))
1042 (not (tramp-adb-execute-adb-command
1043 vec "connect"
1044 (replace-regexp-in-string
1045 tramp-prefix-port-format ":" host))))
1046 ;; When new device connected, running other adb command (e.g.
1047 ;; adb shell) immediately will fail. To get around this
1048 ;; problem, add sleep 0.1 second here.
1049 (sleep-for 0.1)
1050 host)
1051 (t (tramp-error
1052 vec 'file-error "Could not find device %s" host)))))))
993 1053
994(defun tramp-adb-execute-adb-command (vec &rest args) 1054(defun tramp-adb-execute-adb-command (vec &rest args)
995 "Returns nil on success error-output on failure." 1055 "Returns nil on success error-output on failure."
996 (when (> (length (tramp-file-name-host vec)) 0) 1056 (when (and (> (length (tramp-file-name-host vec)) 0)
997 (setq args (append (list "-s" (tramp-file-name-host vec)) args))) 1057 ;; The -s switch is only available for ADB device commands.
1058 (not (member (car args) (list "connect" "disconnect"))))
1059 (setq args (append (list "-s" (tramp-adb-get-device vec)) args)))
998 (with-temp-buffer 1060 (with-temp-buffer
999 (prog1 1061 (prog1
1000 (unless 1062 (unless
@@ -1097,7 +1159,12 @@ connection if a previous connection has died for some reason."
1097 (p (get-buffer-process buf)) 1159 (p (get-buffer-process buf))
1098 (host (tramp-file-name-host vec)) 1160 (host (tramp-file-name-host vec))
1099 (user (tramp-file-name-user vec)) 1161 (user (tramp-file-name-user vec))
1100 devices) 1162 (device (tramp-adb-get-device vec)))
1163
1164 ;; Set variables for proper tracing in `tramp-adb-parse-device-names'.
1165 (setq tramp-current-method (tramp-file-name-method vec)
1166 tramp-current-user (tramp-file-name-user vec)
1167 tramp-current-host (tramp-file-name-host vec))
1101 1168
1102 ;; Maybe we know already that "su" is not supported. We cannot 1169 ;; Maybe we know already that "su" is not supported. We cannot
1103 ;; use a connection property, because we have not checked yet 1170 ;; use a connection property, because we have not checked yet
@@ -1109,20 +1176,13 @@ connection if a previous connection has died for some reason."
1109 (and p (processp p) (memq (process-status p) '(run open))) 1176 (and p (processp p) (memq (process-status p) '(run open)))
1110 (save-match-data 1177 (save-match-data
1111 (when (and p (processp p)) (delete-process p)) 1178 (when (and p (processp p)) (delete-process p))
1112 (setq devices (mapcar 'cadr (tramp-adb-parse-device-names nil))) 1179 (if (zerop (length device))
1113 (if (not devices)
1114 (tramp-error vec 'file-error "No device connected"))
1115 (if (and (> (length host) 0) (not (member host devices)))
1116 (tramp-error vec 'file-error "Device %s not connected" host)) 1180 (tramp-error vec 'file-error "Device %s not connected" host))
1117 (if (and (> (length devices) 1) (zerop (length host)))
1118 (tramp-error
1119 vec 'file-error
1120 "Multiple Devices connected: No Host/Device specified"))
1121 (with-tramp-progress-reporter vec 3 "Opening adb shell connection" 1181 (with-tramp-progress-reporter vec 3 "Opening adb shell connection"
1122 (let* ((coding-system-for-read 'utf-8-dos) ;is this correct? 1182 (let* ((coding-system-for-read 'utf-8-dos) ;is this correct?
1123 (process-connection-type tramp-process-connection-type) 1183 (process-connection-type tramp-process-connection-type)
1124 (args (if (> (length host) 0) 1184 (args (if (> (length host) 0)
1125 (list "-s" host "shell") 1185 (list "-s" device "shell")
1126 (list "shell"))) 1186 (list "shell")))
1127 (p (let ((default-directory 1187 (p (let ((default-directory
1128 (tramp-compat-temporary-file-directory))) 1188 (tramp-compat-temporary-file-directory)))
@@ -1187,4 +1247,5 @@ connection if a previous connection has died for some reason."
1187 (unload-feature 'tramp-adb 'force))) 1247 (unload-feature 'tramp-adb 'force)))
1188 1248
1189(provide 'tramp-adb) 1249(provide 'tramp-adb)
1250
1190;;; tramp-adb.el ends here 1251;;; tramp-adb.el ends here