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.CallbackExecutor; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.TestApi; 23 import android.content.Context; 24 import android.content.Intent; 25 import android.graphics.drawable.Drawable; 26 27 import java.io.Closeable; 28 import java.util.concurrent.Executor; 29 30 /** 31 * Facilitates accessing cards from the {@link QuickAccessWalletService}. 32 * 33 * @hide 34 */ 35 @TestApi 36 public interface QuickAccessWalletClient extends Closeable { 37 38 /** 39 * Create a client for accessing wallet cards from the {@link QuickAccessWalletService}. If the 40 * service is unavailable, {@link #isWalletServiceAvailable()} will return false. 41 */ 42 @NonNull create(@onNull Context context)43 static QuickAccessWalletClient create(@NonNull Context context) { 44 return new QuickAccessWalletClientImpl(context); 45 } 46 47 /** 48 * @return true if the {@link QuickAccessWalletService} is available. This means that the 49 * default NFC payment application has an exported service that can provide cards to the Quick 50 * Access Wallet. However, it does not mean that (1) the call will necessarily be successful, 51 * nor does it mean that cards may be displayed at this time. Addition checks are required: 52 * <ul> 53 * <li>If {@link #isWalletFeatureAvailable()} is false, cards should not be displayed 54 * <li>If the device is locked and {@link #isWalletFeatureAvailableWhenDeviceLocked} is 55 * false, cards should not be displayed while the device remains locked. (A message 56 * prompting the user to unlock to view cards may be appropriate).</li> 57 * </ul> 58 */ isWalletServiceAvailable()59 boolean isWalletServiceAvailable(); 60 61 /** 62 * Wallet cards should not be displayed if: 63 * <ul> 64 * <li>The wallet service is unavailable</li> 65 * <li>The device is not provisioned, ie user setup is incomplete</li> 66 * <li>If the wallet feature has been disabled by the user</li> 67 * <li>If the phone has been put into lockdown mode</li> 68 * </ul> 69 * <p> 70 * Quick Access Wallet implementers should call this method before calling 71 * {@link #getWalletCards} to ensure that cards may be displayed. 72 */ isWalletFeatureAvailable()73 boolean isWalletFeatureAvailable(); 74 75 /** 76 * Wallet cards may not be displayed on the lock screen if the user has opted to hide 77 * notifications or sensitive content on the lock screen. 78 * <ul> 79 * <li>The device is not provisioned, ie user setup is incomplete</li> 80 * <li>If the wallet feature has been disabled by the user</li> 81 * <li>If the phone has been put into lockdown mode</li> 82 * </ul> 83 * 84 * <p> 85 * Quick Access Wallet implementers should call this method before calling 86 * {@link #getWalletCards} if the device is currently locked. 87 * 88 * @return true if cards may be displayed on the lock screen. 89 */ isWalletFeatureAvailableWhenDeviceLocked()90 boolean isWalletFeatureAvailableWhenDeviceLocked(); 91 92 /** 93 * Get wallet cards from the {@link QuickAccessWalletService}. 94 */ getWalletCards( @onNull GetWalletCardsRequest request, @NonNull OnWalletCardsRetrievedCallback callback)95 void getWalletCards( 96 @NonNull GetWalletCardsRequest request, 97 @NonNull OnWalletCardsRetrievedCallback callback); 98 99 /** 100 * Get wallet cards from the {@link QuickAccessWalletService}. 101 */ getWalletCards( @onNull @allbackExecutor Executor executor, @NonNull GetWalletCardsRequest request, @NonNull OnWalletCardsRetrievedCallback callback)102 void getWalletCards( 103 @NonNull @CallbackExecutor Executor executor, 104 @NonNull GetWalletCardsRequest request, 105 @NonNull OnWalletCardsRetrievedCallback callback); 106 107 /** 108 * Callback for getWalletCards 109 */ 110 interface OnWalletCardsRetrievedCallback { onWalletCardsRetrieved(@onNull GetWalletCardsResponse response)111 void onWalletCardsRetrieved(@NonNull GetWalletCardsResponse response); 112 onWalletCardRetrievalError(@onNull GetWalletCardsError error)113 void onWalletCardRetrievalError(@NonNull GetWalletCardsError error); 114 } 115 116 /** 117 * Notify the {@link QuickAccessWalletService} service that a wallet card was selected. 118 */ selectWalletCard(@onNull SelectWalletCardRequest request)119 void selectWalletCard(@NonNull SelectWalletCardRequest request); 120 121 /** 122 * Notify the {@link QuickAccessWalletService} service that the Wallet was dismissed. 123 */ notifyWalletDismissed()124 void notifyWalletDismissed(); 125 126 /** 127 * Register an event listener. 128 */ addWalletServiceEventListener(@onNull WalletServiceEventListener listener)129 void addWalletServiceEventListener(@NonNull WalletServiceEventListener listener); 130 131 /** 132 * Register an event listener. 133 */ addWalletServiceEventListener( @onNull @allbackExecutor Executor executor, @NonNull WalletServiceEventListener listener)134 void addWalletServiceEventListener( 135 @NonNull @CallbackExecutor Executor executor, 136 @NonNull WalletServiceEventListener listener); 137 138 /** 139 * Unregister an event listener 140 */ removeWalletServiceEventListener(@onNull WalletServiceEventListener listener)141 void removeWalletServiceEventListener(@NonNull WalletServiceEventListener listener); 142 143 /** 144 * A listener for {@link WalletServiceEvent walletServiceEvents} 145 */ 146 interface WalletServiceEventListener { onWalletServiceEvent(@onNull WalletServiceEvent event)147 void onWalletServiceEvent(@NonNull WalletServiceEvent event); 148 } 149 150 /** 151 * Unregister all event listeners and disconnect from the service. 152 */ disconnect()153 void disconnect(); 154 155 /** 156 * The manifest entry for the QuickAccessWalletService may also publish information about the 157 * activity that hosts the Wallet view. This is typically the home screen of the Wallet 158 * application. 159 */ 160 @Nullable createWalletIntent()161 Intent createWalletIntent(); 162 163 /** 164 * The manifest entry for the {@link QuickAccessWalletService} may publish the activity that 165 * hosts the settings 166 */ 167 @Nullable createWalletSettingsIntent()168 Intent createWalletSettingsIntent(); 169 170 /** 171 * Returns the logo associated with the {@link QuickAccessWalletService}. This is specified by 172 * {@code android:logo} manifest entry. If the logo is not specified, the app icon will be 173 * returned instead ({@code android:icon}). 174 * 175 * @hide 176 */ 177 @Nullable getLogo()178 Drawable getLogo(); 179 180 /** 181 * Returns the tile icon associated with the {@link QuickAccessWalletService}. 182 * 183 * @hide 184 */ 185 @Nullable getTileIcon()186 Drawable getTileIcon(); 187 188 /** 189 * Returns the service label specified by {@code android:label} in the service manifest entry. 190 * 191 * @hide 192 */ 193 @Nullable getServiceLabel()194 CharSequence getServiceLabel(); 195 196 /** 197 * Returns the text specified by the {@link android:shortcutShortLabel} in the service manifest 198 * entry. If the shortcutShortLabel isn't specified, the service label ({@code android:label}) 199 * will be returned instead. 200 * 201 * @hide 202 */ 203 @Nullable getShortcutShortLabel()204 CharSequence getShortcutShortLabel(); 205 206 /** 207 * Returns the text specified by the {@link android:shortcutLongLabel} in the service manifest 208 * entry. If the shortcutShortLabel isn't specified, the service label ({@code android:label}) 209 * will be returned instead. 210 * 211 * @hide 212 */ 213 @Nullable getShortcutLongLabel()214 CharSequence getShortcutLongLabel(); 215 } 216