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