merge in jb-mr1-release history after reset to jb-mr1-dev
diff --git a/build/phone-xhdpi-1024-dalvik-heap.mk b/build/phone-xhdpi-1024-dalvik-heap.mk
index 0e850e8..221227d 100644
--- a/build/phone-xhdpi-1024-dalvik-heap.mk
+++ b/build/phone-xhdpi-1024-dalvik-heap.mk
@@ -14,11 +14,11 @@
 # limitations under the License.
 #
 
-# Provides overrides to configure the Dalvik heap for a standard tablet device.
+# Provides overrides to configure the Dalvik heap for a xhdpi phone
 
 PRODUCT_PROPERTY_OVERRIDES += \
     dalvik.vm.heapstartsize=8m \
-    dalvik.vm.heapgrowthlimit=64m \
+    dalvik.vm.heapgrowthlimit=96m \
     dalvik.vm.heapsize=256m \
     dalvik.vm.heaptargetutilization=0.75 \
     dalvik.vm.heapminfree=512k \
diff --git a/build/phone-xhdpi-2048-dalvik-heap.mk b/build/phone-xhdpi-2048-dalvik-heap.mk
new file mode 100644
index 0000000..8a3f6bb
--- /dev/null
+++ b/build/phone-xhdpi-2048-dalvik-heap.mk
@@ -0,0 +1,26 @@
+#
+# Copyright (C) 2012 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Provides overrides to configure the Dalvik heap for a 2G phone
+# 192m of RAM gives enough space for 5 8 megapixel camera bitmaps in RAM.
+
+PRODUCT_PROPERTY_OVERRIDES += \
+    dalvik.vm.heapstartsize=8m \
+    dalvik.vm.heapgrowthlimit=192m \
+    dalvik.vm.heapsize=768m \
+    dalvik.vm.heaptargetutilization=0.75 \
+    dalvik.vm.heapminfree=512k \
+    dalvik.vm.heapmaxfree=8m
diff --git a/cmds/dumpstate/dumpstate.c b/cmds/dumpstate/dumpstate.c
index 56ba3c8..ef5c2e9 100644
--- a/cmds/dumpstate/dumpstate.c
+++ b/cmds/dumpstate/dumpstate.c
@@ -166,7 +166,7 @@
 
     run_command("SYSTEM SETTINGS", 20, SU_PATH, "root", "sqlite3",
             "/data/data/com.android.providers.settings/databases/settings.db",
-            "pragma user_version; select * from system; select * from secure;", NULL);
+            "pragma user_version; select * from system; select * from secure; select * from global;", NULL);
 
     /* The following have a tendency to get wedged when wifi drivers/fw goes belly-up. */
     run_command("NETWORK INTERFACES", 10, SU_PATH, "root", "netcfg", NULL);
diff --git a/services/sensorservice/Fusion.cpp b/services/sensorservice/Fusion.cpp
index 93d6127..b88a647 100644
--- a/services/sensorservice/Fusion.cpp
+++ b/services/sensorservice/Fusion.cpp
@@ -201,15 +201,15 @@
     // q11 = su^2.dt
     //
 
-    const float dT2 = dT*dT;
-    const float dT3 = dT2*dT;
-
-    // variance of integrated output at 1/dT Hz (random drift)
-    const float q00 = gyroVAR * dT + 0.33333f * biasVAR * dT3;
+    // variance of integrated output at 1/dT Hz
+    // (random drift)
+    const float q00 = gyroVAR * dT;
 
     // variance of drift rate ramp
     const float q11 = biasVAR * dT;
-    const float q10 = 0.5f * biasVAR * dT2;
+
+    const float u   = q11 / dT;
+    const float q10 = 0.5f*u*dT*dT;
     const float q01 = q10;
 
     GQGt[0][0] =  q00;      // rad^2
@@ -220,22 +220,6 @@
     // initial covariance: Var{ x(t0) }
     // TODO: initialize P correctly
     P = 0;
-
-    // it is unclear how to set the initial covariance. It does affect
-    // how quickly the fusion converges. Experimentally it would take
-    // about 10 seconds at 200 Hz to estimate the gyro-drift with an
-    // initial covariance of 0, and about a second with an initial covariance
-    // of about 1 deg/s.
-    const float covv = 0;
-    const float covu = 0.5f * (float(M_PI) / 180);
-    mat33_t& Pv = P[0][0];
-    Pv[0][0] = covv;
-    Pv[1][1] = covv;
-    Pv[2][2] = covv;
-    mat33_t& Pu = P[1][1];
-    Pu[0][0] = covu;
-    Pu[1][1] = covu;
-    Pu[2][2] = covu;
 }
 
 bool Fusion::hasEstimate() const {
@@ -373,11 +357,6 @@
 
 mat34_t Fusion::getF(const vec4_t& q) {
     mat34_t F;
-
-    // This is used to compute the derivative of q
-    // F = | [q.xyz]x |
-    //     |  -q.xyz  |
-
     F[0].x = q.w;   F[1].x =-q.z;   F[2].x = q.y;
     F[0].y = q.z;   F[1].y = q.w;   F[2].y =-q.x;
     F[0].z =-q.y;   F[1].z = q.x;   F[2].z = q.w;
@@ -389,18 +368,10 @@
     const vec4_t q  = x0;
     const vec3_t b  = x1;
     const vec3_t we = w - b;
+    const vec4_t dq = getF(q)*((0.5f*dT)*we);
+    x0 = normalize_quat(q + dq);
 
-    // q(k+1) = O(we)*q(k)
-    // --------------------
-    //
-    // O(w) = | cos(0.5*||w||*dT)*I33 - [psi]x                   psi |
-    //        | -psi'                              cos(0.5*||w||*dT) |
-    //
-    // psi = sin(0.5*||w||*dT)*w / ||w||
-    //
-    //
     // P(k+1) = Phi(k)*P(k)*Phi(k)' + G*Q(k)*G'
-    // ----------------------------------------
     //
     // G = | -I33    0 |
     //     |    0  I33 |
@@ -421,26 +392,13 @@
     const mat33_t wx(crossMatrix(we, 0));
     const mat33_t wx2(wx*wx);
     const float lwedT = length(we)*dT;
-    const float hlwedT = 0.5f*lwedT;
     const float ilwe = 1/length(we);
     const float k0 = (1-cosf(lwedT))*(ilwe*ilwe);
     const float k1 = sinf(lwedT);
-    const float k2 = cosf(hlwedT);
-    const vec3_t psi(sinf(hlwedT)*ilwe*we);
-    const mat33_t O33(crossMatrix(-psi, k2));
-    mat44_t O;
-    O[0].xyz = O33[0];  O[0].w = -psi.x;
-    O[1].xyz = O33[1];  O[1].w = -psi.y;
-    O[2].xyz = O33[2];  O[2].w = -psi.z;
-    O[3].xyz = psi;     O[3].w = k2;
 
     Phi[0][0] = I33 - wx*(k1*ilwe) + wx2*k0;
     Phi[1][0] = wx*k0 - I33dT - wx2*(ilwe*ilwe*ilwe)*(lwedT-k1);
 
-    x0 = O*q;
-    if (x0.w < 0)
-        x0 = -x0;
-
     P = Phi*P*transpose(Phi) + GQGt;
 
     checkState();
@@ -467,12 +425,7 @@
     K[1] = transpose(P[1][0])*LtSi;
 
     // update...
-    // P = (I-K*H) * P
-    // P -= K*H*P
-    // | K0 | * | L 0 | * P = | K0*L  0 | * | P00  P10 | = | K0*L*P00  K0*L*P10 |
-    // | K1 |                 | K1*L  0 |   | P01  P11 |   | K1*L*P00  K1*L*P10 |
-    // Note: the Joseph form is numerically more stable and given by:
-    //     P = (I-KH) * P * (I-KH)' + K*R*R'
+    // P -= K*H*P;
     const mat33_t K0L(K[0] * L);
     const mat33_t K1L(K[1] * L);
     P[0][0] -= K0L*P[0][0];
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
index 960fb0e..d4adad2 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -613,6 +613,7 @@
         const DisplayData& disp(mDisplayData[id]);
         if (disp.framebufferTarget) {
             fd = disp.framebufferTarget->releaseFenceFd;
+            disp.framebufferTarget->acquireFenceFd = -1;
             disp.framebufferTarget->releaseFenceFd = -1;
         }
     }