summaryrefslogtreecommitdiffstats
path: root/core/jni/android_util_AssetManager.cpp
diff options
context:
space:
mode:
authorJosh Guilfoyle <Josh.Guilfoyle@T-Mobile.com>2010-12-24 22:29:40 -0800
committerJosh Guilfoyle <Josh.Guilfoyle@T-Mobile.com>2010-12-24 22:29:40 -0800
commitbc9dee971d4885af83e506c60730d3dfe5677ad5 (patch)
treed4adada64cd643d40da185ba6c067caebc52d6d4 /core/jni/android_util_AssetManager.cpp
parent2eb3f3d1e48b1504b3cb6f3e9146bf5b9801cca0 (diff)
downloadframeworks_base-bc9dee971d4885af83e506c60730d3dfe5677ad5.zip
frameworks_base-bc9dee971d4885af83e506c60730d3dfe5677ad5.tar.gz
frameworks_base-bc9dee971d4885af83e506c60730d3dfe5677ad5.tar.bz2
Proper error handling doing redirections within bag access.
If resources fail to lookup, print an error rather than pressing forward with invalid values returned from either getResource or resolveReference.
Diffstat (limited to 'core/jni/android_util_AssetManager.cpp')
-rw-r--r--core/jni/android_util_AssetManager.cpp44
1 files changed, 36 insertions, 8 deletions
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index 1c0537d..c9f0ca7 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -1140,10 +1140,24 @@ static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject cla
if (resid != 0) {
uint32_t redirect = res.lookupRedirectionMap(resid);
if (redirect != 0) {
- REDIRECT_NOISY(LOGW("deep REDIRECT FROM resid=0x%08x TO redirect=0x%08x\n", resid, redirect));
- block = res.getResource(redirect, &value, false, &typeSetFlags, &config);
- block = res.resolveReference(&value, block, &redirect);
- resid = redirect;
+ REDIRECT_NOISY(LOGW("deep REDIRECT 0x%08x => 0x%08x\n", resid, redirect));
+ ssize_t newBlock = res.getResource(redirect, &value, true, &typeSetFlags, &config);
+ if (newBlock >= 0) {
+ newBlock = res.resolveReference(&value, newBlock, &redirect, &typeSetFlags, &config);
+#if THROW_ON_BAD_ID
+ if (newBlock == BAD_INDEX) {
+ jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!");
+ return JNI_FALSE;
+ }
+#endif
+ if (newBlock >= 0) {
+ block = newBlock;
+ resid = redirect;
+ }
+ }
+ if (resid != redirect) {
+ LOGW("deep redirect failure from 0x%08x => 0x%08x, defStyleAttr=0x%08x, defStyleRes=0x%08x, style=0x%08x\n", resid, redirect, defStyleAttr, defStyleRes, style);
+ }
}
}
@@ -1410,10 +1424,24 @@ static jint android_content_AssetManager_retrieveArray(JNIEnv* env, jobject claz
if (resid != 0) {
uint32_t redirect = res.lookupRedirectionMap(resid);
if (redirect != 0) {
- REDIRECT_NOISY(LOGW("array REDIRECT FROM resid=0x%08x TO redirect=0x%08x\n", resid, redirect));
- block = res.getResource(redirect, &value, false, &typeSetFlags, &config);
- block = res.resolveReference(&value, block, &redirect);
- resid = redirect;
+ REDIRECT_NOISY(LOGW("array REDIRECT 0x%08x => 0x%08x\n", resid, redirect));
+ ssize_t newBlock = res.getResource(redirect, &value, true, &typeSetFlags, &config);
+ if (newBlock >= 0) {
+ newBlock = res.resolveReference(&value, newBlock, &redirect, &typeSetFlags, &config);
+#if THROW_ON_BAD_ID
+ if (newBlock == BAD_INDEX) {
+ jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!");
+ return JNI_FALSE;
+ }
+#endif
+ if (newBlock >= 0) {
+ block = newBlock;
+ resid = redirect;
+ }
+ }
+ if (resid != redirect) {
+ LOGW("array redirect failure from 0x%08x => 0x%08x, array id=0x%08x", resid, redirect, id);
+ }
}
}