summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2009-11-17 18:28:55 -0800
committerDianne Hackborn <hackbod@google.com>2009-11-18 11:47:15 -0800
commitf93152028726f75c26fa960ef6a5bc87ce867eea (patch)
tree8d7eb86ce00b0b2a1d0e352caae1ca953ff8bcc7 /core
parent1d62ea9d8c2646d198b6967e2c6ae3dad5c18f9e (diff)
downloadframeworks_base-f93152028726f75c26fa960ef6a5bc87ce867eea.zip
frameworks_base-f93152028726f75c26fa960ef6a5bc87ce867eea.tar.gz
frameworks_base-f93152028726f75c26fa960ef6a5bc87ce867eea.tar.bz2
Fix issue #2262563: 40 ANR reports from com.android.settings in dogfooding sholes running ERD43
Don't hold the global package log while instantiated an AssetManager+Resources, since this is a fairly heavy-weight operation, and if done in the background can starve the foreground. Change-Id: I5ad37324fb7c27ffdbf28e1498ca0ad667479580
Diffstat (limited to 'core')
-rw-r--r--core/java/android/app/ActivityThread.java47
1 files changed, 30 insertions, 17 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index b116bf8..467812e 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -178,15 +178,16 @@ public final class ActivityThread {
* null.
*/
Resources getTopLevelResources(String resDir, CompatibilityInfo compInfo) {
+ ResourcesKey key = new ResourcesKey(resDir, compInfo.applicationScale);
+ Resources r;
synchronized (mPackages) {
// Resources is app scale dependent.
- ResourcesKey key = new ResourcesKey(resDir, compInfo.applicationScale);
if (false) {
Log.w(TAG, "getTopLevelResources: " + resDir + " / "
+ compInfo.applicationScale);
}
WeakReference<Resources> wr = mActiveResources.get(key);
- Resources r = wr != null ? wr.get() : null;
+ r = wr != null ? wr.get() : null;
if (r != null && r.getAssets().isUpToDate()) {
if (false) {
Log.w(TAG, "Returning cached resources " + r + " " + resDir
@@ -194,25 +195,37 @@ public final class ActivityThread {
}
return r;
}
+ }
- //if (r != null) {
- // Log.w(TAG, "Throwing away out-of-date resources!!!! "
- // + r + " " + resDir);
- //}
+ //if (r != null) {
+ // Log.w(TAG, "Throwing away out-of-date resources!!!! "
+ // + r + " " + resDir);
+ //}
- AssetManager assets = new AssetManager();
- if (assets.addAssetPath(resDir) == 0) {
- return null;
- }
+ AssetManager assets = new AssetManager();
+ if (assets.addAssetPath(resDir) == 0) {
+ return null;
+ }
- //Log.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
- DisplayMetrics metrics = getDisplayMetricsLocked(false);
- r = new Resources(assets, metrics, getConfiguration(), compInfo);
- if (false) {
- Log.i(TAG, "Created app resources " + resDir + " " + r + ": "
- + r.getConfiguration() + " appScale="
- + r.getCompatibilityInfo().applicationScale);
+ //Log.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
+ DisplayMetrics metrics = getDisplayMetricsLocked(false);
+ r = new Resources(assets, metrics, getConfiguration(), compInfo);
+ if (false) {
+ Log.i(TAG, "Created app resources " + resDir + " " + r + ": "
+ + r.getConfiguration() + " appScale="
+ + r.getCompatibilityInfo().applicationScale);
+ }
+
+ synchronized (mPackages) {
+ WeakReference<Resources> wr = mActiveResources.get(key);
+ Resources existing = wr != null ? wr.get() : null;
+ if (existing != null && existing.getAssets().isUpToDate()) {
+ // Someone else already created the resources while we were
+ // unlocked; go ahead and use theirs.
+ r.getAssets().close();
+ return existing;
}
+
// XXX need to remove entries when weak references go away
mActiveResources.put(key, new WeakReference<Resources>(r));
return r;