Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [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 | 35cda39 | 2017-02-27 09:46:00 -0800 | [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; |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | import android.telephony.euicc.DownloadableSubscription; |
| 23 | |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 24 | /** |
Jeff Davidson | 91c3d07 | 2017-04-12 12:17:11 -0700 | [diff] [blame] | 25 | * Result of a {@link EuiccService#onGetDownloadableSubscriptionMetadata} operation. |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 26 | * @hide |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 27 | */ |
Holly Jiuyu Sun | 4f73b9c | 2017-12-12 20:17:09 -0800 | [diff] [blame] | 28 | @SystemApi |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 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 | |
Jeff Davidson | 83f8bc8 | 2017-05-15 10:22:20 -0700 | [diff] [blame] | 44 | /** |
Holly Jiuyu Sun | 4f73b9c | 2017-12-12 20:17:09 -0800 | [diff] [blame] | 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. |
Jeff Davidson | 83f8bc8 | 2017-05-15 10:22:20 -0700 | [diff] [blame] | 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 | */ |
Holly Jiuyu Sun | 4f73b9c | 2017-12-12 20:17:09 -0800 | [diff] [blame] | 60 | public int getResult() { |
| 61 | return result; |
| 62 | } |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 63 | |
| 64 | /** |
Holly Jiuyu Sun | 4f73b9c | 2017-12-12 20:17:09 -0800 | [diff] [blame] | 65 | * Gets the {@link DownloadableSubscription} with filled-in metadata. |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 66 | * |
Jeff Davidson | 83f8bc8 | 2017-05-15 10:22:20 -0700 | [diff] [blame] | 67 | * <p>Only non-null if {@link #result} is {@link EuiccService#RESULT_OK}. |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 68 | */ |
| 69 | @Nullable |
Holly Jiuyu Sun | 4f73b9c | 2017-12-12 20:17:09 -0800 | [diff] [blame] | 70 | public DownloadableSubscription getDownloadableSubscription() { |
| 71 | return mSubscription; |
| 72 | } |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 73 | |
Jeff Davidson | 83f8bc8 | 2017-05-15 10:22:20 -0700 | [diff] [blame] | 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) { |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 85 | this.result = result; |
Jeff Davidson | 83f8bc8 | 2017-05-15 10:22:20 -0700 | [diff] [blame] | 86 | if (this.result == EuiccService.RESULT_OK) { |
Holly Jiuyu Sun | 4f73b9c | 2017-12-12 20:17:09 -0800 | [diff] [blame] | 87 | this.mSubscription = subscription; |
Jeff Davidson | 83f8bc8 | 2017-05-15 10:22:20 -0700 | [diff] [blame] | 88 | } else { |
| 89 | if (subscription != null) { |
| 90 | throw new IllegalArgumentException( |
| 91 | "Error result with non-null subscription: " + result); |
| 92 | } |
Holly Jiuyu Sun | 4f73b9c | 2017-12-12 20:17:09 -0800 | [diff] [blame] | 93 | this.mSubscription = null; |
Jeff Davidson | 83f8bc8 | 2017-05-15 10:22:20 -0700 | [diff] [blame] | 94 | } |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | private GetDownloadableSubscriptionMetadataResult(Parcel in) { |
| 98 | this.result = in.readInt(); |
Holly Jiuyu Sun | 4f73b9c | 2017-12-12 20:17:09 -0800 | [diff] [blame] | 99 | this.mSubscription = in.readTypedObject(DownloadableSubscription.CREATOR); |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public void writeToParcel(Parcel dest, int flags) { |
| 104 | dest.writeInt(result); |
Holly Jiuyu Sun | 4f73b9c | 2017-12-12 20:17:09 -0800 | [diff] [blame] | 105 | dest.writeTypedObject(this.mSubscription, flags); |
Jeff Davidson | 35cda39 | 2017-02-27 09:46:00 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public int describeContents() { |
| 110 | return 0; |
| 111 | } |
| 112 | } |