| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.carrier; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.os.Parcel; |
| 22 |
import android.os.Parcelable; |
| 23 |
import android.telephony.TelephonyManager; |
| 24 |
|
| 25 |
import com.android.internal.telephony.uicc.IccUtils; |
| 26 |
import com.android.telephony.Rlog; |
| 27 |
|
| 28 |
import java.util.Objects; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class CarrierIdentifier implements Parcelable { |
| 38 |
|
| 39 |
|
| 40 |
public static final @android.annotation.NonNull Creator<CarrierIdentifier> CREATOR = new Creator<CarrierIdentifier>() { |
| 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; |
| 54 |
private @Nullable String mSpn; |
| 55 |
private @Nullable String mImsi; |
| 56 |
private @Nullable String mGid1; |
| 57 |
private @Nullable String mGid2; |
| 58 |
private int mCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID; |
| 59 |
private int mSpecificCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID; |
| 60 |
|
| 61 |
public CarrierIdentifier(String mcc, String mnc, @Nullable String spn, @Nullable String imsi, |
| 62 |
@Nullable String gid1, @Nullable String gid2) { |
| 63 |
this(mcc, mnc, spn, imsi, gid1, gid2, TelephonyManager.UNKNOWN_CARRIER_ID, |
| 64 |
TelephonyManager.UNKNOWN_CARRIER_ID); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public CarrierIdentifier(@NonNull String mcc, @NonNull String mnc, @Nullable String spn, |
| 80 |
@Nullable String imsi, @Nullable String gid1, @Nullable String gid2, |
| 81 |
int carrierid, int specificCarrierId) { |
| 82 |
mMcc = mcc; |
| 83 |
mMnc = mnc; |
| 84 |
mSpn = spn; |
| 85 |
mImsi = imsi; |
| 86 |
mGid1 = gid1; |
| 87 |
mGid2 = gid2; |
| 88 |
mCarrierId = carrierid; |
| 89 |
mSpecificCarrierId = specificCarrierId; |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 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 |
|
| 118 |
|
| 119 |
public CarrierIdentifier(Parcel parcel) { |
| 120 |
readFromParcel(parcel); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
public String getMcc() { |
| 125 |
return mMcc; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
public String getMnc() { |
| 130 |
return mMnc; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
@Nullable |
| 135 |
public String getSpn() { |
| 136 |
return mSpn; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
@Nullable |
| 141 |
public String getImsi() { |
| 142 |
return mImsi; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
@Nullable |
| 147 |
public String getGid1() { |
| 148 |
return mGid1; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
@Nullable |
| 153 |
public String getGid2() { |
| 154 |
return mGid2; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
public int getCarrierId() { |
| 162 |
return mCarrierId; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
public int getSpecificCarrierId() { |
| 176 |
return mSpecificCarrierId; |
| 177 |
} |
| 178 |
|
| 179 |
@Override |
| 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) |
| 194 |
&& Objects.equals(mGid2, that.mGid2) |
| 195 |
&& Objects.equals(mCarrierId, that.mCarrierId) |
| 196 |
&& Objects.equals(mSpecificCarrierId, that.mSpecificCarrierId); |
| 197 |
} |
| 198 |
|
| 199 |
@Override |
| 200 |
public int hashCode(){ |
| 201 |
return Objects.hash(mMcc, mMnc, mSpn, mImsi, mGid1, mGid2, mCarrierId, mSpecificCarrierId); |
| 202 |
} |
| 203 |
|
| 204 |
@Override |
| 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); |
| 217 |
out.writeInt(mCarrierId); |
| 218 |
out.writeInt(mSpecificCarrierId); |
| 219 |
} |
| 220 |
|
| 221 |
@Override |
| 222 |
public String toString() { |
| 223 |
return "CarrierIdentifier{" |
| 224 |
+ "mcc=" + mMcc |
| 225 |
+ ",mnc=" + mMnc |
| 226 |
+ ",spn=" + mSpn |
| 227 |
+ ",imsi=" + Rlog.pii(false, mImsi) |
| 228 |
+ ",gid1=" + mGid1 |
| 229 |
+ ",gid2=" + mGid2 |
| 230 |
+ ",carrierid=" + mCarrierId |
| 231 |
+ ",specificCarrierId=" + mSpecificCarrierId |
| 232 |
+ "}"; |
| 233 |
} |
| 234 |
|
| 235 |
|
| 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(); |
| 243 |
mCarrierId = in.readInt(); |
| 244 |
mSpecificCarrierId = in.readInt(); |
| 245 |
} |
| 246 |
|
| 247 |
|
| 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 |
} |
| 255 |
} |