From 7825334929b098b36e1144872200e75ba6d24b13 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Thu, 6 Feb 2014 15:25:25 -0800 Subject: [PATCH] Split AndroidRuntime into AndroidRuntimeBase base-class and the rest. AndroidRuntimeBase (exported by libandroid_runtime_base.so) is all you need to link against to gain the ability to do AndroidRuntimeBase::getJNIEnv() thus minimizing build dependencies. Change-Id: Ia7f0c94c8c02b974c068e0db34774827f96aa95b --- cmds/app_process/Android.mk | 4 +- core/jni/Android.mk | 24 +++++++-- core/jni/AndroidRuntime.cpp | 28 ---------- core/jni/AndroidRuntimeBase.cpp | 56 ++++++++++++++++++++ include/android_runtime/AndroidRuntime.h | 19 ++----- include/android_runtime/AndroidRuntimeBase.h | 50 +++++++++++++++++ media/jni/Android.mk | 1 + media/jni/mediaeditor/Android.mk | 1 + native/android/Android.mk | 3 +- native/graphics/jni/Android.mk | 1 + rs/jni/Android.mk | 1 + services/core/jni/Android.mk | 1 + 12 files changed, 139 insertions(+), 50 deletions(-) create mode 100644 core/jni/AndroidRuntimeBase.cpp create mode 100644 include/android_runtime/AndroidRuntimeBase.h diff --git a/cmds/app_process/Android.mk b/cmds/app_process/Android.mk index b9afe4024f637..4eef12920682f 100644 --- a/cmds/app_process/Android.mk +++ b/cmds/app_process/Android.mk @@ -9,7 +9,7 @@ LOCAL_SHARED_LIBRARIES := \ libutils \ liblog \ libbinder \ - libandroid_runtime + libandroid_runtime_derived LOCAL_MODULE:= app_process @@ -30,7 +30,7 @@ LOCAL_SHARED_LIBRARIES := \ libutils \ liblog \ libbinder \ - libandroid_runtime + libandroid_runtime_derived LOCAL_MODULE := app_process__asan LOCAL_MODULE_TAGS := eng diff --git a/core/jni/Android.mk b/core/jni/Android.mk index f8d96e394a6f9..cc1081a19eee0 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -1,6 +1,25 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) +LOCAL_SRC_FILES:= \ + AndroidRuntimeBase.cpp \ + android_os_Parcel.cpp \ + android_util_Binder.cpp + +LOCAL_SHARED_LIBRARIES:= \ + libbinder \ + libcutils \ + libnativehelper \ + libutils \ + +LOCAL_MODULE := libandroid_runtime + +include $(BUILD_SHARED_LIBRARY) + +################################################################################ + +include $(CLEAR_VARS) + LOCAL_CFLAGS += -DHAVE_CONFIG_H -DKHTML_NO_EXCEPTIONS -DGKWQ_NO_JAVA LOCAL_CFLAGS += -DNO_SUPPORT_JS_BINDING -DQT_NO_WHEELEVENT -DKHTML_NO_XBL LOCAL_CFLAGS += -U__APPLE__ @@ -66,7 +85,6 @@ LOCAL_SRC_FILES:= \ android_os_Debug.cpp \ android_os_MemoryFile.cpp \ android_os_MessageQueue.cpp \ - android_os_Parcel.cpp \ android_os_SELinux.cpp \ android_os_SystemClock.cpp \ android_os_SystemProperties.cpp \ @@ -78,7 +96,6 @@ LOCAL_SRC_FILES:= \ android_nio_utils.cpp \ android_text_format_Time.cpp \ android_util_AssetManager.cpp \ - android_util_Binder.cpp \ android_util_EventLog.cpp \ android_util_Log.cpp \ android_util_FloatMath.cpp \ @@ -182,6 +199,7 @@ LOCAL_C_INCLUDES += \ LOCAL_SHARED_LIBRARIES := \ libmemtrack \ + libandroid_runtime \ libandroidfw \ libexpat \ libnativehelper \ @@ -241,7 +259,7 @@ ifeq ($(WITH_MALLOC_LEAK_CHECK),true) LOCAL_CFLAGS += -DMALLOC_LEAK_CHECK endif -LOCAL_MODULE:= libandroid_runtime +LOCAL_MODULE:= libandroid_runtime_derived include external/stlport/libstlport.mk include $(BUILD_SHARED_LIBRARY) diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index 7ed66415e883e..77be9ec563f51 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -226,9 +226,6 @@ int register_com_android_internal_os_RuntimeInit(JNIEnv* env) // ---------------------------------------------------------------------- -/*static*/ JavaVM* AndroidRuntime::mJavaVM = NULL; - - AndroidRuntime::AndroidRuntime() : mExitWithoutCleanup(false) { @@ -256,15 +253,6 @@ AndroidRuntime::~AndroidRuntime() SkGraphics::Term(); } -/* - * Register native methods using JNI. - */ -/*static*/ int AndroidRuntime::registerNativeMethods(JNIEnv* env, - const char* className, const JNINativeMethod* gMethods, int numMethods) -{ - return jniRegisterNativeMethods(env, className, gMethods, numMethods); -} - status_t AndroidRuntime::callMain(const char* className, jclass clazz, int argc, const char* const argv[]) { @@ -926,22 +914,6 @@ void AndroidRuntime::onVmCreated(JNIEnv* env) // If AndroidRuntime had anything to do here, we'd have done it in 'start'. } -/* - * Get the JNIEnv pointer for this thread. - * - * Returns NULL if the slot wasn't allocated or populated. - */ -/*static*/ JNIEnv* AndroidRuntime::getJNIEnv() -{ - JNIEnv* env; - JavaVM* vm = AndroidRuntime::getJavaVM(); - assert(vm != NULL); - - if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) - return NULL; - return env; -} - /* * Makes the current thread visible to the VM. * diff --git a/core/jni/AndroidRuntimeBase.cpp b/core/jni/AndroidRuntimeBase.cpp new file mode 100644 index 0000000000000..38afc49c0dfeb --- /dev/null +++ b/core/jni/AndroidRuntimeBase.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "AndroidRuntimeBase" +//#define LOG_NDEBUG 0 +#include + +#include + +#include "jni.h" +#include "JNIHelp.h" + +namespace android { + +/*static*/ JavaVM* AndroidRuntimeBase::mJavaVM = NULL; + +/* + * Get the JNIEnv pointer for this thread. + * + * Returns NULL if the slot wasn't allocated or populated. + */ +/*static*/ JNIEnv* AndroidRuntimeBase::getJNIEnv() +{ + JNIEnv* env; + JavaVM* vm = AndroidRuntimeBase::getJavaVM(); + assert(vm != NULL); + + if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) + return NULL; + return env; +} + +/* + * Register native methods using JNI. + */ +/*static*/ int AndroidRuntimeBase::registerNativeMethods(JNIEnv* env, + const char* className, const JNINativeMethod* gMethods, int numMethods) +{ + return jniRegisterNativeMethods(env, className, gMethods, numMethods); +} + +} // namespace android + diff --git a/include/android_runtime/AndroidRuntime.h b/include/android_runtime/AndroidRuntime.h index 0b3ce9a261b41..efd92bbb8050c 100644 --- a/include/android_runtime/AndroidRuntime.h +++ b/include/android_runtime/AndroidRuntime.h @@ -19,6 +19,8 @@ #ifndef _RUNTIME_ANDROID_RUNTIME_H #define _RUNTIME_ANDROID_RUNTIME_H +#include "AndroidRuntimeBase.h" + #include #include #include @@ -31,7 +33,7 @@ namespace android { -class AndroidRuntime +class AndroidRuntime : public AndroidRuntimeBase { public: AndroidRuntime(); @@ -44,12 +46,6 @@ public: Tool, }; - /** - * Register a set of methods in the specified class. - */ - static int registerNativeMethods(JNIEnv* env, - const char* className, const JNINativeMethod* gMethods, int numMethods); - /** * Call a class's static main method with the given arguments, */ @@ -104,12 +100,6 @@ public: static android_thread_id_t createJavaThread(const char* name, void (*start)(void *), void* arg); - /** return a pointer to the VM running in this process */ - static JavaVM* getJavaVM() { return mJavaVM; } - - /** return a pointer to the JNIEnv pointer for this thread */ - static JNIEnv* getJNIEnv(); - /** return a new string corresponding to 'className' with all '.'s replaced by '/'s. */ static char* toSlashClassName(const char* className); @@ -121,9 +111,6 @@ private: Vector mOptions; bool mExitWithoutCleanup; - /* JNI JavaVM pointer */ - static JavaVM* mJavaVM; - /* * Thread creation helpers. */ diff --git a/include/android_runtime/AndroidRuntimeBase.h b/include/android_runtime/AndroidRuntimeBase.h new file mode 100644 index 0000000000000..2b149870093c3 --- /dev/null +++ b/include/android_runtime/AndroidRuntimeBase.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _RUNTIME_ANDROID_RUNTIME_BASE_H +#define _RUNTIME_ANDROID_RUNTIME_BASE_H + +#include + +namespace android { + +struct AndroidRuntimeBase { + /** return a pointer to the VM running in this process */ + static JavaVM* getJavaVM() { return mJavaVM; } + + /** return a pointer to the JNIEnv pointer for this thread */ + static JNIEnv* getJNIEnv(); + + /** + * Register a set of methods in the specified class. + */ + static int registerNativeMethods(JNIEnv* env, + const char* className, const JNINativeMethod* gMethods, int numMethods); + +protected: + /* JNI JavaVM pointer */ + static JavaVM* mJavaVM; + + AndroidRuntimeBase() {} + virtual ~AndroidRuntimeBase() {} + + AndroidRuntimeBase(const AndroidRuntimeBase &); + AndroidRuntimeBase &operator=(const AndroidRuntimeBase &); +}; + +} // namespace android + +#endif // _RUNTIME_ANDROID_RUNTIME_BASE_H diff --git a/media/jni/Android.mk b/media/jni/Android.mk index 51fccd4d1b231..8323ae3ca88a1 100644 --- a/media/jni/Android.mk +++ b/media/jni/Android.mk @@ -24,6 +24,7 @@ LOCAL_SRC_FILES:= \ LOCAL_SHARED_LIBRARIES := \ libandroid_runtime \ + libandroid_runtime_derived \ libnativehelper \ libutils \ libbinder \ diff --git a/media/jni/mediaeditor/Android.mk b/media/jni/mediaeditor/Android.mk index 6be7fdd40b83d..b9c70f8f90cc7 100644 --- a/media/jni/mediaeditor/Android.mk +++ b/media/jni/mediaeditor/Android.mk @@ -48,6 +48,7 @@ LOCAL_C_INCLUDES += \ LOCAL_SHARED_LIBRARIES := \ libandroid_runtime \ + libandroid_runtime_derived \ libaudioflinger \ libaudioutils \ libbinder \ diff --git a/native/android/Android.mk b/native/android/Android.mk index cda38e06270ba..f55f94a782646 100644 --- a/native/android/Android.mk +++ b/native/android/Android.mk @@ -25,7 +25,8 @@ LOCAL_SHARED_LIBRARIES := \ libbinder \ libui \ libgui \ - libandroid_runtime + libandroid_runtime \ + libandroid_runtime_derived LOCAL_STATIC_LIBRARIES := \ libstorage diff --git a/native/graphics/jni/Android.mk b/native/graphics/jni/Android.mk index 8b333e7294542..02fa1b913067f 100644 --- a/native/graphics/jni/Android.mk +++ b/native/graphics/jni/Android.mk @@ -20,6 +20,7 @@ LOCAL_SRC_FILES:= \ LOCAL_SHARED_LIBRARIES := \ libandroid_runtime \ + libandroid_runtime_derived \ libskia LOCAL_C_INCLUDES += \ diff --git a/rs/jni/Android.mk b/rs/jni/Android.mk index cbb5b3b6ba504..4814a6e0f9a1b 100644 --- a/rs/jni/Android.mk +++ b/rs/jni/Android.mk @@ -6,6 +6,7 @@ LOCAL_SRC_FILES:= \ LOCAL_SHARED_LIBRARIES := \ libandroid_runtime \ + libandroid_runtime_derived \ libandroidfw \ libnativehelper \ libRS \ diff --git a/services/core/jni/Android.mk b/services/core/jni/Android.mk index 1a3ce639c015d..93b80dc34d8fb 100644 --- a/services/core/jni/Android.mk +++ b/services/core/jni/Android.mk @@ -35,6 +35,7 @@ LOCAL_C_INCLUDES += \ LOCAL_SHARED_LIBRARIES += \ libandroid_runtime \ + libandroid_runtime_derived \ libandroidfw \ libbinder \ libcutils \