1 /* 2 * Copyright (C) 2017 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 package android.service.euicc; 17 18 import android.annotation.IntDef; 19 import android.annotation.Nullable; 20 import android.annotation.SystemApi; 21 import android.annotation.UnsupportedAppUsage; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 import android.service.carrier.CarrierIdentifier; 25 import android.telephony.UiccAccessRule; 26 import android.text.TextUtils; 27 28 import java.lang.annotation.Retention; 29 import java.lang.annotation.RetentionPolicy; 30 import java.util.Arrays; 31 import java.util.List; 32 import java.util.Objects; 33 34 /** 35 * Information about an embedded profile (subscription) on an eUICC. 36 * 37 * @hide 38 */ 39 @SystemApi 40 public final class EuiccProfileInfo implements Parcelable { 41 42 /** Profile policy rules (bit mask) */ 43 @Retention(RetentionPolicy.SOURCE) 44 @IntDef(flag = true, prefix = { "POLICY_RULE_" }, value = { 45 POLICY_RULE_DO_NOT_DISABLE, 46 POLICY_RULE_DO_NOT_DELETE, 47 POLICY_RULE_DELETE_AFTER_DISABLING 48 }) 49 /** @hide */ 50 public @interface PolicyRule {} 51 /** Once this profile is enabled, it cannot be disabled. */ 52 public static final int POLICY_RULE_DO_NOT_DISABLE = 1; 53 /** This profile cannot be deleted. */ 54 public static final int POLICY_RULE_DO_NOT_DELETE = 1 << 1; 55 /** This profile should be deleted after being disabled. */ 56 public static final int POLICY_RULE_DELETE_AFTER_DISABLING = 1 << 2; 57 58 /** Class of the profile */ 59 @Retention(RetentionPolicy.SOURCE) 60 @IntDef(prefix = { "PROFILE_CLASS_" }, value = { 61 PROFILE_CLASS_TESTING, 62 PROFILE_CLASS_PROVISIONING, 63 PROFILE_CLASS_OPERATIONAL, 64 PROFILE_CLASS_UNSET 65 }) 66 /** @hide */ 67 public @interface ProfileClass {} 68 /** Testing profiles */ 69 public static final int PROFILE_CLASS_TESTING = 0; 70 /** Provisioning profiles which are pre-loaded on eUICC */ 71 public static final int PROFILE_CLASS_PROVISIONING = 1; 72 /** Operational profiles which can be pre-loaded or downloaded */ 73 public static final int PROFILE_CLASS_OPERATIONAL = 2; 74 /** 75 * Profile class not set. 76 * @hide 77 */ 78 public static final int PROFILE_CLASS_UNSET = -1; 79 80 /** State of the profile */ 81 @Retention(RetentionPolicy.SOURCE) 82 @IntDef(prefix = { "PROFILE_STATE_" }, value = { 83 PROFILE_STATE_DISABLED, 84 PROFILE_STATE_ENABLED, 85 PROFILE_STATE_UNSET 86 }) 87 /** @hide */ 88 public @interface ProfileState {} 89 /** Disabled profiles */ 90 public static final int PROFILE_STATE_DISABLED = 0; 91 /** Enabled profile */ 92 public static final int PROFILE_STATE_ENABLED = 1; 93 /** 94 * Profile state not set. 95 * @hide 96 */ 97 public static final int PROFILE_STATE_UNSET = -1; 98 99 /** The iccid of the subscription. */ 100 private final String mIccid; 101 102 /** An optional nickname for the subscription. */ 103 private final @Nullable String mNickname; 104 105 /** The service provider name for the subscription. */ 106 private final String mServiceProviderName; 107 108 /** The profile name for the subscription. */ 109 private final String mProfileName; 110 111 /** Profile class for the subscription. */ 112 @ProfileClass private final int mProfileClass; 113 114 /** The profile state of the subscription. */ 115 @ProfileState private final int mState; 116 117 /** The operator Id of the subscription. */ 118 private final CarrierIdentifier mCarrierIdentifier; 119 120 /** The policy rules of the subscription. */ 121 @PolicyRule private final int mPolicyRules; 122 123 /** 124 * Optional access rules defining which apps can manage this subscription. If unset, only the 125 * platform can manage it. 126 */ 127 private final @Nullable UiccAccessRule[] mAccessRules; 128 129 public static final @android.annotation.NonNull Creator<EuiccProfileInfo> CREATOR = new Creator<EuiccProfileInfo>() { 130 @Override 131 public EuiccProfileInfo createFromParcel(Parcel in) { 132 return new EuiccProfileInfo(in); 133 } 134 135 @Override 136 public EuiccProfileInfo[] newArray(int size) { 137 return new EuiccProfileInfo[size]; 138 } 139 }; 140 141 // TODO(b/70292228): Remove this method when LPA can be updated. 142 /** 143 * @hide 144 * @deprecated - Do not use. 145 */ 146 @Deprecated 147 @UnsupportedAppUsage EuiccProfileInfo(String iccid, @Nullable UiccAccessRule[] accessRules, @Nullable String nickname)148 public EuiccProfileInfo(String iccid, @Nullable UiccAccessRule[] accessRules, 149 @Nullable String nickname) { 150 if (!TextUtils.isDigitsOnly(iccid)) { 151 throw new IllegalArgumentException("iccid contains invalid characters: " + iccid); 152 } 153 this.mIccid = iccid; 154 this.mAccessRules = accessRules; 155 this.mNickname = nickname; 156 157 this.mServiceProviderName = null; 158 this.mProfileName = null; 159 this.mProfileClass = PROFILE_CLASS_UNSET; 160 this.mState = PROFILE_STATE_UNSET; 161 this.mCarrierIdentifier = null; 162 this.mPolicyRules = 0; 163 } 164 EuiccProfileInfo(Parcel in)165 private EuiccProfileInfo(Parcel in) { 166 mIccid = in.readString(); 167 mNickname = in.readString(); 168 mServiceProviderName = in.readString(); 169 mProfileName = in.readString(); 170 mProfileClass = in.readInt(); 171 mState = in.readInt(); 172 byte exist = in.readByte(); 173 if (exist == (byte) 1) { 174 mCarrierIdentifier = CarrierIdentifier.CREATOR.createFromParcel(in); 175 } else { 176 mCarrierIdentifier = null; 177 } 178 mPolicyRules = in.readInt(); 179 mAccessRules = in.createTypedArray(UiccAccessRule.CREATOR); 180 } 181 182 @Override writeToParcel(Parcel dest, int flags)183 public void writeToParcel(Parcel dest, int flags) { 184 dest.writeString(mIccid); 185 dest.writeString(mNickname); 186 dest.writeString(mServiceProviderName); 187 dest.writeString(mProfileName); 188 dest.writeInt(mProfileClass); 189 dest.writeInt(mState); 190 if (mCarrierIdentifier != null) { 191 dest.writeByte((byte) 1); 192 mCarrierIdentifier.writeToParcel(dest, flags); 193 } else { 194 dest.writeByte((byte) 0); 195 } 196 dest.writeInt(mPolicyRules); 197 dest.writeTypedArray(mAccessRules, flags); 198 } 199 200 @Override describeContents()201 public int describeContents() { 202 return 0; 203 } 204 205 /** The builder to build a new {@link EuiccProfileInfo} instance. */ 206 public static final class Builder { 207 private String mIccid; 208 private List<UiccAccessRule> mAccessRules; 209 private String mNickname; 210 private String mServiceProviderName; 211 private String mProfileName; 212 @ProfileClass private int mProfileClass; 213 @ProfileState private int mState; 214 private CarrierIdentifier mCarrierIdentifier; 215 @PolicyRule private int mPolicyRules; 216 Builder(String value)217 public Builder(String value) { 218 if (!TextUtils.isDigitsOnly(value)) { 219 throw new IllegalArgumentException("iccid contains invalid characters: " + value); 220 } 221 mIccid = value; 222 } 223 Builder(EuiccProfileInfo baseProfile)224 public Builder(EuiccProfileInfo baseProfile) { 225 mIccid = baseProfile.mIccid; 226 mNickname = baseProfile.mNickname; 227 mServiceProviderName = baseProfile.mServiceProviderName; 228 mProfileName = baseProfile.mProfileName; 229 mProfileClass = baseProfile.mProfileClass; 230 mState = baseProfile.mState; 231 mCarrierIdentifier = baseProfile.mCarrierIdentifier; 232 mPolicyRules = baseProfile.mPolicyRules; 233 mAccessRules = Arrays.asList(baseProfile.mAccessRules); 234 } 235 236 /** Builds the profile instance. */ build()237 public EuiccProfileInfo build() { 238 if (mIccid == null) { 239 throw new IllegalStateException("ICCID must be set for a profile."); 240 } 241 return new EuiccProfileInfo( 242 mIccid, 243 mNickname, 244 mServiceProviderName, 245 mProfileName, 246 mProfileClass, 247 mState, 248 mCarrierIdentifier, 249 mPolicyRules, 250 mAccessRules); 251 } 252 253 /** Sets the iccId of the subscription. */ setIccid(String value)254 public Builder setIccid(String value) { 255 if (!TextUtils.isDigitsOnly(value)) { 256 throw new IllegalArgumentException("iccid contains invalid characters: " + value); 257 } 258 mIccid = value; 259 return this; 260 } 261 262 /** Sets the nickname of the subscription. */ setNickname(String value)263 public Builder setNickname(String value) { 264 mNickname = value; 265 return this; 266 } 267 268 /** Sets the service provider name of the subscription. */ setServiceProviderName(String value)269 public Builder setServiceProviderName(String value) { 270 mServiceProviderName = value; 271 return this; 272 } 273 274 /** Sets the profile name of the subscription. */ setProfileName(String value)275 public Builder setProfileName(String value) { 276 mProfileName = value; 277 return this; 278 } 279 280 /** Sets the profile class of the subscription. */ setProfileClass(@rofileClass int value)281 public Builder setProfileClass(@ProfileClass int value) { 282 mProfileClass = value; 283 return this; 284 } 285 286 /** Sets the state of the subscription. */ setState(@rofileState int value)287 public Builder setState(@ProfileState int value) { 288 mState = value; 289 return this; 290 } 291 292 /** Sets the carrier identifier of the subscription. */ setCarrierIdentifier(CarrierIdentifier value)293 public Builder setCarrierIdentifier(CarrierIdentifier value) { 294 mCarrierIdentifier = value; 295 return this; 296 } 297 298 /** Sets the policy rules of the subscription. */ setPolicyRules(@olicyRule int value)299 public Builder setPolicyRules(@PolicyRule int value) { 300 mPolicyRules = value; 301 return this; 302 } 303 304 /** Sets the access rules of the subscription. */ setUiccAccessRule(@ullable List<UiccAccessRule> value)305 public Builder setUiccAccessRule(@Nullable List<UiccAccessRule> value) { 306 mAccessRules = value; 307 return this; 308 } 309 } 310 EuiccProfileInfo( String iccid, @Nullable String nickname, String serviceProviderName, String profileName, @ProfileClass int profileClass, @ProfileState int state, CarrierIdentifier carrierIdentifier, @PolicyRule int policyRules, @Nullable List<UiccAccessRule> accessRules)311 private EuiccProfileInfo( 312 String iccid, 313 @Nullable String nickname, 314 String serviceProviderName, 315 String profileName, 316 @ProfileClass int profileClass, 317 @ProfileState int state, 318 CarrierIdentifier carrierIdentifier, 319 @PolicyRule int policyRules, 320 @Nullable List<UiccAccessRule> accessRules) { 321 this.mIccid = iccid; 322 this.mNickname = nickname; 323 this.mServiceProviderName = serviceProviderName; 324 this.mProfileName = profileName; 325 this.mProfileClass = profileClass; 326 this.mState = state; 327 this.mCarrierIdentifier = carrierIdentifier; 328 this.mPolicyRules = policyRules; 329 if (accessRules != null && accessRules.size() > 0) { 330 this.mAccessRules = accessRules.toArray(new UiccAccessRule[accessRules.size()]); 331 } else { 332 this.mAccessRules = null; 333 } 334 } 335 336 /** Gets the ICCID string. */ getIccid()337 public String getIccid() { 338 return mIccid; 339 } 340 341 /** Gets the access rules. */ 342 @Nullable getUiccAccessRules()343 public List<UiccAccessRule> getUiccAccessRules() { 344 if (mAccessRules == null) return null; 345 return Arrays.asList(mAccessRules); 346 } 347 348 /** Gets the nickname. */ 349 @Nullable getNickname()350 public String getNickname() { 351 return mNickname; 352 } 353 354 /** Gets the service provider name. */ getServiceProviderName()355 public String getServiceProviderName() { 356 return mServiceProviderName; 357 } 358 359 /** Gets the profile name. */ getProfileName()360 public String getProfileName() { 361 return mProfileName; 362 } 363 364 /** Gets the profile class. */ 365 @ProfileClass getProfileClass()366 public int getProfileClass() { 367 return mProfileClass; 368 } 369 370 /** Gets the state of the subscription. */ 371 @ProfileState getState()372 public int getState() { 373 return mState; 374 } 375 376 /** Gets the carrier identifier. */ getCarrierIdentifier()377 public CarrierIdentifier getCarrierIdentifier() { 378 return mCarrierIdentifier; 379 } 380 381 /** Gets the policy rules. */ 382 @PolicyRule getPolicyRules()383 public int getPolicyRules() { 384 return mPolicyRules; 385 } 386 387 /** Returns whether any policy rule exists. */ hasPolicyRules()388 public boolean hasPolicyRules() { 389 return mPolicyRules != 0; 390 } 391 392 /** Checks whether a certain policy rule exists. */ hasPolicyRule(@olicyRule int policy)393 public boolean hasPolicyRule(@PolicyRule int policy) { 394 return (mPolicyRules & policy) != 0; 395 } 396 397 @Override equals(Object obj)398 public boolean equals(Object obj) { 399 if (this == obj) { 400 return true; 401 } 402 if (obj == null || getClass() != obj.getClass()) { 403 return false; 404 } 405 406 EuiccProfileInfo that = (EuiccProfileInfo) obj; 407 return Objects.equals(mIccid, that.mIccid) 408 && Objects.equals(mNickname, that.mNickname) 409 && Objects.equals(mServiceProviderName, that.mServiceProviderName) 410 && Objects.equals(mProfileName, that.mProfileName) 411 && mProfileClass == that.mProfileClass 412 && mState == that.mState 413 && Objects.equals(mCarrierIdentifier, that.mCarrierIdentifier) 414 && mPolicyRules == that.mPolicyRules 415 && Arrays.equals(mAccessRules, that.mAccessRules); 416 } 417 418 @Override hashCode()419 public int hashCode() { 420 int result = 1; 421 result = 31 * result + Objects.hashCode(mIccid); 422 result = 31 * result + Objects.hashCode(mNickname); 423 result = 31 * result + Objects.hashCode(mServiceProviderName); 424 result = 31 * result + Objects.hashCode(mProfileName); 425 result = 31 * result + mProfileClass; 426 result = 31 * result + mState; 427 result = 31 * result + Objects.hashCode(mCarrierIdentifier); 428 result = 31 * result + mPolicyRules; 429 result = 31 * result + Arrays.hashCode(mAccessRules); 430 return result; 431 } 432 433 @Override toString()434 public String toString() { 435 return "EuiccProfileInfo (nickname=" 436 + mNickname 437 + ", serviceProviderName=" 438 + mServiceProviderName 439 + ", profileName=" 440 + mProfileName 441 + ", profileClass=" 442 + mProfileClass 443 + ", state=" 444 + mState 445 + ", CarrierIdentifier=" 446 + mCarrierIdentifier 447 + ", policyRules=" 448 + mPolicyRules 449 + ", accessRules=" 450 + Arrays.toString(mAccessRules) 451 + ")"; 452 } 453 } 454