/// <summary>Creates the top level Resources for applications with the given compatibility info. /// </summary> /// <remarks>Creates the top level Resources for applications with the given compatibility info. /// </remarks> /// <param name="resDir">the resource directory.</param> /// <param name="compInfo"> /// the compability info. It will use the default compatibility info when it's /// null. /// </param> internal android.content.res.Resources getTopLevelResources(string resDir, android.content.res.CompatibilityInfo compInfo) { android.app.ActivityThread.ResourcesKey key = new android.app.ActivityThread.ResourcesKey (resDir, compInfo.applicationScale); android.content.res.Resources r; lock (mPackages) { // Resources is app scale dependent. if (false) { android.util.Slog.w(TAG, "getTopLevelResources: " + resDir + " / " + compInfo.applicationScale ); } [email protected]<android.content.res.Resources> wr = mActiveResources .get(key); r = wr != null ? wr.get() : null; //if (r != null) Slog.i(TAG, "isUpToDate " + resDir + ": " + r.getAssets().isUpToDate()); if (r != null && r.getAssets().isUpToDate()) { if (false) { android.util.Slog.w(TAG, "Returning cached resources " + r + " " + resDir + ": appScale=" + r.getCompatibilityInfo().applicationScale); } return r; } } //if (r != null) { // Slog.w(TAG, "Throwing away out-of-date resources!!!! " // + r + " " + resDir); //} android.content.res.AssetManager assets = new android.content.res.AssetManager(); if (assets.addAssetPath(resDir) == 0) { return null; } //Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics); android.util.DisplayMetrics metrics = getDisplayMetricsLocked(null, false); r = new android.content.res.Resources(assets, metrics, getConfiguration(), compInfo ); if (false) { android.util.Slog.i(TAG, "Created app resources " + resDir + " " + r + ": " + r.getConfiguration () + " appScale=" + r.getCompatibilityInfo().applicationScale); } lock (mPackages) { [email protected]<android.content.res.Resources> wr = mActiveResources .get(key); android.content.res.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 [email protected]<android.content.res.Resources >(r)); return r; } }