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 /** 25 * Result of a {@link EuiccService#onGetDownloadableSubscriptionMetadata} operation. 26 * @hide 27 */ 28 @SystemApi 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 * @hide 46 * @deprecated - Do no use. Use getResult() instead. 47 */ 48 @Deprecated 49 public final int result; 50 51 @Nullable 52 private final DownloadableSubscription mSubscription; 53 54 /** 55 * Gets the result of the operation. 56 * 57 * <p>May be one of the predefined {@code RESULT_} constants in EuiccService or any 58 * implementation-specific code starting with {@link EuiccService#RESULT_FIRST_USER}. 59 */ 60 public int getResult() { 61 return result; 62 } 63 64 /** 65 * Gets the {@link DownloadableSubscription} with filled-in metadata. 66 * 67 * <p>Only non-null if {@link #result} is {@link EuiccService#RESULT_OK}. 68 */ 69 @Nullable 70 public DownloadableSubscription getDownloadableSubscription() { 71 return mSubscription; 72 } 73 74 /** 75 * Construct a new {@link GetDownloadableSubscriptionMetadataResult}. 76 * 77 * @param result Result of the operation. May be one of the predefined {@code RESULT_} constants 78 * in EuiccService or any implementation-specific code starting with 79 * {@link EuiccService#RESULT_FIRST_USER}. 80 * @param subscription The subscription with filled-in metadata. Should only be provided if the 81 * result is {@link EuiccService#RESULT_OK}. 82 */ 83 public GetDownloadableSubscriptionMetadataResult(int result, 84 @Nullable DownloadableSubscription subscription) { 85 this.result = result; 86 if (this.result == EuiccService.RESULT_OK) { 87 this.mSubscription = subscription; 88 } else { 89 if (subscription != null) { 90 throw new IllegalArgumentException( 91 "Error result with non-null subscription: " + result); 92 } 93 this.mSubscription = null; 94 } 95 } 96 97 private GetDownloadableSubscriptionMetadataResult(Parcel in) { 98 this.result = in.readInt(); 99 this.mSubscription = in.readTypedObject(DownloadableSubscription.CREATOR); 100 } 101 102 @Override 103 public void writeToParcel(Parcel dest, int flags) { 104 dest.writeInt(result); 105 dest.writeTypedObject(this.mSubscription, flags); 106 } 107 108 @Override 109 public int describeContents() { 110 return 0; 111 } 112 }