JNI WARNING: input is not valid Modified UTF-8: illegal start byte 0x【已解决】
播放一首歌的时候出现该错误,导致表面上的重启。
具体信息为:
01-24 18:11:07.780 W/MMParserExtractor( 6226): Something looks wrong with the AlbumArtData, ignoring it
01-24 18:11:07.780 W/dalvikvm( 6362): JNI WARNING: input is not valid Modified UTF-8: illegal start byte 0xf3
01-24 18:11:07.780 W/dalvikvm( 6362): string: 'www.9t9t.com 1,1,?PQ'
01-24 18:11:07.780 W/dalvikvm( 6362): in Landroid/media/MediaMetadataRetriever;.extractMetadata:(I)Ljava/lang/String; (NewStringUTF)
01-24 18:11:07.780 I/dalvikvm( 6362): "android.server.ServerThread" prio=5 tid=11 NATIVE
01-24 18:11:07.780 W/dalvikvm( 6362): JNI WARNING: input is not valid Modified UTF-8: illegal start byte 0xf3
01-24 18:11:07.780 W/dalvikvm( 6362): string: 'www.9t9t.com 1,1,?PQ'
01-24 18:11:07.780 W/dalvikvm( 6362): in Landroid/media/MediaMetadataRetriever;.extractMetadata:(I)Ljava/lang/String; (NewStringUTF)
01-24 18:11:07.780 I/dalvikvm( 6362): "android.server.ServerThread" prio=5 tid=11 NATIVE
最后通过utf8字符判断修正该问题,文件位置frameworks\base\media\jni\android_media_MediaMetadataRetriever.cpp
增加函数IsUTF8()
bool IsUTF8(const void* pBuffer, long size)
{
bool IsUTF8 = true;
unsigned char* start = (unsigned char*)pBuffer;
unsigned char* end = (unsigned char*)pBuffer + size;
while (start < end)
{
if (*start < 0×80) // (10000000): 值小于0×80的为ASCII字符
{
start++;
}
else if (*start < (0xC0)) // (11000000): 值介于0×80与0xC0之间的为无效UTF-8字符
{
IsUTF8 = false;
break;
}
else if (*start < (0xE0)) // (11100000): 此范围内为2字节UTF-8字符
{
if (start >= end - 1)
break;
if ((start[1] & (0xC0)) != 0×80)
{
IsUTF8 = false;
break;
}
start += 2;
}
else if (*start < (0xF0)) // (11110000): 此范围内为3字节UTF-8字符
{
if (start >= end - 2)
break;
if ((start[1] & (0xC0)) != 0×80 || (start[2] & (0xC0)) != 0×80)
{
IsUTF8 = false;
break;
}
start += 3;
}
else
{
IsUTF8 = false;
break;
}
}
return IsUTF8;
}
{
bool IsUTF8 = true;
unsigned char* start = (unsigned char*)pBuffer;
unsigned char* end = (unsigned char*)pBuffer + size;
while (start < end)
{
if (*start < 0×80) // (10000000): 值小于0×80的为ASCII字符
{
start++;
}
else if (*start < (0xC0)) // (11000000): 值介于0×80与0xC0之间的为无效UTF-8字符
{
IsUTF8 = false;
break;
}
else if (*start < (0xE0)) // (11100000): 此范围内为2字节UTF-8字符
{
if (start >= end - 1)
break;
if ((start[1] & (0xC0)) != 0×80)
{
IsUTF8 = false;
break;
}
start += 2;
}
else if (*start < (0xF0)) // (11110000): 此范围内为3字节UTF-8字符
{
if (start >= end - 2)
break;
if ((start[1] & (0xC0)) != 0×80 || (start[2] & (0xC0)) != 0×80)
{
IsUTF8 = false;
break;
}
start += 3;
}
else
{
IsUTF8 = false;
break;
}
}
return IsUTF8;
}
然后在android_media_MediaMetadataRetriever_extractMetadata方法中做出判断,当不为utf-8时返回null,
static jobject android_media_MediaMetadataRetriever_extractMetadata(JNIEnv *env, jobject thiz, jint keyCode)
{
ALOGV("extractMetadata");
MediaMetadataRetriever* retriever = getRetriever(env, thiz);
if (retriever == 0) {
jniThrowException(env, "java/lang/IllegalStateException", "No retriever available");
return NULL;
}
const char* value = retriever->extractMetadata(keyCode);
if (!value) {
ALOGV("extractMetadata: Metadata is not found");
return NULL;
}
ALOGV("extractMetadata: value (%s) for keyCode(%d)", value, keyCode);
if (!IsUTF8(value,strlen(value)))
{
return NULL;
}
return env->NewStringUTF(value);
}
{
ALOGV("extractMetadata");
MediaMetadataRetriever* retriever = getRetriever(env, thiz);
if (retriever == 0) {
jniThrowException(env, "java/lang/IllegalStateException", "No retriever available");
return NULL;
}
const char* value = retriever->extractMetadata(keyCode);
if (!value) {
ALOGV("extractMetadata: Metadata is not found");
return NULL;
}
ALOGV("extractMetadata: value (%s) for keyCode(%d)", value, keyCode);
if (!IsUTF8(value,strlen(value)))
{
return NULL;
}
return env->NewStringUTF(value);
}
编译libmedia_jni,之后push进system/lib,删除/data/data/com.android.providers.media文件夹,重启手机即可修正问题。
Tags: android 重启 音乐
发表评论