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  */
16 package android.service.euicc;
17 
18 import android.annotation.Nullable;
19 import android.annotation.SystemApi;
20 import android.compat.annotation.UnsupportedAppUsage;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import android.telephony.euicc.DownloadableSubscription;
24 
25 /**
26  * Result of a {@link EuiccService#onGetDownloadableSubscriptionMetadata} operation.
27  * @hide
28  */
29 @SystemApi
30 public final class GetDownloadableSubscriptionMetadataResult implements Parcelable {
31 
32     public static final @android.annotation.NonNull Creator<GetDownloadableSubscriptionMetadataResult> CREATOR =
33             new Creator<GetDownloadableSubscriptionMetadataResult>() {
34         @Override
35         public GetDownloadableSubscriptionMetadataResult createFromParcel(Parcel in) {
36             return new GetDownloadableSubscriptionMetadataResult(in);
37         }
38 
39         @Override
40         public GetDownloadableSubscriptionMetadataResult[] newArray(int size) {
41             return new GetDownloadableSubscriptionMetadataResult[size];
42         }
43     };
44 
45     /**
46      * @hide
47      * @deprecated - Do no use. Use getResult() instead.
48      */
49     @Deprecated
50     @UnsupportedAppUsage
51     public final int result;
52 
53     @Nullable
54     private final DownloadableSubscription mSubscription;
55 
56     /**
57      * Gets the result of the operation.
58      *
59      * <p>May be one of the predefined {@code RESULT_} constants in EuiccService or any
60      * implementation-specific code starting with {@link EuiccService#RESULT_FIRST_USER}.
61      */
getResult()62     public int getResult() {
63         return result;
64     }
65 
66     /**
67      * Gets the {@link DownloadableSubscription} with filled-in metadata.
68      *
69      * <p>Only non-null if {@link #result} is {@link EuiccService#RESULT_OK}.
70      */
71     @Nullable
getDownloadableSubscription()72     public DownloadableSubscription getDownloadableSubscription() {
73         return mSubscription;
74     }
75 
76     /**
77      * Construct a new {@link GetDownloadableSubscriptionMetadataResult}.
78      *
79      * @param result Result of the operation. May be one of the predefined {@code RESULT_} constants
80      *     in EuiccService or any implementation-specific code starting with
81      *     {@link EuiccService#RESULT_FIRST_USER}.
82      * @param subscription The subscription with filled-in metadata. Should only be provided if the
83      *     result is {@link EuiccService#RESULT_OK}.
84      */
GetDownloadableSubscriptionMetadataResult(int result, @Nullable DownloadableSubscription subscription)85     public GetDownloadableSubscriptionMetadataResult(int result,
86             @Nullable DownloadableSubscription subscription) {
87         this.result = result;
88         if (this.result == EuiccService.RESULT_OK) {
89             this.mSubscription = subscription;
90         } else {
91             if (subscription != null) {
92                 throw new IllegalArgumentException(
93                         "Error result with non-null subscription: " + result);
94             }
95             this.mSubscription = null;
96         }
97     }
98 
GetDownloadableSubscriptionMetadataResult(Parcel in)99     private GetDownloadableSubscriptionMetadataResult(Parcel in) {
100         this.result = in.readInt();
101         this.mSubscription = in.readTypedObject(DownloadableSubscription.CREATOR);
102     }
103 
104     @Override
writeToParcel(Parcel dest, int flags)105     public void writeToParcel(Parcel dest, int flags) {
106         dest.writeInt(result);
107         dest.writeTypedObject(this.mSubscription, flags);
108     }
109 
110     @Override
describeContents()111     public int describeContents() {
112         return 0;
113     }
114 }