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