1*1789df15SXin Li;;;; Copyright 2007 The Android Open Source Project 2*1789df15SXin Li 3*1789df15SXin Li;;; Set up GUD+JDB to attach to a Java process running on the phone or 4*1789df15SXin Li;;; under the emulator. 5*1789df15SXin Li 6*1789df15SXin Li(defvar android-jdb-port-history '("8700") 7*1789df15SXin Li "history of ports supplied to `android-jdb'") 8*1789df15SXin Li 9*1789df15SXin Li(defvar android-jdb-project-root-history '() 10*1789df15SXin Li "history of project roots supplied to `android-jdb'") 11*1789df15SXin Li(defvar android-jdb-history nil 12*1789df15SXin Li "history of commands supplied to `android-jdb'") 13*1789df15SXin Li 14*1789df15SXin Li(defvar android-jdb-activity-class-history () 15*1789df15SXin Li "history of activity classes supplied to `start-android-activity'") 16*1789df15SXin Li 17*1789df15SXin Li(defcustom android-jdb-command-name "jdb" 18*1789df15SXin Li "Name of Java debugger." 19*1789df15SXin Li :type 'string 20*1789df15SXin Li :group 'android) 21*1789df15SXin Li 22*1789df15SXin Li(defgroup android nil 23*1789df15SXin Li "Android Applications." 24*1789df15SXin Li :group 'applications) 25*1789df15SXin Li 26*1789df15SXin Li(defcustom android-project-root nil 27*1789df15SXin Li "This is where your Android project root is stored." 28*1789df15SXin Li :type 'directory 29*1789df15SXin Li :group 'android ) 30*1789df15SXin Li 31*1789df15SXin Li(defcustom android-apk nil 32*1789df15SXin Li "This is where your Android Application Package is stored." 33*1789df15SXin Li :type 'string 34*1789df15SXin Li :group 'android) 35*1789df15SXin Li 36*1789df15SXin Li(defcustom android-activity-class nil 37*1789df15SXin Li "This is where your Android Activity class is stored." 38*1789df15SXin Li :type 'string 39*1789df15SXin Li :group 'android) 40*1789df15SXin Li 41*1789df15SXin Li(defun android-read-project-root () 42*1789df15SXin Li (if (or (string-match "XEmacs" emacs-version) 43*1789df15SXin Li (>= emacs-major-version 22)) 44*1789df15SXin Li (read-file-name "Android project root: " 45*1789df15SXin Li android-project-root 46*1789df15SXin Li nil 47*1789df15SXin Li t 48*1789df15SXin Li nil 49*1789df15SXin Li 'file-directory-p) 50*1789df15SXin Li (labels ((read-directory () 51*1789df15SXin Li (read-file-name "Android project root: " 52*1789df15SXin Li android-project-root 53*1789df15SXin Li nil 54*1789df15SXin Li t 55*1789df15SXin Li nil))) 56*1789df15SXin Li (do ((entered-root (read-directory) (read-directory))) 57*1789df15SXin Li ((and entered-root 58*1789df15SXin Li (file-directory-p entered-root)) 59*1789df15SXin Li (expand-file-name entered-root)))))) 60*1789df15SXin Li 61*1789df15SXin Li(defun android-jdb (port root) 62*1789df15SXin Li "Set GUD+JDB up to run against Android on PORT in directory ROOT." 63*1789df15SXin Li (interactive 64*1789df15SXin Li (list 65*1789df15SXin Li (read-from-minibuffer "Activity's JDWP DDMS port: " 66*1789df15SXin Li (car android-jdb-port-history) 67*1789df15SXin Li nil 68*1789df15SXin Li t 69*1789df15SXin Li 'android-jdb-port-history) 70*1789df15SXin Li (android-read-project-root))) 71*1789df15SXin Li (setq android-project-root root) 72*1789df15SXin Li (let ((jdb-command 73*1789df15SXin Li (format "%s -attach localhost:%s -sourcepath%s" 74*1789df15SXin Li android-jdb-command-name 75*1789df15SXin Li port 76*1789df15SXin Li (format "%s/src" root)))) 77*1789df15SXin Li (if (not (string= jdb-command (car android-jdb-history))) 78*1789df15SXin Li (push jdb-command android-jdb-history)) 79*1789df15SXin Li (jdb jdb-command))) 80*1789df15SXin Li 81*1789df15SXin Li(defun android-emulate () 82*1789df15SXin Li "Run the Android emulator. This expects the SDK tools directory to be in the current path." 83*1789df15SXin Li (interactive) 84*1789df15SXin Li (compile "emulator")) 85*1789df15SXin Li 86*1789df15SXin Li(defun android-install-app (apk) 87*1789df15SXin Li "Install an Android application package APK in the Android emulator. This expects the SDK tools directory to be in the current path." 88*1789df15SXin Li (interactive (list (expand-file-name 89*1789df15SXin Li (read-file-name "Android Application Package (.apk): " 90*1789df15SXin Li nil 91*1789df15SXin Li android-apk 92*1789df15SXin Li t 93*1789df15SXin Li nil 94*1789df15SXin Li nil)))) 95*1789df15SXin Li (setq android-apk apk) 96*1789df15SXin Li (compile (format "adb install -r %s" apk))) 97*1789df15SXin Li 98*1789df15SXin Li(defun android-uninstall-app (package-name) 99*1789df15SXin Li "Uninstall an Android application package APK in the Android emulator. This expects the SDK tools directory to be in the current path. 100*1789df15SXin LiSpecify the package name --- and not the name of the application e.g., com.android.foo." 101*1789df15SXin Li (interactive 102*1789df15SXin Li (list 103*1789df15SXin Li (read-from-minibuffer "Package: "))) 104*1789df15SXin Li (compile (format "adb uninstall %s" package-name))) 105*1789df15SXin Li 106*1789df15SXin Li(defun android-start-activity (package class) 107*1789df15SXin Li "Start the activity PACKAGE/CLASS in the Android emulator. This expects the SDK tools directory to be in the current path." 108*1789df15SXin Li (interactive 109*1789df15SXin Li (list 110*1789df15SXin Li (read-from-minibuffer "Package: ") 111*1789df15SXin Li (read-from-minibuffer "Activity Java class: " 112*1789df15SXin Li (car android-jdb-activity-class-history) 113*1789df15SXin Li nil 114*1789df15SXin Li t 115*1789df15SXin Li 'android-jdb-activity-class-history))) 116*1789df15SXin Li (compile (format "adb shell am start -n %s/%s" package class))) 117*1789df15SXin Li 118*1789df15SXin Li(defun android-debug-activity (package class) 119*1789df15SXin Li "Start the activity PACKAGE/CLASS within the debugger in the Android emulator. This expects the SDK tools directory to be in the current path." 120*1789df15SXin Li (interactive 121*1789df15SXin Li (list 122*1789df15SXin Li (read-from-minibuffer "Package: ") 123*1789df15SXin Li (read-from-minibuffer "Activity Java class: " 124*1789df15SXin Li (car android-jdb-activity-class-history) 125*1789df15SXin Li nil 126*1789df15SXin Li t 127*1789df15SXin Li 'android-jdb-activity-class-history))) 128*1789df15SXin Li (compile (format "adb shell am start -D -n %s/%s" package class))) 129*1789df15SXin Li 130*1789df15SXin Li(provide 'android) 131*1789df15SXin Li 132