blob: e2171ae6bc7669abe01a2cc80cdedd3613ccf49c [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 Sunaf6a5ff2017-12-12 20:17:09 -080019import android.annotation.SystemApi;
Jeff Davidson91c3d072017-04-12 12:17:11 -070020import android.os.Parcel;
21import android.os.Parcelable;
22import android.telephony.euicc.DownloadableSubscription;
23
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080024import java.util.Arrays;
25import java.util.List;
26
Jeff Davidson91c3d072017-04-12 12:17:11 -070027/**
28 * Result of a {@link EuiccService#onGetDefaultDownloadableSubscriptionList} operation.
29 * @hide
Jeff Davidson91c3d072017-04-12 12:17:11 -070030 */
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080031@SystemApi
Jeff Davidson91c3d072017-04-12 12:17:11 -070032public final class GetDefaultDownloadableSubscriptionListResult implements Parcelable {
33
34 public static final Creator<GetDefaultDownloadableSubscriptionListResult> CREATOR =
35 new Creator<GetDefaultDownloadableSubscriptionListResult>() {
36 @Override
37 public GetDefaultDownloadableSubscriptionListResult createFromParcel(Parcel in) {
38 return new GetDefaultDownloadableSubscriptionListResult(in);
39 }
40
41 @Override
42 public GetDefaultDownloadableSubscriptionListResult[] newArray(int size) {
43 return new GetDefaultDownloadableSubscriptionListResult[size];
44 }
45 };
46
Jeff Davidson83f8bc82017-05-15 10:22:20 -070047 /**
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080048 * @hide
49 * @deprecated - Do no use. Use getResult() instead.
50 */
51 @Deprecated
52 public final int result;
53
54 @Nullable
55 private final DownloadableSubscription[] mSubscriptions;
56
57 /**
58 * Gets the result of the operation.
Jeff Davidson83f8bc82017-05-15 10:22:20 -070059 *
60 * <p>May be one of the predefined {@code RESULT_} constants in EuiccService or any
61 * implementation-specific code starting with {@link EuiccService#RESULT_FIRST_USER}.
62 */
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080063 public int getResult() {
64 return result;
65 }
Jeff Davidson91c3d072017-04-12 12:17:11 -070066
67 /**
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080068 * Gets the available {@link DownloadableSubscription}s (with filled-in metadata).
Jeff Davidson91c3d072017-04-12 12:17:11 -070069 *
Jeff Davidson83f8bc82017-05-15 10:22:20 -070070 * <p>Only non-null if {@link #result} is {@link EuiccService#RESULT_OK}.
Jeff Davidson91c3d072017-04-12 12:17:11 -070071 */
72 @Nullable
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080073 public List<DownloadableSubscription> getDownloadableSubscriptions() {
74 if (mSubscriptions == null) return null;
75 return Arrays.asList(mSubscriptions);
76 }
Jeff Davidson91c3d072017-04-12 12:17:11 -070077
Jeff Davidson83f8bc82017-05-15 10:22:20 -070078 /**
79 * Construct a new {@link GetDefaultDownloadableSubscriptionListResult}.
80 *
81 * @param result Result of the operation. May be one of the predefined {@code RESULT_} constants
82 * in EuiccService or any implementation-specific code starting with
83 * {@link EuiccService#RESULT_FIRST_USER}.
84 * @param subscriptions The available subscriptions. Should only be provided if the result is
85 * {@link EuiccService#RESULT_OK}.
86 */
87 public GetDefaultDownloadableSubscriptionListResult(int result,
88 @Nullable DownloadableSubscription[] subscriptions) {
Jeff Davidson91c3d072017-04-12 12:17:11 -070089 this.result = result;
Jeff Davidson83f8bc82017-05-15 10:22:20 -070090 if (this.result == EuiccService.RESULT_OK) {
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080091 this.mSubscriptions = subscriptions;
Jeff Davidson83f8bc82017-05-15 10:22:20 -070092 } else {
93 if (subscriptions != null) {
94 throw new IllegalArgumentException(
95 "Error result with non-null subscriptions: " + result);
96 }
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080097 this.mSubscriptions = null;
Jeff Davidson83f8bc82017-05-15 10:22:20 -070098 }
Jeff Davidson91c3d072017-04-12 12:17:11 -070099 }
100
101 private GetDefaultDownloadableSubscriptionListResult(Parcel in) {
102 this.result = in.readInt();
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -0800103 this.mSubscriptions = in.createTypedArray(DownloadableSubscription.CREATOR);
Jeff Davidson91c3d072017-04-12 12:17:11 -0700104 }
105
106 @Override
107 public void writeToParcel(Parcel dest, int flags) {
108 dest.writeInt(result);
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -0800109 dest.writeTypedArray(mSubscriptions, flags);
Jeff Davidson91c3d072017-04-12 12:17:11 -0700110 }
111
112 @Override
113 public int describeContents() {
114 return 0;
115 }
116}