Merge "Fix issue 5090721: audio record broken"
diff --git a/api/current.txt b/api/current.txt
index ac40096..a9c3ca0 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -198,6 +198,7 @@
     field public static final int actionBarTabBarStyle = 16843508; // 0x10102f4
     field public static final int actionBarTabStyle = 16843507; // 0x10102f3
     field public static final int actionBarTabTextStyle = 16843509; // 0x10102f5
+    field public static final int actionBarWidgetTheme = 16843683; // 0x10103a3
     field public static final int actionButtonStyle = 16843480; // 0x10102d8
     field public static final int actionDropDownStyle = 16843479; // 0x10102d7
     field public static final int actionLayout = 16843515; // 0x10102fb
@@ -2243,6 +2244,7 @@
     method public abstract java.lang.CharSequence getSubtitle();
     method public abstract android.app.ActionBar.Tab getTabAt(int);
     method public abstract int getTabCount();
+    method public android.content.Context getThemedContext();
     method public abstract java.lang.CharSequence getTitle();
     method public abstract void hide();
     method public abstract boolean isShowing();
@@ -2263,7 +2265,7 @@
     method public abstract void setDisplayShowHomeEnabled(boolean);
     method public abstract void setDisplayShowTitleEnabled(boolean);
     method public abstract void setDisplayUseLogoEnabled(boolean);
-    method public abstract void setHomeButtonEnabled(boolean);
+    method public void setHomeButtonEnabled(boolean);
     method public abstract void setIcon(int);
     method public abstract void setIcon(android.graphics.drawable.Drawable);
     method public abstract void setListNavigationCallbacks(android.widget.SpinnerAdapter, android.app.ActionBar.OnNavigationListener);
diff --git a/core/java/android/app/ActionBar.java b/core/java/android/app/ActionBar.java
index a217867..7acaec8 100644
--- a/core/java/android/app/ActionBar.java
+++ b/core/java/android/app/ActionBar.java
@@ -627,7 +627,18 @@
      *
      * @param enabled true to enable the home button, false to disable the home button.
      */
-    public abstract void setHomeButtonEnabled(boolean enabled);
+    public void setHomeButtonEnabled(boolean enabled) { }
+
+    /**
+     * Returns a {@link Context} with an appropriate theme for creating views that
+     * will appear in the action bar. If you are inflating or instantiating custom views
+     * that will appear in an action bar, you should use the Context returned by this method.
+     * (This includes adapters used for list navigation mode.)
+     * This will ensure that views contrast properly against the action bar.
+     *
+     * @return A themed Context for creating views
+     */
+    public Context getThemedContext() { return null; }
 
     /**
      * Listener interface for ActionBar navigation events.
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 8d03ac7..c6c4025 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -32,6 +32,7 @@
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
+import android.content.res.Resources.Theme;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
@@ -54,6 +55,7 @@
 import android.util.EventLog;
 import android.util.Log;
 import android.util.SparseArray;
+import android.util.TypedValue;
 import android.view.ActionMode;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
@@ -672,6 +674,7 @@
     /*package*/ int mConfigChangeFlags;
     /*package*/ Configuration mCurrentConfig;
     private SearchManager mSearchManager;
+    private MenuInflater mMenuInflater;
 
     static final class NonConfigurationInstances {
         Object activity;
@@ -3083,7 +3086,16 @@
      * Returns a {@link MenuInflater} with this context.
      */
     public MenuInflater getMenuInflater() {
-        return new MenuInflater(this);
+        // Make sure that action views can get an appropriate theme.
+        if (mMenuInflater == null) {
+            initActionBar();
+            if (mActionBar != null) {
+                mMenuInflater = new MenuInflater(mActionBar.getThemedContext());
+            } else {
+                mMenuInflater = new MenuInflater(this);
+            }
+        }
+        return mMenuInflater;
     }
 
     @Override
diff --git a/core/java/android/preference/TwoStatePreference.java b/core/java/android/preference/TwoStatePreference.java
index 55ef108..b6f00ad 100644
--- a/core/java/android/preference/TwoStatePreference.java
+++ b/core/java/android/preference/TwoStatePreference.java
@@ -202,7 +202,8 @@
                 && view.isEnabled()) {
             mSendAccessibilityEventViewClickedType = false;
             if (mSendAccessibilityEventTypeViewClicked == null) {
-                mSendAccessibilityEventTypeViewClicked = new SendAccessibilityEventTypeViewClicked();
+                mSendAccessibilityEventTypeViewClicked =
+                    new SendAccessibilityEventTypeViewClicked();
             }
             mSendAccessibilityEventTypeViewClicked.mView = view;
             view.post(mSendAccessibilityEventTypeViewClicked);
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index b6bb3cf..157df8d 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -3964,6 +3964,7 @@
             ACCESSIBILITY_SCRIPT_INJECTION,
             BACKUP_AUTO_RESTORE,
             ENABLED_ACCESSIBILITY_SERVICES,
+            TOUCH_EXPLORATION_ENABLED,
             TTS_USE_DEFAULTS,
             TTS_DEFAULT_RATE,
             TTS_DEFAULT_PITCH,
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index 95f1f98..7684bc5 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -35,10 +35,13 @@
 import android.app.FragmentTransaction;
 import android.content.Context;
 import android.content.res.Configuration;
+import android.content.res.Resources;
 import android.graphics.drawable.Drawable;
 import android.os.Build;
 import android.os.Handler;
+import android.util.TypedValue;
 import android.view.ActionMode;
+import android.view.ContextThemeWrapper;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
@@ -61,6 +64,7 @@
     private static final String TAG = "ActionBarImpl";
 
     private Context mContext;
+    private Context mThemedContext;
     private Activity mActivity;
     private Dialog mDialog;
 
@@ -605,6 +609,23 @@
         }
     }
 
+    public Context getThemedContext() {
+        if (mThemedContext == null) {
+            TypedValue outValue = new TypedValue();
+            Resources.Theme currentTheme = mContext.getTheme();
+            currentTheme.resolveAttribute(com.android.internal.R.attr.actionBarWidgetTheme,
+                    outValue, true);
+            final int targetThemeRes = outValue.resourceId;
+            
+            if (targetThemeRes != 0 && mContext.getThemeResId() != targetThemeRes) {
+                mThemedContext = new ContextThemeWrapper(mContext, targetThemeRes);
+            } else {
+                mThemedContext = mContext;
+            }
+        }
+        return mThemedContext;
+    }
+    
     /**
      * @hide 
      */
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index f6bf76b..f80f27d 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -616,6 +616,14 @@
              buttons. actionBarStyle is still used for the primary
              bar. -->
         <attr name="actionBarSplitStyle" format="reference" />
+        <!-- Reference to a theme that should be used to inflate widgets
+             and layouts destined for the action bar. Most of the time
+             this will be a reference to the current theme, but when
+             the action bar has a significantly different contrast
+             profile than the rest of the activity the difference
+             can become important. If this is set to @null the current
+             theme will be used.-->
+        <attr name="actionBarWidgetTheme" format="reference" />
         <!-- Size of the Action Bar, including the contextual
              bar used to present Action Modes. -->
         <attr name="actionBarSize" format="dimension" >
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 49c9447..0555d10 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1781,6 +1781,11 @@
 
   <public type="attr" name="actionModeStyle" />
 
+  <public type="attr" name="minResizeWidth" />
+  <public type="attr" name="minResizeHeight" />
+
+  <public type="attr" name="actionBarWidgetTheme" />
+
   <public type="style" name="TextAppearance.SuggestionHighlight" />
   <public type="style" name="Theme.Holo.SplitActionBarWhenNarrow" />
   <public type="style" name="Theme.Holo.Light.SplitActionBarWhenNarrow" />
@@ -1819,7 +1824,4 @@
   <public type="color" name="holo_orange_dark" />
   <public type="color" name="holo_purple" />
   <public type="color" name="holo_blue_bright" />
-
-  <public type="attr" name="minResizeWidth" />
-  <public type="attr" name="minResizeHeight" />
 </resources>
diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml
index 8d66b93..3e7c5ca 100644
--- a/core/res/res/values/themes.xml
+++ b/core/res/res/values/themes.xml
@@ -290,6 +290,7 @@
         <item name="actionModePopupWindowStyle">?android:attr/popupWindowStyle</item>
         <item name="actionMenuTextAppearance">@android:style/TextAppearance.Holo.Widget.ActionBar.Menu</item>
         <item name="actionMenuTextColor">?android:attr/textColorPrimary</item>
+        <item name="actionBarWidgetTheme">@null</item>
 
         <item name="dividerVertical">@drawable/divider_vertical_dark</item>
         <item name="dividerHorizontal">@drawable/divider_vertical_dark</item>
@@ -1042,6 +1043,7 @@
         <item name="actionBarStyle">@android:style/Widget.Holo.ActionBar</item>
         <item name="actionBarSize">@dimen/action_bar_default_height</item>
         <item name="actionModePopupWindowStyle">@android:style/Widget.Holo.PopupWindow.ActionMode</item>
+        <item name="actionBarWidgetTheme">@null</item>
 
         <item name="actionModeCutDrawable">@android:drawable/ic_menu_cut_holo_dark</item>
         <item name="actionModeCopyDrawable">@android:drawable/ic_menu_copy_holo_dark</item>
@@ -1338,6 +1340,7 @@
         <item name="actionBarStyle">@android:style/Widget.Holo.Light.ActionBar</item>
         <item name="actionBarSize">@dimen/action_bar_default_height</item>
         <item name="actionModePopupWindowStyle">@android:style/Widget.Holo.Light.PopupWindow.ActionMode</item>
+        <item name="actionBarWidgetTheme">@null</item>
 
         <item name="actionModeCutDrawable">@android:drawable/ic_menu_cut_holo_light</item>
         <item name="actionModeCopyDrawable">@android:drawable/ic_menu_copy_holo_light</item>
@@ -1399,6 +1402,7 @@
     <style name="Theme.Holo.Light.SolidActionBar.Inverse">
         <item name="android:windowContentOverlay">@android:drawable/title_bar_shadow</item>
         <item name="android:actionBarStyle">@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse</item>
+        <item name="actionBarWidgetTheme">@android:style/Theme.Holo</item>
 
         <item name="actionDropDownStyle">@android:style/Widget.Holo.Spinner.DropDown.ActionBar</item>
         <item name="actionButtonStyle">@android:style/Widget.Holo.ActionButton</item>
diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml
index b349030..c61da4e 100644
--- a/packages/SettingsProvider/res/values/defaults.xml
+++ b/packages/SettingsProvider/res/values/defaults.xml
@@ -112,6 +112,9 @@
             0x200000038=0x03000701:0x03010701:0x03020701;
     </string>
 
+    <!-- Default for Settings.Secure.TOUCH_EXPLORATION_ENABLED -->
+    <bool name="def_touch_exploration_enabled">false</bool>
+
     <!-- Default for Settings.System.USER_ROTATION -->
     <integer name="def_user_rotation">0</integer>
 
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
index a5022e9..ad84112 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -891,6 +891,25 @@
              upgradeVersion = 67;
          }
 
+        if (upgradeVersion == 67) {
+            // New setting to enable touch exploration.
+            db.beginTransaction();
+            SQLiteStatement stmt = null;
+            try {
+                stmt = db.compileStatement("INSERT INTO secure(name,value)"
+                        + " VALUES(?,?);");
+                loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
+                        R.bool.def_touch_exploration_enabled);
+                stmt.close();
+                db.setTransactionSuccessful();
+            } finally {
+                db.endTransaction();
+                if (stmt != null) stmt.close();
+            }
+            upgradeVersion = 68;
+        }
+
+
         // *** Remember to update DATABASE_VERSION above!
 
         if (upgradeVersion != currentVersion) {
@@ -1427,6 +1446,9 @@
 
             loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT,
                     R.integer.def_long_press_timeout_millis);
+
+            loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED,
+                    R.bool.def_touch_exploration_enabled);
         } finally {
             if (stmt != null) stmt.close();
         }
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
index e988b68..c896046 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
@@ -45,6 +45,7 @@
 import android.util.AttributeSet;
 import android.util.DisplayMetrics;
 import android.util.Log;
+import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.MenuItem;
 import android.view.MotionEvent;
@@ -53,7 +54,6 @@
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.BaseAdapter;
-import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.PopupMenu;
 import android.widget.RelativeLayout;
@@ -182,6 +182,15 @@
         }
     }
 
+    @Override
+    public boolean onKeyUp(int keyCode, KeyEvent event) {
+        if (keyCode == KeyEvent.KEYCODE_BACK && !event.isCanceled()) {
+            show(false, true);
+            return true;
+        }
+        return super.onKeyUp(keyCode, event);
+    }
+
     public boolean isInContentArea(int x, int y) {
         // use mRecentsContainer's exact bounds to determine horizontal position
         final int l = mRecentsContainer.getLeft();
@@ -220,6 +229,11 @@
             setVisibility(show ? View.VISIBLE : View.GONE);
             mChoreo.jumpTo(show);
         }
+        if (show) {
+            setFocusable(true);
+            setFocusableInTouchMode(true);
+            requestFocus();
+        }
     }
 
     public void onAnimationCancel(Animator animation) {
diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java
index ce45998..ae8b89d 100644
--- a/services/java/com/android/server/connectivity/Tethering.java
+++ b/services/java/com/android/server/connectivity/Tethering.java
@@ -377,7 +377,8 @@
             }
         }
         Intent broadcast = new Intent(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
-        broadcast.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
+        broadcast.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
+                Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
         broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_AVAILABLE_TETHER,
                 availableList);
         broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ACTIVE_TETHER, activeList);
diff --git a/services/java/com/android/server/location/GpsLocationProvider.java b/services/java/com/android/server/location/GpsLocationProvider.java
index c813d37..5159b7a 100755
--- a/services/java/com/android/server/location/GpsLocationProvider.java
+++ b/services/java/com/android/server/location/GpsLocationProvider.java
@@ -495,7 +495,12 @@
         if (info != null && info.getType() == ConnectivityManager.TYPE_MOBILE_SUPL
                 && mAGpsDataConnectionState == AGPS_DATA_CONNECTION_OPENING) {
             String apnName = info.getExtraInfo();
-            if (mNetworkAvailable && apnName != null && apnName.length() > 0) {
+            if (mNetworkAvailable) {
+                if (apnName == null) {
+                    /* Assign a dummy value in the case of C2K as otherwise we will have a runtime 
+                    exception in the following call to native_agps_data_conn_open*/
+                    apnName = "dummy-apn";
+                }
                 mAGpsApn = apnName;
                 if (DEBUG) Log.d(TAG, "call native_agps_data_conn_open");
                 native_agps_data_conn_open(apnName);
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java
index 41e44cb..f8c32dd 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java
@@ -159,7 +159,7 @@
         // Expose window.gc function to JavaScript. JSC build exposes
         // this function by default, but V8 requires the flag to turn it on.
         // WebView::setJsFlags is noop in JSC build.
-        mWebView.setJsFlags("--expose_gc --crankshaft=false");
+        mWebView.setJsFlags("--expose_gc");
 
         mHandler = new AsyncHandler();