Merge change 8220 into donut

* changes:
  Fix issue 1996218: Disable use of shared memory buffer by SoundPool.
diff --git a/api/current.xml b/api/current.xml
index 0e04f50..a730ed0 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -2231,6 +2231,17 @@
  visibility="public"
 >
 </field>
+<field name="anyDensity"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16843372"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="apiKey"
  type="int"
  transient="false"
@@ -3078,17 +3089,6 @@
  visibility="public"
 >
 </field>
-<field name="density"
- type="int"
- transient="false"
- volatile="false"
- value="16843372"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
 <field name="dependency"
  type="int"
  transient="false"
@@ -35540,6 +35540,17 @@
  visibility="public"
 >
 </field>
+<field name="FLAG_SUPPORTS_SCREEN_DENSITIES"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="8192"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="FLAG_SUPPORTS_SMALL_SCREENS"
  type="int"
  transient="false"
@@ -35695,17 +35706,6 @@
  visibility="public"
 >
 </field>
-<field name="supportsDensities"
- type="int[]"
- transient="false"
- volatile="false"
- value="null"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
 <field name="targetSdkVersion"
  type="int"
  transient="false"
@@ -37604,17 +37604,6 @@
  visibility="public"
 >
 </field>
-<field name="GET_SUPPORTS_DENSITIES"
- type="int"
- transient="false"
- volatile="false"
- value="32768"
- static="true"
- final="true"
- deprecated="not deprecated"
- visibility="public"
->
-</field>
 <field name="GET_UNINSTALLED_PACKAGES"
  type="int"
  transient="false"
@@ -91633,6 +91622,56 @@
 </parameter>
 </method>
 </class>
+<class name="Version"
+ extends="java.lang.Object"
+ abstract="false"
+ static="false"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<constructor name="Version"
+ type="android.opengl.Version"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</constructor>
+<method name="getOpenGLESVersion"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<field name="OPENGLES_11"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="11"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="OPENGLES_20"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="20"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+</class>
 <class name="Visibility"
  extends="java.lang.Object"
  abstract="false"
diff --git a/core/java/android/app/SearchDialog.java b/core/java/android/app/SearchDialog.java
index 27c6376..0380c90 100644
--- a/core/java/android/app/SearchDialog.java
+++ b/core/java/android/app/SearchDialog.java
@@ -34,7 +34,10 @@
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.Bundle;
+import android.os.IBinder;
+import android.os.RemoteException;
 import android.os.SystemClock;
+import android.provider.Browser;
 import android.server.search.SearchableInfo;
 import android.speech.RecognizerIntent;
 import android.text.Editable;
@@ -42,6 +45,7 @@
 import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.text.util.Regex;
+import android.util.AndroidRuntimeException;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.ContextThemeWrapper;
@@ -1093,7 +1097,8 @@
      */
     protected void launchQuerySearch(int actionKey, String actionMsg)  {
         String query = mSearchAutoComplete.getText().toString();
-        Intent intent = createIntent(Intent.ACTION_SEARCH, null, null, query, null,
+        String action = mGlobalSearchMode ? Intent.ACTION_WEB_SEARCH : Intent.ACTION_SEARCH;
+        Intent intent = createIntent(action, null, null, query, null,
                 actionKey, actionMsg);
         launchIntent(intent);
     }
@@ -1245,16 +1250,127 @@
             return;
         }
         Log.d(LOG_TAG, "launching " + intent);
-        getContext().startActivity(intent);
-
-        // in global search mode, SearchDialogWrapper#performActivityResuming will handle hiding
-        // the dialog when the next activity starts, but for in-app search, we still need to
-        // dismiss the dialog.
-        if (!mGlobalSearchMode) {
-            dismiss();
+        try {
+            // in global search mode, we send the activity straight to the original suggestion
+            // source. this is because GlobalSearch may not have permission to launch the
+            // intent, and to avoid the extra step of going through GlobalSearch.
+            if (mGlobalSearchMode) {
+                launchGlobalSearchIntent(intent);
+            } else {
+                getContext().startActivity(intent);
+                // in global search mode, SearchDialogWrapper#performActivityResuming
+                // will handle hiding the dialog when the next activity starts, but for
+                // in-app search, we still need to dismiss the dialog.
+                dismiss();
+            }
+        } catch (RuntimeException ex) {
+            Log.e(LOG_TAG, "Failed launch activity: " + intent, ex);
         }
     }
-    
+
+    private void launchGlobalSearchIntent(Intent intent) {
+        final String packageName;
+        // GlobalSearch puts the original source of the suggestion in the
+        // 'component name' column. If set, we send the intent to that activity.
+        // We trust GlobalSearch to always set this to the suggestion source.
+        String intentComponent = intent.getStringExtra(SearchManager.COMPONENT_NAME_KEY);
+        if (intentComponent != null) {
+            ComponentName componentName = ComponentName.unflattenFromString(intentComponent);
+            intent.setComponent(componentName);
+            intent.removeExtra(SearchManager.COMPONENT_NAME_KEY);
+            // Launch the intent as the suggestion source.
+            // This prevents sources from using the search dialog to launch
+            // intents that they don't have permission for themselves.
+            packageName = componentName.getPackageName();
+        } else {
+            // If there is no component in the suggestion, it must be a built-in suggestion
+            // from GlobalSearch (e.g. "Search the web for") or the intent
+            // launched when pressing the search/go button in the search dialog.
+            // Launch the intent with the permissions of GlobalSearch.
+            packageName = mSearchable.getSearchActivity().getPackageName();
+        }
+
+        // Launch all global search suggestions as new tasks, since they don't relate
+        // to the current task.
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        setBrowserApplicationId(intent);
+
+        if (DBG) Log.d(LOG_TAG, "Launching intent " + intent.toURI() + " as " + packageName);
+        startActivityInPackage(intent, packageName);
+    }
+
+    /**
+     * If the intent is to open an HTTP or HTTPS URL, we set
+     * {@link Browser#EXTRA_APPLICATION_ID} so that any existing browser window that
+     * has been opened by us for the same URL will be reused.
+     */
+    private void setBrowserApplicationId(Intent intent) {
+        Uri data = intent.getData();
+        if (Intent.ACTION_VIEW.equals(intent.getAction()) && data != null) {
+            String scheme = data.getScheme();
+            if (scheme != null && scheme.startsWith("http")) {
+                intent.putExtra(Browser.EXTRA_APPLICATION_ID, data.toString());
+            }
+        }
+    }
+
+    /**
+     * Starts an activity as if it had been started by the given package.
+     *
+     * @param intent The description of the activity to start.
+     * @param packageName
+     * @throws ActivityNotFoundException If the intent could not be resolved to
+     *         and existing activity.
+     * @throws SecurityException If the package does not have permission to start
+     *         start the activity.
+     * @throws AndroidRuntimeException If some other error occurs.
+     */
+    private void startActivityInPackage(Intent intent, String packageName) {
+        try {
+            int uid = ActivityThread.getPackageManager().getPackageUid(packageName);
+            if (uid < 0) {
+                throw new AndroidRuntimeException("Package UID not found " + packageName);
+            }
+            String resolvedType = intent.resolveTypeIfNeeded(getContext().getContentResolver());
+            IBinder resultTo = null;
+            String resultWho = null;
+            int requestCode = -1;
+            boolean onlyIfNeeded = false;
+            int result = ActivityManagerNative.getDefault().startActivityInPackage(
+                    uid, intent, resolvedType, resultTo, resultWho, requestCode, onlyIfNeeded);
+            checkStartActivityResult(result, intent);
+        } catch (RemoteException ex) {
+            throw new AndroidRuntimeException(ex);
+        }
+    }
+
+    // Stolen from Instrumentation.checkStartActivityResult()
+    private static void checkStartActivityResult(int res, Intent intent) {
+        if (res >= IActivityManager.START_SUCCESS) {
+            return;
+        }
+        switch (res) {
+            case IActivityManager.START_INTENT_NOT_RESOLVED:
+            case IActivityManager.START_CLASS_NOT_FOUND:
+                if (intent.getComponent() != null)
+                    throw new ActivityNotFoundException(
+                            "Unable to find explicit activity class "
+                            + intent.getComponent().toShortString()
+                            + "; have you declared this activity in your AndroidManifest.xml?");
+                throw new ActivityNotFoundException(
+                        "No Activity found to handle " + intent);
+            case IActivityManager.START_PERMISSION_DENIED:
+                throw new SecurityException("Not allowed to start activity "
+                        + intent);
+            case IActivityManager.START_FORWARD_AND_REQUEST_CONFLICT:
+                throw new AndroidRuntimeException(
+                        "FORWARD_RESULT_FLAG used while also requesting a result");
+            default:
+                throw new AndroidRuntimeException("Unknown error code "
+                        + res + " when starting " + intent);
+        }
+    }
+
     /**
      * Handles the special intent actions declared in {@link SearchManager}.
      * 
@@ -1460,8 +1576,10 @@
             intent.putExtra(SearchManager.ACTION_KEY, actionKey);
             intent.putExtra(SearchManager.ACTION_MSG, actionMsg);
         }
-        // attempt to enforce security requirement (no 3rd-party intents)
-        intent.setComponent(mSearchable.getSearchActivity());
+        // Only allow 3rd-party intents from GlobalSearch
+        if (!mGlobalSearchMode) {
+            intent.setComponent(mSearchable.getSearchActivity());
+        }
         return intent;
     }
     
diff --git a/core/java/android/app/SuggestionsAdapter.java b/core/java/android/app/SuggestionsAdapter.java
index 593b7b7..4cd35a4 100644
--- a/core/java/android/app/SuggestionsAdapter.java
+++ b/core/java/android/app/SuggestionsAdapter.java
@@ -27,6 +27,7 @@
 import android.database.Cursor;
 import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
+import android.graphics.drawable.DrawableContainer;
 import android.graphics.drawable.StateListDrawable;
 import android.net.Uri;
 import android.os.Bundle;
@@ -359,6 +360,10 @@
             newBg.addState(new int[]{android.R.attr.state_selected}, transparent);
             newBg.addState(new int[]{android.R.attr.state_pressed}, transparent);
             newBg.addState(new int[]{}, background);
+            // Workaround for the fact that StateListDrawable.getPadding(Rect) always returns
+            // true, and thus sets the padding of any view that has it as a background.
+            ((DrawableContainer.DrawableContainerState) newBg.getConstantState())
+                    .setVariablePadding(true);
             mBackgroundsCache.put(backgroundColor, newBg.getConstantState());
             return newBg;
         }
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index 4a3137f..9ca11cd 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -169,21 +169,22 @@
     public static final int FLAG_RESIZEABLE_FOR_SCREENS = 1<<12;
     
     /**
+     * Value for {@link #flags}: true when the application knows how to
+     * accomodate different screen densities.  Corresponds to
+     * {@link android.R.styleable#AndroidManifestSupportsScreens_anyDensity
+     * android:anyDensity}.
+     */
+    public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 1<<13;
+    
+    /**
      * 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<<13;
+    public static final int FLAG_ALLOW_BACKUP = 1<<14;
     
     /**
-     * Indicates that the application supports any densities;
-     * {@hide}
-     */
-    public static final int ANY_DENSITY = -1;
-    static final int[] ANY_DENSITIES_ARRAY = { ANY_DENSITY };
-
-    /**
      * Flags associated with the application.  Any combination of
      * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
      * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
@@ -228,13 +229,6 @@
     public int uid;
     
     /**
-     * The list of densities in DPI that application supprots. This
-     * field is only set if the {@link PackageManager#GET_SUPPORTS_DENSITIES} flag was
-     * used when retrieving the structure.
-     */
-    public int[] supportsDensities;
-
-    /**
      * The minimum SDK version this application targets.  It may run on earilier
      * versions, but it knows how to work with any new behavior added at this
      * version.  Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
@@ -267,7 +261,6 @@
         pw.println(prefix + "enabled=" + enabled);
         pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);
         pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes));
-        pw.println(prefix + "supportsDensities=" + supportsDensities);
         super.dumpBack(pw, prefix);
     }
     
@@ -314,7 +307,6 @@
         enabled = orig.enabled;
         manageSpaceActivityName = orig.manageSpaceActivityName;
         descriptionRes = orig.descriptionRes;
-        supportsDensities = orig.supportsDensities;
     }
 
 
@@ -346,7 +338,6 @@
         dest.writeString(manageSpaceActivityName);
         dest.writeString(backupAgentName);
         dest.writeInt(descriptionRes);
-        dest.writeIntArray(supportsDensities);
     }
 
     public static final Parcelable.Creator<ApplicationInfo> CREATOR
@@ -377,7 +368,6 @@
         manageSpaceActivityName = source.readString();
         backupAgentName = source.readString();
         descriptionRes = source.readInt();
-        supportsDensities = source.createIntArray();
     }
 
     /**
@@ -408,7 +398,7 @@
      */
     public void disableCompatibilityMode() {
         flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
-                FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS);
-        supportsDensities = ANY_DENSITIES_ARRAY;
+                FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
+                FLAG_SUPPORTS_SCREEN_DENSITIES);
     }
 }
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 941ca9e..67bd1ac 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -165,12 +165,6 @@
     public static final int GET_CONFIGURATIONS = 0x00004000;
 
     /**
-     * {@link ApplicationInfo} flag: return the
-     * {@link ApplicationInfo#supportsDensities} that the package supports.
-     */
-    public static final int GET_SUPPORTS_DENSITIES    = 0x00008000;
-
-    /**
      * Resolution and querying flag: if set, only filters that support the
      * {@link android.content.Intent#CATEGORY_DEFAULT} will be considered for
      * matching.  This is a synonym for including the CATEGORY_DEFAULT in your
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 93ba959..33f4b52 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -675,6 +675,7 @@
         int supportsNormalScreens = 1;
         int supportsLargeScreens = 1;
         int resizeable = 1;
+        int anyDensity = 1;
         
         int outerDepth = parser.getDepth();
         while ((type=parser.next()) != parser.END_DOCUMENT
@@ -854,21 +855,6 @@
 
                 XmlUtils.skipCurrentTag(parser);
 
-            } else if (tagName.equals("supports-density")) {
-                sa = res.obtainAttributes(attrs,
-                        com.android.internal.R.styleable.AndroidManifestSupportsDensity);
-
-                int density = sa.getInteger(
-                        com.android.internal.R.styleable.AndroidManifestSupportsDensity_density, -1);
-
-                sa.recycle();
-
-                if (density != -1 && !pkg.supportsDensityList.contains(density)) {
-                    pkg.supportsDensityList.add(density);
-                }
-
-                XmlUtils.skipCurrentTag(parser);
-
             } else if (tagName.equals("supports-screens")) {
                 sa = res.obtainAttributes(attrs,
                         com.android.internal.R.styleable.AndroidManifestSupportsScreens);
@@ -887,6 +873,9 @@
                 resizeable = sa.getInteger(
                         com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable,
                         supportsLargeScreens);
+                anyDensity = sa.getInteger(
+                        com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity,
+                        anyDensity);
 
                 sa.recycle();
                 
@@ -962,7 +951,7 @@
         
         if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
                 && pkg.applicationInfo.targetSdkVersion
-                        >= android.os.Build.VERSION_CODES.CUR_DEVELOPMENT)) {
+                        >= android.os.Build.VERSION_CODES.DONUT)) {
             pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
         }
         if (supportsNormalScreens != 0) {
@@ -970,32 +959,19 @@
         }
         if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
                 && pkg.applicationInfo.targetSdkVersion
-                        >= android.os.Build.VERSION_CODES.CUR_DEVELOPMENT)) {
+                        >= android.os.Build.VERSION_CODES.DONUT)) {
             pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
         }
         if (resizeable < 0 || (resizeable > 0
                 && pkg.applicationInfo.targetSdkVersion
-                        >= android.os.Build.VERSION_CODES.CUR_DEVELOPMENT)) {
+                        >= android.os.Build.VERSION_CODES.DONUT)) {
             pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
         }
-        int densities[] = null;
-        int size = pkg.supportsDensityList.size();
-        if (size > 0) {
-            densities = pkg.supportsDensities = new int[size];
-            List<Integer> densityList = pkg.supportsDensityList;
-            for (int i = 0; i < size; i++) {
-                densities[i] = densityList.get(i);
-            }
+        if (anyDensity < 0 || (anyDensity > 0
+                && pkg.applicationInfo.targetSdkVersion
+                        >= android.os.Build.VERSION_CODES.DONUT)) {
+            pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
         }
-        /**
-         * TODO: enable this before code freeze. b/1967935
-         * *
-        if ((densities == null || densities.length == 0)
-                && (pkg.applicationInfo.targetSdkVersion
-                        >= android.os.Build.VERSION_CODES.CUR_DEVELOPMENT)) {
-            pkg.supportsDensities = ApplicationInfo.ANY_DENSITIES_ARRAY;
-        }
-         */
 
         return pkg;
     }
@@ -2446,9 +2422,6 @@
         // We store the application meta-data independently to avoid multiple unwanted references
         public Bundle mAppMetaData = null;
 
-        public final ArrayList<Integer> supportsDensityList = new ArrayList<Integer>();
-        public int[] supportsDensities = null;
-
         // If this is a 3rd party app, this is the path of the zip file.
         public String mPath;
 
@@ -2630,10 +2603,6 @@
                 && p.usesLibraryFiles != null) {
             return true;
         }
-        if ((flags & PackageManager.GET_SUPPORTS_DENSITIES) != 0
-                && p.supportsDensities != null) {
-            return true;
-        }
         return false;
     }
 
@@ -2656,9 +2625,6 @@
         if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
             ai.sharedLibraryFiles = p.usesLibraryFiles;
         }
-        if ((flags & PackageManager.GET_SUPPORTS_DENSITIES) != 0) {
-            ai.supportsDensities = p.supportsDensities;
-        }
         if (!sCompatibilityModeEnabled) {
             ai.disableCompatibilityMode();
         }
diff --git a/core/java/android/content/res/CompatibilityInfo.java b/core/java/android/content/res/CompatibilityInfo.java
index 517551e..e2abfd1 100644
--- a/core/java/android/content/res/CompatibilityInfo.java
+++ b/core/java/android/content/res/CompatibilityInfo.java
@@ -131,41 +131,15 @@
             mCompatibilityFlags |= EXPANDABLE | CONFIGURED_EXPANDABLE;
         }
         
-        float packageDensityScale = -1.0f;
-        int packageDensity = 0;
-        if (appInfo.supportsDensities != null) {
-            int minDiff = Integer.MAX_VALUE;
-            for (int density : appInfo.supportsDensities) {
-                if (density == ApplicationInfo.ANY_DENSITY) {
-                    packageDensity = DisplayMetrics.DENSITY_DEVICE;
-                    packageDensityScale = 1.0f;
-                    break;
-                }
-                int tmpDiff = Math.abs(DisplayMetrics.DENSITY_DEVICE - density);
-                if (tmpDiff == 0) {
-                    packageDensity = DisplayMetrics.DENSITY_DEVICE;
-                    packageDensityScale = 1.0f;
-                    break;
-                }
-                // prefer higher density (appScale>1.0), unless that's only option.
-                if (tmpDiff < minDiff && packageDensityScale < 1.0f) {
-                    packageDensity = density;
-                    packageDensityScale = DisplayMetrics.DENSITY_DEVICE / (float) density;
-                    minDiff = tmpDiff;
-                }
-            }
-        }
-        if (packageDensityScale > 0.0f) {
-            applicationDensity = packageDensity;
-            applicationScale = packageDensityScale;
+        if ((appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) {
+            applicationDensity = DisplayMetrics.DENSITY_DEVICE;
+            applicationScale = 1.0f;
+            applicationInvertedScale = 1.0f;
         } else {
             applicationDensity = DisplayMetrics.DENSITY_DEFAULT;
-            applicationScale =
-                    DisplayMetrics.DENSITY_DEVICE / (float) DisplayMetrics.DENSITY_DEFAULT;
-        }
-
-        applicationInvertedScale = 1.0f / applicationScale;
-        if (applicationScale != 1.0f) {
+            applicationScale = DisplayMetrics.DENSITY_DEVICE
+                    / (float) DisplayMetrics.DENSITY_DEFAULT;
+            applicationInvertedScale = 1.0f / applicationScale;
             mCompatibilityFlags |= SCALING_REQUIRED;
         }
     }
diff --git a/core/java/android/server/search/SearchDialogWrapper.java b/core/java/android/server/search/SearchDialogWrapper.java
index d3ef5de..b8a9875 100644
--- a/core/java/android/server/search/SearchDialogWrapper.java
+++ b/core/java/android/server/search/SearchDialogWrapper.java
@@ -190,6 +190,9 @@
         msgData.putBundle(KEY_APP_SEARCH_DATA, appSearchData);
         msgData.putInt(KEY_IDENT, ident);
         mSearchUiThread.sendMessage(msg);
+        // be a little more eager in setting this so isVisible will return the correct value if
+        // called immediately after startSearch
+        mVisible = true;
     }
 
     /**
@@ -199,6 +202,9 @@
     public void stopSearch() {
         if (DBG) debug("stopSearch()");
         mSearchUiThread.sendEmptyMessage(MSG_STOP_SEARCH);
+        // be a little more eager in setting this so isVisible will return the correct value if
+        // called immediately after stopSearch
+        mVisible = false;
     }
 
     /**
diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java
index bb6b4b0..8f8d976 100755
--- a/core/java/android/speech/tts/TextToSpeech.java
+++ b/core/java/android/speech/tts/TextToSpeech.java
@@ -921,8 +921,10 @@
                 mCachedParams[Engine.TTS_PARAM_POSITION_LANGUAGE + 1] = loc.getISO3Language();
                 mCachedParams[Engine.TTS_PARAM_POSITION_COUNTRY + 1] = loc.getISO3Country();
                 mCachedParams[Engine.TTS_PARAM_POSITION_VARIANT + 1] = loc.getVariant();
-
-                result = mITts.setLanguage(mPackageName,
+                // the language is not set here, instead it is cached so it will be associated
+                // with all upcoming utterances. But we still need to report the language support,
+                // which is achieved by calling isLanguageAvailable()
+                result = mITts.isLanguageAvailable(
                         mCachedParams[Engine.TTS_PARAM_POSITION_LANGUAGE + 1],
                         mCachedParams[Engine.TTS_PARAM_POSITION_COUNTRY + 1],
                         mCachedParams[Engine.TTS_PARAM_POSITION_VARIANT + 1] );
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index 777beed..eea97dc 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -1535,6 +1535,9 @@
     protected void onDetachedFromWindow() {
         super.onDetachedFromWindow();
 
+        // Dismiss the popup in case onSaveInstanceState() was not invoked
+        dismissPopup();
+
         final ViewTreeObserver treeObserver = getViewTreeObserver();
         if (treeObserver != null) {
             treeObserver.removeOnTouchModeChangeListener(this);
diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java
index 4bc00de..47798a4 100644
--- a/core/java/android/widget/AutoCompleteTextView.java
+++ b/core/java/android/widget/AutoCompleteTextView.java
@@ -205,11 +205,10 @@
      * Private hook into the on click event, dispatched from {@link PassThroughClickListener}
      */
     private void onClickImpl() {
-        // if drop down should always visible, bring it back in front of the soft
-        // keyboard when the user touches the text field
-        if (mDropDownAlwaysVisible
-                && mPopup.isShowing()
-                && mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED) {
+        // If the dropdown is showing, bring it back in front of the soft
+        // keyboard when the user touches the text field.
+        if (mPopup.isShowing() &&
+                mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED) {
             ensureImeVisible();
         }
     }
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index 75568e1..48b565f 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -827,28 +827,6 @@
         <attr name="name" />
     </declare-styleable>
     
-    <!-- The <code>supports-density</code> specifies a screen density that this
-         package supports. Application can specify multiple densities it supports.
-         <p>This appears as a child tag of the
-         {@link #AndroidManifest manifest} tag. -->
-    <declare-styleable name="AndroidManifestSupportsDensity" parent="AndroidManifest">
-        <!-- Required value of the density in dip (device independent pixel).
-             You should use one of the pre-defined constants for the standard
-             screen densities defined here.
-        -->
-        <attr name="density" format="integer">
-            <!-- A low density screen, such as a QVGA or WQVGA screen in a
-                 typical hand-held phone.  The constant for this is 120. -->
-            <enum name="low" value="120" />
-            <!-- A medium density screen, such as an HVGA screen in a
-                 typical hand-held phone.  The constant for this is 160. -->
-            <enum name="medium" value="160" />
-            <!-- A high density screen, such as a VGA or WVGA screen in a
-                 typical hand-held phone.  The constant for this is 240. -->
-            <enum name="high" value="240" />
-        </attr>
-    </declare-styleable>
-
     <!-- The <code>supports-screens</code> specifies the screen dimensions an
          application supports.  By default a modern application supports all
          screen sizes and must explicitly disable certain screen sizes here;
@@ -892,6 +870,11 @@
              set for you automatically based on whether you are targeting
              a newer platform that supports more screens. -->
         <attr name="resizeable" format="boolean" />
+        <!-- Indicates whether the application can accommodate any screen
+             density.  Older applications are assumed to not be able to,
+             new ones able to.  You can explicitly supply your abilities
+             here. -->
+        <attr name="anyDensity" 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 919c3d6..6a6b7fc 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1093,7 +1093,7 @@
 
   <public type="attr" name="tension" id="0x0101026a" />
   <public type="attr" name="extraTension" />
-  <public type="attr" name="density" />
+  <public type="attr" name="anyDensity" />
   <public type="attr" name="searchSuggestThreshold" />
   <public type="attr" name="includeInGlobalSearch" />
   <public type="attr" name="onClick" />
diff --git a/docs/html/guide/topics/resources/resources-i18n.jd b/docs/html/guide/topics/resources/resources-i18n.jd
index c26cb63..85b89d1 100755
--- a/docs/html/guide/topics/resources/resources-i18n.jd
+++ b/docs/html/guide/topics/resources/resources-i18n.jd
@@ -465,37 +465,37 @@
     </tr>
     <tr>
       <td>MCC and MNC</td>
-      <td>The mobile country code optionally followed by mobile network code
+      <td><p>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>
+        </p><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>
+        resources can only be used if both the MCC and the MNC match. </p></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
+        <td><p>The two letter <a href="http://www.loc.gov/standards/iso639-2/php/code_list.php">ISO
                 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>fr</code>, <code>en-rUS</code>, <code>fr-rFR</code>, <code>es-rES</code>.
-                <p>
+          </p><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>
+          for example <code>en</code>, <code>fr</code>, <code>es</code>.</p> </td>
     </tr>
     <tr>
         <td>Screen dimensions</td>
-        <td><code>small</code>, <code>normal</code>, <code>large</code>
-        <p>
+        <td><p><code>small</code>, <code>normal</code>, <code>large</code>
+        </p><p>
         Specify that the resource is for a particular class of screen.
         The meanings of these are:</p>
         <ul>
@@ -517,27 +517,27 @@
     </tr>
     <tr>
         <td>Wider/taller screens</td>
-        <td><code>long</code>, <code>notlong</code>
-        <p>
+        <td><p><code>long</code>, <code>notlong</code>
+        </p><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.
+        orientation.</p>
         </td>
     </tr>
     <tr>
         <td>Screen orientation</td>
-        <td><code>port</code>, <code>land</code>, <code>square</code>
-        <p>
+        <td><p><code>port</code>, <code>land</code>, <code>square</code>
+        </p><p>
         Specifies that the resource is for a screen that is tall (port)
-        or wide (land); square is not currently used.
+        or wide (land); square is not currently used.</p>
         </td>
     </tr>
     <tr>
         <td>Screen pixel density</td>
-        <td><code>ldpi</code>, <code>mdpi</code>, <code>hdpi</code>, <code>nodpi</code>
-        <p>
+        <td><p><code>ldpi</code>, <code>mdpi</code>, <code>hdpi</code>, <code>nodpi</code>
+        </p><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
@@ -545,7 +545,7 @@
          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>
+        </p><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
@@ -553,10 +553,11 @@
          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>
+         </p><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.
+         </p>
          </td>
     </tr>
     <tr>
@@ -565,9 +566,9 @@
     </tr>
     <tr>
         <td>Whether the keyboard is available to the user</td>
-        <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>
+        <td><p><code>keysexposed</code>, <code>keyshidden</code>, <code>keyssoft</code>
+        </p><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.</p> </td>
     </tr>
     <tr>
         <td>Primary text input method</td>
diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java
index 376b1df..dc80cf5 100644
--- a/graphics/java/android/graphics/drawable/DrawableContainer.java
+++ b/graphics/java/android/graphics/drawable/DrawableContainer.java
@@ -272,6 +272,8 @@
         boolean     mCheckedConstantState;
         boolean     mCanConstantState;
 
+        boolean     mPaddingChecked = false;
+
         DrawableContainerState(DrawableContainerState orig, DrawableContainer owner) {
             mOwner = owner;
 
@@ -334,6 +336,7 @@
             mHaveStateful = false;
 
             mConstantPadding = null;
+            mPaddingChecked = false;
             mComputedConstantSize = false;
 
             return pos;
@@ -359,23 +362,25 @@
             if (mVariablePadding) {
                 return null;
             }
-            if (mConstantPadding != null) {
+            if (mConstantPadding != null || mPaddingChecked) {
                 return mConstantPadding;
             }
 
-            final Rect r = new Rect(0, 0, 0, 0);
+            Rect r = null;
             final Rect t = new Rect();
             final int N = getChildCount();
             final Drawable[] drawables = mDrawables;
             for (int i = 0; i < N; i++) {
                 if (drawables[i].getPadding(t)) {
+                    if (r == null) r = new Rect(0, 0, 0, 0);
                     if (t.left > r.left) r.left = t.left;
                     if (t.top > r.top) r.top = t.top;
                     if (t.right > r.right) r.right = t.right;
                     if (t.bottom > r.bottom) r.bottom = t.bottom;
                 }
             }
-            return (mConstantPadding=r);
+            mPaddingChecked = true;
+            return (mConstantPadding = r);
         }
 
         public final void setConstantSize(boolean constant) {
diff --git a/opengl/java/android/opengl/Version.java b/opengl/java/android/opengl/Version.java
new file mode 100644
index 0000000..6e89d7e
--- /dev/null
+++ b/opengl/java/android/opengl/Version.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+package android.opengl;
+
+import android.os.SystemProperties;
+
+public final class Version {
+    /**
+     * Return the highest OpenGL ES API level supported by the current device.
+     * <p>
+     * A device that supports a given API level must also support
+     * numerically smaller API levels.
+     * <p>
+     * A device that supports a given API level may not necessarily
+     * support every feature of that API level. API-specific techniques may
+     * be used to determine whether specific features are supported.
+     *
+     * @return the highest OpenGL ES API level supported by the current device.
+     */
+    public static int getOpenGLESVersion() {
+        return SystemProperties.getInt("ro.opengles.version", OPENGLES_11);
+    }
+
+    /**
+     * The version number for OpenGL ES 1.1.
+     */
+    public final static int OPENGLES_11 = 11;
+
+    /**
+     * The version number for OpenGL ES 2.0.
+     */
+    public final static int OPENGLES_20 = 20;
+}
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index ee53274..4afa03e 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -4902,26 +4902,40 @@
                     if (ps.pkg != null) {
                         pw.print("    dataDir="); pw.println(ps.pkg.applicationInfo.dataDir);
                         pw.print("    targetSdk="); pw.println(ps.pkg.applicationInfo.targetSdkVersion);
-                        pw.print("    densities="); pw.println(ps.pkg.supportsDensityList);
-                        ArrayList<String> screens = new ArrayList<String>();
+                        pw.print("    supportsScreens=[");
+                        boolean first = true;
                         if ((ps.pkg.applicationInfo.flags & 
                                 ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0) {
-                            screens.add("medium");
+                            if (!first) pw.print(", ");
+                            first = false;
+                            pw.print("medium");
                         }
                         if ((ps.pkg.applicationInfo.flags & 
                                 ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) {
-                            screens.add("large");
+                            if (!first) pw.print(", ");
+                            first = false;
+                            pw.print("large");
                         }
                         if ((ps.pkg.applicationInfo.flags & 
                                 ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) {
-                            screens.add("small,");
+                            if (!first) pw.print(", ");
+                            first = false;
+                            pw.print("small");
                         }
                         if ((ps.pkg.applicationInfo.flags & 
                                 ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) {
-                            screens.add("resizeable,");
+                            if (!first) pw.print(", ");
+                            first = false;
+                            pw.print("resizeable");
                         }
-                        pw.print("    supportsScreens="); pw.println(screens);
+                        if ((ps.pkg.applicationInfo.flags & 
+                                ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) {
+                            if (!first) pw.print(", ");
+                            first = false;
+                            pw.print("anyDensity");
+                        }
                     }
+                    pw.println("]");
                     pw.print("    timeStamp="); pw.println(ps.getTimeStampStr());
                     pw.print("    signatures="); pw.println(ps.signatures);
                     pw.print("    permissionsFixed="); pw.print(ps.permissionsFixed);
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index b4754b6..394ed3a 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -1075,6 +1075,17 @@
                 break setVariables;
             }
 
+            if ((config.phase2 != null) && !WifiNative.setNetworkVariableCommand(
+                    netId,
+                    WifiConfiguration.phase2VarName,
+                    config.phase2)) {
+                if (DBG) {
+                    Log.d(TAG, config.SSID + ": failed to set phase2: "+
+                          config.phase2);
+                }
+                break setVariables;
+            }
+
             if ((config.identity != null) && !WifiNative.setNetworkVariableCommand(
                     netId,
                     WifiConfiguration.identityVarName,
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index d9c40ec..8e4c897 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -184,8 +184,7 @@
     static final int LOG_BOOT_PROGRESS_ENABLE_SCREEN = 3050;
 
     // The flags that are set for all calls we make to the package manager.
-    static final int STOCK_PM_FLAGS = PackageManager.GET_SHARED_LIBRARY_FILES
-            | PackageManager.GET_SUPPORTS_DENSITIES;
+    static final int STOCK_PM_FLAGS = PackageManager.GET_SHARED_LIBRARY_FILES;
     
     private static final String SYSTEM_SECURE = "ro.secure";
 
diff --git a/tests/CoreTests/android/AndroidManifest.xml b/tests/CoreTests/android/AndroidManifest.xml
index 4809f844..98cc9e5 100644
--- a/tests/CoreTests/android/AndroidManifest.xml
+++ b/tests/CoreTests/android/AndroidManifest.xml
@@ -30,6 +30,7 @@
     <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
     <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
     <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
     
     <application>
         <uses-library android:name="android.test.runner" />
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 49fff57..dd4fae3 100644
--- a/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java
+++ b/tests/DpiTest/src/com/google/android/test/dpi/DpiTestActivity.java
@@ -52,14 +52,13 @@
             // be doing it.
             Application app = ActivityThread.currentActivityThread().getApplication();
             ApplicationInfo ai = app.getPackageManager().getApplicationInfo(
-                    "com.google.android.test.dpi",
-                    PackageManager.GET_SUPPORTS_DENSITIES);
+                    "com.google.android.test.dpi", 0);
             if (noCompat) {
                 ai.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS
                     | ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS
                     | ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS
-                    | ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
-                ai.supportsDensities = new int[] { ApplicationInfo.ANY_DENSITY };
+                    | ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS
+                    | ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
                 app.getResources().setCompatibilityInfo(new CompatibilityInfo(ai));
             }
         } catch (PackageManager.NameNotFoundException e) {
diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java
index eda2f2d..f85aadd 100644
--- a/wifi/java/android/net/wifi/WifiConfiguration.java
+++ b/wifi/java/android/net/wifi/WifiConfiguration.java
@@ -45,6 +45,8 @@
     /** {@hide} */
     public static final String eapVarName = "eap";
     /** {@hide} */
+    public static final String phase2VarName = "phase2";
+    /** {@hide} */
     public static final String identityVarName = "identity";
     /** {@hide} */
     public static final String anonymousIdentityVarName = "anonymous_identity";
@@ -273,6 +275,11 @@
      */
     public String eap;
     /**
+     * The phase2 authenication could be PAP, MSCHAP, MSCHAP2, GTC.
+     * {@hide}
+     */
+    public String phase2;
+    /**
      * The identity of the user in string,
      * which is used for the authentication.
      * {@hide}
@@ -314,6 +321,7 @@
         for (int i = 0; i < wepKeys.length; i++)
             wepKeys[i] = null;
         eap = null;
+        phase2 = null;
         identity = null;
         anonymousIdentity = null;
         password = null;
@@ -399,6 +407,10 @@
         if (this.eap != null) {
             sbuf.append(eap);
         }
+        sbuf.append('\n').append(" phase2: ");
+        if (this.phase2 != null) {
+            sbuf.append(phase2);
+        }
         sbuf.append('\n').append(" Identity: ");
         if (this.identity != null) {
             sbuf.append(identity);
@@ -486,6 +498,7 @@
         writeBitSet(dest, allowedPairwiseCiphers);
         writeBitSet(dest, allowedGroupCiphers);
         dest.writeString(eap);
+        dest.writeString(phase2);
         dest.writeString(identity);
         dest.writeString(anonymousIdentity);
         dest.writeString(password);
@@ -516,6 +529,7 @@
                 config.allowedPairwiseCiphers = readBitSet(in);
                 config.allowedGroupCiphers    = readBitSet(in);
                 config.eap = in.readString();
+                config.phase2 = in.readString();
                 config.identity = in.readString();
                 config.anonymousIdentity = in.readString();
                 config.password = in.readString();