@@ -1471,13 +1471,25 @@ public final boolean queueIdle() {
14711471
14721472 private static class ResourcesKey {
14731473 final private String mResDir ;
1474+ final private Configuration mOverrideConfiguration ;
14741475 final private float mScale ;
14751476 final private int mHash ;
14761477
1477- ResourcesKey (String resDir , float scale ) {
1478+ ResourcesKey (String resDir , Configuration overrideConfiguration , float scale ) {
14781479 mResDir = resDir ;
1480+ if (overrideConfiguration != null ) {
1481+ if (Configuration .EMPTY .equals (overrideConfiguration )) {
1482+ overrideConfiguration = null ;
1483+ }
1484+ }
1485+ mOverrideConfiguration = overrideConfiguration ;
14791486 mScale = scale ;
1480- mHash = mResDir .hashCode () << 2 + (int ) (mScale * 2 );
1487+ int hash = 17 ;
1488+ hash = 31 * hash + mResDir .hashCode ();
1489+ hash = 31 * hash + (mOverrideConfiguration != null
1490+ ? mOverrideConfiguration .hashCode () : 0 );
1491+ hash = 31 * hash + Float .floatToIntBits (mScale );
1492+ mHash = hash ;
14811493 }
14821494
14831495 @ Override
@@ -1491,7 +1503,21 @@ public boolean equals(Object obj) {
14911503 return false ;
14921504 }
14931505 ResourcesKey peer = (ResourcesKey ) obj ;
1494- return mResDir .equals (peer .mResDir ) && mScale == peer .mScale ;
1506+ if (!mResDir .equals (peer .mResDir )) {
1507+ return false ;
1508+ }
1509+ if (mOverrideConfiguration != peer .mOverrideConfiguration ) {
1510+ if (mOverrideConfiguration == null || peer .mOverrideConfiguration == null ) {
1511+ return false ;
1512+ }
1513+ if (!mOverrideConfiguration .equals (peer .mOverrideConfiguration )) {
1514+ return false ;
1515+ }
1516+ }
1517+ if (mScale != peer .mScale ) {
1518+ return false ;
1519+ }
1520+ return true ;
14951521 }
14961522 }
14971523
@@ -1562,8 +1588,10 @@ Configuration applyConfigCompatMainThread(int displayDensity, Configuration conf
15621588 * @param compInfo the compability info. It will use the default compatibility info when it's
15631589 * null.
15641590 */
1565- Resources getTopLevelResources (String resDir , CompatibilityInfo compInfo ) {
1566- ResourcesKey key = new ResourcesKey (resDir , compInfo .applicationScale );
1591+ Resources getTopLevelResources (String resDir , Configuration overrideConfiguration ,
1592+ CompatibilityInfo compInfo ) {
1593+ ResourcesKey key = new ResourcesKey (resDir , overrideConfiguration ,
1594+ compInfo .applicationScale );
15671595 Resources r ;
15681596 synchronized (mPackages ) {
15691597 // Resources is app scale dependent.
@@ -1595,13 +1623,20 @@ Resources getTopLevelResources(String resDir, CompatibilityInfo compInfo) {
15951623
15961624 //Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
15971625 DisplayMetrics metrics = getDisplayMetricsLocked (null , false );
1598- r = new Resources (assets , metrics , getConfiguration (), compInfo );
1626+ Configuration config ;
1627+ if (key .mOverrideConfiguration != null ) {
1628+ config = new Configuration (getConfiguration ());
1629+ config .updateFrom (key .mOverrideConfiguration );
1630+ } else {
1631+ config = getConfiguration ();
1632+ }
1633+ r = new Resources (assets , metrics , config , compInfo );
15991634 if (false ) {
16001635 Slog .i (TAG , "Created app resources " + resDir + " " + r + ": "
16011636 + r .getConfiguration () + " appScale="
16021637 + r .getCompatibilityInfo ().applicationScale );
16031638 }
1604-
1639+
16051640 synchronized (mPackages ) {
16061641 WeakReference <Resources > wr = mActiveResources .get (key );
16071642 Resources existing = wr != null ? wr .get () : null ;
@@ -1621,8 +1656,10 @@ Resources getTopLevelResources(String resDir, CompatibilityInfo compInfo) {
16211656 /**
16221657 * Creates the top level resources for the given package.
16231658 */
1624- Resources getTopLevelResources (String resDir , LoadedApk pkgInfo ) {
1625- return getTopLevelResources (resDir , pkgInfo .mCompatibilityInfo .get ());
1659+ Resources getTopLevelResources (String resDir , Configuration overrideConfiguration ,
1660+ LoadedApk pkgInfo ) {
1661+ return getTopLevelResources (resDir , overrideConfiguration ,
1662+ pkgInfo .mCompatibilityInfo .get ());
16261663 }
16271664
16281665 final Handler getHandler () {
@@ -3675,18 +3712,28 @@ final boolean applyConfigurationToResourcesLocked(Configuration config,
36753712
36763713 ApplicationPackageManager .configurationChanged ();
36773714 //Slog.i(TAG, "Configuration changed in " + currentPackageName());
3678-
3679- Iterator < WeakReference < Resources >> it =
3680- mActiveResources . values (). iterator ();
3681- // Iterator<Map.Entry<String , WeakReference<Resources>>> it =
3682- // mActiveResources.entrySet().iterator();
3715+
3716+ Configuration tmpConfig = null ;
3717+
3718+ Iterator <Map .Entry <ResourcesKey , WeakReference <Resources >>> it =
3719+ mActiveResources .entrySet ().iterator ();
36833720 while (it .hasNext ()) {
3684- WeakReference <Resources > v = it .next ();
3685- Resources r = v .get ();
3721+ Map . Entry < ResourcesKey , WeakReference <Resources >> entry = it .next ();
3722+ Resources r = entry . getValue () .get ();
36863723 if (r != null ) {
36873724 if (DEBUG_CONFIGURATION ) Slog .v (TAG , "Changing resources "
36883725 + r + " config to: " + config );
3689- r .updateConfiguration (config , dm , compat );
3726+ Configuration override = entry .getKey ().mOverrideConfiguration ;
3727+ if (override != null ) {
3728+ if (tmpConfig == null ) {
3729+ tmpConfig = new Configuration ();
3730+ }
3731+ tmpConfig .setTo (config );
3732+ tmpConfig .updateFrom (override );
3733+ r .updateConfiguration (tmpConfig , dm , compat );
3734+ } else {
3735+ r .updateConfiguration (config , dm , compat );
3736+ }
36903737 //Slog.i(TAG, "Updated app resources " + v.getKey()
36913738 // + " " + r + ": " + r.getConfiguration());
36923739 } else {
0 commit comments