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