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.Nullable;
19import android.os.Parcel;
20import android.os.Parcelable;
21
22/**
23 * Result of a {@link EuiccService#onGetEuiccProfileInfoList} operation.
24 * @hide
25 *
26 * TODO(b/35851809): Make this a SystemApi.
27 */
28public final class GetEuiccProfileInfoListResult implements Parcelable {
29
30    public static final Creator<GetEuiccProfileInfoListResult> CREATOR =
31            new Creator<GetEuiccProfileInfoListResult>() {
32                @Override
33                public GetEuiccProfileInfoListResult createFromParcel(Parcel in) {
34                    return new GetEuiccProfileInfoListResult(in);
35                }
36
37                @Override
38                public GetEuiccProfileInfoListResult[] newArray(int size) {
39                    return new GetEuiccProfileInfoListResult[size];
40                }
41            };
42
43    /**
44     * Result of the operation.
45     *
46     * <p>May be one of the predefined {@code RESULT_} constants in EuiccService or any
47     * implementation-specific code starting with {@link EuiccService#RESULT_FIRST_USER}.
48     */
49    public final int result;
50
51    /** The profile list (only upon success). */
52    @Nullable
53    public final EuiccProfileInfo[] profiles;
54
55    /** Whether the eUICC is removable. */
56    public final boolean isRemovable;
57
58    /**
59     * Construct a new {@link GetEuiccProfileInfoListResult}.
60     *
61     * @param result Result of the operation. May be one of the predefined {@code RESULT_} constants
62     *     in EuiccService or any implementation-specific code starting with
63     *     {@link EuiccService#RESULT_FIRST_USER}.
64     * @param profiles the list of profiles. Should only be provided if the result is
65     *     {@link EuiccService#RESULT_OK}.
66     * @param isRemovable whether the eUICC in this slot is removable. If true, the profiles
67     *     returned here will only be considered accessible as long as this eUICC is present.
68     *     Otherwise, they will remain accessible until the next time a response with isRemovable
69     *     set to false is returned.
70     */
71    public GetEuiccProfileInfoListResult(
72            int result, @Nullable EuiccProfileInfo[] profiles, boolean isRemovable) {
73        this.result = result;
74        this.isRemovable = isRemovable;
75        if (this.result == EuiccService.RESULT_OK) {
76            this.profiles = profiles;
77        } else {
78            if (profiles != null) {
79                throw new IllegalArgumentException(
80                        "Error result with non-null profiles: " + result);
81            }
82            this.profiles = null;
83        }
84
85    }
86
87    private GetEuiccProfileInfoListResult(Parcel in) {
88        this.result = in.readInt();
89        this.profiles = in.createTypedArray(EuiccProfileInfo.CREATOR);
90        this.isRemovable = in.readBoolean();
91    }
92
93    @Override
94    public void writeToParcel(Parcel dest, int flags) {
95        dest.writeInt(result);
96        dest.writeTypedArray(profiles, flags);
97        dest.writeBoolean(isRemovable);
98    }
99
100    @Override
101    public int describeContents() {
102        return 0;
103    }
104}
105