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 40;; associated buffer (*Android Output*) for errors when you use it. 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 ;; Always force root and remount, this way sync always works even on 87 ;; a device that has just rebooted or that runs a userdebug build. 88 (android-adb-root) 89 (android-adb-remount) 90 (android-adb-command "sync" 'p)) 91 92(defun android-fastboot-sentinel (process event) 93 "Called when the fastboot process is done." 94 ;; TODO: Should barf if the last lines are not: 95 ;; OKAY 96 ;; rebooting... 97 (princ 98 (format "Process: %s had the event `%s'" process event))) 99 100(defun android-fastboot-flashall (arg) 101 "Execute 'fastboot -p <product> flashall'. 102 103With no ARG, don't wipe the user data. 104With ARG, wipe the user data." 105 (interactive "P") 106 (when (get-buffer android-output-buffer-name) 107 (with-current-buffer android-output-buffer-name 108 (erase-buffer))) 109 (let ((proc 110 (if arg 111 (start-process-shell-command 112 "fastboot" 113 android-output-buffer-name 114 (concat (android-fastboot) " flashall -w")) 115 (start-process-shell-command 116 "fastboot" android-output-buffer-name 117 (concat (android-fastboot) " flashall"))))) 118 (set-process-sentinel proc 'android-fastboot-sentinel))) 119 120 121(provide 'android-host) 122;;; android-host.el ends here 123