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 23 import java.util.Arrays; 24 import java.util.List; 25 26 /** 27 * Result of a {@link EuiccService#onGetEuiccProfileInfoList} operation. 28 * @hide 29 */ 30 @SystemApi 31 public final class GetEuiccProfileInfoListResult implements Parcelable { 32 33 public static final @android.annotation.NonNull Creator<GetEuiccProfileInfoListResult> CREATOR = 34 new Creator<GetEuiccProfileInfoListResult>() { 35 @Override 36 public GetEuiccProfileInfoListResult createFromParcel(Parcel in) { 37 return new GetEuiccProfileInfoListResult(in); 38 } 39 40 @Override 41 public GetEuiccProfileInfoListResult[] newArray(int size) { 42 return new GetEuiccProfileInfoListResult[size]; 43 } 44 }; 45 46 /** 47 * @hide 48 * @deprecated - Do no use. Use getResult() instead. 49 */ 50 @Deprecated 51 public final int result; 52 53 @Nullable 54 private final EuiccProfileInfo[] mProfiles; 55 56 private final boolean mIsRemovable; 57 58 /** 59 * Gets the result of the operation. 60 * 61 * <p>May be one of the predefined {@code RESULT_} constants in EuiccService or any 62 * implementation-specific code starting with {@link EuiccService#RESULT_FIRST_USER}. 63 */ getResult()64 public int getResult() { 65 return result; 66 } 67 68 /** Gets the profile list (only upon success). */ 69 @Nullable getProfiles()70 public List<EuiccProfileInfo> getProfiles() { 71 if (mProfiles == null) return null; 72 return Arrays.asList(mProfiles); 73 } 74 75 /** Gets whether the eUICC is removable. */ getIsRemovable()76 public boolean getIsRemovable() { 77 return mIsRemovable; 78 } 79 80 /** 81 * Construct a new {@link GetEuiccProfileInfoListResult}. 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 profiles the list of profiles. Should only be provided if the result is 87 * {@link EuiccService#RESULT_OK}. 88 * @param isRemovable whether the eUICC in this slot is removable. If true, the profiles 89 * returned here will only be considered accessible as long as this eUICC is present. 90 * Otherwise, they will remain accessible until the next time a response with isRemovable 91 * set to false is returned. 92 */ GetEuiccProfileInfoListResult( int result, @Nullable EuiccProfileInfo[] profiles, boolean isRemovable)93 public GetEuiccProfileInfoListResult( 94 int result, @Nullable EuiccProfileInfo[] profiles, boolean isRemovable) { 95 this.result = result; 96 this.mIsRemovable = isRemovable; 97 if (this.result == EuiccService.RESULT_OK) { 98 this.mProfiles = profiles; 99 } else { 100 // For error case, profiles is either null or 0 size. 101 if (profiles != null && profiles.length > 0) { 102 throw new IllegalArgumentException( 103 "Error result with non-empty profiles: " + result); 104 } 105 this.mProfiles = null; 106 } 107 } 108 GetEuiccProfileInfoListResult(Parcel in)109 private GetEuiccProfileInfoListResult(Parcel in) { 110 this.result = in.readInt(); 111 this.mProfiles = in.createTypedArray(EuiccProfileInfo.CREATOR); 112 this.mIsRemovable = in.readBoolean(); 113 } 114 115 @Override writeToParcel(Parcel dest, int flags)116 public void writeToParcel(Parcel dest, int flags) { 117 dest.writeInt(result); 118 dest.writeTypedArray(mProfiles, flags); 119 dest.writeBoolean(mIsRemovable); 120 } 121 122 @Override describeContents()123 public int describeContents() { 124 return 0; 125 } 126 } 127