am 9fc20b0e: Merge change 8126 into donut

Merge commit '9fc20b0e381b5fe00b7049ef357c839cd05a33bf'

* commit '9fc20b0e381b5fe00b7049ef357c839cd05a33bf':
  First pass at reworking screen density/size APIs.
diff --git a/api/current.xml b/api/current.xml
index ae7e756..9f79118 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -3463,17 +3463,6 @@
  visibility="public"
 >
 </field>
-<field name="donut_resource_pad19"
- type="int"
- transient="false"
- volatile="false"
- value="16843405"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
 <field name="donut_resource_pad2"
  type="int"
  transient="false"
@@ -7038,6 +7027,17 @@
  visibility="public"
 >
 </field>
+<field name="resizeable"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843405"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="resource"
  type="int"
  transient="false"
@@ -39142,6 +39142,17 @@
  visibility="public"
 >
 </field>
+<field name="FLAG_RESIZEABLE_FOR_SCREENS"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="4096"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="FLAG_SUPPORTS_LARGE_SCREENS"
  type="int"
  transient="false"
@@ -43458,7 +43469,51 @@
  visibility="public"
 >
 </field>
-<field name="SCREENLAYOUT_LARGE"
+<field name="SCREENLAYOUT_LONG_MASK"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="48"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="SCREENLAYOUT_LONG_NO"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="SCREENLAYOUT_LONG_UNDEFINED"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="0"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="SCREENLAYOUT_LONG_YES"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="32"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="SCREENLAYOUT_SIZE_LARGE"
  type="int"
  transient="false"
  volatile="false"
@@ -43469,7 +43524,18 @@
  visibility="public"
 >
 </field>
-<field name="SCREENLAYOUT_NORMAL"
+<field name="SCREENLAYOUT_SIZE_MASK"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="15"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="SCREENLAYOUT_SIZE_NORMAL"
  type="int"
  transient="false"
  volatile="false"
@@ -43480,7 +43546,7 @@
  visibility="public"
 >
 </field>
-<field name="SCREENLAYOUT_SMALL"
+<field name="SCREENLAYOUT_SIZE_SMALL"
  type="int"
  transient="false"
  volatile="false"
@@ -43491,7 +43557,7 @@
  visibility="public"
 >
 </field>
-<field name="SCREENLAYOUT_UNDEFINED"
+<field name="SCREENLAYOUT_SIZE_UNDEFINED"
  type="int"
  transient="false"
  volatile="false"
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index 28a77a5..4a3137f 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -161,12 +161,20 @@
     public static final int FLAG_SUPPORTS_LARGE_SCREENS = 1<<11;
     
     /**
+     * Value for {@link #flags}: true when the application knows how to adjust
+     * its UI for different screen sizes.  Corresponds to
+     * {@link android.R.styleable#AndroidManifestSupportsScreens_resizeable
+     * android:resizeable}.
+     */
+    public static final int FLAG_RESIZEABLE_FOR_SCREENS = 1<<12;
+    
+    /**
      * Value for {@link #flags}: this is false if the application has set
      * its android:allowBackup to false, true otherwise.
      * 
      * {@hide}
      */
-    public static final int FLAG_ALLOW_BACKUP = 1<<12;
+    public static final int FLAG_ALLOW_BACKUP = 1<<13;
     
     /**
      * Indicates that the application supports any densities;
@@ -183,7 +191,7 @@
      * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
      * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS},
      * {@link #FLAG_SUPPORTS_NORMAL_SCREENS},
-     * {@link #FLAG_SUPPORTS_LARGE_SCREENS}.
+     * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_RESIZEABLE_FOR_SCREENS}.
      */
     public int flags = 0;
     
@@ -400,7 +408,7 @@
      */
     public void disableCompatibilityMode() {
         flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
-                FLAG_SUPPORTS_SMALL_SCREENS);
+                FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS);
         supportsDensities = ANY_DENSITIES_ARRAY;
     }
 }
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 39c27aa9..93ba959 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -674,6 +674,7 @@
         int supportsSmallScreens = 1;
         int supportsNormalScreens = 1;
         int supportsLargeScreens = 1;
+        int resizeable = 1;
         
         int outerDepth = parser.getDepth();
         while ((type=parser.next()) != parser.END_DOCUMENT
@@ -883,6 +884,9 @@
                 supportsLargeScreens = sa.getInteger(
                         com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
                         supportsLargeScreens);
+                resizeable = sa.getInteger(
+                        com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
+                        supportsLargeScreens);
 
                 sa.recycle();
                 
@@ -969,6 +973,11 @@
                         >= android.os.Build.VERSION_CODES.CUR_DEVELOPMENT)) {
             pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
         }
+        if (resizeable < 0 || (resizeable > 0
+                && pkg.applicationInfo.targetSdkVersion
+                        >= android.os.Build.VERSION_CODES.CUR_DEVELOPMENT)) {
+            pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
+        }
         int densities[] = null;
         int size = pkg.supportsDensityList.size();
         if (size > 0) {
diff --git a/core/java/android/content/res/CompatibilityInfo.java b/core/java/android/content/res/CompatibilityInfo.java
index 2805bd5..517551e 100644
--- a/core/java/android/content/res/CompatibilityInfo.java
+++ b/core/java/android/content/res/CompatibilityInfo.java
@@ -69,8 +69,8 @@
     /**
      * A flag mask to indicates that the application can expand over the original size.
      * The flag is set to true if
-     * 1) Application declares its expandable in manifest file using <expandable /> or
-     * 2) The screen size is same as (320 x 480) * density. 
+     * 1) Application declares its expandable in manifest file using <supports-screens> or
+     * 2) Configuration.SCREENLAYOUT_COMPAT_NEEDED is not set
      * {@see compatibilityFlag}
      */
     private static final int EXPANDABLE = 2;
@@ -78,11 +78,28 @@
     /**
      * A flag mask to tell if the application is configured to be expandable. This differs
      * from EXPANDABLE in that the application that is not expandable will be 
-     * marked as expandable if it runs in (320x 480) * density screen size.
+     * marked as expandable if Configuration.SCREENLAYOUT_COMPAT_NEEDED is not set.
      */
     private static final int CONFIGURED_EXPANDABLE = 4; 
 
-    private static final int SCALING_EXPANDABLE_MASK = SCALING_REQUIRED | EXPANDABLE;
+    /**
+     * A flag mask to indicates that the application supports large screens.
+     * The flag is set to true if
+     * 1) Application declares it supports large screens in manifest file using <supports-screens> or
+     * 2) The screen size is not large
+     * {@see compatibilityFlag}
+     */
+    private static final int LARGE_SCREENS = 8;
+    
+    /**
+     * A flag mask to tell if the application supports large screens. This differs
+     * from LARGE_SCREENS in that the application that does not support large
+     * screens will be marked as supporting them if the current screen is not
+     * large.
+     */
+    private static final int CONFIGURED_LARGE_SCREENS = 16; 
+
+    private static final int SCALING_EXPANDABLE_MASK = SCALING_REQUIRED | EXPANDABLE | LARGE_SCREENS;
 
     /**
      * The effective screen density we have selected for this application.
@@ -108,7 +125,10 @@
         appFlags = appInfo.flags;
         
         if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) {
-            mCompatibilityFlags = EXPANDABLE | CONFIGURED_EXPANDABLE;
+            mCompatibilityFlags |= LARGE_SCREENS | CONFIGURED_LARGE_SCREENS;
+        }
+        if ((appInfo.flags & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) {
+            mCompatibilityFlags |= EXPANDABLE | CONFIGURED_EXPANDABLE;
         }
         
         float packageDensityScale = -1.0f;
@@ -162,7 +182,8 @@
     private CompatibilityInfo() {
         this(ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS
                 | ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS
-                | ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS,
+                | ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS
+                | ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS,
                 EXPANDABLE | CONFIGURED_EXPANDABLE,
                 DisplayMetrics.DENSITY_DEVICE,
                 1.0f,
@@ -190,6 +211,17 @@
     }
 
     /**
+     * Sets large screen bit in the compatibility flag.
+     */
+    public void setLargeScreens(boolean expandable) {
+        if (expandable) {
+            mCompatibilityFlags |= CompatibilityInfo.LARGE_SCREENS;
+        } else {
+            mCompatibilityFlags &= ~CompatibilityInfo.LARGE_SCREENS;
+        }
+    }
+
+    /**
      * @return true if the application is configured to be expandable.
      */
     public boolean isConfiguredExpandable() {
@@ -197,6 +229,13 @@
     }
 
     /**
+     * @return true if the application is configured to be expandable.
+     */
+    public boolean isConfiguredLargeScreens() {
+        return (mCompatibilityFlags & CompatibilityInfo.CONFIGURED_LARGE_SCREENS) != 0;
+    }
+
+    /**
      * @return true if the scaling is required
      */
     public boolean isScalingRequired() {
@@ -204,7 +243,8 @@
     }
     
     public boolean supportsScreen() {
-        return (mCompatibilityFlags & CompatibilityInfo.EXPANDABLE) != 0;
+        return (mCompatibilityFlags & (EXPANDABLE|LARGE_SCREENS))
+                == (EXPANDABLE|LARGE_SCREENS);
     }
     
     @Override
@@ -219,8 +259,8 @@
      * @param params the window's parameter
      */
     public Translator getTranslator(WindowManager.LayoutParams params) {
-        if ( (mCompatibilityFlags & CompatibilityInfo.SCALING_EXPANDABLE_MASK)
-                == CompatibilityInfo.EXPANDABLE) {
+        if ( (mCompatibilityFlags & SCALING_EXPANDABLE_MASK)
+                == (EXPANDABLE|LARGE_SCREENS)) {
             if (DBG) Log.d(TAG, "no translation required");
             return null;
         }
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java
index 4928e93..cbf8410 100644
--- a/core/java/android/content/res/Configuration.java
+++ b/core/java/android/content/res/Configuration.java
@@ -41,6 +41,39 @@
      */
     public boolean userSetLocale;
 
+    public static final int SCREENLAYOUT_SIZE_MASK = 0x0f;
+    public static final int SCREENLAYOUT_SIZE_UNDEFINED = 0x00;
+    public static final int SCREENLAYOUT_SIZE_SMALL = 0x01;
+    public static final int SCREENLAYOUT_SIZE_NORMAL = 0x02;
+    public static final int SCREENLAYOUT_SIZE_LARGE = 0x03;
+    
+    public static final int SCREENLAYOUT_LONG_MASK = 0x30;
+    public static final int SCREENLAYOUT_LONG_UNDEFINED = 0x00;
+    public static final int SCREENLAYOUT_LONG_NO = 0x10;
+    public static final int SCREENLAYOUT_LONG_YES = 0x20;
+    
+    /**
+     * Special flag we generate to indicate that the screen layout requires
+     * us to use a compatibility mode for apps that are not modern layout
+     * aware.
+     * @hide
+     */
+    public static final int SCREENLAYOUT_COMPAT_NEEDED = 0x10000000;
+    
+    /**
+     * Bit mask of overall layout of the screen.  Currently there are two
+     * fields:
+     * <p>The {@link #SCREENLAYOUT_SIZE_MASK} bits define the overall size
+     * of the screen.  They may be one of
+     * {@link #SCREENLAYOUT_SIZE_SMALL}, {@link #SCREENLAYOUT_SIZE_NORMAL},
+     * or {@link #SCREENLAYOUT_SIZE_LARGE}.
+     * 
+     * <p>The {@link #SCREENLAYOUT_LONG_MASK} defines whether the screen
+     * is wider/taller than normal.  They may be one of
+     * {@link #SCREENLAYOUT_LONG_NO} or {@link #SCREENLAYOUT_LONG_YES}.
+     */
+    public int screenLayout;
+    
     public static final int TOUCHSCREEN_UNDEFINED = 0;
     public static final int TOUCHSCREEN_NOTOUCH = 1;
     public static final int TOUCHSCREEN_STYLUS = 2;
@@ -117,18 +150,6 @@
      */
     public int orientation;
     
-    public static final int SCREENLAYOUT_UNDEFINED = 0;
-    public static final int SCREENLAYOUT_SMALL = 1;
-    public static final int SCREENLAYOUT_NORMAL = 2;
-    public static final int SCREENLAYOUT_LARGE = 3;
-    
-    /**
-     * Overall layout of the screen.  May be one of
-     * {@link #SCREENLAYOUT_SMALL}, {@link #SCREENLAYOUT_NORMAL},
-     * or {@link #SCREENLAYOUT_LARGE}.
-     */
-    public int screenLayout;
-    
     /**
      * Construct an invalid Configuration.  You must call {@link #setToDefaults}
      * for this object to be valid.  {@more}
@@ -199,7 +220,7 @@
         hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED;
         navigation = NAVIGATION_UNDEFINED;
         orientation = ORIENTATION_UNDEFINED;
-        screenLayout = SCREENLAYOUT_UNDEFINED;
+        screenLayout = SCREENLAYOUT_SIZE_UNDEFINED;
     }
 
     /** {@hide} */
@@ -270,7 +291,7 @@
             changed |= ActivityInfo.CONFIG_ORIENTATION;
             orientation = delta.orientation;
         }
-        if (delta.screenLayout != SCREENLAYOUT_UNDEFINED
+        if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED
                 && screenLayout != delta.screenLayout) {
             changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
             screenLayout = delta.screenLayout;
@@ -343,7 +364,7 @@
                 && orientation != delta.orientation) {
             changed |= ActivityInfo.CONFIG_ORIENTATION;
         }
-        if (delta.screenLayout != SCREENLAYOUT_UNDEFINED
+        if (delta.screenLayout != SCREENLAYOUT_SIZE_UNDEFINED
                 && screenLayout != delta.screenLayout) {
             changed |= ActivityInfo.CONFIG_SCREEN_LAYOUT;
         }
diff --git a/core/java/android/util/DisplayMetrics.java b/core/java/android/util/DisplayMetrics.java
index 38d99b3..061f98a 100644
--- a/core/java/android/util/DisplayMetrics.java
+++ b/core/java/android/util/DisplayMetrics.java
@@ -123,51 +123,67 @@
      */
     public void updateMetrics(CompatibilityInfo compatibilityInfo, int orientation,
             int screenLayout) {
-        if (!compatibilityInfo.isConfiguredExpandable()) {
-            // Note: this assume that configuration is updated before calling
-            // updateMetrics method.
-            if (screenLayout == Configuration.SCREENLAYOUT_LARGE) {
-                // This is a large screen device and the app is not 
-                // compatible with large screens, to diddle it.
-                
-                compatibilityInfo.setExpandable(false);
-                // Figure out the compatibility width and height of the screen.
-                int defaultWidth;
-                int defaultHeight;
-                switch (orientation) {
-                    case Configuration.ORIENTATION_LANDSCAPE: {
-                        defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density +
-                                0.5f);
-                        defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density +
-                                0.5f);
-                        break;
-                    }
-                    case Configuration.ORIENTATION_PORTRAIT:
-                    case Configuration.ORIENTATION_SQUARE:
-                    default: {
-                        defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density +
-                                0.5f);
-                        defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density +
-                                0.5f);
-                        break;
-                    }
-                    case Configuration.ORIENTATION_UNDEFINED: {
-                        // don't change
-                        return;
-                    }
-                }
-                
-                if (defaultWidth < widthPixels) {
-                    // content/window's x offset in original pixels
-                    widthPixels = defaultWidth;
-                }
-                if (defaultHeight < heightPixels) {
-                    heightPixels = defaultHeight;
-                }
-                
-            } else {
-                // the screen size is same as expected size. make it expandable
+        boolean expandable = compatibilityInfo.isConfiguredExpandable();
+        boolean largeScreens = compatibilityInfo.isConfiguredLargeScreens();
+        
+        // Note: this assume that configuration is updated before calling
+        // updateMetrics method.
+        if (!expandable) {
+            if ((screenLayout&Configuration.SCREENLAYOUT_COMPAT_NEEDED) == 0) {
+                expandable = true;
+                // the current screen size is compatible with non-resizing apps.
                 compatibilityInfo.setExpandable(true);
+            } else {
+                compatibilityInfo.setExpandable(false);
+            }
+        }
+        if (!largeScreens) {
+            if ((screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK)
+                    != Configuration.SCREENLAYOUT_SIZE_LARGE) {
+                largeScreens = true;
+                // the current screen size is not large.
+                compatibilityInfo.setLargeScreens(true);
+            } else {
+                compatibilityInfo.setLargeScreens(false);
+            }
+        }
+        
+        if (!expandable || !largeScreens) {
+            // This is a larger screen device and the app is not 
+            // compatible with large screens, so diddle it.
+            
+            // Figure out the compatibility width and height of the screen.
+            int defaultWidth;
+            int defaultHeight;
+            switch (orientation) {
+                case Configuration.ORIENTATION_LANDSCAPE: {
+                    defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density +
+                            0.5f);
+                    defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density +
+                            0.5f);
+                    break;
+                }
+                case Configuration.ORIENTATION_PORTRAIT:
+                case Configuration.ORIENTATION_SQUARE:
+                default: {
+                    defaultWidth = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_WIDTH * density +
+                            0.5f);
+                    defaultHeight = (int)(CompatibilityInfo.DEFAULT_PORTRAIT_HEIGHT * density +
+                            0.5f);
+                    break;
+                }
+                case Configuration.ORIENTATION_UNDEFINED: {
+                    // don't change
+                    return;
+                }
+            }
+            
+            if (defaultWidth < widthPixels) {
+                // content/window's x offset in original pixels
+                widthPixels = defaultWidth;
+            }
+            if (defaultHeight < heightPixels) {
+                heightPixels = defaultHeight;
             }
         }
         if (compatibilityInfo.isScalingRequired()) {
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index 2d90ba4..59f4067 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -553,7 +553,7 @@
     config.touchscreen = (uint8_t)touchscreen;
     config.density = (uint16_t)density;
     config.keyboard = (uint8_t)keyboard;
-    config.inputFlags = (uint8_t)keyboardHidden<<ResTable_config::SHIFT_KEYSHIDDEN;
+    config.inputFlags = (uint8_t)keyboardHidden;
     config.navigation = (uint8_t)navigation;
     config.screenWidth = (uint16_t)screenWidth;
     config.screenHeight = (uint16_t)screenHeight;
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index 9dc483c..75568e1 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -885,6 +885,13 @@
              screen, so that it retains the dimensions it was originally
              designed for. -->
         <attr name="largeScreens" format="boolean" />
+        <!-- Indicates whether the application can resize itself to newer
+             screen sizes.  This is mostly used to distinguish between old
+             applications that may not be compatible with newly introduced
+             screen sizes and newer applications that should be; it will be
+             set for you automatically based on whether you are targeting
+             a newer platform that supports more screens. -->
+        <attr name="resizeable" format="boolean" />
     </declare-styleable>
 
     <!-- Private tag to declare system protected broadcast actions.
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 6906e438..e99f8be 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1126,6 +1126,7 @@
   <public type="attr" name="searchSettingsDescription" />
   <public type="attr" name="textColorPrimaryInverseDisableOnly" />
   <public type="attr" name="autoUrlDetect" />
+  <public type="attr" name="resizeable" />
 
   <public-padding type="attr" name="donut_resource_pad" end="0x0101029f" />
 
diff --git a/docs/html/guide/topics/resources/resources-i18n.jd b/docs/html/guide/topics/resources/resources-i18n.jd
index 2bcc5e3..c26cb63 100755
--- a/docs/html/guide/topics/resources/resources-i18n.jd
+++ b/docs/html/guide/topics/resources/resources-i18n.jd
@@ -441,7 +441,7 @@
 <pre>
 MyApp/
     res/
-        drawable-en-rUS-port-160dpi-finger-keysexposed-qwerty-dpad-480x320/
+        drawable-en-rUS-large-long-port-mdpi-finger-keysexposed-qwerty-dpad-480x320/
 </pre>
 
 <p>More typically, you will only specify a few specific configuration options. You may drop any of the values from the
@@ -453,7 +453,7 @@
     res/
         drawable-en-rUS-finger/
         drawable-port/
-        drawable-port-160dpi/
+        drawable-port-mdpi/
         drawable-qwerty/
 </pre>
 <p>Table 2 lists the valid folder-name qualifiers, in order of precedence. Qualifiers that are listed higher in the table take precedence over those listed lower, as described in <a href="#best-match">How Android finds the best matching directory</a>. </p>
@@ -465,37 +465,110 @@
     </tr>
     <tr>
       <td>MCC and MNC</td>
-      <td>The mobile country code and mobile network code from the SIM in the device. For example  <code>mcc310-mnc004</code> (U.S., Verizon brand); <code>mcc208-mnc00</code> (France, Orange brand); <code>mcc234-mnc00</code> (U.K., BT brand). <br>
-        <br>
-        If the device uses a radio connection  (GSM phone), the MCC will come from the SIM, and the MNC will come from the  network to which the device is attached. You might sometimes use the MCC alone, for example to include country-specific legal resources in your application. If your application specifies resources for a MCC/MNC  combination, those resources can only be used if both the MCC and the MNC match. </td>
-  </tr>
+      <td>The mobile country code optionally followed by mobile network code
+      from the SIM in the device. For example
+      <code>mcc310</code> (U.S. on any carrier);
+      <code>mcc310-mnc004</code> (U.S., Verizon brand);
+      <code>mcc208-mnc00</code> (France, Orange brand);
+      <code>mcc234-mnc00</code> (U.K., BT brand).
+        <p>
+        If the device uses a radio connection  (GSM phone), the MCC will come
+        from the SIM, and the MNC will come from the  network to which the
+        device is attached. You might sometimes use the MCC alone, for example
+        to include country-specific legal resources in your application. If
+        your application specifies resources for a MCC/MNC  combination, those
+        resources can only be used if both the MCC and the MNC match. </td>
+    </tr>
     <tr>
         <td>Language and region</td>
         <td>The two letter <a href="http://www.loc.gov/standards/iso639-2/php/code_list.php">ISO
-                639-1</a> language code and two letter
+                639-1</a> language code optionally followed by a two letter
                 <a href="http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html">ISO
                 3166-1-alpha-2</a> region code (preceded by lowercase &quot;r&quot;). For example 
-                <code>en-rUS</code>, <code>fr-rFR</code>, <code>es-rES</code>. <br>
-                <br>
-          The codes are case-sensitive: The language code is lowercase, and the country code is uppercase. You cannot specify a region alone, but you can specify a language alone, for example <code>en</code>, <code>fr</code>, <code>es</code>. </td>
-  </tr>
+                <code>fr</code>, <code>en-rUS</code>, <code>fr-rFR</code>, <code>es-rES</code>.
+                <p>
+          The codes are <em>not</em> case-sensitive; the r prefix is used to
+          distinguish the region portion.
+          You cannot specify a region alone, but you can specify a language alone,
+          for example <code>en</code>, <code>fr</code>, <code>es</code>. </td>
+    </tr>
+    <tr>
+        <td>Screen dimensions</td>
+        <td><code>small</code>, <code>normal</code>, <code>large</code>
+        <p>
+        Specify that the resource is for a particular class of screen.
+        The meanings of these are:</p>
+        <ul>
+        <li> <b>Normal screens</b> are based on the traditional Android HVGA
+        medium density screen.  A screen is considered to be normal if it is
+        at least this size (independent of density) and not large.  Examples
+        of such screens a WQVGA low density, HVGA medium density, WVGA
+        high density.
+        <li> <b>Small screens</b> are based on the space available on a
+        QVGA low density screen.  Considering a portrait HVGA display, this has
+        the same available width but less height -- it is 3:4 vs. HVGA's
+        2:3 aspect ratio.  Examples are QVGA low density and VGA high
+        density.
+        <li> <b>Large screens</b> are based on the space available on a
+        VGA medium density screen.  Such a screen has significantly more
+        available space in both width and height than an HVGA display.
+        Examples are VGA and WVGA medium density screens.
+        </td>
+    </tr>
+    <tr>
+        <td>Wider/taller screens</td>
+        <td><code>long</code>, <code>notlong</code>
+        <p>
+        Specify that the resource is for a taller/wider than traditional
+        screen.  This is based purely on the aspect ration of the screen:
+        QVGA, HVGA, and VGA are notlong; WQVGA, WVGA, FWVGA are long.  Note
+        that long may mean either wide or tall, depending on the current
+        orientation.
+        </td>
+    </tr>
     <tr>
         <td>Screen orientation</td>
-        <td><code>port</code>, <code>land</code>, <code>square</code> </td>
+        <td><code>port</code>, <code>land</code>, <code>square</code>
+        <p>
+        Specifies that the resource is for a screen that is tall (port)
+        or wide (land); square is not currently used.
+        </td>
     </tr>
     <tr>
         <td>Screen pixel density</td>
-        <td><code>92dpi</code>, <code>108dpi</code>, etc. When Android selects which resource files to use, it handles screen density  differently than the other qualifiers. In step 1 of <a href="#best-match">How Android finds the best matching directory</a> (below),  screen density is always  considered to be a match. In step 4, if the qualifier being considered is screen density, Android will select the best final match at that point, without any need to move on to step 5. </td>
-  </tr>
+        <td><code>ldpi</code>, <code>mdpi</code>, <code>hdpi</code>, <code>nodpi</code>
+        <p>
+         Specifies the screen density the resource is defined for.  The medium
+         density of traditional HVGA screens (mdpi) is defined to be approximately
+         160dpi; low density (ldpi) is 120, and high density (hdpi) is 240.  There
+         is thus a 4:3 scaling factor between each density, so a 9x9 bitmap
+         in ldpi would be 12x12 is mdpi and 16x16 in hdpi.  The special
+         <code>nodpi</code> density can be used with bitmap resources to prevent
+         them from being scaled at load time to match the device density.
+        <p>
+         When Android selects which resource files to use,
+         it handles screen density  differently than the other qualifiers.
+         In step 1 of <a href="#best-match">How Android finds the best
+         matching directory</a> (below), screen density is always considered to
+         be a match. In step 4, if the qualifier being considered is screen
+         density, Android will select the best final match at that point,
+         without any need to move on to step 5.
+         <p>
+         You can also specify explicit densities like <code>92dpi</code>
+         or <code>108dpi</code>, but these are not fully supported by the
+         system so should not be used.
+         </td>
+    </tr>
     <tr>
         <td>Touchscreen type</td>
         <td><code>notouch</code>, <code>stylus</code>, <code>finger</code></td>
     </tr>
     <tr>
         <td>Whether the keyboard is available to the user</td>
-        <td><code>keysexposed</code>, <code>keyshidden</code>, <code>keyssoft</code> <br>
+        <td><code>keysexposed</code>, <code>keyshidden</code>, <code>keyssoft</code>
+        <p>
           If your application has specific resources that should only be used with a soft keyboard, use the <code>keyssoft</code> value. If no <code>keyssoft</code> resources are available (only <code>keysexposed</code> and <code>keyshidden</code>) and the device  shows a soft keyboard,  the system will use <code>keysexposed</code> resources. </td>
-  </tr>
+    </tr>
     <tr>
         <td>Primary text input method</td>
         <td><code>nokeys</code>, <code>qwerty</code>, <code>12key</code> </td>
@@ -508,15 +581,17 @@
     <tr>
         <td>Screen dimensions</td>
         <td><code>320x240</code>, <code>640x480</code>, etc. The larger dimension
-            must be specified first. </td>
+            must be specified first.  This configuration is deprecated and
+            should not be used; use instead screen dimension, wider/taller
+            screens, and screen orientation described above.</td>
     </tr>
     <tr>
       <td>SDK version</td>
       <td>The SDK version supported by the device, for example <code>v3</code>. The Android 1.0 SDK is <code>v1, </code> the 1.1 SDK is <code>v2</code>, and the 1.5 SDK is <code>v3</code>.</td>
-  </tr>
+    </tr>
     <tr>
       <td>(Minor version)</td>
-      <td>(You cannot currently    specify minor version. It is always set to 0.)</td>
+      <td>(You cannot currently specify minor version. It is always set to 0.)</td>
   </tr>
 </table>
 
@@ -536,8 +611,11 @@
         <li>Incorrect: <code>values-nokeys-mcc460/</code></li>
       </ul>
     </li>
-    <li>Values are case-sensitive. For example, a portrait-specific <code>drawable</code> directory must be named
-    <code>drawable-port</code>, not <code>drawable-PORT</code> or <code>drawable-Port</code>.</li>
+    <li>Values are case-insensitive.  The resource compiler converts folder names
+    to lower case before processing to avoid problems in case-insensitive
+    file systems.  On case-sensitive file systems, you should keep all names
+    lower-case or at least use a consistent case to protect your future
+    sanity when trying to find a resource file.</li>
     <li>Only one value for each qualifier type is supported. For example, if you want to use exactly the same drawable files for Spain and France, you will need two  resource directories, such as <code>drawable-rES/</code> and <code>drawable-rFR/</code>, containing identical files. You cannot 
         have a directory named <code>drawable-rES-rFR/</code>. </li>
     <li>Qualified directories cannot be nested. For example, you cannot have <code>res/drawable/drawable-en</code>. </li>
@@ -546,7 +624,7 @@
 <h3>How resources are referenced in code</h3>
 <p>All resources will be referenced in code or resource reference syntax by
     their simple, undecorated names. So if a resource were named this:<br />
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>MyApp/res/drawable-port-92dpi/myimage.png</code><br />
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>MyApp/res/drawable-port-mdpi/myimage.png</code><br />
   It would be referenced as this:<br />
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>R.drawable.myimage</code> (code)<br />
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<code>&#064;drawable/myimage</code> (XML)</p>
@@ -554,11 +632,12 @@
 <h3 id="best-match">How Android finds the best matching directory </h3>
 
 <p>Android will pick which of the various underlying resource files should be
-used at runtime, depending on the current configuration of the device. The example used here assumes the following device configuration:</p>
+used at runtime, depending on the current configuration of the device.
+The example used here assumes the following device configuration:</p>
 <blockquote>
   <p>Locale = <code>en-GB</code><br>
   Screen orientation = <code>port</code><br>
-  Screen pixel density = <code>108dpi</code><br>
+  Screen pixel density = <code>mdpi</code><br>
     Touchscreen type = <code>notouch</code><br>
     Primary text input method = <code>12key</code><br>
   </p>
@@ -573,9 +652,9 @@
 <strike>MyApp/res/drawable-fr-rCA/</strike>
 MyApp/res/drawable-en-port/
 MyApp/res/drawable-en-notouch-12key/
-MyApp/res/drawable-port-92dpi/
+MyApp/res/drawable-port-ldpi/
 MyApp/res/drawable-port-notouch-12key</pre>
-      <strong>Exception: </strong>Screen pixel density is the one qualifier that is not used to eliminate files. Even though the screen density of the device is 108 dpi, <code>drawable-port-92dpi/</code> is not  eliminated from the list, because every screen density is considered to be a 
+      <strong>Exception: </strong>Screen pixel density is the one qualifier that is not used to eliminate files. Even though the screen density of the device is medium dpi, <code>drawable-port-ldpi/</code> is not  eliminated from the list, because every screen density is considered to be a 
         match at this point.</li>
     <li>From <a href="#table2">Table 2</a>, pick the   highest-precedence qualifier that remains in the list. (Start with MCC, then move down through the list.) </li>
   <li>Do any of the available resource directories include this qualifier?  </li>
@@ -588,7 +667,7 @@
 MyApp/res/drawable-en/
 MyApp/res/drawable-en-port/
 MyApp/res/drawable-en-notouch-12key/
-<strike>MyApp/res/drawable-port-92dpi/</strike>
+<strike>MyApp/res/drawable-port-ldpi/</strike>
 <strike>MyApp/res/drawable-port-notouch-12key</strike></pre>
   <strong>Exception:</strong> If the qualifier in question  is screen pixel density, Android will select the option that most closely matches the device, and the selection process will be complete. In general, Android will prefer scaling down a larger original image to scaling  up a smaller original image.<br><br></li>
 
@@ -597,7 +676,11 @@
     <pre><strike>MyApp/res/drawable-en/</strike>
 MyApp/res/drawable-en-port/
 <strike>MyApp/res/drawable-en-notouch-12key/</strike></pre>
-  Only one choice remains, so that's it. When drawables are called for in this example application, the Android system will load resources from the <code>MyApp/res/drawable-en-port/</code> directory.
+  Only one choice remains, so that's it. When drawables are called for in this
+  example application, the Android system will load resources from the
+  <code>MyApp/res/drawable-en-port/</code> directory.  In addition, if the
+  resource being loaded is a bitmap, it will be scaled up so that its supplied
+  low density matches the device's medium density.
 </ol>
 <p class="note"><strong>Tip:</strong> The <em>precedence</em> of the qualifiers is more important than the number of qualifiers that exactly match the device. For example, in step 4 above, the last choice on the list includes three qualifiers that exactly match the device (orientation, touchscreen type, and input method), while <code>drawable-en</code> has only one parameter that matches (language). However, language has a higher precedence, so <code>drawable-port-notouch-12key</code> is out.</p>
 <p>This flowchart summarizes how Android selects resource directories to load.</p>
diff --git a/include/utils/ResourceTypes.h b/include/utils/ResourceTypes.h
index 3819335..edd0cae6 100644
--- a/include/utils/ResourceTypes.h
+++ b/include/utils/ResourceTypes.h
@@ -826,6 +826,9 @@
     
     enum {
         DENSITY_DEFAULT = 0,
+        DENSITY_LOW = 120,
+        DENSITY_MEDIUM = 160,
+        DENSITY_HIGH = 240,
         DENSITY_NONE = 0xffff
     };
     
@@ -855,7 +858,6 @@
     
     enum {
         MASK_KEYSHIDDEN = 0x0003,
-        SHIFT_KEYSHIDDEN = 0,
         KEYSHIDDEN_ANY = 0x0000,
         KEYSHIDDEN_NO = 0x0001,
         KEYSHIDDEN_YES = 0x0002,
@@ -907,10 +909,18 @@
     };
     
     enum {
-        SCREENLAYOUT_ANY  = 0x0000,
-        SCREENLAYOUT_SMALL = 0x0001,
-        SCREENLAYOUT_NORMAL = 0x0002,
-        SCREENLAYOUT_LARGE = 0x0003,
+        // screenLayout bits for screen size class.
+        MASK_SCREENSIZE = 0x0f,
+        SCREENSIZE_ANY  = 0x00,
+        SCREENSIZE_SMALL = 0x01,
+        SCREENSIZE_NORMAL = 0x02,
+        SCREENSIZE_LARGE = 0x03,
+        
+        // screenLayout bits for wide/long screen variation.
+        MASK_SCREENLONG = 0x30,
+        SCREENLONG_ANY = 0x00,
+        SCREENLONG_NO = 0x10,
+        SCREENLONG_YES = 0x20,
     };
     
     union {
@@ -1040,6 +1050,17 @@
             }
         }
 
+        if (screenConfig || o.screenConfig) {
+            if (((screenLayout^o.screenLayout) & MASK_SCREENSIZE) != 0) {
+                if (!(screenLayout & MASK_SCREENSIZE)) return false;
+                if (!(o.screenLayout & MASK_SCREENSIZE)) return true;
+            }
+            if (((screenLayout^o.screenLayout) & MASK_SCREENLONG) != 0) {
+                if (!(screenLayout & MASK_SCREENLONG)) return false;
+                if (!(o.screenLayout & MASK_SCREENLONG)) return true;
+            }
+        }
+
         if (screenType || o.screenType) {
             if (orientation != o.orientation) {
                 if (!orientation) return false;
@@ -1056,7 +1077,7 @@
         }
 
         if (input || o.input) {
-            if (inputFlags != o.inputFlags) {
+            if (((inputFlags^o.inputFlags) & MASK_KEYSHIDDEN) != 0) {
                 if (!(inputFlags & MASK_KEYSHIDDEN)) return false;
                 if (!(o.inputFlags & MASK_KEYSHIDDEN)) return true;
             }
@@ -1084,13 +1105,6 @@
             }
         }
 
-        if (screenConfig || o.screenConfig) {
-            if (screenLayout != o.screenLayout) {
-                if (!screenLayout) return false;
-                if (!o.screenLayout) return true;
-            }
-        }
-
         if (version || o.version) {
             if (sdkVersion != o.sdkVersion) {
                 if (!sdkVersion) return false;
@@ -1139,6 +1153,17 @@
                 }
             }
 
+            if (screenConfig || o.screenConfig) {
+                if (((screenLayout^o.screenLayout) & MASK_SCREENSIZE) != 0
+                        && (requested->screenLayout & MASK_SCREENSIZE)) {
+                    return (screenLayout & MASK_SCREENSIZE);
+                }
+                if (((screenLayout^o.screenLayout) & MASK_SCREENLONG) != 0
+                        && (requested->screenLayout & MASK_SCREENLONG)) {
+                    return (screenLayout & MASK_SCREENLONG);
+                }
+            }
+
             if (screenType || o.screenType) {
                 if ((orientation != o.orientation) && requested->orientation) {
                     return (orientation);
@@ -1220,12 +1245,6 @@
                 }
             }
 
-            if (screenConfig || o.screenConfig) {
-                if ((screenLayout != o.screenLayout) && requested->screenLayout) {
-                    return (screenLayout);
-                }
-            }
-
             if (version || o.version) {
                 if ((sdkVersion != o.sdkVersion) && requested->sdkVersion) {
                     return (sdkVersion);
@@ -1273,6 +1292,21 @@
                 return false;
             }
         }
+        if (screenConfig != 0) {
+            const int screenSize = screenLayout&MASK_SCREENSIZE;
+            const int setScreenSize = settings.screenLayout&MASK_SCREENSIZE;
+            if (setScreenSize != 0 && screenSize != 0
+                    && screenSize != setScreenSize) {
+                return false;
+            }
+            
+            const int screenLong = screenLayout&MASK_SCREENLONG;
+            const int setScreenLong = settings.screenLayout&MASK_SCREENLONG;
+            if (setScreenLong != 0 && screenLong != 0
+                    && screenLong != setScreenLong) {
+                return false;
+            }
+        }
         if (screenType != 0) {
             if (settings.orientation != 0 && orientation != 0
                 && orientation != settings.orientation) {
@@ -1317,12 +1351,6 @@
                 return false;
             }
         }
-        if (screenConfig != 0) {
-            if (settings.screenLayout != 0 && screenLayout != 0
-                && screenLayout != settings.screenLayout) {
-                return false;
-            }
-        }
         if (version != 0) {
             if (settings.sdkVersion != 0 && sdkVersion != 0
                 && sdkVersion != settings.sdkVersion) {
@@ -1352,12 +1380,14 @@
     String8 toString() const {
         char buf[200];
         sprintf(buf, "imsi=%d/%d lang=%c%c reg=%c%c orient=%d touch=%d dens=%d "
-                "kbd=%d nav=%d input=%d scrnW=%d scrnH=%d layout=%d vers=%d.%d",
+                "kbd=%d nav=%d input=%d scrnW=%d scrnH=%d sz=%d long=%d vers=%d.%d",
                 mcc, mnc,
                 language[0] ? language[0] : '-', language[1] ? language[1] : '-',
                 country[0] ? country[0] : '-', country[1] ? country[1] : '-',
                 orientation, touchscreen, density, keyboard, navigation, inputFlags,
-                screenWidth, screenHeight, screenLayout, sdkVersion, minorVersion);
+                screenWidth, screenHeight,
+                screenLayout&MASK_SCREENSIZE, screenLayout&MASK_SCREENLONG,
+                sdkVersion, minorVersion);
         return String8(buf);
     }
 };
diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp
index 98d450b..4dca8bd 100644
--- a/libs/utils/ResourceTypes.cpp
+++ b/libs/utils/ResourceTypes.cpp
@@ -4012,11 +4012,11 @@
                     if (dval == ResTable_config::DENSITY_DEFAULT) {
                         strcpy(density, "def");
                     } else if (dval == ResTable_config::DENSITY_NONE) {
-                        strcpy(density, "non");
+                        strcpy(density, "no");
                     } else {
                         sprintf(density, "%d", (int)dval);
                     }
-                    printf("      config %d lang=%c%c cnt=%c%c orien=%d touch=%d density=%s key=%d infl=%d nav=%d w=%d h=%d lyt=%d\n",
+                    printf("      config %d lang=%c%c cnt=%c%c orien=%d touch=%d density=%s key=%d infl=%d nav=%d w=%d h=%d sz=%d lng=%d\n",
                            (int)configIndex,
                            type->config.language[0] ? type->config.language[0] : '-',
                            type->config.language[1] ? type->config.language[1] : '-',
@@ -4030,7 +4030,8 @@
                            type->config.navigation,
                            dtohs(type->config.screenWidth),
                            dtohs(type->config.screenHeight),
-                           type->config.screenLayout);
+                           type->config.screenLayout&ResTable_config::MASK_SCREENSIZE,
+                           type->config.screenLayout&ResTable_config::MASK_SCREENLONG);
                     size_t entryCount = dtohl(type->entryCount);
                     uint32_t entriesStart = dtohl(type->entriesStart);
                     if ((entriesStart&0x3) != 0) {
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index 9de4150..9c60157 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -4919,6 +4919,10 @@
                                 ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) {
                             screens.add("small,");
                         }
+                        if ((ps.pkg.applicationInfo.flags & 
+                                ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) {
+                            screens.add("resizeable,");
+                        }
                         pw.print("    supportsScreens="); pw.println(screens);
                     }
                     pw.print("    timeStamp="); pw.println(ps.getTimeStampStr());
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index 4bc7c68..b43acaf 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -423,7 +423,7 @@
     final Rect mTempRect = new Rect();
 
     final Configuration mTempConfiguration = new Configuration();
-    int screenLayout = Configuration.SCREENLAYOUT_UNDEFINED;
+    int mScreenLayout = Configuration.SCREENLAYOUT_SIZE_UNDEFINED;
 
     // The frame use to limit the size of the app running in compatibility mode.
     Rect mCompatibleScreenFrame = new Rect();
@@ -3766,7 +3766,7 @@
         mDisplay.getMetrics(dm);
         CompatibilityInfo.updateCompatibleScreenFrame(dm, orientation, mCompatibleScreenFrame);
 
-        if (screenLayout == Configuration.SCREENLAYOUT_UNDEFINED) {
+        if (mScreenLayout == Configuration.SCREENLAYOUT_SIZE_UNDEFINED) {
             // Note we only do this once because at this point we don't
             // expect the screen to change in this way at runtime, and want
             // to avoid all of this computation for every config change.
@@ -3786,16 +3786,35 @@
             if (longSize < 470) {
                 // This is shorter than an HVGA normal density screen (which
                 // is 480 pixels on its long side).
-                screenLayout = Configuration.SCREENLAYOUT_SMALL;
-            } else if (longSize > 490 && shortSize > 330) {
-                // This is larger than an HVGA normal density screen (which
-                // is 480x320 pixels).
-                screenLayout = Configuration.SCREENLAYOUT_LARGE;
+                mScreenLayout = Configuration.SCREENLAYOUT_SIZE_SMALL
+                        | Configuration.SCREENLAYOUT_LONG_NO;
             } else {
-                screenLayout = Configuration.SCREENLAYOUT_NORMAL;
+                // Is this a large screen?
+                if (longSize > 640 && shortSize >= 480) {
+                    // VGA or larger screens at medium density are the point
+                    // at which we consider it to be a large screen.
+                    mScreenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
+                } else {
+                    mScreenLayout = Configuration.SCREENLAYOUT_SIZE_NORMAL;
+                    
+                    // If this screen is wider than normal HVGA, or taller
+                    // than FWVGA, then for old apps we want to run in size
+                    // compatibility mode.
+                    if (shortSize > 321 || longSize > 570) {
+                        mScreenLayout |= Configuration.SCREENLAYOUT_COMPAT_NEEDED;
+                    }
+                }
+                
+                // Is this a long screen?
+                if (((longSize*3)/5) >= (shortSize-1)) {
+                    // Anything wider than WVGA (5:3) is considering to be long.
+                    mScreenLayout |= Configuration.SCREENLAYOUT_LONG_YES;
+                } else {
+                    mScreenLayout |= Configuration.SCREENLAYOUT_LONG_NO;
+                }
             }
         }
-        config.screenLayout = screenLayout;
+        config.screenLayout = mScreenLayout;
         
         config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO;
         config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_NO;
diff --git a/tests/DpiTest/res/drawable-240dpi/logo240dpi.png b/tests/DpiTest/res/drawable-hdpi/logo240dpi.png
similarity index 100%
rename from tests/DpiTest/res/drawable-240dpi/logo240dpi.png
rename to tests/DpiTest/res/drawable-hdpi/logo240dpi.png
Binary files differ
diff --git a/tests/DpiTest/res/drawable-120dpi/logo120dpi.png b/tests/DpiTest/res/drawable-ldpi/logo120dpi.png
similarity index 100%
rename from tests/DpiTest/res/drawable-120dpi/logo120dpi.png
rename to tests/DpiTest/res/drawable-ldpi/logo120dpi.png
Binary files differ
diff --git a/tests/DpiTest/res/values-largeScreen/strings.xml b/tests/DpiTest/res/values-large-long/strings.xml
similarity index 91%
copy from tests/DpiTest/res/values-largeScreen/strings.xml
copy to tests/DpiTest/res/values-large-long/strings.xml
index f4dd543..be304a7 100644
--- a/tests/DpiTest/res/values-largeScreen/strings.xml
+++ b/tests/DpiTest/res/values-large-long/strings.xml
@@ -15,5 +15,5 @@
 -->
 
 <resources>
-    <string name="act_title">DpiTest: Large Screen</string>
+    <string name="act_title">DpiTest: Large Long</string>
 </resources>
diff --git a/tests/DpiTest/res/values-largeScreen/strings.xml b/tests/DpiTest/res/values-large-notlong/strings.xml
similarity index 91%
copy from tests/DpiTest/res/values-largeScreen/strings.xml
copy to tests/DpiTest/res/values-large-notlong/strings.xml
index f4dd543..9681f44 100644
--- a/tests/DpiTest/res/values-largeScreen/strings.xml
+++ b/tests/DpiTest/res/values-large-notlong/strings.xml
@@ -15,5 +15,5 @@
 -->
 
 <resources>
-    <string name="act_title">DpiTest: Large Screen</string>
+    <string name="act_title">DpiTest: Large NotLong</string>
 </resources>
diff --git a/tests/DpiTest/res/values-largeScreen/strings.xml b/tests/DpiTest/res/values-large/strings.xml
similarity index 91%
copy from tests/DpiTest/res/values-largeScreen/strings.xml
copy to tests/DpiTest/res/values-large/strings.xml
index f4dd543..faa95f2 100644
--- a/tests/DpiTest/res/values-largeScreen/strings.xml
+++ b/tests/DpiTest/res/values-large/strings.xml
@@ -15,5 +15,5 @@
 -->
 
 <resources>
-    <string name="act_title">DpiTest: Large Screen</string>
+    <string name="act_title">DpiTest: Large</string>
 </resources>
diff --git a/tests/DpiTest/res/values-largeScreen/strings.xml b/tests/DpiTest/res/values-long/strings.xml
similarity index 91%
copy from tests/DpiTest/res/values-largeScreen/strings.xml
copy to tests/DpiTest/res/values-long/strings.xml
index f4dd543..d6e5d93 100644
--- a/tests/DpiTest/res/values-largeScreen/strings.xml
+++ b/tests/DpiTest/res/values-long/strings.xml
@@ -15,5 +15,5 @@
 -->
 
 <resources>
-    <string name="act_title">DpiTest: Large Screen</string>
+    <string name="act_title">DpiTest: Long</string>
 </resources>
diff --git a/tests/DpiTest/res/values-largeScreen/strings.xml b/tests/DpiTest/res/values-normal-long/strings.xml
similarity index 91%
copy from tests/DpiTest/res/values-largeScreen/strings.xml
copy to tests/DpiTest/res/values-normal-long/strings.xml
index f4dd543..6406083 100644
--- a/tests/DpiTest/res/values-largeScreen/strings.xml
+++ b/tests/DpiTest/res/values-normal-long/strings.xml
@@ -15,5 +15,5 @@
 -->
 
 <resources>
-    <string name="act_title">DpiTest: Large Screen</string>
+    <string name="act_title">DpiTest: Normal Long</string>
 </resources>
diff --git a/tests/DpiTest/res/values-largeScreen/strings.xml b/tests/DpiTest/res/values-normal-notlong/strings.xml
similarity index 91%
rename from tests/DpiTest/res/values-largeScreen/strings.xml
rename to tests/DpiTest/res/values-normal-notlong/strings.xml
index f4dd543..3265e4c5 100644
--- a/tests/DpiTest/res/values-largeScreen/strings.xml
+++ b/tests/DpiTest/res/values-normal-notlong/strings.xml
@@ -15,5 +15,5 @@
 -->
 
 <resources>
-    <string name="act_title">DpiTest: Large Screen</string>
+    <string name="act_title">DpiTest: Normal NotLong</string>
 </resources>
diff --git a/tests/DpiTest/res/values-largeScreen/strings.xml b/tests/DpiTest/res/values-normal/strings.xml
similarity index 91%
copy from tests/DpiTest/res/values-largeScreen/strings.xml
copy to tests/DpiTest/res/values-normal/strings.xml
index f4dd543..1e27da4 100644
--- a/tests/DpiTest/res/values-largeScreen/strings.xml
+++ b/tests/DpiTest/res/values-normal/strings.xml
@@ -15,5 +15,5 @@
 -->
 
 <resources>
-    <string name="act_title">DpiTest: Large Screen</string>
+    <string name="act_title">DpiTest: Normal</string>
 </resources>
diff --git a/tests/DpiTest/res/values-normalScreen/strings.xml b/tests/DpiTest/res/values-normalScreen/strings.xml
deleted file mode 100644
index 256d696..0000000
--- a/tests/DpiTest/res/values-normalScreen/strings.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2007 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-  
-          http://www.apache.org/licenses/LICENSE-2.0
-  
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<resources>
-    <string name="act_title">DpiTest: Normal Screen</string>
-</resources>
diff --git a/tests/DpiTest/res/values-largeScreen/strings.xml b/tests/DpiTest/res/values-notlong/strings.xml
similarity index 91%
copy from tests/DpiTest/res/values-largeScreen/strings.xml
copy to tests/DpiTest/res/values-notlong/strings.xml
index f4dd543..4b9d5da 100644
--- a/tests/DpiTest/res/values-largeScreen/strings.xml
+++ b/tests/DpiTest/res/values-notlong/strings.xml
@@ -15,5 +15,5 @@
 -->
 
 <resources>
-    <string name="act_title">DpiTest: Large Screen</string>
+    <string name="act_title">DpiTest: NotLong</string>
 </resources>
diff --git a/tests/DpiTest/res/values-largeScreen/strings.xml b/tests/DpiTest/res/values-small-long/strings.xml
similarity index 91%
copy from tests/DpiTest/res/values-largeScreen/strings.xml
copy to tests/DpiTest/res/values-small-long/strings.xml
index f4dd543..2575b0d 100644
--- a/tests/DpiTest/res/values-largeScreen/strings.xml
+++ b/tests/DpiTest/res/values-small-long/strings.xml
@@ -15,5 +15,5 @@
 -->
 
 <resources>
-    <string name="act_title">DpiTest: Large Screen</string>
+    <string name="act_title">DpiTest: Small Long</string>
 </resources>
diff --git a/tests/DpiTest/res/values-largeScreen/strings.xml b/tests/DpiTest/res/values-small-notlong/strings.xml
similarity index 91%
copy from tests/DpiTest/res/values-largeScreen/strings.xml
copy to tests/DpiTest/res/values-small-notlong/strings.xml
index f4dd543..2df2b29 100644
--- a/tests/DpiTest/res/values-largeScreen/strings.xml
+++ b/tests/DpiTest/res/values-small-notlong/strings.xml
@@ -15,5 +15,5 @@
 -->
 
 <resources>
-    <string name="act_title">DpiTest: Large Screen</string>
+    <string name="act_title">DpiTest: Small NotLong</string>
 </resources>
diff --git a/tests/DpiTest/res/values-largeScreen/strings.xml b/tests/DpiTest/res/values-small/strings.xml
similarity index 91%
copy from tests/DpiTest/res/values-largeScreen/strings.xml
copy to tests/DpiTest/res/values-small/strings.xml
index f4dd543..9fd5e40 100644
--- a/tests/DpiTest/res/values-largeScreen/strings.xml
+++ b/tests/DpiTest/res/values-small/strings.xml
@@ -15,5 +15,5 @@
 -->
 
 <resources>
-    <string name="act_title">DpiTest: Large Screen</string>
+    <string name="act_title">DpiTest: Small</string>
 </resources>
diff --git a/tests/DpiTest/res/values-smallScreen/strings.xml b/tests/DpiTest/res/values-smallScreen/strings.xml
deleted file mode 100644
index cdb4ac9..0000000
--- a/tests/DpiTest/res/values-smallScreen/strings.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2007 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-  
-          http://www.apache.org/licenses/LICENSE-2.0
-  
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<resources>
-    <string name="act_title">DpiTest: Small Screen</string>
-</resources>
diff --git a/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java b/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java
index 8c69305..49fff57 100644
--- a/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java
+++ b/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java
@@ -57,7 +57,8 @@
             if (noCompat) {
                 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS
                     | ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS
-                    | ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
+                    | ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS
+                    | ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
                 ai.supportsDensities = new int[] { ApplicationInfo.ANY_DENSITY };
                 app.getResources().setCompatibilityInfo(new CompatibilityInfo(ai));
             }
diff --git a/tools/aapt/AaptAssets.cpp b/tools/aapt/AaptAssets.cpp
index 14cad2f..dbcef6d 100644
--- a/tools/aapt/AaptAssets.cpp
+++ b/tools/aapt/AaptAssets.cpp
@@ -138,6 +138,20 @@
         return 0;
     }
 
+    // screen layout size
+    if (getScreenLayoutSizeName(part.string(), &config)) {
+        *axis = AXIS_SCREENLAYOUTSIZE;
+        *value = (config.screenLayout&ResTable_config::MASK_SCREENSIZE);
+        return 0;
+    }
+
+    // screen layout long
+    if (getScreenLayoutLongName(part.string(), &config)) {
+        *axis = AXIS_SCREENLAYOUTLONG;
+        *value = (config.screenLayout&ResTable_config::MASK_SCREENLONG);
+        return 0;
+    }
+
     // orientation
     if (getOrientationName(part.string(), &config)) {
         *axis = AXIS_ORIENTATION;
@@ -187,13 +201,6 @@
         return 0;
     }
 
-    // screen layout
-    if (getScreenLayoutName(part.string(), &config)) {
-        *axis = AXIS_SCREENLAYOUT;
-        *value = config.screenLayout;
-        return 0;
-    }
-
     // version
     if (getVersionName(part.string(), &config)) {
         *axis = AXIS_VERSION;
@@ -209,7 +216,8 @@
 {
     Vector<String8> parts;
 
-    String8 mcc, mnc, loc, orient, den, touch, key, keysHidden, nav, size, layout, vers;
+    String8 mcc, mnc, loc, layoutsize, layoutlong, orient, den;
+    String8 touch, key, keysHidden, nav, size, vers;
 
     const char *p = dir;
     const char *q;
@@ -296,6 +304,30 @@
         //printf("not region: %s\n", part.string());
     }
 
+    if (getScreenLayoutSizeName(part.string())) {
+        layoutsize = part;
+
+        index++;
+        if (index == N) {
+            goto success;
+        }
+        part = parts[index];
+    } else {
+        //printf("not screen layout size: %s\n", part.string());
+    }
+
+    if (getScreenLayoutLongName(part.string())) {
+        layoutlong = part;
+
+        index++;
+        if (index == N) {
+            goto success;
+        }
+        part = parts[index];
+    } else {
+        //printf("not screen layout long: %s\n", part.string());
+    }
+
     // orientation
     if (getOrientationName(part.string())) {
         orient = part;
@@ -385,18 +417,6 @@
         //printf("not screen size: %s\n", part.string());
     }
 
-    if (getScreenLayoutName(part.string())) {
-        layout = part;
-
-        index++;
-        if (index == N) {
-            goto success;
-        }
-        part = parts[index];
-    } else {
-        //printf("not screen layout: %s\n", part.string());
-    }
-
     if (getVersionName(part.string())) {
         vers = part;
 
@@ -416,6 +436,8 @@
     this->mcc = mcc;
     this->mnc = mnc;
     this->locale = loc;
+    this->screenLayoutSize = layoutsize;
+    this->screenLayoutLong = layoutlong;
     this->orientation = orient;
     this->density = den;
     this->touchscreen = touch;
@@ -423,7 +445,6 @@
     this->keyboard = key;
     this->navigation = nav;
     this->screenSize = size;
-    this->screenLayout = layout;
     this->version = vers;
 
     // what is this anyway?
@@ -441,6 +462,10 @@
     s += ",";
     s += this->locale;
     s += ",";
+    s += screenLayoutSize;
+    s += ",";
+    s += screenLayoutLong;
+    s += ",";
     s += this->orientation;
     s += ",";
     s += density;
@@ -455,8 +480,6 @@
     s += ",";
     s += screenSize;
     s += ",";
-    s += screenLayout;
-    s += ",";
     s += version;
     return s;
 }
@@ -477,6 +500,14 @@
         s += "-";
         s += locale;
     }
+    if (this->screenLayoutSize != "") {
+        s += "-";
+        s += screenLayoutSize;
+    }
+    if (this->screenLayoutLong != "") {
+        s += "-";
+        s += screenLayoutLong;
+    }
     if (this->orientation != "") {
         s += "-";
         s += orientation;
@@ -505,10 +536,6 @@
         s += "-";
         s += screenSize;
     }
-    if (this->screenLayout != "") {
-        s += "-";
-        s += screenLayout;
-    }
     if (this->version != "") {
         s += "-";
         s += version;
@@ -630,6 +657,57 @@
     return false;
 }
 
+bool AaptGroupEntry::getScreenLayoutSizeName(const char* name,
+                                     ResTable_config* out)
+{
+    if (strcmp(name, kWildcardName) == 0) {
+        if (out) out->screenLayout =
+                (out->screenLayout&~ResTable_config::MASK_SCREENSIZE)
+                | ResTable_config::SCREENSIZE_ANY;
+        return true;
+    } else if (strcmp(name, "small") == 0) {
+        if (out) out->screenLayout =
+                (out->screenLayout&~ResTable_config::MASK_SCREENSIZE)
+                | ResTable_config::SCREENSIZE_SMALL;
+        return true;
+    } else if (strcmp(name, "normal") == 0) {
+        if (out) out->screenLayout =
+                (out->screenLayout&~ResTable_config::MASK_SCREENSIZE)
+                | ResTable_config::SCREENSIZE_NORMAL;
+        return true;
+    } else if (strcmp(name, "large") == 0) {
+        if (out) out->screenLayout =
+                (out->screenLayout&~ResTable_config::MASK_SCREENSIZE)
+                | ResTable_config::SCREENSIZE_LARGE;
+        return true;
+    }
+
+    return false;
+}
+
+bool AaptGroupEntry::getScreenLayoutLongName(const char* name,
+                                     ResTable_config* out)
+{
+    if (strcmp(name, kWildcardName) == 0) {
+        if (out) out->screenLayout =
+                (out->screenLayout&~ResTable_config::MASK_SCREENLONG)
+                | ResTable_config::SCREENLONG_ANY;
+        return true;
+    } else if (strcmp(name, "long") == 0) {
+        if (out) out->screenLayout =
+                (out->screenLayout&~ResTable_config::MASK_SCREENLONG)
+                | ResTable_config::SCREENLONG_YES;
+        return true;
+    } else if (strcmp(name, "notlong") == 0) {
+        if (out) out->screenLayout =
+                (out->screenLayout&~ResTable_config::MASK_SCREENLONG)
+                | ResTable_config::SCREENLONG_NO;
+        return true;
+    }
+
+    return false;
+}
+
 bool AaptGroupEntry::getOrientationName(const char* name,
                                         ResTable_config* out)
 {
@@ -663,6 +741,21 @@
         return true;
     }
     
+    if (strcmp(name, "ldpi") == 0) {
+        if (out) out->density = ResTable_config::DENSITY_LOW;
+        return true;
+    }
+    
+    if (strcmp(name, "mdpi") == 0) {
+        if (out) out->density = ResTable_config::DENSITY_MEDIUM;
+        return true;
+    }
+    
+    if (strcmp(name, "hdpi") == 0) {
+        if (out) out->density = ResTable_config::DENSITY_HIGH;
+        return true;
+    }
+    
     char* c = (char*)name;
     while (*c >= '0' && *c <= '9') {
         c++;
@@ -818,26 +911,6 @@
     return true;
 }
 
-bool AaptGroupEntry::getScreenLayoutName(const char* name,
-                                     ResTable_config* out)
-{
-    if (strcmp(name, kWildcardName) == 0) {
-        if (out) out->screenLayout = out->SCREENLAYOUT_ANY;
-        return true;
-    } else if (strcmp(name, "smallscreen") == 0) {
-        if (out) out->screenLayout = out->SCREENLAYOUT_SMALL;
-        return true;
-    } else if (strcmp(name, "normalscreen") == 0) {
-        if (out) out->screenLayout = out->SCREENLAYOUT_NORMAL;
-        return true;
-    } else if (strcmp(name, "largescreen") == 0) {
-        if (out) out->screenLayout = out->SCREENLAYOUT_LARGE;
-        return true;
-    }
-
-    return false;
-}
-
 bool AaptGroupEntry::getVersionName(const char* name,
                                     ResTable_config* out)
 {
@@ -873,6 +946,8 @@
     if (v == 0) v = mnc.compare(o.mnc);
     if (v == 0) v = locale.compare(o.locale);
     if (v == 0) v = vendor.compare(o.vendor);
+    if (v == 0) v = screenLayoutSize.compare(o.screenLayoutSize);
+    if (v == 0) v = screenLayoutLong.compare(o.screenLayoutLong);
     if (v == 0) v = orientation.compare(o.orientation);
     if (v == 0) v = density.compare(o.density);
     if (v == 0) v = touchscreen.compare(o.touchscreen);
@@ -880,7 +955,6 @@
     if (v == 0) v = keyboard.compare(o.keyboard);
     if (v == 0) v = navigation.compare(o.navigation);
     if (v == 0) v = screenSize.compare(o.screenSize);
-    if (v == 0) v = screenLayout.compare(o.screenLayout);
     if (v == 0) v = version.compare(o.version);
     return v;
 }
@@ -892,6 +966,8 @@
     getMccName(mcc.string(), &params);
     getMncName(mnc.string(), &params);
     getLocaleName(locale.string(), &params);
+    getScreenLayoutSizeName(screenLayoutSize.string(), &params);
+    getScreenLayoutLongName(screenLayoutLong.string(), &params);
     getOrientationName(orientation.string(), &params);
     getDensityName(density.string(), &params);
     getTouchscreenName(touchscreen.string(), &params);
@@ -899,7 +975,6 @@
     getKeyboardName(keyboard.string(), &params);
     getNavigationName(navigation.string(), &params);
     getScreenSizeName(screenSize.string(), &params);
-    getScreenLayoutName(screenLayout.string(), &params);
     getVersionName(version.string(), &params);
     return params;
 }
diff --git a/tools/aapt/AaptAssets.h b/tools/aapt/AaptAssets.h
index e8c7395..5724349 100644
--- a/tools/aapt/AaptAssets.h
+++ b/tools/aapt/AaptAssets.h
@@ -30,6 +30,8 @@
     AXIS_MNC,
     AXIS_LANGUAGE,
     AXIS_REGION,
+    AXIS_SCREENLAYOUTSIZE,
+    AXIS_SCREENLAYOUTLONG,
     AXIS_ORIENTATION,
     AXIS_DENSITY,
     AXIS_TOUCHSCREEN,
@@ -37,7 +39,6 @@
     AXIS_KEYBOARD,
     AXIS_NAVIGATION,
     AXIS_SCREENSIZE,
-    AXIS_SCREENLAYOUT,
     AXIS_VERSION
 };
 
@@ -56,6 +57,8 @@
     String8 mnc;
     String8 locale;
     String8 vendor;
+    String8 screenLayoutSize;
+    String8 screenLayoutLong;
     String8 orientation;
     String8 density;
     String8 touchscreen;
@@ -63,7 +66,6 @@
     String8 keyboard;
     String8 navigation;
     String8 screenSize;
-    String8 screenLayout;
     String8 version;
 
     bool initFromDirName(const char* dir, String8* resType);
@@ -73,6 +75,8 @@
     static bool getMccName(const char* name, ResTable_config* out = NULL);
     static bool getMncName(const char* name, ResTable_config* out = NULL);
     static bool getLocaleName(const char* name, ResTable_config* out = NULL);
+    static bool getScreenLayoutSizeName(const char* name, ResTable_config* out = NULL);
+    static bool getScreenLayoutLongName(const char* name, ResTable_config* out = NULL);
     static bool getOrientationName(const char* name, ResTable_config* out = NULL);
     static bool getDensityName(const char* name, ResTable_config* out = NULL);
     static bool getTouchscreenName(const char* name, ResTable_config* out = NULL);
@@ -80,7 +84,6 @@
     static bool getKeyboardName(const char* name, ResTable_config* out = NULL);
     static bool getNavigationName(const char* name, ResTable_config* out = NULL);
     static bool getScreenSizeName(const char* name, ResTable_config* out = NULL);
-    static bool getScreenLayoutName(const char* name, ResTable_config* out = NULL);
     static bool getVersionName(const char* name, ResTable_config* out = NULL);
 
     int compare(const AaptGroupEntry& o) const;