Debian Codegraph @

telephony/java/android/service/euicc/EuiccProfileInfo.java

raw symbols SCIP
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.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.compat.annotation.UnsupportedAppUsage;
23 import android.os.Build;
24 import android.os.Parcel;
25 import android.os.Parcelable;
26 import android.service.carrier.CarrierIdentifier;
27 import android.telephony.UiccAccessRule;
28 import android.text.TextUtils;
29
30 import java.lang.annotation.Retention;
31 import java.lang.annotation.RetentionPolicy;
32 import java.util.Arrays;
33 import java.util.Collections;
34 import java.util.List;
35 import java.util.Objects;
36
37 /**
38 * Information about an embedded profile (subscription) on an eUICC.
39 *
40 * @hide
41 */
42 @SystemApi
43 public final class EuiccProfileInfo implements Parcelable {
44
45 /** Profile policy rules (bit mask) */
46 @Retention(RetentionPolicy.SOURCE)
47 @IntDef(flag = true, prefix = { "POLICY_RULE_" }, value = {
48 POLICY_RULE_DO_NOT_DISABLE,
49 POLICY_RULE_DO_NOT_DELETE,
50 POLICY_RULE_DELETE_AFTER_DISABLING
51 })
52 public @interface PolicyRule {}
53 /** Once this profile is enabled, it cannot be disabled. */
54 public static final int POLICY_RULE_DO_NOT_DISABLE = 1;
55 /** This profile cannot be deleted. */
56 public static final int POLICY_RULE_DO_NOT_DELETE = 1 << 1;
57 /** This profile should be deleted after being disabled. */
58 public static final int POLICY_RULE_DELETE_AFTER_DISABLING = 1 << 2;
59
60 /** Class of the profile */
61 @Retention(RetentionPolicy.SOURCE)
62 @IntDef(prefix = { "PROFILE_CLASS_" }, value = {
63 PROFILE_CLASS_TESTING,
64 PROFILE_CLASS_PROVISIONING,
65 PROFILE_CLASS_OPERATIONAL,
66 PROFILE_CLASS_UNSET
67 })
68 public @interface ProfileClass {}
69 /** Testing profiles */
70 public static final int PROFILE_CLASS_TESTING = 0;
71 /** Provisioning profiles which are pre-loaded on eUICC */
72 public static final int PROFILE_CLASS_PROVISIONING = 1;
73 /** Operational profiles which can be pre-loaded or downloaded */
74 public static final int PROFILE_CLASS_OPERATIONAL = 2;
75 /**
76 * Profile class not set.
77 * @hide
78 */
79 public static final int PROFILE_CLASS_UNSET = -1;
80
81 /** State of the profile */
82 @Retention(RetentionPolicy.SOURCE)
83 @IntDef(prefix = { "PROFILE_STATE_" }, value = {
84 PROFILE_STATE_DISABLED,
85 PROFILE_STATE_ENABLED,
86 PROFILE_STATE_UNSET
87 })
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(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
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
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
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
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
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
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 = baseProfile.mAccessRules == null
234 ? Collections.emptyList()
235 : Arrays.asList(baseProfile.mAccessRules);
236 }
237
238 /** Builds the profile instance. */
239 public EuiccProfileInfo build() {
240 if (mIccid == null) {
241 throw new IllegalStateException("ICCID must be set for a profile.");
242 }
243 return new EuiccProfileInfo(
244 mIccid,
245 mNickname,
246 mServiceProviderName,
247 mProfileName,
248 mProfileClass,
249 mState,
250 mCarrierIdentifier,
251 mPolicyRules,
252 mAccessRules);
253 }
254
255 /** Sets the iccId of the subscription. */
256 public Builder setIccid(String value) {
257 if (!TextUtils.isDigitsOnly(value)) {
258 throw new IllegalArgumentException("iccid contains invalid characters: " + value);
259 }
260 mIccid = value;
261 return this;
262 }
263
264 /** Sets the nickname of the subscription. */
265 public Builder setNickname(String value) {
266 mNickname = value;
267 return this;
268 }
269
270 /** Sets the service provider name of the subscription. */
271 public Builder setServiceProviderName(String value) {
272 mServiceProviderName = value;
273 return this;
274 }
275
276 /** Sets the profile name of the subscription. */
277 public Builder setProfileName(String value) {
278 mProfileName = value;
279 return this;
280 }
281
282 /** Sets the profile class of the subscription. */
283 public Builder setProfileClass(@ProfileClass int value) {
284 mProfileClass = value;
285 return this;
286 }
287
288 /** Sets the state of the subscription. */
289 public Builder setState(@ProfileState int value) {
290 mState = value;
291 return this;
292 }
293
294 /** Sets the carrier identifier of the subscription. */
295 public Builder setCarrierIdentifier(CarrierIdentifier value) {
296 mCarrierIdentifier = value;
297 return this;
298 }
299
300 /** Sets the policy rules of the subscription. */
301 public Builder setPolicyRules(@PolicyRule int value) {
302 mPolicyRules = value;
303 return this;
304 }
305
306 /** Sets the access rules of the subscription. */
307 public Builder setUiccAccessRule(@Nullable List<UiccAccessRule> value) {
308 mAccessRules = value;
309 return this;
310 }
311 }
312
313 private EuiccProfileInfo(
314 String iccid,
315 @Nullable String nickname,
316 String serviceProviderName,
317 String profileName,
318 @ProfileClass int profileClass,
319 @ProfileState int state,
320 CarrierIdentifier carrierIdentifier,
321 @PolicyRule int policyRules,
322 @Nullable List<UiccAccessRule> accessRules) {
323 this.mIccid = iccid;
324 this.mNickname = nickname;
325 this.mServiceProviderName = serviceProviderName;
326 this.mProfileName = profileName;
327 this.mProfileClass = profileClass;
328 this.mState = state;
329 this.mCarrierIdentifier = carrierIdentifier;
330 this.mPolicyRules = policyRules;
331 if (accessRules != null && accessRules.size() > 0) {
332 this.mAccessRules = accessRules.toArray(new UiccAccessRule[accessRules.size()]);
333 } else {
334 this.mAccessRules = null;
335 }
336 }
337
338 /** Gets the ICCID string. */
339 public String getIccid() {
340 return mIccid;
341 }
342
343 /** Gets the access rules. */
344 @Nullable
345 public List<UiccAccessRule> getUiccAccessRules() {
346 if (mAccessRules == null) return null;
347 return Arrays.asList(mAccessRules);
348 }
349
350 /** Gets the nickname. */
351 @Nullable
352 public String getNickname() {
353 return mNickname;
354 }
355
356 /** Gets the service provider name. */
357 public String getServiceProviderName() {
358 return mServiceProviderName;
359 }
360
361 /** Gets the profile name. */
362 public String getProfileName() {
363 return mProfileName;
364 }
365
366 /** Gets the profile class. */
367 @ProfileClass
368 public int getProfileClass() {
369 return mProfileClass;
370 }
371
372 /** Gets the state of the subscription. */
373 @ProfileState
374 public int getState() {
375 return mState;
376 }
377
378 /** Gets the carrier identifier. */
379 public CarrierIdentifier getCarrierIdentifier() {
380 return mCarrierIdentifier;
381 }
382
383 /** Gets the policy rules. */
384 @PolicyRule
385 public int getPolicyRules() {
386 return mPolicyRules;
387 }
388
389 /** Returns whether any policy rule exists. */
390 public boolean hasPolicyRules() {
391 return mPolicyRules != 0;
392 }
393
394 /** Checks whether a certain policy rule exists. */
395 public boolean hasPolicyRule(@PolicyRule int policy) {
396 return (mPolicyRules & policy) != 0;
397 }
398
399 @Override
400 public boolean equals(@Nullable Object obj) {
401 if (this == obj) {
402 return true;
403 }
404 if (obj == null || getClass() != obj.getClass()) {
405 return false;
406 }
407
408 EuiccProfileInfo that = (EuiccProfileInfo) obj;
409 return Objects.equals(mIccid, that.mIccid)
410 && Objects.equals(mNickname, that.mNickname)
411 && Objects.equals(mServiceProviderName, that.mServiceProviderName)
412 && Objects.equals(mProfileName, that.mProfileName)
413 && mProfileClass == that.mProfileClass
414 && mState == that.mState
415 && Objects.equals(mCarrierIdentifier, that.mCarrierIdentifier)
416 && mPolicyRules == that.mPolicyRules
417 && Arrays.equals(mAccessRules, that.mAccessRules);
418 }
419
420 @Override
421 public int hashCode() {
422 int result = 1;
423 result = 31 * result + Objects.hashCode(mIccid);
424 result = 31 * result + Objects.hashCode(mNickname);
425 result = 31 * result + Objects.hashCode(mServiceProviderName);
426 result = 31 * result + Objects.hashCode(mProfileName);
427 result = 31 * result + mProfileClass;
428 result = 31 * result + mState;
429 result = 31 * result + Objects.hashCode(mCarrierIdentifier);
430 result = 31 * result + mPolicyRules;
431 result = 31 * result + Arrays.hashCode(mAccessRules);
432 return result;
433 }
434
435 @NonNull
436 @Override
437 public String toString() {
438 return "EuiccProfileInfo (nickname="
439 + mNickname
440 + ", serviceProviderName="
441 + mServiceProviderName
442 + ", profileName="
443 + mProfileName
444 + ", profileClass="
445 + mProfileClass
446 + ", state="
447 + mState
448 + ", CarrierIdentifier="
449 + mCarrierIdentifier
450 + ", policyRules="
451 + mPolicyRules
452 + ", accessRules="
453 + Arrays.toString(mAccessRules)
454 + ")";
455 }
456 }