• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.phone.testapps.embmsmw;
18 
19 import android.net.Uri;
20 import android.telephony.mbms.StreamingServiceInfo;
21 
22 import java.util.Date;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Locale;
26 import java.util.Map;
27 import java.util.stream.Collectors;
28 
29 public class StreamingServiceRepository {
30     private static final String STREAMING_SCHEME = "stream";
31     private static final String STREAMING_URI_SSP_PREFIX = "identifier/";
32 
33     private static int sServiceIdCounter = 0;
34     private static final Map<String, StreamingServiceInfo> sIdToServiceInfo =
35             new HashMap<>();
36     private static final Map<String, Uri> sIdToStreamingUri = new HashMap<>();
37 
38     static {
fetchStreamingServices()39         fetchStreamingServices();
40     }
41 
getStreamingServicesForClasses( List<String> serviceClasses)42     public static List<StreamingServiceInfo> getStreamingServicesForClasses(
43             List<String> serviceClasses) {
44         return sIdToServiceInfo.values().stream()
45                 .filter((info) -> serviceClasses.contains(info.getServiceClassName()))
46                 .collect(Collectors.toList());
47     }
48 
getUriForService(String serviceId)49     public static Uri getUriForService(String serviceId) {
50         if (sIdToStreamingUri.containsKey(serviceId)) {
51             return sIdToStreamingUri.get(serviceId);
52         }
53         return null;
54     }
55 
getStreamingServiceInfoForId(String serviceId)56     public static StreamingServiceInfo getStreamingServiceInfoForId(String serviceId) {
57         return sIdToServiceInfo.getOrDefault(serviceId, null);
58     }
59 
createStreamingService(String className)60     private static void createStreamingService(String className) {
61         sServiceIdCounter++;
62         String id = "StreamingServiceId[" + sServiceIdCounter + "]";
63         Map<Locale, String> localeDict = Map.of(
64                 Locale.US, "Entertainment Source " + sServiceIdCounter,
65                 Locale.CANADA, "Entertainment Source, eh?" + sServiceIdCounter);
66         List<Locale> locales = List.of(Locale.CANADA, Locale.US);
67         StreamingServiceInfo info = new StreamingServiceInfo(localeDict, className, locales,
68                 id, new Date(System.currentTimeMillis() - 10000),
69                 new Date(System.currentTimeMillis() + 10000));
70         sIdToServiceInfo.put(id, info);
71         sIdToStreamingUri.put(id, Uri.fromParts(STREAMING_SCHEME,
72                 STREAMING_URI_SSP_PREFIX + sServiceIdCounter,
73                 null));
74     }
75 
fetchStreamingServices()76     private static void fetchStreamingServices() {
77         createStreamingService("Class1");
78         createStreamingService("Class2");
79         createStreamingService("Class3");
80         createStreamingService("Class4");
81         createStreamingService("Class5");
82         createStreamingService("Class6");
83     }
84 
85     // Do not instantiate
StreamingServiceRepository()86     private StreamingServiceRepository() {}
87 }
88