Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2cf270f1 authored by Li Sun's avatar Li Sun Committed by Gerrit - the friendly Code Review server
Browse files

MediaHTTPConnection: support Cookie update

- The server side would keep the Cookie in the
  response header. The client should update it
  in the http connection session.

- disable the functionality as it's server specific.
  enable it by "adb shell setprop persist.media.cookie.cust
  true"

Change-Id: Ibde2dbb228856200ea1ecbfa391f8480b5595ae9
parent 1c6d9d68
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.media;
import android.net.NetworkUtils;
import android.os.IBinder;
import android.os.StrictMode;
import android.os.SystemProperties;
import android.util.Log;

import java.io.BufferedInputStream;
@@ -34,6 +35,7 @@ import java.net.NoRouteToHostException;
import java.net.ProtocolException;
import java.net.UnknownServiceException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import java.net.InetSocketAddress;
@@ -59,6 +61,8 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
    private HttpURLConnection mConnection = null;
    private long mTotalSize = -1;
    private InputStream mInputStream = null;
    private List<String> mCookies = null;
    private boolean mIsCookieUpdated = false;

    private boolean mAllowCrossDomainRedirect = true;
    private boolean mAllowCrossProtocolRedirect = true;
@@ -117,6 +121,8 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
                mProxyPort = Integer.parseInt(val.substring(colonPos + 1));
                Log.d(TAG, "sta-proxy-ip " + mProxyIP + " port " + mProxyPort);
            }
        } else if ("Cookie".equalsIgnoreCase(key) && mIsCookieUpdated) {
            Log.d(TAG, "filterOutInternalHeaders: Cookie");
        } else {
            return false;
        }
@@ -222,6 +228,14 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
                    }
                }

                if (mIsCookieUpdated) {
                    if (VERBOSE)
                        Log.d(TAG, "add Cookie in the request");
                    for (String cookie : mCookies) {
                        mConnection.addRequestProperty("Cookie", cookie.split(";", 2)[0]);
                    }
                }

                if (offset > 0) {
                    mConnection.setRequestProperty(
                            "Range", "bytes=" + offset + "-");
@@ -308,6 +322,16 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
                throw new IOException();
            } else {
                mTotalSize = mConnection.getContentLength();
                if (mConnection.getHeaderFields().containsKey("Set-Cookie")) {
                    mIsCookieUpdated = SystemProperties.getBoolean(
                            "persist.media.cookie.cust", false);
                    mCookies = mConnection.getHeaderFields().get("Set-Cookie");
                    if (VERBOSE) {
                        for (String cookie : mCookies) {
                            Log.d(TAG, "get Cookie" + cookie);
                        }
                    }
                 }
            }

            if (offset > 0 && response != HttpURLConnection.HTTP_PARTIAL) {