Merge "Fix issue #5155678: Portrait > Landscape full-screen transition..."
diff --git a/api/current.txt b/api/current.txt
index 5efa32f..0b6c245 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -11369,13 +11369,13 @@
     method public static boolean isEffectSupported(java.lang.String);
     field public static final java.lang.String EFFECT_AUTOFIX = "android.media.effect.effects.AutoFixEffect";
     field public static final java.lang.String EFFECT_BACKDROPPER = "android.media.effect.effects.BackDropperEffect";
+    field public static final java.lang.String EFFECT_BITMAPOVERLAY = "android.media.effect.effects.BitmapOverlayEffect";
     field public static final java.lang.String EFFECT_BLACKWHITE = "android.media.effect.effects.BlackWhiteEffect";
     field public static final java.lang.String EFFECT_BRIGHTNESS = "android.media.effect.effects.BrightnessEffect";
     field public static final java.lang.String EFFECT_CONTRAST = "android.media.effect.effects.ContrastEffect";
     field public static final java.lang.String EFFECT_CROP = "android.media.effect.effects.CropEffect";
     field public static final java.lang.String EFFECT_CROSSPROCESS = "android.media.effect.effects.CrossProcessEffect";
     field public static final java.lang.String EFFECT_DOCUMENTARY = "android.media.effect.effects.DocumentaryEffect";
-    field public static final java.lang.String EFFECT_DOODLE = "android.media.effect.effects.DoodleEffect";
     field public static final java.lang.String EFFECT_DUOTONE = "android.media.effect.effects.DuotoneEffect";
     field public static final java.lang.String EFFECT_FILLLIGHT = "android.media.effect.effects.FillLightEffect";
     field public static final java.lang.String EFFECT_FISHEYE = "android.media.effect.effects.FisheyeEffect";
diff --git a/core/java/android/hardware/SensorManager.java b/core/java/android/hardware/SensorManager.java
index 2111cce..aeb5d92 100644
--- a/core/java/android/hardware/SensorManager.java
+++ b/core/java/android/hardware/SensorManager.java
@@ -1090,7 +1090,7 @@
                 delay = 20000;
                 break;
             case SENSOR_DELAY_UI:
-                delay = 60000;
+                delay = 66667;
                 break;
             case SENSOR_DELAY_NORMAL:
                 delay = 200000;
diff --git a/core/java/android/inputmethodservice/ExtractEditLayout.java b/core/java/android/inputmethodservice/ExtractEditLayout.java
index 25c0c99..220214b 100644
--- a/core/java/android/inputmethodservice/ExtractEditLayout.java
+++ b/core/java/android/inputmethodservice/ExtractEditLayout.java
@@ -16,6 +16,9 @@
 
 package android.inputmethodservice;
 
+import com.android.internal.view.menu.MenuBuilder;
+import com.android.internal.view.menu.MenuPopupHelper;
+
 import android.content.Context;
 import android.util.AttributeSet;
 import android.view.ActionMode;
@@ -23,12 +26,10 @@
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
+import android.view.accessibility.AccessibilityEvent;
 import android.widget.Button;
 import android.widget.LinearLayout;
 
-import com.android.internal.view.menu.MenuBuilder;
-import com.android.internal.view.menu.MenuPopupHelper;
-
 /**
  * ExtractEditLayout provides an ActionMode presentation for the
  * limited screen real estate in extract mode.
@@ -56,6 +57,7 @@
             mExtractActionButton.setVisibility(INVISIBLE);
             mEditButton.setVisibility(VISIBLE);
             mActionMode = mode;
+            sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
             return mode;
         }
         return null;
@@ -158,6 +160,8 @@
             mExtractActionButton.setVisibility(VISIBLE);
             mEditButton.setVisibility(INVISIBLE);
 
+            sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
+
             mActionMode = null;
         }
 
diff --git a/core/java/android/widget/TimePicker.java b/core/java/android/widget/TimePicker.java
index 7865d50..7444d46 100644
--- a/core/java/android/widget/TimePicker.java
+++ b/core/java/android/widget/TimePicker.java
@@ -218,9 +218,9 @@
                     updateAmPmControl();
                 }
             });
+            EditText amPmInput = (EditText) mAmPmSpinner.findViewById(R.id.numberpicker_input);
+            amPmInput.setImeOptions(EditorInfo.IME_ACTION_DONE);
         }
-        EditText amPmInput = (EditText) mAmPmSpinner.findViewById(R.id.numberpicker_input);
-        amPmInput.setImeOptions(EditorInfo.IME_ACTION_DONE);
 
         // update controls to initial state
         updateHourControl();
@@ -519,9 +519,11 @@
         text = mContext.getString(R.string.time_picker_decrement_hour_button);
         mHourSpinner.findViewById(R.id.decrement).setContentDescription(text);
         // AM/PM
-        text = mContext.getString(R.string.time_picker_increment_set_pm_button);
-        mAmPmSpinner.findViewById(R.id.increment).setContentDescription(text);
-        text = mContext.getString(R.string.time_picker_decrement_set_am_button);
-        mAmPmSpinner.findViewById(R.id.decrement).setContentDescription(text);
+        if (mAmPmSpinner != null) {
+            text = mContext.getString(R.string.time_picker_increment_set_pm_button);
+            mAmPmSpinner.findViewById(R.id.increment).setContentDescription(text);
+            text = mContext.getString(R.string.time_picker_decrement_set_am_button);
+            mAmPmSpinner.findViewById(R.id.decrement).setContentDescription(text);
+        }
     }
 }
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index ccca22e..afb5bf1 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -48,6 +48,7 @@
 import android.view.MenuItem;
 import android.view.View;
 import android.view.Window;
+import android.view.accessibility.AccessibilityEvent;
 import android.widget.SpinnerAdapter;
 
 import java.lang.ref.WeakReference;
@@ -397,6 +398,7 @@
                 // TODO animate this
                 mSplitView.setVisibility(View.VISIBLE);
             }
+            mContextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
             mActionMode = mode;
             return mode;
         }
@@ -681,6 +683,7 @@
 
             // Clear out the context mode views after the animation finishes
             mContextView.closeMode();
+            mActionView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
 
             mActionMode = null;
 
diff --git a/core/java/com/android/internal/view/StandaloneActionMode.java b/core/java/com/android/internal/view/StandaloneActionMode.java
index b54daba..ecda47e 100644
--- a/core/java/com/android/internal/view/StandaloneActionMode.java
+++ b/core/java/com/android/internal/view/StandaloneActionMode.java
@@ -26,6 +26,7 @@
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
+import android.view.accessibility.AccessibilityEvent;
 
 import java.lang.ref.WeakReference;
 
@@ -86,6 +87,7 @@
         }
         mFinished = true;
 
+        mContextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
         mCallback.onDestroyActionMode(this);
     }
 
diff --git a/core/java/com/android/internal/widget/ActionBarContextView.java b/core/java/com/android/internal/widget/ActionBarContextView.java
index a631380..7bc33c7 100644
--- a/core/java/com/android/internal/widget/ActionBarContextView.java
+++ b/core/java/com/android/internal/widget/ActionBarContextView.java
@@ -34,6 +34,7 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.accessibility.AccessibilityEvent;
 import android.view.animation.DecelerateInterpolator;
 import android.widget.LinearLayout;
 import android.widget.TextView;
@@ -455,4 +456,17 @@
     public boolean shouldDelayChildPressedState() {
         return false;
     }
+
+    @Override
+    public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
+        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
+            // Action mode started
+            event.setSource(this);
+            event.setClassName(getClass().getName());
+            event.setPackageName(getContext().getPackageName());
+            event.setContentDescription(mTitle);
+        } else {
+            super.onInitializeAccessibilityEvent(event);
+        }
+    }
 }
diff --git a/core/res/res/drawable-hdpi/ic_contact_picture.png b/core/res/res/drawable-hdpi/ic_contact_picture.png
index 9123c8c..2eef7b5 100644
--- a/core/res/res/drawable-hdpi/ic_contact_picture.png
+++ b/core/res/res/drawable-hdpi/ic_contact_picture.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_contact_picture.png b/core/res/res/drawable-mdpi/ic_contact_picture.png
index 535a772..6c7cb61 100644
--- a/core/res/res/drawable-mdpi/ic_contact_picture.png
+++ b/core/res/res/drawable-mdpi/ic_contact_picture.png
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_contact_picture.png b/core/res/res/drawable-xhdpi/ic_contact_picture.png
index 4ade625..1a2bfde 100644
--- a/core/res/res/drawable-xhdpi/ic_contact_picture.png
+++ b/core/res/res/drawable-xhdpi/ic_contact_picture.png
Binary files differ
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index eeff473..6e72fd7 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -2485,7 +2485,10 @@
     <string name="textSelectionCABTitle">Text selection</string>
 
     <!-- Option to add the current misspelled word to the user dictionary. [CHAR LIMIT=25] -->
-    <string name="addToDictionary">+ add to dictionary</string>
+    <string name="addToDictionary">add to dictionary</string>
+
+    <!-- Option to delete the highlighted part of the text from the suggestion popup. [CHAR LIMIT=25] -->
+    <string name="deleteText">delete</string>
 
     <!-- EditText context menu -->
     <string name="inputMethod">Input method</string>
diff --git a/include/media/stagefright/OMXCodec.h b/include/media/stagefright/OMXCodec.h
index 2932744..8baf5ec 100644
--- a/include/media/stagefright/OMXCodec.h
+++ b/include/media/stagefright/OMXCodec.h
@@ -303,7 +303,7 @@
     bool flushPortAsync(OMX_U32 portIndex);
 
     void disablePortAsync(OMX_U32 portIndex);
-    void enablePortAsync(OMX_U32 portIndex);
+    status_t enablePortAsync(OMX_U32 portIndex);
 
     static size_t countBuffersWeOwn(const Vector<BufferInfo> &buffers);
     static bool isIntermediateState(State state);
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index 9ab470b..6280f51 100755
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -2452,13 +2452,16 @@
                     mOutputPortSettingsHaveChanged = formatChanged;
                 }
 
-                enablePortAsync(portIndex);
-
-                status_t err = allocateBuffersOnPort(portIndex);
-
+                status_t err = enablePortAsync(portIndex);
                 if (err != OK) {
-                    CODEC_LOGE("allocateBuffersOnPort failed (err = %d)", err);
+                    CODEC_LOGE("enablePortAsync(%ld) failed (err = %d)", portIndex, err);
                     setState(ERROR);
+                } else {
+                    err = allocateBuffersOnPort(portIndex);
+                    if (err != OK) {
+                        CODEC_LOGE("allocateBuffersOnPort failed (err = %d)", err);
+                        setState(ERROR);
+                    }
                 }
             }
             break;
@@ -2773,16 +2776,14 @@
     freeBuffersOnPort(portIndex, true);
 }
 
-void OMXCodec::enablePortAsync(OMX_U32 portIndex) {
+status_t OMXCodec::enablePortAsync(OMX_U32 portIndex) {
     CHECK(mState == EXECUTING || mState == RECONFIGURING);
 
     CHECK_EQ((int)mPortStatus[portIndex], (int)DISABLED);
     mPortStatus[portIndex] = ENABLING;
 
     CODEC_LOGV("sending OMX_CommandPortEnable(%ld)", portIndex);
-    status_t err =
-        mOMX->sendCommand(mNode, OMX_CommandPortEnable, portIndex);
-    CHECK_EQ(err, (status_t)OK);
+    return mOMX->sendCommand(mNode, OMX_CommandPortEnable, portIndex);
 }
 
 void OMXCodec::fillOutputBuffers() {
diff --git a/opengl/include/EGL/eglext.h b/opengl/include/EGL/eglext.h
index 6a199db..a08932a 100644
--- a/opengl/include/EGL/eglext.h
+++ b/opengl/include/EGL/eglext.h
@@ -242,6 +242,20 @@
 #define EGL_RECORDABLE_ANDROID                  0x3142  /* EGLConfig attribute */
 #endif
 
+/* EGL_NV_system_time
+ */
+#ifndef EGL_NV_system_time
+#define EGL_NV_system_time 1
+typedef khronos_int64_t EGLint64NV;
+typedef khronos_uint64_t EGLuint64NV;
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeFrequencyNV(void);
+EGLAPI EGLuint64NV EGLAPIENTRY eglGetSystemTimeNV(void);
+#endif
+typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMEFREQUENCYNVPROC)(void);
+typedef EGLuint64NV (EGLAPIENTRYP PFNEGLGETSYSTEMTIMENVPROC)(void);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp
index 7e85230..23f67d5 100644
--- a/opengl/libs/EGL/eglApi.cpp
+++ b/opengl/libs/EGL/eglApi.cpp
@@ -62,6 +62,7 @@
         "EGL_KHR_fence_sync "
         "EGL_ANDROID_image_native_buffer "
         "EGL_ANDROID_swap_rectangle "
+        "EGL_NV_system_time "
         ;
 
 struct extention_map_t {
@@ -80,6 +81,10 @@
             (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR },
     { "eglSetSwapRectangleANDROID",
             (__eglMustCastToProperFunctionPointerType)&eglSetSwapRectangleANDROID },
+    { "eglGetSystemTimeFrequencyNV",
+            (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV },
+    { "eglGetSystemTimeNV",
+            (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV },
 };
 
 // accesses protected by sExtensionMapMutex
@@ -1454,3 +1459,46 @@
     }
     return setError(EGL_BAD_DISPLAY, NULL);
 }
+
+// ----------------------------------------------------------------------------
+// NVIDIA extensions
+// ----------------------------------------------------------------------------
+EGLuint64NV eglGetSystemTimeFrequencyNV()
+{
+    clearError();
+
+    if (egl_init_drivers() == EGL_FALSE) {
+        return setError(EGL_BAD_PARAMETER, EGL_FALSE);
+    }
+
+    EGLuint64NV ret = 0;
+    egl_connection_t* const cnx = &gEGLImpl[IMPL_HARDWARE];
+
+    if (cnx->dso) {
+        if (cnx->egl.eglGetSystemTimeFrequencyNV) {
+            return cnx->egl.eglGetSystemTimeFrequencyNV();
+        }
+    }
+
+    return setError(EGL_BAD_DISPLAY, 0);;
+}
+
+EGLuint64NV eglGetSystemTimeNV()
+{
+    clearError();
+
+    if (egl_init_drivers() == EGL_FALSE) {
+        return setError(EGL_BAD_PARAMETER, EGL_FALSE);
+    }
+
+    EGLuint64NV ret = 0;
+    egl_connection_t* const cnx = &gEGLImpl[IMPL_HARDWARE];
+
+    if (cnx->dso) {
+        if (cnx->egl.eglGetSystemTimeNV) {
+            return cnx->egl.eglGetSystemTimeNV();
+        }
+    }
+
+    return setError(EGL_BAD_DISPLAY, 0);;
+}
diff --git a/opengl/libs/EGL/egl_entries.in b/opengl/libs/EGL/egl_entries.in
index 63c3c19..bdd2a7e 100644
--- a/opengl/libs/EGL/egl_entries.in
+++ b/opengl/libs/EGL/egl_entries.in
@@ -62,3 +62,8 @@
 
 EGL_ENTRY(EGLBoolean, eglSetSwapRectangleANDROID, EGLDisplay, EGLSurface, EGLint, EGLint, EGLint, EGLint)
 EGL_ENTRY(EGLClientBuffer, eglGetRenderBufferANDROID, EGLDisplay, EGLSurface)
+
+/* NVIDIA extensions */
+
+EGL_ENTRY(EGLuint64NV, eglGetSystemTimeFrequencyNV, void)
+EGL_ENTRY(EGLuint64NV, eglGetSystemTimeNV, void)
diff --git a/packages/BackupRestoreConfirmation/res/values/strings.xml b/packages/BackupRestoreConfirmation/res/values/strings.xml
index e207a98..e91c6e2 100644
--- a/packages/BackupRestoreConfirmation/res/values/strings.xml
+++ b/packages/BackupRestoreConfirmation/res/values/strings.xml
@@ -43,4 +43,15 @@
 
     <!-- Text for message to user when performing a full restore operation, explaining that they must enter the password originally used to encrypt the full backup data. -->
     <string name="restore_enc_password_text">If the restore data is encrypted, please enter the password below:</string>
+
+    <!-- Text of a toast telling the user that a full backup operation has begun -->
+    <string name="toast_backup_started">Backup starting...</string>
+    <!-- Text of a toast telling the user that a full backup operation has ended -->
+    <string name="toast_backup_ended">Backup finished</string>
+    <!-- Text of a toast telling the user that a full restore operation has begun -->
+    <string name="toast_restore_started">Restore starting...</string>
+    <!-- Text of a toast telling the user that a full restore operation has ended -->
+    <string name="toast_restore_ended">Restore ended</string>
+    <!-- Text of a toast telling the user that the operation has timed out -->
+    <string name="toast_timeout">Operation timed out</string>
 </resources>
diff --git a/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java b/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java
index d053f29..fbdf3cc 100644
--- a/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java
+++ b/packages/BackupRestoreConfirmation/src/com/android/backupconfirm/BackupRestoreConfirmation.java
@@ -82,7 +82,7 @@
         public void handleMessage(Message msg) {
             switch (msg.what) {
                 case MSG_START_BACKUP: {
-                    Toast.makeText(mContext, "!!! Backup starting !!!", Toast.LENGTH_LONG).show();
+                    Toast.makeText(mContext, R.string.toast_backup_started, Toast.LENGTH_LONG).show();
                 }
                 break;
 
@@ -93,13 +93,13 @@
                 break;
 
                 case MSG_END_BACKUP: {
-                    Toast.makeText(mContext, "!!! Backup ended !!!", Toast.LENGTH_SHORT).show();
+                    Toast.makeText(mContext, R.string.toast_backup_ended, Toast.LENGTH_LONG).show();
                     finish();
                 }
                 break;
 
                 case MSG_START_RESTORE: {
-                    Toast.makeText(mContext, "!!! Restore starting !!!", Toast.LENGTH_LONG).show();
+                    Toast.makeText(mContext, R.string.toast_restore_started, Toast.LENGTH_LONG).show();
                 }
                 break;
 
@@ -110,13 +110,13 @@
                 break;
 
                 case MSG_END_RESTORE: {
-                    Toast.makeText(mContext, "!!! Restore ended !!!", Toast.LENGTH_SHORT).show();
+                    Toast.makeText(mContext, R.string.toast_restore_ended, Toast.LENGTH_SHORT).show();
                     finish();
                 }
                 break;
 
                 case MSG_TIMEOUT: {
-                    Toast.makeText(mContext, "!!! TIMED OUT !!!", Toast.LENGTH_LONG).show();
+                    Toast.makeText(mContext, R.string.toast_timeout, Toast.LENGTH_LONG).show();
                 }
                 break;
             }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
index cd361ad..610edfa 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
@@ -42,7 +42,7 @@
 
 public class NavigationBarView extends LinearLayout {
     final static boolean DEBUG = false;
-    final static String TAG = "NavigationBarView";
+    final static String TAG = "PhoneStatusBar/NavigationBarView";
 
     final static boolean DEBUG_DEADZONE = false;
 
@@ -60,6 +60,7 @@
     boolean mVertical;
 
     boolean mHidden, mLowProfile;
+    int mDisabledFlags = 0;
 
     public View getRecentsButton() {
         return mCurrentView.findViewById(R.id.recent_apps);
@@ -99,7 +100,7 @@
                 // even though setting the systemUI visibility below will turn these views
                 // on, we need them to come up faster so that they can catch this motion
                 // event
-                setLowProfile(false, false);
+                setLowProfile(false, false, false);
 
                 try {
                     mBarService.setSystemUiVisibility(0);
@@ -110,9 +111,17 @@
         }
     };
 
-    public void setNavigationVisibility(int disabledFlags) {
-        boolean disableNavigation = ((disabledFlags & View.STATUS_BAR_DISABLE_NAVIGATION) != 0);
-        boolean disableBack = ((disabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0);
+    public void setDisabledFlags(int disabledFlags) {
+        setDisabledFlags(disabledFlags, false);
+    }
+
+    public void setDisabledFlags(int disabledFlags, boolean force) {
+        if (!force && mDisabledFlags == disabledFlags) return;
+
+        mDisabledFlags = disabledFlags;
+
+        final boolean disableNavigation = ((disabledFlags & View.STATUS_BAR_DISABLE_NAVIGATION) != 0);
+        final boolean disableBack = ((disabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0);
 
         getBackButton()   .setVisibility(disableBack       ? View.INVISIBLE : View.VISIBLE);
         getHomeButton()   .setVisibility(disableNavigation ? View.INVISIBLE : View.VISIBLE);
@@ -121,11 +130,11 @@
     }
 
     public void setLowProfile(final boolean lightsOut) {
-        setLowProfile(lightsOut, true);
+        setLowProfile(lightsOut, true, false);
     }
 
-    public void setLowProfile(final boolean lightsOut, final boolean animate) {
-        if (lightsOut == mLowProfile) return;
+    public void setLowProfile(final boolean lightsOut, final boolean animate, final boolean force) {
+        if (!force && lightsOut == mLowProfile) return;
 
         mLowProfile = lightsOut;
 
@@ -245,6 +254,10 @@
         mCurrentView.setVisibility(View.VISIBLE);
         mVertical = (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270);
 
+        // force the low profile & disabled states into compliance
+        setLowProfile(mLowProfile, false, true /* force */);
+        setDisabledFlags(mDisabledFlags, true /* force */);
+
         if (DEBUG_DEADZONE) {
             mCurrentView.findViewById(R.id.deadzone).setBackgroundColor(0x808080FF);
         }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index 81233df..febf3ab 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -297,7 +297,7 @@
                 mNavigationBarView = 
                     (NavigationBarView) View.inflate(context, R.layout.navigation_bar, null);
 
-                setNavigationVisibility(mDisabled);
+                mNavigationBarView.setDisabledFlags(mDisabled);
 
                 sb.setOnSystemUiVisibilityChangeListener(
                     new View.OnSystemUiVisibilityChangeListener() {
@@ -1058,62 +1058,67 @@
                 old, state, diff));
         }
 
+        StringBuilder flagdbg = new StringBuilder();
+        flagdbg.append("disable: < ");
+        flagdbg.append(((state & StatusBarManager.DISABLE_EXPAND) != 0) ? "EXPAND" : "expand");
+        flagdbg.append(((diff  & StatusBarManager.DISABLE_EXPAND) != 0) ? "* " : " ");
+        flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "ICONS" : "icons");
+        flagdbg.append(((diff  & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) ? "* " : " ");
+        flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "ALERTS" : "alerts");
+        flagdbg.append(((diff  & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0) ? "* " : " ");
+        flagdbg.append(((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "TICKER" : "ticker");
+        flagdbg.append(((diff  & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) ? "* " : " ");
+        flagdbg.append(((state & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "SYSTEM_INFO" : "system_info");
+        flagdbg.append(((diff  & StatusBarManager.DISABLE_SYSTEM_INFO) != 0) ? "* " : " ");
+        flagdbg.append(((state & StatusBarManager.DISABLE_NAVIGATION) != 0) ? "NAVIGATION" : "navigation");
+        flagdbg.append(((diff  & StatusBarManager.DISABLE_NAVIGATION) != 0) ? "* " : " ");
+        flagdbg.append(((state & StatusBarManager.DISABLE_BACK) != 0) ? "BACK" : "back");
+        flagdbg.append(((diff  & StatusBarManager.DISABLE_BACK) != 0) ? "* " : " ");
+        flagdbg.append(((state & StatusBarManager.DISABLE_CLOCK) != 0) ? "CLOCK" : "clock");
+        flagdbg.append(((diff  & StatusBarManager.DISABLE_CLOCK) != 0) ? "* " : " ");
+        flagdbg.append(">");
+        Slog.d(TAG, flagdbg.toString());
+
         if ((diff & StatusBarManager.DISABLE_CLOCK) != 0) {
             boolean show = (state & StatusBarManager.DISABLE_CLOCK) == 0;
             showClock(show);
         }
         if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) {
             if ((state & StatusBarManager.DISABLE_EXPAND) != 0) {
-                Slog.d(TAG, "DISABLE_EXPAND: yes");
                 animateCollapse();
             }
         }
 
         if ((diff & (StatusBarManager.DISABLE_NAVIGATION | StatusBarManager.DISABLE_BACK)) != 0) {
-            setNavigationVisibility(state &
-                    (StatusBarManager.DISABLE_NAVIGATION | StatusBarManager.DISABLE_BACK));
+            // the nav bar will take care of DISABLE_NAVIGATION and DISABLE_BACK
+            if (mNavigationBarView != null) mNavigationBarView.setDisabledFlags(state);
+
+            if ((state & StatusBarManager.DISABLE_NAVIGATION) != 0) {
+                // close recents if it's visible
+                mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL);
+                mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
+            }
         }
 
         if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
             if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
-                Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: yes");
                 if (mTicking) {
                     mTicker.halt();
                 } else {
                     setNotificationIconVisibility(false, com.android.internal.R.anim.fade_out);
                 }
             } else {
-                Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: no");
                 if (!mExpandedVisible) {
                     setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in);
                 }
             }
         } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
             if (mTicking && (state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
-                Slog.d(TAG, "DISABLE_NOTIFICATION_TICKER: yes");
                 mTicker.halt();
             }
         }
     }
 
-    private void setNavigationVisibility(int visibility) {
-        boolean disableNavigation = ((visibility & StatusBarManager.DISABLE_NAVIGATION) != 0);
-        boolean disableBack = ((visibility & StatusBarManager.DISABLE_BACK) != 0);
-
-        Slog.i(TAG, "DISABLE_BACK: " + (disableBack ? "yes" : "no"));
-        Slog.i(TAG, "DISABLE_NAVIGATION: " + (disableNavigation ? "yes" : "no"));
-
-        if (mNavigationBarView != null) {
-            mNavigationBarView.setNavigationVisibility(visibility);
-        }
-
-        if (disableNavigation) {
-            // close recents if it's visible
-            mHandler.removeMessages(MSG_CLOSE_RECENTS_PANEL);
-            mHandler.sendEmptyMessage(MSG_CLOSE_RECENTS_PANEL);
-        }
-    }
-
     /**
      * All changes to the status bar and notifications funnel through here and are batched.
      */
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index 20088b1..903b405 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -2171,6 +2171,8 @@
                         if (mActionModePopup != null) {
                             post(mShowActionModePopup);
                         }
+                        mActionModeView.sendAccessibilityEvent(
+                                AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
                     } else {
                         mActionMode = null;
                     }
diff --git a/services/sensorservice/Fusion.cpp b/services/sensorservice/Fusion.cpp
index 0ab86c3..d76f19c 100644
--- a/services/sensorservice/Fusion.cpp
+++ b/services/sensorservice/Fusion.cpp
@@ -167,6 +167,9 @@
     Bm.y = 1;
     Bm.z = 0;
 
+    x0 = 0;
+    x1 = 0;
+
     init();
 }
 
diff --git a/services/sensorservice/SensorDevice.cpp b/services/sensorservice/SensorDevice.cpp
index 38d498c..d82a7e2 100644
--- a/services/sensorservice/SensorDevice.cpp
+++ b/services/sensorservice/SensorDevice.cpp
@@ -138,9 +138,18 @@
 
     Mutex::Autolock _l(mLock);
     for (size_t i=0 ; i<size_t(count) ; i++) {
-        snprintf(buffer, SIZE, "handle=0x%08x, active-count=%d\n",
+        const Info& info = mActivationCount.valueFor(list[i].handle);
+        snprintf(buffer, SIZE, "handle=0x%08x, active-count=%d, rates(ms)={ ",
                 list[i].handle,
-                mActivationCount.valueFor(list[i].handle).rates.size());
+                info.rates.size());
+        result.append(buffer);
+        for (size_t j=0 ; j<info.rates.size() ; j++) {
+            snprintf(buffer, SIZE, "%4.1f%s",
+                    info.rates.valueAt(j) / 1e6f,
+                    j<info.rates.size()-1 ? ", " : "");
+            result.append(buffer);
+        }
+        snprintf(buffer, SIZE, " }, selected=%4.1f ms\n",  info.delay / 1e6f);
         result.append(buffer);
     }
 }
@@ -217,17 +226,9 @@
         }
     }
 
-    if (!actuateHardware || enabled) {
+    { // scope for the lock
         Mutex::Autolock _l(mLock);
-        nsecs_t ns = info.rates.valueAt(0);
-        for (size_t i=1 ; i<info.rates.size() ; i++) {
-            if (info.rates.valueAt(i) < ns) {
-                nsecs_t cur = info.rates.valueAt(i);
-                if (cur < ns) {
-                    ns = cur;
-                }
-            }
-        }
+        nsecs_t ns = info.selectDelay();
         mSensorDevice->setDelay(mSensorDevice, handle, ns);
     }
 
@@ -237,24 +238,39 @@
 status_t SensorDevice::setDelay(void* ident, int handle, int64_t ns)
 {
     if (!mSensorDevice) return NO_INIT;
+    Mutex::Autolock _l(mLock);
     Info& info( mActivationCount.editValueFor(handle) );
-    { // scope for lock
-        Mutex::Autolock _l(mLock);
-        ssize_t index = info.rates.indexOfKey(ident);
-        if (index < 0) return BAD_INDEX;
-        info.rates.editValueAt(index) = ns;
-        ns = info.rates.valueAt(0);
-        for (size_t i=1 ; i<info.rates.size() ; i++) {
-            nsecs_t cur = info.rates.valueAt(i);
-            if (cur < ns) {
-                ns = cur;
-            }
+    status_t err = info.setDelayForIdent(ident, ns);
+    if (err < 0) return err;
+    ns = info.selectDelay();
+    return mSensorDevice->setDelay(mSensorDevice, handle, ns);
+}
+
+// ---------------------------------------------------------------------------
+
+status_t SensorDevice::Info::setDelayForIdent(void* ident, int64_t ns)
+{
+    ssize_t index = rates.indexOfKey(ident);
+    if (index < 0) {
+        LOGE("Info::setDelayForIdent(ident=%p, ns=%lld) failed (%s)",
+                ident, ns, strerror(-index));
+        return BAD_INDEX;
+    }
+    rates.editValueAt(index) = ns;
+    return NO_ERROR;
+}
+
+nsecs_t SensorDevice::Info::selectDelay()
+{
+    nsecs_t ns = rates.valueAt(0);
+    for (size_t i=1 ; i<rates.size() ; i++) {
+        nsecs_t cur = rates.valueAt(i);
+        if (cur < ns) {
+            ns = cur;
         }
     }
-
-    //LOGD("setDelay: ident=%p, handle=%d, ns=%lld", ident, handle, ns);
-
-    return mSensorDevice->setDelay(mSensorDevice, handle, ns);
+    delay = ns;
+    return ns;
 }
 
 // ---------------------------------------------------------------------------
diff --git a/services/sensorservice/SensorDevice.h b/services/sensorservice/SensorDevice.h
index c19b2ce..728b6cb 100644
--- a/services/sensorservice/SensorDevice.h
+++ b/services/sensorservice/SensorDevice.h
@@ -37,11 +37,14 @@
     friend class Singleton<SensorDevice>;
     struct sensors_poll_device_t* mSensorDevice;
     struct sensors_module_t* mSensorModule;
-    Mutex mLock; // protect mActivationCount[].rates
+    mutable Mutex mLock; // protect mActivationCount[].rates
     // fixed-size array after construction
     struct Info {
-        Info() { }
+        Info() : delay(0) { }
         KeyedVector<void*, nsecs_t> rates;
+        nsecs_t delay;
+        status_t setDelayForIdent(void* ident, int64_t ns);
+        nsecs_t selectDelay();
     };
     DefaultKeyedVector<int, Info> mActivationCount;