Merge "Fix bug with display lists and layout." into honeycomb
diff --git a/core/java/com/android/internal/widget/PasswordEntryKeyboardHelper.java b/core/java/com/android/internal/widget/PasswordEntryKeyboardHelper.java
index a1a28ac..65973b6 100644
--- a/core/java/com/android/internal/widget/PasswordEntryKeyboardHelper.java
+++ b/core/java/com/android/internal/widget/PasswordEntryKeyboardHelper.java
@@ -128,7 +128,8 @@
                 final boolean visiblePassword = Settings.System.getInt(
                         mContext.getContentResolver(),
                         Settings.System.TEXT_SHOW_PASSWORD, 1) != 0;
-                mKeyboardView.setPreviewEnabled(visiblePassword);
+                final boolean enablePreview = false; // TODO: grab from configuration
+                mKeyboardView.setPreviewEnabled(visiblePassword && enablePreview);
                 break;
             case KEYBOARD_MODE_NUMERIC:
                 mKeyboardView.setKeyboard(mNumericKeyboard);
diff --git a/libs/rs/java/tests/src/com/android/rs/test/math.rs b/libs/rs/java/tests/src/com/android/rs/test/math.rs
index 02993fe..8cad82b 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/math.rs
+++ b/libs/rs/java/tests/src/com/android/rs/test/math.rs
@@ -12,6 +12,31 @@
 volatile int3 i3;
 volatile int4 i4;
 
+volatile uint ui1;
+volatile uint2 ui2;
+volatile uint3 ui3;
+volatile uint4 ui4;
+
+volatile short s1;
+volatile short2 s2;
+volatile short3 s3;
+volatile short4 s4;
+
+volatile ushort us1;
+volatile ushort2 us2;
+volatile ushort3 us3;
+volatile ushort4 us4;
+
+volatile char c1;
+volatile char2 c2;
+volatile char3 c3;
+volatile char4 c4;
+
+volatile uchar uc1;
+volatile uchar2 uc2;
+volatile uchar3 uc3;
+volatile uchar4 uc4;
+
 #define TEST_FN_FUNC_FN(fnc)        \
     rsDebug("Testing " #fnc, 0);    \
     f1 = fnc(f1);                   \
@@ -168,9 +193,124 @@
     return failed;
 }
 
+#define DECL_INT(prefix)            \
+volatile char prefix##_c_1 = 1;     \
+volatile char2 prefix##_c_2 = 1;    \
+volatile char3 prefix##_c_3 = 1;    \
+volatile char4 prefix##_c_4 = 1;    \
+volatile uchar prefix##_uc_1 = 1;   \
+volatile uchar2 prefix##_uc_2 = 1;  \
+volatile uchar3 prefix##_uc_3 = 1;  \
+volatile uchar4 prefix##_uc_4 = 1;  \
+volatile short prefix##_s_1 = 1;    \
+volatile short2 prefix##_s_2 = 1;   \
+volatile short3 prefix##_s_3 = 1;   \
+volatile short4 prefix##_s_4 = 1;   \
+volatile ushort prefix##_us_1 = 1;  \
+volatile ushort2 prefix##_us_2 = 1; \
+volatile ushort3 prefix##_us_3 = 1; \
+volatile ushort4 prefix##_us_4 = 1; \
+volatile int prefix##_i_1 = 1;      \
+volatile int2 prefix##_i_2 = 1;     \
+volatile int3 prefix##_i_3 = 1;     \
+volatile int4 prefix##_i_4 = 1;     \
+volatile uint prefix##_ui_1 = 1;    \
+volatile uint2 prefix##_ui_2 = 1;   \
+volatile uint3 prefix##_ui_3 = 1;   \
+volatile uint4 prefix##_ui_4 = 1;   \
+volatile long prefix##_l_1 = 1;     \
+volatile ulong prefix##_ul_1 = 1;
+
+#define TEST_INT_OP_TYPE(op, type)                      \
+rsDebug("Testing " #op " for " #type "1", i++);         \
+res_##type##_1 = src1_##type##_1 op src2_##type##_1;    \
+rsDebug("Testing " #op " for " #type "2", i++);         \
+res_##type##_2 = src1_##type##_2 op src2_##type##_2;    \
+rsDebug("Testing " #op " for " #type "3", i++);         \
+res_##type##_3 = src1_##type##_3 op src2_##type##_3;    \
+rsDebug("Testing " #op " for " #type "4", i++);         \
+res_##type##_4 = src1_##type##_4 op src2_##type##_4;
+
+#define TEST_INT_OP(op)                     \
+TEST_INT_OP_TYPE(op, c)                     \
+TEST_INT_OP_TYPE(op, uc)                    \
+TEST_INT_OP_TYPE(op, s)                     \
+TEST_INT_OP_TYPE(op, us)                    \
+TEST_INT_OP_TYPE(op, i)                     \
+TEST_INT_OP_TYPE(op, ui)                    \
+rsDebug("Testing " #op " for l1", i++);     \
+res_l_1 = src1_l_1 op src2_l_1;             \
+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)
+
+static bool test_basic_operators() {
+    bool failed = false;
+    int i = 0;
+
+    TEST_INT_OP(+);
+    TEST_INT_OP(-);
+    TEST_INT_OP(*);
+    TEST_INT_OP(/);
+    TEST_INT_OP(%);
+    TEST_INT_OP(<<);
+    TEST_INT_OP(>>);
+
+    if (failed) {
+        rsDebug("test_basic_operators FAILED", 0);
+    }
+    else {
+        rsDebug("test_basic_operators PASSED", 0);
+    }
+
+    return failed;
+}
+
+#define TEST_CVT(to, from, type)                        \
+rsDebug("Testing convert from " #from " to " #to, 0);   \
+to##1 = from##1;                                        \
+to##2 = convert_##type##2(from##2);                     \
+to##3 = convert_##type##3(from##3);                     \
+to##4 = convert_##type##4(from##4);
+
+#define TEST_CVT_MATRIX(to, type)   \
+TEST_CVT(to, c, type);              \
+TEST_CVT(to, uc, type);             \
+TEST_CVT(to, s, type);              \
+TEST_CVT(to, us, type);             \
+TEST_CVT(to, i, type);              \
+TEST_CVT(to, ui, type);             \
+TEST_CVT(to, f, type);              \
+
+static bool test_convert() {
+    bool failed = false;
+
+    TEST_CVT_MATRIX(c, char);
+    TEST_CVT_MATRIX(uc, uchar);
+    TEST_CVT_MATRIX(s, short);
+    TEST_CVT_MATRIX(us, ushort);
+    TEST_CVT_MATRIX(i, int);
+    TEST_CVT_MATRIX(ui, uint);
+    TEST_CVT_MATRIX(f, float);
+
+    if (failed) {
+        rsDebug("test_convert FAILED", 0);
+    }
+    else {
+        rsDebug("test_convert PASSED", 0);
+    }
+
+    return failed;
+}
+
 void math_test(uint32_t index, int test_num) {
     bool failed = false;
+    failed |= test_convert();
     failed |= test_fp_math(index);
+    failed |= test_basic_operators();
 
     if (failed) {
         rsSendToClientBlocking(RS_MSG_TEST_FAILED);
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index f550d98..beb4d72 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -305,6 +305,14 @@
     return a % b;
 }
 
+unsigned int SC_udivsi3(unsigned int a, unsigned int b) {
+    return a / b;
+}
+
+unsigned int SC_umodsi3(unsigned int a, unsigned int b) {
+    return a % b;
+}
+
 int SC_getAllocation(const void *ptr) {
     GET_TLS();
     const Allocation *alloc = sc->ptrToAllocation(ptr);
@@ -363,6 +371,8 @@
 static ScriptCState::SymbolTable_t gSyms[] = {
     { "__divsi3", (void *)&SC_divsi3, true },
     { "__modsi3", (void *)&SC_modsi3, true },
+    { "__udivsi3", (void *)&SC_udivsi3, true },
+    { "__umodsi3", (void *)&SC_umodsi3, true },
 
     // allocation
     { "_Z19rsAllocationGetDimX13rs_allocation", (void *)&SC_allocGetDimX, true },
diff --git a/libs/rs/scriptc/rs_core.rsh b/libs/rs/scriptc/rs_core.rsh
index f3e0ab0..21c0f7b 100644
--- a/libs/rs/scriptc/rs_core.rsh
+++ b/libs/rs/scriptc/rs_core.rsh
@@ -683,7 +683,7 @@
 rsQuaternionMultiply(rs_quaternion *q, const rs_quaternion *rhs) {
     q->w = -q->x*rhs->x - q->y*rhs->y - q->z*rhs->z + q->w*rhs->w;
     q->x =  q->x*rhs->w + q->y*rhs->z - q->z*rhs->y + q->w*rhs->x;
-    q->y = -q->x*rhs->z + q->y*rhs->w + q->z*rhs->z + q->w*rhs->y;
+    q->y = -q->x*rhs->z + q->y*rhs->w + q->z*rhs->x + q->w*rhs->y;
     q->z =  q->x*rhs->y - q->y*rhs->x + q->z*rhs->w + q->w*rhs->z;
 }
 
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index eeb224c..2c8403c 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -677,8 +677,7 @@
 
             // stop intercepting input
             mDragState.unregister();
-            mInputMonitor.setUpdateInputWindowsNeededLw();
-            mInputMonitor.updateInputWindowsLw();
+            mInputMonitor.updateInputWindowsLw(true /*force*/);
 
             // free our resources and drop all the object references
             mDragState.reset();
@@ -2382,6 +2381,8 @@
                 res |= WindowManagerImpl.ADD_FLAG_APP_VISIBLE;
             }
 
+            mInputMonitor.setUpdateInputWindowsNeededLw();
+
             boolean focusChanged = false;
             if (win.canReceiveKeys()) {
                 focusChanged = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_ASSIGN_LAYERS,
@@ -2404,7 +2405,7 @@
             if (focusChanged) {
                 finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
             }
-            mInputMonitor.updateInputWindowsLw();
+            mInputMonitor.updateInputWindowsLw(false /*force*/);
 
             if (localLOGV) Slog.v(
                 TAG, "New client " + client.asBinder()
@@ -2484,7 +2485,7 @@
                 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
                         false /*updateInputWindows*/);
                 performLayoutAndPlaceSurfacesLocked();
-                mInputMonitor.updateInputWindowsLw();
+                mInputMonitor.updateInputWindowsLw(false /*force*/);
                 if (win.mAppToken != null) {
                     win.mAppToken.updateReportedVisibilityLocked();
                 }
@@ -2600,8 +2601,7 @@
             }
         }
         
-        mInputMonitor.setUpdateInputWindowsNeededLw();
-        mInputMonitor.updateInputWindowsLw();
+        mInputMonitor.updateInputWindowsLw(true /*force*/);
     }
 
     private static void logSurface(WindowState w, String msg, RuntimeException where) {
@@ -2851,8 +2851,7 @@
                         outSurface.release();
                     }
                 } catch (Exception e) {
-                    mInputMonitor.setUpdateInputWindowsNeededLw();
-                    mInputMonitor.updateInputWindowsLw();
+                    mInputMonitor.updateInputWindowsLw(true /*force*/);
                     
                     Slog.w(TAG, "Exception thrown when creating surface for client "
                              + client + " (" + win.mAttrs.getTitle() + ")",
@@ -2996,8 +2995,7 @@
 
             inTouchMode = mInTouchMode;
             
-            mInputMonitor.setUpdateInputWindowsNeededLw();
-            mInputMonitor.updateInputWindowsLw();
+            mInputMonitor.updateInputWindowsLw(true /*force*/);
         }
 
         if (configChanged) {
@@ -3380,8 +3378,7 @@
                     }
                 }
 
-                mInputMonitor.setUpdateInputWindowsNeededLw();
-                mInputMonitor.updateInputWindowsLw();
+                mInputMonitor.updateInputWindowsLw(true /*force*/);
             } else {
                 Slog.w(TAG, "Attempted to remove non-existing token: " + token);
             }
@@ -4042,7 +4039,7 @@
                             false /*updateInputWindows*/);
                     performLayoutAndPlaceSurfacesLocked();
                 }
-                mInputMonitor.updateInputWindowsLw();
+                mInputMonitor.updateInputWindowsLw(false /*force*/);
             }
         }
 
@@ -4479,8 +4476,9 @@
                 updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
                         false /*updateInputWindows*/);
                 mLayoutNeeded = true;
+                mInputMonitor.setUpdateInputWindowsNeededLw();
                 performLayoutAndPlaceSurfacesLocked();
-                mInputMonitor.updateInputWindowsLw();
+                mInputMonitor.updateInputWindowsLw(false /*force*/);
             }
             Binder.restoreCallingIdentity(origId);
         }
@@ -4517,13 +4515,14 @@
         pos = reAddAppWindowsLocked(pos, wtoken);
 
         if (updateFocusAndLayout) {
+            mInputMonitor.setUpdateInputWindowsNeededLw();
             if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
                     false /*updateInputWindows*/)) {
                 assignLayersLocked();
             }
             mLayoutNeeded = true;
             performLayoutAndPlaceSurfacesLocked();
-            mInputMonitor.updateInputWindowsLw();
+            mInputMonitor.updateInputWindowsLw(false /*force*/);
         }
     }
 
@@ -4549,13 +4548,14 @@
             }
         }
 
+        mInputMonitor.setUpdateInputWindowsNeededLw();
         if (!updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
                 false /*updateInputWindows*/)) {
             assignLayersLocked();
         }
         mLayoutNeeded = true;
         performLayoutAndPlaceSurfacesLocked();
-        mInputMonitor.updateInputWindowsLw();
+        mInputMonitor.updateInputWindowsLw(false /*force*/);
 
         //dump();
     }
@@ -5909,8 +5909,8 @@
         }
 
         /* Updates the cached window information provided to the input dispatcher. */
-        public void updateInputWindowsLw() {
-            if (!mUpdateInputWindowsNeeded) {
+        public void updateInputWindowsLw(boolean force) {
+            if (!force && !mUpdateInputWindowsNeeded) {
                 return;
             }
             mUpdateInputWindowsNeeded = false;
@@ -6060,7 +6060,7 @@
                 setUpdateInputWindowsNeededLw();
 
                 if (updateInputWindows) {
-                    updateInputWindowsLw();
+                    updateInputWindowsLw(false /*force*/);
                 }
             }
         }
@@ -6088,8 +6088,7 @@
                 }
                 
                 window.paused = true;
-                setUpdateInputWindowsNeededLw();
-                updateInputWindowsLw();
+                updateInputWindowsLw(true /*force*/);
             }
         }
         
@@ -6100,8 +6099,7 @@
                 }
                 
                 window.paused = false;
-                setUpdateInputWindowsNeededLw();
-                updateInputWindowsLw();
+                updateInputWindowsLw(true /*force*/);
             }
         }
         
@@ -6577,15 +6575,13 @@
                 // the actual drag event dispatch stuff in the dragstate
 
                 mDragState.register();
-                mInputMonitor.setUpdateInputWindowsNeededLw();
-                mInputMonitor.updateInputWindowsLw();
+                mInputMonitor.updateInputWindowsLw(true /*force*/);
                 if (!mInputManager.transferTouchFocus(callingWin.mInputChannel,
                         mDragState.mServerChannel)) {
                     Slog.e(TAG, "Unable to transfer touch focus");
                     mDragState.unregister();
                     mDragState = null;
-                    mInputMonitor.setUpdateInputWindowsNeededLw();
-                    mInputMonitor.updateInputWindowsLw();
+                    mInputMonitor.updateInputWindowsLw(true /*force*/);
                     return false;
                 }
 
@@ -9183,8 +9179,7 @@
                         // !!! TODO: ANR the app that has failed to start the drag in time
                         if (mDragState != null) {
                             mDragState.unregister();
-                            mInputMonitor.setUpdateInputWindowsNeededLw();
-                            mInputMonitor.updateInputWindowsLw();
+                            mInputMonitor.updateInputWindowsLw(true /*force*/);
                             mDragState.reset();
                             mDragState = null;
                         }
@@ -9584,7 +9579,7 @@
         // Window frames may have changed.  Tell the input dispatcher about it.
         mInputMonitor.setUpdateInputWindowsNeededLw();
         if (updateInputWindows) {
-            mInputMonitor.updateInputWindowsLw();
+            mInputMonitor.updateInputWindowsLw(false /*force*/);
         }
 
         return mPolicy.finishLayoutLw();
@@ -10858,8 +10853,7 @@
         }
 
         // Finally update all input windows now that the window changes have stabilized.
-        mInputMonitor.setUpdateInputWindowsNeededLw();
-        mInputMonitor.updateInputWindowsLw();
+        mInputMonitor.updateInputWindowsLw(true /*force*/);
 
         setHoldScreenLocked(holdScreen != null);
         if (screenBrightness < 0 || screenBrightness > 1.0f) {