Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 084dd872 authored by Gilles Debunne's avatar Gilles Debunne Committed by Android Git Automerger
Browse files

am b8fd0473: Merge "Fix for 512 limit in assetManager.list" into gingerbread

Merge commit 'b8fd0473' into gingerbread-plus-aosp

* commit 'b8fd0473':
  Fix for 512 limit in assetManager.list
parents 04108437 b8fd0473
Loading
Loading
Loading
Loading
+77 −77
Original line number Diff line number Diff line
@@ -66,16 +66,6 @@ jclass g_stringClass = NULL;

// ----------------------------------------------------------------------------

static void doThrow(JNIEnv* env, const char* exc, const char* msg = NULL)
{
    jclass npeClazz;

    npeClazz = env->FindClass(exc);
    LOG_FATAL_IF(npeClazz == NULL, "Unable to find class %s", exc);

    env->ThrowNew(npeClazz, msg);
}

enum {
    STYLE_NUM_ENTRIES = 6,
    STYLE_TYPE = 0,
@@ -131,14 +121,14 @@ static jint android_content_AssetManager_openAsset(JNIEnv* env, jobject clazz,

    LOGV("openAsset in %p (Java object %p)\n", am, clazz);

    if (fileName == NULL || am == NULL) {
        doThrow(env, "java/lang/NullPointerException");
    if (fileName == NULL) {
        jniThrowException(env, "java/lang/NullPointerException", "fileName");
        return -1;
    }

    if (mode != Asset::ACCESS_UNKNOWN && mode != Asset::ACCESS_RANDOM
        && mode != Asset::ACCESS_STREAMING && mode != Asset::ACCESS_BUFFER) {
        doThrow(env, "java/lang/IllegalArgumentException");
        jniThrowException(env, "java/lang/IllegalArgumentException", "Bad access mode");
        return -1;
    }

@@ -146,7 +136,7 @@ static jint android_content_AssetManager_openAsset(JNIEnv* env, jobject clazz,
    Asset* a = am->open(fileName8, (Asset::AccessMode)mode);

    if (a == NULL) {
        doThrow(env, "java/io/FileNotFoundException", fileName8);
        jniThrowException(env, "java/io/FileNotFoundException", fileName8);
        env->ReleaseStringUTFChars(fileName, fileName8);
        return -1;
    }
@@ -164,7 +154,7 @@ static jobject returnParcelFileDescriptor(JNIEnv* env, Asset* a, jlongArray outO
    delete a;
    
    if (fd < 0) {
        doThrow(env, "java/io/FileNotFoundException",
        jniThrowException(env, "java/io/FileNotFoundException",
                "This file can not be opened as a file descriptor; it is probably compressed");
        return NULL;
    }
@@ -199,8 +189,8 @@ static jobject android_content_AssetManager_openAssetFd(JNIEnv* env, jobject cla

    LOGV("openAssetFd in %p (Java object %p)\n", am, clazz);

    if (fileName == NULL || am == NULL) {
        doThrow(env, "java/lang/NullPointerException");
    if (fileName == NULL) {
        jniThrowException(env, "java/lang/NullPointerException", "fileName");
        return NULL;
    }

@@ -208,7 +198,7 @@ static jobject android_content_AssetManager_openAssetFd(JNIEnv* env, jobject cla
    Asset* a = am->open(fileName8, Asset::ACCESS_RANDOM);

    if (a == NULL) {
        doThrow(env, "java/io/FileNotFoundException", fileName8);
        jniThrowException(env, "java/io/FileNotFoundException", fileName8);
        env->ReleaseStringUTFChars(fileName, fileName8);
        return NULL;
    }
@@ -231,14 +221,14 @@ static jint android_content_AssetManager_openNonAssetNative(JNIEnv* env, jobject

    LOGV("openNonAssetNative in %p (Java object %p)\n", am, clazz);

    if (fileName == NULL || am == NULL) {
        doThrow(env, "java/lang/NullPointerException");
    if (fileName == NULL) {
        jniThrowException(env, "java/lang/NullPointerException", "fileName");
        return -1;
    }

    if (mode != Asset::ACCESS_UNKNOWN && mode != Asset::ACCESS_RANDOM
        && mode != Asset::ACCESS_STREAMING && mode != Asset::ACCESS_BUFFER) {
        doThrow(env, "java/lang/IllegalArgumentException");
        jniThrowException(env, "java/lang/IllegalArgumentException", "Bad access mode");
        return -1;
    }

@@ -248,7 +238,7 @@ static jint android_content_AssetManager_openNonAssetNative(JNIEnv* env, jobject
        : am->openNonAsset(fileName8, (Asset::AccessMode)mode);

    if (a == NULL) {
        doThrow(env, "java/io/FileNotFoundException", fileName8);
        jniThrowException(env, "java/io/FileNotFoundException", fileName8);
        env->ReleaseStringUTFChars(fileName, fileName8);
        return -1;
    }
@@ -271,8 +261,8 @@ static jobject android_content_AssetManager_openNonAssetFdNative(JNIEnv* env, jo

    LOGV("openNonAssetFd in %p (Java object %p)\n", am, clazz);

    if (fileName == NULL || am == NULL) {
        doThrow(env, "java/lang/NullPointerException");
    if (fileName == NULL ) {
        jniThrowException(env, "java/lang/NullPointerException", "fileName");
        return NULL;
    }

@@ -282,7 +272,7 @@ static jobject android_content_AssetManager_openNonAssetFdNative(JNIEnv* env, jo
        : am->openNonAsset(fileName8, Asset::ACCESS_RANDOM);

    if (a == NULL) {
        doThrow(env, "java/io/FileNotFoundException", fileName8);
        jniThrowException(env, "java/io/FileNotFoundException", fileName8);
        env->ReleaseStringUTFChars(fileName, fileName8);
        return NULL;
    }
@@ -301,8 +291,8 @@ static jobjectArray android_content_AssetManager_list(JNIEnv* env, jobject clazz
        return NULL;
    }

    if (fileName == NULL || am == NULL) {
        doThrow(env, "java/lang/NullPointerException");
    if (fileName == NULL) {
        jniThrowException(env, "java/lang/NullPointerException", "fileName");
        return NULL;
    }

@@ -313,7 +303,7 @@ static jobjectArray android_content_AssetManager_list(JNIEnv* env, jobject clazz
    env->ReleaseStringUTFChars(fileName, fileName8);

    if (dir == NULL) {
        doThrow(env, "java/io/FileNotFoundException", fileName8);
        jniThrowException(env, "java/io/FileNotFoundException", fileName8);
        return NULL;
    }

@@ -329,7 +319,6 @@ static jobjectArray android_content_AssetManager_list(JNIEnv* env, jobject clazz
    jobjectArray array = env->NewObjectArray(dir->getFileCount(),
                                                cls, NULL);
    if (array == NULL) {
        doThrow(env, "java/lang/OutOfMemoryError");
        delete dir;
        return NULL;
    }
@@ -338,11 +327,11 @@ static jobjectArray android_content_AssetManager_list(JNIEnv* env, jobject clazz
        const String8& name = dir->getFileName(i);
        jstring str = env->NewStringUTF(name.string());
        if (str == NULL) {
            doThrow(env, "java/lang/OutOfMemoryError");
            delete dir;
            return NULL;
        }
        env->SetObjectArrayElement(array, i, str);
        env->DeleteLocalRef(str);
    }

    delete dir;
@@ -358,7 +347,7 @@ static void android_content_AssetManager_destroyAsset(JNIEnv* env, jobject clazz
    //printf("Destroying Asset Stream: %p\n", a);

    if (a == NULL) {
        doThrow(env, "java/lang/NullPointerException");
        jniThrowException(env, "java/lang/NullPointerException", "asset");
        return;
    }

@@ -371,7 +360,7 @@ static jint android_content_AssetManager_readAssetChar(JNIEnv* env, jobject claz
    Asset* a = (Asset*)asset;

    if (a == NULL) {
        doThrow(env, "java/lang/NullPointerException");
        jniThrowException(env, "java/lang/NullPointerException", "asset");
        return -1;
    }

@@ -387,7 +376,7 @@ static jint android_content_AssetManager_readAsset(JNIEnv* env, jobject clazz,
    Asset* a = (Asset*)asset;

    if (a == NULL || bArray == NULL) {
        doThrow(env, "java/lang/NullPointerException");
        jniThrowException(env, "java/lang/NullPointerException", "asset");
        return -1;
    }

@@ -397,7 +386,7 @@ static jint android_content_AssetManager_readAsset(JNIEnv* env, jobject clazz,
    
    jsize bLen = env->GetArrayLength(bArray);
    if (off < 0 || off >= bLen || len < 0 || len > bLen || (off+len) > bLen) {
        doThrow(env, "java/lang/IndexOutOfBoundsException");
        jniThrowException(env, "java/lang/IndexOutOfBoundsException", "");
        return -1;
    }

@@ -408,7 +397,7 @@ static jint android_content_AssetManager_readAsset(JNIEnv* env, jobject clazz,
    if (res > 0) return res;

    if (res < 0) {
        doThrow(env, "java/io/IOException");
        jniThrowException(env, "java/io/IOException", "");
    }
    return -1;
}
@@ -420,7 +409,7 @@ static jlong android_content_AssetManager_seekAsset(JNIEnv* env, jobject clazz,
    Asset* a = (Asset*)asset;

    if (a == NULL) {
        doThrow(env, "java/lang/NullPointerException");
        jniThrowException(env, "java/lang/NullPointerException", "asset");
        return -1;
    }

@@ -434,7 +423,7 @@ static jlong android_content_AssetManager_getAssetLength(JNIEnv* env, jobject cl
    Asset* a = (Asset*)asset;

    if (a == NULL) {
        doThrow(env, "java/lang/NullPointerException");
        jniThrowException(env, "java/lang/NullPointerException", "asset");
        return -1;
    }

@@ -447,7 +436,7 @@ static jlong android_content_AssetManager_getAssetRemainingLength(JNIEnv* env, j
    Asset* a = (Asset*)asset;

    if (a == NULL) {
        doThrow(env, "java/lang/NullPointerException");
        jniThrowException(env, "java/lang/NullPointerException", "asset");
        return -1;
    }

@@ -458,7 +447,7 @@ static jint android_content_AssetManager_addAssetPath(JNIEnv* env, jobject clazz
                                                       jstring path)
{
    if (path == NULL) {
        doThrow(env, "java/lang/NullPointerException");
        jniThrowException(env, "java/lang/NullPointerException", "path");
        return JNI_FALSE;
    }

@@ -490,7 +479,7 @@ static void android_content_AssetManager_setLocale(JNIEnv* env, jobject clazz,
                                                jstring locale)
{
    if (locale == NULL) {
        doThrow(env, "java/lang/NullPointerException");
        jniThrowException(env, "java/lang/NullPointerException", "locale");
        return;
    }

@@ -525,7 +514,12 @@ static jobjectArray android_content_AssetManager_getLocales(JNIEnv* env, jobject
    }

    for (int i=0; i<N; i++) {
        env->SetObjectArrayElement(result, i, env->NewStringUTF(locales[i].string()));
        jstring str = env->NewStringUTF(locales[i].string())
        if (str == NULL) {
            return NULL;
        }
        env->SetObjectArrayElement(result, i, str);
        env->DeleteLocalRef(str);
    }

    return result;
@@ -576,7 +570,7 @@ static jint android_content_AssetManager_getResourceIdentifier(JNIEnv* env, jobj
                                                            jstring defPackage)
{
    if (name == NULL) {
        doThrow(env, "java/lang/NullPointerException");
        jniThrowException(env, "java/lang/NullPointerException", "name");
        return 0;
    }

@@ -814,14 +808,10 @@ static jstring android_content_AssetManager_getCookieName(JNIEnv* env, jobject c
    }
    String8 name(am->getAssetPath((void*)cookie));
    if (name.length() == 0) {
        doThrow(env, "java/lang/IndexOutOfBoundsException");
        jniThrowException(env, "java/lang/IndexOutOfBoundsException", "Empty cookie name");
        return NULL;
    }
    jstring str = env->NewStringUTF(name.string());
    if (str == NULL) {
        doThrow(env, "java/lang/OutOfMemoryError");
        return NULL;
    }
    return str;
}

@@ -889,7 +879,7 @@ static void android_content_AssetManager_dumpTheme(JNIEnv* env, jobject clazz,
    const ResTable& res(theme->getResTable());
    
    if (tag == NULL) {
        doThrow(env, "java/lang/NullPointerException");
        jniThrowException(env, "java/lang/NullPointerException", "tag");
        return;
    }
    
@@ -917,8 +907,16 @@ static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject cla
                                                        jintArray outValues,
                                                        jintArray outIndices)
{
    if (themeToken == 0 || attrs == NULL || outValues == NULL) {
        doThrow(env, "java/lang/NullPointerException");
    if (themeToken == 0) {
        jniThrowException(env, "java/lang/NullPointerException", "theme token");
        return JNI_FALSE;
    }
    if (attrs == NULL) {
        jniThrowException(env, "java/lang/NullPointerException", "attrs");
        return JNI_FALSE;
    }
    if (outValues == NULL) {
        jniThrowException(env, "java/lang/NullPointerException", "out values");
        return JNI_FALSE;
    }

@@ -934,13 +932,13 @@ static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject cla
    const jsize NI = env->GetArrayLength(attrs);
    const jsize NV = env->GetArrayLength(outValues);
    if (NV < (NI*STYLE_NUM_ENTRIES)) {
        doThrow(env, "java/lang/IndexOutOfBoundsException");
        jniThrowException(env, "java/lang/IndexOutOfBoundsException", "out values too small");
        return JNI_FALSE;
    }

    jint* src = (jint*)env->GetPrimitiveArrayCritical(attrs, 0);
    if (src == NULL) {
        doThrow(env, "java/lang/OutOfMemoryError");
        jniThrowException(env, "java/lang/OutOfMemoryError", "");
        return JNI_FALSE;
    }

@@ -948,7 +946,7 @@ static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject cla
    jint* dest = baseDest;
    if (dest == NULL) {
        env->ReleasePrimitiveArrayCritical(attrs, src, 0);
        doThrow(env, "java/lang/OutOfMemoryError");
        jniThrowException(env, "java/lang/OutOfMemoryError", "");
        return JNI_FALSE;
    }

@@ -1152,8 +1150,16 @@ static jboolean android_content_AssetManager_retrieveAttributes(JNIEnv* env, job
                                                        jintArray outValues,
                                                        jintArray outIndices)
{
    if (xmlParserToken == 0 || attrs == NULL || outValues == NULL) {
        doThrow(env, "java/lang/NullPointerException");
    if (xmlParserToken == 0) {
        jniThrowException(env, "java/lang/NullPointerException", "xmlParserToken");
        return JNI_FALSE;
    }
    if (attrs == NULL) {
        jniThrowException(env, "java/lang/NullPointerException", "attrs");
        return JNI_FALSE;
    }
    if (outValues == NULL) {
        jniThrowException(env, "java/lang/NullPointerException", "out values");
        return JNI_FALSE;
    }
    
@@ -1169,13 +1175,13 @@ static jboolean android_content_AssetManager_retrieveAttributes(JNIEnv* env, job
    const jsize NI = env->GetArrayLength(attrs);
    const jsize NV = env->GetArrayLength(outValues);
    if (NV < (NI*STYLE_NUM_ENTRIES)) {
        doThrow(env, "java/lang/IndexOutOfBoundsException");
        jniThrowException(env, "java/lang/IndexOutOfBoundsException", "out values too small");
        return JNI_FALSE;
    }
    
    jint* src = (jint*)env->GetPrimitiveArrayCritical(attrs, 0);
    if (src == NULL) {
        doThrow(env, "java/lang/OutOfMemoryError");
        jniThrowException(env, "java/lang/OutOfMemoryError", "");
        return JNI_FALSE;
    }
    
@@ -1183,7 +1189,7 @@ static jboolean android_content_AssetManager_retrieveAttributes(JNIEnv* env, job
    jint* dest = baseDest;
    if (dest == NULL) {
        env->ReleasePrimitiveArrayCritical(attrs, src, 0);
        doThrow(env, "java/lang/OutOfMemoryError");
        jniThrowException(env, "java/lang/OutOfMemoryError", "");
        return JNI_FALSE;
    }
    
@@ -1306,7 +1312,7 @@ static jint android_content_AssetManager_retrieveArray(JNIEnv* env, jobject claz
                                                        jintArray outValues)
{
    if (outValues == NULL) {
        doThrow(env, "java/lang/NullPointerException");
        jniThrowException(env, "java/lang/NullPointerException", "out values");
        return JNI_FALSE;
    }
    
@@ -1324,7 +1330,7 @@ static jint android_content_AssetManager_retrieveArray(JNIEnv* env, jobject claz
    jint* baseDest = (jint*)env->GetPrimitiveArrayCritical(outValues, 0);
    jint* dest = baseDest;
    if (dest == NULL) {
        doThrow(env, "java/lang/OutOfMemoryError");
        jniThrowException(env, "java/lang/OutOfMemoryError", "");
        return JNI_FALSE;
    }
    
@@ -1399,8 +1405,8 @@ static jint android_content_AssetManager_openXmlAssetNative(JNIEnv* env, jobject

    LOGV("openXmlAsset in %p (Java object %p)\n", am, clazz);

    if (fileName == NULL || am == NULL) {
        doThrow(env, "java/lang/NullPointerException");
    if (fileName == NULL) {
        jniThrowException(env, "java/lang/NullPointerException", "fileName");
        return 0;
    }

@@ -1410,7 +1416,7 @@ static jint android_content_AssetManager_openXmlAssetNative(JNIEnv* env, jobject
        : am->openNonAsset(fileName8, Asset::ACCESS_BUFFER);

    if (a == NULL) {
        doThrow(env, "java/io/FileNotFoundException", fileName8);
        jniThrowException(env, "java/io/FileNotFoundException", fileName8);
        env->ReleaseStringUTFChars(fileName, fileName8);
        return 0;
    }
@@ -1422,7 +1428,7 @@ static jint android_content_AssetManager_openXmlAssetNative(JNIEnv* env, jobject
    delete a;

    if (err != NO_ERROR) {
        doThrow(env, "java/io/FileNotFoundException", "Corrupt XML binary file");
        jniThrowException(env, "java/io/FileNotFoundException", "Corrupt XML binary file");
        return 0;
    }

@@ -1446,7 +1452,7 @@ static jintArray android_content_AssetManager_getArrayStringInfo(JNIEnv* env, jo

    jintArray array = env->NewIntArray(N * 2);
    if (array == NULL) {
        doThrow(env, "java/lang/OutOfMemoryError");
        jniThrowException(env, "java/lang/OutOfMemoryError", "");
        res.unlockBag(startOfBag);
        return NULL;
    }
@@ -1540,13 +1546,12 @@ static jobjectArray android_content_AssetManager_getArrayStringResource(JNIEnv*
                res.unlockBag(startOfBag);
                return NULL;
            }
        }

            env->SetObjectArrayElement(array, i, str);

            // str is not NULL at that point, otherwise ExceptionCheck would have been true.
            // If we have a large amount of strings in our array, we might
            // overflow the local reference table of the VM.
        if (str != NULL) {
            env->DeleteLocalRef(str);
        }
    }
@@ -1571,7 +1576,7 @@ static jintArray android_content_AssetManager_getArrayIntResource(JNIEnv* env, j

    jintArray array = env->NewIntArray(N);
    if (array == NULL) {
        doThrow(env, "java/lang/OutOfMemoryError");
        jniThrowException(env, "java/lang/OutOfMemoryError", "");
        res.unlockBag(startOfBag);
        return NULL;
    }
@@ -1603,7 +1608,7 @@ static void android_content_AssetManager_init(JNIEnv* env, jobject clazz)
{
    AssetManager* am = new AssetManager();
    if (am == NULL) {
        doThrow(env, "java/lang/OutOfMemoryError");
        jniThrowException(env, "java/lang/OutOfMemoryError", "");
        return;
    }

@@ -1637,11 +1642,6 @@ static jobject android_content_AssetManager_getAssetAllocations(JNIEnv* env, job
    }
    
    jstring str = env->NewStringUTF(alloc.string());
    if (str == NULL) {
        doThrow(env, "java/lang/OutOfMemoryError");
        return NULL;
    }
    
    return str;
}