* tramp-tests.el (tramp-test29-vc-registered):
[emacs.git] / lisp / net / tramp-adb.el
blob538884732172d8cbf8698b1f5d02269e9f117736
1 ;;; tramp-adb.el --- Functions for calling Android Debug Bridge from Tramp
3 ;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
5 ;; Author: Juergen Hoetzel <juergen@archlinux.org>
6 ;; Keywords: comm, processes
7 ;; Package: tramp
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; The Android Debug Bridge "adb" must be installed on your local
27 ;; machine. If it is not in your $PATH, add the following form into
28 ;; your .emacs:
30 ;; (setq tramp-adb-program "/path/to/adb")
32 ;; Due to security it is not possible to access non-root devices.
34 ;;; Code:
36 (require 'tramp)
37 (require 'time-date)
39 ;; Pacify byte-compiler.
40 (defvar directory-sep-char)
42 (defcustom tramp-adb-program "adb"
43 "Name of the Android Debug Bridge program."
44 :group 'tramp
45 :version "24.4"
46 :type 'string)
48 ;;;###tramp-autoload
49 (defconst tramp-adb-method "adb"
50 "*When this method name is used, forward all calls to Android Debug Bridge.")
52 (defcustom tramp-adb-prompt
53 "^\\(?:[[:digit:]]*|?\\)?\\(?:[[:alnum:]]*@[[:alnum:]]*[^#\\$]*\\)?[#\\$][[:space:]]"
54 "Regexp used as prompt in almquist shell."
55 :type 'string
56 :version "24.4"
57 :group 'tramp)
59 (defconst tramp-adb-ls-date-regexp
60 "[[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]][0-9][0-9]:[0-9][0-9][[:space:]]")
62 (defconst tramp-adb-ls-toolbox-regexp
63 (concat
64 "^[[:space:]]*\\([-[:alpha:]]+\\)" ; \1 permissions
65 "[[:space:]]*\\([^[:space:]]+\\)" ; \2 username
66 "[[:space:]]+\\([^[:space:]]+\\)" ; \3 group
67 "[[:space:]]+\\([[:digit:]]+\\)" ; \4 size
68 "[[:space:]]+\\([-[:digit:]]+[[:space:]][:[:digit:]]+\\)" ; \5 date
69 "[[:space:]]+\\(.*\\)$")) ; \6 filename
71 ;;;###tramp-autoload
72 (add-to-list 'tramp-methods
73 `(,tramp-adb-method
74 (tramp-tmpdir "/data/local/tmp")))
76 ;;;###tramp-autoload
77 (add-to-list 'tramp-default-host-alist `(,tramp-adb-method nil ""))
79 ;;;###tramp-autoload
80 (eval-after-load 'tramp
81 '(tramp-set-completion-function
82 tramp-adb-method '((tramp-adb-parse-device-names ""))))
84 ;;;###tramp-autoload
85 (add-to-list 'tramp-foreign-file-name-handler-alist
86 (cons 'tramp-adb-file-name-p 'tramp-adb-file-name-handler))
88 (defconst tramp-adb-file-name-handler-alist
89 '((access-file . ignore)
90 (add-name-to-file . tramp-adb-handle-copy-file)
91 ;; `byte-compiler-base-file-name' performed by default handler.
92 ;; `copy-directory' performed by default handler.
93 (copy-file . tramp-adb-handle-copy-file)
94 (delete-directory . tramp-adb-handle-delete-directory)
95 (delete-file . tramp-adb-handle-delete-file)
96 ;; `diff-latest-backup-file' performed by default handler.
97 (directory-file-name . tramp-handle-directory-file-name)
98 (directory-files . tramp-handle-directory-files)
99 (directory-files-and-attributes
100 . tramp-adb-handle-directory-files-and-attributes)
101 (dired-call-process . ignore)
102 (dired-compress-file . ignore)
103 (dired-uncache . tramp-handle-dired-uncache)
104 (expand-file-name . tramp-adb-handle-expand-file-name)
105 (file-accessible-directory-p . tramp-handle-file-accessible-directory-p)
106 (file-acl . ignore)
107 (file-attributes . tramp-adb-handle-file-attributes)
108 (file-directory-p . tramp-adb-handle-file-directory-p)
109 ;; `file-equal-p' performed by default handler.
110 ;; FIXME: This is too sloppy.
111 (file-executable-p . tramp-handle-file-exists-p)
112 (file-exists-p . tramp-handle-file-exists-p)
113 ;; `file-in-directory-p' performed by default handler.
114 (file-local-copy . tramp-adb-handle-file-local-copy)
115 (file-modes . tramp-handle-file-modes)
116 (file-name-all-completions . tramp-adb-handle-file-name-all-completions)
117 (file-name-as-directory . tramp-handle-file-name-as-directory)
118 (file-name-completion . tramp-handle-file-name-completion)
119 (file-name-directory . tramp-handle-file-name-directory)
120 (file-name-nondirectory . tramp-handle-file-name-nondirectory)
121 ;; `file-name-sans-versions' performed by default handler.
122 (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
123 (file-notify-add-watch . tramp-handle-file-notify-add-watch)
124 (file-notify-rm-watch . tramp-handle-file-notify-rm-watch)
125 (file-ownership-preserved-p . ignore)
126 (file-readable-p . tramp-handle-file-exists-p)
127 (file-regular-p . tramp-handle-file-regular-p)
128 (file-remote-p . tramp-handle-file-remote-p)
129 (file-selinux-context . ignore)
130 (file-symlink-p . tramp-handle-file-symlink-p)
131 (file-truename . tramp-adb-handle-file-truename)
132 (file-writable-p . tramp-adb-handle-file-writable-p)
133 (find-backup-file-name . tramp-handle-find-backup-file-name)
134 ;; `find-file-noselect' performed by default handler.
135 ;; `get-file-buffer' performed by default handler.
136 (insert-directory . tramp-handle-insert-directory)
137 (insert-file-contents . tramp-handle-insert-file-contents)
138 (load . tramp-handle-load)
139 (make-auto-save-file-name . tramp-handle-make-auto-save-file-name)
140 (make-directory . tramp-adb-handle-make-directory)
141 (make-directory-internal . ignore)
142 (make-symbolic-link . tramp-handle-make-symbolic-link)
143 (process-file . tramp-adb-handle-process-file)
144 (rename-file . tramp-adb-handle-rename-file)
145 (set-file-acl . ignore)
146 (set-file-modes . tramp-adb-handle-set-file-modes)
147 (set-file-selinux-context . ignore)
148 (set-file-times . tramp-adb-handle-set-file-times)
149 (set-visited-file-modtime . tramp-handle-set-visited-file-modtime)
150 (shell-command . tramp-adb-handle-shell-command)
151 (start-file-process . tramp-adb-handle-start-file-process)
152 (substitute-in-file-name . tramp-handle-substitute-in-file-name)
153 (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
154 (vc-registered . ignore)
155 (verify-visited-file-modtime . tramp-handle-verify-visited-file-modtime)
156 (write-region . tramp-adb-handle-write-region))
157 "Alist of handler functions for Tramp ADB method.")
159 ;; It must be a `defsubst' in order to push the whole code into
160 ;; tramp-loaddefs.el. Otherwise, there would be recursive autoloading.
161 ;;;###tramp-autoload
162 (defsubst tramp-adb-file-name-p (filename)
163 "Check if it's a filename for ADB."
164 (let ((v (tramp-dissect-file-name filename)))
165 (string= (tramp-file-name-method v) tramp-adb-method)))
167 ;;;###tramp-autoload
168 (defun tramp-adb-file-name-handler (operation &rest args)
169 "Invoke the ADB handler for OPERATION.
170 First arg specifies the OPERATION, second arg is a list of arguments to
171 pass to the OPERATION."
172 (let ((fn (assoc operation tramp-adb-file-name-handler-alist)))
173 (if fn
174 (save-match-data (apply (cdr fn) args))
175 (tramp-run-real-handler operation args))))
177 ;;;###tramp-autoload
178 (defun tramp-adb-parse-device-names (_ignore)
179 "Return a list of (nil host) tuples allowed to access."
180 (with-timeout (10)
181 (with-temp-buffer
182 ;; `call-process' does not react on timer under MS Windows.
183 ;; That's why we use `start-process'.
184 (let ((p (start-process
185 tramp-adb-program (current-buffer) tramp-adb-program "devices"))
186 result)
187 (tramp-compat-set-process-query-on-exit-flag p nil)
188 (while (eq 'run (process-status p))
189 (accept-process-output p 0.1))
190 (accept-process-output p 0.1)
191 (goto-char (point-min))
192 (while (search-forward-regexp "^\\(\\S-+\\)[[:space:]]+device$" nil t)
193 (add-to-list 'result (list nil (match-string 1))))
194 result))))
196 (defun tramp-adb-handle-expand-file-name (name &optional dir)
197 "Like `expand-file-name' for Tramp files."
198 ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
199 (setq dir (or dir default-directory "/"))
200 ;; Unless NAME is absolute, concat DIR and NAME.
201 (unless (file-name-absolute-p name)
202 (setq name (concat (file-name-as-directory dir) name)))
203 ;; If NAME is not a Tramp file, run the real handler.
204 (if (not (tramp-tramp-file-p name))
205 (tramp-run-real-handler 'expand-file-name (list name nil))
206 ;; Dissect NAME.
207 (with-parsed-tramp-file-name name nil
208 (unless (tramp-run-real-handler 'file-name-absolute-p (list localname))
209 (setq localname (concat "/" localname)))
210 ;; Do normal `expand-file-name' (this does "/./" and "/../").
211 ;; We bind `directory-sep-char' here for XEmacs on Windows,
212 ;; which would otherwise use backslash. `default-directory' is
213 ;; bound, because on Windows there would be problems with UNC
214 ;; shares or Cygwin mounts.
215 (let ((directory-sep-char ?/)
216 (default-directory (tramp-compat-temporary-file-directory)))
217 (tramp-make-tramp-file-name
218 method user host
219 (tramp-drop-volume-letter
220 (tramp-run-real-handler
221 'expand-file-name (list localname))))))))
223 (defun tramp-adb-handle-file-directory-p (filename)
224 "Like `file-directory-p' for Tramp files."
225 (car (file-attributes (file-truename filename))))
227 ;; This is derived from `tramp-sh-handle-file-truename'. Maybe the
228 ;; code could be shared?
229 (defun tramp-adb-handle-file-truename (filename)
230 "Like `file-truename' for Tramp files."
231 (format
232 "%s%s"
233 (with-parsed-tramp-file-name (expand-file-name filename) nil
234 (tramp-make-tramp-file-name
235 method user host
236 (with-tramp-file-property v localname "file-truename"
237 (let ((result nil)) ; result steps in reverse order
238 (tramp-message v 4 "Finding true name for `%s'" filename)
239 (let* ((directory-sep-char ?/)
240 (steps (tramp-compat-split-string localname "/"))
241 (localnamedir (tramp-run-real-handler
242 'file-name-as-directory (list localname)))
243 (is-dir (string= localname localnamedir))
244 (thisstep nil)
245 (numchase 0)
246 ;; Don't make the following value larger than
247 ;; necessary. People expect an error message in a
248 ;; timely fashion when something is wrong; otherwise
249 ;; they might think that Emacs is hung. Of course,
250 ;; correctness has to come first.
251 (numchase-limit 20)
252 symlink-target)
253 (while (and steps (< numchase numchase-limit))
254 (setq thisstep (pop steps))
255 (tramp-message
256 v 5 "Check %s"
257 (mapconcat 'identity
258 (append '("") (reverse result) (list thisstep))
259 "/"))
260 (setq symlink-target
261 (nth 0 (file-attributes
262 (tramp-make-tramp-file-name
263 method user host
264 (mapconcat 'identity
265 (append '("")
266 (reverse result)
267 (list thisstep))
268 "/")))))
269 (cond ((string= "." thisstep)
270 (tramp-message v 5 "Ignoring step `.'"))
271 ((string= ".." thisstep)
272 (tramp-message v 5 "Processing step `..'")
273 (pop result))
274 ((stringp symlink-target)
275 ;; It's a symlink, follow it.
276 (tramp-message v 5 "Follow symlink to %s" symlink-target)
277 (setq numchase (1+ numchase))
278 (when (file-name-absolute-p symlink-target)
279 (setq result nil))
280 ;; If the symlink was absolute, we'll get a string
281 ;; like "/user@host:/some/target"; extract the
282 ;; "/some/target" part from it.
283 (when (tramp-tramp-file-p symlink-target)
284 (unless (tramp-equal-remote filename symlink-target)
285 (tramp-error
286 v 'file-error
287 "Symlink target `%s' on wrong host" symlink-target))
288 (setq symlink-target localname))
289 (setq steps
290 (append (tramp-compat-split-string
291 symlink-target "/")
292 steps)))
294 ;; It's a file.
295 (setq result (cons thisstep result)))))
296 (when (>= numchase numchase-limit)
297 (tramp-error
298 v 'file-error
299 "Maximum number (%d) of symlinks exceeded" numchase-limit))
300 (setq result (reverse result))
301 ;; Combine list to form string.
302 (setq result
303 (if result
304 (mapconcat 'identity (cons "" result) "/")
305 "/"))
306 (when (and is-dir (or (string= "" result)
307 (not (string= (substring result -1) "/"))))
308 (setq result (concat result "/"))))
310 (tramp-message v 4 "True name of `%s' is `%s'" localname result)
311 result))))
313 ;; Preserve trailing "/".
314 (if (string-equal (file-name-nondirectory filename) "") "/" "")))
316 (defun tramp-adb-handle-file-attributes (filename &optional id-format)
317 "Like `file-attributes' for Tramp files."
318 (unless id-format (setq id-format 'integer))
319 (with-parsed-tramp-file-name filename nil
320 (with-tramp-file-property
321 v localname (format "file-attributes-%s" id-format)
322 (and
323 (tramp-adb-send-command-and-check
324 v (format "%s -d -l %s"
325 (tramp-adb-get-ls-command v)
326 (tramp-shell-quote-argument localname)))
327 (with-current-buffer (tramp-get-buffer v)
328 (tramp-adb-sh-fix-ls-output)
329 (cdar (tramp-do-parse-file-attributes-with-ls v id-format)))))))
331 (defun tramp-do-parse-file-attributes-with-ls (vec &optional id-format)
332 "Parse `file-attributes' for Tramp files using the ls(1) command."
333 (with-current-buffer (tramp-get-buffer vec)
334 (goto-char (point-min))
335 (let ((file-properties nil))
336 (while (re-search-forward tramp-adb-ls-toolbox-regexp nil t)
337 (let* ((mod-string (match-string 1))
338 (is-dir (eq ?d (aref mod-string 0)))
339 (is-symlink (eq ?l (aref mod-string 0)))
340 (uid (match-string 2))
341 (gid (match-string 3))
342 (size (string-to-number (match-string 4)))
343 (date (match-string 5))
344 (name (match-string 6))
345 (symlink-target
346 (and is-symlink
347 (cadr (split-string name "\\( -> \\|\n\\)")))))
348 (push (list
349 (if is-symlink
350 (car (split-string name "\\( -> \\|\n\\)"))
351 name)
352 (or is-dir symlink-target)
353 1 ;link-count
354 ;; no way to handle numeric ids in Androids ash
355 (if (eq id-format 'integer) 0 uid)
356 (if (eq id-format 'integer) 0 gid)
357 '(0 0) ; atime
358 (date-to-time date) ; mtime
359 '(0 0) ; ctime
360 size
361 mod-string
362 ;; fake
364 (tramp-get-device vec))
365 file-properties)))
366 file-properties)))
368 (defun tramp-adb-handle-directory-files-and-attributes
369 (directory &optional full match nosort id-format)
370 "Like `directory-files-and-attributes' for Tramp files."
371 (when (file-directory-p directory)
372 (with-parsed-tramp-file-name (expand-file-name directory) nil
373 (with-tramp-file-property
374 v localname (format "directory-files-attributes-%s-%s-%s-%s"
375 full match id-format nosort)
376 (with-current-buffer (tramp-get-buffer v)
377 (when (tramp-adb-send-command-and-check
378 v (format "%s -a -l %s"
379 (tramp-adb-get-ls-command v)
380 (tramp-shell-quote-argument localname)))
381 ;; We insert also filename/. and filename/.., because "ls" doesn't.
382 (narrow-to-region (point) (point))
383 (tramp-adb-send-command
384 v (format "%s -d -a -l %s %s"
385 (tramp-adb-get-ls-command v)
386 (concat (file-name-as-directory localname) ".")
387 (concat (file-name-as-directory localname) "..")))
388 (widen))
389 (tramp-adb-sh-fix-ls-output)
390 (let ((result (tramp-do-parse-file-attributes-with-ls
391 v (or id-format 'integer))))
392 (when full
393 (setq result
394 (mapcar
395 (lambda (x)
396 (cons (expand-file-name (car x) directory) (cdr x)))
397 result)))
398 (unless nosort
399 (setq result
400 (sort result (lambda (x y) (string< (car x) (car y))))))
401 (delq nil
402 (mapcar (lambda (x)
403 (if (or (not match) (string-match match (car x)))
405 result))))))))
407 (defun tramp-adb-get-ls-command (vec)
408 (with-tramp-connection-property vec "ls"
409 (tramp-message vec 5 "Finding a suitable `ls' command")
410 (if (tramp-adb-send-command-and-check vec "ls --color=never -al /dev/null")
411 ;; On CyanogenMod based system BusyBox is used and "ls" output
412 ;; coloring is enabled by default. So we try to disable it
413 ;; when possible.
414 "ls --color=never"
415 "ls")))
417 (defun tramp-adb--gnu-switches-to-ash
418 (switches)
419 "Almquist shell can't handle multiple arguments.
420 Convert (\"-al\") to (\"-a\" \"-l\"). Remove arguments like \"--dired\"."
421 (split-string
422 (apply 'concat
423 (mapcar (lambda (s)
424 (tramp-compat-replace-regexp-in-string
425 "\\(.\\)" " -\\1"
426 (tramp-compat-replace-regexp-in-string "^-" "" s)))
427 ;; FIXME: Warning about removed switches (long and non-dash).
428 (delq nil
429 (mapcar
430 (lambda (s)
431 (and (not (string-match "\\(^--\\|^[^-]\\)" s)) s))
432 switches))))))
434 (defun tramp-adb-sh-fix-ls-output (&optional sort-by-time)
435 "Insert dummy 0 in empty size columns.
436 Androids \"ls\" command doesn't insert size column for directories:
437 Emacs dired can't find files."
438 (save-excursion
439 ;; Insert missing size.
440 (goto-char (point-min))
441 (while
442 (search-forward-regexp
443 "[[:space:]]\\([[:space:]][0-9]\\{4\\}-[0-9][0-9]-[0-9][0-9][[:space:]]\\)" nil t)
444 (replace-match "0\\1" "\\1" nil)
445 ;; Insert missing "/".
446 (when (looking-at "[0-9][0-9]:[0-9][0-9][[:space:]]+$")
447 (end-of-line)
448 (insert "/")))
449 ;; Sort entries.
450 (let* ((lines (split-string (buffer-string) "\n" t))
451 (sorted-lines
452 (sort
453 lines
454 (if sort-by-time
455 'tramp-adb-ls-output-time-less-p
456 'tramp-adb-ls-output-name-less-p))))
457 (delete-region (point-min) (point-max))
458 (insert " " (mapconcat 'identity sorted-lines "\n ")))
459 ;; Add final newline.
460 (goto-char (point-max))
461 (unless (= (point) (line-beginning-position))
462 (insert "\n"))))
465 (defun tramp-adb-ls-output-time-less-p (a b)
466 "Sort \"ls\" output by time, descending."
467 (let (time-a time-b)
468 (string-match tramp-adb-ls-date-regexp a)
469 (setq time-a (apply 'encode-time (parse-time-string (match-string 0 a))))
470 (string-match tramp-adb-ls-date-regexp b)
471 (setq time-b (apply 'encode-time (parse-time-string (match-string 0 b))))
472 (tramp-time-less-p time-b time-a)))
474 (defun tramp-adb-ls-output-name-less-p (a b)
475 "Sort \"ls\" output by name, ascending."
476 (let (posa posb)
477 (string-match directory-listing-before-filename-regexp a)
478 (setq posa (match-end 0))
479 (string-match directory-listing-before-filename-regexp b)
480 (setq posb (match-end 0))
481 (string-lessp (substring a posa) (substring b posb))))
483 (defun tramp-adb-handle-make-directory (dir &optional parents)
484 "Like `make-directory' for Tramp files."
485 (setq dir (expand-file-name dir))
486 (with-parsed-tramp-file-name dir nil
487 (when parents
488 (let ((par (expand-file-name ".." dir)))
489 (unless (file-directory-p par)
490 (make-directory par parents))))
491 (tramp-adb-barf-unless-okay
492 v (format "mkdir %s" (tramp-shell-quote-argument localname))
493 "Couldn't make directory %s" dir)
494 (tramp-flush-file-property v (file-name-directory localname))
495 (tramp-flush-directory-property v localname)))
497 (defun tramp-adb-handle-delete-directory (directory &optional recursive)
498 "Like `delete-directory' for Tramp files."
499 (setq directory (expand-file-name directory))
500 (with-parsed-tramp-file-name directory nil
501 (tramp-flush-file-property v (file-name-directory localname))
502 (tramp-flush-directory-property v localname)
503 (tramp-adb-barf-unless-okay
504 v (format "%s %s"
505 (if recursive "rm -r" "rmdir")
506 (tramp-shell-quote-argument localname))
507 "Couldn't delete %s" directory)))
509 (defun tramp-adb-handle-delete-file (filename &optional _trash)
510 "Like `delete-file' for Tramp files."
511 (setq filename (expand-file-name filename))
512 (with-parsed-tramp-file-name filename nil
513 (tramp-flush-file-property v (file-name-directory localname))
514 (tramp-flush-file-property v localname)
515 (tramp-adb-barf-unless-okay
516 v (format "rm %s" (tramp-shell-quote-argument localname))
517 "Couldn't delete %s" filename)))
519 (defun tramp-adb-handle-file-name-all-completions (filename directory)
520 "Like `file-name-all-completions' for Tramp files."
521 (all-completions
522 filename
523 (with-parsed-tramp-file-name directory nil
524 (with-tramp-file-property v localname "file-name-all-completions"
525 (save-match-data
526 (tramp-adb-send-command
527 v (format "%s -a %s"
528 (tramp-adb-get-ls-command v)
529 (tramp-shell-quote-argument localname)))
530 (mapcar
531 (lambda (f)
532 (if (file-directory-p (expand-file-name f directory))
533 (file-name-as-directory f)
535 (with-current-buffer (tramp-get-buffer v)
536 (append
537 '("." "..")
538 (delq
540 (mapcar
541 (lambda (l) (and (not (string-match "^[[:space:]]*$" l)) l))
542 (split-string (buffer-string) "\n")))))))))))
544 (defun tramp-adb-handle-file-local-copy (filename)
545 "Like `file-local-copy' for Tramp files."
546 (with-parsed-tramp-file-name filename nil
547 (unless (file-exists-p (file-truename filename))
548 (tramp-error
549 v 'file-error
550 "Cannot make local copy of non-existing file `%s'" filename))
551 (let ((tmpfile (tramp-compat-make-temp-file filename)))
552 (with-tramp-progress-reporter
553 v 3 (format "Fetching %s to tmp file %s" filename tmpfile)
554 (when (tramp-adb-execute-adb-command v "pull" localname tmpfile)
555 (delete-file tmpfile)
556 (tramp-error
557 v 'file-error "Cannot make local copy of file `%s'" filename))
558 (set-file-modes
559 tmpfile
560 (logior (or (file-modes filename) 0)
561 (tramp-compat-octal-to-decimal "0400"))))
562 tmpfile)))
564 (defun tramp-adb-handle-file-writable-p (filename)
565 "Like `tramp-sh-handle-file-writable-p'.
566 But handle the case, if the \"test\" command is not available."
567 (with-parsed-tramp-file-name filename nil
568 (with-tramp-file-property v localname "file-writable-p"
569 (if (tramp-adb-find-test-command v)
570 (if (file-exists-p filename)
571 (tramp-adb-send-command-and-check
572 v (format "test -w %s" (tramp-shell-quote-argument localname)))
573 (and
574 (file-directory-p (file-name-directory filename))
575 (file-writable-p (file-name-directory filename))))
577 ;; Missing "test" command on Android < 4.
578 (let ((rw-path "/data/data"))
579 (tramp-message
581 "Not implemented yet (assuming \"/data/data\" is writable): %s"
582 localname)
583 (and (>= (length localname) (length rw-path))
584 (string= (substring localname 0 (length rw-path))
585 rw-path)))))))
587 (defun tramp-adb-handle-write-region
588 (start end filename &optional append visit lockname confirm)
589 "Like `write-region' for Tramp files."
590 (setq filename (expand-file-name filename))
591 (with-parsed-tramp-file-name filename nil
592 (when (and confirm (file-exists-p filename))
593 (unless (y-or-n-p (format "File %s exists; overwrite anyway? "
594 filename))
595 (tramp-error v 'file-error "File not overwritten")))
596 ;; We must also flush the cache of the directory, because
597 ;; `file-attributes' reads the values from there.
598 (tramp-flush-file-property v (file-name-directory localname))
599 (tramp-flush-file-property v localname)
600 (let* ((curbuf (current-buffer))
601 (tmpfile (tramp-compat-make-temp-file filename)))
602 (when (and append (file-exists-p filename))
603 (copy-file filename tmpfile 'ok)
604 (set-file-modes
605 tmpfile
606 (logior (or (file-modes tmpfile) 0)
607 (tramp-compat-octal-to-decimal "0600"))))
608 (tramp-run-real-handler
609 'write-region
610 (list start end tmpfile append 'no-message lockname confirm))
611 (with-tramp-progress-reporter
612 v 3 (format "Moving tmp file %s to %s" tmpfile filename)
613 (unwind-protect
614 (when (tramp-adb-execute-adb-command v "push" tmpfile localname)
615 (tramp-error v 'file-error "Cannot write: `%s' filename"))
616 (delete-file tmpfile)))
618 (when (or (eq visit t) (stringp visit))
619 (set-visited-file-modtime))
621 (unless (equal curbuf (current-buffer))
622 (tramp-error
623 v 'file-error
624 "Buffer has changed from `%s' to `%s'" curbuf (current-buffer))))))
626 (defun tramp-adb-handle-set-file-modes (filename mode)
627 "Like `set-file-modes' for Tramp files."
628 (with-parsed-tramp-file-name filename nil
629 (tramp-flush-file-property v localname)
630 (tramp-adb-send-command-and-check
631 v (format "chmod %s %s" (tramp-compat-decimal-to-octal mode) localname))))
633 (defun tramp-adb-handle-set-file-times (filename &optional time)
634 "Like `set-file-times' for Tramp files."
635 (with-parsed-tramp-file-name filename nil
636 (tramp-flush-file-property v localname)
637 (let ((time (if (or (null time) (equal time '(0 0)))
638 (current-time)
639 time)))
640 (tramp-adb-send-command-and-check
641 ;; Use shell arithmetic because of Emacs integer size limit.
642 v (format "touch -t $(( %d * 65536 + %d )) %s"
643 (car time) (cadr time)
644 (tramp-shell-quote-argument localname))))))
646 (defun tramp-adb-handle-copy-file
647 (filename newname &optional ok-if-already-exists keep-date
648 _preserve-uid-gid _preserve-extended-attributes)
649 "Like `copy-file' for Tramp files.
650 PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are completely ignored."
651 (setq filename (expand-file-name filename)
652 newname (expand-file-name newname))
654 (if (file-directory-p filename)
655 (tramp-file-name-handler 'copy-directory filename newname keep-date t)
656 (with-tramp-progress-reporter
657 (tramp-dissect-file-name
658 (if (tramp-tramp-file-p filename) filename newname))
659 0 (format "Copying %s to %s" filename newname)
661 (let ((tmpfile (file-local-copy filename)))
663 (if tmpfile
664 ;; Remote filename.
665 (condition-case err
666 (rename-file tmpfile newname ok-if-already-exists)
667 ((error quit)
668 (delete-file tmpfile)
669 (signal (car err) (cdr err))))
671 ;; Remote newname.
672 (when (file-directory-p newname)
673 (setq newname
674 (expand-file-name (file-name-nondirectory filename) newname)))
676 (with-parsed-tramp-file-name newname nil
677 (when (and (not ok-if-already-exists)
678 (file-exists-p newname))
679 (tramp-error v 'file-already-exists newname))
681 ;; We must also flush the cache of the directory, because
682 ;; `file-attributes' reads the values from there.
683 (tramp-flush-file-property v (file-name-directory localname))
684 (tramp-flush-file-property v localname)
685 (when (tramp-adb-execute-adb-command v "push" filename localname)
686 (tramp-error
687 v 'file-error "Cannot copy `%s' `%s'" filename newname))))))
689 ;; KEEP-DATE handling.
690 (when keep-date
691 (set-file-times newname (nth 5 (file-attributes filename))))))
693 (defun tramp-adb-handle-rename-file
694 (filename newname &optional ok-if-already-exists)
695 "Like `rename-file' for Tramp files."
696 (setq filename (expand-file-name filename)
697 newname (expand-file-name newname))
699 (let ((t1 (tramp-tramp-file-p filename))
700 (t2 (tramp-tramp-file-p newname)))
701 (with-parsed-tramp-file-name (if t1 filename newname) nil
702 (with-tramp-progress-reporter
703 v 0 (format "Renaming %s to %s" filename newname)
705 (if (and t1 t2
706 (tramp-equal-remote filename newname)
707 (not (file-directory-p filename)))
708 (let ((l1 (tramp-file-name-handler
709 'file-remote-p filename 'localname))
710 (l2 (tramp-file-name-handler
711 'file-remote-p newname 'localname)))
712 (when (and (not ok-if-already-exists)
713 (file-exists-p newname))
714 (tramp-error v 'file-already-exists newname))
715 ;; We must also flush the cache of the directory, because
716 ;; `file-attributes' reads the values from there.
717 (tramp-flush-file-property v (file-name-directory l1))
718 (tramp-flush-file-property v l1)
719 (tramp-flush-file-property v (file-name-directory l2))
720 (tramp-flush-file-property v l2)
721 ;; Short track.
722 (tramp-adb-barf-unless-okay
723 v (format "mv %s %s" l1 l2)
724 "Error renaming %s to %s" filename newname))
726 ;; Rename by copy.
727 (copy-file filename newname ok-if-already-exists t t)
728 (delete-file filename))))))
730 (defun tramp-adb-handle-process-file
731 (program &optional infile destination display &rest args)
732 "Like `process-file' for Tramp files."
733 ;; The implementation is not complete yet.
734 (when (and (numberp destination) (zerop destination))
735 (error "Implementation does not handle immediate return"))
737 (with-parsed-tramp-file-name default-directory nil
738 (let (command input tmpinput stderr tmpstderr outbuf ret)
739 ;; Compute command.
740 (setq command (mapconcat 'tramp-shell-quote-argument
741 (cons program args) " "))
742 ;; Determine input.
743 (if (null infile)
744 (setq input "/dev/null")
745 (setq infile (expand-file-name infile))
746 (if (tramp-equal-remote default-directory infile)
747 ;; INFILE is on the same remote host.
748 (setq input (with-parsed-tramp-file-name infile nil localname))
749 ;; INFILE must be copied to remote host.
750 (setq input (tramp-make-tramp-temp-file v)
751 tmpinput (tramp-make-tramp-file-name method user host input))
752 (copy-file infile tmpinput t)))
753 (when input (setq command (format "%s <%s" command input)))
755 ;; Determine output.
756 (cond
757 ;; Just a buffer.
758 ((bufferp destination)
759 (setq outbuf destination))
760 ;; A buffer name.
761 ((stringp destination)
762 (setq outbuf (get-buffer-create destination)))
763 ;; (REAL-DESTINATION ERROR-DESTINATION)
764 ((consp destination)
765 ;; output.
766 (cond
767 ((bufferp (car destination))
768 (setq outbuf (car destination)))
769 ((stringp (car destination))
770 (setq outbuf (get-buffer-create (car destination))))
771 ((car destination)
772 (setq outbuf (current-buffer))))
773 ;; stderr.
774 (cond
775 ((stringp (cadr destination))
776 (setcar (cdr destination) (expand-file-name (cadr destination)))
777 (if (tramp-equal-remote default-directory (cadr destination))
778 ;; stderr is on the same remote host.
779 (setq stderr (with-parsed-tramp-file-name
780 (cadr destination) nil localname))
781 ;; stderr must be copied to remote host. The temporary
782 ;; file must be deleted after execution.
783 (setq stderr (tramp-make-tramp-temp-file v)
784 tmpstderr (tramp-make-tramp-file-name
785 method user host stderr))))
786 ;; stderr to be discarded.
787 ((null (cadr destination))
788 (setq stderr "/dev/null"))))
789 ;; 't
790 (destination
791 (setq outbuf (current-buffer))))
792 (when stderr (setq command (format "%s 2>%s" command stderr)))
794 ;; Send the command. It might not return in time, so we protect
795 ;; it. Call it in a subshell, in order to preserve working
796 ;; directory.
797 (condition-case nil
798 (progn
799 (setq ret 0)
800 (tramp-adb-barf-unless-okay
801 v (format "(cd %s; %s)"
802 (tramp-shell-quote-argument localname) command)
804 ;; We should show the output anyway.
805 (when outbuf
806 (with-current-buffer outbuf
807 (insert-buffer-substring (tramp-get-connection-buffer v)))
808 (when display (display-buffer outbuf))))
809 ;; When the user did interrupt, we should do it also. We use
810 ;; return code -1 as marker.
811 (quit
812 (kill-buffer (tramp-get-connection-buffer v))
813 (setq ret -1))
814 ;; Handle errors.
815 (error
816 (kill-buffer (tramp-get-connection-buffer v))
817 (setq ret 1)))
819 ;; Provide error file.
820 (when tmpstderr (rename-file tmpstderr (cadr destination) t))
822 ;; Cleanup. We remove all file cache values for the connection,
823 ;; because the remote process could have changed them.
824 (when tmpinput (delete-file tmpinput))
826 ;; `process-file-side-effects' has been introduced with GNU
827 ;; Emacs 23.2. If set to `nil', no remote file will be changed
828 ;; by `program'. If it doesn't exist, we assume its default
829 ;; value 't'.
830 (unless (and (boundp 'process-file-side-effects)
831 (not (symbol-value 'process-file-side-effects)))
832 (tramp-flush-directory-property v ""))
834 ;; Return exit status.
835 (if (equal ret -1)
836 (keyboard-quit)
837 ret))))
839 (defun tramp-adb-handle-shell-command
840 (command &optional output-buffer error-buffer)
841 "Like `shell-command' for Tramp files."
842 (let* ((asynchronous (string-match "[ \t]*&[ \t]*\\'" command))
843 ;; We cannot use `shell-file-name' and `shell-command-switch',
844 ;; they are variables of the local host.
845 (args (list "sh" "-c" (substring command 0 asynchronous)))
846 current-buffer-p
847 (output-buffer
848 (cond
849 ((bufferp output-buffer) output-buffer)
850 ((stringp output-buffer) (get-buffer-create output-buffer))
851 (output-buffer
852 (setq current-buffer-p t)
853 (current-buffer))
854 (t (get-buffer-create
855 (if asynchronous
856 "*Async Shell Command*"
857 "*Shell Command Output*")))))
858 (error-buffer
859 (cond
860 ((bufferp error-buffer) error-buffer)
861 ((stringp error-buffer) (get-buffer-create error-buffer))))
862 (buffer
863 (if (and (not asynchronous) error-buffer)
864 (with-parsed-tramp-file-name default-directory nil
865 (list output-buffer (tramp-make-tramp-temp-file v)))
866 output-buffer))
867 (p (get-buffer-process output-buffer)))
869 ;; Check whether there is another process running. Tramp does not
870 ;; support 2 (asynchronous) processes in parallel.
871 (when p
872 (if (yes-or-no-p "A command is running. Kill it? ")
873 (ignore-errors (kill-process p))
874 (tramp-user-error p "Shell command in progress")))
876 (if current-buffer-p
877 (progn
878 (barf-if-buffer-read-only)
879 (push-mark nil t))
880 (with-current-buffer output-buffer
881 (setq buffer-read-only nil)
882 (erase-buffer)))
884 (if (and (not current-buffer-p) (integerp asynchronous))
885 (prog1
886 ;; Run the process.
887 (apply 'start-file-process "*Async Shell*" buffer args)
888 ;; Display output.
889 (pop-to-buffer output-buffer)
890 (setq mode-line-process '(":%s"))
891 (shell-mode))
893 (prog1
894 ;; Run the process.
895 (apply 'process-file (car args) nil buffer nil (cdr args))
896 ;; Insert error messages if they were separated.
897 (when (listp buffer)
898 (with-current-buffer error-buffer
899 (insert-file-contents (cadr buffer)))
900 (delete-file (cadr buffer)))
901 (if current-buffer-p
902 ;; This is like exchange-point-and-mark, but doesn't
903 ;; activate the mark. It is cleaner to avoid activation,
904 ;; even though the command loop would deactivate the mark
905 ;; because we inserted text.
906 (goto-char (prog1 (mark t)
907 (set-marker (mark-marker) (point)
908 (current-buffer))))
909 ;; There's some output, display it.
910 (when (with-current-buffer output-buffer (> (point-max) (point-min)))
911 (if (functionp 'display-message-or-buffer)
912 (tramp-compat-funcall 'display-message-or-buffer output-buffer)
913 (pop-to-buffer output-buffer))))))))
915 ;; We use BUFFER also as connection buffer during setup. Because of
916 ;; this, its original contents must be saved, and restored once
917 ;; connection has been setup.
918 (defun tramp-adb-handle-start-file-process (name buffer program &rest args)
919 "Like `start-file-process' for Tramp files."
920 (with-parsed-tramp-file-name default-directory nil
921 ;; When PROGRAM is nil, we should provide a tty. This is not
922 ;; possible here.
923 (unless (stringp program)
924 (tramp-error v 'file-error "PROGRAM must be a string"))
926 (let ((command
927 (format "cd %s; %s"
928 (tramp-shell-quote-argument localname)
929 (mapconcat 'tramp-shell-quote-argument
930 (cons program args) " ")))
931 (tramp-process-connection-type
932 (or (null program) tramp-process-connection-type))
933 (bmp (and (buffer-live-p buffer) (buffer-modified-p buffer)))
934 (name1 name)
935 (i 0))
937 (unless buffer
938 ;; BUFFER can be nil. We use a temporary buffer.
939 (setq buffer (generate-new-buffer tramp-temp-buffer-name)))
940 (while (get-process name1)
941 ;; NAME must be unique as process name.
942 (setq i (1+ i)
943 name1 (format "%s<%d>" name i)))
944 (setq name name1)
945 ;; Set the new process properties.
946 (tramp-set-connection-property v "process-name" name)
947 (tramp-set-connection-property v "process-buffer" buffer)
949 (with-current-buffer (tramp-get-connection-buffer v)
950 (unwind-protect
951 ;; We catch this event. Otherwise, `start-process' could
952 ;; be called on the local host.
953 (save-excursion
954 (save-restriction
955 ;; Activate narrowing in order to save BUFFER
956 ;; contents. Clear also the modification time;
957 ;; otherwise we might be interrupted by
958 ;; `verify-visited-file-modtime'.
959 (let ((buffer-undo-list t)
960 (buffer-read-only nil)
961 (mark (point)))
962 (clear-visited-file-modtime)
963 (narrow-to-region (point-max) (point-max))
964 ;; We call `tramp-adb-maybe-open-connection', in
965 ;; order to cleanup the prompt afterwards.
966 (tramp-adb-maybe-open-connection v)
967 (widen)
968 (delete-region mark (point))
969 (narrow-to-region (point-max) (point-max))
970 ;; Send the command.
971 (let ((tramp-adb-prompt (regexp-quote command)))
972 (tramp-adb-send-command v command))
973 (let ((p (tramp-get-connection-process v)))
974 ;; Set query flag and process marker for this
975 ;; process. We ignore errors, because the process
976 ;; could have finished already.
977 (ignore-errors
978 (tramp-compat-set-process-query-on-exit-flag p t)
979 (set-marker (process-mark p) (point)))
980 ;; Return process.
981 p))))
983 ;; Save exit.
984 (if (string-match tramp-temp-buffer-name (buffer-name))
985 (ignore-errors
986 (set-process-buffer (tramp-get-connection-process v) nil)
987 (kill-buffer (current-buffer)))
988 (set-buffer-modified-p bmp))
989 (tramp-set-connection-property v "process-name" nil)
990 (tramp-set-connection-property v "process-buffer" nil))))))
992 ;; Helper functions.
994 (defun tramp-adb-execute-adb-command (vec &rest args)
995 "Returns nil on success error-output on failure."
996 (when (> (length (tramp-file-name-host vec)) 0)
997 (setq args (append (list "-s" (tramp-file-name-host vec)) args)))
998 (with-temp-buffer
999 (prog1
1000 (unless
1001 (zerop (apply 'tramp-call-process tramp-adb-program nil t nil args))
1002 (buffer-string))
1003 (tramp-message vec 6 "%s" (buffer-string)))))
1005 (defun tramp-adb-find-test-command (vec)
1006 "Checks, whether the ash has a builtin \"test\" command.
1007 This happens for Android >= 4.0."
1008 (with-tramp-connection-property vec "test"
1009 (tramp-adb-send-command-and-check vec "type test")))
1011 ;; Connection functions
1013 (defun tramp-adb-send-command (vec command)
1014 "Send the COMMAND to connection VEC."
1015 (tramp-adb-maybe-open-connection vec)
1016 (tramp-message vec 6 "%s" command)
1017 (tramp-send-string vec command)
1018 ;; fixme: Race condition
1019 (tramp-adb-wait-for-output (tramp-get-connection-process vec))
1020 (with-current-buffer (tramp-get-connection-buffer vec)
1021 (save-excursion
1022 (goto-char (point-min))
1023 ;; We can't use stty to disable echo of command.
1024 (delete-matching-lines (regexp-quote command))
1025 ;; When the local machine is W32, there are still trailing ^M.
1026 ;; There must be a better solution by setting the correct coding
1027 ;; system, but this requires changes in core Tramp.
1028 (goto-char (point-min))
1029 (while (re-search-forward "\r+$" nil t)
1030 (replace-match "" nil nil)))))
1032 (defun tramp-adb-send-command-and-check
1033 (vec command)
1034 "Run COMMAND and and check its exit status.
1035 Sends `echo $?' along with the COMMAND for checking the exit status. If
1036 COMMAND is nil, just sends `echo $?'. Returns the exit status found."
1037 (tramp-adb-send-command
1038 vec (if command
1039 (format "%s; echo tramp_exit_status $?" command)
1040 "echo tramp_exit_status $?"))
1041 (with-current-buffer (tramp-get-connection-buffer vec)
1042 (goto-char (point-max))
1043 (unless (re-search-backward "tramp_exit_status [0-9]+" nil t)
1044 (tramp-error
1045 vec 'file-error "Couldn't find exit status of `%s'" command))
1046 (skip-chars-forward "^ ")
1047 (prog1
1048 (zerop (read (current-buffer)))
1049 (let (buffer-read-only)
1050 (delete-region (match-beginning 0) (point-max))))))
1052 (defun tramp-adb-barf-unless-okay (vec command fmt &rest args)
1053 "Run COMMAND, check exit status, throw error if exit status not okay.
1054 FMT and ARGS are passed to `error'."
1055 (unless (tramp-adb-send-command-and-check vec command)
1056 (apply 'tramp-error vec 'file-error fmt args)))
1058 (defun tramp-adb-wait-for-output (proc &optional timeout)
1059 "Wait for output from remote command."
1060 (unless (buffer-live-p (process-buffer proc))
1061 (delete-process proc)
1062 (tramp-error proc 'file-error "Process `%s' not available, try again" proc))
1063 (with-current-buffer (process-buffer proc)
1064 (if (tramp-wait-for-regexp proc timeout tramp-adb-prompt)
1065 (let (buffer-read-only)
1066 (goto-char (point-min))
1067 ;; ADB terminal sends "^H" sequences.
1068 (when (re-search-forward "<\b+" (point-at-eol) t)
1069 (forward-line 1)
1070 (delete-region (point-min) (point)))
1071 ;; Delete the prompt.
1072 (goto-char (point-min))
1073 (when (re-search-forward tramp-adb-prompt (point-at-eol) t)
1074 (forward-line 1)
1075 (delete-region (point-min) (point)))
1076 (goto-char (point-max))
1077 (re-search-backward tramp-adb-prompt nil t)
1078 (delete-region (point) (point-max)))
1079 (if timeout
1080 (tramp-error
1081 proc 'file-error
1082 "[[Remote adb prompt `%s' not found in %d secs]]"
1083 tramp-adb-prompt timeout)
1084 (tramp-error
1085 proc 'file-error
1086 "[[Remote prompt `%s' not found]]" tramp-adb-prompt)))))
1088 (defun tramp-adb-maybe-open-connection (vec)
1089 "Maybe open a connection VEC.
1090 Does not do anything if a connection is already open, but re-opens the
1091 connection if a previous connection has died for some reason."
1092 (tramp-check-proper-method-and-host vec)
1094 (let* ((buf (tramp-get-connection-buffer vec))
1095 (p (get-buffer-process buf))
1096 (host (tramp-file-name-host vec))
1097 (user (tramp-file-name-user vec))
1098 devices)
1100 ;; Maybe we know already that "su" is not supported. We cannot
1101 ;; use a connection property, because we have not checked yet
1102 ;; whether it is still the same device.
1103 (when (and user (not (tramp-get-file-property vec "" "su-command-p" t)))
1104 (tramp-error vec 'file-error "Cannot switch to user `%s'" user))
1106 (unless
1107 (and p (processp p) (memq (process-status p) '(run open)))
1108 (save-match-data
1109 (when (and p (processp p)) (delete-process p))
1110 (setq tramp-current-method (tramp-file-name-method vec)
1111 tramp-current-user (tramp-file-name-user vec)
1112 tramp-current-host (tramp-file-name-host vec)
1113 devices (mapcar 'cadr (tramp-adb-parse-device-names nil)))
1114 (if (not devices)
1115 (tramp-error vec 'file-error "No device connected"))
1116 (if (and (> (length host) 0) (not (member host devices)))
1117 (tramp-error vec 'file-error "Device %s not connected" host))
1118 (if (and (> (length devices) 1) (zerop (length host)))
1119 (tramp-error
1120 vec 'file-error
1121 "Multiple Devices connected: No Host/Device specified"))
1122 (with-tramp-progress-reporter vec 3 "Opening adb shell connection"
1123 (let* ((coding-system-for-read 'utf-8-dos) ;is this correct?
1124 (process-connection-type tramp-process-connection-type)
1125 (args (if (> (length host) 0)
1126 (list "-s" host "shell")
1127 (list "shell")))
1128 (p (let ((default-directory
1129 (tramp-compat-temporary-file-directory)))
1130 (apply 'start-process (tramp-get-connection-name vec) buf
1131 tramp-adb-program args))))
1132 (tramp-message
1133 vec 6 "%s" (mapconcat 'identity (process-command p) " "))
1134 ;; Wait for initial prompt.
1135 (tramp-adb-wait-for-output p 30)
1136 (unless (eq 'run (process-status p))
1137 (tramp-error vec 'file-error "Terminated!"))
1138 (tramp-set-connection-property p "vector" vec)
1139 (tramp-compat-set-process-query-on-exit-flag p nil)
1141 ;; Check whether the properties have been changed. If
1142 ;; yes, this is a strong indication that we must expire all
1143 ;; connection properties. We start again.
1144 (tramp-message vec 5 "Checking system information")
1145 (tramp-adb-send-command
1146 vec "echo \\\"`getprop ro.product.model` `getprop ro.product.version` `getprop ro.build.version.release`\\\"")
1147 (let ((old-getprop
1148 (tramp-get-connection-property vec "getprop" nil))
1149 (new-getprop
1150 (tramp-set-connection-property
1151 vec "getprop"
1152 (with-current-buffer (tramp-get-connection-buffer vec)
1153 ;; Read the expression.
1154 (goto-char (point-min))
1155 (read (current-buffer))))))
1156 (when (and (stringp old-getprop)
1157 (not (string-equal old-getprop new-getprop)))
1158 (tramp-message
1159 vec 3
1160 "Connection reset, because remote host changed from `%s' to `%s'"
1161 old-getprop new-getprop)
1162 (tramp-cleanup-connection vec t)
1163 (tramp-adb-maybe-open-connection vec)))
1165 ;; Change user if indicated.
1166 (when user
1167 (tramp-adb-send-command vec (format "su %s" user))
1168 (unless (tramp-adb-send-command-and-check vec nil)
1169 (delete-process p)
1170 (tramp-set-file-property vec "" "su-command-p" nil)
1171 (tramp-error
1172 vec 'file-error "Cannot switch to user `%s'" user)))
1174 ;; Set "remote-path" connection property. This is needed
1175 ;; for eshell.
1176 (tramp-adb-send-command vec "echo \\\"$PATH\\\"")
1177 (tramp-set-connection-property
1178 vec "remote-path"
1179 (split-string
1180 (with-current-buffer (tramp-get-connection-buffer vec)
1181 ;; Read the expression.
1182 (goto-char (point-min))
1183 (read (current-buffer)))
1184 ":" 'omit-nulls))))))))
1186 (add-hook 'tramp-unload-hook
1187 (lambda ()
1188 (unload-feature 'tramp-adb 'force)))
1190 (provide 'tramp-adb)
1191 ;;; tramp-adb.el ends here