@@ -203,7 +203,7 @@ public final class ActivityThread {
203203 = new HashMap <String , WeakReference <LoadedApk >>();
204204 final HashMap <String , WeakReference <LoadedApk >> mResourcePackages
205205 = new HashMap <String , WeakReference <LoadedApk >>();
206- final HashMap <CompatibilityInfo , DisplayMetrics > mDisplayMetrics
206+ final HashMap <CompatibilityInfo , DisplayMetrics > mDefaultDisplayMetrics
207207 = new HashMap <CompatibilityInfo , DisplayMetrics >();
208208 final HashMap <ResourcesKey , WeakReference <Resources > > mActiveResources
209209 = new HashMap <ResourcesKey , WeakReference <Resources > >();
@@ -1475,12 +1475,14 @@ public final boolean queueIdle() {
14751475
14761476 private static class ResourcesKey {
14771477 final private String mResDir ;
1478+ final private int mDisplayId ;
14781479 final private Configuration mOverrideConfiguration ;
14791480 final private float mScale ;
14801481 final private int mHash ;
14811482
1482- ResourcesKey (String resDir , Configuration overrideConfiguration , float scale ) {
1483+ ResourcesKey (String resDir , int displayId , Configuration overrideConfiguration , float scale ) {
14831484 mResDir = resDir ;
1485+ mDisplayId = displayId ;
14841486 if (overrideConfiguration != null ) {
14851487 if (Configuration .EMPTY .equals (overrideConfiguration )) {
14861488 overrideConfiguration = null ;
@@ -1490,6 +1492,7 @@ private static class ResourcesKey {
14901492 mScale = scale ;
14911493 int hash = 17 ;
14921494 hash = 31 * hash + mResDir .hashCode ();
1495+ hash = 31 * hash + mDisplayId ;
14931496 hash = 31 * hash + (mOverrideConfiguration != null
14941497 ? mOverrideConfiguration .hashCode () : 0 );
14951498 hash = 31 * hash + Float .floatToIntBits (mScale );
@@ -1510,6 +1513,9 @@ public boolean equals(Object obj) {
15101513 if (!mResDir .equals (peer .mResDir )) {
15111514 return false ;
15121515 }
1516+ if (mDisplayId != peer .mDisplayId ) {
1517+ return false ;
1518+ }
15131519 if (mOverrideConfiguration != peer .mOverrideConfiguration ) {
15141520 if (mOverrideConfiguration == null || peer .mOverrideConfiguration == null ) {
15151521 return false ;
@@ -1552,28 +1558,32 @@ public static IPackageManager getPackageManager() {
15521558 return sPackageManager ;
15531559 }
15541560
1555- DisplayMetrics getDisplayMetricsLocked (CompatibilityInfo ci , boolean forceUpdate ) {
1556- DisplayMetrics dm = mDisplayMetrics .get (ci );
1557- if (dm != null && !forceUpdate ) {
1561+ private void flushDisplayMetricsLocked () {
1562+ mDefaultDisplayMetrics .clear ();
1563+ }
1564+
1565+ DisplayMetrics getDisplayMetricsLocked (int displayId , CompatibilityInfo ci ) {
1566+ boolean isDefaultDisplay = (displayId == Display .DEFAULT_DISPLAY );
1567+ DisplayMetrics dm = isDefaultDisplay ? mDefaultDisplayMetrics .get (ci ) : null ;
1568+ if (dm != null ) {
15581569 return dm ;
15591570 }
1571+ dm = new DisplayMetrics ();
15601572
15611573 DisplayManagerGlobal displayManager = DisplayManagerGlobal .getInstance ();
15621574 if (displayManager == null ) {
15631575 // may be null early in system startup
1564- dm = new DisplayMetrics ();
15651576 dm .setToDefaults ();
15661577 return dm ;
15671578 }
15681579
1569- if (dm == null ) {
1570- dm = new DisplayMetrics ();
1571- mDisplayMetrics .put (ci , dm );
1580+ if (isDefaultDisplay ) {
1581+ mDefaultDisplayMetrics .put (ci , dm );
15721582 }
15731583
15741584 CompatibilityInfoHolder cih = new CompatibilityInfoHolder ();
15751585 cih .set (ci );
1576- Display d = displayManager .getCompatibleDisplay (Display . DEFAULT_DISPLAY , cih );
1586+ Display d = displayManager .getCompatibleDisplay (displayId , cih );
15771587 d .getMetrics (dm );
15781588 //Slog.i("foo", "New metrics: w=" + metrics.widthPixels + " h="
15791589 // + metrics.heightPixels + " den=" + metrics.density
@@ -1602,9 +1612,11 @@ Configuration applyConfigCompatMainThread(int displayDensity, Configuration conf
16021612 * @param compInfo the compability info. It will use the default compatibility info when it's
16031613 * null.
16041614 */
1605- Resources getTopLevelResources (String resDir , Configuration overrideConfiguration ,
1615+ Resources getTopLevelResources (String resDir ,
1616+ int displayId , Configuration overrideConfiguration ,
16061617 CompatibilityInfo compInfo ) {
1607- ResourcesKey key = new ResourcesKey (resDir , overrideConfiguration ,
1618+ ResourcesKey key = new ResourcesKey (resDir ,
1619+ displayId , overrideConfiguration ,
16081620 compInfo .applicationScale );
16091621 Resources r ;
16101622 synchronized (mPackages ) {
@@ -1636,15 +1648,21 @@ Resources getTopLevelResources(String resDir, Configuration overrideConfiguratio
16361648 }
16371649
16381650 //Slog.i(TAG, "Resource: key=" + key + ", display metrics=" + metrics);
1639- DisplayMetrics metrics = getDisplayMetricsLocked (null , false );
1651+ DisplayMetrics dm = getDisplayMetricsLocked (displayId , null );
16401652 Configuration config ;
1641- if (key .mOverrideConfiguration != null ) {
1653+ boolean isDefaultDisplay = (displayId == Display .DEFAULT_DISPLAY );
1654+ if (!isDefaultDisplay || key .mOverrideConfiguration != null ) {
16421655 config = new Configuration (getConfiguration ());
1643- config .updateFrom (key .mOverrideConfiguration );
1656+ if (!isDefaultDisplay ) {
1657+ applyNonDefaultDisplayMetricsToConfigurationLocked (dm , config );
1658+ }
1659+ if (key .mOverrideConfiguration != null ) {
1660+ config .updateFrom (key .mOverrideConfiguration );
1661+ }
16441662 } else {
16451663 config = getConfiguration ();
16461664 }
1647- r = new Resources (assets , metrics , config , compInfo );
1665+ r = new Resources (assets , dm , config , compInfo );
16481666 if (false ) {
16491667 Slog .i (TAG , "Created app resources " + resDir + " " + r + ": "
16501668 + r .getConfiguration () + " appScale="
@@ -1670,9 +1688,10 @@ Resources getTopLevelResources(String resDir, Configuration overrideConfiguratio
16701688 /**
16711689 * Creates the top level resources for the given package.
16721690 */
1673- Resources getTopLevelResources (String resDir , Configuration overrideConfiguration ,
1691+ Resources getTopLevelResources (String resDir ,
1692+ int displayId , Configuration overrideConfiguration ,
16741693 LoadedApk pkgInfo ) {
1675- return getTopLevelResources (resDir , overrideConfiguration ,
1694+ return getTopLevelResources (resDir , displayId , overrideConfiguration ,
16761695 pkgInfo .mCompatibilityInfo .get ());
16771696 }
16781697
@@ -1844,7 +1863,8 @@ public ContextImpl getSystemContext() {
18441863 context .init (info , null , this );
18451864 context .getResources ().updateConfiguration (
18461865 getConfiguration (), getDisplayMetricsLocked (
1847- CompatibilityInfo .DEFAULT_COMPATIBILITY_INFO , false ));
1866+ Display .DEFAULT_DISPLAY ,
1867+ CompatibilityInfo .DEFAULT_COMPATIBILITY_INFO ));
18481868 mSystemContext = context ;
18491869 //Slog.i(TAG, "Created system resources " + context.getResources()
18501870 // + ": " + context.getResources().getConfiguration());
@@ -3707,7 +3727,9 @@ final boolean applyConfigurationToResourcesLocked(Configuration config,
37073727 return false ;
37083728 }
37093729 int changes = mResConfiguration .updateFrom (config );
3710- DisplayMetrics dm = getDisplayMetricsLocked (null , true );
3730+ flushDisplayMetricsLocked ();
3731+ DisplayMetrics defaultDisplayMetrics = getDisplayMetricsLocked (
3732+ Display .DEFAULT_DISPLAY , null );
37113733
37123734 if (compat != null && (mResCompatibilityInfo == null ||
37133735 !mResCompatibilityInfo .equals (compat ))) {
@@ -3722,7 +3744,7 @@ final boolean applyConfigurationToResourcesLocked(Configuration config,
37223744 Locale .setDefault (config .locale );
37233745 }
37243746
3725- Resources .updateSystemConfiguration (config , dm , compat );
3747+ Resources .updateSystemConfiguration (config , defaultDisplayMetrics , compat );
37263748
37273749 ApplicationPackageManager .configurationChanged ();
37283750 //Slog.i(TAG, "Configuration changed in " + currentPackageName());
@@ -3737,13 +3759,22 @@ final boolean applyConfigurationToResourcesLocked(Configuration config,
37373759 if (r != null ) {
37383760 if (DEBUG_CONFIGURATION ) Slog .v (TAG , "Changing resources "
37393761 + r + " config to: " + config );
3740- Configuration override = entry .getKey ().mOverrideConfiguration ;
3741- if (override != null ) {
3762+ int displayId = entry .getKey ().mDisplayId ;
3763+ boolean isDefaultDisplay = (displayId == Display .DEFAULT_DISPLAY );
3764+ DisplayMetrics dm = defaultDisplayMetrics ;
3765+ Configuration overrideConfig = entry .getKey ().mOverrideConfiguration ;
3766+ if (!isDefaultDisplay || overrideConfig != null ) {
37423767 if (tmpConfig == null ) {
37433768 tmpConfig = new Configuration ();
37443769 }
37453770 tmpConfig .setTo (config );
3746- tmpConfig .updateFrom (override );
3771+ if (!isDefaultDisplay ) {
3772+ dm = getDisplayMetricsLocked (displayId , null );
3773+ applyNonDefaultDisplayMetricsToConfigurationLocked (dm , tmpConfig );
3774+ }
3775+ if (overrideConfig != null ) {
3776+ tmpConfig .updateFrom (overrideConfig );
3777+ }
37473778 r .updateConfiguration (tmpConfig , dm , compat );
37483779 } else {
37493780 r .updateConfiguration (config , dm , compat );
@@ -3759,6 +3790,22 @@ final boolean applyConfigurationToResourcesLocked(Configuration config,
37593790 return changes != 0 ;
37603791 }
37613792
3793+ final void applyNonDefaultDisplayMetricsToConfigurationLocked (
3794+ DisplayMetrics dm , Configuration config ) {
3795+ config .screenLayout = Configuration .SCREENLAYOUT_SIZE_XLARGE
3796+ | Configuration .SCREENLAYOUT_LONG_NO ;
3797+ config .touchscreen = Configuration .TOUCHSCREEN_NOTOUCH ;
3798+ config .orientation = (dm .widthPixels >= dm .heightPixels ) ?
3799+ Configuration .ORIENTATION_LANDSCAPE : Configuration .ORIENTATION_PORTRAIT ;
3800+ config .densityDpi = dm .densityDpi ;
3801+ config .screenWidthDp = (int )(dm .widthPixels / dm .density );
3802+ config .screenHeightDp = (int )(dm .heightPixels / dm .density );
3803+ config .smallestScreenWidthDp = config .screenWidthDp ; // assume screen does not rotate
3804+ config .compatScreenWidthDp = config .screenWidthDp ;
3805+ config .compatScreenHeightDp = config .screenHeightDp ;
3806+ config .compatSmallestScreenWidthDp = config .smallestScreenWidthDp ;
3807+ }
3808+
37623809 final Configuration applyCompatConfiguration (int displayDensity ) {
37633810 Configuration config = mConfiguration ;
37643811 if (mCompatConfiguration == null ) {
0 commit comments