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