Merge "Fix ACTION_CANCEL handling in status bar. Bug: 5198231"
diff --git a/core/java/android/content/SyncManager.java b/core/java/android/content/SyncManager.java
index 9678d48..684c4fe 100644
--- a/core/java/android/content/SyncManager.java
+++ b/core/java/android/content/SyncManager.java
@@ -191,12 +191,6 @@
     private static final long SYNC_ALARM_TIMEOUT_MIN = 30 * 1000; // 30 seconds
     private static final long SYNC_ALARM_TIMEOUT_MAX = 2 * 60 * 60 * 1000; // two hours
 
-    /**
-     * The amount of time (in milliseconds) to wait after attempting a bind
-     * before canceling a sync and disabling the sync adapter
-     */
-    public static final long BIND_TIMEOUT_MS = 5 * 60 * 1000;
-
     public void onAccountsUpdated(Account[] accounts) {
         // remember if this was the first time this was called after an update
         final boolean justBootedUp = mAccounts == INITIAL_ACCOUNTS_ARRAY;
@@ -1074,9 +1068,6 @@
             pw.print(" - ");
             pw.print(activeSyncContext.mSyncOperation.dump(false));
             pw.println();
-            if (activeSyncContext.mSyncAdapter == null) {
-                pw.println("   **** Waiting for onServiceConnected ****");
-            }
         }
 
         synchronized (mSyncQueue) {
@@ -1433,7 +1424,6 @@
         public void handleMessage(Message msg) {
             long earliestFuturePollTime = Long.MAX_VALUE;
             long nextPendingSyncTime = Long.MAX_VALUE;
-            long nextBindTimeoutTime = Long.MAX_VALUE;
 
             // Setting the value here instead of a method because we want the dumpsys logs
             // to have the most recent value used.
@@ -1441,7 +1431,6 @@
                 waitUntilReadyToRun();
                 mDataConnectionIsConnected = readDataConnectionState();
                 mSyncManagerWakeLock.acquire();
-                nextBindTimeoutTime = auditRunningSyncsForStuckBindsLocked();
                 // Always do this first so that we be sure that any periodic syncs that
                 // are ready to run have been converted into pending syncs. This allows the
                 // logic that considers the next steps to take based on the set of pending syncs
@@ -1543,7 +1532,6 @@
                         break;
                 }
             } finally {
-                nextPendingSyncTime = Math.min(nextBindTimeoutTime, nextPendingSyncTime);
                 manageSyncNotificationLocked();
                 manageSyncAlarmLocked(earliestFuturePollTime, nextPendingSyncTime);
                 mSyncTimeTracker.update();
@@ -1552,36 +1540,6 @@
         }
 
         /**
-         * Looks to see if any of the active syncs have been waiting for a bind for too long,
-         * and if so the sync is canceled and the sync adapter is disabled for that account.
-         * @return the earliest time that an active sync can have waited too long to bind,
-         * relative to {@link android.os.SystemClock#elapsedRealtime()}.
-         */
-        private long auditRunningSyncsForStuckBindsLocked() {
-            final long now = SystemClock.elapsedRealtime();
-            long oldest = Long.MAX_VALUE;
-            for (ActiveSyncContext active : mActiveSyncContexts) {
-                if (active.mSyncAdapter == null) {
-                    final long timeoutTime = active.mStartTime + BIND_TIMEOUT_MS;
-                    if (timeoutTime < now) {
-                        Log.w(TAG, "canceling long-running bind and disabling sync for "
-                                + active.mSyncOperation.account + ", authority "
-                                + active.mSyncOperation.authority);
-                        runSyncFinishedOrCanceledLocked(null, active);
-                        ContentResolver.setIsSyncable(active.mSyncOperation.account,
-                                active.mSyncOperation.authority, 0);
-                    } else {
-                        if (oldest > timeoutTime) {
-                            oldest = timeoutTime;
-                        }
-                    }
-                }
-            }
-
-            return oldest;
-        }
-
-        /**
          * Turn any periodic sync operations that are ready to run into pending sync operations.
          * @return the desired start time of the earliest future  periodic sync operation,
          * in milliseconds since boot
@@ -1861,17 +1819,13 @@
                 synchronized (mSyncQueue){
                     mSyncQueue.remove(candidate);
                 }
-                ActiveSyncContext newSyncContext = dispatchSyncOperation(candidate);
-                if (newSyncContext != null) {
-                    nextReadyToRunTime = Math.min(nextReadyToRunTime,
-                            newSyncContext.mStartTime + BIND_TIMEOUT_MS);
-                }
+                dispatchSyncOperation(candidate);
             }
 
             return nextReadyToRunTime;
      }
 
-        private ActiveSyncContext dispatchSyncOperation(SyncOperation op) {
+        private boolean dispatchSyncOperation(SyncOperation op) {
             if (Log.isLoggable(TAG, Log.VERBOSE)) {
                 Log.v(TAG, "dispatchSyncOperation: we are going to sync " + op);
                 Log.v(TAG, "num active syncs: " + mActiveSyncContexts.size());
@@ -1888,7 +1842,7 @@
                 Log.d(TAG, "can't find a sync adapter for " + syncAdapterType
                         + ", removing settings for it");
                 mSyncStorageEngine.removeAuthority(op.account, op.authority);
-                return null;
+                return false;
             }
 
             ActiveSyncContext activeSyncContext =
@@ -1901,10 +1855,10 @@
             if (!activeSyncContext.bindToSyncAdapter(syncAdapterInfo)) {
                 Log.e(TAG, "Bind attempt failed to " + syncAdapterInfo);
                 closeActiveSyncContext(activeSyncContext);
-                return null;
+                return false;
             }
 
-            return activeSyncContext;
+            return true;
         }
 
         private void runBoundToSyncAdapter(final ActiveSyncContext activeSyncContext,
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index b948114..40d85d8 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -3102,6 +3102,11 @@
             text = "";
         }
 
+        // If suggestions are not enabled, remove the suggestion spans from the text
+        if (!isSuggestionsEnabled()) {
+            text = removeSuggestionSpans(text);
+        }
+
         if (!mUserSetTextScaleX) mTextPaint.setTextScaleX(1.0f);
 
         if (text instanceof Spanned &&
@@ -3503,6 +3508,10 @@
             applySingleLine(singleLine, !isPassword, true);
         }
         
+        if (!isSuggestionsEnabled()) {
+            mText = removeSuggestionSpans(mText);
+        }
+
         InputMethodManager imm = InputMethodManager.peekInstance();
         if (imm != null) imm.restartInput(this);
     }
@@ -9923,9 +9932,28 @@
         }
     }
 
-    void showSuggestions() {
-        if (!isSuggestionsEnabled() || !isTextEditable()) return;
+    /**
+     * Removes the suggestion spans.
+     */
+    CharSequence removeSuggestionSpans(CharSequence text) {
+       if (text instanceof Spanned) {
+           Spannable spannable;
+           if (text instanceof Spannable) {
+               spannable = (Spannable) text;
+           } else {
+               spannable = new SpannableString(text);
+               text = spannable;
+           }
 
+           SuggestionSpan[] spans = spannable.getSpans(0, text.length(), SuggestionSpan.class);
+           for (int i = 0; i < spans.length; i++) {
+               spannable.removeSpan(spans[i]);
+           }
+       }
+       return text;
+    }
+
+    void showSuggestions() {
         if (mSuggestionsPopupWindow == null) {
             mSuggestionsPopupWindow = new SuggestionsPopupWindow();
         }
diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java
index ee65223..ce42612 100644
--- a/graphics/java/android/graphics/Paint.java
+++ b/graphics/java/android/graphics/Paint.java
@@ -20,7 +20,6 @@
 import android.text.SpannableString;
 import android.text.SpannedString;
 import android.text.TextUtils;
-import android.util.DisplayMetrics;
 
 /**
  * The Paint class holds the style and color information about how to draw
@@ -344,8 +343,10 @@
     public Paint(int flags) {
         mNativePaint = native_init();
         setFlags(flags | DEFAULT_PAINT_FLAGS);
-        setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV
-                ? HINTING_OFF : HINTING_ON);
+        // TODO: Turning off hinting has undesirable side effects, we need to
+        //       revisit hinting once we add support for subpixel positioning
+        // setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV
+        //        ? HINTING_OFF : HINTING_ON);
         mCompatScaling = mInvCompatScaling = 1;
     }
 
@@ -365,8 +366,10 @@
     public void reset() {
         native_reset(mNativePaint);
         setFlags(DEFAULT_PAINT_FLAGS);
-        setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV
-                ? HINTING_OFF : HINTING_ON);
+        // TODO: Turning off hinting has undesirable side effects, we need to
+        //       revisit hinting once we add support for subpixel positioning
+        // setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV
+        //        ? HINTING_OFF : HINTING_ON);
         mHasCompatScaling = false;
         mCompatScaling = mInvCompatScaling = 1;
         mBidiFlags = BIDI_DEFAULT_LTR;
diff --git a/include/media/stagefright/ACodec.h b/include/media/stagefright/ACodec.h
index e965f14..b7286e5 100644
--- a/include/media/stagefright/ACodec.h
+++ b/include/media/stagefright/ACodec.h
@@ -164,6 +164,8 @@
 
     void sendFormatChange();
 
+    void signalError(OMX_ERRORTYPE error = OMX_ErrorUndefined);
+
     DISALLOW_EVIL_CONSTRUCTORS(ACodec);
 };
 
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index e9dc61c..2ba2273 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -1131,6 +1131,13 @@
     mSentFormat = true;
 }
 
+void ACodec::signalError(OMX_ERRORTYPE error) {
+    sp<AMessage> notify = mNotify->dup();
+    notify->setInt32("what", ACodec::kWhatError);
+    notify->setInt32("omx-error", error);
+    notify->post();
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
 ACodec::BaseState::BaseState(ACodec *codec, const sp<AState> &parentState)
@@ -1252,10 +1259,7 @@
 
     LOGE("[%s] ERROR(0x%08lx)", mCodec->mComponentName.c_str(), data1);
 
-    sp<AMessage> notify = mCodec->mNotify->dup();
-    notify->setInt32("what", ACodec::kWhatError);
-    notify->setInt32("omx-error", data1);
-    notify->post();
+    mCodec->signalError((OMX_ERRORTYPE)data1);
 
     return true;
 }
@@ -1548,12 +1552,14 @@
             && msg->findInt32("render", &render) && render != 0) {
         // The client wants this buffer to be rendered.
 
-        CHECK_EQ(mCodec->mNativeWindow->queueBuffer(
+        if (mCodec->mNativeWindow->queueBuffer(
                     mCodec->mNativeWindow.get(),
-                    info->mGraphicBuffer.get()),
-                 0);
-
-        info->mStatus = BufferInfo::OWNED_BY_NATIVE_WINDOW;
+                    info->mGraphicBuffer.get()) == OK) {
+            info->mStatus = BufferInfo::OWNED_BY_NATIVE_WINDOW;
+        } else {
+            mCodec->signalError();
+            info->mStatus = BufferInfo::OWNED_BY_US;
+        }
     } else {
         info->mStatus = BufferInfo::OWNED_BY_US;
     }
@@ -1692,11 +1698,7 @@
     if (node == NULL) {
         LOGE("Unable to instantiate a decoder for type '%s'.", mime.c_str());
 
-        sp<AMessage> notify = mCodec->mNotify->dup();
-        notify->setInt32("what", ACodec::kWhatError);
-        notify->setInt32("omx-error", OMX_ErrorComponentNotFound);
-        notify->post();
-
+        mCodec->signalError(OMX_ErrorComponentNotFound);
         return;
     }
 
@@ -1744,10 +1746,7 @@
              "(error 0x%08x)",
              err);
 
-        sp<AMessage> notify = mCodec->mNotify->dup();
-        notify->setInt32("what", ACodec::kWhatError);
-        notify->setInt32("omx-error", OMX_ErrorUndefined);
-        notify->post();
+        mCodec->signalError();
     }
 }
 
@@ -2063,10 +2062,7 @@
                          "port reconfiguration (error 0x%08x)",
                          err);
 
-                    sp<AMessage> notify = mCodec->mNotify->dup();
-                    notify->setInt32("what", ACodec::kWhatError);
-                    notify->setInt32("omx-error", OMX_ErrorUndefined);
-                    notify->post();
+                    mCodec->signalError();
                 }
 
                 return true;
diff --git a/media/libstagefright/AVIExtractor.cpp b/media/libstagefright/AVIExtractor.cpp
index 6313ca3..62d17da 100644
--- a/media/libstagefright/AVIExtractor.cpp
+++ b/media/libstagefright/AVIExtractor.cpp
@@ -911,7 +911,11 @@
 
     if (!memcmp(tmp, "RIFF", 4) && !memcmp(&tmp[8], "AVI ", 4)) {
         mimeType->setTo(MEDIA_MIMETYPE_CONTAINER_AVI);
-        *confidence = 0.2;
+
+        // Just a tad over the mp3 extractor's confidence, since
+        // these .avi files may contain .mp3 content that otherwise would
+        // mistakenly lead to us identifying the entire file as a .mp3 file.
+        *confidence = 0.21;
 
         return true;
     }
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java
index be2ef82..2938c45 100644
--- a/services/java/com/android/server/BackupManagerService.java
+++ b/services/java/com/android/server/BackupManagerService.java
@@ -497,10 +497,14 @@
 
             case MSG_RUN_FULL_BACKUP:
             {
+                // TODO: refactor full backup to be a looper-based state machine
+                // similar to normal backup/restore.
                 FullBackupParams params = (FullBackupParams)msg.obj;
-                (new PerformFullBackupTask(params.fd, params.observer, params.includeApks,
+                PerformFullBackupTask task = new PerformFullBackupTask(params.fd,
+                        params.observer, params.includeApks,
                         params.includeShared, params.curPassword, params.encryptPassword,
-                        params.allApps, params.packages, params.latch)).run();
+                        params.allApps, params.packages, params.latch);
+                (new Thread(task)).start();
                 break;
             }
 
@@ -519,9 +523,13 @@
 
             case MSG_RUN_FULL_RESTORE:
             {
+                // TODO: refactor full restore to be a looper-based state machine
+                // similar to normal backup/restore.
                 FullRestoreParams params = (FullRestoreParams)msg.obj;
-                (new PerformFullRestoreTask(params.fd, params.curPassword, params.encryptPassword,
-                        params.observer, params.latch)).run();
+                PerformFullRestoreTask task = new PerformFullRestoreTask(params.fd,
+                        params.curPassword, params.encryptPassword,
+                        params.observer, params.latch);
+                (new Thread(task)).start();
                 break;
             }
 
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index e6b5898..4b1a4e6 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -69,6 +69,7 @@
 import java.io.PrintWriter;
 
 import com.android.internal.app.IBatteryStats;
+import com.android.internal.telephony.TelephonyIntents;
 import com.android.internal.util.AsyncChannel;
 import com.android.server.am.BatteryStatsService;
 import com.android.internal.R;
@@ -96,6 +97,7 @@
     private static final int IDLE_REQUEST = 0;
     private boolean mScreenOff;
     private boolean mDeviceIdle;
+    private boolean mEmergencyCallbackMode = false;
     private int mPluggedType;
 
     /* Chipset supports background scan */
@@ -996,6 +998,9 @@
                 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
                         BluetoothAdapter.STATE_DISCONNECTED);
                 mWifiStateMachine.sendBluetoothAdapterStateChange(state);
+            } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
+                mEmergencyCallbackMode = intent.getBooleanExtra("phoneinECMState", false);
+                updateWifiState();
             }
         }
 
@@ -1057,7 +1062,13 @@
     private void updateWifiState() {
         boolean lockHeld = mLocks.hasLocks();
         int strongestLockMode = WifiManager.WIFI_MODE_FULL;
-        boolean wifiShouldBeStarted = !mDeviceIdle || lockHeld;
+        boolean wifiShouldBeStarted;
+
+        if (mEmergencyCallbackMode) {
+            wifiShouldBeStarted = false;
+        } else {
+            wifiShouldBeStarted = !mDeviceIdle || lockHeld;
+        }
 
         if (lockHeld) {
             strongestLockMode = mLocks.getStrongestLockMode();
@@ -1097,6 +1108,7 @@
         intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
         intentFilter.addAction(ACTION_DEVICE_IDLE);
         intentFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
+        intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
         mContext.registerReceiver(mReceiver, intentFilter);
     }
 
diff --git a/services/java/com/android/server/wm/DimSurface.java b/services/java/com/android/server/wm/DimSurface.java
index d7bb8b3..dc6cc0d 100644
--- a/services/java/com/android/server/wm/DimSurface.java
+++ b/services/java/com/android/server/wm/DimSurface.java
@@ -53,19 +53,22 @@
     void show(int dw, int dh, int layer, int color) {
         if (!mDimShown) {
             if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "  DIM " + mDimSurface + ": SHOW pos=(0,0) (" +
-                    dw + "x" + dh + ")");
+                    dw + "x" + dh + " layer=" + layer + ")");
             mDimShown = true;
             try {
                 mLastDimWidth = dw;
                 mLastDimHeight = dh;
                 mDimSurface.setPosition(0, 0);
                 mDimSurface.setSize(dw, dh);
+                mDimSurface.setLayer(layer);
                 mDimSurface.show();
             } catch (RuntimeException e) {
                 Slog.w(WindowManagerService.TAG, "Failure showing dim surface", e);
             }
         } else if (mLastDimWidth != dw || mLastDimHeight != dh || mDimColor != color
                 || mLayer != layer) {
+            if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "  DIM " + mDimSurface + ": pos=(0,0) (" +
+                    dw + "x" + dh + " layer=" + layer + ")");
             mLastDimWidth = dw;
             mLastDimHeight = dh;
             mLayer = layer;
@@ -80,6 +83,7 @@
         if (mDimShown) {
             mDimShown = false;
             try {
+                if (WindowManagerService.SHOW_TRANSACTIONS) Slog.i(WindowManagerService.TAG, "  HIDE " + mDimSurface);
                 mDimSurface.hide();
             } catch (RuntimeException e) {
                 Slog.w(WindowManagerService.TAG, "Illegal argument exception hiding dim surface");
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index df9698e..5a7fc9f 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -7458,9 +7458,12 @@
                                     windowDetachedWallpaper = w;
                                 }
                                 if (w.mAnimation.getBackgroundColor() != 0) {
-                                    windowAnimationBackground = w;
-                                    windowAnimationBackgroundColor =
-                                            w.mAnimation.getBackgroundColor();
+                                    if (windowAnimationBackground == null || w.mAnimLayer <
+                                            windowAnimationBackground.mAnimLayer) {
+                                        windowAnimationBackground = w;
+                                        windowAnimationBackgroundColor =
+                                                w.mAnimation.getBackgroundColor();
+                                    }
                                 }
                             }
                             animating = true;
@@ -7469,14 +7472,18 @@
                         // If this window's app token is running a detached wallpaper
                         // animation, make a note so we can ensure the wallpaper is
                         // displayed behind it.
-                        if (w.mAppToken != null && w.mAppToken.animation != null) {
+                        if (w.mAppToken != null && w.mAppToken.animation != null
+                                && w.mAppToken.animating) {
                             if (w.mAppToken.animation.getDetachWallpaper()) {
                                 windowDetachedWallpaper = w;
                             }
                             if (w.mAppToken.animation.getBackgroundColor() != 0) {
-                                windowAnimationBackground = w;
-                                windowAnimationBackgroundColor =
-                                        w.mAppToken.animation.getBackgroundColor();
+                                if (windowAnimationBackground == null || w.mAnimLayer <
+                                        windowAnimationBackground.mAnimLayer) {
+                                    windowAnimationBackground = w;
+                                    windowAnimationBackgroundColor =
+                                            w.mAppToken.animation.getBackgroundColor();
+                                }
                             }
                         }
 
diff --git a/tests/RenderScriptTests/tests/src/com/android/rs/test/math.rs b/tests/RenderScriptTests/tests/src/com/android/rs/test/math.rs
index 8cad82b..aae29a4 100644
--- a/tests/RenderScriptTests/tests/src/com/android/rs/test/math.rs
+++ b/tests/RenderScriptTests/tests/src/com/android/rs/test/math.rs
@@ -37,162 +37,6 @@
 volatile uchar3 uc3;
 volatile uchar4 uc4;
 
-#define TEST_FN_FUNC_FN(fnc)        \
-    rsDebug("Testing " #fnc, 0);    \
-    f1 = fnc(f1);                   \
-    f2 = fnc(f2);                   \
-    f3 = fnc(f3);                   \
-    f4 = fnc(f4);
-
-#define TEST_FN_FUNC_FN_PFN(fnc)    \
-    rsDebug("Testing " #fnc, 0);    \
-    f1 = fnc(f1, (float*) &f1);     \
-    f2 = fnc(f2, (float2*) &f2);    \
-    f3 = fnc(f3, (float3*) &f3);    \
-    f4 = fnc(f4, (float4*) &f4);
-
-#define TEST_FN_FUNC_FN_FN(fnc)     \
-    rsDebug("Testing " #fnc, 0);    \
-    f1 = fnc(f1, f1);               \
-    f2 = fnc(f2, f2);               \
-    f3 = fnc(f3, f3);               \
-    f4 = fnc(f4, f4);
-
-#define TEST_FN_FUNC_FN_F(fnc)      \
-    rsDebug("Testing " #fnc, 0);    \
-    f1 = fnc(f1, f1);               \
-    f2 = fnc(f2, f1);               \
-    f3 = fnc(f3, f1);               \
-    f4 = fnc(f4, f1);
-
-#define TEST_FN_FUNC_FN_IN(fnc)     \
-    rsDebug("Testing " #fnc, 0);    \
-    f1 = fnc(f1, i1);               \
-    f2 = fnc(f2, i2);               \
-    f3 = fnc(f3, i3);               \
-    f4 = fnc(f4, i4);
-
-#define TEST_FN_FUNC_FN_I(fnc)      \
-    rsDebug("Testing " #fnc, 0);    \
-    f1 = fnc(f1, i1);               \
-    f2 = fnc(f2, i1);               \
-    f3 = fnc(f3, i1);               \
-    f4 = fnc(f4, i1);
-
-#define TEST_FN_FUNC_FN_FN_FN(fnc)  \
-    rsDebug("Testing " #fnc, 0);    \
-    f1 = fnc(f1, f1, f1);           \
-    f2 = fnc(f2, f2, f2);           \
-    f3 = fnc(f3, f3, f3);           \
-    f4 = fnc(f4, f4, f4);
-
-#define TEST_FN_FUNC_FN_PIN(fnc)    \
-    rsDebug("Testing " #fnc, 0);    \
-    f1 = fnc(f1, (int*) &i1);       \
-    f2 = fnc(f2, (int2*) &i2);      \
-    f3 = fnc(f3, (int3*) &i3);      \
-    f4 = fnc(f4, (int4*) &i4);
-
-#define TEST_FN_FUNC_FN_FN_PIN(fnc) \
-    rsDebug("Testing " #fnc, 0);    \
-    f1 = fnc(f1, f1, (int*) &i1);   \
-    f2 = fnc(f2, f2, (int2*) &i2);  \
-    f3 = fnc(f3, f3, (int3*) &i3);  \
-    f4 = fnc(f4, f4, (int4*) &i4);
-
-#define TEST_IN_FUNC_FN(fnc)        \
-    rsDebug("Testing " #fnc, 0);    \
-    i1 = fnc(f1);                   \
-    i2 = fnc(f2);                   \
-    i3 = fnc(f3);                   \
-    i4 = fnc(f4);
-
-
-static bool test_fp_math(uint32_t index) {
-    bool failed = false;
-    start();
-
-    TEST_FN_FUNC_FN(acos);
-    TEST_FN_FUNC_FN(acosh);
-    TEST_FN_FUNC_FN(acospi);
-    TEST_FN_FUNC_FN(asin);
-    TEST_FN_FUNC_FN(asinh);
-    TEST_FN_FUNC_FN(asinpi);
-    TEST_FN_FUNC_FN(atan);
-    TEST_FN_FUNC_FN_FN(atan2);
-    TEST_FN_FUNC_FN(atanh);
-    TEST_FN_FUNC_FN(atanpi);
-    TEST_FN_FUNC_FN_FN(atan2pi);
-    TEST_FN_FUNC_FN(cbrt);
-    TEST_FN_FUNC_FN(ceil);
-    TEST_FN_FUNC_FN_FN(copysign);
-    TEST_FN_FUNC_FN(cos);
-    TEST_FN_FUNC_FN(cosh);
-    TEST_FN_FUNC_FN(cospi);
-    TEST_FN_FUNC_FN(erfc);
-    TEST_FN_FUNC_FN(erf);
-    TEST_FN_FUNC_FN(exp);
-    TEST_FN_FUNC_FN(exp2);
-    TEST_FN_FUNC_FN(exp10);
-    TEST_FN_FUNC_FN(expm1);
-    TEST_FN_FUNC_FN(fabs);
-    TEST_FN_FUNC_FN_FN(fdim);
-    TEST_FN_FUNC_FN(floor);
-    TEST_FN_FUNC_FN_FN_FN(fma);
-    TEST_FN_FUNC_FN_FN(fmax);
-    TEST_FN_FUNC_FN_F(fmax);
-    TEST_FN_FUNC_FN_FN(fmin);
-    TEST_FN_FUNC_FN_F(fmin);
-    TEST_FN_FUNC_FN_FN(fmod);
-    TEST_FN_FUNC_FN_PFN(fract);
-    TEST_FN_FUNC_FN_PIN(frexp);
-    TEST_FN_FUNC_FN_FN(hypot);
-    TEST_IN_FUNC_FN(ilogb);
-    TEST_FN_FUNC_FN_IN(ldexp);
-    TEST_FN_FUNC_FN_I(ldexp);
-    TEST_FN_FUNC_FN(lgamma);
-    TEST_FN_FUNC_FN_PIN(lgamma);
-    TEST_FN_FUNC_FN(log);
-    TEST_FN_FUNC_FN(log2);
-    TEST_FN_FUNC_FN(log10);
-    TEST_FN_FUNC_FN(log1p);
-    TEST_FN_FUNC_FN(logb);
-    TEST_FN_FUNC_FN_FN_FN(mad);
-    TEST_FN_FUNC_FN_PFN(modf);
-    // nan
-    TEST_FN_FUNC_FN_FN(nextafter);
-    TEST_FN_FUNC_FN_FN(pow);
-    TEST_FN_FUNC_FN_IN(pown);
-    TEST_FN_FUNC_FN_FN(powr);
-    TEST_FN_FUNC_FN_FN(remainder);
-    TEST_FN_FUNC_FN_FN_PIN(remquo);
-    TEST_FN_FUNC_FN(rint);
-    TEST_FN_FUNC_FN_IN(rootn);
-    TEST_FN_FUNC_FN(round);
-    TEST_FN_FUNC_FN(rsqrt);
-    TEST_FN_FUNC_FN(sin);
-    TEST_FN_FUNC_FN_PFN(sincos);
-    TEST_FN_FUNC_FN(sinh);
-    TEST_FN_FUNC_FN(sinpi);
-    TEST_FN_FUNC_FN(sqrt);
-    TEST_FN_FUNC_FN(tan);
-    TEST_FN_FUNC_FN(tanh);
-    TEST_FN_FUNC_FN(tanpi);
-    TEST_FN_FUNC_FN(tgamma);
-    TEST_FN_FUNC_FN(trunc);
-
-    float time = end(index);
-
-    if (failed) {
-        rsDebug("test_fp_math FAILED", time);
-    }
-    else {
-        rsDebug("test_fp_math PASSED", time);
-    }
-
-    return failed;
-}
-
 #define DECL_INT(prefix)            \
 volatile char prefix##_c_1 = 1;     \
 volatile char2 prefix##_c_2 = 1;    \
@@ -221,6 +65,10 @@
 volatile long prefix##_l_1 = 1;     \
 volatile ulong prefix##_ul_1 = 1;
 
+DECL_INT(res)
+DECL_INT(src1)
+DECL_INT(src2)
+
 #define TEST_INT_OP_TYPE(op, type)                      \
 rsDebug("Testing " #op " for " #type "1", i++);         \
 res_##type##_1 = src1_##type##_1 op src2_##type##_1;    \
@@ -243,9 +91,274 @@
 rsDebug("Testing " #op " for ul1", i++);    \
 res_ul_1 = src1_ul_1 op src2_ul_1;
 
-DECL_INT(res)
-DECL_INT(src1)
-DECL_INT(src2)
+#define TEST_XN_FUNC_YN(typeout, fnc, typein)   \
+    res_##typeout##_1 = fnc(src1_##typein##_1); \
+    res_##typeout##_2 = fnc(src1_##typein##_2); \
+    res_##typeout##_3 = fnc(src1_##typein##_3); \
+    res_##typeout##_4 = fnc(src1_##typein##_4);
+
+#define TEST_XN_FUNC_XN_XN(type, fnc)                       \
+    res_##type##_1 = fnc(src1_##type##_1, src2_##type##_1); \
+    res_##type##_2 = fnc(src1_##type##_2, src2_##type##_2); \
+    res_##type##_3 = fnc(src1_##type##_3, src2_##type##_3); \
+    res_##type##_4 = fnc(src1_##type##_4, src2_##type##_4);
+
+#define TEST_X_FUNC_X_X_X(type, fnc)    \
+    res_##type##_1 = fnc(src1_##type##_1, src2_##type##_1, src2_##type##_1);
+
+#define TEST_IN_FUNC_IN(fnc)        \
+    rsDebug("Testing " #fnc, 0);    \
+    TEST_XN_FUNC_YN(uc, fnc, uc)    \
+    TEST_XN_FUNC_YN(c, fnc, c)      \
+    TEST_XN_FUNC_YN(us, fnc, us)    \
+    TEST_XN_FUNC_YN(s, fnc, s)      \
+    TEST_XN_FUNC_YN(ui, fnc, ui)    \
+    TEST_XN_FUNC_YN(i, fnc, i)
+
+#define TEST_UIN_FUNC_IN(fnc)       \
+    rsDebug("Testing " #fnc, 0);    \
+    TEST_XN_FUNC_YN(uc, fnc, c)     \
+    TEST_XN_FUNC_YN(us, fnc, s)     \
+    TEST_XN_FUNC_YN(ui, fnc, i)     \
+
+#define TEST_IN_FUNC_IN_IN(fnc)     \
+    rsDebug("Testing " #fnc, 0);    \
+    TEST_XN_FUNC_XN_XN(uc, fnc)     \
+    TEST_XN_FUNC_XN_XN(c, fnc)      \
+    TEST_XN_FUNC_XN_XN(us, fnc)     \
+    TEST_XN_FUNC_XN_XN(s, fnc)      \
+    TEST_XN_FUNC_XN_XN(ui, fnc)     \
+    TEST_XN_FUNC_XN_XN(i, fnc)
+
+#define TEST_I_FUNC_I_I_I(fnc)      \
+    rsDebug("Testing " #fnc, 0);    \
+    TEST_X_FUNC_X_X_X(uc, fnc)      \
+    TEST_X_FUNC_X_X_X(c, fnc)       \
+    TEST_X_FUNC_X_X_X(us, fnc)      \
+    TEST_X_FUNC_X_X_X(s, fnc)       \
+    TEST_X_FUNC_X_X_X(ui, fnc)      \
+    TEST_X_FUNC_X_X_X(i, fnc)
+
+#define TEST_FN_FUNC_FN(fnc)        \
+    rsDebug("Testing " #fnc, 0);    \
+    f1 = fnc(f1);                   \
+    f2 = fnc(f2);                   \
+    f3 = fnc(f3);                   \
+    f4 = fnc(f4);
+
+#define TEST_FN_FUNC_FN_PFN(fnc)    \
+    rsDebug("Testing " #fnc, 0);    \
+    f1 = fnc(f1, (float*) &f1);     \
+    f2 = fnc(f2, (float2*) &f2);    \
+    f3 = fnc(f3, (float3*) &f3);    \
+    f4 = fnc(f4, (float4*) &f4);
+
+#define TEST_FN_FUNC_FN_FN(fnc)     \
+    rsDebug("Testing " #fnc, 0);    \
+    f1 = fnc(f1, f1);               \
+    f2 = fnc(f2, f2);               \
+    f3 = fnc(f3, f3);               \
+    f4 = fnc(f4, f4);
+
+#define TEST_F34_FUNC_F34_F34(fnc)  \
+    rsDebug("Testing " #fnc, 0);    \
+    f3 = fnc(f3, f3);               \
+    f4 = fnc(f4, f4);
+
+#define TEST_FN_FUNC_FN_F(fnc)      \
+    rsDebug("Testing " #fnc, 0);    \
+    f1 = fnc(f1, f1);               \
+    f2 = fnc(f2, f1);               \
+    f3 = fnc(f3, f1);               \
+    f4 = fnc(f4, f1);
+
+#define TEST_F_FUNC_FN(fnc)         \
+    rsDebug("Testing " #fnc, 0);    \
+    f1 = fnc(f1);                   \
+    f1 = fnc(f2);                   \
+    f1 = fnc(f3);                   \
+    f1 = fnc(f4);
+
+#define TEST_F_FUNC_FN_FN(fnc)      \
+    rsDebug("Testing " #fnc, 0);    \
+    f1 = fnc(f1, f1);               \
+    f1 = fnc(f2, f2);               \
+    f1 = fnc(f3, f3);               \
+    f1 = fnc(f4, f4);
+
+#define TEST_FN_FUNC_FN_IN(fnc)     \
+    rsDebug("Testing " #fnc, 0);    \
+    f1 = fnc(f1, i1);               \
+    f2 = fnc(f2, i2);               \
+    f3 = fnc(f3, i3);               \
+    f4 = fnc(f4, i4);
+
+#define TEST_FN_FUNC_FN_I(fnc)      \
+    rsDebug("Testing " #fnc, 0);    \
+    f1 = fnc(f1, i1);               \
+    f2 = fnc(f2, i1);               \
+    f3 = fnc(f3, i1);               \
+    f4 = fnc(f4, i1);
+
+#define TEST_FN_FUNC_FN_FN_FN(fnc)  \
+    rsDebug("Testing " #fnc, 0);    \
+    f1 = fnc(f1, f1, f1);           \
+    f2 = fnc(f2, f2, f2);           \
+    f3 = fnc(f3, f3, f3);           \
+    f4 = fnc(f4, f4, f4);
+
+#define TEST_FN_FUNC_FN_FN_F(fnc)   \
+    rsDebug("Testing " #fnc, 0);    \
+    f1 = fnc(f1, f1, f1);           \
+    f2 = fnc(f2, f1, f1);           \
+    f3 = fnc(f3, f1, f1);           \
+    f4 = fnc(f4, f1, f1);
+
+#define TEST_FN_FUNC_FN_PIN(fnc)    \
+    rsDebug("Testing " #fnc, 0);    \
+    f1 = fnc(f1, (int*) &i1);       \
+    f2 = fnc(f2, (int2*) &i2);      \
+    f3 = fnc(f3, (int3*) &i3);      \
+    f4 = fnc(f4, (int4*) &i4);
+
+#define TEST_FN_FUNC_FN_FN_PIN(fnc) \
+    rsDebug("Testing " #fnc, 0);    \
+    f1 = fnc(f1, f1, (int*) &i1);   \
+    f2 = fnc(f2, f2, (int2*) &i2);  \
+    f3 = fnc(f3, f3, (int3*) &i3);  \
+    f4 = fnc(f4, f4, (int4*) &i4);
+
+#define TEST_IN_FUNC_FN(fnc)        \
+    rsDebug("Testing " #fnc, 0);    \
+    i1 = fnc(f1);                   \
+    i2 = fnc(f2);                   \
+    i3 = fnc(f3);                   \
+    i4 = fnc(f4);
+
+static bool test_fp_math(uint32_t index) {
+    bool failed = false;
+    start();
+
+    TEST_FN_FUNC_FN(acos);
+    TEST_FN_FUNC_FN(acosh);
+    TEST_FN_FUNC_FN(acospi);
+    TEST_FN_FUNC_FN(asin);
+    TEST_FN_FUNC_FN(asinh);
+    TEST_FN_FUNC_FN(asinpi);
+    TEST_FN_FUNC_FN(atan);
+    TEST_FN_FUNC_FN_FN(atan2);
+    TEST_FN_FUNC_FN(atanh);
+    TEST_FN_FUNC_FN(atanpi);
+    TEST_FN_FUNC_FN_FN(atan2pi);
+    TEST_FN_FUNC_FN(cbrt);
+    TEST_FN_FUNC_FN(ceil);
+    TEST_FN_FUNC_FN_FN_FN(clamp);
+    TEST_FN_FUNC_FN_FN_F(clamp);
+    TEST_FN_FUNC_FN_FN(copysign);
+    TEST_FN_FUNC_FN(cos);
+    TEST_FN_FUNC_FN(cosh);
+    TEST_FN_FUNC_FN(cospi);
+    TEST_F34_FUNC_F34_F34(cross);
+    TEST_FN_FUNC_FN(degrees);
+    TEST_F_FUNC_FN_FN(distance);
+    TEST_F_FUNC_FN_FN(dot);
+    TEST_FN_FUNC_FN(erfc);
+    TEST_FN_FUNC_FN(erf);
+    TEST_FN_FUNC_FN(exp);
+    TEST_FN_FUNC_FN(exp2);
+    TEST_FN_FUNC_FN(exp10);
+    TEST_FN_FUNC_FN(expm1);
+    TEST_FN_FUNC_FN(fabs);
+    TEST_FN_FUNC_FN_FN(fdim);
+    TEST_FN_FUNC_FN(floor);
+    TEST_FN_FUNC_FN_FN_FN(fma);
+    TEST_FN_FUNC_FN_FN(fmax);
+    TEST_FN_FUNC_FN_F(fmax);
+    TEST_FN_FUNC_FN_FN(fmin);
+    TEST_FN_FUNC_FN_F(fmin);
+    TEST_FN_FUNC_FN_FN(fmod);
+    TEST_FN_FUNC_FN_PFN(fract);
+    TEST_FN_FUNC_FN_PIN(frexp);
+    TEST_FN_FUNC_FN_FN(hypot);
+    TEST_IN_FUNC_FN(ilogb);
+    TEST_FN_FUNC_FN_IN(ldexp);
+    TEST_FN_FUNC_FN_I(ldexp);
+    TEST_F_FUNC_FN(length);
+    TEST_FN_FUNC_FN(lgamma);
+    TEST_FN_FUNC_FN_PIN(lgamma);
+    TEST_FN_FUNC_FN(log);
+    TEST_FN_FUNC_FN(log2);
+    TEST_FN_FUNC_FN(log10);
+    TEST_FN_FUNC_FN(log1p);
+    TEST_FN_FUNC_FN(logb);
+    TEST_FN_FUNC_FN_FN_FN(mad);
+    TEST_FN_FUNC_FN_FN(max);
+    TEST_FN_FUNC_FN_F(max);
+    TEST_FN_FUNC_FN_FN(min);
+    TEST_FN_FUNC_FN_F(min);
+    TEST_FN_FUNC_FN_FN_FN(mix);
+    TEST_FN_FUNC_FN_FN_F(mix);
+    TEST_FN_FUNC_FN_PFN(modf);
+    // nan
+    TEST_FN_FUNC_FN_FN(nextafter);
+    TEST_FN_FUNC_FN(normalize);
+    TEST_FN_FUNC_FN_FN(pow);
+    TEST_FN_FUNC_FN_IN(pown);
+    TEST_FN_FUNC_FN_FN(powr);
+    TEST_FN_FUNC_FN(radians);
+    TEST_FN_FUNC_FN_FN(remainder);
+    TEST_FN_FUNC_FN_FN_PIN(remquo);
+    TEST_FN_FUNC_FN(rint);
+    TEST_FN_FUNC_FN_IN(rootn);
+    TEST_FN_FUNC_FN(round);
+    TEST_FN_FUNC_FN(rsqrt);
+    TEST_FN_FUNC_FN(sign);
+    TEST_FN_FUNC_FN(sin);
+    TEST_FN_FUNC_FN_PFN(sincos);
+    TEST_FN_FUNC_FN(sinh);
+    TEST_FN_FUNC_FN(sinpi);
+    TEST_FN_FUNC_FN(sqrt);
+    TEST_FN_FUNC_FN_FN(step);
+    TEST_FN_FUNC_FN_F(step);
+    TEST_FN_FUNC_FN(tan);
+    TEST_FN_FUNC_FN(tanh);
+    TEST_FN_FUNC_FN(tanpi);
+    TEST_FN_FUNC_FN(tgamma);
+    TEST_FN_FUNC_FN(trunc);
+
+    float time = end(index);
+
+    if (failed) {
+        rsDebug("test_fp_math FAILED", time);
+    }
+    else {
+        rsDebug("test_fp_math PASSED", time);
+    }
+
+    return failed;
+}
+
+static bool test_int_math(uint32_t index) {
+    bool failed = false;
+    start();
+
+    TEST_UIN_FUNC_IN(abs);
+    TEST_IN_FUNC_IN(clz);
+    TEST_IN_FUNC_IN_IN(min);
+    TEST_IN_FUNC_IN_IN(max);
+    TEST_I_FUNC_I_I_I(rsClamp);
+
+    float time = end(index);
+
+    if (failed) {
+        rsDebug("test_int_math FAILED", time);
+    }
+    else {
+        rsDebug("test_int_math PASSED", time);
+    }
+
+    return failed;
+}
 
 static bool test_basic_operators() {
     bool failed = false;
@@ -310,6 +423,7 @@
     bool failed = false;
     failed |= test_convert();
     failed |= test_fp_math(index);
+    failed |= test_int_math(index);
     failed |= test_basic_operators();
 
     if (failed) {
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
index 2f7b927..fb2c134 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
@@ -61,6 +61,7 @@
 import android.widget.EditText;
 
 import com.android.internal.R;
+import com.android.internal.telephony.TelephonyIntents;
 import com.android.internal.util.AsyncChannel;
 import com.android.internal.util.Protocol;
 import com.android.internal.util.State;
@@ -134,6 +135,8 @@
 
     /* Airplane mode changed */
     private static final int AIRPLANE_MODE_CHANGED          =   BASE + 6;
+    /* Emergency callback mode */
+    private static final int EMERGENCY_CALLBACK_MODE        =   BASE + 7;
 
     private final boolean mP2pSupported;
     private final String mDeviceType;
@@ -172,6 +175,7 @@
         IntentFilter filter = new IntentFilter();
         filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
         filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
+        filter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
         filter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
         mContext.registerReceiver(new WifiStateReceiver(), filter);
 
@@ -185,14 +189,19 @@
     private class WifiStateReceiver extends BroadcastReceiver {
         @Override
         public void onReceive(Context context, Intent intent) {
-            if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
+            String action = intent.getAction();
+            if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
                 mWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
                         WifiManager.WIFI_STATE_DISABLED);
-            } else if (intent.getAction().equals(WifiManager.WIFI_AP_STATE_CHANGED_ACTION)) {
+            } else if (action.equals(WifiManager.WIFI_AP_STATE_CHANGED_ACTION)) {
                 mWifiApState = intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_STATE,
                         WifiManager.WIFI_AP_STATE_DISABLED);
-            } else if (intent.getAction().equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
+            } else if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
                 mP2pStateMachine.sendMessage(AIRPLANE_MODE_CHANGED);
+            } else if (action.equals(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED)) {
+                if (intent.getBooleanExtra("phoneinECMState", false) == true) {
+                    mP2pStateMachine.sendMessage(EMERGENCY_CALLBACK_MODE);
+                }
             }
         }
     }
@@ -361,6 +370,9 @@
                 case AIRPLANE_MODE_CHANGED:
                     if (isAirplaneModeOn()) sendMessage(WifiP2pManager.DISABLE_P2P);
                     break;
+                case EMERGENCY_CALLBACK_MODE:
+                    sendMessage(WifiP2pManager.DISABLE_P2P);
+                    break;
                     // Ignore
                 case WIFI_DISABLE_USER_ACCEPT:
                 case WIFI_DISABLE_USER_REJECT: