Aurimas Liutikas | 88c7ff1 | 2023-08-10 12:42:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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 | |
| 17 | package android.service.quickaccesswallet; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
| 21 | import android.graphics.drawable.Icon; |
| 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
| 24 | import android.text.TextUtils; |
| 25 | |
| 26 | /** |
| 27 | * Error response for an {@link GetWalletCardsRequest}. |
| 28 | */ |
| 29 | public final class GetWalletCardsError implements Parcelable { |
| 30 | |
| 31 | private final Icon mIcon; |
| 32 | private final CharSequence mMessage; |
| 33 | |
| 34 | /** |
| 35 | * Construct a new error response. If provided, the icon and message will be displayed to the |
| 36 | * user. |
| 37 | * |
| 38 | * @param icon an icon to be shown to the user next to the message. Optional. |
| 39 | * @param message message to be shown to the user. Optional. |
| 40 | */ |
| 41 | public GetWalletCardsError(@Nullable Icon icon, @Nullable CharSequence message) { |
| 42 | mIcon = icon; |
| 43 | mMessage = message; |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public int describeContents() { |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 53 | if (mIcon == null) { |
| 54 | dest.writeByte((byte) 0); |
| 55 | } else { |
| 56 | dest.writeByte((byte) 1); |
| 57 | mIcon.writeToParcel(dest, flags); |
| 58 | } |
| 59 | TextUtils.writeToParcel(mMessage, dest, flags); |
| 60 | } |
| 61 | |
| 62 | private static GetWalletCardsError readFromParcel(Parcel source) { |
| 63 | Icon icon = source.readByte() == 0 ? null : Icon.CREATOR.createFromParcel(source); |
| 64 | CharSequence message = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 65 | return new GetWalletCardsError(icon, message); |
| 66 | } |
| 67 | |
| 68 | @NonNull |
| 69 | public static final Creator<GetWalletCardsError> CREATOR = |
| 70 | new Creator<GetWalletCardsError>() { |
| 71 | @Override |
| 72 | public GetWalletCardsError createFromParcel(Parcel source) { |
| 73 | return readFromParcel(source); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public GetWalletCardsError[] newArray(int size) { |
| 78 | return new GetWalletCardsError[size]; |
| 79 | } |
| 80 | }; |
| 81 | |
| 82 | /** |
| 83 | * An icon that may be displayed with the message to provide a visual indication of why cards |
| 84 | * could not be provided in the Quick Access Wallet. |
| 85 | */ |
| 86 | @Nullable |
| 87 | public Icon getIcon() { |
| 88 | return mIcon; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * A localized message that may be shown to the user in the event that the wallet cards cannot |
| 93 | * be retrieved. <b>Note: </b> this message should <b>not</b> contain PII (Personally |
| 94 | * Identifiable Information, such as username or email address). |
| 95 | */ |
| 96 | @Nullable |
| 97 | public CharSequence getMessage() { |
| 98 | return mMessage; |
| 99 | } |
| 100 | } |