Home | History | Annotate | Download | only in euicc
      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.os.Parcel;
     20 import android.os.Parcelable;
     21 import android.telephony.euicc.DownloadableSubscription;
     22 
     23 /**
     24  * Result of a {@link EuiccService#onGetDownloadableSubscriptionMetadata} operation.
     25  * @hide
     26  *
     27  * TODO(b/35851809): Make this a SystemApi.
     28  */
     29 public 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 
     44     /**
     45      * Result of the operation.
     46      *
     47      * <p>May be one of the predefined {@code RESULT_} constants in EuiccService or any
     48      * implementation-specific code starting with {@link EuiccService#RESULT_FIRST_USER}.
     49      */
     50     public final int result;
     51 
     52     /**
     53      * The {@link DownloadableSubscription} with filled-in metadata.
     54      *
     55      * <p>Only non-null if {@link #result} is {@link EuiccService#RESULT_OK}.
     56      */
     57     @Nullable
     58     public final DownloadableSubscription subscription;
     59 
     60     /**
     61      * Construct a new {@link GetDownloadableSubscriptionMetadataResult}.
     62      *
     63      * @param result Result of the operation. May be one of the predefined {@code RESULT_} constants
     64      *     in EuiccService or any implementation-specific code starting with
     65      *     {@link EuiccService#RESULT_FIRST_USER}.
     66      * @param subscription The subscription with filled-in metadata. Should only be provided if the
     67      *     result is {@link EuiccService#RESULT_OK}.
     68      */
     69     public GetDownloadableSubscriptionMetadataResult(int result,
     70             @Nullable DownloadableSubscription subscription) {
     71         this.result = result;
     72         if (this.result == EuiccService.RESULT_OK) {
     73             this.subscription = subscription;
     74         } else {
     75             if (subscription != null) {
     76                 throw new IllegalArgumentException(
     77                         "Error result with non-null subscription: " + result);
     78             }
     79             this.subscription = null;
     80         }
     81     }
     82 
     83     private GetDownloadableSubscriptionMetadataResult(Parcel in) {
     84         this.result = in.readInt();
     85         this.subscription = in.readTypedObject(DownloadableSubscription.CREATOR);
     86     }
     87 
     88     @Override
     89     public void writeToParcel(Parcel dest, int flags) {
     90         dest.writeInt(result);
     91         dest.writeTypedObject(this.subscription, flags);
     92     }
     93 
     94     @Override
     95     public int describeContents() {
     96         return 0;
     97     }
     98 }