GetEuiccProfileInfoListResult.java revision d02731ffff9b8eb9b604377f50b2c43a9c753c2e
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 */
16package android.service.euicc;
17
18import android.annotation.IntDef;
19import android.annotation.Nullable;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23import java.lang.annotation.Retention;
24import java.lang.annotation.RetentionPolicy;
25
26/**
27 * Result of a {@link EuiccService#onGetEuiccProfileInfoList} operation.
28 * @hide
29 *
30 * TODO(b/35851809): Make this a SystemApi.
31 */
32public final class GetEuiccProfileInfoListResult implements Parcelable {
33
34    public static final Creator<GetEuiccProfileInfoListResult> CREATOR =
35            new Creator<GetEuiccProfileInfoListResult>() {
36        @Override
37        public GetEuiccProfileInfoListResult createFromParcel(Parcel in) {
38            return new GetEuiccProfileInfoListResult(in);
39        }
40
41        @Override
42        public GetEuiccProfileInfoListResult[] newArray(int size) {
43            return new GetEuiccProfileInfoListResult[size];
44        }
45    };
46
47    /** @hide */
48    @IntDef({
49            RESULT_OK,
50            RESULT_GENERIC_ERROR,
51    })
52    @Retention(RetentionPolicy.SOURCE)
53    public @interface ResultCode {}
54
55    public static final int RESULT_OK = 0;
56    public static final int RESULT_GENERIC_ERROR = 1;
57
58    /** Result of the operation - one of the RESULT_* constants. */
59    public final @ResultCode int result;
60
61    /** Implementation-defined detailed error code in case of a failure not covered here. */
62    public final int detailedCode;
63
64    /** The profile list (only upon success). */
65    @Nullable
66    public final EuiccProfileInfo[] profiles;
67
68    /** Whether the eUICC is removable. */
69    public final boolean isRemovable;
70
71    private GetEuiccProfileInfoListResult(int result, int detailedCode, EuiccProfileInfo[] profiles,
72            boolean isRemovable) {
73        this.result = result;
74        this.detailedCode = detailedCode;
75        this.profiles = profiles;
76        this.isRemovable = isRemovable;
77    }
78
79    private GetEuiccProfileInfoListResult(Parcel in) {
80        this.result = in.readInt();
81        this.detailedCode = in.readInt();
82        this.profiles = in.createTypedArray(EuiccProfileInfo.CREATOR);
83        this.isRemovable = in.readBoolean();
84    }
85
86    @Override
87    public void writeToParcel(Parcel dest, int flags) {
88        dest.writeInt(result);
89        dest.writeInt(detailedCode);
90        dest.writeTypedArray(profiles, flags);
91        dest.writeBoolean(isRemovable);
92    }
93
94    /**
95     * Return a result indicating that the listing was successful.
96     *
97     * @param profiles the list of profiles
98     * @param isRemovable whether the eUICC in this slot is removable. If true, the profiles
99     *     returned here will only be considered accessible as long as this eUICC is present.
100     *     Otherwise, they will remain accessible until the next time a response with isRemovable
101     *     set to false is returned.
102     */
103    public static GetEuiccProfileInfoListResult success(
104            EuiccProfileInfo[] profiles, boolean isRemovable) {
105        return new GetEuiccProfileInfoListResult(
106                RESULT_OK, 0 /* detailedCode */, profiles, isRemovable);
107    }
108
109    /**
110     * Return a result indicating that an error occurred for which no other more specific error
111     * code has been defined.
112     *
113     * @param detailedCode an implementation-defined detailed error code for debugging purposes.
114     * @param isRemovable whether the eUICC in this slot is removable. If true, only removable
115     *     profiles will be made inaccessible. Otherwise, all embedded profiles will be
116     *     considered inaccessible.
117     */
118    public static GetEuiccProfileInfoListResult genericError(
119            int detailedCode, boolean isRemovable) {
120        return new GetEuiccProfileInfoListResult(
121                RESULT_GENERIC_ERROR, detailedCode, null /* profiles */, isRemovable);
122    }
123
124    @Override
125    public int describeContents() {
126        return 0;
127    }
128}
129