| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#ifndef _RUNTIME_ANDROID_RUNTIME_H |
| 20 |
#define _RUNTIME_ANDROID_RUNTIME_H |
| 21 |
|
| 22 |
#include <jni.h> |
| 23 |
#include <pthread.h> |
| 24 |
#include <utils/Errors.h> |
| 25 |
#include <utils/String16.h> |
| 26 |
#include <utils/String8.h> |
| 27 |
#include <utils/Vector.h> |
| 28 |
#include <utils/threads.h> |
| 29 |
|
| 30 |
namespace android { |
| 31 |
|
| 32 |
class AndroidRuntime |
| 33 |
{ |
| 34 |
public: |
| 35 |
AndroidRuntime(char* argBlockStart, size_t argBlockSize); |
| 36 |
virtual ~AndroidRuntime(); |
| 37 |
|
| 38 |
enum StartMode { |
| 39 |
Zygote, |
| 40 |
SystemServer, |
| 41 |
Application, |
| 42 |
Tool, |
| 43 |
}; |
| 44 |
|
| 45 |
void setArgv0(const char* argv0, bool setProcName = false); |
| 46 |
void addOption(const char* optionString, void* extra_info = NULL); |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
static int registerNativeMethods(JNIEnv* env, |
| 52 |
const char* className, const JNINativeMethod* gMethods, int numMethods); |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
status_t callMain(const String8& className, jclass clazz, const Vector<String8>& args); |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
static jclass findClass(JNIEnv* env, const char* className); |
| 64 |
|
| 65 |
void start(const char *classname, const Vector<String8>& options, bool zygote); |
| 66 |
|
| 67 |
void exit(int code); |
| 68 |
|
| 69 |
void setExitWithoutCleanup(bool exitWithoutCleanup) { |
| 70 |
mExitWithoutCleanup = exitWithoutCleanup; |
| 71 |
} |
| 72 |
|
| 73 |
static AndroidRuntime* getRuntime(); |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
virtual void onVmCreated(JNIEnv* env); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
virtual void onStarted() = 0; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
virtual void onZygoteInit() { } |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
virtual void onExit(int ) { } |
| 100 |
|
| 101 |
|
| 102 |
static android_thread_id_t createJavaThread(const char* name, void (*start)(void *), |
| 103 |
void* arg); |
| 104 |
|
| 105 |
|
| 106 |
static JavaVM* getJavaVM(); |
| 107 |
|
| 108 |
|
| 109 |
static JNIEnv* getJNIEnv(); |
| 110 |
|
| 111 |
|
| 112 |
static char* toSlashClassName(const char* className); |
| 113 |
|
| 114 |
|
| 115 |
static jstring NewStringLatin1(JNIEnv* env, const char* bytes); |
| 116 |
|
| 117 |
private: |
| 118 |
static int startReg(JNIEnv* env); |
| 119 |
bool parseRuntimeOption(const char* property, |
| 120 |
char* buffer, |
| 121 |
const char* runtimeArg, |
| 122 |
const char* defaultArg = ""); |
| 123 |
bool parseCompilerOption(const char* property, |
| 124 |
char* buffer, |
| 125 |
const char* compilerArg, |
| 126 |
const char* quotingArg); |
| 127 |
bool parseCompilerRuntimeOption(const char* property, |
| 128 |
char* buffer, |
| 129 |
const char* runtimeArg, |
| 130 |
const char* quotingArg); |
| 131 |
void parseExtraOpts(char* extraOptsBuf, const char* quotingArg); |
| 132 |
int startVm(JavaVM** pJavaVM, JNIEnv** pEnv, bool zygote, bool primary_zygote); |
| 133 |
|
| 134 |
Vector<JavaVMOption> mOptions; |
| 135 |
bool mExitWithoutCleanup; |
| 136 |
char* const mArgBlockStart; |
| 137 |
const size_t mArgBlockLength; |
| 138 |
|
| 139 |
|
| 140 |
static JavaVM* mJavaVM; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
static int javaCreateThreadEtc( |
| 146 |
android_thread_func_t entryFunction, |
| 147 |
void* userData, |
| 148 |
const char* threadName, |
| 149 |
int32_t threadPriority, |
| 150 |
size_t threadStackSize, |
| 151 |
android_thread_id_t* threadId); |
| 152 |
static int javaThreadShell(void* args); |
| 153 |
}; |
| 154 |
|
| 155 |
} |
| 156 |
|
| 157 |
#endif |