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 | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 23 | import android.telephony.TelephonyManager; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 24 | |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 25 | import com.android.internal.telephony.uicc.IccUtils; |
| 26 | |
| 27 | import java.util.Objects; |
| 28 | |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 29 | /** |
| 30 | * Used to pass info to CarrierConfigService implementations so they can decide what values to |
chen xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 31 | * 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 Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 35 | */ |
| 36 | public 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 Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 53 | private @Nullable String mSpn; |
| 54 | private @Nullable String mImsi; |
| 55 | private @Nullable String mGid1; |
| 56 | private @Nullable String mGid2; |
chen xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 57 | private int mCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID; |
| 58 | private int mPreciseCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 59 | |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 60 | public CarrierIdentifier(String mcc, String mnc, @Nullable String spn, @Nullable String imsi, |
| 61 | @Nullable String gid1, @Nullable String gid2) { |
chen xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 62 | 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 xu | 64c1d764 | 2018-12-06 15:34:05 -0800 | [diff] [blame] | 75 | * @param preciseCarrierId precise carrier identifier |
| 76 | * {@link TelephonyManager#getSimPreciseCarrierId()} |
chen xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 77 | */ |
chen xu | bc8411c | 2019-03-03 15:15:30 -0800 | [diff] [blame] | 78 | public CarrierIdentifier(@NonNull String mcc, @NonNull String mnc, @Nullable String spn, |
chen xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 79 | @Nullable String imsi, @Nullable String gid1, @Nullable String gid2, |
| 80 | int carrierid, int preciseCarrierId) { |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 81 | mMcc = mcc; |
| 82 | mMnc = mnc; |
| 83 | mSpn = spn; |
| 84 | mImsi = imsi; |
| 85 | mGid1 = gid1; |
| 86 | mGid2 = gid2; |
chen xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 87 | mCarrierId = carrierid; |
| 88 | mPreciseCarrierId = preciseCarrierId; |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 89 | } |
| 90 | |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 91 | /** |
| 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 Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 117 | /** @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 Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 133 | @Nullable |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 134 | public String getSpn() { |
| 135 | return mSpn; |
| 136 | } |
| 137 | |
| 138 | /** Get the international mobile subscriber identity. */ |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 139 | @Nullable |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 140 | public String getImsi() { |
| 141 | return mImsi; |
| 142 | } |
| 143 | |
| 144 | /** Get the group identifier level 1. */ |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 145 | @Nullable |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 146 | public String getGid1() { |
| 147 | return mGid1; |
| 148 | } |
| 149 | |
| 150 | /** Get the group identifier level 2. */ |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 151 | @Nullable |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 152 | public String getGid2() { |
| 153 | return mGid2; |
| 154 | } |
| 155 | |
chen xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 156 | /** |
chen xu | 64c1d764 | 2018-12-06 15:34:05 -0800 | [diff] [blame] | 157 | * Returns the carrier id. |
| 158 | * @see TelephonyManager#getSimCarrierId() |
chen xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 159 | */ |
| 160 | public int getCarrierId() { |
| 161 | return mCarrierId; |
| 162 | } |
| 163 | |
| 164 | /** |
chen xu | 64c1d764 | 2018-12-06 15:34:05 -0800 | [diff] [blame] | 165 | * Returns the precise carrier id. |
| 166 | * @see TelephonyManager#getSimPreciseCarrierId() |
chen xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 167 | */ |
| 168 | public int getPreciseCarrierId() { |
| 169 | return mPreciseCarrierId; |
| 170 | } |
| 171 | |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 172 | @Override |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 173 | 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 xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 187 | && Objects.equals(mGid2, that.mGid2) |
| 188 | && Objects.equals(mCarrierId, that.mCarrierId) |
| 189 | && Objects.equals(mPreciseCarrierId, that.mPreciseCarrierId); |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | @Override |
chen xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 193 | public int hashCode(){ |
| 194 | return Objects.hash(mMcc, mMnc, mSpn, mImsi, mGid1, mGid2, mCarrierId, mPreciseCarrierId); |
Holly Jiuyu Sun | e6153b9 | 2017-12-07 15:35:49 -0800 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | @Override |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 198 | 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 xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 210 | out.writeInt(mCarrierId); |
| 211 | out.writeInt(mPreciseCarrierId); |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 212 | } |
| 213 | |
Jonathan Basseri | b1a4348 | 2016-01-22 19:49:05 -0800 | [diff] [blame] | 214 | @Override |
| 215 | public String toString() { |
| 216 | return "CarrierIdentifier{" |
chen xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 217 | + "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 Basseri | b1a4348 | 2016-01-22 19:49:05 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 228 | /** @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 xu | d95965a | 2018-11-11 19:01:50 -0800 | [diff] [blame] | 236 | mCarrierId = in.readInt(); |
| 237 | mPreciseCarrierId = in.readInt(); |
Jonathan Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 238 | } |
Meng Wang | 6499762 | 2016-05-05 09:36:47 -0700 | [diff] [blame] | 239 | |
| 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 Basseri | 9a1c9b6 | 2015-02-25 13:01:52 -0800 | [diff] [blame] | 248 | } |