Merge "Add cdma_rmnet4 to list of monitored interfaces" into ics-mr0
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java
index caad6fd..68f0247 100644
--- a/core/java/android/hardware/Camera.java
+++ b/core/java/android/hardware/Camera.java
@@ -1687,15 +1687,18 @@
          * aggressive than {@link #FOCUS_MODE_CONTINUOUS_VIDEO}. Auto focus
          * starts when the parameter is set.
          *
-         * <p>If applications call {@link #autoFocus(AutoFocusCallback)} in this
-         * mode, the focus callback will immediately return with a boolean that
-         * indicates whether the focus is sharp or not. The apps can then decide
-         * if they want to take a picture immediately or to change the focus
-         * mode to auto, and run a full autofocus cycle. The focus position is
-         * locked after autoFocus call. If applications want to resume the
-         * continuous focus, cancelAutoFocus must be called. Restarting the
-         * preview will not resume the continuous autofocus. To stop continuous
-         * focus, applications should change the focus mode to other modes.
+         * <p>Applications can call {@link #autoFocus(AutoFocusCallback)} in
+         * this mode. If the autofocus is in the middle of scanning, the focus
+         * callback will return when it completes. If the autofocus is not
+         * scanning, the focus callback will immediately return with a boolean
+         * that indicates whether the focus is sharp or not. The apps can then
+         * decide if they want to take a picture immediately or to change the
+         * focus mode to auto, and run a full autofocus cycle. The focus
+         * position is locked after autoFocus call. If applications want to
+         * resume the continuous focus, cancelAutoFocus must be called.
+         * Restarting the preview will not resume the continuous autofocus. To
+         * stop continuous focus, applications should change the focus mode to
+         * other modes.
          *
          * @see #FOCUS_MODE_CONTINUOUS_VIDEO
          */
diff --git a/core/java/android/nfc/NfcFragment.java b/core/java/android/nfc/NfcFragment.java
index 17278dc..d6b15ad 100644
--- a/core/java/android/nfc/NfcFragment.java
+++ b/core/java/android/nfc/NfcFragment.java
@@ -48,7 +48,10 @@
         FragmentManager manager = activity.getFragmentManager();
         Fragment fragment = manager.findFragmentByTag(FRAGMENT_TAG);
         if (fragment != null) {
-            manager.beginTransaction().remove(fragment).commit();
+            // We allow state loss at this point, because the state is only
+            // lost when activity is being paused *AND* subsequently destroyed.
+            // In that case, the app will setup foreground dispatch again anyway.
+            manager.beginTransaction().remove(fragment).commitAllowingStateLoss();
         }
     }
 
diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp
index 0b53850..3fdc79b 100644
--- a/core/jni/android/graphics/TextLayoutCache.cpp
+++ b/core/jni/android/graphics/TextLayoutCache.cpp
@@ -425,14 +425,10 @@
         // Initialize Harfbuzz Shaper
         initShaperItem(shaperItem, &font, &fontData, paint, chars, contextCount);
 
+        bool useSingleRun = false;
+        bool isRTL = forceRTL;
         if (forceLTR || forceRTL) {
-#if DEBUG_GLYPHS
-                    LOGD("computeValuesWithHarfbuzz -- forcing run with LTR=%d RTL=%d",
-                            forceLTR, forceRTL);
-#endif
-            computeRunValuesWithHarfbuzz(shaperItem, paint,
-                    start, count, forceRTL,
-                    outAdvances, outTotalAdvance, outGlyphs);
+            useSingleRun = true;
         } else {
             UBiDi* bidi = ubidi_open();
             if (bidi) {
@@ -443,43 +439,50 @@
                 ubidi_setPara(bidi, chars, contextCount, bidiReq, NULL, &status);
                 if (U_SUCCESS(status)) {
                     int paraDir = ubidi_getParaLevel(bidi) & kDirection_Mask; // 0 if ltr, 1 if rtl
-                    size_t rc = ubidi_countRuns(bidi, &status);
+                    ssize_t rc = ubidi_countRuns(bidi, &status);
 #if DEBUG_GLYPHS
                     LOGD("computeValuesWithHarfbuzz -- dirFlags=%d run-count=%d paraDir=%d",
                             dirFlags, rc, paraDir);
 #endif
-                    if (rc == 1 || !U_SUCCESS(status)) {
-                        bool isRTL = (paraDir == 1);
-#if DEBUG_GLYPHS
-                        LOGD("computeValuesWithHarfbuzz -- processing SINGLE run "
-                                "-- run-start=%d run-len=%d isRTL=%d", start, count, isRTL);
-#endif
-                        computeRunValuesWithHarfbuzz(shaperItem, paint,
-                                start, count, isRTL,
-                                outAdvances, outTotalAdvance, outGlyphs);
+                    if (!U_SUCCESS(status) || rc <= 1) {
+                        LOGW("computeValuesWithHarfbuzz -- need to force to single run");
+                        isRTL = (paraDir == 1);
+                        useSingleRun = true;
                     } else {
                         int32_t end = start + count;
-                        for (size_t i = 0; i < rc; ++i) {
-                            int32_t startRun;
-                            int32_t lengthRun;
+                        for (size_t i = 0; i < size_t(rc); ++i) {
+                            int32_t startRun = -1;
+                            int32_t lengthRun = -1;
                             UBiDiDirection runDir = ubidi_getVisualRun(bidi, i, &startRun, &lengthRun);
 
+                            if (startRun == -1 || lengthRun == -1) {
+                                // Something went wrong when getting the visual run, need to clear
+                                // already computed data before doing a single run pass
+                                LOGW("computeValuesWithHarfbuzz -- visual run is not valid");
+                                outGlyphs->clear();
+                                outAdvances->clear();
+                                *outTotalAdvance = 0;
+                                isRTL = (paraDir == 1);
+                                useSingleRun = true;
+                                break;
+                            }
+
                             if (startRun >= end) {
                                 continue;
                             }
                             int32_t endRun = startRun + lengthRun;
-                            if (endRun <= start) {
+                            if (endRun <= int32_t(start)) {
                                 continue;
                             }
-                            if (startRun < start) {
-                                startRun = start;
+                            if (startRun < int32_t(start)) {
+                                startRun = int32_t(start);
                             }
                             if (endRun > end) {
                                 endRun = end;
                             }
 
                             lengthRun = endRun - startRun;
-                            bool isRTL = (runDir == UBIDI_RTL);
+                            isRTL = (runDir == UBIDI_RTL);
                             jfloat runTotalAdvance = 0;
 #if DEBUG_GLYPHS
                             LOGD("computeValuesWithHarfbuzz -- run-start=%d run-len=%d isRTL=%d",
@@ -492,21 +495,30 @@
                             *outTotalAdvance += runTotalAdvance;
                         }
                     }
+                } else {
+                    LOGW("computeValuesWithHarfbuzz -- cannot set Para");
+                    useSingleRun = true;
+                    isRTL = (bidiReq = 1) || (bidiReq = UBIDI_DEFAULT_RTL);
                 }
                 ubidi_close(bidi);
             } else {
-                // Cannot run BiDi, just consider one Run
-                bool isRTL = (bidiReq = 1) || (bidiReq = UBIDI_DEFAULT_RTL);
-#if DEBUG_GLYPHS
-                LOGD("computeValuesWithHarfbuzz -- cannot run BiDi, considering a SINGLE Run "
-                        "-- run-start=%d run-len=%d isRTL=%d", start, count, isRTL);
-#endif
-                computeRunValuesWithHarfbuzz(shaperItem, paint,
-                        start, count, isRTL,
-                        outAdvances, outTotalAdvance, outGlyphs);
+                LOGW("computeValuesWithHarfbuzz -- cannot ubidi_open()");
+                useSingleRun = true;
+                isRTL = (bidiReq = 1) || (bidiReq = UBIDI_DEFAULT_RTL);
             }
         }
 
+        // Default single run case
+        if (useSingleRun){
+#if DEBUG_GLYPHS
+            LOGD("computeValuesWithHarfbuzz -- Using a SINGLE Run "
+                    "-- run-start=%d run-len=%d isRTL=%d", start, count, isRTL);
+#endif
+            computeRunValuesWithHarfbuzz(shaperItem, paint,
+                    start, count, isRTL,
+                    outAdvances, outTotalAdvance, outGlyphs);
+        }
+
         // Cleaning
         freeShaperItem(shaperItem);
 
diff --git a/include/camera/CameraParameters.h b/include/camera/CameraParameters.h
index ef4cf5c..7edf6b4 100644
--- a/include/camera/CameraParameters.h
+++ b/include/camera/CameraParameters.h
@@ -644,15 +644,17 @@
     // than FOCUS_MODE_CONTINUOUS_VIDEO. Auto focus starts when the parameter is
     // set.
     //
-    // If applications call CameraHardwareInterface.autoFocus in this mode, the
-    // focus callback will immediately return with a boolean that indicates
-    // whether the focus is sharp or not. The apps can then decide if they want
-    // to take a picture immediately or to change the focus mode to auto, and
-    // run a full autofocus cycle. The focus position is locked after autoFocus
-    // call. If applications want to resume the continuous focus,
-    // cancelAutoFocus must be called. Restarting the preview will not resume
-    // the continuous autofocus. To stop continuous focus, applications should
-    // change the focus mode to other modes.
+    // Applications can call CameraHardwareInterface.autoFocus in this mode. If
+    // the autofocus is in the middle of scanning, the focus callback will
+    // return when it completes. If the autofocus is not scanning, focus
+    // callback will immediately return with a boolean that indicates whether
+    // the focus is sharp or not. The apps can then decide if they want to take
+    // a picture immediately or to change the focus mode to auto, and run a full
+    // autofocus cycle. The focus position is locked after autoFocus call. If
+    // applications want to resume the continuous focus, cancelAutoFocus must be
+    // called. Restarting the preview will not resume the continuous autofocus.
+    // To stop continuous focus, applications should change the focus mode to
+    // other modes.
     static const char FOCUS_MODE_CONTINUOUS_PICTURE[];
 
 private:
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 948ecf9..5291a1f 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -359,6 +359,7 @@
     mTargetSdkVersion = 14;
     mDPI = 96;
     mIsContextLite = false;
+    memset(&watchdog, 0, sizeof(watchdog));
 }
 
 Context * Context::createContext(Device *dev, const RsSurfaceConfig *sc) {
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 25a3705..2f32bd8 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -1635,8 +1635,10 @@
                     // "silent mode", but which one?
                     newRingerMode = vibeInSilent ? RINGER_MODE_VIBRATE : RINGER_MODE_SILENT;
                 }
-                if (uiIndex == 0 || (mPrevVolDirection == AudioManager.ADJUST_LOWER &&
-                        mVoiceCapable && streamType == AudioSystem.STREAM_RING)) {
+                if (uiIndex == 0 ||
+                        (!vibeInSilent &&
+                         mPrevVolDirection == AudioManager.ADJUST_LOWER &&
+                         mVoiceCapable && streamType == AudioSystem.STREAM_RING)) {
                     adjustVolumeIndex = false;
                 }
             }
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
index 0471dfe..c802bc1 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
@@ -616,8 +616,8 @@
         final IccCard.State state = mUpdateMonitor.getSimState();
         final boolean lockedOrMissing = state.isPinLocked()
                 || ((state == IccCard.State.ABSENT
-                        || state == IccCard.State.PERM_DISABLED)
-                        && requireSim);
+                || state == IccCard.State.PERM_DISABLED)
+                && requireSim);
 
         if (!lockedOrMissing && !provisioned) {
             if (DEBUG) Log.d(TAG, "doKeyguard: not showing because device isn't provisioned"
@@ -625,7 +625,7 @@
             return;
         }
 
-        if (mLockPatternUtils.isLockScreenDisabled()) {
+        if (mLockPatternUtils.isLockScreenDisabled() && !lockedOrMissing) {
             if (DEBUG) Log.d(TAG, "doKeyguard: not showing because lockscreen is off");
             return;
         }