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.annotation.SystemApi;
     20 import android.os.Parcel;
     21 import android.os.Parcelable;
     22 import android.telephony.euicc.DownloadableSubscription;
     23 
     24 import java.util.Arrays;
     25 import java.util.List;
     26 
     27 /**
     28  * Result of a {@link EuiccService#onGetDefaultDownloadableSubscriptionList} operation.
     29  * @hide
     30  */
     31 @SystemApi
     32 public 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 
     47     /**
     48      * @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.
     59      *
     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      */
     63     public int getResult() {
     64         return result;
     65     }
     66 
     67     /**
     68      * Gets the available {@link DownloadableSubscription}s (with filled-in metadata).
     69      *
     70      * <p>Only non-null if {@link #result} is {@link EuiccService#RESULT_OK}.
     71      */
     72     @Nullable
     73     public List<DownloadableSubscription> getDownloadableSubscriptions() {
     74         if (mSubscriptions == null) return null;
     75         return Arrays.asList(mSubscriptions);
     76     }
     77 
     78     /**
     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) {
     89         this.result = result;
     90         if (this.result == EuiccService.RESULT_OK) {
     91             this.mSubscriptions = subscriptions;
     92         } else {
     93             if (subscriptions != null) {
     94                 throw new IllegalArgumentException(
     95                         "Error result with non-null subscriptions: " + result);
     96             }
     97             this.mSubscriptions = null;
     98         }
     99     }
    100 
    101     private GetDefaultDownloadableSubscriptionListResult(Parcel in) {
    102         this.result = in.readInt();
    103         this.mSubscriptions = in.createTypedArray(DownloadableSubscription.CREATOR);
    104     }
    105 
    106     @Override
    107     public void writeToParcel(Parcel dest, int flags) {
    108         dest.writeInt(result);
    109         dest.writeTypedArray(mSubscriptions, flags);
    110     }
    111 
    112     @Override
    113     public int describeContents() {
    114         return 0;
    115     }
    116 }
    117