blob: 1edb5398add4c5c6aaaaf5f466b4f1cdaa19b6a6 [file] [log] [blame]
Jeff Davidson35cda392017-02-27 09:46:00 -08001/*
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 Davidson35cda392017-02-27 09:46:00 -080018import android.annotation.Nullable;
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080019import android.annotation.SystemApi;
Jeff Davidson35cda392017-02-27 09:46:00 -080020import android.os.Parcel;
21import android.os.Parcelable;
22import android.telephony.euicc.DownloadableSubscription;
23
Jeff Davidson35cda392017-02-27 09:46:00 -080024/**
Jeff Davidson91c3d072017-04-12 12:17:11 -070025 * Result of a {@link EuiccService#onGetDownloadableSubscriptionMetadata} operation.
Jeff Davidson35cda392017-02-27 09:46:00 -080026 * @hide
Jeff Davidson35cda392017-02-27 09:46:00 -080027 */
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080028@SystemApi
Jeff Davidson35cda392017-02-27 09:46:00 -080029public final class GetDownloadableSubscriptionMetadataResult implements Parcelable {
30
31 public static final Creator<GetDownloadableSubscriptionMetadataResult> CREATOR =
32 new Creator<GetDownloadableSubscriptionMetadataResult>() {
33 @Override
34 public GetDownloadableSubscriptionMetadataResult createFromParcel(Parcel in) {
35 return new GetDownloadableSubscriptionMetadataResult(in);
36 }
37
38 @Override
39 public GetDownloadableSubscriptionMetadataResult[] newArray(int size) {
40 return new GetDownloadableSubscriptionMetadataResult[size];
41 }
42 };
43
Jeff Davidson83f8bc82017-05-15 10:22:20 -070044 /**
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080045 * @hide
46 * @deprecated - Do no use. Use getResult() instead.
47 */
48 @Deprecated
49 public final int result;
50
51 @Nullable
52 private final DownloadableSubscription mSubscription;
53
54 /**
55 * Gets the result of the operation.
Jeff Davidson83f8bc82017-05-15 10:22:20 -070056 *
57 * <p>May be one of the predefined {@code RESULT_} constants in EuiccService or any
58 * implementation-specific code starting with {@link EuiccService#RESULT_FIRST_USER}.
59 */
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080060 public int getResult() {
61 return result;
62 }
Jeff Davidson35cda392017-02-27 09:46:00 -080063
64 /**
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080065 * Gets the {@link DownloadableSubscription} with filled-in metadata.
Jeff Davidson35cda392017-02-27 09:46:00 -080066 *
Jeff Davidson83f8bc82017-05-15 10:22:20 -070067 * <p>Only non-null if {@link #result} is {@link EuiccService#RESULT_OK}.
Jeff Davidson35cda392017-02-27 09:46:00 -080068 */
69 @Nullable
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080070 public DownloadableSubscription getDownloadableSubscription() {
71 return mSubscription;
72 }
Jeff Davidson35cda392017-02-27 09:46:00 -080073
Jeff Davidson83f8bc82017-05-15 10:22:20 -070074 /**
75 * Construct a new {@link GetDownloadableSubscriptionMetadataResult}.
76 *
77 * @param result Result of the operation. May be one of the predefined {@code RESULT_} constants
78 * in EuiccService or any implementation-specific code starting with
79 * {@link EuiccService#RESULT_FIRST_USER}.
80 * @param subscription The subscription with filled-in metadata. Should only be provided if the
81 * result is {@link EuiccService#RESULT_OK}.
82 */
83 public GetDownloadableSubscriptionMetadataResult(int result,
84 @Nullable DownloadableSubscription subscription) {
Jeff Davidson35cda392017-02-27 09:46:00 -080085 this.result = result;
Jeff Davidson83f8bc82017-05-15 10:22:20 -070086 if (this.result == EuiccService.RESULT_OK) {
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080087 this.mSubscription = subscription;
Jeff Davidson83f8bc82017-05-15 10:22:20 -070088 } else {
89 if (subscription != null) {
90 throw new IllegalArgumentException(
91 "Error result with non-null subscription: " + result);
92 }
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080093 this.mSubscription = null;
Jeff Davidson83f8bc82017-05-15 10:22:20 -070094 }
Jeff Davidson35cda392017-02-27 09:46:00 -080095 }
96
97 private GetDownloadableSubscriptionMetadataResult(Parcel in) {
98 this.result = in.readInt();
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -080099 this.mSubscription = in.readTypedObject(DownloadableSubscription.CREATOR);
Jeff Davidson35cda392017-02-27 09:46:00 -0800100 }
101
102 @Override
103 public void writeToParcel(Parcel dest, int flags) {
104 dest.writeInt(result);
Holly Jiuyu Sunaf6a5ff2017-12-12 20:17:09 -0800105 dest.writeTypedObject(this.mSubscription, flags);
Jeff Davidson35cda392017-02-27 09:46:00 -0800106 }
107
108 @Override
109 public int describeContents() {
110 return 0;
111 }
112}