Merge "Fix issue #4279860: previous UI flashes before showing lock screen..."
diff --git a/core/java/android/app/ProgressDialog.java b/core/java/android/app/ProgressDialog.java
index d421173..f1a04f8 100644
--- a/core/java/android/app/ProgressDialog.java
+++ b/core/java/android/app/ProgressDialog.java
@@ -343,7 +343,7 @@
     
     private void onProgressChanged() {
         if (mProgressStyle == STYLE_HORIZONTAL) {
-            if (!mViewUpdateHandler.hasMessages(0)) {
+            if (mViewUpdateHandler != null && !mViewUpdateHandler.hasMessages(0)) {
                 mViewUpdateHandler.sendEmptyMessage(0);
             }
         }
diff --git a/media/libstagefright/MP3Extractor.cpp b/media/libstagefright/MP3Extractor.cpp
index 92e84c2..09f91f5 100644
--- a/media/libstagefright/MP3Extractor.cpp
+++ b/media/libstagefright/MP3Extractor.cpp
@@ -52,7 +52,10 @@
         *post_id3_pos = 0;
     }
 
+    bool resync_from_head = false;
     if (*inout_pos == 0) {
+        resync_from_head = true;
+
         // Skip an optional ID3 header if syncing at the very beginning
         // of the datasource.
 
@@ -137,22 +140,20 @@
 
         uint32_t header = U32_AT(tmp);
 
-        if (match_header != 0 && (header & kMask) != (match_header & kMask)) {
-            ++pos;
-            ++tmp;
-            --remainingBytes;
-            continue;
-        }
-
         size_t frame_size;
-        int sample_rate, num_channels, bitrate;
-        if (!GetMPEGAudioFrameSize(
-                    header, &frame_size,
-                    &sample_rate, &num_channels, &bitrate)) {
-            ++pos;
-            ++tmp;
-            --remainingBytes;
-            continue;
+        if ((match_header != 0 && (header & kMask) != (match_header & kMask))
+                || !GetMPEGAudioFrameSize(header, &frame_size)) {
+            if (resync_from_head) {
+                // This isn't a valid mp3 file because it failed to detect
+                // a header while a valid mp3 file should have a valid
+                // header here.
+                break;
+            } else {
+                ++pos;
+                ++tmp;
+                --remainingBytes;
+                continue;
+            }
         }
 
         LOGV("found possible 1st frame at %lld (header = 0x%08x)", pos, header);