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 com.android.i18n.timezone; 18 19 import static com.android.i18n.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 /** 91 * Returns the Mobile Country Code of the network. 92 */ 93 @libcore.api.CorePlatformApi getMcc()94 public String getMcc() { 95 return mccMnc.mcc; 96 } 97 98 /** 99 * Returns the Mobile Network Code of the network. 100 */ 101 @libcore.api.CorePlatformApi getMnc()102 public String getMnc() { 103 return mccMnc.mnc; 104 } 105 106 /** 107 * Returns the country in which the network operates as an ISO 3166 alpha-2 (lower case). 108 */ 109 @libcore.api.CorePlatformApi getCountryIsoCode()110 public String getCountryIsoCode() { 111 return countryIsoCode; 112 } 113 114 @Override equals(Object o)115 public boolean equals(Object o) { 116 if (this == o) { 117 return true; 118 } 119 if (o == null || getClass() != o.getClass()) { 120 return false; 121 } 122 TelephonyNetwork that = (TelephonyNetwork) o; 123 return mccMnc.equals(that.mccMnc) && 124 countryIsoCode.equals(that.countryIsoCode); 125 } 126 127 @Override hashCode()128 public int hashCode() { 129 return Objects.hash(mccMnc, countryIsoCode); 130 } 131 132 @Override toString()133 public String toString() { 134 return "TelephonyNetwork{" 135 + "mccMnc=" + mccMnc 136 + ", countryIsoCode='" + countryIsoCode + '\'' 137 + '}'; 138 } 139 } 140