blob: b7f46fac2461003f6fd3cf886386effc613595ef [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
18import android.annotation.IntDef;
19import android.annotation.Nullable;
20import android.os.Parcel;
21import android.os.Parcelable;
22import android.telephony.euicc.DownloadableSubscription;
23
24import java.lang.annotation.Retention;
25import java.lang.annotation.RetentionPolicy;
26
27/**
28 * Result of a {@link EuiccService#getDownloadableSubscriptionMetadata} operation.
29 * @hide
30 *
31 * TODO(b/35851809): Make this a SystemApi.
32 */
33public final class GetDownloadableSubscriptionMetadataResult implements Parcelable {
34
35 public static final Creator<GetDownloadableSubscriptionMetadataResult> CREATOR =
36 new Creator<GetDownloadableSubscriptionMetadataResult>() {
37 @Override
38 public GetDownloadableSubscriptionMetadataResult createFromParcel(Parcel in) {
39 return new GetDownloadableSubscriptionMetadataResult(in);
40 }
41
42 @Override
43 public GetDownloadableSubscriptionMetadataResult[] newArray(int size) {
44 return new GetDownloadableSubscriptionMetadataResult[size];
45 }
46 };
47
48 /** @hide */
49 @IntDef({
50 RESULT_OK,
51 RESULT_GENERIC_ERROR,
52 RESULT_MUST_DEACTIVATE_REMOVABLE_SIM,
53 })
54 @Retention(RetentionPolicy.SOURCE)
55 public @interface ResultCode {}
56
57 public static final int RESULT_OK = 0;
58 public static final int RESULT_MUST_DEACTIVATE_REMOVABLE_SIM = 1;
59 public static final int RESULT_GENERIC_ERROR = 2;
60
61 /** Result of the operation - one of the RESULT_* constants. */
62 public final @ResultCode int result;
63
64 /**
65 * The {@link DownloadableSubscription} with filled-in metadata.
66 *
67 * <p>Only non-null if {@link #result} is {@link #RESULT_OK}.
68 */
69 @Nullable
70 public final DownloadableSubscription subscription;
71
72 /** Implementation-defined detailed error code in case of a failure not covered here. */
73 public final int detailedCode;
74
75 private GetDownloadableSubscriptionMetadataResult(int result,
76 @Nullable DownloadableSubscription subscription, int detailedCode) {
77 this.result = result;
78 this.subscription = subscription;
79 this.detailedCode = detailedCode;
80 }
81
82 private GetDownloadableSubscriptionMetadataResult(Parcel in) {
83 this.result = in.readInt();
84 this.subscription = DownloadableSubscription.CREATOR.createFromParcel(in);
85 this.detailedCode = in.readInt();
86 }
87
88 @Override
89 public void writeToParcel(Parcel dest, int flags) {
90 dest.writeInt(result);
91 this.subscription.writeToParcel(dest, 0);
92 dest.writeInt(detailedCode);
93 }
94
95 /** Return a result indicating that the download was successful. */
96 public static GetDownloadableSubscriptionMetadataResult success(
97 DownloadableSubscription subscription) {
98 return new GetDownloadableSubscriptionMetadataResult(RESULT_OK, subscription,
99 0 /* detailedCode */);
100 }
101
102 /**
103 * Return a result indicating that the removable SIM must be deactivated to perform the
104 * operation.
105 */
106 public static GetDownloadableSubscriptionMetadataResult mustDeactivateRemovableSim() {
107 return new GetDownloadableSubscriptionMetadataResult(RESULT_MUST_DEACTIVATE_REMOVABLE_SIM,
108 null /* subscription */, 0 /* detailedCode */);
109 }
110
111 /**
112 * Return a result indicating that an error occurred for which no other more specific error
113 * code has been defined.
114 *
115 * @param detailedCode an implementation-defined detailed error code for debugging purposes.
116 */
117 public static GetDownloadableSubscriptionMetadataResult genericError(int detailedCode) {
118 return new GetDownloadableSubscriptionMetadataResult(RESULT_GENERIC_ERROR,
119 null /* subscription */, detailedCode);
120 }
121
122 @Override
123 public int describeContents() {
124 return 0;
125 }
126}