summaryrefslogtreecommitdiffstats
path: root/media/jni/android_media_MediaScanner.cpp
diff options
context:
space:
mode:
authorMarco Nelissen <marcone@google.com>2009-08-03 11:12:58 -0700
committerMarco Nelissen <marcone@google.com>2009-08-03 11:32:30 -0700
commit4935d05eaa306cef88cf0ab13eca386f270409ec (patch)
treea32743c415083ac6565997d2a62ec5432fbfe62e /media/jni/android_media_MediaScanner.cpp
parentf2beab58f34fc593fff583bfcd8143ce09fcdecd (diff)
downloadframeworks_base-4935d05eaa306cef88cf0ab13eca386f270409ec.zip
frameworks_base-4935d05eaa306cef88cf0ab13eca386f270409ec.tar.gz
frameworks_base-4935d05eaa306cef88cf0ab13eca386f270409ec.tar.bz2
Untangle MediaPlayer, MediaRecorder, MediaScanner and MediaMetadataRetriever JNI
code, so that creating one of those doesn't initialize all the others. Shaves a hundred milliseconds or so off music app startup time.
Diffstat (limited to 'media/jni/android_media_MediaScanner.cpp')
-rw-r--r--media/jni/android_media_MediaScanner.cpp38
1 files changed, 24 insertions, 14 deletions
diff --git a/media/jni/android_media_MediaScanner.cpp b/media/jni/android_media_MediaScanner.cpp
index 8764a70..97de486 100644
--- a/media/jni/android_media_MediaScanner.cpp
+++ b/media/jni/android_media_MediaScanner.cpp
@@ -241,6 +241,27 @@ done:
return array;
}
+// This function gets a field ID, which in turn causes class initialization.
+// It is called from a static block in MediaScanner, which won't run until the
+// first time an instance of this class is used.
+static void
+android_media_MediaScanner_native_init(JNIEnv *env)
+{
+ jclass clazz;
+
+ clazz = env->FindClass("android/media/MediaScanner");
+ if (clazz == NULL) {
+ jniThrowException(env, "java/lang/RuntimeException", "Can't find android/media/MediaScanner");
+ return;
+ }
+
+ fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+ if (fields.context == NULL) {
+ jniThrowException(env, "java/lang/RuntimeException", "Can't find MediaScanner.mNativeContext");
+ return;
+ }
+}
+
static void
android_media_MediaScanner_native_setup(JNIEnv *env, jobject thiz)
{
@@ -275,28 +296,17 @@ static JNINativeMethod gMethods[] = {
(void *)android_media_MediaScanner_processFile},
{"setLocale", "(Ljava/lang/String;)V", (void *)android_media_MediaScanner_setLocale},
{"extractAlbumArt", "(Ljava/io/FileDescriptor;)[B", (void *)android_media_MediaScanner_extractAlbumArt},
+ {"native_init", "()V", (void *)android_media_MediaScanner_native_init},
{"native_setup", "()V", (void *)android_media_MediaScanner_native_setup},
{"native_finalize", "()V", (void *)android_media_MediaScanner_native_finalize},
};
static const char* const kClassPathName = "android/media/MediaScanner";
+// This function only registers the native methods, and is called from
+// JNI_OnLoad in android_media_MediaPlayer.cpp
int register_android_media_MediaScanner(JNIEnv *env)
{
- jclass clazz;
-
- clazz = env->FindClass("android/media/MediaScanner");
- if (clazz == NULL) {
- LOGE("Can't find android/media/MediaScanner");
- return -1;
- }
-
- fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
- if (fields.context == NULL) {
- LOGE("Can't find MediaScanner.mNativeContext");
- return -1;
- }
-
return AndroidRuntime::registerNativeMethods(env,
"android/media/MediaScanner", gMethods, NELEM(gMethods));
}