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