blob: 568ca0f6b56e9f742adb73baaa08fd9d3af5891b [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
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080019import android.annotation.Nullable;
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080020import android.os.Parcel;
21import android.os.Parcelable;
chen xued7a2e12018-11-11 19:01:50 -080022import android.telephony.TelephonyManager;
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080023
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080024import com.android.internal.telephony.uicc.IccUtils;
25
26import java.util.Objects;
27
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080028/**
29 * Used to pass info to CarrierConfigService implementations so they can decide what values to
chen xued7a2e12018-11-11 19:01:50 -080030 * return. Instead of passing mcc, mnc, gid1, gid2, spn, imsi to locate carrier information,
31 * CarrierIdentifier also include carrier id {@link TelephonyManager#getSimCarrierId()},
32 * a platform-wide unique identifier for each carrier. CarrierConfigService can directly use
33 * carrier id as the key to look up the carrier info.
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080034 */
35public class CarrierIdentifier implements Parcelable {
36
37 /** Used to create a {@link CarrierIdentifier} from a {@link Parcel}. */
38 public static final Creator<CarrierIdentifier> CREATOR = new Creator<CarrierIdentifier>() {
39 @Override
40 public CarrierIdentifier createFromParcel(Parcel parcel) {
41 return new CarrierIdentifier(parcel);
42 }
43
44 @Override
45 public CarrierIdentifier[] newArray(int i) {
46 return new CarrierIdentifier[i];
47 }
48 };
49
50 private String mMcc;
51 private String mMnc;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080052 private @Nullable String mSpn;
53 private @Nullable String mImsi;
54 private @Nullable String mGid1;
55 private @Nullable String mGid2;
chen xued7a2e12018-11-11 19:01:50 -080056 private int mCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
57 private int mPreciseCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080058
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080059 public CarrierIdentifier(String mcc, String mnc, @Nullable String spn, @Nullable String imsi,
60 @Nullable String gid1, @Nullable String gid2) {
chen xued7a2e12018-11-11 19:01:50 -080061 this(mcc, mnc, spn, imsi, gid1, gid2, TelephonyManager.UNKNOWN_CARRIER_ID,
62 TelephonyManager.UNKNOWN_CARRIER_ID);
63 }
64
65 /**
66 * @param mcc mobile country code
67 * @param mnc mobile network code
68 * @param spn service provider name
69 * @param imsi International Mobile Subscriber Identity {@link TelephonyManager#getSubscriberId()}
70 * @param gid1 group id level 1 {@link TelephonyManager#getGroupIdLevel1()}
71 * @param gid2 group id level 2
72 * @param carrierid carrier unique identifier {@link TelephonyManager#getSimCarrierId()}, used
73 * to uniquely identify the carrier and look up the carrier configurations.
chen xud47a0682018-12-06 15:34:05 -080074 * @param preciseCarrierId precise carrier identifier
75 * {@link TelephonyManager#getSimPreciseCarrierId()}
chen xued7a2e12018-11-11 19:01:50 -080076 */
77 public CarrierIdentifier(String mcc, String mnc, @Nullable String spn,
78 @Nullable String imsi, @Nullable String gid1, @Nullable String gid2,
79 int carrierid, int preciseCarrierId) {
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080080 mMcc = mcc;
81 mMnc = mnc;
82 mSpn = spn;
83 mImsi = imsi;
84 mGid1 = gid1;
85 mGid2 = gid2;
chen xued7a2e12018-11-11 19:01:50 -080086 mCarrierId = carrierid;
87 mPreciseCarrierId = preciseCarrierId;
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080088 }
89
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080090 /**
91 * Creates a carrier identifier instance.
92 *
93 * @param mccMnc A 3-byte array as defined by 3GPP TS 24.008.
94 * @param gid1 The group identifier level 1.
95 * @param gid2 The group identifier level 2.
96 * @throws IllegalArgumentException If the length of {@code mccMnc} is not 3.
97 */
98 public CarrierIdentifier(byte[] mccMnc, @Nullable String gid1, @Nullable String gid2) {
99 if (mccMnc.length != 3) {
100 throw new IllegalArgumentException(
101 "MCC & MNC must be set by a 3-byte array: byte[" + mccMnc.length + "]");
102 }
103 String hex = IccUtils.bytesToHexString(mccMnc);
104 mMcc = new String(new char[] {hex.charAt(1), hex.charAt(0), hex.charAt(3)});
105 if (hex.charAt(2) == 'F') {
106 mMnc = new String(new char[] {hex.charAt(5), hex.charAt(4)});
107 } else {
108 mMnc = new String(new char[] {hex.charAt(5), hex.charAt(4), hex.charAt(2)});
109 }
110 mGid1 = gid1;
111 mGid2 = gid2;
112 mSpn = null;
113 mImsi = null;
114 }
115
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800116 /** @hide */
117 public CarrierIdentifier(Parcel parcel) {
118 readFromParcel(parcel);
119 }
120
121 /** Get the mobile country code. */
122 public String getMcc() {
123 return mMcc;
124 }
125
126 /** Get the mobile network code. */
127 public String getMnc() {
128 return mMnc;
129 }
130
131 /** Get the service provider name. */
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800132 @Nullable
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800133 public String getSpn() {
134 return mSpn;
135 }
136
137 /** Get the international mobile subscriber identity. */
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800138 @Nullable
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800139 public String getImsi() {
140 return mImsi;
141 }
142
143 /** Get the group identifier level 1. */
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800144 @Nullable
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800145 public String getGid1() {
146 return mGid1;
147 }
148
149 /** Get the group identifier level 2. */
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800150 @Nullable
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800151 public String getGid2() {
152 return mGid2;
153 }
154
chen xued7a2e12018-11-11 19:01:50 -0800155 /**
chen xud47a0682018-12-06 15:34:05 -0800156 * Returns the carrier id.
157 * @see TelephonyManager#getSimCarrierId()
chen xued7a2e12018-11-11 19:01:50 -0800158 */
159 public int getCarrierId() {
160 return mCarrierId;
161 }
162
163 /**
chen xud47a0682018-12-06 15:34:05 -0800164 * Returns the precise carrier id.
165 * @see TelephonyManager#getSimPreciseCarrierId()
chen xued7a2e12018-11-11 19:01:50 -0800166 */
167 public int getPreciseCarrierId() {
168 return mPreciseCarrierId;
169 }
170
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800171 @Override
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800172 public boolean equals(Object obj) {
173 if (this == obj) {
174 return true;
175 }
176 if (obj == null || getClass() != obj.getClass()) {
177 return false;
178 }
179
180 CarrierIdentifier that = (CarrierIdentifier) obj;
181 return Objects.equals(mMcc, that.mMcc)
182 && Objects.equals(mMnc, that.mMnc)
183 && Objects.equals(mSpn, that.mSpn)
184 && Objects.equals(mImsi, that.mImsi)
185 && Objects.equals(mGid1, that.mGid1)
chen xued7a2e12018-11-11 19:01:50 -0800186 && Objects.equals(mGid2, that.mGid2)
187 && Objects.equals(mCarrierId, that.mCarrierId)
188 && Objects.equals(mPreciseCarrierId, that.mPreciseCarrierId);
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800189 }
190
191 @Override
chen xued7a2e12018-11-11 19:01:50 -0800192 public int hashCode(){
193 return Objects.hash(mMcc, mMnc, mSpn, mImsi, mGid1, mGid2, mCarrierId, mPreciseCarrierId);
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800194 }
195
196 @Override
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800197 public int describeContents() {
198 return 0;
199 }
200
201 @Override
202 public void writeToParcel(Parcel out, int flags) {
203 out.writeString(mMcc);
204 out.writeString(mMnc);
205 out.writeString(mSpn);
206 out.writeString(mImsi);
207 out.writeString(mGid1);
208 out.writeString(mGid2);
chen xued7a2e12018-11-11 19:01:50 -0800209 out.writeInt(mCarrierId);
210 out.writeInt(mPreciseCarrierId);
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800211 }
212
Jonathan Basserib1a43482016-01-22 19:49:05 -0800213 @Override
214 public String toString() {
215 return "CarrierIdentifier{"
chen xued7a2e12018-11-11 19:01:50 -0800216 + "mcc=" + mMcc
217 + ",mnc=" + mMnc
218 + ",spn=" + mSpn
219 + ",imsi=" + mImsi
220 + ",gid1=" + mGid1
221 + ",gid2=" + mGid2
222 + ",carrierid=" + mCarrierId
223 + ",mPreciseCarrierId=" + mPreciseCarrierId
224 + "}";
Jonathan Basserib1a43482016-01-22 19:49:05 -0800225 }
226
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800227 /** @hide */
228 public void readFromParcel(Parcel in) {
229 mMcc = in.readString();
230 mMnc = in.readString();
231 mSpn = in.readString();
232 mImsi = in.readString();
233 mGid1 = in.readString();
234 mGid2 = in.readString();
chen xued7a2e12018-11-11 19:01:50 -0800235 mCarrierId = in.readInt();
236 mPreciseCarrierId = in.readInt();
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800237 }
Meng Wang64997622016-05-05 09:36:47 -0700238
239 /** @hide */
240 public interface MatchType {
241 int ALL = 0;
242 int SPN = 1;
243 int IMSI_PREFIX = 2;
244 int GID1 = 3;
245 int GID2 = 4;
246 }
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800247}