summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2009-11-16 17:16:26 -0800
committerEd Heyl <edheyl@google.com>2009-12-02 17:25:45 -0800
commit9fdeac11705093fed5b9c36b3b0bf8b6c80f685c (patch)
treea059be939317676b37d0af573fab45c53768659f
parentbae4c6b619a027c97b6e6a50807211f74c6c1376 (diff)
downloadbase-9fdeac11705093fed5b9c36b3b0bf8b6c80f685c.tar.gz
Fix #2262593: 42 ANR reports from android.process.acore
There was a lock in AssetManager that purported to be per-instance (mSync) but was actually static. A lot of code used it like it was per-instance, but this would actually block all instances. This is now changed to fix the name and make everything except the actual static data lock on the specific AssetManager instance. Change-Id: Ie8e9ad60f962184e76b2301f7a2790d0c2487063
-rw-r--r--core/java/android/content/res/AssetManager.java53
1 files changed, 26 insertions, 27 deletions
diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java
index 0bc8a9d2e482..9b0c2c238b36 100644
--- a/core/java/android/content/res/AssetManager.java
+++ b/core/java/android/content/res/AssetManager.java
@@ -60,11 +60,12 @@ public final class AssetManager {
private static final String TAG = "AssetManager";
private static final boolean localLOGV = Config.LOGV || false;
- private static final Object mSync = new Object();
- private static final TypedValue mValue = new TypedValue();
- private static final long[] mOffsets = new long[2];
- private static AssetManager mSystem = null;
+ private static final Object sSync = new Object();
+ private static AssetManager sSystem = null;
+ private final TypedValue mValue = new TypedValue();
+ private final long[] mOffsets = new long[2];
+
// For communication with native code.
private int mObject;
@@ -72,9 +73,7 @@ public final class AssetManager {
private int mNumRefs = 1;
private boolean mOpen = true;
- private String mAssetDir;
- private String mAppName;
-
+
/**
* Create a new AssetManager containing only the basic system assets.
* Applications will not generally use this method, instead retrieving the
@@ -83,7 +82,7 @@ public final class AssetManager {
* {@hide}
*/
public AssetManager() {
- synchronized (mSync) {
+ synchronized (this) {
init();
if (localLOGV) Log.v(TAG, "New asset manager: " + this);
ensureSystemAssets();
@@ -91,11 +90,11 @@ public final class AssetManager {
}
private static void ensureSystemAssets() {
- synchronized (mSync) {
- if (mSystem == null) {
+ synchronized (sSync) {
+ if (sSystem == null) {
AssetManager system = new AssetManager(true);
system.makeStringBlocks(false);
- mSystem = system;
+ sSystem = system;
}
}
}
@@ -112,14 +111,14 @@ public final class AssetManager {
*/
public static AssetManager getSystem() {
ensureSystemAssets();
- return mSystem;
+ return sSystem;
}
/**
* Close this asset manager.
*/
public void close() {
- synchronized(mSync) {
+ synchronized(this) {
//System.out.println("Release: num=" + mNumRefs
// + ", released=" + mReleased);
if (mOpen) {
@@ -134,7 +133,7 @@ public final class AssetManager {
* identifier for the current configuration / skin.
*/
/*package*/ final CharSequence getResourceText(int ident) {
- synchronized (mSync) {
+ synchronized (this) {
TypedValue tmpValue = mValue;
int block = loadResourceValue(ident, tmpValue, true);
if (block >= 0) {
@@ -152,7 +151,7 @@ public final class AssetManager {
* identifier for the current configuration / skin.
*/
/*package*/ final CharSequence getResourceBagText(int ident, int bagEntryId) {
- synchronized (mSync) {
+ synchronized (this) {
TypedValue tmpValue = mValue;
int block = loadResourceBagValue(ident, bagEntryId, tmpValue, true);
if (block >= 0) {
@@ -230,7 +229,7 @@ public final class AssetManager {
/*package*/ final void ensureStringBlocks() {
if (mStringBlocks == null) {
- synchronized (mSync) {
+ synchronized (this) {
if (mStringBlocks == null) {
makeStringBlocks(true);
}
@@ -239,14 +238,14 @@ public final class AssetManager {
}
private final void makeStringBlocks(boolean copyFromSystem) {
- final int sysNum = copyFromSystem ? mSystem.mStringBlocks.length : 0;
+ final int sysNum = copyFromSystem ? sSystem.mStringBlocks.length : 0;
final int num = getStringBlockCount();
mStringBlocks = new StringBlock[num];
if (localLOGV) Log.v(TAG, "Making string blocks for " + this
+ ": " + num);
for (int i=0; i<num; i++) {
if (i < sysNum) {
- mStringBlocks[i] = mSystem.mStringBlocks[i];
+ mStringBlocks[i] = sSystem.mStringBlocks[i];
} else {
mStringBlocks[i] = new StringBlock(getNativeStringBlock(i), true);
}
@@ -294,7 +293,7 @@ public final class AssetManager {
*/
public final InputStream open(String fileName, int accessMode)
throws IOException {
- synchronized (mSync) {
+ synchronized (this) {
if (!mOpen) {
throw new RuntimeException("Assetmanager has been closed");
}
@@ -309,7 +308,7 @@ public final class AssetManager {
public final AssetFileDescriptor openFd(String fileName)
throws IOException {
- synchronized (mSync) {
+ synchronized (this) {
if (!mOpen) {
throw new RuntimeException("Assetmanager has been closed");
}
@@ -385,7 +384,7 @@ public final class AssetManager {
*/
public final InputStream openNonAsset(int cookie, String fileName, int accessMode)
throws IOException {
- synchronized (mSync) {
+ synchronized (this) {
if (!mOpen) {
throw new RuntimeException("Assetmanager has been closed");
}
@@ -405,7 +404,7 @@ public final class AssetManager {
public final AssetFileDescriptor openNonAssetFd(int cookie,
String fileName) throws IOException {
- synchronized (mSync) {
+ synchronized (this) {
if (!mOpen) {
throw new RuntimeException("Assetmanager has been closed");
}
@@ -464,7 +463,7 @@ public final class AssetManager {
*/
/*package*/ final XmlBlock openXmlBlockAsset(int cookie, String fileName)
throws IOException {
- synchronized (mSync) {
+ synchronized (this) {
if (!mOpen) {
throw new RuntimeException("Assetmanager has been closed");
}
@@ -478,13 +477,13 @@ public final class AssetManager {
}
/*package*/ void xmlBlockGone() {
- synchronized (mSync) {
+ synchronized (this) {
decRefsLocked();
}
}
/*package*/ final int createTheme() {
- synchronized (mSync) {
+ synchronized (this) {
if (!mOpen) {
throw new RuntimeException("Assetmanager has been closed");
}
@@ -494,7 +493,7 @@ public final class AssetManager {
}
/*package*/ final void releaseTheme(int theme) {
- synchronized (mSync) {
+ synchronized (this) {
deleteTheme(theme);
decRefsLocked();
}
@@ -524,7 +523,7 @@ public final class AssetManager {
return len > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)len;
}
public final void close() throws IOException {
- synchronized (AssetManager.mSync) {
+ synchronized (AssetManager.this) {
if (mAsset != 0) {
destroyAsset(mAsset);
mAsset = 0;