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

Commit 18d58d81 authored by Hassan Shojania's avatar Hassan Shojania Committed by Android (Google) Code Review
Browse files

Merge "New setDataSource API for accepting cookies"

parents c788f3e1 a6c969c0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22331,6 +22331,7 @@ package android.media {
    method public void setAuxEffectSendLevel(float);
    method public void setBufferingParams(android.media.BufferingParams);
    method public void setDataSource(android.content.Context, android.net.Uri) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(android.content.Context, android.net.Uri, java.util.Map<java.lang.String, java.lang.String>, java.util.List<java.net.HttpCookie>) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(android.content.Context, android.net.Uri, java.util.Map<java.lang.String, java.lang.String>) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(java.lang.String) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(android.content.res.AssetFileDescriptor) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException;
+1 −0
Original line number Diff line number Diff line
@@ -23974,6 +23974,7 @@ package android.media {
    method public void setAuxEffectSendLevel(float);
    method public void setBufferingParams(android.media.BufferingParams);
    method public void setDataSource(android.content.Context, android.net.Uri) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(android.content.Context, android.net.Uri, java.util.Map<java.lang.String, java.lang.String>, java.util.List<java.net.HttpCookie>) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(android.content.Context, android.net.Uri, java.util.Map<java.lang.String, java.lang.String>) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(java.lang.String) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(android.content.res.AssetFileDescriptor) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException;
+1 −0
Original line number Diff line number Diff line
@@ -22424,6 +22424,7 @@ package android.media {
    method public void setAuxEffectSendLevel(float);
    method public void setBufferingParams(android.media.BufferingParams);
    method public void setDataSource(android.content.Context, android.net.Uri) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(android.content.Context, android.net.Uri, java.util.Map<java.lang.String, java.lang.String>, java.util.List<java.net.HttpCookie>) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(android.content.Context, android.net.Uri, java.util.Map<java.lang.String, java.lang.String>) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(java.lang.String) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(android.content.res.AssetFileDescriptor) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException;
+3 −2
Original line number Diff line number Diff line
@@ -61,8 +61,9 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
    private final static int MAX_REDIRECTS = 20;

    public MediaHTTPConnection() {
        if (CookieHandler.getDefault() == null) {
            CookieHandler.setDefault(new CookieManager());
        CookieManager cookieManager = (CookieManager)CookieHandler.getDefault();
        if (cookieManager == null) {
            Log.w(TAG, "MediaHTTPConnection: Unexpected. No CookieManager found.");
        }

        native_setup();
+55 −2
Original line number Diff line number Diff line
@@ -19,25 +19,78 @@ package android.media;
import android.os.IBinder;
import android.util.Log;

import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.util.List;

/** @hide */
public class MediaHTTPService extends IMediaHTTPService.Stub {
    private static final String TAG = "MediaHTTPService";
    private List<HttpCookie> mCookies;
    private Boolean mCookieStoreInitialized = new Boolean(false);

    public MediaHTTPService() {
    public MediaHTTPService(List<HttpCookie> cookies) {
        mCookies = cookies;
        Log.v(TAG, "MediaHTTPService(" + this + "): Cookies: " + cookies);
    }

    public IMediaHTTPConnection makeHTTPConnection() {

        synchronized (mCookieStoreInitialized) {
            // Only need to do it once for all connections
            if ( !mCookieStoreInitialized )  {
                CookieManager cookieManager = (CookieManager)CookieHandler.getDefault();
                if (cookieManager == null) {
                    cookieManager = new CookieManager();
                    CookieHandler.setDefault(cookieManager);
                    Log.v(TAG, "makeHTTPConnection: CookieManager created: " + cookieManager);
                }
                else {
                    Log.v(TAG, "makeHTTPConnection: CookieManager(" + cookieManager + ") exists.");
                }

                // Applying the bootstrapping cookies
                if ( mCookies != null ) {
                    CookieStore store = cookieManager.getCookieStore();
                    for ( HttpCookie cookie : mCookies ) {
                        try {
                            store.add(null, cookie);
                        } catch ( Exception e ) {
                            Log.v(TAG, "makeHTTPConnection: CookieStore.add" + e);
                        }
                        //for extended debugging when needed
                        //Log.v(TAG, "MediaHTTPConnection adding Cookie[" + cookie.getName() +
                        //        "]: " + cookie);
                    }
                }   // mCookies

                mCookieStoreInitialized = true;

                Log.v(TAG, "makeHTTPConnection(" + this + "): cookieManager: " + cookieManager +
                        " Cookies: " + mCookies);
            }   // mCookieStoreInitialized
        }   // synchronized

        return new MediaHTTPConnection();
    }

    /* package private */static IBinder createHttpServiceBinderIfNecessary(
            String path) {
        return createHttpServiceBinderIfNecessary(path, null);
    }

    // when cookies are provided
    static IBinder createHttpServiceBinderIfNecessary(
            String path, List<HttpCookie> cookies) {
        if (path.startsWith("http://") || path.startsWith("https://")) {
            return (new MediaHTTPService()).asBinder();
            return (new MediaHTTPService(cookies)).asBinder();
        } else if (path.startsWith("widevine://")) {
            Log.d(TAG, "Widevine classic is no longer supported");
        }

        return null;
    }

}
Loading