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#onGetDefaultDownloadableSubscriptionList} operation. 25 * @hide 26 * 27 * TODO(b/35851809): Make this a SystemApi. 28 */ 29 public final class GetDefaultDownloadableSubscriptionListResult implements Parcelable { 30 31 public static final Creator<GetDefaultDownloadableSubscriptionListResult> CREATOR = 32 new Creator<GetDefaultDownloadableSubscriptionListResult>() { 33 @Override 34 public GetDefaultDownloadableSubscriptionListResult createFromParcel(Parcel in) { 35 return new GetDefaultDownloadableSubscriptionListResult(in); 36 } 37 38 @Override 39 public GetDefaultDownloadableSubscriptionListResult[] newArray(int size) { 40 return new GetDefaultDownloadableSubscriptionListResult[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 available {@link DownloadableSubscription}s (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[] subscriptions; 59 60 /** 61 * Construct a new {@link GetDefaultDownloadableSubscriptionListResult}. 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 subscriptions The available subscriptions. Should only be provided if the result is 67 * {@link EuiccService#RESULT_OK}. 68 */ 69 public GetDefaultDownloadableSubscriptionListResult(int result, 70 @Nullable DownloadableSubscription[] subscriptions) { 71 this.result = result; 72 if (this.result == EuiccService.RESULT_OK) { 73 this.subscriptions = subscriptions; 74 } else { 75 if (subscriptions != null) { 76 throw new IllegalArgumentException( 77 "Error result with non-null subscriptions: " + result); 78 } 79 this.subscriptions = null; 80 } 81 } 82 83 private GetDefaultDownloadableSubscriptionListResult(Parcel in) { 84 this.result = in.readInt(); 85 this.subscriptions = in.createTypedArray(DownloadableSubscription.CREATOR); 86 } 87 88 @Override 89 public void writeToParcel(Parcel dest, int flags) { 90 dest.writeInt(result); 91 dest.writeTypedArray(subscriptions, flags); 92 } 93 94 @Override 95 public int describeContents() { 96 return 0; 97 } 98 } 99