diff options
author | Ashok Bhat <ashok.bhat@arm.com> | 2014-01-17 16:02:38 +0000 |
---|---|---|
committer | Narayan Kamath <narayan@google.com> | 2014-01-31 14:14:29 +0000 |
commit | 896043d67d3ac75760bd99db8a1561e31ebee1e1 (patch) | |
tree | 8f2ca459558ed89495990bf51d967b4f05363b3e /core/jni/android_util_AssetManager.cpp | |
parent | 1cadc07dd1e3711fb1e57548038e3026682c5ef8 (diff) | |
download | frameworks_base-896043d67d3ac75760bd99db8a1561e31ebee1e1.zip frameworks_base-896043d67d3ac75760bd99db8a1561e31ebee1e1.tar.gz frameworks_base-896043d67d3ac75760bd99db8a1561e31ebee1e1.tar.bz2 |
AArch64: Make AssetManager and related classes 64-bit compatible
Following changes have been done:
[x] Long is used to store native pointers as pointers can be
64-bit.
[x] AssetManager openAsset native function returned -1 if
file name was empty and java function considered any
non-zero value as success. This has been fixed by native
function throwing Illegal Argument Exception as well.
[x] AssetManager incRefsLocked and decRefsLocked now accept
long as input to support 64-bit native references.
[x] AssetManager incRefsLocked method incorrecly used
'this.hashCode()' instead of the passed parameter id.
This has been fixed.
[x] Some minor changes have been done to conform with
standard JNI practice (e.g. use of jint instead of int
in JNI function prototypes)
Change-Id: I095b9f900d49e51f43ad6afc47cbc23116a6a64a
Signed-off-by: Ashok Bhat <ashok.bhat@arm.com>
Signed-off-by: Craig Barber <craig.barber@arm.com>
Signed-off-by: Kévin PETIT <kevin.petit@arm.com>
Diffstat (limited to 'core/jni/android_util_AssetManager.cpp')
-rw-r--r-- | core/jni/android_util_AssetManager.cpp | 150 |
1 files changed, 80 insertions, 70 deletions
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp index 8836918..f96aef8 100644 --- a/core/jni/android_util_AssetManager.cpp +++ b/core/jni/android_util_AssetManager.cpp @@ -88,7 +88,7 @@ jint copyValue(JNIEnv* env, jobject outValue, const ResTable* table, { env->SetIntField(outValue, gTypedValueOffsets.mType, value.dataType); env->SetIntField(outValue, gTypedValueOffsets.mAssetCookie, - (jint)table->getTableCookie(block)); + static_cast<jint>(table->getTableCookie(block))); env->SetIntField(outValue, gTypedValueOffsets.mData, value.data); env->SetObjectField(outValue, gTypedValueOffsets.mString, NULL); env->SetIntField(outValue, gTypedValueOffsets.mResourceId, ref); @@ -105,7 +105,8 @@ jint copyValue(JNIEnv* env, jobject outValue, const ResTable* table, // this guy is exported to other jni routines AssetManager* assetManagerForJavaObject(JNIEnv* env, jobject obj) { - AssetManager* am = (AssetManager*)env->GetIntField(obj, gAssetManagerOffsets.mObject); + jlong amHandle = env->GetLongField(obj, gAssetManagerOffsets.mObject); + AssetManager* am = reinterpret_cast<AssetManager*>(amHandle); if (am != NULL) { return am; } @@ -113,7 +114,7 @@ AssetManager* assetManagerForJavaObject(JNIEnv* env, jobject obj) return NULL; } -static jint android_content_AssetManager_openAsset(JNIEnv* env, jobject clazz, +static jlong android_content_AssetManager_openAsset(JNIEnv* env, jobject clazz, jstring fileName, jint mode) { AssetManager* am = assetManagerForJavaObject(env, clazz); @@ -125,6 +126,7 @@ static jint android_content_AssetManager_openAsset(JNIEnv* env, jobject clazz, ScopedUtfChars fileName8(env, fileName); if (fileName8.c_str() == NULL) { + jniThrowException(env, "java/lang/IllegalArgumentException", "Empty file name"); return -1; } @@ -143,7 +145,7 @@ static jint android_content_AssetManager_openAsset(JNIEnv* env, jobject clazz, //printf("Created Asset Stream: %p\n", a); - return (jint)a; + return reinterpret_cast<jlong>(a); } static jobject returnParcelFileDescriptor(JNIEnv* env, Asset* a, jlongArray outOffsets) @@ -205,7 +207,7 @@ static jobject android_content_AssetManager_openAssetFd(JNIEnv* env, jobject cla return returnParcelFileDescriptor(env, a, outOffsets); } -static jint android_content_AssetManager_openNonAssetNative(JNIEnv* env, jobject clazz, +static jlong android_content_AssetManager_openNonAssetNative(JNIEnv* env, jobject clazz, jint cookie, jstring fileName, jint mode) @@ -240,7 +242,7 @@ static jint android_content_AssetManager_openNonAssetNative(JNIEnv* env, jobject //printf("Created Asset Stream: %p\n", a); - return (jint)a; + return reinterpret_cast<jlong>(a); } static jobject android_content_AssetManager_openNonAssetFdNative(JNIEnv* env, jobject clazz, @@ -320,9 +322,9 @@ static jobjectArray android_content_AssetManager_list(JNIEnv* env, jobject clazz } static void android_content_AssetManager_destroyAsset(JNIEnv* env, jobject clazz, - jint asset) + jlong assetHandle) { - Asset* a = (Asset*)asset; + Asset* a = reinterpret_cast<Asset*>(assetHandle); //printf("Destroying Asset Stream: %p\n", a); @@ -335,9 +337,9 @@ static void android_content_AssetManager_destroyAsset(JNIEnv* env, jobject clazz } static jint android_content_AssetManager_readAssetChar(JNIEnv* env, jobject clazz, - jint asset) + jlong assetHandle) { - Asset* a = (Asset*)asset; + Asset* a = reinterpret_cast<Asset*>(assetHandle); if (a == NULL) { jniThrowNullPointerException(env, "asset"); @@ -350,10 +352,10 @@ static jint android_content_AssetManager_readAssetChar(JNIEnv* env, jobject claz } static jint android_content_AssetManager_readAsset(JNIEnv* env, jobject clazz, - jint asset, jbyteArray bArray, + jlong assetHandle, jbyteArray bArray, jint off, jint len) { - Asset* a = (Asset*)asset; + Asset* a = reinterpret_cast<Asset*>(assetHandle); if (a == NULL || bArray == NULL) { jniThrowNullPointerException(env, "asset"); @@ -374,7 +376,7 @@ static jint android_content_AssetManager_readAsset(JNIEnv* env, jobject clazz, ssize_t res = a->read(b+off, len); env->ReleaseByteArrayElements(bArray, b, 0); - if (res > 0) return res; + if (res > 0) return static_cast<jint>(res); if (res < 0) { jniThrowException(env, "java/io/IOException", ""); @@ -383,10 +385,10 @@ static jint android_content_AssetManager_readAsset(JNIEnv* env, jobject clazz, } static jlong android_content_AssetManager_seekAsset(JNIEnv* env, jobject clazz, - jint asset, + jlong assetHandle, jlong offset, jint whence) { - Asset* a = (Asset*)asset; + Asset* a = reinterpret_cast<Asset*>(assetHandle); if (a == NULL) { jniThrowNullPointerException(env, "asset"); @@ -398,9 +400,9 @@ static jlong android_content_AssetManager_seekAsset(JNIEnv* env, jobject clazz, } static jlong android_content_AssetManager_getAssetLength(JNIEnv* env, jobject clazz, - jint asset) + jlong assetHandle) { - Asset* a = (Asset*)asset; + Asset* a = reinterpret_cast<Asset*>(assetHandle); if (a == NULL) { jniThrowNullPointerException(env, "asset"); @@ -411,9 +413,9 @@ static jlong android_content_AssetManager_getAssetLength(JNIEnv* env, jobject cl } static jlong android_content_AssetManager_getAssetRemainingLength(JNIEnv* env, jobject clazz, - jint asset) + jlong assetHandle) { - Asset* a = (Asset*)asset; + Asset* a = reinterpret_cast<Asset*>(assetHandle); if (a == NULL) { jniThrowNullPointerException(env, "asset"); @@ -725,7 +727,11 @@ static jint android_content_AssetManager_loadResourceValue(JNIEnv* env, jobject } #endif } - return block >= 0 ? copyValue(env, outValue, &res, value, ref, block, typeSpecFlags, &config) : block; + if (block >= 0) { + return copyValue(env, outValue, &res, value, ref, block, typeSpecFlags, &config); + } + + return static_cast<jint>(block); } static jint android_content_AssetManager_loadResourceBagValue(JNIEnv* env, jobject clazz, @@ -759,7 +765,7 @@ static jint android_content_AssetManager_loadResourceBagValue(JNIEnv* env, jobje res.unlock(); if (block < 0) { - return block; + return static_cast<jint>(block); } uint32_t ref = ident; @@ -772,7 +778,11 @@ static jint android_content_AssetManager_loadResourceBagValue(JNIEnv* env, jobje } #endif } - return block >= 0 ? copyValue(env, outValue, &res, value, ref, block, typeSpecFlags) : block; + if (block >= 0) { + return copyValue(env, outValue, &res, value, ref, block, typeSpecFlags); + } + + return static_cast<jint>(block); } static jint android_content_AssetManager_getStringBlockCount(JNIEnv* env, jobject clazz) @@ -784,14 +794,14 @@ static jint android_content_AssetManager_getStringBlockCount(JNIEnv* env, jobjec return am->getResources().getTableCount(); } -static jint android_content_AssetManager_getNativeStringBlock(JNIEnv* env, jobject clazz, +static jlong android_content_AssetManager_getNativeStringBlock(JNIEnv* env, jobject clazz, jint block) { AssetManager* am = assetManagerForJavaObject(env, clazz); if (am == NULL) { return 0; } - return (jint)am->getResources().getTableStringBlock(block); + return reinterpret_cast<jlong>(am->getResources().getTableStringBlock(block)); } static jstring android_content_AssetManager_getCookieName(JNIEnv* env, jobject clazz, @@ -810,43 +820,43 @@ static jstring android_content_AssetManager_getCookieName(JNIEnv* env, jobject c return str; } -static jint android_content_AssetManager_newTheme(JNIEnv* env, jobject clazz) +static jlong android_content_AssetManager_newTheme(JNIEnv* env, jobject clazz) { AssetManager* am = assetManagerForJavaObject(env, clazz); if (am == NULL) { return 0; } - return (jint)(new ResTable::Theme(am->getResources())); + return reinterpret_cast<jlong>(new ResTable::Theme(am->getResources())); } static void android_content_AssetManager_deleteTheme(JNIEnv* env, jobject clazz, - jint themeInt) + jlong themeHandle) { - ResTable::Theme* theme = (ResTable::Theme*)themeInt; + ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); delete theme; } static void android_content_AssetManager_applyThemeStyle(JNIEnv* env, jobject clazz, - jint themeInt, + jlong themeHandle, jint styleRes, jboolean force) { - ResTable::Theme* theme = (ResTable::Theme*)themeInt; + ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); theme->applyStyle(styleRes, force ? true : false); } static void android_content_AssetManager_copyTheme(JNIEnv* env, jobject clazz, - jint destInt, jint srcInt) + jlong destHandle, jlong srcHandle) { - ResTable::Theme* dest = (ResTable::Theme*)destInt; - ResTable::Theme* src = (ResTable::Theme*)srcInt; + ResTable::Theme* dest = reinterpret_cast<ResTable::Theme*>(destHandle); + ResTable::Theme* src = reinterpret_cast<ResTable::Theme*>(srcHandle); dest->setTo(*src); } static jint android_content_AssetManager_loadThemeAttributeValue( - JNIEnv* env, jobject clazz, jint themeInt, jint ident, jobject outValue, jboolean resolve) + JNIEnv* env, jobject clazz, jlong themeHandle, jint ident, jobject outValue, jboolean resolve) { - ResTable::Theme* theme = (ResTable::Theme*)themeInt; + ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); const ResTable& res(theme->getResTable()); Res_value value; @@ -867,10 +877,10 @@ static jint android_content_AssetManager_loadThemeAttributeValue( } static void android_content_AssetManager_dumpTheme(JNIEnv* env, jobject clazz, - jint themeInt, jint pri, + jlong themeHandle, jint pri, jstring tag, jstring prefix) { - ResTable::Theme* theme = (ResTable::Theme*)themeInt; + ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); const ResTable& res(theme->getResTable()); // XXX Need to use params. @@ -878,10 +888,10 @@ static void android_content_AssetManager_dumpTheme(JNIEnv* env, jobject clazz, } static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject clazz, - jint themeToken, + jlong themeToken, jint defStyleAttr, jint defStyleRes, - jint xmlParserToken, + jlong xmlParserToken, jintArray attrs, jintArray outValues, jintArray outIndices) @@ -902,9 +912,9 @@ static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject cla DEBUG_STYLES(LOGI("APPLY STYLE: theme=0x%x defStyleAttr=0x%x defStyleRes=0x%x xml=0x%x", themeToken, defStyleAttr, defStyleRes, xmlParserToken)); - ResTable::Theme* theme = (ResTable::Theme*)themeToken; + ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeToken); const ResTable& res = theme->getResTable(); - ResXMLParser* xmlParser = (ResXMLParser*)xmlParserToken; + ResXMLParser* xmlParser = reinterpret_cast<ResXMLParser*>(xmlParserToken); ResTable_config config; Res_value value; @@ -1097,7 +1107,7 @@ static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject cla dest[STYLE_TYPE] = value.dataType; dest[STYLE_DATA] = value.data; dest[STYLE_ASSET_COOKIE] = - block != kXmlBlock ? (jint)res.getTableCookie(block) : (jint)-1; + block != kXmlBlock ? reinterpret_cast<jint>(res.getTableCookie(block)) : (jint)-1; dest[STYLE_RESOURCE_ID] = resid; dest[STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags; dest[STYLE_DENSITY] = config.density; @@ -1123,7 +1133,7 @@ static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject cla } static jboolean android_content_AssetManager_retrieveAttributes(JNIEnv* env, jobject clazz, - jint xmlParserToken, + jlong xmlParserToken, jintArray attrs, jintArray outValues, jintArray outIndices) @@ -1240,7 +1250,7 @@ static jboolean android_content_AssetManager_retrieveAttributes(JNIEnv* env, job dest[STYLE_TYPE] = value.dataType; dest[STYLE_DATA] = value.data; dest[STYLE_ASSET_COOKIE] = - block != kXmlBlock ? (jint)res.getTableCookie(block) : (jint)-1; + block != kXmlBlock ? reinterpret_cast<jint>(res.getTableCookie(block)) : (jint)-1; dest[STYLE_RESOURCE_ID] = resid; dest[STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags; dest[STYLE_DENSITY] = config.density; @@ -1280,7 +1290,7 @@ static jint android_content_AssetManager_getArraySize(JNIEnv* env, jobject clazz ssize_t bagOff = res.getBagLocked(id, &defStyleEnt); res.unlock(); - return bagOff; + return static_cast<jint>(bagOff); } static jint android_content_AssetManager_retrieveArray(JNIEnv* env, jobject clazz, @@ -1352,7 +1362,7 @@ static jint android_content_AssetManager_retrieveArray(JNIEnv* env, jobject claz // Write the final value back to Java. dest[STYLE_TYPE] = value.dataType; dest[STYLE_DATA] = value.data; - dest[STYLE_ASSET_COOKIE] = (jint)res.getTableCookie(block); + dest[STYLE_ASSET_COOKIE] = reinterpret_cast<jint>(res.getTableCookie(block)); dest[STYLE_RESOURCE_ID] = resid; dest[STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags; dest[STYLE_DENSITY] = config.density; @@ -1370,7 +1380,7 @@ static jint android_content_AssetManager_retrieveArray(JNIEnv* env, jobject claz return i; } -static jint android_content_AssetManager_openXmlAssetNative(JNIEnv* env, jobject clazz, +static jlong android_content_AssetManager_openXmlAssetNative(JNIEnv* env, jobject clazz, jint cookie, jstring fileName) { @@ -1405,7 +1415,7 @@ static jint android_content_AssetManager_openXmlAssetNative(JNIEnv* env, jobject return 0; } - return (jint)block; + return reinterpret_cast<jlong>(block); } static jintArray android_content_AssetManager_getArrayStringInfo(JNIEnv* env, jobject clazz, @@ -1580,17 +1590,17 @@ static void android_content_AssetManager_init(JNIEnv* env, jobject clazz) am->addDefaultAssets(); ALOGV("Created AssetManager %p for Java object %p\n", am, clazz); - env->SetIntField(clazz, gAssetManagerOffsets.mObject, (jint)am); + env->SetLongField(clazz, gAssetManagerOffsets.mObject, reinterpret_cast<jlong>(am)); } static void android_content_AssetManager_destroy(JNIEnv* env, jobject clazz) { AssetManager* am = (AssetManager*) - (env->GetIntField(clazz, gAssetManagerOffsets.mObject)); + (env->GetLongField(clazz, gAssetManagerOffsets.mObject)); ALOGV("Destroying AssetManager %p for Java object %p\n", am, clazz); if (am != NULL) { delete am; - env->SetIntField(clazz, gAssetManagerOffsets.mObject, 0); + env->SetLongField(clazz, gAssetManagerOffsets.mObject, 0); } } @@ -1624,27 +1634,27 @@ static JNINativeMethod gAssetManagerMethods[] = { /* name, signature, funcPtr */ // Basic asset stuff. - { "openAsset", "(Ljava/lang/String;I)I", + { "openAsset", "(Ljava/lang/String;I)J", (void*) android_content_AssetManager_openAsset }, { "openAssetFd", "(Ljava/lang/String;[J)Landroid/os/ParcelFileDescriptor;", (void*) android_content_AssetManager_openAssetFd }, - { "openNonAssetNative", "(ILjava/lang/String;I)I", + { "openNonAssetNative", "(ILjava/lang/String;I)J", (void*) android_content_AssetManager_openNonAssetNative }, { "openNonAssetFdNative", "(ILjava/lang/String;[J)Landroid/os/ParcelFileDescriptor;", (void*) android_content_AssetManager_openNonAssetFdNative }, { "list", "(Ljava/lang/String;)[Ljava/lang/String;", (void*) android_content_AssetManager_list }, - { "destroyAsset", "(I)V", + { "destroyAsset", "(J)V", (void*) android_content_AssetManager_destroyAsset }, - { "readAssetChar", "(I)I", + { "readAssetChar", "(J)I", (void*) android_content_AssetManager_readAssetChar }, - { "readAsset", "(I[BII)I", + { "readAsset", "(J[BII)I", (void*) android_content_AssetManager_readAsset }, - { "seekAsset", "(IJI)J", + { "seekAsset", "(JJI)J", (void*) android_content_AssetManager_seekAsset }, - { "getAssetLength", "(I)J", + { "getAssetLength", "(J)J", (void*) android_content_AssetManager_getAssetLength }, - { "getAssetRemainingLength", "(I)J", + { "getAssetRemainingLength", "(J)J", (void*) android_content_AssetManager_getAssetRemainingLength }, { "addAssetPathNative", "(Ljava/lang/String;)I", (void*) android_content_AssetManager_addAssetPath }, @@ -1674,27 +1684,27 @@ static JNINativeMethod gAssetManagerMethods[] = { (void*) android_content_AssetManager_loadResourceBagValue }, { "getStringBlockCount","()I", (void*) android_content_AssetManager_getStringBlockCount }, - { "getNativeStringBlock","(I)I", + { "getNativeStringBlock","(I)J", (void*) android_content_AssetManager_getNativeStringBlock }, { "getCookieName","(I)Ljava/lang/String;", (void*) android_content_AssetManager_getCookieName }, // Themes. - { "newTheme", "()I", + { "newTheme", "()J", (void*) android_content_AssetManager_newTheme }, - { "deleteTheme", "(I)V", + { "deleteTheme", "(J)V", (void*) android_content_AssetManager_deleteTheme }, - { "applyThemeStyle", "(IIZ)V", + { "applyThemeStyle", "(JIZ)V", (void*) android_content_AssetManager_applyThemeStyle }, - { "copyTheme", "(II)V", + { "copyTheme", "(JJ)V", (void*) android_content_AssetManager_copyTheme }, - { "loadThemeAttributeValue", "(IILandroid/util/TypedValue;Z)I", + { "loadThemeAttributeValue", "(JILandroid/util/TypedValue;Z)I", (void*) android_content_AssetManager_loadThemeAttributeValue }, - { "dumpTheme", "(IILjava/lang/String;Ljava/lang/String;)V", + { "dumpTheme", "(JILjava/lang/String;Ljava/lang/String;)V", (void*) android_content_AssetManager_dumpTheme }, - { "applyStyle","(IIII[I[I[I)Z", + { "applyStyle","(JIIJ[I[I[I)Z", (void*) android_content_AssetManager_applyStyle }, - { "retrieveAttributes","(I[I[I[I)Z", + { "retrieveAttributes","(J[I[I[I)Z", (void*) android_content_AssetManager_retrieveAttributes }, { "getArraySize","(I)I", (void*) android_content_AssetManager_getArraySize }, @@ -1702,7 +1712,7 @@ static JNINativeMethod gAssetManagerMethods[] = { (void*) android_content_AssetManager_retrieveArray }, // XML files. - { "openXmlAssetNative", "(ILjava/lang/String;)I", + { "openXmlAssetNative", "(ILjava/lang/String;)J", (void*) android_content_AssetManager_openXmlAssetNative }, // Arrays. @@ -1766,7 +1776,7 @@ int register_android_content_AssetManager(JNIEnv* env) jclass assetManager = env->FindClass("android/content/res/AssetManager"); LOG_FATAL_IF(assetManager == NULL, "Unable to find class android/content/res/AssetManager"); gAssetManagerOffsets.mObject - = env->GetFieldID(assetManager, "mObject", "I"); + = env->GetFieldID(assetManager, "mObject", "J"); LOG_FATAL_IF(gAssetManagerOffsets.mObject == NULL, "Unable to find AssetManager.mObject"); jclass stringClass = env->FindClass("java/lang/String"); |