Work on issue #6949468: android.dpi.cts.ConfigurationScreenLayoutTest...

...#testScreenLayout failures on JO

This doesn't actually fix it; I have concluded that the test is broken
(the platform is correctly reporting that this is a NOT LONG device
because in portrait once you account for the status bar and system
bar our size is 880dp high and 600dp wide, which is not enough for us
to be in the LONG config).

However while working on this I noticed that the code for computing
the configuration of the external display was wrong.  I have fixed
that by putting this code for computing these parts of the configuration
in a common place that both the window manager and external display
code can use.

Change-Id: Ic6a84b955e9ec345a87f725203a29e4712dac0ad
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 6638433..6ef3651 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -3872,14 +3872,20 @@
 
     final void applyNonDefaultDisplayMetricsToConfigurationLocked(
             DisplayMetrics dm, Configuration config) {
-        config.screenLayout = Configuration.SCREENLAYOUT_SIZE_XLARGE
-                | Configuration.SCREENLAYOUT_LONG_NO;
         config.touchscreen = Configuration.TOUCHSCREEN_NOTOUCH;
-        config.orientation = (dm.widthPixels >= dm.heightPixels) ?
-                Configuration.ORIENTATION_LANDSCAPE : Configuration.ORIENTATION_PORTRAIT;
         config.densityDpi = dm.densityDpi;
         config.screenWidthDp = (int)(dm.widthPixels / dm.density);
         config.screenHeightDp = (int)(dm.heightPixels / dm.density);
+        int sl = Configuration.resetScreenLayout(config.screenLayout);
+        if (dm.widthPixels > dm.heightPixels) {
+            config.orientation = Configuration.ORIENTATION_LANDSCAPE;
+            config.screenLayout = Configuration.reduceScreenLayout(sl,
+                    config.screenWidthDp, config.screenHeightDp);
+        } else {
+            config.orientation = Configuration.ORIENTATION_PORTRAIT;
+            config.screenLayout = Configuration.reduceScreenLayout(sl,
+                    config.screenHeightDp, config.screenWidthDp);
+        }
         config.smallestScreenWidthDp = config.screenWidthDp; // assume screen does not rotate
         config.compatScreenWidthDp = config.screenWidthDp;
         config.compatScreenHeightDp = config.screenHeightDp;