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