blob: 8c73a87e2132f9505f9df6ce6bdf36636c080d3e [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 xud95965a2018-11-11 19:01:50 -080023import android.telephony.TelephonyManager;
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080024
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080025import com.android.internal.telephony.uicc.IccUtils;
26
27import java.util.Objects;
28
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080029/**
30 * Used to pass info to CarrierConfigService implementations so they can decide what values to
chen xud95965a2018-11-11 19:01:50 -080031 * return. Instead of passing mcc, mnc, gid1, gid2, spn, imsi to locate carrier information,
32 * CarrierIdentifier also include carrier id {@link TelephonyManager#getSimCarrierId()},
33 * a platform-wide unique identifier for each carrier. CarrierConfigService can directly use
34 * carrier id as the key to look up the carrier info.
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080035 */
36public class CarrierIdentifier implements Parcelable {
37
38 /** Used to create a {@link CarrierIdentifier} from a {@link Parcel}. */
39 public static final Creator<CarrierIdentifier> CREATOR = new Creator<CarrierIdentifier>() {
40 @Override
41 public CarrierIdentifier createFromParcel(Parcel parcel) {
42 return new CarrierIdentifier(parcel);
43 }
44
45 @Override
46 public CarrierIdentifier[] newArray(int i) {
47 return new CarrierIdentifier[i];
48 }
49 };
50
51 private String mMcc;
52 private String mMnc;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080053 private @Nullable String mSpn;
54 private @Nullable String mImsi;
55 private @Nullable String mGid1;
56 private @Nullable String mGid2;
chen xud95965a2018-11-11 19:01:50 -080057 private int mCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
58 private int mPreciseCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID;
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080059
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080060 public CarrierIdentifier(String mcc, String mnc, @Nullable String spn, @Nullable String imsi,
61 @Nullable String gid1, @Nullable String gid2) {
chen xud95965a2018-11-11 19:01:50 -080062 this(mcc, mnc, spn, imsi, gid1, gid2, TelephonyManager.UNKNOWN_CARRIER_ID,
63 TelephonyManager.UNKNOWN_CARRIER_ID);
64 }
65
66 /**
67 * @param mcc mobile country code
68 * @param mnc mobile network code
69 * @param spn service provider name
70 * @param imsi International Mobile Subscriber Identity {@link TelephonyManager#getSubscriberId()}
71 * @param gid1 group id level 1 {@link TelephonyManager#getGroupIdLevel1()}
72 * @param gid2 group id level 2
73 * @param carrierid carrier unique identifier {@link TelephonyManager#getSimCarrierId()}, used
74 * to uniquely identify the carrier and look up the carrier configurations.
chen xu64c1d7642018-12-06 15:34:05 -080075 * @param preciseCarrierId precise carrier identifier
76 * {@link TelephonyManager#getSimPreciseCarrierId()}
chen xud95965a2018-11-11 19:01:50 -080077 */
chen xubc8411c2019-03-03 15:15:30 -080078 public CarrierIdentifier(@NonNull String mcc, @NonNull String mnc, @Nullable String spn,
chen xud95965a2018-11-11 19:01:50 -080079 @Nullable String imsi, @Nullable String gid1, @Nullable String gid2,
80 int carrierid, int preciseCarrierId) {
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080081 mMcc = mcc;
82 mMnc = mnc;
83 mSpn = spn;
84 mImsi = imsi;
85 mGid1 = gid1;
86 mGid2 = gid2;
chen xud95965a2018-11-11 19:01:50 -080087 mCarrierId = carrierid;
88 mPreciseCarrierId = preciseCarrierId;
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -080089 }
90
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080091 /**
92 * Creates a carrier identifier instance.
93 *
94 * @param mccMnc A 3-byte array as defined by 3GPP TS 24.008.
95 * @param gid1 The group identifier level 1.
96 * @param gid2 The group identifier level 2.
97 * @throws IllegalArgumentException If the length of {@code mccMnc} is not 3.
98 */
99 public CarrierIdentifier(byte[] mccMnc, @Nullable String gid1, @Nullable String gid2) {
100 if (mccMnc.length != 3) {
101 throw new IllegalArgumentException(
102 "MCC & MNC must be set by a 3-byte array: byte[" + mccMnc.length + "]");
103 }
104 String hex = IccUtils.bytesToHexString(mccMnc);
105 mMcc = new String(new char[] {hex.charAt(1), hex.charAt(0), hex.charAt(3)});
106 if (hex.charAt(2) == 'F') {
107 mMnc = new String(new char[] {hex.charAt(5), hex.charAt(4)});
108 } else {
109 mMnc = new String(new char[] {hex.charAt(5), hex.charAt(4), hex.charAt(2)});
110 }
111 mGid1 = gid1;
112 mGid2 = gid2;
113 mSpn = null;
114 mImsi = null;
115 }
116
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800117 /** @hide */
118 public CarrierIdentifier(Parcel parcel) {
119 readFromParcel(parcel);
120 }
121
122 /** Get the mobile country code. */
123 public String getMcc() {
124 return mMcc;
125 }
126
127 /** Get the mobile network code. */
128 public String getMnc() {
129 return mMnc;
130 }
131
132 /** Get the service provider name. */
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800133 @Nullable
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800134 public String getSpn() {
135 return mSpn;
136 }
137
138 /** Get the international mobile subscriber identity. */
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800139 @Nullable
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800140 public String getImsi() {
141 return mImsi;
142 }
143
144 /** Get the group identifier level 1. */
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800145 @Nullable
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800146 public String getGid1() {
147 return mGid1;
148 }
149
150 /** Get the group identifier level 2. */
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800151 @Nullable
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800152 public String getGid2() {
153 return mGid2;
154 }
155
chen xud95965a2018-11-11 19:01:50 -0800156 /**
chen xu64c1d7642018-12-06 15:34:05 -0800157 * Returns the carrier id.
158 * @see TelephonyManager#getSimCarrierId()
chen xud95965a2018-11-11 19:01:50 -0800159 */
160 public int getCarrierId() {
161 return mCarrierId;
162 }
163
164 /**
chen xu64c1d7642018-12-06 15:34:05 -0800165 * Returns the precise carrier id.
166 * @see TelephonyManager#getSimPreciseCarrierId()
chen xud95965a2018-11-11 19:01:50 -0800167 */
168 public int getPreciseCarrierId() {
169 return mPreciseCarrierId;
170 }
171
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800172 @Override
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800173 public boolean equals(Object obj) {
174 if (this == obj) {
175 return true;
176 }
177 if (obj == null || getClass() != obj.getClass()) {
178 return false;
179 }
180
181 CarrierIdentifier that = (CarrierIdentifier) obj;
182 return Objects.equals(mMcc, that.mMcc)
183 && Objects.equals(mMnc, that.mMnc)
184 && Objects.equals(mSpn, that.mSpn)
185 && Objects.equals(mImsi, that.mImsi)
186 && Objects.equals(mGid1, that.mGid1)
chen xud95965a2018-11-11 19:01:50 -0800187 && Objects.equals(mGid2, that.mGid2)
188 && Objects.equals(mCarrierId, that.mCarrierId)
189 && Objects.equals(mPreciseCarrierId, that.mPreciseCarrierId);
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800190 }
191
192 @Override
chen xud95965a2018-11-11 19:01:50 -0800193 public int hashCode(){
194 return Objects.hash(mMcc, mMnc, mSpn, mImsi, mGid1, mGid2, mCarrierId, mPreciseCarrierId);
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800195 }
196
197 @Override
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800198 public int describeContents() {
199 return 0;
200 }
201
202 @Override
203 public void writeToParcel(Parcel out, int flags) {
204 out.writeString(mMcc);
205 out.writeString(mMnc);
206 out.writeString(mSpn);
207 out.writeString(mImsi);
208 out.writeString(mGid1);
209 out.writeString(mGid2);
chen xud95965a2018-11-11 19:01:50 -0800210 out.writeInt(mCarrierId);
211 out.writeInt(mPreciseCarrierId);
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800212 }
213
Jonathan Basserib1a43482016-01-22 19:49:05 -0800214 @Override
215 public String toString() {
216 return "CarrierIdentifier{"
chen xud95965a2018-11-11 19:01:50 -0800217 + "mcc=" + mMcc
218 + ",mnc=" + mMnc
219 + ",spn=" + mSpn
220 + ",imsi=" + mImsi
221 + ",gid1=" + mGid1
222 + ",gid2=" + mGid2
223 + ",carrierid=" + mCarrierId
224 + ",mPreciseCarrierId=" + mPreciseCarrierId
225 + "}";
Jonathan Basserib1a43482016-01-22 19:49:05 -0800226 }
227
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800228 /** @hide */
229 public void readFromParcel(Parcel in) {
230 mMcc = in.readString();
231 mMnc = in.readString();
232 mSpn = in.readString();
233 mImsi = in.readString();
234 mGid1 = in.readString();
235 mGid2 = in.readString();
chen xud95965a2018-11-11 19:01:50 -0800236 mCarrierId = in.readInt();
237 mPreciseCarrierId = in.readInt();
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800238 }
Meng Wang64997622016-05-05 09:36:47 -0700239
240 /** @hide */
241 public interface MatchType {
242 int ALL = 0;
243 int SPN = 1;
244 int IMSI_PREFIX = 2;
245 int GID1 = 3;
246 int GID2 = 4;
247 }
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800248}