1 /*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define ATRACE_TAG ATRACE_TAG_DALVIK
18 #define LOG_TAG "AndroidRuntime"
19 #define LOG_NDEBUG 1
20
21 #include <android_runtime/AndroidRuntime.h>
22
23 #include <android-base/properties.h>
24 #include <binder/IBinder.h>
25 #include <binder/IPCThreadState.h>
26 #include <binder/IServiceManager.h>
27 #include <utils/Log.h>
28 #include <utils/misc.h>
29 #include <utils/Trace.h>
30 #include <binder/Parcel.h>
31 #include <utils/threads.h>
32 #include <cutils/properties.h>
33
34 #include <SkGraphics.h>
35
36 #include "jni.h"
37 #include <nativehelper/JNIHelp.h>
38 #include <nativehelper/JniInvocation.h>
39 #include "android_util_Binder.h"
40
41 #include <stdio.h>
42 #include <signal.h>
43 #include <sys/stat.h>
44 #include <sys/types.h>
45 #include <signal.h>
46 #include <dirent.h>
47 #include <assert.h>
48
49 #include <string>
50 #include <vector>
51
52 using namespace android;
53 using android::base::GetProperty;
54
55 extern int register_android_os_Binder(JNIEnv* env);
56 extern int register_android_os_Process(JNIEnv* env);
57 extern int register_android_graphics_Bitmap(JNIEnv*);
58 extern int register_android_graphics_BitmapFactory(JNIEnv*);
59 extern int register_android_graphics_BitmapRegionDecoder(JNIEnv*);
60 extern int register_android_graphics_ByteBufferStreamAdaptor(JNIEnv* env);
61 extern int register_android_graphics_Camera(JNIEnv* env);
62 extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
63 extern int register_android_graphics_GraphicBuffer(JNIEnv* env);
64 extern int register_android_graphics_Graphics(JNIEnv* env);
65 extern int register_android_graphics_ImageDecoder(JNIEnv*);
66 extern int register_android_graphics_drawable_AnimatedImageDrawable(JNIEnv*);
67 extern int register_android_graphics_Interpolator(JNIEnv* env);
68 extern int register_android_graphics_MaskFilter(JNIEnv* env);
69 extern int register_android_graphics_Movie(JNIEnv* env);
70 extern int register_android_graphics_NinePatch(JNIEnv*);
71 extern int register_android_graphics_PathEffect(JNIEnv* env);
72 extern int register_android_graphics_Shader(JNIEnv* env);
73 extern int register_android_graphics_Typeface(JNIEnv* env);
74 extern int register_android_graphics_YuvImage(JNIEnv* env);
75
76 extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env);
77 extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env);
78 extern int register_android_opengl_jni_EGL14(JNIEnv* env);
79 extern int register_android_opengl_jni_EGLExt(JNIEnv* env);
80 extern int register_android_opengl_jni_GLES10(JNIEnv* env);
81 extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env);
82 extern int register_android_opengl_jni_GLES11(JNIEnv* env);
83 extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env);
84 extern int register_android_opengl_jni_GLES20(JNIEnv* env);
85 extern int register_android_opengl_jni_GLES30(JNIEnv* env);
86 extern int register_android_opengl_jni_GLES31(JNIEnv* env);
87 extern int register_android_opengl_jni_GLES31Ext(JNIEnv* env);
88 extern int register_android_opengl_jni_GLES32(JNIEnv* env);
89
90 extern int register_android_hardware_Camera(JNIEnv *env);
91 extern int register_android_hardware_camera2_CameraMetadata(JNIEnv *env);
92 extern int register_android_hardware_camera2_legacy_LegacyCameraDevice(JNIEnv *env);
93 extern int register_android_hardware_camera2_legacy_PerfMeasurement(JNIEnv *env);
94 extern int register_android_hardware_camera2_DngCreator(JNIEnv *env);
95 extern int register_android_hardware_HardwareBuffer(JNIEnv *env);
96 extern int register_android_hardware_SensorManager(JNIEnv *env);
97 extern int register_android_hardware_SerialPort(JNIEnv *env);
98 extern int register_android_hardware_SoundTrigger(JNIEnv *env);
99 extern int register_android_hardware_UsbDevice(JNIEnv *env);
100 extern int register_android_hardware_UsbDeviceConnection(JNIEnv *env);
101 extern int register_android_hardware_UsbRequest(JNIEnv *env);
102 extern int register_android_hardware_location_ActivityRecognitionHardware(JNIEnv* env);
103
104 extern int register_android_media_AudioRecord(JNIEnv *env);
105 extern int register_android_media_AudioSystem(JNIEnv *env);
106 extern int register_android_media_AudioTrack(JNIEnv *env);
107 extern int register_android_media_MicrophoneInfo(JNIEnv *env);
108 extern int register_android_media_JetPlayer(JNIEnv *env);
109 extern int register_android_media_ToneGenerator(JNIEnv *env);
110
111 namespace android {
112
113 /*
114 * JNI-based registration functions. Note these are properly contained in
115 * namespace android.
116 */
117 extern int register_android_app_admin_SecurityLog(JNIEnv* env);
118 extern int register_android_content_AssetManager(JNIEnv* env);
119 extern int register_android_util_EventLog(JNIEnv* env);
120 extern int register_android_util_StatsLog(JNIEnv* env);
121 extern int register_android_util_Log(JNIEnv* env);
122 extern int register_android_util_MemoryIntArray(JNIEnv* env);
123 extern int register_android_util_PathParser(JNIEnv* env);
124 extern int register_android_content_StringBlock(JNIEnv* env);
125 extern int register_android_content_XmlBlock(JNIEnv* env);
126 extern int register_android_content_res_ApkAssets(JNIEnv* env);
127 extern int register_android_graphics_Canvas(JNIEnv* env);
128 extern int register_android_graphics_CanvasProperty(JNIEnv* env);
129 extern int register_android_graphics_ColorFilter(JNIEnv* env);
130 extern int register_android_graphics_DrawFilter(JNIEnv* env);
131 extern int register_android_graphics_FontFamily(JNIEnv* env);
132 extern int register_android_graphics_Matrix(JNIEnv* env);
133 extern int register_android_graphics_Paint(JNIEnv* env);
134 extern int register_android_graphics_Path(JNIEnv* env);
135 extern int register_android_graphics_PathMeasure(JNIEnv* env);
136 extern int register_android_graphics_Picture(JNIEnv*);
137 extern int register_android_graphics_Region(JNIEnv* env);
138 extern int register_android_graphics_SurfaceTexture(JNIEnv* env);
139 extern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env);
140 extern int register_android_graphics_drawable_VectorDrawable(JNIEnv* env);
141 extern int register_android_graphics_pdf_PdfDocument(JNIEnv* env);
142 extern int register_android_graphics_pdf_PdfEditor(JNIEnv* env);
143 extern int register_android_graphics_pdf_PdfRenderer(JNIEnv* env);
144 extern int register_android_view_DisplayEventReceiver(JNIEnv* env);
145 extern int register_android_view_DisplayListCanvas(JNIEnv* env);
146 extern int register_android_view_TextureLayer(JNIEnv* env);
147 extern int register_android_view_RenderNode(JNIEnv* env);
148 extern int register_android_view_RenderNodeAnimator(JNIEnv* env);
149 extern int register_android_view_Surface(JNIEnv* env);
150 extern int register_android_view_SurfaceControl(JNIEnv* env);
151 extern int register_android_view_SurfaceSession(JNIEnv* env);
152 extern int register_android_view_TextureView(JNIEnv* env);
153 extern int register_android_view_ThreadedRenderer(JNIEnv* env);
154 extern int register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper(JNIEnv *env);
155 extern int register_android_database_CursorWindow(JNIEnv* env);
156 extern int register_android_database_SQLiteConnection(JNIEnv* env);
157 extern int register_android_database_SQLiteGlobal(JNIEnv* env);
158 extern int register_android_database_SQLiteDebug(JNIEnv* env);
159 extern int register_android_nio_utils(JNIEnv* env);
160 extern int register_android_os_Debug(JNIEnv* env);
161 extern int register_android_os_GraphicsEnvironment(JNIEnv* env);
162 extern int register_android_os_HidlSupport(JNIEnv* env);
163 extern int register_android_os_HwBinder(JNIEnv *env);
164 extern int register_android_os_HwBlob(JNIEnv *env);
165 extern int register_android_os_HwParcel(JNIEnv *env);
166 extern int register_android_os_HwRemoteBinder(JNIEnv *env);
167 extern int register_android_os_MessageQueue(JNIEnv* env);
168 extern int register_android_os_Parcel(JNIEnv* env);
169 extern int register_android_os_SELinux(JNIEnv* env);
170 extern int register_android_os_VintfObject(JNIEnv *env);
171 extern int register_android_os_VintfRuntimeInfo(JNIEnv *env);
172 extern int register_android_os_SystemProperties(JNIEnv *env);
173 extern int register_android_os_SystemClock(JNIEnv* env);
174 extern int register_android_os_Trace(JNIEnv* env);
175 extern int register_android_os_FileObserver(JNIEnv *env);
176 extern int register_android_os_UEventObserver(JNIEnv* env);
177 extern int register_android_os_MemoryFile(JNIEnv* env);
178 extern int register_android_os_SharedMemory(JNIEnv* env);
179 extern int register_android_net_LocalSocketImpl(JNIEnv* env);
180 extern int register_android_net_NetworkUtils(JNIEnv* env);
181 extern int register_android_text_AndroidCharacter(JNIEnv *env);
182 extern int register_android_text_Hyphenator(JNIEnv *env);
183 extern int register_android_text_MeasuredParagraph(JNIEnv* env);
184 extern int register_android_text_StaticLayout(JNIEnv *env);
185 extern int register_android_opengl_classes(JNIEnv *env);
186 extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env);
187 extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env);
188 extern int register_android_backup_BackupDataInput(JNIEnv *env);
189 extern int register_android_backup_BackupDataOutput(JNIEnv *env);
190 extern int register_android_backup_FileBackupHelperBase(JNIEnv *env);
191 extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env);
192 extern int register_android_app_backup_FullBackup(JNIEnv *env);
193 extern int register_android_app_Activity(JNIEnv *env);
194 extern int register_android_app_ActivityThread(JNIEnv *env);
195 extern int register_android_app_NativeActivity(JNIEnv *env);
196 extern int register_android_media_RemoteDisplay(JNIEnv *env);
197 extern int register_android_util_jar_StrictJarFile(JNIEnv* env);
198 extern int register_android_view_InputChannel(JNIEnv* env);
199 extern int register_android_view_InputDevice(JNIEnv* env);
200 extern int register_android_view_InputEventReceiver(JNIEnv* env);
201 extern int register_android_view_InputEventSender(JNIEnv* env);
202 extern int register_android_view_InputQueue(JNIEnv* env);
203 extern int register_android_view_KeyCharacterMap(JNIEnv *env);
204 extern int register_android_view_KeyEvent(JNIEnv* env);
205 extern int register_android_view_MotionEvent(JNIEnv* env);
206 extern int register_android_view_PointerIcon(JNIEnv* env);
207 extern int register_android_view_VelocityTracker(JNIEnv* env);
208 extern int register_android_content_res_ObbScanner(JNIEnv* env);
209 extern int register_android_content_res_Configuration(JNIEnv* env);
210 extern int register_android_animation_PropertyValuesHolder(JNIEnv *env);
211 extern int register_android_security_Scrypt(JNIEnv *env);
212 extern int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env);
213 extern int register_com_android_internal_net_NetworkStatsFactory(JNIEnv *env);
214 extern int register_com_android_internal_os_ClassLoaderFactory(JNIEnv* env);
215 extern int register_com_android_internal_os_FuseAppLoop(JNIEnv* env);
216 extern int register_com_android_internal_os_Zygote(JNIEnv *env);
217 extern int register_com_android_internal_os_ZygoteInit(JNIEnv *env);
218 extern int register_com_android_internal_util_VirtualRefBasePtr(JNIEnv *env);
219
220 static AndroidRuntime* gCurRuntime = NULL;
221
222 /*
223 * Code written in the Java Programming Language calls here from main().
224 */
com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv * env,jobject clazz)225 static void com_android_internal_os_RuntimeInit_nativeFinishInit(JNIEnv* env, jobject clazz)
226 {
227 gCurRuntime->onStarted();
228 }
229
com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv * env,jobject clazz)230 static void com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env, jobject clazz)
231 {
232 gCurRuntime->onZygoteInit();
233 }
234
com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv * env,jobject clazz,jboolean exitWithoutCleanup)235 static void com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup(JNIEnv* env,
236 jobject clazz, jboolean exitWithoutCleanup)
237 {
238 gCurRuntime->setExitWithoutCleanup(exitWithoutCleanup);
239 }
240
241 /*
242 * JNI registration.
243 */
244
register_com_android_internal_os_RuntimeInit(JNIEnv * env)245 int register_com_android_internal_os_RuntimeInit(JNIEnv* env)
246 {
247 const JNINativeMethod methods[] = {
248 { "nativeFinishInit", "()V",
249 (void*) com_android_internal_os_RuntimeInit_nativeFinishInit },
250 { "nativeSetExitWithoutCleanup", "(Z)V",
251 (void*) com_android_internal_os_RuntimeInit_nativeSetExitWithoutCleanup },
252 };
253 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit",
254 methods, NELEM(methods));
255 }
256
register_com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv * env)257 int register_com_android_internal_os_ZygoteInit_nativeZygoteInit(JNIEnv* env)
258 {
259 const JNINativeMethod methods[] = {
260 { "nativeZygoteInit", "()V",
261 (void*) com_android_internal_os_ZygoteInit_nativeZygoteInit },
262 };
263 return jniRegisterNativeMethods(env, "com/android/internal/os/ZygoteInit",
264 methods, NELEM(methods));
265 }
266
267 // ----------------------------------------------------------------------
268
269 /*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL;
270
AndroidRuntime(char * argBlockStart,const size_t argBlockLength)271 AndroidRuntime::AndroidRuntime(char* argBlockStart, const size_t argBlockLength) :
272 mExitWithoutCleanup(false),
273 mArgBlockStart(argBlockStart),
274 mArgBlockLength(argBlockLength)
275 {
276 SkGraphics::Init();
277
278 // Pre-allocate enough space to hold a fair number of options.
279 mOptions.setCapacity(20);
280
281 assert(gCurRuntime == NULL); // one per process
282 gCurRuntime = this;
283 }
284
~AndroidRuntime()285 AndroidRuntime::~AndroidRuntime()
286 {
287 }
288
289 /*
290 * Register native methods using JNI.
291 */
registerNativeMethods(JNIEnv * env,const char * className,const JNINativeMethod * gMethods,int numMethods)292 /*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env,
293 const char* className, const JNINativeMethod* gMethods, int numMethods)
294 {
295 return jniRegisterNativeMethods(env, className, gMethods, numMethods);
296 }
297
setArgv0(const char * argv0,bool setProcName)298 void AndroidRuntime::setArgv0(const char* argv0, bool setProcName) {
299 if (setProcName) {
300 int len = strlen(argv0);
301 if (len < 15) {
302 pthread_setname_np(pthread_self(), argv0);
303 } else {
304 pthread_setname_np(pthread_self(), argv0 + len - 15);
305 }
306 }
307 memset(mArgBlockStart, 0, mArgBlockLength);
308 strlcpy(mArgBlockStart, argv0, mArgBlockLength);
309 }
310
callMain(const String8 & className,jclass clazz,const Vector<String8> & args)311 status_t AndroidRuntime::callMain(const String8& className, jclass clazz,
312 const Vector<String8>& args)
313 {
314 JNIEnv* env;
315 jmethodID methodId;
316
317 ALOGD("Calling main entry %s", className.string());
318
319 env = getJNIEnv();
320 if (clazz == NULL || env == NULL) {
321 return UNKNOWN_ERROR;
322 }
323
324 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V");
325 if (methodId == NULL) {
326 ALOGE("ERROR: could not find method %s.main(String[])\n", className.string());
327 return UNKNOWN_ERROR;
328 }
329
330 /*
331 * We want to call main() with a String array with our arguments in it.
332 * Create an array and populate it.
333 */
334 jclass stringClass;
335 jobjectArray strArray;
336
337 const size_t numArgs = args.size();
338 stringClass = env->FindClass("java/lang/String");
339 strArray = env->NewObjectArray(numArgs, stringClass, NULL);
340
341 for (size_t i = 0; i < numArgs; i++) {
342 jstring argStr = env->NewStringUTF(args[i].string());
343 env->SetObjectArrayElement(strArray, i, argStr);
344 }
345
346 env->CallStaticVoidMethod(clazz, methodId, strArray);
347 return NO_ERROR;
348 }
349
350 /*
351 * The VM calls this through the "exit" hook.
352 */
runtime_exit(int code)353 static void runtime_exit(int code)
354 {
355 gCurRuntime->exit(code);
356 }
357
358 /*
359 * The VM calls this through the "vfprintf" hook.
360 *
361 * We ignore "fp" and just write the results to the log file.
362 */
runtime_vfprintf(FILE * fp,const char * format,va_list ap)363 static void runtime_vfprintf(FILE* fp, const char* format, va_list ap)
364 {
365 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap);
366 }
367
368 /**
369 * The VM calls this when mutex contention debugging is enabled to
370 * determine whether or not the blocked thread was a "sensitive thread"
371 * for user responsiveness/smoothess.
372 *
373 * Our policy for this is whether or not we're tracing any StrictMode
374 * events on this thread (which we might've inherited via Binder calls
375 * into us)
376 */
runtime_isSensitiveThread()377 static bool runtime_isSensitiveThread() {
378 IPCThreadState* state = IPCThreadState::selfOrNull();
379 return state && state->getStrictModePolicy() != 0;
380 }
381
hasDir(const char * dir)382 static int hasDir(const char* dir)
383 {
384 struct stat s;
385 int res = stat(dir, &s);
386 if (res == 0) {
387 return S_ISDIR(s.st_mode);
388 }
389 return 0;
390 }
391
hasFile(const char * file)392 static bool hasFile(const char* file) {
393 struct stat s;
394 int res = stat(file, &s);
395 if (res == 0) {
396 return S_ISREG(s.st_mode);
397 }
398 return false;
399 }
400
401 /*
402 * Read the persistent locale. Inspects the following system properties
403 * (in order) and returns the first non-empty property in the list :
404 *
405 * (1) persist.sys.locale
406 * (2) persist.sys.language/country/localevar (country and localevar are
407 * inspected iff. language is non-empty.
408 * (3) ro.product.locale
409 * (4) ro.product.locale.language/region
410 *
411 * Note that we need to inspect persist.sys.language/country/localevar to
412 * preserve language settings for devices that are upgrading from Lollipop
413 * to M. The same goes for ro.product.locale.language/region as well.
414 */
readLocale()415 const std::string readLocale()
416 {
417 const std::string locale = GetProperty("persist.sys.locale", "");
418 if (!locale.empty()) {
419 return locale;
420 }
421
422 const std::string language = GetProperty("persist.sys.language", "");
423 if (!language.empty()) {
424 const std::string country = GetProperty("persist.sys.country", "");
425 const std::string variant = GetProperty("persist.sys.localevar", "");
426
427 std::string out = language;
428 if (!country.empty()) {
429 out = out + "-" + country;
430 }
431
432 if (!variant.empty()) {
433 out = out + "-" + variant;
434 }
435
436 return out;
437 }
438
439 const std::string productLocale = GetProperty("ro.product.locale", "");
440 if (!productLocale.empty()) {
441 return productLocale;
442 }
443
444 // If persist.sys.locale and ro.product.locale are missing,
445 // construct a locale value from the individual locale components.
446 const std::string productLanguage = GetProperty("ro.product.locale.language", "en");
447 const std::string productRegion = GetProperty("ro.product.locale.region", "US");
448
449 return productLanguage + "-" + productRegion;
450 }
451
addOption(const char * optionString,void * extraInfo)452 void AndroidRuntime::addOption(const char* optionString, void* extraInfo)
453 {
454 JavaVMOption opt;
455 opt.optionString = optionString;
456 opt.extraInfo = extraInfo;
457 mOptions.add(opt);
458 }
459
460 /*
461 * Parse a property containing space-separated options that should be
462 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap".
463 *
464 * This will cut up "extraOptsBuf" as we chop it into individual options.
465 *
466 * If "quotingArg" is non-null, it is passed before each extra option in mOptions.
467 *
468 * Adds the strings, if any, to mOptions.
469 */
parseExtraOpts(char * extraOptsBuf,const char * quotingArg)470 void AndroidRuntime::parseExtraOpts(char* extraOptsBuf, const char* quotingArg)
471 {
472 char* start = extraOptsBuf;
473 char* end = NULL;
474 while (*start != '\0') {
475 while (*start == ' ') /* skip leading whitespace */
476 start++;
477 if (*start == '\0') /* was trailing ws, bail */
478 break;
479
480 end = start+1;
481 while (*end != ' ' && *end != '\0') /* find end of token */
482 end++;
483 if (*end == ' ')
484 *end++ = '\0'; /* mark end, advance to indicate more */
485
486 if (quotingArg != NULL) {
487 addOption(quotingArg);
488 }
489 addOption(start);
490 start = end;
491 }
492 }
493
494 /*
495 * Reads a "property" into "buffer" with a default of "defaultArg". If
496 * the property is non-empty, it is treated as a runtime option such
497 * as "-Xmx32m".
498 *
499 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
500 *
501 * If an argument is found, it is added to mOptions.
502 *
503 * If an option is found, it is added to mOptions and true is
504 * returned. Otherwise false is returned.
505 */
parseRuntimeOption(const char * property,char * buffer,const char * runtimeArg,const char * defaultArg)506 bool AndroidRuntime::parseRuntimeOption(const char* property,
507 char* buffer,
508 const char* runtimeArg,
509 const char* defaultArg)
510 {
511 strcpy(buffer, runtimeArg);
512 size_t runtimeArgLen = strlen(runtimeArg);
513 property_get(property, buffer+runtimeArgLen, defaultArg);
514 if (buffer[runtimeArgLen] == '\0') {
515 return false;
516 }
517 addOption(buffer);
518 return true;
519 }
520
521 /*
522 * Reads a "property" into "buffer". If the property is non-empty, it
523 * is treated as a dex2oat compiler option that should be
524 * passed as a quoted option, e.g. "-Ximage-compiler-option --compiler-filter=assume-verified".
525 *
526 * The "compilerArg" is a prefix for the option such as "--compiler-filter=".
527 *
528 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
529 *
530 * If an option is found, it is added to mOptions and true is
531 * returned. Otherwise false is returned.
532 */
parseCompilerOption(const char * property,char * buffer,const char * compilerArg,const char * quotingArg)533 bool AndroidRuntime::parseCompilerOption(const char* property,
534 char* buffer,
535 const char* compilerArg,
536 const char* quotingArg)
537 {
538 strcpy(buffer, compilerArg);
539 size_t compilerArgLen = strlen(compilerArg);
540 property_get(property, buffer+compilerArgLen, "");
541 if (buffer[compilerArgLen] == '\0') {
542 return false;
543 }
544 addOption(quotingArg);
545 addOption(buffer);
546 return true;
547 }
548
549 /*
550 * Reads a "property" into "buffer". If the property is non-empty, it
551 * is treated as a dex2oat compiler runtime option that should be
552 * passed as a quoted option, e.g. "-Ximage-compiler-option
553 * --runtime-arg -Ximage-compiler-option -Xmx32m".
554 *
555 * The "runtimeArg" is a prefix for the option such as "-Xms" or "-Xmx".
556 *
557 * The "quotingArg" should be "-Ximage-compiler-option" or "-Xcompiler-option".
558 *
559 * If an option is found, it is added to mOptions and true is
560 * returned. Otherwise false is returned.
561 */
parseCompilerRuntimeOption(const char * property,char * buffer,const char * runtimeArg,const char * quotingArg)562 bool AndroidRuntime::parseCompilerRuntimeOption(const char* property,
563 char* buffer,
564 const char* runtimeArg,
565 const char* quotingArg)
566 {
567 strcpy(buffer, runtimeArg);
568 size_t runtimeArgLen = strlen(runtimeArg);
569 property_get(property, buffer+runtimeArgLen, "");
570 if (buffer[runtimeArgLen] == '\0') {
571 return false;
572 }
573 addOption(quotingArg);
574 addOption("--runtime-arg");
575 addOption(quotingArg);
576 addOption(buffer);
577 return true;
578 }
579
580 /*
581 * Start the Dalvik Virtual Machine.
582 *
583 * Various arguments, most determined by system properties, are passed in.
584 * The "mOptions" vector is updated.
585 *
586 * CAUTION: when adding options in here, be careful not to put the
587 * char buffer inside a nested scope. Adding the buffer to the
588 * options using mOptions.add() does not copy the buffer, so if the
589 * buffer goes out of scope the option may be overwritten. It's best
590 * to put the buffer at the top of the function so that it is more
591 * unlikely that someone will surround it in a scope at a later time
592 * and thus introduce a bug.
593 *
594 * Returns 0 on success.
595 */
startVm(JavaVM ** pJavaVM,JNIEnv ** pEnv,bool zygote)596 int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote)
597 {
598 JavaVMInitArgs initArgs;
599 char propBuf[PROPERTY_VALUE_MAX];
600 char stackTraceFileBuf[sizeof("-Xstacktracefile:")-1 + PROPERTY_VALUE_MAX];
601 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX];
602 char heapstartsizeOptsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
603 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
604 char heapgrowthlimitOptsBuf[sizeof("-XX:HeapGrowthLimit=")-1 + PROPERTY_VALUE_MAX];
605 char heapminfreeOptsBuf[sizeof("-XX:HeapMinFree=")-1 + PROPERTY_VALUE_MAX];
606 char heapmaxfreeOptsBuf[sizeof("-XX:HeapMaxFree=")-1 + PROPERTY_VALUE_MAX];
607 char usejitOptsBuf[sizeof("-Xusejit:")-1 + PROPERTY_VALUE_MAX];
608 char jitmaxsizeOptsBuf[sizeof("-Xjitmaxsize:")-1 + PROPERTY_VALUE_MAX];
609 char jitinitialsizeOptsBuf[sizeof("-Xjitinitialsize:")-1 + PROPERTY_VALUE_MAX];
610 char jitthresholdOptsBuf[sizeof("-Xjitthreshold:")-1 + PROPERTY_VALUE_MAX];
611 char useJitProfilesOptsBuf[sizeof("-Xjitsaveprofilinginfo:")-1 + PROPERTY_VALUE_MAX];
612 char jitprithreadweightOptBuf[sizeof("-Xjitprithreadweight:")-1 + PROPERTY_VALUE_MAX];
613 char jittransitionweightOptBuf[sizeof("-Xjittransitionweight:")-1 + PROPERTY_VALUE_MAX];
614 char hotstartupsamplesOptsBuf[sizeof("-Xps-hot-startup-method-samples:")-1 + PROPERTY_VALUE_MAX];
615 char madviseRandomOptsBuf[sizeof("-XX:MadviseRandomAccess:")-1 + PROPERTY_VALUE_MAX];
616 char gctypeOptsBuf[sizeof("-Xgc:")-1 + PROPERTY_VALUE_MAX];
617 char backgroundgcOptsBuf[sizeof("-XX:BackgroundGC=")-1 + PROPERTY_VALUE_MAX];
618 char heaptargetutilizationOptsBuf[sizeof("-XX:HeapTargetUtilization=")-1 + PROPERTY_VALUE_MAX];
619 char foregroundHeapGrowthMultiplierOptsBuf[
620 sizeof("-XX:ForegroundHeapGrowthMultiplier=")-1 + PROPERTY_VALUE_MAX];
621 char cachePruneBuf[sizeof("-Xzygote-max-boot-retry=")-1 + PROPERTY_VALUE_MAX];
622 char dex2oatXmsImageFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
623 char dex2oatXmxImageFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
624 char dex2oatXmsFlagsBuf[sizeof("-Xms")-1 + PROPERTY_VALUE_MAX];
625 char dex2oatXmxFlagsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX];
626 char dex2oatCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
627 char dex2oatImageCompilerFilterBuf[sizeof("--compiler-filter=")-1 + PROPERTY_VALUE_MAX];
628 char dex2oatThreadsBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
629 char dex2oatThreadsImageBuf[sizeof("-j")-1 + PROPERTY_VALUE_MAX];
630 char dex2oat_isa_variant_key[PROPERTY_KEY_MAX];
631 char dex2oat_isa_variant[sizeof("--instruction-set-variant=") -1 + PROPERTY_VALUE_MAX];
632 char dex2oat_isa_features_key[PROPERTY_KEY_MAX];
633 char dex2oat_isa_features[sizeof("--instruction-set-features=") -1 + PROPERTY_VALUE_MAX];
634 char dex2oatFlagsBuf[PROPERTY_VALUE_MAX];
635 char dex2oatImageFlagsBuf[PROPERTY_VALUE_MAX];
636 char extraOptsBuf[PROPERTY_VALUE_MAX];
637 char voldDecryptBuf[PROPERTY_VALUE_MAX];
638 enum {
639 kEMDefault,
640 kEMIntPortable,
641 kEMIntFast,
642 kEMJitCompiler,
643 } executionMode = kEMDefault;
644 char localeOption[sizeof("-Duser.locale=") + PROPERTY_VALUE_MAX];
645 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:")-1 + PROPERTY_VALUE_MAX];
646 char nativeBridgeLibrary[sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX];
647 char cpuAbiListBuf[sizeof("--cpu-abilist=") + PROPERTY_VALUE_MAX];
648 char methodTraceFileBuf[sizeof("-Xmethod-trace-file:") + PROPERTY_VALUE_MAX];
649 char methodTraceFileSizeBuf[sizeof("-Xmethod-trace-file-size:") + PROPERTY_VALUE_MAX];
650 std::string fingerprintBuf;
651 char jdwpProviderBuf[sizeof("-XjdwpProvider:") - 1 + PROPERTY_VALUE_MAX];
652
653 bool checkJni = false;
654 property_get("dalvik.vm.checkjni", propBuf, "");
655 if (strcmp(propBuf, "true") == 0) {
656 checkJni = true;
657 } else if (strcmp(propBuf, "false") != 0) {
658 /* property is neither true nor false; fall back on kernel parameter */
659 property_get("ro.kernel.android.checkjni", propBuf, "");
660 if (propBuf[0] == '1') {
661 checkJni = true;
662 }
663 }
664 ALOGV("CheckJNI is %s\n", checkJni ? "ON" : "OFF");
665 if (checkJni) {
666 /* extended JNI checking */
667 addOption("-Xcheck:jni");
668
669 /* with -Xcheck:jni, this provides a JNI function call trace */
670 //addOption("-verbose:jni");
671 }
672
673 property_get("dalvik.vm.execution-mode", propBuf, "");
674 if (strcmp(propBuf, "int:portable") == 0) {
675 executionMode = kEMIntPortable;
676 } else if (strcmp(propBuf, "int:fast") == 0) {
677 executionMode = kEMIntFast;
678 } else if (strcmp(propBuf, "int:jit") == 0) {
679 executionMode = kEMJitCompiler;
680 }
681
682 // If dalvik.vm.stack-trace-dir is set, it enables the "new" stack trace
683 // dump scheme and a new file is created for each stack dump. If it isn't set,
684 // the old scheme is enabled.
685 property_get("dalvik.vm.stack-trace-dir", propBuf, "");
686 if (strlen(propBuf) > 0) {
687 addOption("-Xusetombstonedtraces");
688 } else {
689 parseRuntimeOption("dalvik.vm.stack-trace-file", stackTraceFileBuf, "-Xstacktracefile:");
690 }
691
692 strcpy(jniOptsBuf, "-Xjniopts:");
693 if (parseRuntimeOption("dalvik.vm.jniopts", jniOptsBuf, "-Xjniopts:")) {
694 ALOGI("JNI options: '%s'\n", jniOptsBuf);
695 }
696
697 /* route exit() to our handler */
698 addOption("exit", (void*) runtime_exit);
699
700 /* route fprintf() to our handler */
701 addOption("vfprintf", (void*) runtime_vfprintf);
702
703 /* register the framework-specific "is sensitive thread" hook */
704 addOption("sensitiveThread", (void*) runtime_isSensitiveThread);
705
706 /* enable verbose; standard options are { jni, gc, class } */
707 //addOption("-verbose:jni");
708 addOption("-verbose:gc");
709 //addOption("-verbose:class");
710
711 /*
712 * The default starting and maximum size of the heap. Larger
713 * values should be specified in a product property override.
714 */
715 parseRuntimeOption("dalvik.vm.heapstartsize", heapstartsizeOptsBuf, "-Xms", "4m");
716 parseRuntimeOption("dalvik.vm.heapsize", heapsizeOptsBuf, "-Xmx", "16m");
717
718 parseRuntimeOption("dalvik.vm.heapgrowthlimit", heapgrowthlimitOptsBuf, "-XX:HeapGrowthLimit=");
719 parseRuntimeOption("dalvik.vm.heapminfree", heapminfreeOptsBuf, "-XX:HeapMinFree=");
720 parseRuntimeOption("dalvik.vm.heapmaxfree", heapmaxfreeOptsBuf, "-XX:HeapMaxFree=");
721 parseRuntimeOption("dalvik.vm.heaptargetutilization",
722 heaptargetutilizationOptsBuf,
723 "-XX:HeapTargetUtilization=");
724
725 /* Foreground heap growth multiplier option */
726 parseRuntimeOption("dalvik.vm.foreground-heap-growth-multiplier",
727 foregroundHeapGrowthMultiplierOptsBuf,
728 "-XX:ForegroundHeapGrowthMultiplier=");
729
730 /*
731 * JIT related options.
732 */
733 parseRuntimeOption("dalvik.vm.usejit", usejitOptsBuf, "-Xusejit:");
734 parseRuntimeOption("dalvik.vm.jitmaxsize", jitmaxsizeOptsBuf, "-Xjitmaxsize:");
735 parseRuntimeOption("dalvik.vm.jitinitialsize", jitinitialsizeOptsBuf, "-Xjitinitialsize:");
736 parseRuntimeOption("dalvik.vm.jitthreshold", jitthresholdOptsBuf, "-Xjitthreshold:");
737 property_get("dalvik.vm.usejitprofiles", useJitProfilesOptsBuf, "");
738 if (strcmp(useJitProfilesOptsBuf, "true") == 0) {
739 addOption("-Xjitsaveprofilinginfo");
740 }
741
742 parseRuntimeOption("dalvik.vm.jitprithreadweight",
743 jitprithreadweightOptBuf,
744 "-Xjitprithreadweight:");
745
746 parseRuntimeOption("dalvik.vm.jittransitionweight",
747 jittransitionweightOptBuf,
748 "-Xjittransitionweight:");
749
750 property_get("dalvik.vm.profilebootimage", propBuf, "");
751 if (strcmp(propBuf, "true") == 0) {
752 addOption("-Xps-profile-boot-class-path");
753 addOption("-Xps-profile-aot-code");
754 }
755
756 /*
757 * Madvise related options.
758 */
759 parseRuntimeOption("dalvik.vm.madvise-random", madviseRandomOptsBuf, "-XX:MadviseRandomAccess:");
760
761 /*
762 * Profile related options.
763 */
764 parseRuntimeOption("dalvik.vm.hot-startup-method-samples", hotstartupsamplesOptsBuf,
765 "-Xps-hot-startup-method-samples:");
766
767 property_get("ro.config.low_ram", propBuf, "");
768 if (strcmp(propBuf, "true") == 0) {
769 addOption("-XX:LowMemoryMode");
770 }
771
772 parseRuntimeOption("dalvik.vm.gctype", gctypeOptsBuf, "-Xgc:");
773 parseRuntimeOption("dalvik.vm.backgroundgctype", backgroundgcOptsBuf, "-XX:BackgroundGC=");
774
775 /*
776 * Enable debugging only for apps forked from zygote.
777 */
778 if (zygote) {
779 // Set the JDWP provider and required arguments. By default let the runtime choose how JDWP is
780 // implemented. When this is not set the runtime defaults to not allowing JDWP.
781 addOption("-XjdwpOptions:suspend=n,server=y");
782 parseRuntimeOption("dalvik.vm.jdwp-provider",
783 jdwpProviderBuf,
784 "-XjdwpProvider:",
785 "default");
786 }
787
788 parseRuntimeOption("dalvik.vm.lockprof.threshold",
789 lockProfThresholdBuf,
790 "-Xlockprofthreshold:");
791
792 if (executionMode == kEMIntPortable) {
793 addOption("-Xint:portable");
794 } else if (executionMode == kEMIntFast) {
795 addOption("-Xint:fast");
796 } else if (executionMode == kEMJitCompiler) {
797 addOption("-Xint:jit");
798 }
799
800 // If we are booting without the real /data, don't spend time compiling.
801 property_get("vold.decrypt", voldDecryptBuf, "");
802 bool skip_compilation = ((strcmp(voldDecryptBuf, "trigger_restart_min_framework") == 0) ||
803 (strcmp(voldDecryptBuf, "1") == 0));
804
805 // Extra options for boot.art/boot.oat image generation.
806 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xms", dex2oatXmsImageFlagsBuf,
807 "-Xms", "-Ximage-compiler-option");
808 parseCompilerRuntimeOption("dalvik.vm.image-dex2oat-Xmx", dex2oatXmxImageFlagsBuf,
809 "-Xmx", "-Ximage-compiler-option");
810 if (skip_compilation) {
811 addOption("-Ximage-compiler-option");
812 addOption("--compiler-filter=assume-verified");
813 } else {
814 parseCompilerOption("dalvik.vm.image-dex2oat-filter", dex2oatImageCompilerFilterBuf,
815 "--compiler-filter=", "-Ximage-compiler-option");
816 }
817
818 // If there is a boot profile, it takes precedence over the image and preloaded classes.
819 if (hasFile("/system/etc/boot-image.prof")) {
820 addOption("-Ximage-compiler-option");
821 addOption("--profile-file=/system/etc/boot-image.prof");
822 addOption("-Ximage-compiler-option");
823 addOption("--compiler-filter=speed-profile");
824 } else {
825 // Make sure there is a preloaded-classes file.
826 if (!hasFile("/system/etc/preloaded-classes")) {
827 ALOGE("Missing preloaded-classes file, /system/etc/preloaded-classes not found: %s\n",
828 strerror(errno));
829 return -1;
830 }
831 addOption("-Ximage-compiler-option");
832 addOption("--image-classes=/system/etc/preloaded-classes");
833
834 // If there is a compiled-classes file, push it.
835 if (hasFile("/system/etc/compiled-classes")) {
836 addOption("-Ximage-compiler-option");
837 addOption("--compiled-classes=/system/etc/compiled-classes");
838 }
839
840 // If there is a dirty-image-objects file, push it.
841 if (hasFile("/system/etc/dirty-image-objects")) {
842 addOption("-Ximage-compiler-option");
843 addOption("--dirty-image-objects=/system/etc/dirty-image-objects");
844 }
845 }
846
847 property_get("dalvik.vm.image-dex2oat-flags", dex2oatImageFlagsBuf, "");
848 parseExtraOpts(dex2oatImageFlagsBuf, "-Ximage-compiler-option");
849
850 // Extra options for DexClassLoader.
851 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xms", dex2oatXmsFlagsBuf,
852 "-Xms", "-Xcompiler-option");
853 parseCompilerRuntimeOption("dalvik.vm.dex2oat-Xmx", dex2oatXmxFlagsBuf,
854 "-Xmx", "-Xcompiler-option");
855 if (skip_compilation) {
856 addOption("-Xcompiler-option");
857 addOption("--compiler-filter=assume-verified");
858
859 // We skip compilation when a minimal runtime is brought up for decryption. In that case
860 // /data is temporarily backed by a tmpfs, which is usually small.
861 // If the system image contains prebuilts, they will be relocated into the tmpfs. In this
862 // specific situation it is acceptable to *not* relocate and run out of the prebuilts
863 // directly instead.
864 addOption("--runtime-arg");
865 addOption("-Xnorelocate");
866 } else {
867 parseCompilerOption("dalvik.vm.dex2oat-filter", dex2oatCompilerFilterBuf,
868 "--compiler-filter=", "-Xcompiler-option");
869 }
870 parseCompilerOption("dalvik.vm.dex2oat-threads", dex2oatThreadsBuf, "-j", "-Xcompiler-option");
871 parseCompilerOption("dalvik.vm.image-dex2oat-threads", dex2oatThreadsImageBuf, "-j",
872 "-Ximage-compiler-option");
873
874 // The runtime will compile a boot image, when necessary, not using installd. Thus, we need to
875 // pass the instruction-set-features/variant as an image-compiler-option.
876 // TODO: Find a better way for the instruction-set.
877 #if defined(__arm__)
878 constexpr const char* instruction_set = "arm";
879 #elif defined(__aarch64__)
880 constexpr const char* instruction_set = "arm64";
881 #elif defined(__mips__) && !defined(__LP64__)
882 constexpr const char* instruction_set = "mips";
883 #elif defined(__mips__) && defined(__LP64__)
884 constexpr const char* instruction_set = "mips64";
885 #elif defined(__i386__)
886 constexpr const char* instruction_set = "x86";
887 #elif defined(__x86_64__)
888 constexpr const char* instruction_set = "x86_64";
889 #else
890 constexpr const char* instruction_set = "unknown";
891 #endif
892 // Note: it is OK to reuse the buffer, as the values are exactly the same between
893 // * compiler-option, used for runtime compilation (DexClassLoader)
894 // * image-compiler-option, used for boot-image compilation on device
895
896 // Copy the variant.
897 sprintf(dex2oat_isa_variant_key, "dalvik.vm.isa.%s.variant", instruction_set);
898 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
899 "--instruction-set-variant=", "-Ximage-compiler-option");
900 parseCompilerOption(dex2oat_isa_variant_key, dex2oat_isa_variant,
901 "--instruction-set-variant=", "-Xcompiler-option");
902 // Copy the features.
903 sprintf(dex2oat_isa_features_key, "dalvik.vm.isa.%s.features", instruction_set);
904 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
905 "--instruction-set-features=", "-Ximage-compiler-option");
906 parseCompilerOption(dex2oat_isa_features_key, dex2oat_isa_features,
907 "--instruction-set-features=", "-Xcompiler-option");
908
909
910 property_get("dalvik.vm.dex2oat-flags", dex2oatFlagsBuf, "");
911 parseExtraOpts(dex2oatFlagsBuf, "-Xcompiler-option");
912
913 /* extra options; parse this late so it overrides others */
914 property_get("dalvik.vm.extra-opts", extraOptsBuf, "");
915 parseExtraOpts(extraOptsBuf, NULL);
916
917 /* Set the properties for locale */
918 {
919 strcpy(localeOption, "-Duser.locale=");
920 const std::string locale = readLocale();
921 strncat(localeOption, locale.c_str(), PROPERTY_VALUE_MAX);
922 addOption(localeOption);
923 }
924
925 // Trace files are stored in /data/misc/trace which is writable only in debug mode.
926 property_get("ro.debuggable", propBuf, "0");
927 if (strcmp(propBuf, "1") == 0) {
928 property_get("dalvik.vm.method-trace", propBuf, "false");
929 if (strcmp(propBuf, "true") == 0) {
930 addOption("-Xmethod-trace");
931 parseRuntimeOption("dalvik.vm.method-trace-file",
932 methodTraceFileBuf,
933 "-Xmethod-trace-file:");
934 parseRuntimeOption("dalvik.vm.method-trace-file-siz",
935 methodTraceFileSizeBuf,
936 "-Xmethod-trace-file-size:");
937 property_get("dalvik.vm.method-trace-stream", propBuf, "false");
938 if (strcmp(propBuf, "true") == 0) {
939 addOption("-Xmethod-trace-stream");
940 }
941 }
942 }
943
944 // Native bridge library. "0" means that native bridge is disabled.
945 property_get("ro.dalvik.vm.native.bridge", propBuf, "");
946 if (propBuf[0] == '\0') {
947 ALOGW("ro.dalvik.vm.native.bridge is not expected to be empty");
948 } else if (strcmp(propBuf, "0") != 0) {
949 snprintf(nativeBridgeLibrary, sizeof("-XX:NativeBridge=") + PROPERTY_VALUE_MAX,
950 "-XX:NativeBridge=%s", propBuf);
951 addOption(nativeBridgeLibrary);
952 }
953
954 #if defined(__LP64__)
955 const char* cpu_abilist_property_name = "ro.product.cpu.abilist64";
956 #else
957 const char* cpu_abilist_property_name = "ro.product.cpu.abilist32";
958 #endif // defined(__LP64__)
959 property_get(cpu_abilist_property_name, propBuf, "");
960 if (propBuf[0] == '\0') {
961 ALOGE("%s is not expected to be empty", cpu_abilist_property_name);
962 return -1;
963 }
964 snprintf(cpuAbiListBuf, sizeof(cpuAbiListBuf), "--cpu-abilist=%s", propBuf);
965 addOption(cpuAbiListBuf);
966
967 // Dalvik-cache pruning counter.
968 parseRuntimeOption("dalvik.vm.zygote.max-boot-retry", cachePruneBuf,
969 "-Xzygote-max-boot-retry=");
970
971 /*
972 * When running with debug.generate-debug-info, add --generate-debug-info to
973 * the compiler options so that the boot image, if it is compiled on device,
974 * will include native debugging information.
975 */
976 property_get("debug.generate-debug-info", propBuf, "");
977 if (strcmp(propBuf, "true") == 0) {
978 addOption("-Xcompiler-option");
979 addOption("--generate-debug-info");
980 addOption("-Ximage-compiler-option");
981 addOption("--generate-debug-info");
982 }
983
984 // The mini-debug-info makes it possible to backtrace through JIT code.
985 if (property_get_bool("dalvik.vm.minidebuginfo", 0)) {
986 addOption("-Xcompiler-option");
987 addOption("--generate-mini-debug-info");
988 }
989
990 /*
991 * Retrieve the build fingerprint and provide it to the runtime. That way, ANR dumps will
992 * contain the fingerprint and can be parsed.
993 * Fingerprints are potentially longer than PROPERTY_VALUE_MAX, so parseRuntimeOption() cannot
994 * be used here.
995 * Do not ever re-assign fingerprintBuf as its c_str() value is stored in mOptions.
996 */
997 std::string fingerprint = GetProperty("ro.build.fingerprint", "");
998 if (!fingerprint.empty()) {
999 fingerprintBuf = "-Xfingerprint:" + fingerprint;
1000 addOption(fingerprintBuf.c_str());
1001 }
1002
1003 initArgs.version = JNI_VERSION_1_4;
1004 initArgs.options = mOptions.editArray();
1005 initArgs.nOptions = mOptions.size();
1006 initArgs.ignoreUnrecognized = JNI_FALSE;
1007
1008 /*
1009 * Initialize the VM.
1010 *
1011 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread.
1012 * If this call succeeds, the VM is ready, and we can start issuing
1013 * JNI calls.
1014 */
1015 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) {
1016 ALOGE("JNI_CreateJavaVM failed\n");
1017 return -1;
1018 }
1019
1020 return 0;
1021 }
1022
toSlashClassName(const char * className)1023 char* AndroidRuntime::toSlashClassName(const char* className)
1024 {
1025 char* result = strdup(className);
1026 for (char* cp = result; *cp != '\0'; cp++) {
1027 if (*cp == '.') {
1028 *cp = '/';
1029 }
1030 }
1031 return result;
1032 }
1033
1034 /** Create a Java string from an ASCII or Latin-1 string */
NewStringLatin1(JNIEnv * env,const char * bytes)1035 jstring AndroidRuntime::NewStringLatin1(JNIEnv* env, const char* bytes) {
1036 if (!bytes) return NULL;
1037 int length = strlen(bytes);
1038 jchar* buffer = (jchar *)alloca(length * sizeof(jchar));
1039 if (!buffer) return NULL;
1040 jchar* chp = buffer;
1041 for (int i = 0; i < length; i++) {
1042 *chp++ = *bytes++;
1043 }
1044 return env->NewString(buffer, length);
1045 }
1046
1047
1048 /*
1049 * Start the Android runtime. This involves starting the virtual machine
1050 * and calling the "static void main(String[] args)" method in the class
1051 * named by "className".
1052 *
1053 * Passes the main function two arguments, the class name and the specified
1054 * options string.
1055 */
start(const char * className,const Vector<String8> & options,bool zygote)1056 void AndroidRuntime::start(const char* className, const Vector<String8>& options, bool zygote)
1057 {
1058 ALOGD(">>>>>> START %s uid %d <<<<<<\n",
1059 className != NULL ? className : "(unknown)", getuid());
1060
1061 static const String8 startSystemServer("start-system-server");
1062
1063 /*
1064 * 'startSystemServer == true' means runtime is obsolete and not run from
1065 * init.rc anymore, so we print out the boot start event here.
1066 */
1067 for (size_t i = 0; i < options.size(); ++i) {
1068 if (options[i] == startSystemServer) {
1069 /* track our progress through the boot sequence */
1070 const int LOG_BOOT_PROGRESS_START = 3000;
1071 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, ns2ms(systemTime(SYSTEM_TIME_MONOTONIC)));
1072 }
1073 }
1074
1075 const char* rootDir = getenv("ANDROID_ROOT");
1076 if (rootDir == NULL) {
1077 rootDir = "/system";
1078 if (!hasDir("/system")) {
1079 LOG_FATAL("No root directory specified, and /android does not exist.");
1080 return;
1081 }
1082 setenv("ANDROID_ROOT", rootDir, 1);
1083 }
1084
1085 //const char* kernelHack = getenv("LD_ASSUME_KERNEL");
1086 //ALOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack);
1087
1088 /* start the virtual machine */
1089 JniInvocation jni_invocation;
1090 jni_invocation.Init(NULL);
1091 JNIEnv* env;
1092 if (startVm(&mJavaVM, &env, zygote) != 0) {
1093 return;
1094 }
1095 onVmCreated(env);
1096
1097 /*
1098 * Register android functions.
1099 */
1100 if (startReg(env) < 0) {
1101 ALOGE("Unable to register all android natives\n");
1102 return;
1103 }
1104
1105 /*
1106 * We want to call main() with a String array with arguments in it.
1107 * At present we have two arguments, the class name and an option string.
1108 * Create an array to hold them.
1109 */
1110 jclass stringClass;
1111 jobjectArray strArray;
1112 jstring classNameStr;
1113
1114 stringClass = env->FindClass("java/lang/String");
1115 assert(stringClass != NULL);
1116 strArray = env->NewObjectArray(options.size() + 1, stringClass, NULL);
1117 assert(strArray != NULL);
1118 classNameStr = env->NewStringUTF(className);
1119 assert(classNameStr != NULL);
1120 env->SetObjectArrayElement(strArray, 0, classNameStr);
1121
1122 for (size_t i = 0; i < options.size(); ++i) {
1123 jstring optionsStr = env->NewStringUTF(options.itemAt(i).string());
1124 assert(optionsStr != NULL);
1125 env->SetObjectArrayElement(strArray, i + 1, optionsStr);
1126 }
1127
1128 /*
1129 * Start VM. This thread becomes the main thread of the VM, and will
1130 * not return until the VM exits.
1131 */
1132 char* slashClassName = toSlashClassName(className != NULL ? className : "");
1133 jclass startClass = env->FindClass(slashClassName);
1134 if (startClass == NULL) {
1135 ALOGE("JavaVM unable to locate class '%s'\n", slashClassName);
1136 /* keep going */
1137 } else {
1138 jmethodID startMeth = env->GetStaticMethodID(startClass, "main",
1139 "([Ljava/lang/String;)V");
1140 if (startMeth == NULL) {
1141 ALOGE("JavaVM unable to find main() in '%s'\n", className);
1142 /* keep going */
1143 } else {
1144 env->CallStaticVoidMethod(startClass, startMeth, strArray);
1145
1146 #if 0
1147 if (env->ExceptionCheck())
1148 threadExitUncaughtException(env);
1149 #endif
1150 }
1151 }
1152 free(slashClassName);
1153
1154 ALOGD("Shutting down VM\n");
1155 if (mJavaVM->DetachCurrentThread() != JNI_OK)
1156 ALOGW("Warning: unable to detach main thread\n");
1157 if (mJavaVM->DestroyJavaVM() != 0)
1158 ALOGW("Warning: VM did not shut down cleanly\n");
1159 }
1160
exit(int code)1161 void AndroidRuntime::exit(int code)
1162 {
1163 if (mExitWithoutCleanup) {
1164 ALOGI("VM exiting with result code %d, cleanup skipped.", code);
1165 ::_exit(code);
1166 } else {
1167 ALOGI("VM exiting with result code %d.", code);
1168 onExit(code);
1169 ::exit(code);
1170 }
1171 }
1172
onVmCreated(JNIEnv * env)1173 void AndroidRuntime::onVmCreated(JNIEnv* env)
1174 {
1175 // If AndroidRuntime had anything to do here, we'd have done it in 'start'.
1176 }
1177
1178 /*
1179 * Get the JNIEnv pointer for this thread.
1180 *
1181 * Returns NULL if the slot wasn't allocated or populated.
1182 */
getJNIEnv()1183 /*static*/ JNIEnv* AndroidRuntime::getJNIEnv()
1184 {
1185 JNIEnv* env;
1186 JavaVM* vm = AndroidRuntime::getJavaVM();
1187 assert(vm != NULL);
1188
1189 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK)
1190 return NULL;
1191 return env;
1192 }
1193
1194 /*
1195 * Makes the current thread visible to the VM.
1196 *
1197 * The JNIEnv pointer returned is only valid for the current thread, and
1198 * thus must be tucked into thread-local storage.
1199 */
javaAttachThread(const char * threadName,JNIEnv ** pEnv)1200 static int javaAttachThread(const char* threadName, JNIEnv** pEnv)
1201 {
1202 JavaVMAttachArgs args;
1203 JavaVM* vm;
1204 jint result;
1205
1206 vm = AndroidRuntime::getJavaVM();
1207 assert(vm != NULL);
1208
1209 args.version = JNI_VERSION_1_4;
1210 args.name = (char*) threadName;
1211 args.group = NULL;
1212
1213 result = vm->AttachCurrentThread(pEnv, (void*) &args);
1214 if (result != JNI_OK)
1215 ALOGI("NOTE: attach of thread '%s' failed\n", threadName);
1216
1217 return result;
1218 }
1219
1220 /*
1221 * Detach the current thread from the set visible to the VM.
1222 */
javaDetachThread(void)1223 static int javaDetachThread(void)
1224 {
1225 JavaVM* vm;
1226 jint result;
1227
1228 vm = AndroidRuntime::getJavaVM();
1229 assert(vm != NULL);
1230
1231 result = vm->DetachCurrentThread();
1232 if (result != JNI_OK)
1233 ALOGE("ERROR: thread detach failed\n");
1234 return result;
1235 }
1236
1237 /*
1238 * When starting a native thread that will be visible from the VM, we
1239 * bounce through this to get the right attach/detach action.
1240 * Note that this function calls free(args)
1241 */
javaThreadShell(void * args)1242 /*static*/ int AndroidRuntime::javaThreadShell(void* args) {
1243 void* start = ((void**)args)[0];
1244 void* userData = ((void **)args)[1];
1245 char* name = (char*) ((void **)args)[2]; // we own this storage
1246 free(args);
1247 JNIEnv* env;
1248 int result;
1249
1250 /* hook us into the VM */
1251 if (javaAttachThread(name, &env) != JNI_OK)
1252 return -1;
1253
1254 /* start the thread running */
1255 result = (*(android_thread_func_t)start)(userData);
1256
1257 /* unhook us */
1258 javaDetachThread();
1259 free(name);
1260
1261 return result;
1262 }
1263
1264 /*
1265 * This is invoked from androidCreateThreadEtc() via the callback
1266 * set with androidSetCreateThreadFunc().
1267 *
1268 * We need to create the new thread in such a way that it gets hooked
1269 * into the VM before it really starts executing.
1270 */
javaCreateThreadEtc(android_thread_func_t entryFunction,void * userData,const char * threadName,int32_t threadPriority,size_t threadStackSize,android_thread_id_t * threadId)1271 /*static*/ int AndroidRuntime::javaCreateThreadEtc(
1272 android_thread_func_t entryFunction,
1273 void* userData,
1274 const char* threadName,
1275 int32_t threadPriority,
1276 size_t threadStackSize,
1277 android_thread_id_t* threadId)
1278 {
1279 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free
1280 int result;
1281
1282 LOG_ALWAYS_FATAL_IF(threadName == nullptr, "threadName not provided to javaCreateThreadEtc");
1283
1284 args[0] = (void*) entryFunction;
1285 args[1] = userData;
1286 args[2] = (void*) strdup(threadName); // javaThreadShell must free
1287
1288 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args,
1289 threadName, threadPriority, threadStackSize, threadId);
1290 return result;
1291 }
1292
1293 /*
1294 * Create a thread that is visible from the VM.
1295 *
1296 * This is called from elsewhere in the library.
1297 */
createJavaThread(const char * name,void (* start)(void *),void * arg)1298 /*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name,
1299 void (*start)(void *), void* arg)
1300 {
1301 android_thread_id_t threadId = 0;
1302 javaCreateThreadEtc((android_thread_func_t) start, arg, name,
1303 ANDROID_PRIORITY_DEFAULT, 0, &threadId);
1304 return threadId;
1305 }
1306
1307 #if 0
1308 static void quickTest(void* arg)
1309 {
1310 const char* str = (const char*) arg;
1311
1312 printf("In quickTest: %s\n", str);
1313 }
1314 #endif
1315
1316 #ifdef NDEBUG
1317 #define REG_JNI(name) { name }
1318 struct RegJNIRec {
1319 int (*mProc)(JNIEnv*);
1320 };
1321 #else
1322 #define REG_JNI(name) { name, #name }
1323 struct RegJNIRec {
1324 int (*mProc)(JNIEnv*);
1325 const char* mName;
1326 };
1327 #endif
1328
1329 typedef void (*RegJAMProc)();
1330
register_jni_procs(const RegJNIRec array[],size_t count,JNIEnv * env)1331 static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env)
1332 {
1333 for (size_t i = 0; i < count; i++) {
1334 if (array[i].mProc(env) < 0) {
1335 #ifndef NDEBUG
1336 ALOGD("----------!!! %s failed to load\n", array[i].mName);
1337 #endif
1338 return -1;
1339 }
1340 }
1341 return 0;
1342 }
1343
1344 static const RegJNIRec gRegJNI[] = {
1345 REG_JNI(register_com_android_internal_os_RuntimeInit),
1346 REG_JNI(register_com_android_internal_os_ZygoteInit_nativeZygoteInit),
1347 REG_JNI(register_android_os_SystemClock),
1348 REG_JNI(register_android_util_EventLog),
1349 REG_JNI(register_android_util_Log),
1350 REG_JNI(register_android_util_MemoryIntArray),
1351 REG_JNI(register_android_util_PathParser),
1352 REG_JNI(register_android_util_StatsLog),
1353 REG_JNI(register_android_app_admin_SecurityLog),
1354 REG_JNI(register_android_content_AssetManager),
1355 REG_JNI(register_android_content_StringBlock),
1356 REG_JNI(register_android_content_XmlBlock),
1357 REG_JNI(register_android_content_res_ApkAssets),
1358 REG_JNI(register_android_text_AndroidCharacter),
1359 REG_JNI(register_android_text_Hyphenator),
1360 REG_JNI(register_android_text_MeasuredParagraph),
1361 REG_JNI(register_android_text_StaticLayout),
1362 REG_JNI(register_android_view_InputDevice),
1363 REG_JNI(register_android_view_KeyCharacterMap),
1364 REG_JNI(register_android_os_Process),
1365 REG_JNI(register_android_os_SystemProperties),
1366 REG_JNI(register_android_os_Binder),
1367 REG_JNI(register_android_os_Parcel),
1368 REG_JNI(register_android_os_HidlSupport),
1369 REG_JNI(register_android_os_HwBinder),
1370 REG_JNI(register_android_os_HwBlob),
1371 REG_JNI(register_android_os_HwParcel),
1372 REG_JNI(register_android_os_HwRemoteBinder),
1373 REG_JNI(register_android_os_VintfObject),
1374 REG_JNI(register_android_os_VintfRuntimeInfo),
1375 REG_JNI(register_android_nio_utils),
1376 REG_JNI(register_android_graphics_Canvas),
1377 REG_JNI(register_android_graphics_Graphics),
1378 REG_JNI(register_android_view_DisplayEventReceiver),
1379 REG_JNI(register_android_view_RenderNode),
1380 REG_JNI(register_android_view_RenderNodeAnimator),
1381 REG_JNI(register_android_view_DisplayListCanvas),
1382 REG_JNI(register_android_view_TextureLayer),
1383 REG_JNI(register_android_view_ThreadedRenderer),
1384 REG_JNI(register_android_view_Surface),
1385 REG_JNI(register_android_view_SurfaceControl),
1386 REG_JNI(register_android_view_SurfaceSession),
1387 REG_JNI(register_android_view_TextureView),
1388 REG_JNI(register_com_android_internal_view_animation_NativeInterpolatorFactoryHelper),
1389 REG_JNI(register_com_google_android_gles_jni_EGLImpl),
1390 REG_JNI(register_com_google_android_gles_jni_GLImpl),
1391 REG_JNI(register_android_opengl_jni_EGL14),
1392 REG_JNI(register_android_opengl_jni_EGLExt),
1393 REG_JNI(register_android_opengl_jni_GLES10),
1394 REG_JNI(register_android_opengl_jni_GLES10Ext),
1395 REG_JNI(register_android_opengl_jni_GLES11),
1396 REG_JNI(register_android_opengl_jni_GLES11Ext),
1397 REG_JNI(register_android_opengl_jni_GLES20),
1398 REG_JNI(register_android_opengl_jni_GLES30),
1399 REG_JNI(register_android_opengl_jni_GLES31),
1400 REG_JNI(register_android_opengl_jni_GLES31Ext),
1401 REG_JNI(register_android_opengl_jni_GLES32),
1402
1403 REG_JNI(register_android_graphics_Bitmap),
1404 REG_JNI(register_android_graphics_BitmapFactory),
1405 REG_JNI(register_android_graphics_BitmapRegionDecoder),
1406 REG_JNI(register_android_graphics_ByteBufferStreamAdaptor),
1407 REG_JNI(register_android_graphics_Camera),
1408 REG_JNI(register_android_graphics_CreateJavaOutputStreamAdaptor),
1409 REG_JNI(register_android_graphics_CanvasProperty),
1410 REG_JNI(register_android_graphics_ColorFilter),
1411 REG_JNI(register_android_graphics_DrawFilter),
1412 REG_JNI(register_android_graphics_FontFamily),
1413 REG_JNI(register_android_graphics_GraphicBuffer),
1414 REG_JNI(register_android_graphics_ImageDecoder),
1415 REG_JNI(register_android_graphics_drawable_AnimatedImageDrawable),
1416 REG_JNI(register_android_graphics_Interpolator),
1417 REG_JNI(register_android_graphics_MaskFilter),
1418 REG_JNI(register_android_graphics_Matrix),
1419 REG_JNI(register_android_graphics_Movie),
1420 REG_JNI(register_android_graphics_NinePatch),
1421 REG_JNI(register_android_graphics_Paint),
1422 REG_JNI(register_android_graphics_Path),
1423 REG_JNI(register_android_graphics_PathMeasure),
1424 REG_JNI(register_android_graphics_PathEffect),
1425 REG_JNI(register_android_graphics_Picture),
1426 REG_JNI(register_android_graphics_Region),
1427 REG_JNI(register_android_graphics_Shader),
1428 REG_JNI(register_android_graphics_SurfaceTexture),
1429 REG_JNI(register_android_graphics_Typeface),
1430 REG_JNI(register_android_graphics_YuvImage),
1431 REG_JNI(register_android_graphics_drawable_AnimatedVectorDrawable),
1432 REG_JNI(register_android_graphics_drawable_VectorDrawable),
1433 REG_JNI(register_android_graphics_pdf_PdfDocument),
1434 REG_JNI(register_android_graphics_pdf_PdfEditor),
1435 REG_JNI(register_android_graphics_pdf_PdfRenderer),
1436
1437 REG_JNI(register_android_database_CursorWindow),
1438 REG_JNI(register_android_database_SQLiteConnection),
1439 REG_JNI(register_android_database_SQLiteGlobal),
1440 REG_JNI(register_android_database_SQLiteDebug),
1441 REG_JNI(register_android_os_Debug),
1442 REG_JNI(register_android_os_FileObserver),
1443 REG_JNI(register_android_os_GraphicsEnvironment),
1444 REG_JNI(register_android_os_MessageQueue),
1445 REG_JNI(register_android_os_SELinux),
1446 REG_JNI(register_android_os_Trace),
1447 REG_JNI(register_android_os_UEventObserver),
1448 REG_JNI(register_android_net_LocalSocketImpl),
1449 REG_JNI(register_android_net_NetworkUtils),
1450 REG_JNI(register_android_os_MemoryFile),
1451 REG_JNI(register_android_os_SharedMemory),
1452 REG_JNI(register_com_android_internal_os_ClassLoaderFactory),
1453 REG_JNI(register_com_android_internal_os_Zygote),
1454 REG_JNI(register_com_android_internal_os_ZygoteInit),
1455 REG_JNI(register_com_android_internal_util_VirtualRefBasePtr),
1456 REG_JNI(register_android_hardware_Camera),
1457 REG_JNI(register_android_hardware_camera2_CameraMetadata),
1458 REG_JNI(register_android_hardware_camera2_legacy_LegacyCameraDevice),
1459 REG_JNI(register_android_hardware_camera2_legacy_PerfMeasurement),
1460 REG_JNI(register_android_hardware_camera2_DngCreator),
1461 REG_JNI(register_android_hardware_HardwareBuffer),
1462 REG_JNI(register_android_hardware_SensorManager),
1463 REG_JNI(register_android_hardware_SerialPort),
1464 REG_JNI(register_android_hardware_SoundTrigger),
1465 REG_JNI(register_android_hardware_UsbDevice),
1466 REG_JNI(register_android_hardware_UsbDeviceConnection),
1467 REG_JNI(register_android_hardware_UsbRequest),
1468 REG_JNI(register_android_hardware_location_ActivityRecognitionHardware),
1469 REG_JNI(register_android_media_AudioRecord),
1470 REG_JNI(register_android_media_AudioSystem),
1471 REG_JNI(register_android_media_AudioTrack),
1472 REG_JNI(register_android_media_JetPlayer),
1473 REG_JNI(register_android_media_MicrophoneInfo),
1474 REG_JNI(register_android_media_RemoteDisplay),
1475 REG_JNI(register_android_media_ToneGenerator),
1476
1477 REG_JNI(register_android_opengl_classes),
1478 REG_JNI(register_android_server_NetworkManagementSocketTagger),
1479 REG_JNI(register_android_ddm_DdmHandleNativeHeap),
1480 REG_JNI(register_android_backup_BackupDataInput),
1481 REG_JNI(register_android_backup_BackupDataOutput),
1482 REG_JNI(register_android_backup_FileBackupHelperBase),
1483 REG_JNI(register_android_backup_BackupHelperDispatcher),
1484 REG_JNI(register_android_app_backup_FullBackup),
1485 REG_JNI(register_android_app_Activity),
1486 REG_JNI(register_android_app_ActivityThread),
1487 REG_JNI(register_android_app_NativeActivity),
1488 REG_JNI(register_android_util_jar_StrictJarFile),
1489 REG_JNI(register_android_view_InputChannel),
1490 REG_JNI(register_android_view_InputEventReceiver),
1491 REG_JNI(register_android_view_InputEventSender),
1492 REG_JNI(register_android_view_InputQueue),
1493 REG_JNI(register_android_view_KeyEvent),
1494 REG_JNI(register_android_view_MotionEvent),
1495 REG_JNI(register_android_view_PointerIcon),
1496 REG_JNI(register_android_view_VelocityTracker),
1497
1498 REG_JNI(register_android_content_res_ObbScanner),
1499 REG_JNI(register_android_content_res_Configuration),
1500
1501 REG_JNI(register_android_animation_PropertyValuesHolder),
1502 REG_JNI(register_android_security_Scrypt),
1503 REG_JNI(register_com_android_internal_content_NativeLibraryHelper),
1504 REG_JNI(register_com_android_internal_net_NetworkStatsFactory),
1505 REG_JNI(register_com_android_internal_os_FuseAppLoop),
1506 };
1507
1508 /*
1509 * Register android native functions with the VM.
1510 */
startReg(JNIEnv * env)1511 /*static*/ int AndroidRuntime::startReg(JNIEnv* env)
1512 {
1513 ATRACE_NAME("RegisterAndroidNatives");
1514 /*
1515 * This hook causes all future threads created in this process to be
1516 * attached to the JavaVM. (This needs to go away in favor of JNI
1517 * Attach calls.)
1518 */
1519 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc);
1520
1521 ALOGV("--- registering native functions ---\n");
1522
1523 /*
1524 * Every "register" function calls one or more things that return
1525 * a local reference (e.g. FindClass). Because we haven't really
1526 * started the VM yet, they're all getting stored in the base frame
1527 * and never released. Use Push/Pop to manage the storage.
1528 */
1529 env->PushLocalFrame(200);
1530
1531 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) {
1532 env->PopLocalFrame(NULL);
1533 return -1;
1534 }
1535 env->PopLocalFrame(NULL);
1536
1537 //createJavaThread("fubar", quickTest, (void*) "hello");
1538
1539 return 0;
1540 }
1541
getRuntime()1542 AndroidRuntime* AndroidRuntime::getRuntime()
1543 {
1544 return gCurRuntime;
1545 }
1546
1547 /**
1548 * Used by surface flinger's DdmConnection to register native methods from
1549 * the framework.
1550 */
registerFrameworkNatives(JNIEnv * env)1551 extern "C" jint registerFrameworkNatives(JNIEnv* env) {
1552 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env);
1553 }
1554 } // namespace android
1555