blob: 8e752d1c6c1df1fa723e7b0bbfe9bd06641eb542 [file] [log] [blame]
Jeff Davidsond02731f2017-04-09 14:31:09 -07001/*
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 */
16package android.service.euicc;
17
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080018import android.annotation.IntDef;
Jeff Davidsond02731f2017-04-09 14:31:09 -070019import android.annotation.Nullable;
20import android.os.Parcel;
21import android.os.Parcelable;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080022import android.service.carrier.CarrierIdentifier;
Jeff Davidsond02731f2017-04-09 14:31:09 -070023import android.telephony.UiccAccessRule;
24import android.text.TextUtils;
25
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080026import java.lang.annotation.Retention;
27import java.lang.annotation.RetentionPolicy;
28import java.util.Arrays;
29import java.util.Objects;
30
Jeff Davidsond02731f2017-04-09 14:31:09 -070031/**
32 * Information about an embedded profile (subscription) on an eUICC.
33 *
34 * @hide
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +000035 *
36 * TODO(b/35851809): Make this a SystemApi.
Jeff Davidsond02731f2017-04-09 14:31:09 -070037 */
38public final class EuiccProfileInfo implements Parcelable {
39
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080040 /** Profile policy rules (bit mask) */
41 @Retention(RetentionPolicy.SOURCE)
42 @IntDef(flag = true, prefix = { "POLICY_RULE_" }, value = {
43 POLICY_RULE_DO_NOT_DISABLE,
44 POLICY_RULE_DO_NOT_DELETE,
45 POLICY_RULE_DELETE_AFTER_DISABLING
46 })
47 public @interface PolicyRule {}
48 /** Once this profile is enabled, it cannot be disabled. */
49 public static final int POLICY_RULE_DO_NOT_DISABLE = 1;
50 /** This profile cannot be deleted. */
51 public static final int POLICY_RULE_DO_NOT_DELETE = 1 << 1;
52 /** This profile should be deleted after being disabled. */
53 public static final int POLICY_RULE_DELETE_AFTER_DISABLING = 1 << 2;
54
55 /** Class of the profile */
56 @Retention(RetentionPolicy.SOURCE)
57 @IntDef(prefix = { "PROFILE_CLASS_" }, value = {
58 PROFILE_CLASS_TESTING,
59 PROFILE_CLASS_PROVISIONING,
60 PROFILE_CLASS_OPERATIONAL,
61 PROFILE_CLASS_UNSET
62 })
63 public @interface ProfileClass {}
64 /** Testing profiles */
65 public static final int PROFILE_CLASS_TESTING = 0;
66 /** Provisioning profiles which are pre-loaded on eUICC */
67 public static final int PROFILE_CLASS_PROVISIONING = 1;
68 /** Operational profiles which can be pre-loaded or downloaded */
69 public static final int PROFILE_CLASS_OPERATIONAL = 2;
70 /**
71 * Profile class not set.
72 * @hide
73 */
74 public static final int PROFILE_CLASS_UNSET = -1;
75
76 /** State of the profile */
77 @Retention(RetentionPolicy.SOURCE)
78 @IntDef(prefix = { "PROFILE_STATE_" }, value = {
79 PROFILE_STATE_DISABLED,
80 PROFILE_STATE_ENABLED,
81 PROFILE_STATE_UNSET
82 })
83 public @interface ProfileState {}
84 /** Disabled profiles */
85 public static final int PROFILE_STATE_DISABLED = 0;
86 /** Enabled profile */
87 public static final int PROFILE_STATE_ENABLED = 1;
88 /**
89 * Profile state not set.
90 * @hide
91 */
92 public static final int PROFILE_STATE_UNSET = -1;
93
Jeff Davidsond02731f2017-04-09 14:31:09 -070094 /** The iccid of the subscription. */
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +000095 public final String iccid;
Jeff Davidsond02731f2017-04-09 14:31:09 -070096
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080097 /** An optional nickname for the subscription. */
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +000098 public final @Nullable String nickname;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -080099
100 /** The service provider name for the subscription. */
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000101 public final String serviceProviderName;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800102
103 /** The profile name for the subscription. */
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000104 public final String profileName;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800105
106 /** Profile class for the subscription. */
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000107 @ProfileClass public final int profileClass;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800108
109 /** The profile state of the subscription. */
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000110 @ProfileState public final int state;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800111
112 /** The operator Id of the subscription. */
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000113 public final CarrierIdentifier carrierIdentifier;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800114
115 /** The policy rules of the subscription. */
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000116 @PolicyRule public final int policyRules;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800117
Jeff Davidsond02731f2017-04-09 14:31:09 -0700118 /**
119 * Optional access rules defining which apps can manage this subscription. If unset, only the
120 * platform can manage it.
121 */
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000122 public final @Nullable UiccAccessRule[] accessRules;
Jeff Davidsond02731f2017-04-09 14:31:09 -0700123
Jeff Davidsond02731f2017-04-09 14:31:09 -0700124 public static final Creator<EuiccProfileInfo> CREATOR = new Creator<EuiccProfileInfo>() {
125 @Override
126 public EuiccProfileInfo createFromParcel(Parcel in) {
127 return new EuiccProfileInfo(in);
128 }
129
130 @Override
131 public EuiccProfileInfo[] newArray(int size) {
132 return new EuiccProfileInfo[size];
133 }
134 };
135
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800136 // TODO(b/70292228): Remove this method when LPA can be updated.
137 /**
138 * @hide
139 * @deprecated - Do not use.
140 */
141 @Deprecated
Jeff Davidsond02731f2017-04-09 14:31:09 -0700142 public EuiccProfileInfo(String iccid, @Nullable UiccAccessRule[] accessRules,
143 @Nullable String nickname) {
144 if (!TextUtils.isDigitsOnly(iccid)) {
145 throw new IllegalArgumentException("iccid contains invalid characters: " + iccid);
146 }
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000147 this.iccid = iccid;
148 this.accessRules = accessRules;
149 this.nickname = nickname;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800150
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000151 this.serviceProviderName = null;
152 this.profileName = null;
153 this.profileClass = PROFILE_CLASS_UNSET;
154 this.state = PROFILE_CLASS_UNSET;
155 this.carrierIdentifier = null;
156 this.policyRules = 0;
Jeff Davidsond02731f2017-04-09 14:31:09 -0700157 }
158
159 private EuiccProfileInfo(Parcel in) {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000160 iccid = in.readString();
161 nickname = in.readString();
162 serviceProviderName = in.readString();
163 profileName = in.readString();
164 profileClass = in.readInt();
165 state = in.readInt();
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800166 byte exist = in.readByte();
167 if (exist == (byte) 1) {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000168 carrierIdentifier = CarrierIdentifier.CREATOR.createFromParcel(in);
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800169 } else {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000170 carrierIdentifier = null;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800171 }
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000172 policyRules = in.readInt();
173 accessRules = in.createTypedArray(UiccAccessRule.CREATOR);
Jeff Davidsond02731f2017-04-09 14:31:09 -0700174 }
175
176 @Override
177 public void writeToParcel(Parcel dest, int flags) {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000178 dest.writeString(iccid);
179 dest.writeString(nickname);
180 dest.writeString(serviceProviderName);
181 dest.writeString(profileName);
182 dest.writeInt(profileClass);
183 dest.writeInt(state);
184 if (carrierIdentifier != null) {
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800185 dest.writeByte((byte) 1);
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000186 carrierIdentifier.writeToParcel(dest, flags);
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800187 } else {
188 dest.writeByte((byte) 0);
189 }
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000190 dest.writeInt(policyRules);
191 dest.writeTypedArray(accessRules, flags);
Jeff Davidsond02731f2017-04-09 14:31:09 -0700192 }
193
194 @Override
195 public int describeContents() {
196 return 0;
197 }
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800198
199 /** The builder to build a new {@link EuiccProfileInfo} instance. */
200 public static final class Builder {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000201 public String iccid;
202 public UiccAccessRule[] accessRules;
203 public String nickname;
204 public String serviceProviderName;
205 public String profileName;
206 @ProfileClass public int profileClass;
207 @ProfileState public int state;
208 public CarrierIdentifier carrierIdentifier;
209 @PolicyRule public int policyRules;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800210
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000211 public Builder() {}
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800212
213 public Builder(EuiccProfileInfo baseProfile) {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000214 iccid = baseProfile.iccid;
215 nickname = baseProfile.nickname;
216 serviceProviderName = baseProfile.serviceProviderName;
217 profileName = baseProfile.profileName;
218 profileClass = baseProfile.profileClass;
219 state = baseProfile.state;
220 carrierIdentifier = baseProfile.carrierIdentifier;
221 policyRules = baseProfile.policyRules;
222 accessRules = baseProfile.accessRules;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800223 }
224
225 /** Builds the profile instance. */
226 public EuiccProfileInfo build() {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000227 if (iccid == null) {
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800228 throw new IllegalStateException("ICCID must be set for a profile.");
229 }
230 return new EuiccProfileInfo(
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000231 iccid,
232 nickname,
233 serviceProviderName,
234 profileName,
235 profileClass,
236 state,
237 carrierIdentifier,
238 policyRules,
239 accessRules);
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800240 }
241
242 /** Sets the iccId of the subscription. */
243 public Builder setIccid(String value) {
244 if (!TextUtils.isDigitsOnly(value)) {
245 throw new IllegalArgumentException("iccid contains invalid characters: " + value);
246 }
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000247 iccid = value;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800248 return this;
249 }
250
251 /** Sets the nickname of the subscription. */
252 public Builder setNickname(String value) {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000253 nickname = value;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800254 return this;
255 }
256
257 /** Sets the service provider name of the subscription. */
258 public Builder setServiceProviderName(String value) {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000259 serviceProviderName = value;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800260 return this;
261 }
262
263 /** Sets the profile name of the subscription. */
264 public Builder setProfileName(String value) {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000265 profileName = value;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800266 return this;
267 }
268
269 /** Sets the profile class of the subscription. */
270 public Builder setProfileClass(@ProfileClass int value) {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000271 profileClass = value;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800272 return this;
273 }
274
275 /** Sets the state of the subscription. */
276 public Builder setState(@ProfileState int value) {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000277 state = value;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800278 return this;
279 }
280
281 /** Sets the carrier identifier of the subscription. */
282 public Builder setCarrierIdentifier(CarrierIdentifier value) {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000283 carrierIdentifier = value;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800284 return this;
285 }
286
287 /** Sets the policy rules of the subscription. */
288 public Builder setPolicyRules(@PolicyRule int value) {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000289 policyRules = value;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800290 return this;
291 }
292
293 /** Sets the access rules of the subscription. */
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000294 public Builder setUiccAccessRule(@Nullable UiccAccessRule[] value) {
295 accessRules = value;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800296 return this;
297 }
298 }
299
300 private EuiccProfileInfo(
301 String iccid,
302 @Nullable String nickname,
303 String serviceProviderName,
304 String profileName,
305 @ProfileClass int profileClass,
306 @ProfileState int state,
307 CarrierIdentifier carrierIdentifier,
308 @PolicyRule int policyRules,
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000309 @Nullable UiccAccessRule[] accessRules) {
310 this.iccid = iccid;
311 this.nickname = nickname;
312 this.serviceProviderName = serviceProviderName;
313 this.profileName = profileName;
314 this.profileClass = profileClass;
315 this.state = state;
316 this.carrierIdentifier = carrierIdentifier;
317 this.policyRules = policyRules;
318 this.accessRules = accessRules;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800319 }
320
321 /** Gets the ICCID string. */
322 public String getIccid() {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000323 return iccid;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800324 }
325
326 /** Gets the access rules. */
327 @Nullable
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000328 public UiccAccessRule[] getUiccAccessRules() {
329 return accessRules;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800330 }
331
332 /** Gets the nickname. */
333 public String getNickname() {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000334 return nickname;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800335 }
336
337 /** Gets the service provider name. */
338 public String getServiceProviderName() {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000339 return serviceProviderName;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800340 }
341
342 /** Gets the profile name. */
343 public String getProfileName() {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000344 return profileName;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800345 }
346
347 /** Gets the profile class. */
348 @ProfileClass
349 public int getProfileClass() {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000350 return profileClass;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800351 }
352
353 /** Gets the state of the subscription. */
354 @ProfileState
355 public int getState() {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000356 return state;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800357 }
358
359 /** Gets the carrier identifier. */
360 public CarrierIdentifier getCarrierIdentifier() {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000361 return carrierIdentifier;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800362 }
363
364 /** Gets the policy rules. */
365 @PolicyRule
366 public int getPolicyRules() {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000367 return policyRules;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800368 }
369
370 /** Returns whether any policy rule exists. */
371 public boolean hasPolicyRules() {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000372 return policyRules != 0;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800373 }
374
375 /** Checks whether a certain policy rule exists. */
376 public boolean hasPolicyRule(@PolicyRule int policy) {
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000377 return (policyRules & policy) != 0;
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800378 }
379
380 @Override
381 public boolean equals(Object obj) {
382 if (this == obj) {
383 return true;
384 }
385 if (obj == null || getClass() != obj.getClass()) {
386 return false;
387 }
388
389 EuiccProfileInfo that = (EuiccProfileInfo) obj;
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000390 return Objects.equals(iccid, that.iccid)
391 && Objects.equals(nickname, that.nickname)
392 && Objects.equals(serviceProviderName, that.serviceProviderName)
393 && Objects.equals(profileName, that.profileName)
394 && profileClass == that.profileClass
395 && state == that.state
396 && Objects.equals(carrierIdentifier, that.carrierIdentifier)
397 && policyRules == that.policyRules
398 && Arrays.equals(accessRules, that.accessRules);
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800399 }
400
401 @Override
402 public int hashCode() {
403 int result = 1;
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000404 result = 31 * result + Objects.hashCode(iccid);
405 result = 31 * result + Objects.hashCode(nickname);
406 result = 31 * result + Objects.hashCode(serviceProviderName);
407 result = 31 * result + Objects.hashCode(profileName);
408 result = 31 * result + profileClass;
409 result = 31 * result + state;
410 result = 31 * result + Objects.hashCode(carrierIdentifier);
411 result = 31 * result + policyRules;
412 result = 31 * result + Arrays.hashCode(accessRules);
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800413 return result;
414 }
415
416 @Override
417 public String toString() {
418 return "EuiccProfileInfo (nickname="
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000419 + nickname
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800420 + ", serviceProviderName="
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000421 + serviceProviderName
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800422 + ", profileName="
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000423 + profileName
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800424 + ", profileClass="
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000425 + profileClass
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800426 + ", state="
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000427 + state
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800428 + ", CarrierIdentifier="
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000429 + carrierIdentifier.toString()
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800430 + ", policyRules="
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000431 + policyRules
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800432 + ", accessRules="
Jiuyu Sund3bb4ae2018-02-08 16:38:26 +0000433 + Arrays.toString(accessRules)
Holly Jiuyu Sune6153b92017-12-07 15:35:49 -0800434 + ")";
435 }
Jeff Davidsond02731f2017-04-09 14:31:09 -0700436}