Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 1 | /** |
| 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 | |
| 17 | package android.service.carrier; |
| 18 | |
chen xu | bc8411c | 2019-03-03 15:15:30 -0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 20 | import android.annotation.Nullable; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
chen xu | 61b2c86 | 2019-03-28 16:28:45 -0700 | [diff] [blame] | 23 | import android.telephony.Rlog; |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 24 | import android.telephony.TelephonyManager; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 25 | |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 26 | import com.android.internal.telephony.uicc.IccUtils; |
| 27 | |
| 28 | import java.util.Objects; |
| 29 | |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 30 | /** |
| 31 | * Used to pass info to CarrierConfigService implementations so they can decide what values to |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 32 | * 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 Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 36 | */ |
| 37 | public class CarrierIdentifier implements Parcelable { |
| 38 | |
| 39 | /** Used to create a {@link CarrierIdentifier} from a {@link Parcel}. */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 40 | public static final @android.annotation.NonNull Creator<CarrierIdentifier> CREATOR = new Creator<CarrierIdentifier>() { |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 41 | @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 Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 54 | private @Nullable String mSpn; |
| 55 | private @Nullable String mImsi; |
| 56 | private @Nullable String mGid1; |
| 57 | private @Nullable String mGid2; |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 58 | private int mCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID; |
chen xu | 45f6621 | 2019-03-06 14:43:40 -0800 | [diff] [blame] | 59 | private int mSpecificCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 60 | |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 61 | public CarrierIdentifier(String mcc, String mnc, @Nullable String spn, @Nullable String imsi, |
| 62 | @Nullable String gid1, @Nullable String gid2) { |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 63 | 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 xu | 45f6621 | 2019-03-06 14:43:40 -0800 | [diff] [blame] | 76 | * @param specificCarrierId specific carrier identifier |
| 77 | * {@link TelephonyManager#getSimSpecificCarrierId()} |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 78 | */ |
chen xu | bc8411c | 2019-03-03 15:15:30 -0800 | [diff] [blame] | 79 | public CarrierIdentifier(@NonNull String mcc, @NonNull String mnc, @Nullable String spn, |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 80 | @Nullable String imsi, @Nullable String gid1, @Nullable String gid2, |
chen xu | 45f6621 | 2019-03-06 14:43:40 -0800 | [diff] [blame] | 81 | int carrierid, int specificCarrierId) { |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 82 | mMcc = mcc; |
| 83 | mMnc = mnc; |
| 84 | mSpn = spn; |
| 85 | mImsi = imsi; |
| 86 | mGid1 = gid1; |
| 87 | mGid2 = gid2; |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 88 | mCarrierId = carrierid; |
chen xu | 45f6621 | 2019-03-06 14:43:40 -0800 | [diff] [blame] | 89 | mSpecificCarrierId = specificCarrierId; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 92 | /** |
| 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 Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 118 | /** @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 Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 134 | @Nullable |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 135 | public String getSpn() { |
| 136 | return mSpn; |
| 137 | } |
| 138 | |
| 139 | /** Get the international mobile subscriber identity. */ |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 140 | @Nullable |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 141 | public String getImsi() { |
| 142 | return mImsi; |
| 143 | } |
| 144 | |
| 145 | /** Get the group identifier level 1. */ |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 146 | @Nullable |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 147 | public String getGid1() { |
| 148 | return mGid1; |
| 149 | } |
| 150 | |
| 151 | /** Get the group identifier level 2. */ |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 152 | @Nullable |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 153 | public String getGid2() { |
| 154 | return mGid2; |
| 155 | } |
| 156 | |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 157 | /** |
chen xu | d47a068 | 2018-12-06 15:34:05 -0800 | [diff] [blame] | 158 | * Returns the carrier id. |
| 159 | * @see TelephonyManager#getSimCarrierId() |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 160 | */ |
| 161 | public int getCarrierId() { |
| 162 | return mCarrierId; |
| 163 | } |
| 164 | |
| 165 | /** |
chen xu | 45f6621 | 2019-03-06 14:43:40 -0800 | [diff] [blame] | 166 | * 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 xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 174 | */ |
chen xu | 45f6621 | 2019-03-06 14:43:40 -0800 | [diff] [blame] | 175 | public int getSpecificCarrierId() { |
| 176 | return mSpecificCarrierId; |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 179 | @Override |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 180 | 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 xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 194 | && Objects.equals(mGid2, that.mGid2) |
| 195 | && Objects.equals(mCarrierId, that.mCarrierId) |
chen xu | 45f6621 | 2019-03-06 14:43:40 -0800 | [diff] [blame] | 196 | && Objects.equals(mSpecificCarrierId, that.mSpecificCarrierId); |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Override |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 200 | public int hashCode(){ |
chen xu | 45f6621 | 2019-03-06 14:43:40 -0800 | [diff] [blame] | 201 | return Objects.hash(mMcc, mMnc, mSpn, mImsi, mGid1, mGid2, mCarrierId, mSpecificCarrierId); |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | @Override |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 205 | 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 xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 217 | out.writeInt(mCarrierId); |
chen xu | 45f6621 | 2019-03-06 14:43:40 -0800 | [diff] [blame] | 218 | out.writeInt(mSpecificCarrierId); |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Jonathan Basseri | b1a4348 | 2016-01-22 19:49:05 -0800 | [diff] [blame] | 221 | @Override |
| 222 | public String toString() { |
| 223 | return "CarrierIdentifier{" |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 224 | + "mcc=" + mMcc |
| 225 | + ",mnc=" + mMnc |
| 226 | + ",spn=" + mSpn |
chen xu | 61b2c86 | 2019-03-28 16:28:45 -0700 | [diff] [blame] | 227 | + ",imsi=" + Rlog.pii(false, mImsi) |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 228 | + ",gid1=" + mGid1 |
| 229 | + ",gid2=" + mGid2 |
| 230 | + ",carrierid=" + mCarrierId |
chen xu | 45f6621 | 2019-03-06 14:43:40 -0800 | [diff] [blame] | 231 | + ",specificCarrierId=" + mSpecificCarrierId |
chen xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 232 | + "}"; |
Jonathan Basseri | b1a4348 | 2016-01-22 19:49:05 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 235 | /** @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 xu | ed7a2e1 | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 243 | mCarrierId = in.readInt(); |
chen xu | 45f6621 | 2019-03-06 14:43:40 -0800 | [diff] [blame] | 244 | mSpecificCarrierId = in.readInt(); |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 245 | } |
Meng Wang | 6499762 | 2016-05-05 09:36:47 -0700 | [diff] [blame] | 246 | |
| 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 Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 255 | } |