blob: e930f401ecd5f69c3b15d62be75aae2adeeafbd5 [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 xud95965a2018-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 xud95965a2018-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 xud95965a2018-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 xud95965a2018-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.
74 * @param preciseCarrierId precise carrier identifier {@link TelephonyManager#getSimPreciseCarrierId()}
75 * @hide
76 *
77 * TODO: expose this to public API
78 */
79 public CarrierIdentifier(String mcc, String mnc, @Nullable String spn,
80 @Nullable String imsi, @Nullable String gid1, @Nullable String gid2,
81 int carrierid, int preciseCarrierId) {
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 xud95965a2018-11-11 19:01:50 -080088 mCarrierId = carrierid;
89 mPreciseCarrierId = preciseCarrierId;
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 xud95965a2018-11-11 19:01:50 -0800157 /**
158 * Get the carrier id {@link TelephonyManager#getSimCarrierId() }
159 * @hide
160 */
161 public int getCarrierId() {
162 return mCarrierId;
163 }
164
165 /**
166 * Get the precise carrier id {@link TelephonyManager#getSimPreciseCarrierId()}
167 * @hide
168 */
169 public int getPreciseCarrierId() {
170 return mPreciseCarrierId;
171 }
172
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800173 @Override
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800174 public boolean equals(Object obj) {
175 if (this == obj) {
176 return true;
177 }
178 if (obj == null || getClass() != obj.getClass()) {
179 return false;
180 }
181
182 CarrierIdentifier that = (CarrierIdentifier) obj;
183 return Objects.equals(mMcc, that.mMcc)
184 && Objects.equals(mMnc, that.mMnc)
185 && Objects.equals(mSpn, that.mSpn)
186 && Objects.equals(mImsi, that.mImsi)
187 && Objects.equals(mGid1, that.mGid1)
chen xud95965a2018-11-11 19:01:50 -0800188 && Objects.equals(mGid2, that.mGid2)
189 && Objects.equals(mCarrierId, that.mCarrierId)
190 && Objects.equals(mPreciseCarrierId, that.mPreciseCarrierId);
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800191 }
192
193 @Override
chen xud95965a2018-11-11 19:01:50 -0800194 public int hashCode(){
195 return Objects.hash(mMcc, mMnc, mSpn, mImsi, mGid1, mGid2, mCarrierId, mPreciseCarrierId);
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800196 }
197
198 @Override
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800199 public int describeContents() {
200 return 0;
201 }
202
203 @Override
204 public void writeToParcel(Parcel out, int flags) {
205 out.writeString(mMcc);
206 out.writeString(mMnc);
207 out.writeString(mSpn);
208 out.writeString(mImsi);
209 out.writeString(mGid1);
210 out.writeString(mGid2);
chen xud95965a2018-11-11 19:01:50 -0800211 out.writeInt(mCarrierId);
212 out.writeInt(mPreciseCarrierId);
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800213 }
214
Jonathan Basserib1a43482016-01-22 19:49:05 -0800215 @Override
216 public String toString() {
217 return "CarrierIdentifier{"
chen xud95965a2018-11-11 19:01:50 -0800218 + "mcc=" + mMcc
219 + ",mnc=" + mMnc
220 + ",spn=" + mSpn
221 + ",imsi=" + mImsi
222 + ",gid1=" + mGid1
223 + ",gid2=" + mGid2
224 + ",carrierid=" + mCarrierId
225 + ",mPreciseCarrierId=" + mPreciseCarrierId
226 + "}";
Jonathan Basserib1a43482016-01-22 19:49:05 -0800227 }
228
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800229 /** @hide */
230 public void readFromParcel(Parcel in) {
231 mMcc = in.readString();
232 mMnc = in.readString();
233 mSpn = in.readString();
234 mImsi = in.readString();
235 mGid1 = in.readString();
236 mGid2 = in.readString();
chen xud95965a2018-11-11 19:01:50 -0800237 mCarrierId = in.readInt();
238 mPreciseCarrierId = in.readInt();
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800239 }
Meng Wang64997622016-05-05 09:36:47 -0700240
241 /** @hide */
242 public interface MatchType {
243 int ALL = 0;
244 int SPN = 1;
245 int IMSI_PREFIX = 2;
246 int GID1 = 3;
247 int GID2 = 4;
248 }
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -0800249}