Nicolas Catania | 081e65d | 2009-10-09 21:17:27 -0700 | [diff] [blame] | 1 | ;;; android-host.el --- Module to use host binaries from an Android dev tree. |
| 2 | ;; |
| 3 | ;; Copyright (C) 2009 The Android Open Source Project |
| 4 | ;; |
| 5 | ;; Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ;; you may not use this file except in compliance with the License. |
| 7 | ;; You may obtain a copy of the License at |
| 8 | ;; |
| 9 | ;; http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ;; |
| 11 | ;; Unless required by applicable law or agreed to in writing, software |
| 12 | ;; distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ;; See the License for the specific language governing permissions and |
| 15 | ;; limitations under the License. |
| 16 | |
| 17 | ;;; Commentary: |
| 18 | ;; |
| 19 | ;; This module defines interactive functions to send the most common |
| 20 | ;; commands to a device. |
| 21 | ;; |
| 22 | ;; Currently only one device is supported. |
| 23 | ;; |
| 24 | ;; In your .emacs load this file (e.g (require 'android-host)) then |
| 25 | ;; you can either create new shortcuts e.g: |
| 26 | ;; |
| 27 | ;; (global-set-key [f8] 'android-adb-sync) |
| 28 | ;; |
| 29 | ;; or rely on autocompletion M-x and-sync will expand to |
| 30 | ;; M-x android-adb-sync |
| 31 | ;; |
| 32 | ;; By default the following key bindings are active: |
| 33 | ;; C-x a a android-adb-root |
| 34 | ;; C-x a r android-adb-remount |
| 35 | ;; C-x a s android-adb-sync |
| 36 | ;; C-x a b android-adb-shell-reboot-bootloader |
| 37 | ;; C-x a f android-fastboot-flashall |
| 38 | ;; |
| 39 | ;; android-fastboot-flashall is still work in progress, check the |
Nicolas Catania | 2022dcd | 2009-10-13 09:10:19 -0700 | [diff] [blame] | 40 | ;; associated buffer (*Android Output*) for errors when you use it. |
Nicolas Catania | 081e65d | 2009-10-09 21:17:27 -0700 | [diff] [blame] | 41 | |
| 42 | ;;; Code: |
| 43 | |
| 44 | (require 'android-common) |
| 45 | |
| 46 | (defvar android-host-command-map (make-sparse-keymap)) |
| 47 | |
| 48 | (defun android-host-key-prefix-set (var val) |
| 49 | "Bind the keys shortcuts to the functions.i" |
| 50 | ;; TODO: This should go in a minor mode keymap instead of |
| 51 | ;; messing with the global one. |
| 52 | (define-key global-map (read-kbd-macro val) android-host-command-map) |
| 53 | (custom-set-default var val)) |
| 54 | |
| 55 | (let ((map android-host-command-map)) |
| 56 | (define-key map (kbd "a") 'android-adb-root) |
| 57 | (define-key map (kbd "r") 'android-adb-remount) |
| 58 | (define-key map (kbd "s") 'android-adb-sync) |
| 59 | (define-key map (kbd "b") 'android-adb-shell-reboot-bootloader) |
| 60 | (define-key map (kbd "f") 'android-fastboot-flashall)) |
| 61 | |
| 62 | (defcustom android-host-key-prefix "C-x a" |
| 63 | "Prefix keystrokes for Android commands." |
| 64 | :group 'android |
| 65 | :type 'string |
| 66 | :set 'android-host-key-prefix-set) |
| 67 | |
| 68 | (defun android-adb-remount () |
| 69 | "Execute 'adb remount'." |
| 70 | (interactive) |
| 71 | (android-adb-command "remount")) |
| 72 | |
| 73 | (defun android-adb-root () |
| 74 | "Execute 'adb root'." |
| 75 | (interactive) |
| 76 | (android-adb-command "root")) |
| 77 | |
| 78 | (defun android-adb-shell-reboot-bootloader () |
| 79 | "Execute 'adb shell reboot bootloader'." |
| 80 | (interactive) |
| 81 | (android-adb-shell-command "reboot bootloader")) |
| 82 | |
| 83 | (defun android-adb-sync () |
| 84 | "Execute 'adb sync'." |
| 85 | (interactive) |
| 86 | (android-adb-command "sync" 'p)) |
| 87 | |
| 88 | (defun android-fastboot-sentinel (process event) |
| 89 | "Called when the fastboot process is done." |
| 90 | ;; TODO: Should barf if the last lines are not: |
| 91 | ;; OKAY |
| 92 | ;; rebooting... |
| 93 | (princ |
| 94 | (format "Process: %s had the event `%s'" process event))) |
| 95 | |
| 96 | (defun android-fastboot-flashall (arg) |
| 97 | "Execute 'fastboot -p <product> flashall'. |
| 98 | |
| 99 | With no ARG, don't wipe the user data. |
| 100 | With ARG, wipe the user data." |
| 101 | (interactive "P") |
Nicolas Catania | 2022dcd | 2009-10-13 09:10:19 -0700 | [diff] [blame] | 102 | (when (get-buffer android-output-buffer-name) |
| 103 | (with-current-buffer android-output-buffer-name |
| 104 | (erase-buffer))) |
Nicolas Catania | 081e65d | 2009-10-09 21:17:27 -0700 | [diff] [blame] | 105 | (let ((proc |
| 106 | (if arg |
| 107 | (start-process-shell-command |
Nicolas Catania | 2022dcd | 2009-10-13 09:10:19 -0700 | [diff] [blame] | 108 | "fastboot" |
| 109 | android-output-buffer-name |
| 110 | (concat (android-fastboot) " flashall -w")) |
Nicolas Catania | 081e65d | 2009-10-09 21:17:27 -0700 | [diff] [blame] | 111 | (start-process-shell-command |
Nicolas Catania | 2022dcd | 2009-10-13 09:10:19 -0700 | [diff] [blame] | 112 | "fastboot" android-output-buffer-name |
| 113 | (concat (android-fastboot) " flashall"))))) |
Nicolas Catania | 081e65d | 2009-10-09 21:17:27 -0700 | [diff] [blame] | 114 | (set-process-sentinel proc 'android-fastboot-sentinel))) |
| 115 | |
| 116 | |
| 117 | (provide 'android-host) |
| 118 | ;;; android-host.el ends here |