Sean Pont | d00aefb | 2020-01-07 12:05:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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; |
Sean Pont | 72fc25f | 2020-02-11 19:02:44 -0800 | [diff] [blame] | 21 | import android.annotation.TestApi; |
Sean Pont | d00aefb | 2020-01-07 12:05:09 -0800 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
| 24 | |
Sean Pont | d00aefb | 2020-01-07 12:05:09 -0800 | [diff] [blame] | 25 | /** |
| 26 | * Facilitates accessing cards from the {@link QuickAccessWalletService}. |
| 27 | * |
| 28 | * @hide |
| 29 | */ |
Sean Pont | 72fc25f | 2020-02-11 19:02:44 -0800 | [diff] [blame] | 30 | @TestApi |
Sean Pont | d00aefb | 2020-01-07 12:05:09 -0800 | [diff] [blame] | 31 | public interface QuickAccessWalletClient { |
| 32 | |
| 33 | /** |
| 34 | * Create a client for accessing wallet cards from the {@link QuickAccessWalletService}. If the |
| 35 | * service is unavailable, {@link #isWalletServiceAvailable()} will return false. |
| 36 | */ |
| 37 | @NonNull |
| 38 | static QuickAccessWalletClient create(@NonNull Context context) { |
| 39 | return new QuickAccessWalletClientImpl(context); |
| 40 | } |
| 41 | |
| 42 | /** |
Sean Pont | 72fc25f | 2020-02-11 19:02:44 -0800 | [diff] [blame] | 43 | * @return true if the {@link QuickAccessWalletService} is available. This means that the |
| 44 | * default NFC payment application has an exported service that can provide cards to the Quick |
| 45 | * Access Wallet. However, it does not mean that (1) the call will necessarily be successful, |
| 46 | * nor does it mean that cards may be displayed at this time. Addition checks are required: |
| 47 | * <ul> |
| 48 | * <li>If {@link #isWalletFeatureAvailable()} is false, cards should not be displayed |
| 49 | * <li>If the device is locked and {@link #isWalletFeatureAvailableWhenDeviceLocked} is |
| 50 | * false, cards should not be displayed while the device remains locked. (A message |
| 51 | * prompting the user to unlock to view cards may be appropriate).</li> |
| 52 | * </ul> |
Sean Pont | d00aefb | 2020-01-07 12:05:09 -0800 | [diff] [blame] | 53 | */ |
| 54 | boolean isWalletServiceAvailable(); |
| 55 | |
| 56 | /** |
Sean Pont | 72fc25f | 2020-02-11 19:02:44 -0800 | [diff] [blame] | 57 | * Wallet cards should not be displayed if: |
| 58 | * <ul> |
| 59 | * <li>The wallet service is unavailable</li> |
| 60 | * <li>The device is not provisioned, ie user setup is incomplete</li> |
| 61 | * <li>If the wallet feature has been disabled by the user</li> |
| 62 | * <li>If the phone has been put into lockdown mode</li> |
| 63 | * </ul> |
| 64 | * <p> |
| 65 | * Quick Access Wallet implementers should call this method before calling |
| 66 | * {@link #getWalletCards} to ensure that cards may be displayed. |
| 67 | */ |
| 68 | boolean isWalletFeatureAvailable(); |
| 69 | |
| 70 | /** |
| 71 | * Wallet cards may not be displayed on the lock screen if the user has opted to hide |
| 72 | * notifications or sensitive content on the lock screen. |
| 73 | * <ul> |
| 74 | * <li>The device is not provisioned, ie user setup is incomplete</li> |
| 75 | * <li>If the wallet feature has been disabled by the user</li> |
| 76 | * <li>If the phone has been put into lockdown mode</li> |
| 77 | * </ul> |
| 78 | * |
| 79 | * <p> |
| 80 | * Quick Access Wallet implementers should call this method before calling |
| 81 | * {@link #getWalletCards} if the device is currently locked. |
| 82 | * |
| 83 | * @return true if cards may be displayed on the lock screen. |
| 84 | */ |
| 85 | boolean isWalletFeatureAvailableWhenDeviceLocked(); |
| 86 | |
| 87 | /** |
Sean Pont | d00aefb | 2020-01-07 12:05:09 -0800 | [diff] [blame] | 88 | * Get wallet cards from the {@link QuickAccessWalletService}. |
| 89 | */ |
| 90 | void getWalletCards( |
| 91 | @NonNull GetWalletCardsRequest request, |
Sean Pont | 72fc25f | 2020-02-11 19:02:44 -0800 | [diff] [blame] | 92 | @NonNull OnWalletCardsRetrievedCallback callback); |
| 93 | |
| 94 | /** |
| 95 | * Callback for getWalletCards |
| 96 | */ |
| 97 | interface OnWalletCardsRetrievedCallback { |
| 98 | void onWalletCardsRetrieved(@NonNull GetWalletCardsResponse response); |
| 99 | |
| 100 | void onWalletCardRetrievalError(@NonNull GetWalletCardsError error); |
| 101 | } |
Sean Pont | d00aefb | 2020-01-07 12:05:09 -0800 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Notify the {@link QuickAccessWalletService} service that a wallet card was selected. |
| 105 | */ |
| 106 | void selectWalletCard(@NonNull SelectWalletCardRequest request); |
| 107 | |
| 108 | /** |
| 109 | * Notify the {@link QuickAccessWalletService} service that the Wallet was dismissed. |
| 110 | */ |
| 111 | void notifyWalletDismissed(); |
| 112 | |
| 113 | /** |
| 114 | * Unregister event listener. |
| 115 | */ |
Sean Pont | 72fc25f | 2020-02-11 19:02:44 -0800 | [diff] [blame] | 116 | void addWalletServiceEventListener(@NonNull WalletServiceEventListener listener); |
Sean Pont | d00aefb | 2020-01-07 12:05:09 -0800 | [diff] [blame] | 117 | |
| 118 | /** |
| 119 | * Unregister event listener |
| 120 | */ |
Sean Pont | 72fc25f | 2020-02-11 19:02:44 -0800 | [diff] [blame] | 121 | void removeWalletServiceEventListener(@NonNull WalletServiceEventListener listener); |
| 122 | |
| 123 | /** |
| 124 | * A listener for {@link WalletServiceEvent walletServiceEvents} |
| 125 | */ |
| 126 | interface WalletServiceEventListener { |
| 127 | void onWalletServiceEvent(@NonNull WalletServiceEvent event); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Unregister all event listeners and disconnect from the service. |
| 132 | */ |
| 133 | void disconnect(); |
Sean Pont | d00aefb | 2020-01-07 12:05:09 -0800 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * The manifest entry for the QuickAccessWalletService may also publish information about the |
| 137 | * activity that hosts the Wallet view. This is typically the home screen of the Wallet |
| 138 | * application. |
| 139 | */ |
| 140 | @Nullable |
Sean Pont | 72fc25f | 2020-02-11 19:02:44 -0800 | [diff] [blame] | 141 | Intent createWalletIntent(); |
Sean Pont | d00aefb | 2020-01-07 12:05:09 -0800 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * The manifest entry for the {@link QuickAccessWalletService} may publish the activity that |
| 145 | * hosts the settings |
| 146 | */ |
| 147 | @Nullable |
Sean Pont | 72fc25f | 2020-02-11 19:02:44 -0800 | [diff] [blame] | 148 | Intent createWalletSettingsIntent(); |
Sean Pont | d00aefb | 2020-01-07 12:05:09 -0800 | [diff] [blame] | 149 | } |