From 60d7db4c3e3d60060e7ac021445ea1f510b7a1fb Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Mon, 16 Nov 2009 17:16:26 -0800 Subject: [PATCH] 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 --- .../android/content/res/AssetManager.java | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java index 0d43b2a83c72f..5894c4f166b6b 100644 --- a/core/java/android/content/res/AssetManager.java +++ b/core/java/android/content/res/AssetManager.java @@ -59,11 +59,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; @@ -71,9 +72,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 @@ -82,7 +81,7 @@ public final class AssetManager { * {@hide} */ public AssetManager() { - synchronized (mSync) { + synchronized (this) { init(); if (localLOGV) Log.v(TAG, "New asset manager: " + this); ensureSystemAssets(); @@ -90,11 +89,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; } } } @@ -111,14 +110,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) { @@ -133,7 +132,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) { @@ -151,7 +150,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) { @@ -229,7 +228,7 @@ public final class AssetManager { /*package*/ final void ensureStringBlocks() { if (mStringBlocks == null) { - synchronized (mSync) { + synchronized (this) { if (mStringBlocks == null) { makeStringBlocks(true); } @@ -238,14 +237,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 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;