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