blob: 321c2e3dcc4400987dbbec27af5e6becfe1f0418 [file] [log] [blame]
James Dongf3997522011-03-11 12:02:12 -08001/*
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002**
3** Copyright 2007, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
James Dongf3997522011-03-11 12:02:12 -080018//#define LOG_NDEBUG 0
19#define LOG_TAG "MediaScannerJNI"
20#include <utils/Log.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021#include <utils/threads.h>
James Dongf3997522011-03-11 12:02:12 -080022#include <media/mediascanner.h>
23#include <media/stagefright/StagefrightMediaScanner.h>
Elliott Hughes9fa803b2014-06-05 10:38:30 -070024#include <private/media/VideoFrame.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
26#include "jni.h"
27#include "JNIHelp.h"
28#include "android_runtime/AndroidRuntime.h"
Ruben Brunk87eac992013-09-09 17:44:59 -070029#include "android_runtime/Log.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031using namespace android;
32
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
James Dongf3997522011-03-11 12:02:12 -080034static const char* const kClassMediaScannerClient =
35 "android/media/MediaScannerClient";
36
37static const char* const kClassMediaScanner =
38 "android/media/MediaScanner";
39
40static const char* const kRunTimeException =
41 "java/lang/RuntimeException";
42
43static const char* const kIllegalArgumentException =
44 "java/lang/IllegalArgumentException";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
James Dong133cf8b2011-03-11 15:18:40 -080046struct fields_t {
47 jfieldID context;
48};
49static fields_t fields;
James Dong133cf8b2011-03-11 15:18:40 -080050
Jeff Brown2c70d4a2011-07-20 16:38:43 -070051static status_t checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodName) {
52 if (env->ExceptionCheck()) {
Steve Blockc6aacce2012-01-06 19:20:56 +000053 ALOGE("An exception was thrown by callback '%s'.", methodName);
Jeff Brown2c70d4a2011-07-20 16:38:43 -070054 LOGE_EX(env);
55 env->ExceptionClear();
56 return UNKNOWN_ERROR;
57 }
58 return OK;
59}
60
Marco Nelissena0a73ed2013-02-12 18:33:41 +000061// stolen from dalvik/vm/checkJni.cpp
62static bool isValidUtf8(const char* bytes) {
63 while (*bytes != '\0') {
64 unsigned char utf8 = *(bytes++);
65 // Switch on the high four bits.
66 switch (utf8 >> 4) {
67 case 0x00:
68 case 0x01:
69 case 0x02:
70 case 0x03:
71 case 0x04:
72 case 0x05:
73 case 0x06:
74 case 0x07:
75 // Bit pattern 0xxx. No need for any extra bytes.
76 break;
77 case 0x08:
78 case 0x09:
79 case 0x0a:
80 case 0x0b:
81 case 0x0f:
82 /*
83 * Bit pattern 10xx or 1111, which are illegal start bytes.
84 * Note: 1111 is valid for normal UTF-8, but not the
85 * modified UTF-8 used here.
86 */
87 return false;
88 case 0x0e:
89 // Bit pattern 1110, so there are two additional bytes.
90 utf8 = *(bytes++);
91 if ((utf8 & 0xc0) != 0x80) {
92 return false;
93 }
94 // Fall through to take care of the final byte.
95 case 0x0c:
96 case 0x0d:
97 // Bit pattern 110x, so there is one additional byte.
98 utf8 = *(bytes++);
99 if ((utf8 & 0xc0) != 0x80) {
100 return false;
101 }
102 break;
103 }
104 }
105 return true;
106}
107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108class MyMediaScannerClient : public MediaScannerClient
109{
110public:
111 MyMediaScannerClient(JNIEnv *env, jobject client)
112 : mEnv(env),
113 mClient(env->NewGlobalRef(client)),
114 mScanFileMethodID(0),
115 mHandleStringTagMethodID(0),
116 mSetMimeTypeMethodID(0)
117 {
Steve Block06ade6a2011-10-20 11:56:00 +0100118 ALOGV("MyMediaScannerClient constructor");
James Dongf3997522011-03-11 12:02:12 -0800119 jclass mediaScannerClientInterface =
120 env->FindClass(kClassMediaScannerClient);
121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 if (mediaScannerClientInterface == NULL) {
Steve Blockc6aacce2012-01-06 19:20:56 +0000123 ALOGE("Class %s not found", kClassMediaScannerClient);
James Dongf3997522011-03-11 12:02:12 -0800124 } else {
125 mScanFileMethodID = env->GetMethodID(
126 mediaScannerClientInterface,
127 "scanFile",
Mike Lockwood997354e2011-04-24 11:15:09 -0700128 "(Ljava/lang/String;JJZZ)V");
James Dongf3997522011-03-11 12:02:12 -0800129
130 mHandleStringTagMethodID = env->GetMethodID(
131 mediaScannerClientInterface,
132 "handleStringTag",
133 "(Ljava/lang/String;Ljava/lang/String;)V");
134
135 mSetMimeTypeMethodID = env->GetMethodID(
136 mediaScannerClientInterface,
137 "setMimeType",
138 "(Ljava/lang/String;)V");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 }
140 }
James Dongf3997522011-03-11 12:02:12 -0800141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 virtual ~MyMediaScannerClient()
143 {
Steve Block06ade6a2011-10-20 11:56:00 +0100144 ALOGV("MyMediaScannerClient destructor");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 mEnv->DeleteGlobalRef(mClient);
146 }
James Dongf3997522011-03-11 12:02:12 -0800147
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700148 virtual status_t scanFile(const char* path, long long lastModified,
Mike Lockwood997354e2011-04-24 11:15:09 -0700149 long long fileSize, bool isDirectory, bool noMedia)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 {
Steve Block06ade6a2011-10-20 11:56:00 +0100151 ALOGV("scanFile: path(%s), time(%lld), size(%lld) and isDir(%d)",
James Dongf3997522011-03-11 12:02:12 -0800152 path, lastModified, fileSize, isDirectory);
153
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 jstring pathStr;
James Dongf3997522011-03-11 12:02:12 -0800155 if ((pathStr = mEnv->NewStringUTF(path)) == NULL) {
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700156 mEnv->ExceptionClear();
157 return NO_MEMORY;
James Dongf3997522011-03-11 12:02:12 -0800158 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159
Mike Lockwood076e05b2010-12-16 12:54:24 -0800160 mEnv->CallVoidMethod(mClient, mScanFileMethodID, pathStr, lastModified,
Mike Lockwood997354e2011-04-24 11:15:09 -0700161 fileSize, isDirectory, noMedia);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162
163 mEnv->DeleteLocalRef(pathStr);
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700164 return checkAndClearExceptionFromCallback(mEnv, "scanFile");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 }
166
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700167 virtual status_t handleStringTag(const char* name, const char* value)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 {
Steve Block06ade6a2011-10-20 11:56:00 +0100169 ALOGV("handleStringTag: name(%s) and value(%s)", name, value);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 jstring nameStr, valueStr;
James Dongf3997522011-03-11 12:02:12 -0800171 if ((nameStr = mEnv->NewStringUTF(name)) == NULL) {
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700172 mEnv->ExceptionClear();
173 return NO_MEMORY;
James Dongf3997522011-03-11 12:02:12 -0800174 }
Marco Nelissenf51f1bd2011-11-02 10:49:50 -0700175 char *cleaned = NULL;
Marco Nelissena0a73ed2013-02-12 18:33:41 +0000176 if (!isValidUtf8(value)) {
Marco Nelissenf51f1bd2011-11-02 10:49:50 -0700177 cleaned = strdup(value);
178 char *chp = cleaned;
179 char ch;
180 while ((ch = *chp)) {
181 if (ch & 0x80) {
182 *chp = '?';
183 }
184 chp++;
185 }
186 value = cleaned;
187 }
188 valueStr = mEnv->NewStringUTF(value);
189 free(cleaned);
190 if (valueStr == NULL) {
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700191 mEnv->DeleteLocalRef(nameStr);
192 mEnv->ExceptionClear();
193 return NO_MEMORY;
James Dongf3997522011-03-11 12:02:12 -0800194 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195
James Dongf3997522011-03-11 12:02:12 -0800196 mEnv->CallVoidMethod(
197 mClient, mHandleStringTagMethodID, nameStr, valueStr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198
199 mEnv->DeleteLocalRef(nameStr);
200 mEnv->DeleteLocalRef(valueStr);
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700201 return checkAndClearExceptionFromCallback(mEnv, "handleStringTag");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 }
203
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700204 virtual status_t setMimeType(const char* mimeType)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 {
Steve Block06ade6a2011-10-20 11:56:00 +0100206 ALOGV("setMimeType: %s", mimeType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 jstring mimeTypeStr;
James Dongf3997522011-03-11 12:02:12 -0800208 if ((mimeTypeStr = mEnv->NewStringUTF(mimeType)) == NULL) {
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700209 mEnv->ExceptionClear();
210 return NO_MEMORY;
James Dongf3997522011-03-11 12:02:12 -0800211 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212
213 mEnv->CallVoidMethod(mClient, mSetMimeTypeMethodID, mimeTypeStr);
214
215 mEnv->DeleteLocalRef(mimeTypeStr);
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700216 return checkAndClearExceptionFromCallback(mEnv, "setMimeType");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 }
218
219private:
220 JNIEnv *mEnv;
221 jobject mClient;
James Dongf3997522011-03-11 12:02:12 -0800222 jmethodID mScanFileMethodID;
223 jmethodID mHandleStringTagMethodID;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 jmethodID mSetMimeTypeMethodID;
225};
226
227
James Dong133cf8b2011-03-11 15:18:40 -0800228static MediaScanner *getNativeScanner_l(JNIEnv* env, jobject thiz)
229{
Ashok Bhat075e9a12014-01-06 13:45:09 +0000230 return (MediaScanner *) env->GetLongField(thiz, fields.context);
James Dong133cf8b2011-03-11 15:18:40 -0800231}
232
James Dong133cf8b2011-03-11 15:18:40 -0800233static void setNativeScanner_l(JNIEnv* env, jobject thiz, MediaScanner *s)
234{
Ashok Bhat075e9a12014-01-06 13:45:09 +0000235 env->SetLongField(thiz, fields.context, (jlong)s);
James Dong133cf8b2011-03-11 15:18:40 -0800236}
237
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238static void
James Dongf3997522011-03-11 12:02:12 -0800239android_media_MediaScanner_processDirectory(
240 JNIEnv *env, jobject thiz, jstring path, jobject client)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241{
Steve Block06ade6a2011-10-20 11:56:00 +0100242 ALOGV("processDirectory");
James Dong133cf8b2011-03-11 15:18:40 -0800243 MediaScanner *mp = getNativeScanner_l(env, thiz);
244 if (mp == NULL) {
245 jniThrowException(env, kRunTimeException, "No scanner available");
246 return;
247 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248
249 if (path == NULL) {
James Dongf3997522011-03-11 12:02:12 -0800250 jniThrowException(env, kIllegalArgumentException, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 return;
252 }
Mike Lockwoodc37255d2010-09-10 14:47:36 -0400253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 const char *pathStr = env->GetStringUTFChars(path, NULL);
255 if (pathStr == NULL) { // Out of memory
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 return;
257 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258
259 MyMediaScannerClient myClient(env, client);
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700260 MediaScanResult result = mp->processDirectory(pathStr, myClient);
261 if (result == MEDIA_SCAN_RESULT_ERROR) {
Steve Blockc6aacce2012-01-06 19:20:56 +0000262 ALOGE("An error occurred while scanning directory '%s'.", pathStr);
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700263 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 env->ReleaseStringUTFChars(path, pathStr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265}
266
267static void
James Dongf3997522011-03-11 12:02:12 -0800268android_media_MediaScanner_processFile(
269 JNIEnv *env, jobject thiz, jstring path,
270 jstring mimeType, jobject client)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271{
Steve Block06ade6a2011-10-20 11:56:00 +0100272 ALOGV("processFile");
James Dong133cf8b2011-03-11 15:18:40 -0800273
274 // Lock already hold by processDirectory
275 MediaScanner *mp = getNativeScanner_l(env, thiz);
276 if (mp == NULL) {
277 jniThrowException(env, kRunTimeException, "No scanner available");
278 return;
279 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280
281 if (path == NULL) {
James Dongf3997522011-03-11 12:02:12 -0800282 jniThrowException(env, kIllegalArgumentException, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 return;
284 }
James Dongf3997522011-03-11 12:02:12 -0800285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 const char *pathStr = env->GetStringUTFChars(path, NULL);
287 if (pathStr == NULL) { // Out of memory
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800288 return;
289 }
James Dongf3997522011-03-11 12:02:12 -0800290
291 const char *mimeTypeStr =
292 (mimeType ? env->GetStringUTFChars(mimeType, NULL) : NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 if (mimeType && mimeTypeStr == NULL) { // Out of memory
James Dongc371a022011-04-06 12:16:07 -0700294 // ReleaseStringUTFChars can be called with an exception pending.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 env->ReleaseStringUTFChars(path, pathStr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 return;
297 }
298
299 MyMediaScannerClient myClient(env, client);
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700300 MediaScanResult result = mp->processFile(pathStr, mimeTypeStr, myClient);
301 if (result == MEDIA_SCAN_RESULT_ERROR) {
Steve Blockc6aacce2012-01-06 19:20:56 +0000302 ALOGE("An error occurred while scanning file '%s'.", pathStr);
Jeff Brown2c70d4a2011-07-20 16:38:43 -0700303 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800304 env->ReleaseStringUTFChars(path, pathStr);
305 if (mimeType) {
306 env->ReleaseStringUTFChars(mimeType, mimeTypeStr);
307 }
308}
309
310static void
James Dongf3997522011-03-11 12:02:12 -0800311android_media_MediaScanner_setLocale(
312 JNIEnv *env, jobject thiz, jstring locale)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313{
Steve Block06ade6a2011-10-20 11:56:00 +0100314 ALOGV("setLocale");
James Dong133cf8b2011-03-11 15:18:40 -0800315 MediaScanner *mp = getNativeScanner_l(env, thiz);
316 if (mp == NULL) {
317 jniThrowException(env, kRunTimeException, "No scanner available");
318 return;
319 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320
321 if (locale == NULL) {
James Dongf3997522011-03-11 12:02:12 -0800322 jniThrowException(env, kIllegalArgumentException, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 return;
324 }
325 const char *localeStr = env->GetStringUTFChars(locale, NULL);
326 if (localeStr == NULL) { // Out of memory
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 return;
328 }
329 mp->setLocale(localeStr);
330
331 env->ReleaseStringUTFChars(locale, localeStr);
332}
333
334static jbyteArray
James Dongf3997522011-03-11 12:02:12 -0800335android_media_MediaScanner_extractAlbumArt(
336 JNIEnv *env, jobject thiz, jobject fileDescriptor)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800337{
Steve Block06ade6a2011-10-20 11:56:00 +0100338 ALOGV("extractAlbumArt");
James Dong133cf8b2011-03-11 15:18:40 -0800339 MediaScanner *mp = getNativeScanner_l(env, thiz);
340 if (mp == NULL) {
341 jniThrowException(env, kRunTimeException, "No scanner available");
342 return NULL;
343 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800344
345 if (fileDescriptor == NULL) {
James Dongf3997522011-03-11 12:02:12 -0800346 jniThrowException(env, kIllegalArgumentException, NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 return NULL;
348 }
349
Elliott Hughesa3804cf2011-04-11 16:50:19 -0700350 int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
Elliott Hughes95d3f862014-06-10 16:53:31 -0700351 MediaAlbumArt* mediaAlbumArt = mp->extractAlbumArt(fd);
Elliott Hughese0f2fa32014-06-09 09:22:58 -0700352 if (mediaAlbumArt == NULL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800353 return NULL;
354 }
James Dongf3997522011-03-11 12:02:12 -0800355
Elliott Hughes95d3f862014-06-10 16:53:31 -0700356 jbyteArray array = env->NewByteArray(mediaAlbumArt->size());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 if (array != NULL) {
Elliott Hughes95d3f862014-06-10 16:53:31 -0700358 const jbyte* data =
359 reinterpret_cast<const jbyte*>(mediaAlbumArt->data());
360 env->SetByteArrayRegion(array, 0, mediaAlbumArt->size(), data);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800361 }
James Dongf3997522011-03-11 12:02:12 -0800362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363done:
Elliott Hughes9fa803b2014-06-05 10:38:30 -0700364 free(mediaAlbumArt);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 // if NewByteArray() returned NULL, an out-of-memory
366 // exception will have been raised. I just want to
367 // return null in that case.
368 env->ExceptionClear();
369 return array;
370}
371
Marco Nelissen4935d052009-08-03 11:12:58 -0700372// This function gets a field ID, which in turn causes class initialization.
373// It is called from a static block in MediaScanner, which won't run until the
374// first time an instance of this class is used.
375static void
376android_media_MediaScanner_native_init(JNIEnv *env)
377{
Steve Block06ade6a2011-10-20 11:56:00 +0100378 ALOGV("native_init");
James Dongf3997522011-03-11 12:02:12 -0800379 jclass clazz = env->FindClass(kClassMediaScanner);
Marco Nelissen4935d052009-08-03 11:12:58 -0700380 if (clazz == NULL) {
Marco Nelissen4935d052009-08-03 11:12:58 -0700381 return;
382 }
383
Ashok Bhat075e9a12014-01-06 13:45:09 +0000384 fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
Marco Nelissen4935d052009-08-03 11:12:58 -0700385 if (fields.context == NULL) {
Marco Nelissen4935d052009-08-03 11:12:58 -0700386 return;
387 }
388}
389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390static void
391android_media_MediaScanner_native_setup(JNIEnv *env, jobject thiz)
392{
Steve Block06ade6a2011-10-20 11:56:00 +0100393 ALOGV("native_setup");
Andreas Huber8d65dd22010-06-23 16:40:57 -0700394 MediaScanner *mp = new StagefrightMediaScanner;
Andreas Huberbfb9fb12009-12-03 11:31:19 -0800395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 if (mp == NULL) {
James Dongf3997522011-03-11 12:02:12 -0800397 jniThrowException(env, kRunTimeException, "Out of memory");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 return;
399 }
400
Ashok Bhat075e9a12014-01-06 13:45:09 +0000401 env->SetLongField(thiz, fields.context, (jlong)mp);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402}
403
404static void
405android_media_MediaScanner_native_finalize(JNIEnv *env, jobject thiz)
406{
Steve Block06ade6a2011-10-20 11:56:00 +0100407 ALOGV("native_finalize");
James Dong133cf8b2011-03-11 15:18:40 -0800408 MediaScanner *mp = getNativeScanner_l(env, thiz);
James Dongf3997522011-03-11 12:02:12 -0800409 if (mp == 0) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 return;
James Dongf3997522011-03-11 12:02:12 -0800411 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 delete mp;
James Dong133cf8b2011-03-11 15:18:40 -0800413 setNativeScanner_l(env, thiz, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800414}
415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416static JNINativeMethod gMethods[] = {
James Dongf3997522011-03-11 12:02:12 -0800417 {
418 "processDirectory",
419 "(Ljava/lang/String;Landroid/media/MediaScannerClient;)V",
420 (void *)android_media_MediaScanner_processDirectory
421 },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422
James Dongf3997522011-03-11 12:02:12 -0800423 {
424 "processFile",
425 "(Ljava/lang/String;Ljava/lang/String;Landroid/media/MediaScannerClient;)V",
426 (void *)android_media_MediaScanner_processFile
427 },
428
429 {
430 "setLocale",
431 "(Ljava/lang/String;)V",
432 (void *)android_media_MediaScanner_setLocale
433 },
434
435 {
436 "extractAlbumArt",
437 "(Ljava/io/FileDescriptor;)[B",
438 (void *)android_media_MediaScanner_extractAlbumArt
439 },
440
441 {
442 "native_init",
443 "()V",
444 (void *)android_media_MediaScanner_native_init
445 },
446
447 {
448 "native_setup",
449 "()V",
450 (void *)android_media_MediaScanner_native_setup
451 },
452
453 {
454 "native_finalize",
455 "()V",
456 (void *)android_media_MediaScanner_native_finalize
457 },
458};
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459
Marco Nelissen4935d052009-08-03 11:12:58 -0700460// This function only registers the native methods, and is called from
461// JNI_OnLoad in android_media_MediaPlayer.cpp
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462int register_android_media_MediaScanner(JNIEnv *env)
463{
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 return AndroidRuntime::registerNativeMethods(env,
James Dongf3997522011-03-11 12:02:12 -0800465 kClassMediaScanner, gMethods, NELEM(gMethods));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466}