AndroidRuntime.cpp revision 08e60f2a165d23b53f41993374aa074165bb5863
1/* //device/libs/android_runtime/AndroidRuntime.cpp 2** 3** Copyright 2006, 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 18#define LOG_TAG "AndroidRuntime" 19//#define LOG_NDEBUG 0 20 21#include <android_runtime/AndroidRuntime.h> 22#include <binder/IBinder.h> 23#include <binder/IServiceManager.h> 24#include <utils/Log.h> 25#include <utils/misc.h> 26#include <binder/Parcel.h> 27#include <utils/StringArray.h> 28#include <utils/threads.h> 29#include <cutils/properties.h> 30 31#include <SkGraphics.h> 32#include <SkImageDecoder.h> 33#include <SkImageRef_GlobalPool.h> 34 35#include "jni.h" 36#include "JNIHelp.h" 37#include "android_util_Binder.h" 38 39#include <stdio.h> 40#include <signal.h> 41#include <sys/stat.h> 42#include <sys/types.h> 43#include <signal.h> 44#include <dirent.h> 45#include <assert.h> 46 47 48using namespace android; 49 50extern void register_BindTest(); 51 52extern int register_android_os_Binder(JNIEnv* env); 53extern int register_android_os_Process(JNIEnv* env); 54extern int register_android_graphics_Bitmap(JNIEnv*); 55extern int register_android_graphics_BitmapFactory(JNIEnv*); 56extern int register_android_graphics_LargeBitmap(JNIEnv*); 57extern int register_android_graphics_Camera(JNIEnv* env); 58extern int register_android_graphics_Graphics(JNIEnv* env); 59extern int register_android_graphics_Interpolator(JNIEnv* env); 60extern int register_android_graphics_LayerRasterizer(JNIEnv*); 61extern int register_android_graphics_MaskFilter(JNIEnv* env); 62extern int register_android_graphics_Movie(JNIEnv* env); 63extern int register_android_graphics_NinePatch(JNIEnv*); 64extern int register_android_graphics_PathEffect(JNIEnv* env); 65extern int register_android_graphics_Region(JNIEnv* env); 66extern int register_android_graphics_Shader(JNIEnv* env); 67extern int register_android_graphics_Typeface(JNIEnv* env); 68extern int register_android_graphics_YuvImage(JNIEnv* env); 69 70extern int register_com_google_android_gles_jni_EGLImpl(JNIEnv* env); 71extern int register_com_google_android_gles_jni_GLImpl(JNIEnv* env); 72extern int register_android_opengl_jni_GLES10(JNIEnv* env); 73extern int register_android_opengl_jni_GLES10Ext(JNIEnv* env); 74extern int register_android_opengl_jni_GLES11(JNIEnv* env); 75extern int register_android_opengl_jni_GLES11Ext(JNIEnv* env); 76extern int register_android_opengl_jni_GLES20(JNIEnv* env); 77 78extern int register_android_hardware_Camera(JNIEnv *env); 79 80extern int register_android_hardware_SensorManager(JNIEnv *env); 81 82extern int register_android_media_AudioRecord(JNIEnv *env); 83extern int register_android_media_AudioSystem(JNIEnv *env); 84extern int register_android_media_AudioTrack(JNIEnv *env); 85extern int register_android_media_JetPlayer(JNIEnv *env); 86extern int register_android_media_ToneGenerator(JNIEnv *env); 87 88extern int register_android_message_digest_sha1(JNIEnv *env); 89 90extern int register_android_util_FloatMath(JNIEnv* env); 91 92namespace android { 93 94/* 95 * JNI-based registration functions. Note these are properly contained in 96 * namespace android. 97 */ 98extern int register_android_content_AssetManager(JNIEnv* env); 99extern int register_android_util_EventLog(JNIEnv* env); 100extern int register_android_util_Log(JNIEnv* env); 101extern int register_android_content_StringBlock(JNIEnv* env); 102extern int register_android_content_XmlBlock(JNIEnv* env); 103extern int register_android_emoji_EmojiFactory(JNIEnv* env); 104extern int register_android_graphics_Canvas(JNIEnv* env); 105extern int register_android_graphics_ColorFilter(JNIEnv* env); 106extern int register_android_graphics_DrawFilter(JNIEnv* env); 107extern int register_android_graphics_Matrix(JNIEnv* env); 108extern int register_android_graphics_Paint(JNIEnv* env); 109extern int register_android_graphics_Path(JNIEnv* env); 110extern int register_android_graphics_PathMeasure(JNIEnv* env); 111extern int register_android_graphics_Picture(JNIEnv*); 112extern int register_android_graphics_PorterDuff(JNIEnv* env); 113extern int register_android_graphics_Rasterizer(JNIEnv* env); 114extern int register_android_graphics_Xfermode(JNIEnv* env); 115extern int register_android_graphics_PixelFormat(JNIEnv* env); 116extern int register_com_android_internal_graphics_NativeUtils(JNIEnv *env); 117extern int register_android_view_Display(JNIEnv* env); 118extern int register_android_view_Surface(JNIEnv* env); 119extern int register_android_view_ViewRoot(JNIEnv* env); 120extern int register_android_database_CursorWindow(JNIEnv* env); 121extern int register_android_database_SQLiteCompiledSql(JNIEnv* env); 122extern int register_android_database_SQLiteDatabase(JNIEnv* env); 123extern int register_android_database_SQLiteDebug(JNIEnv* env); 124extern int register_android_database_SQLiteProgram(JNIEnv* env); 125extern int register_android_database_SQLiteQuery(JNIEnv* env); 126extern int register_android_database_SQLiteStatement(JNIEnv* env); 127extern int register_android_debug_JNITest(JNIEnv* env); 128extern int register_android_nio_utils(JNIEnv* env); 129extern int register_android_pim_EventRecurrence(JNIEnv* env); 130extern int register_android_text_format_Time(JNIEnv* env); 131extern int register_android_os_Debug(JNIEnv* env); 132extern int register_android_os_MessageQueue(JNIEnv* env); 133extern int register_android_os_ParcelFileDescriptor(JNIEnv *env); 134extern int register_android_os_Power(JNIEnv *env); 135extern int register_android_os_StatFs(JNIEnv *env); 136extern int register_android_os_SystemProperties(JNIEnv *env); 137extern int register_android_os_SystemClock(JNIEnv* env); 138extern int register_android_os_FileObserver(JNIEnv *env); 139extern int register_android_os_FileUtils(JNIEnv *env); 140extern int register_android_os_UEventObserver(JNIEnv* env); 141extern int register_android_os_MemoryFile(JNIEnv* env); 142extern int register_android_net_LocalSocketImpl(JNIEnv* env); 143extern int register_android_net_NetworkUtils(JNIEnv* env); 144extern int register_android_net_TrafficStats(JNIEnv* env); 145extern int register_android_net_wifi_WifiManager(JNIEnv* env); 146extern int register_android_security_Md5MessageDigest(JNIEnv *env); 147extern int register_android_text_AndroidCharacter(JNIEnv *env); 148extern int register_android_text_AndroidBidi(JNIEnv *env); 149extern int register_android_text_KeyCharacterMap(JNIEnv *env); 150extern int register_android_opengl_classes(JNIEnv *env); 151extern int register_android_bluetooth_HeadsetBase(JNIEnv* env); 152extern int register_android_bluetooth_BluetoothAudioGateway(JNIEnv* env); 153extern int register_android_bluetooth_BluetoothSocket(JNIEnv *env); 154extern int register_android_bluetooth_ScoSocket(JNIEnv *env); 155extern int register_android_server_BluetoothService(JNIEnv* env); 156extern int register_android_server_BluetoothEventLoop(JNIEnv *env); 157extern int register_android_server_BluetoothA2dpService(JNIEnv* env); 158extern int register_android_server_Watchdog(JNIEnv* env); 159extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env); 160extern int register_com_android_internal_os_ZygoteInit(JNIEnv* env); 161extern int register_android_backup_BackupDataInput(JNIEnv *env); 162extern int register_android_backup_BackupDataOutput(JNIEnv *env); 163extern int register_android_backup_FileBackupHelperBase(JNIEnv *env); 164extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env); 165extern int register_android_app_NativeActivity(JNIEnv *env); 166extern int register_android_view_InputChannel(JNIEnv* env); 167extern int register_android_view_InputQueue(JNIEnv* env); 168extern int register_android_view_KeyEvent(JNIEnv* env); 169extern int register_android_view_MotionEvent(JNIEnv* env); 170extern int register_android_content_res_ObbScanner(JNIEnv* env); 171extern int register_android_content_res_Configuration(JNIEnv* env); 172 173static AndroidRuntime* gCurRuntime = NULL; 174 175static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL) 176{ 177 if (jniThrowException(env, exc, msg) != 0) 178 assert(false); 179} 180 181/* 182 * Code written in the Java Programming Language calls here from main(). 183 */ 184static void com_android_internal_os_RuntimeInit_finishInit(JNIEnv* env, jobject clazz) 185{ 186 gCurRuntime->onStarted(); 187} 188 189static void com_android_internal_os_RuntimeInit_zygoteInit(JNIEnv* env, jobject clazz) 190{ 191 gCurRuntime->onZygoteInit(); 192} 193 194static jint com_android_internal_os_RuntimeInit_isComputerOn(JNIEnv* env, jobject clazz) 195{ 196 return 1; 197} 198 199static void com_android_internal_os_RuntimeInit_turnComputerOn(JNIEnv* env, jobject clazz) 200{ 201} 202 203static jint com_android_internal_os_RuntimeInit_getQwertyKeyboard(JNIEnv* env, jobject clazz) 204{ 205 char* value = getenv("qwerty"); 206 if (value != NULL && strcmp(value, "true") == 0) { 207 return 1; 208 } 209 210 return 0; 211} 212 213/* 214 * JNI registration. 215 */ 216static JNINativeMethod gMethods[] = { 217 { "finishInit", "()V", 218 (void*) com_android_internal_os_RuntimeInit_finishInit }, 219 { "zygoteInitNative", "()V", 220 (void*) com_android_internal_os_RuntimeInit_zygoteInit }, 221 { "isComputerOn", "()I", 222 (void*) com_android_internal_os_RuntimeInit_isComputerOn }, 223 { "turnComputerOn", "()V", 224 (void*) com_android_internal_os_RuntimeInit_turnComputerOn }, 225 { "getQwertyKeyboard", "()I", 226 (void*) com_android_internal_os_RuntimeInit_getQwertyKeyboard }, 227}; 228 229int register_com_android_internal_os_RuntimeInit(JNIEnv* env) 230{ 231 return jniRegisterNativeMethods(env, "com/android/internal/os/RuntimeInit", 232 gMethods, NELEM(gMethods)); 233} 234 235// ---------------------------------------------------------------------- 236 237/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL; 238 239 240AndroidRuntime::AndroidRuntime() 241{ 242 SkGraphics::Init(); 243 // this sets our preference for 16bit images during decode 244 // in case the src is opaque and 24bit 245 SkImageDecoder::SetDeviceConfig(SkBitmap::kRGB_565_Config); 246 // This cache is shared between browser native images, and java "purgeable" 247 // bitmaps. This globalpool is for images that do not either use the java 248 // heap, or are not backed by ashmem. See BitmapFactory.cpp for the key 249 // java call site. 250 SkImageRef_GlobalPool::SetRAMBudget(512 * 1024); 251 // There is also a global font cache, but its budget is specified in code 252 // see SkFontHost_android.cpp 253 254 // Pre-allocate enough space to hold a fair number of options. 255 mOptions.setCapacity(20); 256 257 assert(gCurRuntime == NULL); // one per process 258 gCurRuntime = this; 259} 260 261AndroidRuntime::~AndroidRuntime() 262{ 263 SkGraphics::Term(); 264} 265 266/* 267 * Register native methods using JNI. 268 */ 269/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env, 270 const char* className, const JNINativeMethod* gMethods, int numMethods) 271{ 272 return jniRegisterNativeMethods(env, className, gMethods, numMethods); 273} 274 275/* 276 * Call a static Java Programming Language function that takes no arguments and returns void. 277 */ 278status_t AndroidRuntime::callStatic(const char* className, const char* methodName) 279{ 280 JNIEnv* env; 281 jclass clazz; 282 jmethodID methodId; 283 284 env = getJNIEnv(); 285 if (env == NULL) 286 return UNKNOWN_ERROR; 287 288 clazz = findClass(env, className); 289 if (clazz == NULL) { 290 LOGE("ERROR: could not find class '%s'\n", className); 291 return UNKNOWN_ERROR; 292 } 293 methodId = env->GetStaticMethodID(clazz, methodName, "()V"); 294 if (methodId == NULL) { 295 LOGE("ERROR: could not find method %s.%s\n", className, methodName); 296 return UNKNOWN_ERROR; 297 } 298 299 env->CallStaticVoidMethod(clazz, methodId); 300 301 return NO_ERROR; 302} 303 304status_t AndroidRuntime::callMain( 305 const char* className, int argc, const char* const argv[]) 306{ 307 JNIEnv* env; 308 jclass clazz; 309 jmethodID methodId; 310 311 LOGD("Calling main entry %s", className); 312 313 env = getJNIEnv(); 314 if (env == NULL) 315 return UNKNOWN_ERROR; 316 317 clazz = findClass(env, className); 318 if (clazz == NULL) { 319 LOGE("ERROR: could not find class '%s'\n", className); 320 return UNKNOWN_ERROR; 321 } 322 323 methodId = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V"); 324 if (methodId == NULL) { 325 LOGE("ERROR: could not find method %s.main(String[])\n", className); 326 return UNKNOWN_ERROR; 327 } 328 329 /* 330 * We want to call main() with a String array with our arguments in it. 331 * Create an array and populate it. 332 */ 333 jclass stringClass; 334 jobjectArray strArray; 335 336 stringClass = env->FindClass("java/lang/String"); 337 strArray = env->NewObjectArray(argc, stringClass, NULL); 338 339 for (int i = 0; i < argc; i++) { 340 jstring argStr = env->NewStringUTF(argv[i]); 341 env->SetObjectArrayElement(strArray, i, argStr); 342 } 343 344 env->CallStaticVoidMethod(clazz, methodId, strArray); 345 return NO_ERROR; 346} 347 348/* 349 * Find the named class. 350 */ 351jclass AndroidRuntime::findClass(JNIEnv* env, const char* className) 352{ 353 char* convName = NULL; 354 355 if (env->ExceptionCheck()) { 356 LOGE("ERROR: exception pending on entry to findClass()\n"); 357 return NULL; 358 } 359 360 /* 361 * JNI FindClass uses class names with slashes, but ClassLoader.loadClass 362 * uses the dotted "binary name" format. We don't need to convert the 363 * name with the new approach. 364 */ 365#if 0 366 /* (convName only created if necessary -- use className) */ 367 for (char* cp = const_cast<char*>(className); *cp != '\0'; cp++) { 368 if (*cp == '.') { 369 if (convName == NULL) { 370 convName = strdup(className); 371 cp = convName + (cp-className); 372 className = convName; 373 } 374 *cp = '/'; 375 } 376 } 377#endif 378 379 /* 380 * This is a little awkward because the JNI FindClass call uses the 381 * class loader associated with the native method we're executing in. 382 * Because this native method is part of a "boot" class, JNI doesn't 383 * look for the class in CLASSPATH, which unfortunately is a likely 384 * location for it. (Had we issued the FindClass call before calling 385 * into the VM -- at which point there isn't a native method frame on 386 * the stack -- the VM would have checked CLASSPATH. We have to do 387 * this because we call into Java Programming Language code and 388 * bounce back out.) 389 * 390 * JNI lacks a "find class in a specific class loader" operation, so we 391 * have to do things the hard way. 392 */ 393 jclass cls = NULL; 394 //cls = env->FindClass(className); 395 396 jclass javaLangClassLoader; 397 jmethodID getSystemClassLoader, loadClass; 398 jobject systemClassLoader; 399 jstring strClassName; 400 401 /* find the "system" class loader; none of this is expected to fail */ 402 javaLangClassLoader = env->FindClass("java/lang/ClassLoader"); 403 assert(javaLangClassLoader != NULL); 404 getSystemClassLoader = env->GetStaticMethodID(javaLangClassLoader, 405 "getSystemClassLoader", "()Ljava/lang/ClassLoader;"); 406 loadClass = env->GetMethodID(javaLangClassLoader, 407 "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); 408 assert(getSystemClassLoader != NULL && loadClass != NULL); 409 systemClassLoader = env->CallStaticObjectMethod(javaLangClassLoader, 410 getSystemClassLoader); 411 assert(systemClassLoader != NULL); 412 413 /* create an object for the class name string; alloc could fail */ 414 strClassName = env->NewStringUTF(className); 415 if (env->ExceptionCheck()) { 416 LOGE("ERROR: unable to convert '%s' to string\n", className); 417 goto bail; 418 } 419 LOGV("system class loader is %p, loading %p (%s)\n", 420 systemClassLoader, strClassName, className); 421 422 /* try to find the named class */ 423 cls = (jclass) env->CallObjectMethod(systemClassLoader, loadClass, 424 strClassName); 425 if (env->ExceptionCheck()) { 426 LOGE("ERROR: unable to load class '%s' from %p\n", 427 className, systemClassLoader); 428 cls = NULL; 429 goto bail; 430 } 431 432bail: 433 free(convName); 434 return cls; 435} 436 437/* 438 * The VM calls this through the "exit" hook. 439 */ 440static void runtime_exit(int code) 441{ 442 gCurRuntime->onExit(code); 443 exit(code); 444} 445 446/* 447 * The VM calls this through the "vfprintf" hook. 448 * 449 * We ignore "fp" and just write the results to the log file. 450 */ 451static void runtime_vfprintf(FILE* fp, const char* format, va_list ap) 452{ 453 LOG_PRI_VA(ANDROID_LOG_INFO, "vm-printf", format, ap); 454} 455 456 457/** 458 * Add VM arguments to the to-be-executed VM 459 * Stops at first non '-' argument (also stops at an argument of '--') 460 * Returns the number of args consumed 461 */ 462int AndroidRuntime::addVmArguments(int argc, const char* const argv[]) 463{ 464 int i; 465 466 for (i = 0; i<argc; i++) { 467 if (argv[i][0] != '-') { 468 return i; 469 } 470 if (argv[i][1] == '-' && argv[i][2] == 0) { 471 return i+1; 472 } 473 474 JavaVMOption opt; 475 memset(&opt, 0, sizeof(opt)); 476 opt.optionString = (char*)argv[i]; 477 mOptions.add(opt); 478 } 479 return i; 480} 481 482static int hasDir(const char* dir) 483{ 484 struct stat s; 485 int res = stat(dir, &s); 486 if (res == 0) { 487 return S_ISDIR(s.st_mode); 488 } 489 return 0; 490} 491 492/* 493 * We just want failed write() calls to just return with an error. 494 */ 495static void blockSigpipe() 496{ 497 sigset_t mask; 498 499 sigemptyset(&mask); 500 sigaddset(&mask, SIGPIPE); 501 if (sigprocmask(SIG_BLOCK, &mask, NULL) != 0) 502 LOGW("WARNING: SIGPIPE not blocked\n"); 503} 504 505/* 506 * Read the persistent locale. 507 */ 508static void readLocale(char* language, char* region) 509{ 510 char propLang[PROPERTY_VALUE_MAX], propRegn[PROPERTY_VALUE_MAX]; 511 512 property_get("persist.sys.language", propLang, ""); 513 property_get("persist.sys.country", propRegn, ""); 514 if (*propLang == 0 && *propRegn == 0) { 515 /* Set to ro properties, default is en_US */ 516 property_get("ro.product.locale.language", propLang, "en"); 517 property_get("ro.product.locale.region", propRegn, "US"); 518 } 519 strncat(language, propLang, 2); 520 strncat(region, propRegn, 2); 521 //LOGD("language=%s region=%s\n", language, region); 522} 523 524/* 525 * Parse a property containing space-separated options that should be 526 * passed directly to the VM, e.g. "-Xmx32m -verbose:gc -Xregenmap". 527 * 528 * This will cut up "extraOptsBuf" as we chop it into individual options. 529 * 530 * Adds the strings, if any, to mOptions. 531 */ 532void AndroidRuntime::parseExtraOpts(char* extraOptsBuf) 533{ 534 JavaVMOption opt; 535 char* start; 536 char* end; 537 538 memset(&opt, 0, sizeof(opt)); 539 start = extraOptsBuf; 540 while (*start != '\0') { 541 while (*start == ' ') /* skip leading whitespace */ 542 start++; 543 if (*start == '\0') /* was trailing ws, bail */ 544 break; 545 546 end = start+1; 547 while (*end != ' ' && *end != '\0') /* find end of token */ 548 end++; 549 if (*end == ' ') 550 *end++ = '\0'; /* mark end, advance to indicate more */ 551 552 opt.optionString = start; 553 mOptions.add(opt); 554 start = end; 555 } 556} 557 558/* 559 * Start the Dalvik Virtual Machine. 560 * 561 * Various arguments, most determined by system properties, are passed in. 562 * The "mOptions" vector is updated. 563 * 564 * Returns 0 on success. 565 */ 566int AndroidRuntime::startVm(JavaVM** pJavaVM, JNIEnv** pEnv) 567{ 568 int result = -1; 569 JavaVMInitArgs initArgs; 570 JavaVMOption opt; 571 char propBuf[PROPERTY_VALUE_MAX]; 572 char stackTraceFileBuf[PROPERTY_VALUE_MAX]; 573 char dexoptFlagsBuf[PROPERTY_VALUE_MAX]; 574 char enableAssertBuf[sizeof("-ea:")-1 + PROPERTY_VALUE_MAX]; 575 char jniOptsBuf[sizeof("-Xjniopts:")-1 + PROPERTY_VALUE_MAX]; 576 char heapsizeOptsBuf[sizeof("-Xmx")-1 + PROPERTY_VALUE_MAX]; 577 char extraOptsBuf[PROPERTY_VALUE_MAX]; 578 char* stackTraceFile = NULL; 579 bool checkJni = false; 580 bool checkDexSum = false; 581 bool logStdio = false; 582 enum { 583 kEMDefault, 584 kEMIntPortable, 585 kEMIntFast, 586#if defined(WITH_JIT) 587 kEMJitCompiler, 588#endif 589 } executionMode = kEMDefault; 590 591 592 property_get("dalvik.vm.checkjni", propBuf, ""); 593 if (strcmp(propBuf, "true") == 0) { 594 checkJni = true; 595 } else if (strcmp(propBuf, "false") != 0) { 596 /* property is neither true nor false; fall back on kernel parameter */ 597 property_get("ro.kernel.android.checkjni", propBuf, ""); 598 if (propBuf[0] == '1') { 599 checkJni = true; 600 } 601 } 602 603 property_get("dalvik.vm.execution-mode", propBuf, ""); 604 if (strcmp(propBuf, "int:portable") == 0) { 605 executionMode = kEMIntPortable; 606 } else if (strcmp(propBuf, "int:fast") == 0) { 607 executionMode = kEMIntFast; 608#if defined(WITH_JIT) 609 } else if (strcmp(propBuf, "int:jit") == 0) { 610 executionMode = kEMJitCompiler; 611#endif 612 } 613 614 property_get("dalvik.vm.stack-trace-file", stackTraceFileBuf, ""); 615 616 property_get("dalvik.vm.check-dex-sum", propBuf, ""); 617 if (strcmp(propBuf, "true") == 0) { 618 checkDexSum = true; 619 } 620 621 property_get("log.redirect-stdio", propBuf, ""); 622 if (strcmp(propBuf, "true") == 0) { 623 logStdio = true; 624 } 625 626 strcpy(enableAssertBuf, "-ea:"); 627 property_get("dalvik.vm.enableassertions", enableAssertBuf+4, ""); 628 629 strcpy(jniOptsBuf, "-Xjniopts:"); 630 property_get("dalvik.vm.jniopts", jniOptsBuf+10, ""); 631 632 /* route exit() to our handler */ 633 opt.extraInfo = (void*) runtime_exit; 634 opt.optionString = "exit"; 635 mOptions.add(opt); 636 637 /* route fprintf() to our handler */ 638 opt.extraInfo = (void*) runtime_vfprintf; 639 opt.optionString = "vfprintf"; 640 mOptions.add(opt); 641 642 opt.extraInfo = NULL; 643 644 /* enable verbose; standard options are { jni, gc, class } */ 645 //options[curOpt++].optionString = "-verbose:jni"; 646 opt.optionString = "-verbose:gc"; 647 mOptions.add(opt); 648 //options[curOpt++].optionString = "-verbose:class"; 649 650 strcpy(heapsizeOptsBuf, "-Xmx"); 651 property_get("dalvik.vm.heapsize", heapsizeOptsBuf+4, "16m"); 652 //LOGI("Heap size: %s", heapsizeOptsBuf); 653 opt.optionString = heapsizeOptsBuf; 654 mOptions.add(opt); 655 656 /* 657 * Enable or disable dexopt features, such as bytecode verification and 658 * calculation of register maps for precise GC. 659 */ 660 property_get("dalvik.vm.dexopt-flags", dexoptFlagsBuf, ""); 661 if (dexoptFlagsBuf[0] != '\0') { 662 const char* opc; 663 const char* val; 664 665 opc = strstr(dexoptFlagsBuf, "v="); /* verification */ 666 if (opc != NULL) { 667 switch (*(opc+2)) { 668 case 'n': val = "-Xverify:none"; break; 669 case 'r': val = "-Xverify:remote"; break; 670 case 'a': val = "-Xverify:all"; break; 671 default: val = NULL; break; 672 } 673 674 if (val != NULL) { 675 opt.optionString = val; 676 mOptions.add(opt); 677 } 678 } 679 680 opc = strstr(dexoptFlagsBuf, "o="); /* optimization */ 681 if (opc != NULL) { 682 switch (*(opc+2)) { 683 case 'n': val = "-Xdexopt:none"; break; 684 case 'v': val = "-Xdexopt:verified"; break; 685 case 'a': val = "-Xdexopt:all"; break; 686 default: val = NULL; break; 687 } 688 689 if (val != NULL) { 690 opt.optionString = val; 691 mOptions.add(opt); 692 } 693 } 694 695 opc = strstr(dexoptFlagsBuf, "m=y"); /* register map */ 696 if (opc != NULL) { 697 opt.optionString = "-Xgenregmap"; 698 mOptions.add(opt); 699 700 /* turn on precise GC while we're at it */ 701 opt.optionString = "-Xgc:precise"; 702 mOptions.add(opt); 703 } 704 } 705 706 /* enable poisoning of memory of freed objects */ 707 property_get("dalvik.vm.gc.overwritefree", propBuf, "false"); 708 if (strcmp(propBuf, "true") == 0) { 709 opt.optionString = "-Xgc:overwritefree"; 710 mOptions.add(opt); 711 } else if (strcmp(propBuf, "false") != 0) { 712 LOGW("dalvik.vm.gc.overwritefree should be 'true' or 'false'"); 713 } 714 715 /* enable heap verification before each gc */ 716 property_get("dalvik.vm.gc.preverify", propBuf, "false"); 717 if (strcmp(propBuf, "true") == 0) { 718 opt.optionString = "-Xgc:preverify"; 719 mOptions.add(opt); 720 } else if (strcmp(propBuf, "false") != 0) { 721 LOGW("dalvik.vm.gc.preverify should be 'true' or 'false'"); 722 } 723 724 /* enable heap verification after each gc */ 725 property_get("dalvik.vm.gc.postverify", propBuf, "false"); 726 if (strcmp(propBuf, "true") == 0) { 727 opt.optionString = "-Xgc:postverify"; 728 mOptions.add(opt); 729 } else if (strcmp(propBuf, "false") != 0) { 730 LOGW("dalvik.vm.gc.postverify should be 'true' or 'false'"); 731 } 732 733 /* enable card table verification for partial gc */ 734 property_get("dalvik.vm.gc.verifycardtable", propBuf, "false"); 735 if (strcmp(propBuf, "true") == 0) { 736 opt.optionString = "-Xgc:verifycardtable"; 737 mOptions.add(opt); 738 } else if (strcmp(propBuf, "false") != 0) { 739 LOGW("dalvik.vm.gc.verifycardtable should be 'true' or 'false'"); 740 } 741 742 /* enable debugging; set suspend=y to pause during VM init */ 743#ifdef HAVE_ANDROID_OS 744 /* use android ADB transport */ 745 opt.optionString = 746 "-agentlib:jdwp=transport=dt_android_adb,suspend=n,server=y"; 747#else 748 /* use TCP socket; address=0 means start at port 8000 and probe up */ 749 LOGI("Using TCP socket for JDWP\n"); 750 opt.optionString = 751 "-agentlib:jdwp=transport=dt_socket,suspend=n,server=y,address=0"; 752#endif 753 mOptions.add(opt); 754 755 char enableDPBuf[sizeof("-Xdeadlockpredict:") + PROPERTY_VALUE_MAX]; 756 property_get("dalvik.vm.deadlock-predict", propBuf, ""); 757 if (strlen(propBuf) > 0) { 758 strcpy(enableDPBuf, "-Xdeadlockpredict:"); 759 strcat(enableDPBuf, propBuf); 760 opt.optionString = enableDPBuf; 761 mOptions.add(opt); 762 } 763 764 LOGD("CheckJNI is %s\n", checkJni ? "ON" : "OFF"); 765 if (checkJni) { 766 /* extended JNI checking */ 767 opt.optionString = "-Xcheck:jni"; 768 mOptions.add(opt); 769 770 /* set a cap on JNI global references */ 771 opt.optionString = "-Xjnigreflimit:2000"; 772 mOptions.add(opt); 773 774 /* with -Xcheck:jni, this provides a JNI function call trace */ 775 //opt.optionString = "-verbose:jni"; 776 //mOptions.add(opt); 777 } 778 779 char lockProfThresholdBuf[sizeof("-Xlockprofthreshold:") + sizeof(propBuf)]; 780 property_get("dalvik.vm.lockprof.threshold", propBuf, ""); 781 if (strlen(propBuf) > 0) { 782 strcpy(lockProfThresholdBuf, "-Xlockprofthreshold:"); 783 strcat(lockProfThresholdBuf, propBuf); 784 opt.optionString = lockProfThresholdBuf; 785 mOptions.add(opt); 786 } 787 788#if defined(WITH_JIT) 789 /* Force interpreter-only mode for selected opcodes. Eg "1-0a,3c,f1-ff" */ 790 char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX]; 791 property_get("dalvik.vm.jit.op", propBuf, ""); 792 if (strlen(propBuf) > 0) { 793 strcpy(jitOpBuf, "-Xjitop:"); 794 strcat(jitOpBuf, propBuf); 795 opt.optionString = jitOpBuf; 796 mOptions.add(opt); 797 } 798 799 /* Force interpreter-only mode for selected methods */ 800 char jitMethodBuf[sizeof("-Xjitmethod:") + PROPERTY_VALUE_MAX]; 801 property_get("dalvik.vm.jit.method", propBuf, ""); 802 if (strlen(propBuf) > 0) { 803 strcpy(jitMethodBuf, "-Xjitmethod:"); 804 strcat(jitMethodBuf, propBuf); 805 opt.optionString = jitMethodBuf; 806 mOptions.add(opt); 807 } 808#endif 809 810 if (executionMode == kEMIntPortable) { 811 opt.optionString = "-Xint:portable"; 812 mOptions.add(opt); 813 } else if (executionMode == kEMIntFast) { 814 opt.optionString = "-Xint:fast"; 815 mOptions.add(opt); 816#if defined(WITH_JIT) 817 } else if (executionMode == kEMJitCompiler) { 818 opt.optionString = "-Xint:jit"; 819 mOptions.add(opt); 820#endif 821 } 822 823 if (checkDexSum) { 824 /* perform additional DEX checksum tests */ 825 opt.optionString = "-Xcheckdexsum"; 826 mOptions.add(opt); 827 } 828 829 if (logStdio) { 830 /* convert stdout/stderr to log messages */ 831 opt.optionString = "-Xlog-stdio"; 832 mOptions.add(opt); 833 } 834 835 if (enableAssertBuf[4] != '\0') { 836 /* accept "all" to mean "all classes and packages" */ 837 if (strcmp(enableAssertBuf+4, "all") == 0) 838 enableAssertBuf[3] = '\0'; 839 LOGI("Assertions enabled: '%s'\n", enableAssertBuf); 840 opt.optionString = enableAssertBuf; 841 mOptions.add(opt); 842 } else { 843 LOGV("Assertions disabled\n"); 844 } 845 846 if (jniOptsBuf[10] != '\0') { 847 LOGI("JNI options: '%s'\n", jniOptsBuf); 848 opt.optionString = jniOptsBuf; 849 mOptions.add(opt); 850 } 851 852 if (stackTraceFileBuf[0] != '\0') { 853 static const char* stfOptName = "-Xstacktracefile:"; 854 855 stackTraceFile = (char*) malloc(strlen(stfOptName) + 856 strlen(stackTraceFileBuf) +1); 857 strcpy(stackTraceFile, stfOptName); 858 strcat(stackTraceFile, stackTraceFileBuf); 859 opt.optionString = stackTraceFile; 860 mOptions.add(opt); 861 } 862 863 /* extra options; parse this late so it overrides others */ 864 property_get("dalvik.vm.extra-opts", extraOptsBuf, ""); 865 parseExtraOpts(extraOptsBuf); 866 867 /* Set the properties for locale */ 868 { 869 char langOption[sizeof("-Duser.language=") + 3]; 870 char regionOption[sizeof("-Duser.region=") + 3]; 871 strcpy(langOption, "-Duser.language="); 872 strcpy(regionOption, "-Duser.region="); 873 readLocale(langOption, regionOption); 874 opt.extraInfo = NULL; 875 opt.optionString = langOption; 876 mOptions.add(opt); 877 opt.optionString = regionOption; 878 mOptions.add(opt); 879 } 880 881 /* 882 * We don't have /tmp on the device, but we often have an SD card. Apps 883 * shouldn't use this, but some test suites might want to exercise it. 884 */ 885 opt.optionString = "-Djava.io.tmpdir=/sdcard"; 886 mOptions.add(opt); 887 888 initArgs.version = JNI_VERSION_1_4; 889 initArgs.options = mOptions.editArray(); 890 initArgs.nOptions = mOptions.size(); 891 initArgs.ignoreUnrecognized = JNI_FALSE; 892 893 /* 894 * Initialize the VM. 895 * 896 * The JavaVM* is essentially per-process, and the JNIEnv* is per-thread. 897 * If this call succeeds, the VM is ready, and we can start issuing 898 * JNI calls. 899 */ 900 if (JNI_CreateJavaVM(pJavaVM, pEnv, &initArgs) < 0) { 901 LOGE("JNI_CreateJavaVM failed\n"); 902 goto bail; 903 } 904 905 result = 0; 906 907bail: 908 free(stackTraceFile); 909 return result; 910} 911 912/* 913 * Start the Android runtime. This involves starting the virtual machine 914 * and calling the "static void main(String[] args)" method in the class 915 * named by "className". 916 */ 917void AndroidRuntime::start(const char* className, const bool startSystemServer) 918{ 919 LOGD("\n>>>>>> AndroidRuntime START %s <<<<<<\n", 920 className != NULL ? className : "(unknown)"); 921 922 char* slashClassName = NULL; 923 char* cp; 924 JNIEnv* env; 925 926 blockSigpipe(); 927 928 /* 929 * 'startSystemServer == true' means runtime is obslete and not run from 930 * init.rc anymore, so we print out the boot start event here. 931 */ 932 if (startSystemServer) { 933 /* track our progress through the boot sequence */ 934 const int LOG_BOOT_PROGRESS_START = 3000; 935 LOG_EVENT_LONG(LOG_BOOT_PROGRESS_START, 936 ns2ms(systemTime(SYSTEM_TIME_MONOTONIC))); 937 } 938 939 const char* rootDir = getenv("ANDROID_ROOT"); 940 if (rootDir == NULL) { 941 rootDir = "/system"; 942 if (!hasDir("/system")) { 943 LOG_FATAL("No root directory specified, and /android does not exist."); 944 goto bail; 945 } 946 setenv("ANDROID_ROOT", rootDir, 1); 947 } 948 949 //const char* kernelHack = getenv("LD_ASSUME_KERNEL"); 950 //LOGD("Found LD_ASSUME_KERNEL='%s'\n", kernelHack); 951 952 /* start the virtual machine */ 953 if (startVm(&mJavaVM, &env) != 0) 954 goto bail; 955 956 /* 957 * Register android functions. 958 */ 959 if (startReg(env) < 0) { 960 LOGE("Unable to register all android natives\n"); 961 goto bail; 962 } 963 964 /* 965 * We want to call main() with a String array with arguments in it. 966 * At present we only have one argument, the class name. Create an 967 * array to hold it. 968 */ 969 jclass stringClass; 970 jobjectArray strArray; 971 jstring classNameStr; 972 jstring startSystemServerStr; 973 974 stringClass = env->FindClass("java/lang/String"); 975 assert(stringClass != NULL); 976 strArray = env->NewObjectArray(2, stringClass, NULL); 977 assert(strArray != NULL); 978 classNameStr = env->NewStringUTF(className); 979 assert(classNameStr != NULL); 980 env->SetObjectArrayElement(strArray, 0, classNameStr); 981 startSystemServerStr = env->NewStringUTF(startSystemServer ? 982 "true" : "false"); 983 env->SetObjectArrayElement(strArray, 1, startSystemServerStr); 984 985 /* 986 * Start VM. This thread becomes the main thread of the VM, and will 987 * not return until the VM exits. 988 */ 989 jclass startClass; 990 jmethodID startMeth; 991 992 slashClassName = strdup(className); 993 for (cp = slashClassName; *cp != '\0'; cp++) 994 if (*cp == '.') 995 *cp = '/'; 996 997 startClass = env->FindClass(slashClassName); 998 if (startClass == NULL) { 999 LOGE("JavaVM unable to locate class '%s'\n", slashClassName); 1000 /* keep going */ 1001 } else { 1002 startMeth = env->GetStaticMethodID(startClass, "main", 1003 "([Ljava/lang/String;)V"); 1004 if (startMeth == NULL) { 1005 LOGE("JavaVM unable to find main() in '%s'\n", className); 1006 /* keep going */ 1007 } else { 1008 env->CallStaticVoidMethod(startClass, startMeth, strArray); 1009 1010#if 0 1011 if (env->ExceptionCheck()) 1012 threadExitUncaughtException(env); 1013#endif 1014 } 1015 } 1016 1017 LOGD("Shutting down VM\n"); 1018 if (mJavaVM->DetachCurrentThread() != JNI_OK) 1019 LOGW("Warning: unable to detach main thread\n"); 1020 if (mJavaVM->DestroyJavaVM() != 0) 1021 LOGW("Warning: VM did not shut down cleanly\n"); 1022 1023bail: 1024 free(slashClassName); 1025} 1026 1027void AndroidRuntime::start() 1028{ 1029 start("com.android.internal.os.RuntimeInit", 1030 false /* Don't start the system server */); 1031} 1032 1033void AndroidRuntime::onExit(int code) 1034{ 1035 LOGV("AndroidRuntime onExit calling exit(%d)", code); 1036 exit(code); 1037} 1038 1039/* 1040 * Get the JNIEnv pointer for this thread. 1041 * 1042 * Returns NULL if the slot wasn't allocated or populated. 1043 */ 1044/*static*/ JNIEnv* AndroidRuntime::getJNIEnv() 1045{ 1046 JNIEnv* env; 1047 JavaVM* vm = AndroidRuntime::getJavaVM(); 1048 assert(vm != NULL); 1049 1050 if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) 1051 return NULL; 1052 return env; 1053} 1054 1055/* 1056 * Makes the current thread visible to the VM. 1057 * 1058 * The JNIEnv pointer returned is only valid for the current thread, and 1059 * thus must be tucked into thread-local storage. 1060 */ 1061static int javaAttachThread(const char* threadName, JNIEnv** pEnv) 1062{ 1063 JavaVMAttachArgs args; 1064 JavaVM* vm; 1065 jint result; 1066 1067 vm = AndroidRuntime::getJavaVM(); 1068 assert(vm != NULL); 1069 1070 args.version = JNI_VERSION_1_4; 1071 args.name = (char*) threadName; 1072 args.group = NULL; 1073 1074 result = vm->AttachCurrentThread(pEnv, (void*) &args); 1075 if (result != JNI_OK) 1076 LOGI("NOTE: attach of thread '%s' failed\n", threadName); 1077 1078 return result; 1079} 1080 1081/* 1082 * Detach the current thread from the set visible to the VM. 1083 */ 1084static int javaDetachThread(void) 1085{ 1086 JavaVM* vm; 1087 jint result; 1088 1089 vm = AndroidRuntime::getJavaVM(); 1090 assert(vm != NULL); 1091 1092 result = vm->DetachCurrentThread(); 1093 if (result != JNI_OK) 1094 LOGE("ERROR: thread detach failed\n"); 1095 return result; 1096} 1097 1098/* 1099 * When starting a native thread that will be visible from the VM, we 1100 * bounce through this to get the right attach/detach action. 1101 * Note that this function calls free(args) 1102 */ 1103/*static*/ int AndroidRuntime::javaThreadShell(void* args) { 1104 void* start = ((void**)args)[0]; 1105 void* userData = ((void **)args)[1]; 1106 char* name = (char*) ((void **)args)[2]; // we own this storage 1107 free(args); 1108 JNIEnv* env; 1109 int result; 1110 1111 /* hook us into the VM */ 1112 if (javaAttachThread(name, &env) != JNI_OK) 1113 return -1; 1114 1115 /* start the thread running */ 1116 result = (*(android_thread_func_t)start)(userData); 1117 1118 /* unhook us */ 1119 javaDetachThread(); 1120 free(name); 1121 1122 return result; 1123} 1124 1125/* 1126 * This is invoked from androidCreateThreadEtc() via the callback 1127 * set with androidSetCreateThreadFunc(). 1128 * 1129 * We need to create the new thread in such a way that it gets hooked 1130 * into the VM before it really starts executing. 1131 */ 1132/*static*/ int AndroidRuntime::javaCreateThreadEtc( 1133 android_thread_func_t entryFunction, 1134 void* userData, 1135 const char* threadName, 1136 int32_t threadPriority, 1137 size_t threadStackSize, 1138 android_thread_id_t* threadId) 1139{ 1140 void** args = (void**) malloc(3 * sizeof(void*)); // javaThreadShell must free 1141 int result; 1142 1143 assert(threadName != NULL); 1144 1145 args[0] = (void*) entryFunction; 1146 args[1] = userData; 1147 args[2] = (void*) strdup(threadName); // javaThreadShell must free 1148 1149 result = androidCreateRawThreadEtc(AndroidRuntime::javaThreadShell, args, 1150 threadName, threadPriority, threadStackSize, threadId); 1151 return result; 1152} 1153 1154/* 1155 * Create a thread that is visible from the VM. 1156 * 1157 * This is called from elsewhere in the library. 1158 */ 1159/*static*/ android_thread_id_t AndroidRuntime::createJavaThread(const char* name, 1160 void (*start)(void *), void* arg) 1161{ 1162 android_thread_id_t threadId = 0; 1163 javaCreateThreadEtc((android_thread_func_t) start, arg, name, 1164 ANDROID_PRIORITY_DEFAULT, 0, &threadId); 1165 return threadId; 1166} 1167 1168#if 0 1169static void quickTest(void* arg) 1170{ 1171 const char* str = (const char*) arg; 1172 1173 printf("In quickTest: %s\n", str); 1174} 1175#endif 1176 1177#ifdef NDEBUG 1178 #define REG_JNI(name) { name } 1179 struct RegJNIRec { 1180 int (*mProc)(JNIEnv*); 1181 }; 1182#else 1183 #define REG_JNI(name) { name, #name } 1184 struct RegJNIRec { 1185 int (*mProc)(JNIEnv*); 1186 const char* mName; 1187 }; 1188#endif 1189 1190typedef void (*RegJAMProc)(); 1191 1192static int register_jni_procs(const RegJNIRec array[], size_t count, JNIEnv* env) 1193{ 1194 for (size_t i = 0; i < count; i++) { 1195 if (array[i].mProc(env) < 0) { 1196#ifndef NDEBUG 1197 LOGD("----------!!! %s failed to load\n", array[i].mName); 1198#endif 1199 return -1; 1200 } 1201 } 1202 return 0; 1203} 1204 1205static void register_jam_procs(const RegJAMProc array[], size_t count) 1206{ 1207 for (size_t i = 0; i < count; i++) { 1208 array[i](); 1209 } 1210} 1211 1212static const RegJNIRec gRegJNI[] = { 1213 REG_JNI(register_android_debug_JNITest), 1214 REG_JNI(register_com_android_internal_os_RuntimeInit), 1215 REG_JNI(register_android_os_SystemClock), 1216 REG_JNI(register_android_util_EventLog), 1217 REG_JNI(register_android_util_Log), 1218 REG_JNI(register_android_util_FloatMath), 1219 REG_JNI(register_android_text_format_Time), 1220 REG_JNI(register_android_pim_EventRecurrence), 1221 REG_JNI(register_android_content_AssetManager), 1222 REG_JNI(register_android_content_StringBlock), 1223 REG_JNI(register_android_content_XmlBlock), 1224 REG_JNI(register_android_emoji_EmojiFactory), 1225 REG_JNI(register_android_security_Md5MessageDigest), 1226 REG_JNI(register_android_text_AndroidCharacter), 1227 REG_JNI(register_android_text_AndroidBidi), 1228 REG_JNI(register_android_text_KeyCharacterMap), 1229 REG_JNI(register_android_os_Process), 1230 REG_JNI(register_android_os_Binder), 1231 REG_JNI(register_android_view_Display), 1232 REG_JNI(register_android_nio_utils), 1233 REG_JNI(register_android_graphics_PixelFormat), 1234 REG_JNI(register_android_graphics_Graphics), 1235 REG_JNI(register_android_view_Surface), 1236 REG_JNI(register_android_view_ViewRoot), 1237 REG_JNI(register_com_google_android_gles_jni_EGLImpl), 1238 REG_JNI(register_com_google_android_gles_jni_GLImpl), 1239 REG_JNI(register_android_opengl_jni_GLES10), 1240 REG_JNI(register_android_opengl_jni_GLES10Ext), 1241 REG_JNI(register_android_opengl_jni_GLES11), 1242 REG_JNI(register_android_opengl_jni_GLES11Ext), 1243 REG_JNI(register_android_opengl_jni_GLES20), 1244 1245 REG_JNI(register_android_graphics_Bitmap), 1246 REG_JNI(register_android_graphics_BitmapFactory), 1247 REG_JNI(register_android_graphics_LargeBitmap), 1248 REG_JNI(register_android_graphics_Camera), 1249 REG_JNI(register_android_graphics_Canvas), 1250 REG_JNI(register_android_graphics_ColorFilter), 1251 REG_JNI(register_android_graphics_DrawFilter), 1252 REG_JNI(register_android_graphics_Interpolator), 1253 REG_JNI(register_android_graphics_LayerRasterizer), 1254 REG_JNI(register_android_graphics_MaskFilter), 1255 REG_JNI(register_android_graphics_Matrix), 1256 REG_JNI(register_android_graphics_Movie), 1257 REG_JNI(register_android_graphics_NinePatch), 1258 REG_JNI(register_android_graphics_Paint), 1259 REG_JNI(register_android_graphics_Path), 1260 REG_JNI(register_android_graphics_PathMeasure), 1261 REG_JNI(register_android_graphics_PathEffect), 1262 REG_JNI(register_android_graphics_Picture), 1263 REG_JNI(register_android_graphics_PorterDuff), 1264 REG_JNI(register_android_graphics_Rasterizer), 1265 REG_JNI(register_android_graphics_Region), 1266 REG_JNI(register_android_graphics_Shader), 1267 REG_JNI(register_android_graphics_Typeface), 1268 REG_JNI(register_android_graphics_Xfermode), 1269 REG_JNI(register_android_graphics_YuvImage), 1270 REG_JNI(register_com_android_internal_graphics_NativeUtils), 1271 1272 REG_JNI(register_android_database_CursorWindow), 1273 REG_JNI(register_android_database_SQLiteCompiledSql), 1274 REG_JNI(register_android_database_SQLiteDatabase), 1275 REG_JNI(register_android_database_SQLiteDebug), 1276 REG_JNI(register_android_database_SQLiteProgram), 1277 REG_JNI(register_android_database_SQLiteQuery), 1278 REG_JNI(register_android_database_SQLiteStatement), 1279 REG_JNI(register_android_os_Debug), 1280 REG_JNI(register_android_os_FileObserver), 1281 REG_JNI(register_android_os_FileUtils), 1282 REG_JNI(register_android_os_MessageQueue), 1283 REG_JNI(register_android_os_ParcelFileDescriptor), 1284 REG_JNI(register_android_os_Power), 1285 REG_JNI(register_android_os_StatFs), 1286 REG_JNI(register_android_os_SystemProperties), 1287 REG_JNI(register_android_os_UEventObserver), 1288 REG_JNI(register_android_net_LocalSocketImpl), 1289 REG_JNI(register_android_net_NetworkUtils), 1290 REG_JNI(register_android_net_TrafficStats), 1291 REG_JNI(register_android_net_wifi_WifiManager), 1292 REG_JNI(register_android_os_MemoryFile), 1293 REG_JNI(register_com_android_internal_os_ZygoteInit), 1294 REG_JNI(register_android_hardware_Camera), 1295 REG_JNI(register_android_hardware_SensorManager), 1296 REG_JNI(register_android_media_AudioRecord), 1297 REG_JNI(register_android_media_AudioSystem), 1298 REG_JNI(register_android_media_AudioTrack), 1299 REG_JNI(register_android_media_JetPlayer), 1300 REG_JNI(register_android_media_ToneGenerator), 1301 1302 REG_JNI(register_android_opengl_classes), 1303 REG_JNI(register_android_bluetooth_HeadsetBase), 1304 REG_JNI(register_android_bluetooth_BluetoothAudioGateway), 1305 REG_JNI(register_android_bluetooth_BluetoothSocket), 1306 REG_JNI(register_android_bluetooth_ScoSocket), 1307 REG_JNI(register_android_server_BluetoothService), 1308 REG_JNI(register_android_server_BluetoothEventLoop), 1309 REG_JNI(register_android_server_BluetoothA2dpService), 1310 REG_JNI(register_android_server_Watchdog), 1311 REG_JNI(register_android_message_digest_sha1), 1312 REG_JNI(register_android_ddm_DdmHandleNativeHeap), 1313 REG_JNI(register_android_backup_BackupDataInput), 1314 REG_JNI(register_android_backup_BackupDataOutput), 1315 REG_JNI(register_android_backup_FileBackupHelperBase), 1316 REG_JNI(register_android_backup_BackupHelperDispatcher), 1317 1318 REG_JNI(register_android_app_NativeActivity), 1319 REG_JNI(register_android_view_InputChannel), 1320 REG_JNI(register_android_view_InputQueue), 1321 REG_JNI(register_android_view_KeyEvent), 1322 REG_JNI(register_android_view_MotionEvent), 1323 1324 REG_JNI(register_android_content_res_ObbScanner), 1325 REG_JNI(register_android_content_res_Configuration), 1326}; 1327 1328/* 1329 * Register android native functions with the VM. 1330 */ 1331/*static*/ int AndroidRuntime::startReg(JNIEnv* env) 1332{ 1333 /* 1334 * This hook causes all future threads created in this process to be 1335 * attached to the JavaVM. (This needs to go away in favor of JNI 1336 * Attach calls.) 1337 */ 1338 androidSetCreateThreadFunc((android_create_thread_fn) javaCreateThreadEtc); 1339 1340 LOGV("--- registering native functions ---\n"); 1341 1342 /* 1343 * Every "register" function calls one or more things that return 1344 * a local reference (e.g. FindClass). Because we haven't really 1345 * started the VM yet, they're all getting stored in the base frame 1346 * and never released. Use Push/Pop to manage the storage. 1347 */ 1348 env->PushLocalFrame(200); 1349 1350 if (register_jni_procs(gRegJNI, NELEM(gRegJNI), env) < 0) { 1351 env->PopLocalFrame(NULL); 1352 return -1; 1353 } 1354 env->PopLocalFrame(NULL); 1355 1356 //createJavaThread("fubar", quickTest, (void*) "hello"); 1357 1358 return 0; 1359} 1360 1361AndroidRuntime* AndroidRuntime::getRuntime() 1362{ 1363 return gCurRuntime; 1364} 1365 1366/** 1367 * Used by WithFramework to register native functions. 1368 */ 1369extern "C" 1370jint Java_com_android_internal_util_WithFramework_registerNatives( 1371 JNIEnv* env, jclass clazz) { 1372 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env); 1373} 1374 1375/** 1376 * Used by LoadClass to register native functions. 1377 */ 1378extern "C" 1379jint Java_LoadClass_registerNatives(JNIEnv* env, jclass clazz) { 1380 return register_jni_procs(gRegJNI, NELEM(gRegJNI), env); 1381} 1382 1383} // namespace android 1384