W/dalvikvm( 1473): in Landroid/media/MediaScanner;.processFile (Ljava/lang/String;Ljava/lang/String;Landroid/media/MediaScannerClient;)V (NewStringUTF)
I/dalvikvm( 1473): "MediaScannerService" prio=5 tid=10 NATIVE
I/dalvikvm( 1473): | group="main" sCount=0 dsCount=0 s=N obj=0x45f1ea18 self=0x22f0d0
I/dalvikvm( 1473): | sysTid=1647 nice=11 sched=3/0 cgrp=unknown handle=2229456
I/dalvikvm( 1473): at android.media.MediaScanner.processFile(Native Method)
I/dalvikvm( 1473): at android.media.MediaScanner.access$500(MediaScanner.java:103)
这个就是蛋疼的地方,
造成该问题的原因是没有通过虚拟机的checkjni检查。代码在dalvik/vm/CheckJni.c
/*
* Verify that "bytes" points to valid "modified UTF-8" data.
*/
static void checkUtfString(JNIEnv* env, const char* bytes, bool nullOk,
const char* func)
{
const char* origBytes = bytes;
if (bytes == NULL) {
if (!nullOk) {
LOGW("JNI WARNING: unexpectedly null UTF string/n");
goto fail;
}
return;
}
while (*bytes != '/0') {
u1 utf8 = *(bytes++);
// Switch on the high four bits.
switch (utf8 >> 4) {
case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
case 0x07: {
// Bit pattern 0xxx. No need for any extra bytes.
break;
}
case 0x08:
case 0x09:
case 0x0a:
case 0x0b:
case 0x0f: {
/*
* Bit pattern 10xx or 1111, which are illegal start bytes.
* Note: 1111 is valid for normal UTF-8, but not the
* modified UTF-8 used here.
*/
LOGW("JNI WARNING: illegal start byte 0x%x/n", utf8);
goto fail;
}
case 0x0e: {
// Bit pattern 1110, so there are two additional bytes.
utf8 = *(bytes++);
if ((utf8 & 0xc0) != 0x80) {
LOGW("JNI WARNING: illegal continuation byte 0x%x/n", utf8);
goto fail;
}
// Fall through to take care of the final byte.
}
case 0x0c:
case 0x0d: {
// Bit pattern 110x, so there is one additional byte.
utf8 = *(bytes++);
if ((utf8 & 0xc0) != 0x80) {
LOGW("JNI WARNING: illegal continuation byte 0x%x/n", utf8);
goto fail;
}
break;
}
}
}
return;
fail:
LOGW(" string: '%s'/n", origBytes);
showLocation(dvmGetCurrentJNIMethod(), func);
abortMaybe();
}
解决方法:
是否进行checkjni检查是由ro.kernel.android.checkjni决定。
在eng版本中ro.kernel.android.checkjni=1.而在user, userdebug版本不做检查
In build/core/main.mk
user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT))
enable_target_debugging := true
tags_to_install :=
ifneq (,$(user_variant))
...
ro.kernel.android.checkjni=0
else
...
ro.kernel.android.checkjni=1
note: 遇到了一次这个问题,kernel层上传的字符窜格式是S8, 长层接收转换时出错。