1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.media;
18 
19 import android.util.Log;
20 
21 import java.net.HttpCookie;
22 import java.util.List;
23 
24 /** @hide */
25 public class Media2HTTPService {
26     private static final String TAG = "Media2HTTPService";
27     private List<HttpCookie> mCookies;
28     private Boolean mCookieStoreInitialized = new Boolean(false);
29 
Media2HTTPService(List<HttpCookie> cookies)30     public Media2HTTPService(List<HttpCookie> cookies) {
31         mCookies = cookies;
32         Log.v(TAG, "Media2HTTPService(" + this + "): Cookies: " + cookies);
33     }
34 
makeHTTPConnection()35     public Media2HTTPConnection makeHTTPConnection() {
36 
37         synchronized (mCookieStoreInitialized) {
38             Media2Utils.storeCookies(mCookies);
39         }
40 
41         return new Media2HTTPConnection();
42     }
43 
createHTTPService(String path)44     /* package private */ static Media2HTTPService createHTTPService(String path) {
45         return createHTTPService(path, null);
46     }
47 
48     // when cookies are provided
createHTTPService(String path, List<HttpCookie> cookies)49     static Media2HTTPService createHTTPService(String path, List<HttpCookie> cookies) {
50         if (path.startsWith("http://") || path.startsWith("https://")) {
51             return (new Media2HTTPService(cookies));
52         } else if (path.startsWith("widevine://")) {
53             Log.d(TAG, "Widevine classic is no longer supported");
54         }
55 
56         return null;
57     }
58 }
59