Merge "Add one more field in DecryptHandle to support bug 4126624" into honeycomb-mr1
diff --git a/core/java/android/webkit/HTML5VideoFullScreen.java b/core/java/android/webkit/HTML5VideoFullScreen.java
index 6be988e..f52fa66 100644
--- a/core/java/android/webkit/HTML5VideoFullScreen.java
+++ b/core/java/android/webkit/HTML5VideoFullScreen.java
@@ -209,9 +209,6 @@
                 // which happens when the video view is detached from its parent
                 // view. This happens in the WebChromeClient before this method
                 // is invoked.
-                mTimer.cancel();
-                mTimer = null;
-
                 pauseAndDispatch(mProxy);
 
                 mLayout.removeView(getSurfaceView());
diff --git a/core/java/android/webkit/HTML5VideoView.java b/core/java/android/webkit/HTML5VideoView.java
index b9d55e0..cd2264c 100644
--- a/core/java/android/webkit/HTML5VideoView.java
+++ b/core/java/android/webkit/HTML5VideoView.java
@@ -68,6 +68,14 @@
     // common Video control FUNCTIONS:
     public void start() {
         if (mCurrentState == STATE_PREPARED) {
+            // When replaying the same video, there is no onPrepared call.
+            // Therefore, the timer should be set up here.
+            if (mTimer == null)
+            {
+                mTimer = new Timer();
+                mTimer.schedule(new TimeupdateTask(mProxy), TIMEUPDATE_PERIOD,
+                        TIMEUPDATE_PERIOD);
+            }
             mPlayer.start();
         }
     }
@@ -76,8 +84,12 @@
         if (mCurrentState == STATE_PREPARED && mPlayer.isPlaying()) {
             mPlayer.pause();
         }
+
+        // Delete the Timer to stop it since there is no stop call.
         if (mTimer != null) {
             mTimer.purge();
+            mTimer.cancel();
+            mTimer = null;
         }
     }
 
@@ -129,6 +141,7 @@
         mVideoLayerId = videoLayerId;
         mSaveSeekTime = position;
         mAutostart = autoStart;
+        mTimer = null;
     }
 
     protected HTML5VideoView() {
@@ -153,8 +166,6 @@
         // When switching players, surface texture will be reused.
         mUri = uri;
         mHeaders = generateHeaders(uri, proxy);
-
-        mTimer = new Timer();
     }
 
     // Listeners setup FUNCTIONS:
@@ -228,11 +239,9 @@
     public void onPrepared(MediaPlayer mp) {
         mCurrentState = STATE_PREPARED;
         seekTo(mSaveSeekTime);
-        if (mProxy != null)
+        if (mProxy != null) {
             mProxy.onPrepared(mp);
-
-        mTimer.schedule(new TimeupdateTask(mProxy), TIMEUPDATE_PERIOD, TIMEUPDATE_PERIOD);
-
+        }
     }
 
     // Pause the play and update the play/pause button
diff --git a/core/res/res/drawable/list_selector_background.xml b/core/res/res/drawable/list_selector_background.xml
index f5eb12d..1222155 100644
--- a/core/res/res/drawable/list_selector_background.xml
+++ b/core/res/res/drawable/list_selector_background.xml
@@ -24,6 +24,6 @@
     <item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/list_selector_background_disabled" />
     <item android:state_focused="true"                                android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
     <item android:state_focused="false"                               android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
-    <item android:state_focused="true"                                                             android:drawable="@drawable/list_selector_background_focused" />
+    <item android:state_focused="true"                                                             android:drawable="@drawable/list_selector_background_focus" />
     
 </selector>
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index a42cca5..0156634 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -744,7 +744,8 @@
         return TEST_PLAYER;
     }
 
-    if (!strncasecmp("http://", url, 7)) {
+    if (!strncasecmp("http://", url, 7)
+            || !strncasecmp("https://", url, 8)) {
         size_t len = strlen(url);
         if (len >= 5 && !strcasecmp(".m3u8", &url[len - 5])) {
             return NU_PLAYER;
diff --git a/media/libstagefright/httplive/M3UParser.cpp b/media/libstagefright/httplive/M3UParser.cpp
index 95f6741..2eb180a 100644
--- a/media/libstagefright/httplive/M3UParser.cpp
+++ b/media/libstagefright/httplive/M3UParser.cpp
@@ -20,8 +20,8 @@
 
 #include "include/M3UParser.h"
 
+#include <media/stagefright/foundation/ADebug.h>
 #include <media/stagefright/foundation/AMessage.h>
-#include <media/stagefright/MediaDebug.h>
 #include <media/stagefright/MediaErrors.h>
 
 namespace android {
@@ -306,6 +306,29 @@
     return OK;
 }
 
+// Find the next occurence of the character "what" at or after "offset",
+// but ignore occurences between quotation marks.
+// Return the index of the occurrence or -1 if not found.
+static ssize_t FindNextUnquoted(
+        const AString &line, char what, size_t offset) {
+    CHECK_NE((int)what, (int)'"');
+
+    bool quoted = false;
+    while (offset < line.size()) {
+        char c = line.c_str()[offset];
+
+        if (c == '"') {
+            quoted = !quoted;
+        } else if (c == what && !quoted) {
+            return offset;
+        }
+
+        ++offset;
+    }
+
+    return -1;
+}
+
 // static
 status_t M3UParser::parseCipherInfo(
         const AString &line, sp<AMessage> *meta, const AString &baseURI) {
@@ -318,7 +341,7 @@
     size_t offset = colonPos + 1;
 
     while (offset < line.size()) {
-        ssize_t end = line.find(",", offset);
+        ssize_t end = FindNextUnquoted(line, ',', offset);
         if (end < 0) {
             end = line.size();
         }
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaTestUtil.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaTestUtil.java
index beb2927..a80fc13 100755
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaTestUtil.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/MediaTestUtil.java
@@ -16,7 +16,10 @@
 
 package com.android.mediaframeworktest;
 
+import java.io.BufferedWriter;
+import java.io.File;
 import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Writer;
@@ -31,28 +34,58 @@
  *
  */
 public class MediaTestUtil {
-    private MediaTestUtil(){
-    }
 
     private static String TAG = "MediaTestUtil";
-    private static final String STORAGE_PATH =
-        Environment.getExternalStorageDirectory().toString();
-    private static int mMediaStartMemory = 0;
-    private static int mDrmStartMemory = 0;
+    private static final String STORAGE_PATH = Environment.getExternalStorageDirectory().toString();
+    private int mStartMemory = 0;
+    private int mStartPid = 0;
+    private Writer mOutput = null;
+    private String mTestName = null;
+    private String mProcessName = null;
 
-    //Catpure the heapdump for memory leaksage analysis
-    public static void getNativeHeapDump (String name) throws Exception {
+    public MediaTestUtil(String memoryOutFileName, String testName, String processName)
+            throws Exception {
+        File memoryOut = new File(memoryOutFileName);
+        mOutput = new BufferedWriter(new FileWriter(memoryOut, true));
+        mProcessName = processName;
+        mTestName = testName;
+        mStartPid = getPid();
+        mStartMemory = getVsize();
+    }
+
+    // Catpure the heapdump for memory leaksage analysis
+    public static void getNativeHeapDump(String name) throws Exception {
         System.gc();
         System.runFinalization();
         Thread.sleep(1000);
-        FileOutputStream o = new FileOutputStream(STORAGE_PATH + '/' +name + ".dump");
+        FileOutputStream o = new FileOutputStream(STORAGE_PATH + '/' + name + ".dump");
         Debug.dumpNativeHeap(o.getFD());
         o.close();
     }
 
-    public static String captureMemInfo(String type) {
+    private void validateProcessStatus() throws Exception {
+        int currentPid = getPid();
+        //Process crash
+        if (mStartPid != currentPid) {
+            mOutput.write(mProcessName + " died. Test failed\n");
+        }
+    }
+
+    private int getPid() {
+        String memoryUsage = null;
+        int pidvalue = 0;
+        memoryUsage = captureMemInfo();
+        String[] poList2 = memoryUsage.split("\t|\\s+");
+        String pid = poList2[1];
+        pidvalue = Integer.parseInt(pid);
+        Log.v(TAG, "PID = " + pidvalue);
+        return pidvalue;
+    }
+
+    private String captureMemInfo() {
         String cm = "ps ";
-        cm += type;
+        cm += mProcessName;
+        Log.v(TAG, cm);
         String memoryUsage = null;
 
         int ch;
@@ -72,8 +105,8 @@
         return memusage;
     }
 
-    public static int getMediaServerVsize() {
-        String memoryUsage = captureMemInfo("mediaserver");
+    private int getVsize() {
+        String memoryUsage = captureMemInfo();
         String[] poList2 = memoryUsage.split("\t|\\s+");
         String vsize = poList2[3];
         int vsizevalue = Integer.parseInt(vsize);
@@ -81,71 +114,39 @@
         return vsizevalue;
     }
 
-    public static int getDrmServerVsize() {
-        String memoryUsage = captureMemInfo("drmserver");
-        String[] poList2 = memoryUsage.split("\t|\\s+");
-        String vsize = poList2[3];
-        int vsizevalue = Integer.parseInt(vsize);
-        Log.v(TAG, "VSIZE = " + vsizevalue);
-        return vsizevalue;
-    }
-
-    // Write the ps mediaserver output to the file
-    public static void getMediaServerMemoryLog(Writer output, int writeCount, int totalCount)
-            throws Exception {
+    // Write the startup media memory mOutput to the file
+    public void getStartMemoryLog() throws Exception {
         String memusage = null;
-
-        if (writeCount == 0) {
-            mMediaStartMemory = getMediaServerVsize();
-            output.write("Start memory : " + mMediaStartMemory + "\n");
-        }
-        memusage = captureMemInfo("mediaserver");
-        output.write(memusage);
+        mStartMemory = getVsize();
+        mOutput.write(mTestName + '\n');
+        mOutput.write("Start memory : " + mStartMemory + "\n");
+        memusage = captureMemInfo();
+        mOutput.write(memusage);
     }
 
-    // Write the ps drmserver output to the file
-    public static void getDrmServerMemoryLog(Writer output, int writeCount, int totalCount)
-            throws Exception {
+    // Write the ps mediaserver mOutput to the file
+    public void getMemoryLog() throws Exception {
         String memusage = null;
-
-        if (writeCount == 0) {
-            mDrmStartMemory = getDrmServerVsize();
-            output.write("Start memory : " + mDrmStartMemory + "\n");
-        }
-        memusage = captureMemInfo("drmserver");
-        output.write(memusage);
+        memusage = captureMemInfo();
+        mOutput.write(memusage);
+        mOutput.flush();
     }
 
-    // Write the ps drmserver output to the file
-    public static void getDrmServerMemorySummary(Writer output, String tag) throws Exception {
-
-        getTestMemorySummary(output, tag, "drmMem");
-    }
-
-    // Write the ps drmserver output to the file
-    public static void getMediaServerMemorySummary(Writer output, String tag) throws Exception {
-
-        getTestMemorySummary(output, tag, "mediaMem");
-    }
-
-    public static void getTestMemorySummary(Writer output, String tag, String type)
-            throws Exception {
-
+    public void getMemorySummary() throws Exception {
         int endMemory = 0;
         int memDiff = 0;
 
-        if (type == "mediaMem") {
-            endMemory = getMediaServerVsize();
-            memDiff = endMemory - mMediaStartMemory;
-        } else if (type == "drmMem") {
-            endMemory = getDrmServerVsize();
-            memDiff = endMemory - mDrmStartMemory;
-        }
-        output.write("End Memory :" + endMemory + "\n");
+        endMemory = getVsize();
+        memDiff = endMemory - mStartMemory;
+
+        mOutput.write("End Memory :" + endMemory + "\n");
         if (memDiff < 0) {
             memDiff = 0;
         }
-        output.write(tag + " total diff = " + memDiff);
-        output.write("\n\n");
+        mOutput.write(mTestName + " total diff = " + memDiff);
+        mOutput.write("\n\n");
+        validateProcessStatus();
+        mOutput.flush();
+        mOutput.close();
     }
 }