blob: 22c9b72b62761e8f20dee97e97eb1b9ddd9f9329 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2005 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17//
18
19#ifndef _RUNTIME_ANDROID_RUNTIME_H
20#define _RUNTIME_ANDROID_RUNTIME_H
21
22#include <utils/Errors.h>
Mathias Agopian07952722009-05-19 19:08:10 -070023#include <binder/IBinder.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024#include <utils/String8.h>
25#include <utils/String16.h>
26#include <utils/Vector.h>
27#include <utils/threads.h>
28#include <pthread.h>
29#include <nativehelper/jni.h>
30
31
32namespace android {
Mike Lockwood81ea83d2010-06-30 17:49:41 -040033
34class CursorWindow;
35
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036class AndroidRuntime
37{
38public:
39 AndroidRuntime();
40 virtual ~AndroidRuntime();
41
42 /**
43 * Register a set of methods in the specified class.
44 */
45 static int registerNativeMethods(JNIEnv* env,
46 const char* className, const JNINativeMethod* gMethods, int numMethods);
47
48 /**
49 * Call a static Java function that takes no arguments and returns void.
50 */
51 status_t callStatic(const char* className, const char* methodName);
52
53 /**
54 * Call a class's static main method with the given arguments,
55 */
56 status_t callMain(const char* className, int argc, const char* const argv[]);
57
58 /**
59 * Find a class, with the input either of the form
60 * "package/class" or "package.class".
61 */
62 static jclass findClass(JNIEnv* env, const char* className);
63
64 int addVmArguments(int argc, const char* const argv[]);
65
66 void start(const char *classname, const bool startSystemServer);
67 void start(); // start in android.util.RuntimeInit
68
69 static AndroidRuntime* getRuntime();
70
71 /**
72 * This gets called after the JavaVM has initialized. Override it
73 * with the system's native entry point.
74 */
75 virtual void onStarted() = 0;
76
77 /**
78 * This gets called after the JavaVM has initialized after a Zygote
79 * fork. Override it to initialize threads, etc. Upon return, the
80 * correct static main will be invoked.
81 */
82 virtual void onZygoteInit() {};
83
84
85 /**
86 * Called when the Java application exits. The default
87 * implementation calls exit(code).
88 */
89 virtual void onExit(int code);
90
91 /** create a new thread that is visible from Java */
Mike Lockwoodf602d362010-06-20 14:28:16 -070092 static android_thread_id_t createJavaThread(const char* name, void (*start)(void *),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 void* arg);
94
95 /** return a pointer to the VM running in this process */
96 static JavaVM* getJavaVM() { return mJavaVM; }
97
98 /** return a pointer to the JNIEnv pointer for this thread */
99 static JNIEnv* getJNIEnv();
100
101private:
102 static int startReg(JNIEnv* env);
Andy McFaddene4d81f22010-07-14 16:02:20 -0700103 void parseExtraOpts(char* extraOptsBuf);
Andy McFaddenf70188a2009-03-31 15:52:13 -0700104 int startVm(JavaVM** pJavaVM, JNIEnv** pEnv);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105
106 Vector<JavaVMOption> mOptions;
107
108 /* JNI JavaVM pointer */
109 static JavaVM* mJavaVM;
110
111 /*
112 * Thread creation helpers.
113 */
114 static int javaCreateThreadEtc(
115 android_thread_func_t entryFunction,
116 void* userData,
117 const char* threadName,
118 int32_t threadPriority,
119 size_t threadStackSize,
120 android_thread_id_t* threadId);
121 static int javaThreadShell(void* args);
122};
123
124// Returns the Unix file descriptor for a ParcelFileDescriptor object
125extern int getParcelFileDescriptorFD(JNIEnv* env, jobject object);
126
Mike Lockwood81ea83d2010-06-30 17:49:41 -0400127extern CursorWindow * get_window_from_object(JNIEnv * env, jobject javaWindow);
128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129}
130
131#endif