2 * Copyright (C) 2005 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #ifndef _RUNTIME_ANDROID_RUNTIME_H
20 #define _RUNTIME_ANDROID_RUNTIME_H
22 #include <utils/Errors.h>
23 #include <binder/IBinder.h>
24 #include <utils/String8.h>
25 #include <utils/String16.h>
26 #include <utils/Vector.h>
27 #include <utils/threads.h>
29 #include <nativehelper/jni.h>
38 virtual ~AndroidRuntime();
41 * Register a set of methods in the specified class.
43 static int registerNativeMethods(JNIEnv* env,
44 const char* className, const JNINativeMethod* gMethods, int numMethods);
47 * Call a static Java function that takes no arguments and returns void.
49 status_t callStatic(const char* className, const char* methodName);
52 * Call a class's static main method with the given arguments,
54 status_t callMain(const char* className, int argc, const char* const argv[]);
57 * Find a class, with the input either of the form
58 * "package/class" or "package.class".
60 static jclass findClass(JNIEnv* env, const char* className);
62 int addVmArguments(int argc, const char* const argv[]);
64 void start(const char *classname, const bool startSystemServer);
65 void start(); // start in android.util.RuntimeInit
67 static AndroidRuntime* getRuntime();
70 * This gets called after the JavaVM has initialized. Override it
71 * with the system's native entry point.
73 virtual void onStarted() = 0;
76 * This gets called after the JavaVM has initialized after a Zygote
77 * fork. Override it to initialize threads, etc. Upon return, the
78 * correct static main will be invoked.
80 virtual void onZygoteInit() {};
84 * Called when the Java application exits. The default
85 * implementation calls exit(code).
87 virtual void onExit(int code);
89 /** create a new thread that is visible from Java */
90 static android_thread_id_t createJavaThread(const char* name, void (*start)(void *),
93 /** return a pointer to the VM running in this process */
94 static JavaVM* getJavaVM() { return mJavaVM; }
96 /** return a pointer to the JNIEnv pointer for this thread */
97 static JNIEnv* getJNIEnv();
100 static int startReg(JNIEnv* env);
101 void parseExtraOpts(char* extraOptsBuf);
102 int startVm(JavaVM** pJavaVM, JNIEnv** pEnv);
104 Vector<JavaVMOption> mOptions;
106 /* JNI JavaVM pointer */
107 static JavaVM* mJavaVM;
110 * Thread creation helpers.
112 static int javaCreateThreadEtc(
113 android_thread_func_t entryFunction,
115 const char* threadName,
116 int32_t threadPriority,
117 size_t threadStackSize,
118 android_thread_id_t* threadId);
119 static int javaThreadShell(void* args);
122 // Returns the Unix file descriptor for a ParcelFileDescriptor object
123 extern int getParcelFileDescriptorFD(JNIEnv* env, jobject object);