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

Commit 3300d323 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "MediaHTTPConnection: support Cookie update"

parents b8243123 2cf270f1
Loading
Loading
Loading
Loading
+24 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package android.media;
import android.net.NetworkUtils;
import android.net.NetworkUtils;
import android.os.IBinder;
import android.os.IBinder;
import android.os.StrictMode;
import android.os.StrictMode;
import android.os.SystemProperties;
import android.util.Log;
import android.util.Log;


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


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


    private boolean mAllowCrossDomainRedirect = true;
    private boolean mAllowCrossDomainRedirect = true;
    private boolean mAllowCrossProtocolRedirect = true;
    private boolean mAllowCrossProtocolRedirect = true;
@@ -117,6 +121,8 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
                mProxyPort = Integer.parseInt(val.substring(colonPos + 1));
                mProxyPort = Integer.parseInt(val.substring(colonPos + 1));
                Log.d(TAG, "sta-proxy-ip " + mProxyIP + " port " + mProxyPort);
                Log.d(TAG, "sta-proxy-ip " + mProxyIP + " port " + mProxyPort);
            }
            }
        } else if ("Cookie".equalsIgnoreCase(key) && mIsCookieUpdated) {
            Log.d(TAG, "filterOutInternalHeaders: Cookie");
        } else {
        } else {
            return false;
            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) {
                if (offset > 0) {
                    mConnection.setRequestProperty(
                    mConnection.setRequestProperty(
                            "Range", "bytes=" + offset + "-");
                            "Range", "bytes=" + offset + "-");
@@ -308,6 +322,16 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
                throw new IOException();
                throw new IOException();
            } else {
            } else {
                mTotalSize = mConnection.getContentLength();
                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) {
            if (offset > 0 && response != HttpURLConnection.HTTP_PARTIAL) {