Merge change I9a50fdf4 into eclair-mr2

* changes:
  Handle OMX_StateInvalid in emergency shutdown properly (by ignoring it and hoping for the best) instead of asserting.
diff --git a/api/4.xml b/api/4.xml
index e996e8f..9689072 100644
--- a/api/4.xml
+++ b/api/4.xml
@@ -111799,6 +111799,17 @@
  visibility="public"
 >
 </field>
+<field name="DATA_ACTIVITY_DORMANT"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="4"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="DATA_ACTIVITY_IN"
  type="int"
  transient="false"
@@ -111939,6 +111950,28 @@
  visibility="public"
 >
 </field>
+<field name="NETWORK_TYPE_1xRTT"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="7"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="NETWORK_TYPE_CDMA"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="4"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="NETWORK_TYPE_EDGE"
  type="int"
  transient="false"
@@ -111950,6 +111983,28 @@
  visibility="public"
 >
 </field>
+<field name="NETWORK_TYPE_EVDO_0"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="5"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="NETWORK_TYPE_EVDO_A"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="6"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="NETWORK_TYPE_GPRS"
  type="int"
  transient="false"
@@ -111983,6 +112038,17 @@
  visibility="public"
 >
 </field>
+<field name="PHONE_TYPE_CDMA"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="2"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="PHONE_TYPE_GSM"
  type="int"
  transient="false"
diff --git a/core/java/android/provider/Calendar.java b/core/java/android/provider/Calendar.java
index faa63af..b8cf6c2 100644
--- a/core/java/android/provider/Calendar.java
+++ b/core/java/android/provider/Calendar.java
@@ -76,6 +76,15 @@
         Uri.parse("content://" + AUTHORITY);
 
     /**
+     * An optional insert, update or delete URI parameter that allows the caller
+     * to specify that it is a sync adapter. The default value is false. If true
+     * the dirty flag is not automatically set and the "syncToNetwork" parameter
+     * is set to false when calling
+     * {@link ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}.
+     */
+    public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter";
+
+    /**
      * Columns from the Calendars table that other tables join into themselves.
      */
     public interface CalendarsColumns
@@ -341,11 +350,11 @@
          * This field is copied here so that we can efficiently filter out
          * events that are declined without having to look in the Attendees
          * table.
-         * 
+         *
          * <P>Type: INTEGER (int)</P>
          */
         public static final String SELF_ATTENDEE_STATUS = "selfAttendeeStatus";
-        
+
         /**
          * The comments feed uri.
          * <P>Type: TEXT</P>
@@ -868,10 +877,10 @@
          */
         public static final String MAX_BUSYBITS = "maxBusyBits";
     }
-    
+
     public static final class CalendarMetaData implements CalendarMetaDataColumns {
     }
-    
+
     public interface BusyBitsColumns {
         /**
          * The Julian day number.
@@ -895,22 +904,22 @@
          */
         public static final String ALL_DAY_COUNT = "allDayCount";
     }
-    
+
     public static final class BusyBits implements BusyBitsColumns {
         public static final Uri CONTENT_URI = Uri.parse("content://calendar/busybits/when");
 
         public static final String[] PROJECTION = { DAY, BUSYBITS, ALL_DAY_COUNT };
-        
+
         // The number of minutes represented by one busy bit
         public static final int MINUTES_PER_BUSY_INTERVAL = 60;
-        
+
         // The number of intervals in a day
         public static final int INTERVALS_PER_DAY = 24 * 60 / MINUTES_PER_BUSY_INTERVAL;
 
         /**
          * Retrieves the busy bits for the Julian days starting at "startDay"
          * for "numDays".
-         * 
+         *
          * @param cr the ContentResolver
          * @param startDay the first Julian day in the range
          * @param numDays the number of days to load (must be at least 1)
@@ -1038,14 +1047,14 @@
             CalendarAlertsColumns, EventsColumns, CalendarsColumns {
         public static final String TABLE_NAME = "CalendarAlerts";
         public static final Uri CONTENT_URI = Uri.parse("content://calendar/calendar_alerts");
-        
+
         /**
          * This URI is for grouping the query results by event_id and begin
          * time.  This will return one result per instance of an event.  So
          * events with multiple alarms will appear just once, but multiple
          * instances of a repeating event will show up multiple times.
          */
-        public static final Uri CONTENT_URI_BY_INSTANCE = 
+        public static final Uri CONTENT_URI_BY_INSTANCE =
             Uri.parse("content://calendar/calendar_alerts/by_instance");
 
         public static final Uri insert(ContentResolver cr, long eventId,
@@ -1069,11 +1078,11 @@
             return cr.query(CONTENT_URI, projection, selection, selectionArgs,
                     DEFAULT_SORT_ORDER);
         }
-        
+
         /**
          * Finds the next alarm after (or equal to) the given time and returns
          * the time of that alarm or -1 if no such alarm exists.
-         * 
+         *
          * @param cr the ContentResolver
          * @param millis the time in UTC milliseconds
          * @return the next alarm time greater than or equal to "millis", or -1
@@ -1097,13 +1106,13 @@
             }
             return alarmTime;
         }
-        
+
         /**
          * Searches the CalendarAlerts table for alarms that should have fired
          * but have not and then reschedules them.  This method can be called
          * at boot time to restore alarms that may have been lost due to a
          * phone reboot.
-         * 
+         *
          * @param cr the ContentResolver
          * @param context the Context
          * @param manager the AlarmManager
@@ -1131,7 +1140,7 @@
             if (Log.isLoggable(TAG, Log.DEBUG)) {
                 Log.d(TAG, "missed alarms found: " + cursor.getCount());
             }
-            
+
             try {
                 while (cursor.moveToNext()) {
                     long id = cursor.getLong(0);
@@ -1152,14 +1161,14 @@
             } finally {
                 cursor.close();
             }
-            
+
         }
-        
+
         /**
          * Searches for an entry in the CalendarAlerts table that matches
          * the given event id, begin time and alarm time.  If one is found
          * then this alarm already exists and this method returns true.
-         * 
+         *
          * @param cr the ContentResolver
          * @param eventId the event id to match
          * @param begin the start time of the event in UTC millis
diff --git a/media/libstagefright/AudioPlayer.cpp b/media/libstagefright/AudioPlayer.cpp
index 7b4d178..d7e3f66 100644
--- a/media/libstagefright/AudioPlayer.cpp
+++ b/media/libstagefright/AudioPlayer.cpp
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+//#define LOG_NDEBUG 0
 #define LOG_TAG "AudioPlayer"
 #include <utils/Log.h>
 
@@ -136,7 +137,7 @@
     // Make sure to release any buffer we hold onto so that the
     // source is able to stop().
     if (mInputBuffer != NULL) {
-        LOGI("AudioPlayer releasing input buffer.");
+        LOGV("AudioPlayer releasing input buffer.");
 
         mInputBuffer->release();
         mInputBuffer = NULL;
@@ -176,7 +177,7 @@
 
 void AudioPlayer::fillBuffer(void *data, size_t size) {
     if (mNumFramesPlayed == 0) {
-        LOGI("AudioCallback");
+        LOGV("AudioCallback");
     }
 
     size_t size_done = 0;
@@ -216,6 +217,11 @@
             mPositionTimeRealUs =
                 ((mNumFramesPlayed + size_done / mFrameSize) * 1000000)
                     / mSampleRate;
+
+            LOGV("buffer->size() = %d, "
+                 "mPositionTimeMediaUs=%.2f mPositionTimeRealUs=%.2f",
+                 mInputBuffer->range_length(),
+                 mPositionTimeMediaUs / 1E6, mPositionTimeRealUs / 1E6);
         }
 
         if (mInputBuffer->range_length() == 0) {
diff --git a/media/libstagefright/MediaPlayerImpl.cpp b/media/libstagefright/MediaPlayerImpl.cpp
index 4d14e4c..eb9fe7f 100644
--- a/media/libstagefright/MediaPlayerImpl.cpp
+++ b/media/libstagefright/MediaPlayerImpl.cpp
@@ -147,7 +147,15 @@
     if (mAudioSource != NULL) {
         mAudioPlayer = new AudioPlayer(mAudioSink);
         mAudioPlayer->setSource(mAudioDecoder);
-        mAudioPlayer->start();
+
+        if (mVideoDecoder == NULL) {
+            // If there is no video, start playing right away,
+            // otherwise we'll start the audio player after we decode
+            // the first video frame, this way we won't be behind right
+            // away.
+            mAudioPlayer->start();
+        }
+
         mTimeSource = mAudioPlayer;
     } else {
         mTimeSource = new SystemTimeSource;
@@ -276,6 +284,10 @@
         }
 
         if (firstFrame || seeking) {
+            if (firstFrame && mAudioPlayer != NULL) {
+                // We've deferred starting the audio player until now.
+                mAudioPlayer->start();
+            }
             mTimeSourceDeltaUs = mTimeSource->getRealTimeUs() - pts_us;
             firstFrame = false;
         }