blob: 7a9d8a05ab4715a566128c11f171a97b3f52d88b [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
Jeff Davidsond02731f2017-04-09 14:31:09 -070018import android.annotation.Nullable;
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080019import android.annotation.SystemApi;
Jeff Davidsond02731f2017-04-09 14:31:09 -070020import android.os.Parcel;
21import android.os.Parcelable;
22
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080023import java.util.Arrays;
24import java.util.List;
25
Jeff Davidsond02731f2017-04-09 14:31:09 -070026/**
27 * Result of a {@link EuiccService#onGetEuiccProfileInfoList} operation.
28 * @hide
Jeff Davidsond02731f2017-04-09 14:31:09 -070029 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080030@SystemApi
Jeff Davidsond02731f2017-04-09 14:31:09 -070031public final class GetEuiccProfileInfoListResult implements Parcelable {
32
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070033 public static final @android.annotation.NonNull Creator<GetEuiccProfileInfoListResult> CREATOR =
Jeff Davidsond02731f2017-04-09 14:31:09 -070034 new Creator<GetEuiccProfileInfoListResult>() {
Jeff Davidson83f8bc82017-05-15 10:22:20 -070035 @Override
36 public GetEuiccProfileInfoListResult createFromParcel(Parcel in) {
37 return new GetEuiccProfileInfoListResult(in);
38 }
Jeff Davidsond02731f2017-04-09 14:31:09 -070039
Jeff Davidson83f8bc82017-05-15 10:22:20 -070040 @Override
41 public GetEuiccProfileInfoListResult[] newArray(int size) {
42 return new GetEuiccProfileInfoListResult[size];
43 }
44 };
Jeff Davidsond02731f2017-04-09 14:31:09 -070045
Jeff Davidson83f8bc82017-05-15 10:22:20 -070046 /**
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080047 * @hide
48 * @deprecated - Do no use. Use getResult() instead.
49 */
50 @Deprecated
51 public final int result;
52
53 @Nullable
54 private final EuiccProfileInfo[] mProfiles;
55
56 private final boolean mIsRemovable;
57
58 /**
59 * Gets the result of the operation.
Jeff Davidson83f8bc82017-05-15 10:22:20 -070060 *
61 * <p>May be one of the predefined {@code RESULT_} constants in EuiccService or any
62 * implementation-specific code starting with {@link EuiccService#RESULT_FIRST_USER}.
63 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080064 public int getResult() {
65 return result;
66 }
Jeff Davidsond02731f2017-04-09 14:31:09 -070067
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080068 /** Gets the profile list (only upon success). */
Jeff Davidsond02731f2017-04-09 14:31:09 -070069 @Nullable
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080070 public List<EuiccProfileInfo> getProfiles() {
71 if (mProfiles == null) return null;
72 return Arrays.asList(mProfiles);
73 }
Jeff Davidsond02731f2017-04-09 14:31:09 -070074
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080075 /** Gets whether the eUICC is removable. */
76 public boolean getIsRemovable() {
77 return mIsRemovable;
78 }
Jeff Davidsond02731f2017-04-09 14:31:09 -070079
Jeff Davidson83f8bc82017-05-15 10:22:20 -070080 /**
81 * Construct a new {@link GetEuiccProfileInfoListResult}.
82 *
83 * @param result Result of the operation. May be one of the predefined {@code RESULT_} constants
84 * in EuiccService or any implementation-specific code starting with
85 * {@link EuiccService#RESULT_FIRST_USER}.
86 * @param profiles the list of profiles. Should only be provided if the result is
87 * {@link EuiccService#RESULT_OK}.
88 * @param isRemovable whether the eUICC in this slot is removable. If true, the profiles
89 * returned here will only be considered accessible as long as this eUICC is present.
90 * Otherwise, they will remain accessible until the next time a response with isRemovable
91 * set to false is returned.
92 */
93 public GetEuiccProfileInfoListResult(
94 int result, @Nullable EuiccProfileInfo[] profiles, boolean isRemovable) {
Jeff Davidsond02731f2017-04-09 14:31:09 -070095 this.result = result;
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080096 this.mIsRemovable = isRemovable;
Jeff Davidson83f8bc82017-05-15 10:22:20 -070097 if (this.result == EuiccService.RESULT_OK) {
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080098 this.mProfiles = profiles;
Jeff Davidson83f8bc82017-05-15 10:22:20 -070099 } else {
100 if (profiles != null) {
101 throw new IllegalArgumentException(
102 "Error result with non-null profiles: " + result);
103 }
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -0800104 this.mProfiles = null;
Jeff Davidson83f8bc82017-05-15 10:22:20 -0700105 }
Jeff Davidsond02731f2017-04-09 14:31:09 -0700106 }
107
108 private GetEuiccProfileInfoListResult(Parcel in) {
109 this.result = in.readInt();
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -0800110 this.mProfiles = in.createTypedArray(EuiccProfileInfo.CREATOR);
111 this.mIsRemovable = in.readBoolean();
Jeff Davidsond02731f2017-04-09 14:31:09 -0700112 }
113
114 @Override
115 public void writeToParcel(Parcel dest, int flags) {
116 dest.writeInt(result);
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -0800117 dest.writeTypedArray(mProfiles, flags);
118 dest.writeBoolean(mIsRemovable);
Jeff Davidsond02731f2017-04-09 14:31:09 -0700119 }
120
Jeff Davidsond02731f2017-04-09 14:31:09 -0700121 @Override
122 public int describeContents() {
123 return 0;
124 }
125}