14dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt/* 24dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt * Copyright (C) 2016 The Android Open Source Project 34dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt * 44dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt * Licensed under the Apache License, Version 2.0 (the "License"); 54dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt * you may not use this file except in compliance with the License. 64dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt * You may obtain a copy of the License at 74dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt * 84dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt * http://www.apache.org/licenses/LICENSE-2.0 94dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt * 104dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt * Unless required by applicable law or agreed to in writing, software 114dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt * distributed under the License is distributed on an "AS IS" BASIS, 124dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt * See the License for the specific language governing permissions and 144dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt * limitations under the License. 154dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt */ 164dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt 174dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwaltpackage android.telephony.mbms; 184dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt 1923d80af5c11de192bdb648642706c43c942be60eHall Liuimport android.annotation.NonNull; 2023d80af5c11de192bdb648642706c43c942be60eHall Liuimport android.annotation.Nullable; 214dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwaltimport android.os.Parcel; 224dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwaltimport android.os.Parcelable; 234dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwaltimport android.text.TextUtils; 244dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt 2547c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwaltimport java.util.ArrayList; 26d01f6eec20a19c36ec1af380770e4aedfd6723e1Brad Ebingerimport java.util.Collections; 274dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwaltimport java.util.Date; 284dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwaltimport java.util.HashMap; 2947c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwaltimport java.util.List; 304dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwaltimport java.util.Locale; 314dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwaltimport java.util.Map; 32e373ee5d5ce38a7570471ae269e4b7a41052a1beHall Liuimport java.util.NoSuchElementException; 339f116ef480fce78c8a8211ba96e74607e33aec56Hall Liuimport java.util.Objects; 344dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwaltimport java.util.Set; 354dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt 364dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt/** 372398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu * Describes a cell-broadcast service. This class should not be instantiated directly -- use 3823d80af5c11de192bdb648642706c43c942be60eHall Liu * {@link StreamingServiceInfo} or {@link FileServiceInfo} 394dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt */ 40ee19cfc386ba5abf702d81f828da05c4be0beb9fHall Liupublic class ServiceInfo { 414dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt // arbitrary limit on the number of locale -> name pairs we support 42f725f98f170e43aacbfa7cb6a3935f277552efc8Robert Greenwalt final static int MAP_LIMIT = 1000; 434dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt 442398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu private final Map<Locale, String> names; 452398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu private final String className; 462398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu private final List<Locale> locales; 472398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu private final String serviceId; 482398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu private final Date sessionStartTime; 492398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu private final Date sessionEndTime; 504dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt 512398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu /** @hide */ 5247c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt public ServiceInfo(Map<Locale, String> newNames, String newClassName, List<Locale> newLocales, 534dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt String newServiceId, Date start, Date end) { 54c6703d9af7aede1b3d886a575bfe21929dd68dc0Hall Liu if (newNames == null || newClassName == null 55c6703d9af7aede1b3d886a575bfe21929dd68dc0Hall Liu || newLocales == null || newServiceId == null 564dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt || start == null || end == null) { 574dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt throw new IllegalArgumentException("Bad ServiceInfo construction"); 584dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt } 594dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt if (newNames.size() > MAP_LIMIT) { 6047c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt throw new RuntimeException("bad map length " + newNames.size()); 6147c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt } 6247c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt if (newLocales.size() > MAP_LIMIT) { 6347c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt throw new RuntimeException("bad locales length " + newLocales.size()); 644dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt } 6523d80af5c11de192bdb648642706c43c942be60eHall Liu 664dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt names = new HashMap(newNames.size()); 674dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt names.putAll(newNames); 684dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt className = newClassName; 6947c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt locales = new ArrayList(newLocales); 704dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt serviceId = newServiceId; 714dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt sessionStartTime = (Date)start.clone(); 724dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt sessionEndTime = (Date)end.clone(); 734dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt } 744dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt 752398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu /** @hide */ 762398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu protected ServiceInfo(Parcel in) { 774dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt int mapCount = in.readInt(); 784dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt if (mapCount > MAP_LIMIT || mapCount < 0) { 7947c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt throw new RuntimeException("bad map length" + mapCount); 804dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt } 814dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt names = new HashMap(mapCount); 824dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt while (mapCount-- > 0) { 834dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt Locale locale = (java.util.Locale) in.readSerializable(); 844dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt String name = in.readString(); 854dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt names.put(locale, name); 864dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt } 874dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt className = in.readString(); 8847c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt int localesCount = in.readInt(); 8947c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt if (localesCount > MAP_LIMIT || localesCount < 0) { 9047c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt throw new RuntimeException("bad locale length " + localesCount); 9147c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt } 9247c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt locales = new ArrayList<Locale>(localesCount); 9347c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt while (localesCount-- > 0) { 9447c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt Locale l = (java.util.Locale) in.readSerializable(); 9547c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt locales.add(l); 9647c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt } 974dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt serviceId = in.readString(); 984dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt sessionStartTime = (java.util.Date) in.readSerializable(); 994dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt sessionEndTime = (java.util.Date) in.readSerializable(); 1004dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt } 1014dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt 102ee19cfc386ba5abf702d81f828da05c4be0beb9fHall Liu /** @hide */ 1034dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt public void writeToParcel(Parcel dest, int flags) { 1044dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt Set<Locale> keySet = names.keySet(); 1054dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt dest.writeInt(keySet.size()); 1064dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt for (Locale l : keySet) { 1074dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt dest.writeSerializable(l); 1084dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt dest.writeString(names.get(l)); 1094dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt } 1104dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt dest.writeString(className); 11147c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt int localesCount = locales.size(); 11247c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt dest.writeInt(localesCount); 11347c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt for (Locale l : locales) { 11447c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt dest.writeSerializable(l); 11547c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt } 1164dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt dest.writeString(serviceId); 1174dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt dest.writeSerializable(sessionStartTime); 1184dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt dest.writeSerializable(sessionEndTime); 1194dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt } 1204dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt 1212398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu /** 12223d80af5c11de192bdb648642706c43c942be60eHall Liu * Get the user-displayable name for this cell-broadcast service corresponding to the 12323d80af5c11de192bdb648642706c43c942be60eHall Liu * provided {@link Locale}. 12423d80af5c11de192bdb648642706c43c942be60eHall Liu * @param locale The {@link Locale} in which you want the name of the service. This must be a 125d01f6eec20a19c36ec1af380770e4aedfd6723e1Brad Ebinger * value from the set returned by {@link #getNamedContentLocales()} -- an 126e373ee5d5ce38a7570471ae269e4b7a41052a1beHall Liu * {@link java.util.NoSuchElementException} may be thrown otherwise. 12723d80af5c11de192bdb648642706c43c942be60eHall Liu * @return The {@link CharSequence} providing the name of the service in the given 12823d80af5c11de192bdb648642706c43c942be60eHall Liu * {@link Locale} 1292398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu */ 13023d80af5c11de192bdb648642706c43c942be60eHall Liu public @NonNull CharSequence getNameForLocale(@NonNull Locale locale) { 13123d80af5c11de192bdb648642706c43c942be60eHall Liu if (!names.containsKey(locale)) { 132e373ee5d5ce38a7570471ae269e4b7a41052a1beHall Liu throw new NoSuchElementException("Locale not supported"); 13323d80af5c11de192bdb648642706c43c942be60eHall Liu } 13423d80af5c11de192bdb648642706c43c942be60eHall Liu return names.get(locale); 1358023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu } 1368023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu 1372398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu /** 138d01f6eec20a19c36ec1af380770e4aedfd6723e1Brad Ebinger * Return an unmodifiable set of the current {@link Locale}s that have a user-displayable name 139d01f6eec20a19c36ec1af380770e4aedfd6723e1Brad Ebinger * associated with them. The user-displayable name associated with any {@link Locale} in this 140d01f6eec20a19c36ec1af380770e4aedfd6723e1Brad Ebinger * set can be retrieved with {@link #getNameForLocale(Locale)}. 141d01f6eec20a19c36ec1af380770e4aedfd6723e1Brad Ebinger * @return An unmodifiable set of {@link Locale} objects corresponding to a user-displayable 142d01f6eec20a19c36ec1af380770e4aedfd6723e1Brad Ebinger * content name in that locale. 143d01f6eec20a19c36ec1af380770e4aedfd6723e1Brad Ebinger */ 144d01f6eec20a19c36ec1af380770e4aedfd6723e1Brad Ebinger public @NonNull Set<Locale> getNamedContentLocales() { 145d01f6eec20a19c36ec1af380770e4aedfd6723e1Brad Ebinger return Collections.unmodifiableSet(names.keySet()); 146d01f6eec20a19c36ec1af380770e4aedfd6723e1Brad Ebinger } 147d01f6eec20a19c36ec1af380770e4aedfd6723e1Brad Ebinger 148d01f6eec20a19c36ec1af380770e4aedfd6723e1Brad Ebinger /** 1492398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu * The class name for this service - used to categorize and filter 1502398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu */ 151d666a8916346ed760e809d708c63bf36f8b12aedHall Liu public String getServiceClassName() { 1528023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu return className; 1538023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu } 1548023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu 1552398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu /** 1562398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu * The languages available for this service content 1572398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu */ 15847c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt public List<Locale> getLocales() { 15947c2a3e93eff59fe2309917662093e44c5ab70cfRobert Greenwalt return locales; 1608023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu } 1618023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu 1622398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu /** 1632398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu * The carrier's identifier for the service. 1642398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu */ 1658023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu public String getServiceId() { 1668023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu return serviceId; 1678023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu } 1688023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu 1692398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu /** 1702398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu * The start time indicating when this service will be available. 1712398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu */ 1728023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu public Date getSessionStartTime() { 1738023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu return sessionStartTime; 1748023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu } 1758023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu 1762398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu /** 1772398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu * The end time indicating when this session stops being available. 1782398921320c07e9580dbd0bc0e39302d3e0dc8e3Hall Liu */ 1798023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu public Date getSessionEndTime() { 1808023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu return sessionEndTime; 1818023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu } 1828023332b01dda4f4f780fc5d765089ba090fb8d4Hall Liu 1839f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu @Override 1849f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu public boolean equals(Object o) { 1859f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu if (this == o) return true; 1869f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu if (o == null) { 1879f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu return false; 1889f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu } 1899f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu if (!(o instanceof ServiceInfo)) { 1909f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu return false; 1919f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu } 1929f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu ServiceInfo that = (ServiceInfo) o; 1939f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu return Objects.equals(names, that.names) && 1949f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu Objects.equals(className, that.className) && 1959f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu Objects.equals(locales, that.locales) && 1969f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu Objects.equals(serviceId, that.serviceId) && 1979f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu Objects.equals(sessionStartTime, that.sessionStartTime) && 1989f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu Objects.equals(sessionEndTime, that.sessionEndTime); 1999f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu } 2009f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu 2019f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu @Override 2029f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu public int hashCode() { 2039f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu return Objects.hash(names, className, locales, serviceId, sessionStartTime, sessionEndTime); 2049f116ef480fce78c8a8211ba96e74607e33aec56Hall Liu } 2054dded7a1b5a7ff6ed7402a9c2c512e4751421d7fRobert Greenwalt} 206