Merge change 21047

* changes:
  Fix build break.
diff --git a/core/java/android/provider/Im.java b/core/java/android/provider/Im.java
index a054132..b11abe8 100644
--- a/core/java/android/provider/Im.java
+++ b/core/java/android/provider/Im.java
@@ -2101,17 +2101,60 @@
 
     }
 
+
+    /**
+     * Columns for IM branding resource map cache table. This table caches the result of
+     * loading the branding resources to speed up IM landing page start.
+     */
+    public interface BrandingResourceMapCacheColumns {
+        /**
+         * The provider ID
+         * <P>Type: INTEGER</P>
+         */
+        String PROVIDER_ID = "provider_id";
+        /**
+         * The application resource ID
+         * <P>Type: INTEGER</P>
+         */
+        String APP_RES_ID = "app_res_id";
+        /**
+         * The plugin resource ID
+         * <P>Type: INTEGER</P>
+         */
+        String PLUGIN_RES_ID = "plugin_res_id";
+    }
+
+    /**
+     * The table for caching the result of loading IM branding resources.
+     */
+    public static final class BrandingResourceMapCache
+        implements BaseColumns, BrandingResourceMapCacheColumns {
+        /**
+         * The content:// style URL for this table.
+         */
+        public static final Uri CONTENT_URI = Uri.parse("content://im/brandingResMapCache");
+    }
+
+
+
+    /**
+     * //TODO: move these to MCS specific provider.
+     * The following are MCS stuff, and should really live in a separate provider specific to
+     * MCS code.
+     */
+
     /**
      * Columns from OutgoingRmq table
      */
     public interface OutgoingRmqColumns {
         String RMQ_ID = "rmq_id";
-        String TYPE = "type";
         String TIMESTAMP = "ts";
         String DATA = "data";
+        String PROTOBUF_TAG = "type";
     }
 
     /**
+     * //TODO: we should really move these to their own provider and database.
      * The table for storing outgoing rmq packets.
      */
     public static final class OutgoingRmq implements BaseColumns, OutgoingRmqColumns {
@@ -2174,6 +2217,7 @@
     }
 
     /**
+     * //TODO: move these out into their own provider and database
      * The table for storing the last client rmq id sent to the server.
      */
     public static final class LastRmqId implements BaseColumns, LastRmqIdColumns {
@@ -2234,35 +2278,21 @@
     }
 
     /**
-     * Columns for IM branding resource map cache table. This table caches the result of
-     * loading the branding resources to speed up IM landing page start.
+     * Columns for the s2dRmqIds table, which stores the server-to-device message
+     * persistent ids. These are used in the RMQ2 protocol, where in the login request, the
+     * client selective acks these s2d ids to the server.
      */
-    public interface BrandingResourceMapCacheColumns {
-        /**
-         * The provider ID
-         * <P>Type: INTEGER</P>
-         */
-        String PROVIDER_ID = "provider_id";
-        /**
-         * The application resource ID
-         * <P>Type: INTEGER</P>
-         */
-        String APP_RES_ID = "app_res_id";
-        /**
-         * The plugin resource ID
-         * <P>Type: INTEGER</P>
-         */
-        String PLUGIN_RES_ID = "plugin_res_id";
+    public interface ServerToDeviceRmqIdsColumn {
+        String RMQ_ID = "rmq_id";
     }
 
-    /**
-     * The table for caching the result of loading IM branding resources.
-     */
-    public static final class BrandingResourceMapCache
-        implements BaseColumns, BrandingResourceMapCacheColumns {
+    public static final class ServerToDeviceRmqIds implements BaseColumns,
+            ServerToDeviceRmqIdsColumn {
+
         /**
          * The content:// style URL for this table.
          */
-        public static final Uri CONTENT_URI = Uri.parse("content://im/brandingResMapCache");
+        public static final Uri CONTENT_URI = Uri.parse("content://im/s2dids");
     }
+
 }
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index e1b8e99..85a2041 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -2908,7 +2908,52 @@
          * the retrying.
          */
         public static final String GTALK_MAX_RETRIES_FOR_AUTH_EXPIRED =
-            "gtalk_max_retries_for_auth_expired";
+                "gtalk_max_retries_for_auth_expired";
+
+        /**
+         * a boolean setting indicating whether the GTalkService should use RMQ2 protocol or not.
+         */
+        public static final String GTALK_USE_RMQ2_PROTOCOL =
+                "gtalk_use_rmq2";
+
+        /**
+         * a boolean setting indicating whether the GTalkService should support both RMQ and
+         * RMQ2 protocols. This setting is true for the transitional period when we need to
+         * support both protocols.
+         */
+        public static final String GTALK_SUPPORT_RMQ_AND_RMQ2_PROTOCOLS =
+                "gtalk_support_rmq_and_rmq2";
+
+        /**
+         * a boolean setting controlling whether the rmq2 protocol will include stream ids in
+         * the protobufs. This is used for debugging.
+         */
+        public static final String GTALK_RMQ2_INCLUDE_STREAM_ID =
+                "gtalk_rmq2_include_stream_id";
+
+        /**
+         * This is gdata url to lookup album and picture info from picasa web.
+         */
+        public static final String GTALK_PICASA_ALBUM_URL =
+                "gtalk_picasa_album_url";
+
+        /**
+         * This is the url to lookup picture info from flickr.
+         */
+        public static final String GTALK_FLICKR_PHOTO_INFO_URL =
+                "gtalk_flickr_photo_info_url";
+
+        /**
+         * This is the url to lookup an actual picture from flickr.
+         */
+        public static final String GTALK_FLICKR_PHOTO_URL =
+                "gtalk_flickr_photo_url";
+
+        /**
+         * This is the gdata url to lookup info on a youtube video.
+         */
+        public static final String GTALK_YOUTUBE_VIDEO_URL =
+                "gtalk_youtube_video_url";
 
         /**
          * This is the url for getting the app token for server-to-device push messaging.
@@ -2916,37 +2961,6 @@
         public static final String PUSH_MESSAGING_REGISTRATION_URL =
                 "push_messaging_registration_url";
 
-        /**
-         * This is gdata url to lookup album and picture info from picasa web.
-         */
-        public static final String GTALK_PICASA_ALBUM_URL =
-            "gtalk_picasa_album_url";
-
-        /**
-         * This is the url to lookup picture info from flickr.
-         */
-        public static final String GTALK_FLICKR_PHOTO_INFO_URL =
-            "gtalk_flickr_photo_info_url";
-
-        /**
-         * This is the url to lookup an actual picture from flickr.
-         */
-        public static final String GTALK_FLICKR_PHOTO_URL =
-            "gtalk_flickr_photo_url";
-
-        /**
-         * This is the gdata url to lookup info on a youtube video.
-         */
-        public static final String GTALK_YOUTUBE_VIDEO_URL =
-            "gtalk_youtube_video_url";
-
-
-        /**
-         * This is the url for getting the app token for server-to-device data messaging.
-         */
-        public static final String DATA_MESSAGE_GET_APP_TOKEN_URL =
-                "data_messaging_get_app_token_url";
-
 	/**
 	 * Use android://&lt;it&gt; routing infos for Google Sync Server subcriptions.
 	 */
diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java
index a9822f8..6cc794b 100644
--- a/core/java/android/widget/LinearLayout.java
+++ b/core/java/android/widget/LinearLayout.java
@@ -59,7 +59,7 @@
      * Note: this is orthogonal to {@link #mBaselineAligned}, which is concerned
      * with whether the children of this layout are baseline aligned.
      */
-    private int mBaselineAlignedChildIndex = 0;
+    private int mBaselineAlignedChildIndex = -1;
 
     /**
      * The additional offset to the child's baseline.
diff --git a/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java b/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java
index e1bf5ca..7266ee3 100644
--- a/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java
+++ b/core/java/com/android/internal/service/wallpaper/ImageWallpaper.java
@@ -121,6 +121,7 @@
                     final Drawable background = mBackground;
                     //background.setBounds(frame);
                     c.translate(mXOffset, mYOffset);
+                    c.drawColor(0xff000000);
                     background.draw(c);
                 }
                 sh.unlockCanvasAndPost(c);
diff --git a/services/java/com/android/server/InputDevice.java b/services/java/com/android/server/InputDevice.java
index cb23c45..e1bce73 100644
--- a/services/java/com/android/server/InputDevice.java
+++ b/services/java/com/android/server/InputDevice.java
@@ -42,6 +42,10 @@
     long mKeyDownTime = 0;
     int mMetaKeysState = 0;
     
+    // For use by KeyInputQueue for keeping track of the current touch
+    // data in the old non-multi-touch protocol.
+    final int[] curTouchVals = new int[MotionEvent.NUM_SAMPLE_DATA * 2];
+    
     final MotionState mAbs = new MotionState(0, 0);
     final MotionState mRel = new MotionState(TRACKBALL_MOVEMENT_THRESHOLD,
             TRACKBALL_MOVEMENT_THRESHOLD);
@@ -410,7 +414,7 @@
                 
                 switch (orientation) {
                     case Surface.ROTATION_90: {
-                        final float temp = reportData[MotionEvent.SAMPLE_X];
+                        final float temp = reportData[j + MotionEvent.SAMPLE_X];
                         reportData[j + MotionEvent.SAMPLE_X] = reportData[j + MotionEvent.SAMPLE_Y];
                         reportData[j + MotionEvent.SAMPLE_Y] = w-temp;
                         break;
@@ -421,7 +425,7 @@
                         break;
                     }
                     case Surface.ROTATION_270: {
-                        final float temp = reportData[i + MotionEvent.SAMPLE_X];
+                        final float temp = reportData[j + MotionEvent.SAMPLE_X];
                         reportData[j + MotionEvent.SAMPLE_X] = h-reportData[j + MotionEvent.SAMPLE_Y];
                         reportData[j + MotionEvent.SAMPLE_Y] = temp;
                         break;
diff --git a/services/java/com/android/server/KeyInputQueue.java b/services/java/com/android/server/KeyInputQueue.java
index dc7d22b..7ca12f21 100644
--- a/services/java/com/android/server/KeyInputQueue.java
+++ b/services/java/com/android/server/KeyInputQueue.java
@@ -521,31 +521,29 @@
                             // Finger 1
                             if (ev.scancode == RawInputEvent.ABS_X) {
                                 di.mAbs.changed = true;
-                                di.mAbs.mNextData[MotionEvent.SAMPLE_X] = ev.value;
+                                di.curTouchVals[MotionEvent.SAMPLE_X] = ev.value;
                             } else if (ev.scancode == RawInputEvent.ABS_Y) {
                                 di.mAbs.changed = true;
-                                di.mAbs.mNextData[MotionEvent.SAMPLE_Y] = ev.value;
+                                di.curTouchVals[MotionEvent.SAMPLE_Y] = ev.value;
                             } else if (ev.scancode == RawInputEvent.ABS_PRESSURE) {
                                 di.mAbs.changed = true;
-                                di.mAbs.mNextData[MotionEvent.SAMPLE_PRESSURE] = ev.value;
-                                di.mAbs.mNextData[MotionEvent.NUM_SAMPLE_DATA
+                                di.curTouchVals[MotionEvent.SAMPLE_PRESSURE] = ev.value;
+                                di.curTouchVals[MotionEvent.NUM_SAMPLE_DATA
                                                  + MotionEvent.SAMPLE_PRESSURE] = ev.value;
                             } else if (ev.scancode == RawInputEvent.ABS_TOOL_WIDTH) {
                                 di.mAbs.changed = true;
-                                di.mAbs.mNextData[MotionEvent.SAMPLE_SIZE] = ev.value;
-                                di.mAbs.mNextData[MotionEvent.NUM_SAMPLE_DATA
+                                di.curTouchVals[MotionEvent.SAMPLE_SIZE] = ev.value;
+                                di.curTouchVals[MotionEvent.NUM_SAMPLE_DATA
                                                  + MotionEvent.SAMPLE_SIZE] = ev.value;
 
                             // Finger 2
                             } else if (ev.scancode == RawInputEvent.ABS_HAT0X) {
                                 di.mAbs.changed = true;
-                                di.mAbs.mNextData[(di.mAbs.mDown[0] ?
-                                        MotionEvent.NUM_SAMPLE_DATA : 0)
+                                di.curTouchVals[MotionEvent.NUM_SAMPLE_DATA 
                                          + MotionEvent.SAMPLE_X] = ev.value;
                             } else if (ev.scancode == RawInputEvent.ABS_HAT0Y) {
                                 di.mAbs.changed = true;
-                                di.mAbs.mNextData[(di.mAbs.mDown[0] ?
-                                        MotionEvent.NUM_SAMPLE_DATA : 0)
+                                di.curTouchVals[MotionEvent.NUM_SAMPLE_DATA
                                         + MotionEvent.SAMPLE_Y] = ev.value;
                             }
     
@@ -603,8 +601,21 @@
                                             |RawInputEvent.CLASS_TOUCHSCREEN_MT))
                                             == RawInputEvent.CLASS_TOUCHSCREEN) {
                                         ms.mNextNumPointers = 0;
-                                        if (ms.mDown[0]) ms.mNextNumPointers++;
-                                        if (ms.mDown[1]) ms.mNextNumPointers++;
+                                        if (ms.mDown[0]) {
+                                            System.arraycopy(di.curTouchVals, 0,
+                                                    ms.mNextData, 0,
+                                                    MotionEvent.NUM_SAMPLE_DATA);
+                                            ms.mNextNumPointers++;
+                                        }
+                                        if (ms.mDown[1]) {
+                                            System.arraycopy(di.curTouchVals,
+                                                    MotionEvent.NUM_SAMPLE_DATA,
+                                                    ms.mNextData,
+                                                    ms.mNextNumPointers
+                                                    * MotionEvent.NUM_SAMPLE_DATA,
+                                                    MotionEvent.NUM_SAMPLE_DATA);
+                                            ms.mNextNumPointers++;
+                                        }
                                     }
                                     
                                     boolean doMotion = !monitorVirtualKey(di,