Merge change 2302 into donut

* changes:
  added SmsMessage ConcatRef parsing validation
diff --git a/cmds/runtime/main_runtime.cpp b/cmds/runtime/main_runtime.cpp
index 1531a9e..476f38a 100644
--- a/cmds/runtime/main_runtime.cpp
+++ b/cmds/runtime/main_runtime.cpp
@@ -45,9 +45,9 @@
     "--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,3001,3002,3003",
     /* CAP_SYS_TTY_CONFIG & CAP_SYS_RESOURCE & CAP_NET_BROADCAST &
      * CAP_NET_ADMIN & CAP_NET_RAW & CAP_NET_BIND_SERVICE  & CAP_KILL &
-     * CAP_SYS_BOOT
+     * CAP_SYS_BOOT CAP_SYS_NICE
      */
-    "--capabilities=88161312,88161312",
+    "--capabilities=96549920,96549920",
     "--runtime-init",
     "--nice-name=system_server",
     "com.android.server.SystemServer"
diff --git a/libs/utils/Parcel.cpp b/libs/utils/Parcel.cpp
index e74ad4a..b0e3750 100644
--- a/libs/utils/Parcel.cpp
+++ b/libs/utils/Parcel.cpp
@@ -409,12 +409,16 @@
             mObjects[idx++] = off;
             mObjectsSize++;
 
-            const flat_binder_object* flat
+            flat_binder_object* flat
                 = reinterpret_cast<flat_binder_object*>(mData + off);
             acquire_object(proc, *flat, this);
 
-            // take note if the object is a file descriptor
             if (flat->type == BINDER_TYPE_FD) {
+                // If this is a file descriptor, we need to dup it so the
+                // new Parcel now owns its own fd, and can declare that we
+                // officially know we have fds.
+                flat->handle = dup(flat->handle);
+                flat->cookie = (void*)1;
                 mHasFds = mFdsKnown = true;
             }
         }
diff --git a/libs/utils/backup_helper_file.cpp b/libs/utils/backup_helper_file.cpp
index 8efb3eb..7ec2ce8 100644
--- a/libs/utils/backup_helper_file.cpp
+++ b/libs/utils/backup_helper_file.cpp
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <sys/stat.h>
+#include <sys/time.h>  // for utimes
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -607,14 +608,14 @@
         0x11, 0x00, 0x00, 0x00,  0x62, 0x79, 0x74, 0x65,
         0x73, 0x5f, 0x6f, 0x66,  0x5f, 0x70, 0x61, 0x64,
         0x64, 0x69, 0x6e, 0x67,  0x33, 0xab, 0xab, 0xab,
-        
+
         // bytes of padding2
         0x44, 0x11, 0x22, 0x33,  0xef, 0xbe, 0xad, 0xde,
         0x44, 0x33, 0x22, 0x11,  0x34, 0x23, 0x12, 0x01,
         0x12, 0x00, 0x00, 0x00,  0x62, 0x79, 0x74, 0x65,
         0x73, 0x5f, 0x6f, 0x66,  0x5f, 0x70, 0x61, 0x64,
         0x64, 0x69, 0x6e, 0x67,  0x5f, 0x32, 0xab, 0xab,
-        
+
         // bytes of padding3
         0x44, 0x11, 0x22, 0x33,  0xef, 0xbe, 0xad, 0xde,
         0x44, 0x33, 0x22, 0x11,  0x34, 0x23, 0x12, 0x01,
@@ -627,7 +628,7 @@
     if (err != 0) {
         return err;
     }
-    
+
     // read
     fd = open(filename, O_RDONLY);
     if (fd == -1) {
@@ -665,7 +666,7 @@
             matched = false;
         }
     }
-    
+
     return matched ? 0 : 1;
 }
 
@@ -746,7 +747,7 @@
     system("rm -r " SCRATCH_DIR);
     mkdir(SCRATCH_DIR, 0777);
     mkdir(SCRATCH_DIR "data", 0777);
-    
+
     fd = creat(filename, 0666);
     if (fd == -1) {
         fprintf(stderr, "error creating: %s\n", strerror(errno));
@@ -863,7 +864,7 @@
     system("rm -r " SCRATCH_DIR);
     mkdir(SCRATCH_DIR, 0777);
     mkdir(SCRATCH_DIR "data", 0777);
-    
+
     fd = creat(filename, 0666);
     if (fd == -1) {
         fprintf(stderr, "error creating: %s\n", strerror(errno));
@@ -940,9 +941,23 @@
         return errno;
     }
     times[0].tv_sec = st.st_atime;
-    times[0].tv_usec = st.st_atime_nsec / 1000;
     times[1].tv_sec = st.st_mtime;
+
+    // If st_atime is a macro then struct stat64 uses struct timespec
+    // to store the access and modif time values and typically
+    // st_*time_nsec is not defined. In glibc, this is controlled by
+    // __USE_MISC.
+#ifdef __USE_MISC
+#if !defined(st_atime) || defined(st_atime_nsec)
+#error "Check if this __USE_MISC conditional is still needed."
+#endif
+    times[0].tv_usec = st.st_atim.tv_nsec / 1000;
+    times[1].tv_usec = st.st_mtim.tv_nsec / 1000;
+#else
+    times[0].tv_usec = st.st_atime_nsec / 1000;
     times[1].tv_usec = st.st_mtime_nsec / 1000;
+#endif
+
     return 0;
 }
 
@@ -987,7 +1002,7 @@
 
     {
         BackupDataWriter dataStream(dataStreamFD);
-    
+
         err = back_up_files(-1, &dataStream, newSnapshotFD, SCRATCH_DIR, files_before, 5);
         if (err != 0) {
             return err;
@@ -1017,7 +1032,7 @@
     utimes(SCRATCH_DIR "data/e", e_times);
     write_text_file(SCRATCH_DIR "data/g", "g\ngg\n");
     unlink(SCRATCH_DIR "data/f");
-    
+
     char const* files_after[] = {
         "data/a", // added
         "data/b", // same
@@ -1047,7 +1062,7 @@
 
     {
         BackupDataWriter dataStream(dataStreamFD);
-    
+
         err = back_up_files(oldSnapshotFD, &dataStream, newSnapshotFD, SCRATCH_DIR,
                 files_after, 6);
         if (err != 0) {
@@ -1058,7 +1073,7 @@
     close(oldSnapshotFD);
     close(dataStreamFD);
     close(newSnapshotFD);
-    
+
     return 0;
 }
 
diff --git a/libs/utils/futex_synchro.c b/libs/utils/futex_synchro.c
index ba19520..ab48c69 100644
--- a/libs/utils/futex_synchro.c
+++ b/libs/utils/futex_synchro.c
@@ -28,6 +28,7 @@
 // This futex glue code is need on desktop linux, but is already part of bionic.
 #if !defined(HAVE_FUTEX_WRAPPERS)
 
+#include <unistd.h>
 #include <sys/syscall.h>
 typedef unsigned int u32;
 #define asmlinkage
diff --git a/tts/java/android/tts/ITts.aidl b/tts/java/android/tts/ITts.aidl
new file mode 100755
index 0000000..1fe4a6a
--- /dev/null
+++ b/tts/java/android/tts/ITts.aidl
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+package android.tts;
+
+import android.tts.ITtsCallback;
+
+import android.content.Intent;
+
+/**
+ * AIDL for the TTS Service
+ * ITts.java is autogenerated from this.
+ *
+ * {@hide}
+ */
+interface ITts {
+    void setEngine(in String engineName, in String[] requestedLanguages, in int strictness);
+
+    void setEngineWithIntent(in Intent engineIntent);
+
+    void setSpeechRate(in int speechRate);
+
+    void speak(in String text, in int queueMode, in String[] params);
+
+    boolean isSpeaking();
+
+    void stop();
+
+    void addSpeech(in String text, in String packageName, in int resId);
+
+    void addSpeechFile(in String text, in String filename);
+
+    void setLanguage(in String language);
+
+    boolean synthesizeToFile(in String text, in String[] params, in String outputDirectory);
+
+    void playEarcon(in String earcon, in int queueMode, in String[] params);
+
+    void addEarcon(in String earcon, in String packageName, in int resId);
+
+    void addEarconFile(in String earcon, in String filename);
+
+    void registerCallback(ITtsCallback cb);
+
+    void unregisterCallback(ITtsCallback cb);
+}
diff --git a/tts/java/android/tts/ITtsCallback.aidl b/tts/java/android/tts/ITtsCallback.aidl
new file mode 100755
index 0000000..1314010
--- /dev/null
+++ b/tts/java/android/tts/ITtsCallback.aidl
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+package android.tts;
+
+/**
+ * AIDL for the callback from the TTS Service
+ * ITtsCallback.java is autogenerated from this.
+ *
+ * {@hide}
+ */
+oneway interface ITtsCallback {
+    void markReached(String mark);
+}