blob: af5bf7475f95109f9940efce0e139962e500e99e [file] [log] [blame]
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08001/**
2 * Copyright (c) 2015, 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
17package android.service.carrier;
18
chen xubc8411c2019-03-03 15:15:30 -080019import android.annotation.NonNull;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080020import android.annotation.Nullable;
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080021import android.os.Parcel;
22import android.os.Parcelable;
chen xu61b2c862019-03-28 16:28:45 -070023import android.telephony.Rlog;
chen xued7a2e12018-11-11 19:01:50 -080024import android.telephony.TelephonyManager;
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080025
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080026import com.android.internal.telephony.uicc.IccUtils;
27
28import java.util.Objects;
29
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080030/**
31 * Used to pass info to CarrierConfigService implementations so they can decide what values to
chen xued7a2e12018-11-11 19:01:50 -080032 * return. Instead of passing mcc, mnc, gid1, gid2, spn, imsi to locate carrier information,
33 * CarrierIdentifier also include carrier id {@link TelephonyManager#getSimCarrierId()},
34 * a platform-wide unique identifier for each carrier. CarrierConfigService can directly use
35 * carrier id as the key to look up the carrier info.
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080036 */
37public class CarrierIdentifier implements Parcelable {
38
39 /** Used to create a {@link CarrierIdentifier} from a {@link Parcel}. */
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070040 public static final @android.annotation.NonNull Creator<CarrierIdentifier> CREATOR = new Creator<CarrierIdentifier>() {
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080041 @Override
42 public CarrierIdentifier createFromParcel(Parcel parcel) {
43 return new CarrierIdentifier(parcel);
44 }
45
46 @Override
47 public CarrierIdentifier[] newArray(int i) {
48 return new CarrierIdentifier[i];
49 }
50 };
51
52 private String mMcc;
53 private String mMnc;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080054 private @Nullable String mSpn;
55 private @Nullable String mImsi;
56 private @Nullable String mGid1;
57 private @Nullable String mGid2;
chen xued7a2e12018-11-11 19:01:50 -080058 private int mCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
chen xu45f66212019-03-06 14:43:40 -080059 private int mSpecificCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080060
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080061 public CarrierIdentifier(String mcc, String mnc, @Nullable String spn, @Nullable String imsi,
62 @Nullable String gid1, @Nullable String gid2) {
chen xued7a2e12018-11-11 19:01:50 -080063 this(mcc, mnc, spn, imsi, gid1, gid2, TelephonyManager.UNKNOWN_CARRIER_ID,
64 TelephonyManager.UNKNOWN_CARRIER_ID);
65 }
66
67 /**
68 * @param mcc mobile country code
69 * @param mnc mobile network code
70 * @param spn service provider name
71 * @param imsi International Mobile Subscriber Identity {@link TelephonyManager#getSubscriberId()}
72 * @param gid1 group id level 1 {@link TelephonyManager#getGroupIdLevel1()}
73 * @param gid2 group id level 2
74 * @param carrierid carrier unique identifier {@link TelephonyManager#getSimCarrierId()}, used
75 * to uniquely identify the carrier and look up the carrier configurations.
chen xu45f66212019-03-06 14:43:40 -080076 * @param specificCarrierId specific carrier identifier
77 * {@link TelephonyManager#getSimSpecificCarrierId()}
chen xued7a2e12018-11-11 19:01:50 -080078 */
chen xubc8411c2019-03-03 15:15:30 -080079 public CarrierIdentifier(@NonNull String mcc, @NonNull String mnc, @Nullable String spn,
chen xued7a2e12018-11-11 19:01:50 -080080 @Nullable String imsi, @Nullable String gid1, @Nullable String gid2,
chen xu45f66212019-03-06 14:43:40 -080081 int carrierid, int specificCarrierId) {
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080082 mMcc = mcc;
83 mMnc = mnc;
84 mSpn = spn;
85 mImsi = imsi;
86 mGid1 = gid1;
87 mGid2 = gid2;
chen xued7a2e12018-11-11 19:01:50 -080088 mCarrierId = carrierid;
chen xu45f66212019-03-06 14:43:40 -080089 mSpecificCarrierId = specificCarrierId;
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080090 }
91
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080092 /**
93 * Creates a carrier identifier instance.
94 *
95 * @param mccMnc A 3-byte array as defined by 3GPP TS 24.008.
96 * @param gid1 The group identifier level 1.
97 * @param gid2 The group identifier level 2.
98 * @throws IllegalArgumentException If the length of {@code mccMnc} is not 3.
99 */
100 public CarrierIdentifier(byte[] mccMnc, @Nullable String gid1, @Nullable String gid2) {
101 if (mccMnc.length != 3) {
102 throw new IllegalArgumentException(
103 "MCC & MNC must be set by a 3-byte array: byte[" + mccMnc.length + "]");
104 }
105 String hex = IccUtils.bytesToHexString(mccMnc);
106 mMcc = new String(new char[] {hex.charAt(1), hex.charAt(0), hex.charAt(3)});
107 if (hex.charAt(2) == 'F') {
108 mMnc = new String(new char[] {hex.charAt(5), hex.charAt(4)});
109 } else {
110 mMnc = new String(new char[] {hex.charAt(5), hex.charAt(4), hex.charAt(2)});
111 }
112 mGid1 = gid1;
113 mGid2 = gid2;
114 mSpn = null;
115 mImsi = null;
116 }
117
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800118 /** @hide */
119 public CarrierIdentifier(Parcel parcel) {
120 readFromParcel(parcel);
121 }
122
123 /** Get the mobile country code. */
124 public String getMcc() {
125 return mMcc;
126 }
127
128 /** Get the mobile network code. */
129 public String getMnc() {
130 return mMnc;
131 }
132
133 /** Get the service provider name. */
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800134 @Nullable
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800135 public String getSpn() {
136 return mSpn;
137 }
138
139 /** Get the international mobile subscriber identity. */
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800140 @Nullable
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800141 public String getImsi() {
142 return mImsi;
143 }
144
145 /** Get the group identifier level 1. */
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800146 @Nullable
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800147 public String getGid1() {
148 return mGid1;
149 }
150
151 /** Get the group identifier level 2. */
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800152 @Nullable
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800153 public String getGid2() {
154 return mGid2;
155 }
156
chen xued7a2e12018-11-11 19:01:50 -0800157 /**
chen xud47a0682018-12-06 15:34:05 -0800158 * Returns the carrier id.
159 * @see TelephonyManager#getSimCarrierId()
chen xued7a2e12018-11-11 19:01:50 -0800160 */
161 public int getCarrierId() {
162 return mCarrierId;
163 }
164
165 /**
chen xu45f66212019-03-06 14:43:40 -0800166 * A specific carrier ID returns the fine-grained carrier ID of the current subscription.
167 * It can represent the fact that a carrier may be in effect an aggregation of other carriers
168 * (ie in an MVNO type scenario) where each of these specific carriers which are used to make
169 * up the actual carrier service may have different carrier configurations.
170 * A specific carrier ID could also be used, for example, in a scenario where a carrier requires
171 * different carrier configuration for different service offering such as a prepaid plan.
172 *
173 * @see TelephonyManager#getSimSpecificCarrierId()
chen xued7a2e12018-11-11 19:01:50 -0800174 */
chen xu45f66212019-03-06 14:43:40 -0800175 public int getSpecificCarrierId() {
176 return mSpecificCarrierId;
chen xued7a2e12018-11-11 19:01:50 -0800177 }
178
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800179 @Override
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800180 public boolean equals(Object obj) {
181 if (this == obj) {
182 return true;
183 }
184 if (obj == null || getClass() != obj.getClass()) {
185 return false;
186 }
187
188 CarrierIdentifier that = (CarrierIdentifier) obj;
189 return Objects.equals(mMcc, that.mMcc)
190 && Objects.equals(mMnc, that.mMnc)
191 && Objects.equals(mSpn, that.mSpn)
192 && Objects.equals(mImsi, that.mImsi)
193 && Objects.equals(mGid1, that.mGid1)
chen xued7a2e12018-11-11 19:01:50 -0800194 && Objects.equals(mGid2, that.mGid2)
195 && Objects.equals(mCarrierId, that.mCarrierId)
chen xu45f66212019-03-06 14:43:40 -0800196 && Objects.equals(mSpecificCarrierId, that.mSpecificCarrierId);
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800197 }
198
199 @Override
chen xued7a2e12018-11-11 19:01:50 -0800200 public int hashCode(){
chen xu45f66212019-03-06 14:43:40 -0800201 return Objects.hash(mMcc, mMnc, mSpn, mImsi, mGid1, mGid2, mCarrierId, mSpecificCarrierId);
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800202 }
203
204 @Override
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800205 public int describeContents() {
206 return 0;
207 }
208
209 @Override
210 public void writeToParcel(Parcel out, int flags) {
211 out.writeString(mMcc);
212 out.writeString(mMnc);
213 out.writeString(mSpn);
214 out.writeString(mImsi);
215 out.writeString(mGid1);
216 out.writeString(mGid2);
chen xued7a2e12018-11-11 19:01:50 -0800217 out.writeInt(mCarrierId);
chen xu45f66212019-03-06 14:43:40 -0800218 out.writeInt(mSpecificCarrierId);
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800219 }
220
Jonathan Basserib1a43482016-01-22 19:49:05 -0800221 @Override
222 public String toString() {
223 return "CarrierIdentifier{"
chen xued7a2e12018-11-11 19:01:50 -0800224 + "mcc=" + mMcc
225 + ",mnc=" + mMnc
226 + ",spn=" + mSpn
chen xu61b2c862019-03-28 16:28:45 -0700227 + ",imsi=" + Rlog.pii(false, mImsi)
chen xued7a2e12018-11-11 19:01:50 -0800228 + ",gid1=" + mGid1
229 + ",gid2=" + mGid2
230 + ",carrierid=" + mCarrierId
chen xu45f66212019-03-06 14:43:40 -0800231 + ",specificCarrierId=" + mSpecificCarrierId
chen xued7a2e12018-11-11 19:01:50 -0800232 + "}";
Jonathan Basserib1a43482016-01-22 19:49:05 -0800233 }
234
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800235 /** @hide */
236 public void readFromParcel(Parcel in) {
237 mMcc = in.readString();
238 mMnc = in.readString();
239 mSpn = in.readString();
240 mImsi = in.readString();
241 mGid1 = in.readString();
242 mGid2 = in.readString();
chen xued7a2e12018-11-11 19:01:50 -0800243 mCarrierId = in.readInt();
chen xu45f66212019-03-06 14:43:40 -0800244 mSpecificCarrierId = in.readInt();
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800245 }
Meng Wang64997622016-05-05 09:36:47 -0700246
247 /** @hide */
248 public interface MatchType {
249 int ALL = 0;
250 int SPN = 1;
251 int IMSI_PREFIX = 2;
252 int GID1 = 3;
253 int GID2 = 4;
254 }
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800255}