blob: bd91ca00145d31042746c289189d4c330787639b [file] [log] [blame]
Jeff Davidson91c3d072017-04-12 12:17:11 -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 Davidson91c3d072017-04-12 12:17:11 -070018import android.annotation.Nullable;
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080019import android.annotation.SystemApi;
Mathew Inwoode3807372018-08-10 09:51:03 +010020import android.annotation.UnsupportedAppUsage;
Jeff Davidson91c3d072017-04-12 12:17:11 -070021import android.os.Parcel;
22import android.os.Parcelable;
23import android.telephony.euicc.DownloadableSubscription;
24
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080025import java.util.Arrays;
26import java.util.List;
27
Jeff Davidson91c3d072017-04-12 12:17:11 -070028/**
29 * Result of a {@link EuiccService#onGetDefaultDownloadableSubscriptionList} operation.
30 * @hide
Jeff Davidson91c3d072017-04-12 12:17:11 -070031 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080032@SystemApi
Jeff Davidson91c3d072017-04-12 12:17:11 -070033public final class GetDefaultDownloadableSubscriptionListResult implements Parcelable {
34
35 public static final Creator<GetDefaultDownloadableSubscriptionListResult> CREATOR =
36 new Creator<GetDefaultDownloadableSubscriptionListResult>() {
37 @Override
38 public GetDefaultDownloadableSubscriptionListResult createFromParcel(Parcel in) {
39 return new GetDefaultDownloadableSubscriptionListResult(in);
40 }
41
42 @Override
43 public GetDefaultDownloadableSubscriptionListResult[] newArray(int size) {
44 return new GetDefaultDownloadableSubscriptionListResult[size];
45 }
46 };
47
Jeff Davidson83f8bc82017-05-15 10:22:20 -070048 /**
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080049 * @hide
50 * @deprecated - Do no use. Use getResult() instead.
51 */
52 @Deprecated
Mathew Inwoode3807372018-08-10 09:51:03 +010053 @UnsupportedAppUsage
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080054 public final int result;
55
56 @Nullable
57 private final DownloadableSubscription[] mSubscriptions;
58
59 /**
60 * Gets the result of the operation.
Jeff Davidson83f8bc82017-05-15 10:22:20 -070061 *
62 * <p>May be one of the predefined {@code RESULT_} constants in EuiccService or any
63 * implementation-specific code starting with {@link EuiccService#RESULT_FIRST_USER}.
64 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080065 public int getResult() {
66 return result;
67 }
Jeff Davidson91c3d072017-04-12 12:17:11 -070068
69 /**
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080070 * Gets the available {@link DownloadableSubscription}s (with filled-in metadata).
Jeff Davidson91c3d072017-04-12 12:17:11 -070071 *
Jeff Davidson83f8bc82017-05-15 10:22:20 -070072 * <p>Only non-null if {@link #result} is {@link EuiccService#RESULT_OK}.
Jeff Davidson91c3d072017-04-12 12:17:11 -070073 */
74 @Nullable
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080075 public List<DownloadableSubscription> getDownloadableSubscriptions() {
76 if (mSubscriptions == null) return null;
77 return Arrays.asList(mSubscriptions);
78 }
Jeff Davidson91c3d072017-04-12 12:17:11 -070079
Jeff Davidson83f8bc82017-05-15 10:22:20 -070080 /**
81 * Construct a new {@link GetDefaultDownloadableSubscriptionListResult}.
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 subscriptions The available subscriptions. Should only be provided if the result is
87 * {@link EuiccService#RESULT_OK}.
88 */
89 public GetDefaultDownloadableSubscriptionListResult(int result,
90 @Nullable DownloadableSubscription[] subscriptions) {
Jeff Davidson91c3d072017-04-12 12:17:11 -070091 this.result = result;
Jeff Davidson83f8bc82017-05-15 10:22:20 -070092 if (this.result == EuiccService.RESULT_OK) {
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080093 this.mSubscriptions = subscriptions;
Jeff Davidson83f8bc82017-05-15 10:22:20 -070094 } else {
95 if (subscriptions != null) {
96 throw new IllegalArgumentException(
97 "Error result with non-null subscriptions: " + result);
98 }
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -080099 this.mSubscriptions = null;
Jeff Davidson83f8bc82017-05-15 10:22:20 -0700100 }
Jeff Davidson91c3d072017-04-12 12:17:11 -0700101 }
102
103 private GetDefaultDownloadableSubscriptionListResult(Parcel in) {
104 this.result = in.readInt();
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -0800105 this.mSubscriptions = in.createTypedArray(DownloadableSubscription.CREATOR);
Jeff Davidson91c3d072017-04-12 12:17:11 -0700106 }
107
108 @Override
109 public void writeToParcel(Parcel dest, int flags) {
110 dest.writeInt(result);
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -0800111 dest.writeTypedArray(mSubscriptions, flags);
Jeff Davidson91c3d072017-04-12 12:17:11 -0700112 }
113
114 @Override
115 public int describeContents() {
116 return 0;
117 }
118}