• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 libcore.timezone;
18 
19 import static libcore.timezone.XmlUtils.normalizeCountryIso;
20 
21 import java.util.Objects;
22 
23 /**
24  * Information about a telephony network.
25  *
26  * @hide
27  */
28 @libcore.api.CorePlatformApi
29 public final class TelephonyNetwork {
30 
31     /**
32      * A numeric network identifier consisting of the Mobile Country Code (MCC) and the Mobile
33      * Network Code (MNC).
34      *
35      * @hide
36      */
37     public static final class MccMnc {
38         final String mcc;
39         final String mnc;
40 
MccMnc(String mcc, String mnc)41         public MccMnc(String mcc, String mnc) {
42             this.mcc = mcc;
43             this.mnc = mnc;
44         }
45 
46         @Override
equals(Object o)47         public boolean equals(Object o) {
48             if (this == o) {
49                 return true;
50             }
51             if (o == null || getClass() != o.getClass()) {
52                 return false;
53             }
54             MccMnc mccMnc = (MccMnc) o;
55             return Objects.equals(mcc, mccMnc.mcc)
56                     && Objects.equals(mnc, mccMnc.mnc);
57         }
58 
59         @Override
hashCode()60         public int hashCode() {
61             return Objects.hash(mcc, mnc);
62         }
63 
64         @Override
toString()65         public String toString() {
66             return "MccMnc{"
67                     + "mcc=" + mcc
68                     + ", mnc=" + mnc
69                     + '}';
70         }
71     }
72 
73     private final MccMnc mccMnc;
74     private final String countryIsoCode;
75 
create(String mcc, String mnc, String countryIsoCode)76     public static TelephonyNetwork create(String mcc, String mnc, String countryIsoCode) {
77         String normalizedCountryIso = normalizeCountryIso(countryIsoCode);
78         return new TelephonyNetwork(new MccMnc(mcc, mnc), normalizedCountryIso);
79     }
80 
TelephonyNetwork(MccMnc mccMnc, String countryIsoCode)81     private TelephonyNetwork(MccMnc mccMnc, String countryIsoCode) {
82         this.mccMnc = mccMnc;
83         this.countryIsoCode = Objects.requireNonNull(countryIsoCode);
84     }
85 
getMccMnc()86     public MccMnc getMccMnc() {
87         return mccMnc;
88     }
89 
90     @libcore.api.CorePlatformApi
getMcc()91     public String getMcc() {
92         return mccMnc.mcc;
93     }
94 
95     @libcore.api.CorePlatformApi
getMnc()96     public String getMnc() {
97         return mccMnc.mnc;
98     }
99 
100     @libcore.api.CorePlatformApi
getCountryIsoCode()101     public String getCountryIsoCode() {
102         return countryIsoCode;
103     }
104 
105     @Override
equals(Object o)106     public boolean equals(Object o) {
107         if (this == o) {
108             return true;
109         }
110         if (o == null || getClass() != o.getClass()) {
111             return false;
112         }
113         TelephonyNetwork that = (TelephonyNetwork) o;
114         return mccMnc.equals(that.mccMnc) &&
115                 countryIsoCode.equals(that.countryIsoCode);
116     }
117 
118     @Override
hashCode()119     public int hashCode() {
120         return Objects.hash(mccMnc, countryIsoCode);
121     }
122 
123     @Override
toString()124     public String toString() {
125         return "TelephonyNetwork{"
126                 + "mccMnc=" + mccMnc
127                 + ", countryIsoCode='" + countryIsoCode + '\''
128                 + '}';
129     }
130 }
131