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