This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.gnu.emacs;
21
22 import android.os.Looper;
23 import android.os.Build;
24
25 import android.content.Context;
26 import android.content.res.AssetManager;
27
28 import java.lang.reflect.Constructor;
29 import java.lang.reflect.Method;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 @SuppressWarnings ("unchecked")
47 public final class EmacsNoninteractive
48 {
49 public static void
50 main (String[] args)
51 {
52 Object activityThread, loadedApk;
53 Class activityThreadClass, loadedApkClass, contextImplClass;
54 Class compatibilityInfoClass;
55 Method method;
56 Context context;
57 AssetManager assets;
58 String filesDir, libDir, cacheDir;
59
60 Looper.prepare ();
61 context = null;
62 assets = null;
63 filesDir = libDir = cacheDir = null;
64
65 try
66 {
67
68 activityThreadClass = Class.forName ("android.app.ActivityThread");
69
70
71 method = activityThreadClass.getMethod ("systemMain");
72
73
74 activityThread = method.invoke (null);
75 context = null;
76
77
78
79 try
80 {
81 loadedApkClass = Class.forName ("android.app.LoadedApk");
82 }
83 catch (ClassNotFoundException exception)
84 {
85
86
87
88
89 loadedApkClass = null;
90 contextImplClass = Class.forName ("android.app.ContextImpl");
91
92 method = activityThreadClass.getDeclaredMethod ("getSystemContext");
93 context = (Context) method.invoke (activityThread);
94 method = contextImplClass.getDeclaredMethod ("createPackageContext",
95 String.class,
96 int.class);
97 method.setAccessible (true);
98 context = (Context) method.invoke (context, "org.gnu.emacs",
99 0);
100 }
101
102
103
104
105 if (context == null)
106 {
107
108
109
110
111 if (Build.VERSION.SDK_INT
112 <= Build.VERSION_CODES.GINGERBREAD_MR1)
113 {
114 method
115 = activityThreadClass.getMethod ("getPackageInfo",
116 String.class,
117 int.class);
118 loadedApk = method.invoke (activityThread, "org.gnu.emacs",
119 0);
120 }
121 else
122 {
123 compatibilityInfoClass
124 = Class.forName ("android.content.res.CompatibilityInfo");
125
126 method
127 = activityThreadClass.getMethod ("getPackageInfo",
128 String.class,
129 compatibilityInfoClass,
130 int.class);
131 loadedApk = method.invoke (activityThread, "org.gnu.emacs",
132 null, 0);
133 }
134
135 if (loadedApk == null)
136 throw new RuntimeException ("getPackageInfo returned NULL");
137
138
139 contextImplClass = Class.forName ("android.app.ContextImpl");
140
141 try
142 {
143 method
144 = contextImplClass.getDeclaredMethod ("createAppContext",
145 activityThreadClass,
146 loadedApkClass);
147 method.setAccessible (true);
148 context = (Context) method.invoke (null, activityThread,
149 loadedApk);
150 }
151 catch (NoSuchMethodException exception)
152 {
153
154
155
156 method
157 = activityThreadClass.getDeclaredMethod ("getSystemContext");
158 context = (Context) method.invoke (activityThread);
159 method
160 = contextImplClass.getDeclaredMethod ("createPackageContext",
161 String.class,
162 int.class);
163 method.setAccessible (true);
164 context = (Context) method.invoke (context, "org.gnu.emacs",
165 0);
166 }
167 }
168
169
170
171 assets = context.getAssets ();
172
173
174
175 filesDir = context.getFilesDir ().getCanonicalPath ();
176 libDir = EmacsService.getLibraryDirectory (context);
177 cacheDir = context.getCacheDir ().getCanonicalPath ();
178 }
179 catch (Exception e)
180 {
181 System.err.println ("Internal error: " + e);
182 System.err.println ("This means that the Android platform changed,");
183 System.err.println ("and that Emacs needs adjustments in order to");
184 System.err.println ("obtain required system internal resources.");
185 System.err.println ("Please report this bug to bug-gnu-emacs@gnu.org.");
186 e.printStackTrace ();
187
188 System.exit (1);
189 }
190
191 EmacsNative.setEmacsParams (assets, filesDir,
192 libDir, cacheDir, 0.0f,
193 0.0f, 0.0f, null, null,
194 Build.VERSION.SDK_INT);
195
196
197
198 EmacsApplication.findDumpFile (context);
199
200
201 EmacsNative.initEmacs (args, EmacsApplication.dumpFileName);
202 }
203 };