Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -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 | |
| 17 | package android.view.autofill; |
| 18 | |
Felipe Leme | 73fedac | 2017-05-12 09:52:07 -0700 | [diff] [blame] | 19 | import static android.service.autofill.FillRequest.FLAG_MANUAL_REQUEST; |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 20 | import static android.view.autofill.Helper.sDebug; |
| 21 | import static android.view.autofill.Helper.sVerbose; |
Felipe Leme | d633f07 | 2017-02-14 10:17:17 -0800 | [diff] [blame] | 22 | |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 23 | import android.annotation.IntDef; |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 24 | import android.annotation.NonNull; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 25 | import android.annotation.Nullable; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 26 | import android.annotation.SystemService; |
Felipe Leme | 452886a | 2017-11-27 13:09:13 -0800 | [diff] [blame] | 27 | import android.annotation.TestApi; |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 28 | import android.content.ComponentName; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 29 | import android.content.Context; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 30 | import android.content.Intent; |
| 31 | import android.content.IntentSender; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 32 | import android.graphics.Rect; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 33 | import android.metrics.LogMaker; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 34 | import android.os.Bundle; |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 35 | import android.os.IBinder; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 36 | import android.os.Parcelable; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 37 | import android.os.RemoteException; |
Philip P. Moltmann | cc684ed | 2017-04-17 14:18:33 -0700 | [diff] [blame] | 38 | import android.service.autofill.AutofillService; |
| 39 | import android.service.autofill.FillEventHistory; |
Felipe Leme | 452886a | 2017-11-27 13:09:13 -0800 | [diff] [blame] | 40 | import android.service.autofill.UserData; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 41 | import android.util.ArrayMap; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 42 | import android.util.ArraySet; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 43 | import android.util.Log; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 44 | import android.util.SparseArray; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 45 | import android.view.View; |
| 46 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 47 | import com.android.internal.annotations.GuardedBy; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 48 | import com.android.internal.logging.MetricsLogger; |
Felipe Leme | b22d635 | 2017-09-08 20:03:53 -0700 | [diff] [blame] | 49 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 50 | import com.android.internal.util.Preconditions; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 51 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 52 | import java.io.PrintWriter; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 53 | import java.lang.annotation.Retention; |
| 54 | import java.lang.annotation.RetentionPolicy; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 55 | import java.lang.ref.WeakReference; |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 56 | import java.util.ArrayList; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 57 | import java.util.List; |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 58 | import java.util.Objects; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 59 | |
Koji Fukui | ccec6a6 | 2017-10-18 17:48:40 +0900 | [diff] [blame] | 60 | // TODO: use java.lang.ref.Cleaner once Android supports Java 9 |
| 61 | import sun.misc.Cleaner; |
| 62 | |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 63 | /** |
Felipe Leme | 744976e | 2017-07-31 11:34:14 -0700 | [diff] [blame] | 64 | * The {@link AutofillManager} provides ways for apps and custom views to integrate with the |
| 65 | * Autofill Framework lifecycle. |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 66 | * |
Felipe Leme | 744976e | 2017-07-31 11:34:14 -0700 | [diff] [blame] | 67 | * <p>The autofill lifecycle starts with the creation of an autofill context associated with an |
| 68 | * activity context; the autofill context is created when one of the following methods is called for |
| 69 | * the first time in an activity context, and the current user has an enabled autofill service: |
| 70 | * |
| 71 | * <ul> |
| 72 | * <li>{@link #notifyViewEntered(View)} |
| 73 | * <li>{@link #notifyViewEntered(View, int, Rect)} |
| 74 | * <li>{@link #requestAutofill(View)} |
| 75 | * </ul> |
| 76 | * |
| 77 | * <p>Tipically, the context is automatically created when the first view of the activity is |
| 78 | * focused because {@code View.onFocusChanged()} indirectly calls |
| 79 | * {@link #notifyViewEntered(View)}. App developers can call {@link #requestAutofill(View)} to |
| 80 | * explicitly create it (for example, a custom view developer could offer a contextual menu action |
| 81 | * in a text-field view to let users manually request autofill). |
| 82 | * |
| 83 | * <p>After the context is created, the Android System creates a {@link android.view.ViewStructure} |
| 84 | * that represents the view hierarchy by calling |
| 85 | * {@link View#dispatchProvideAutofillStructure(android.view.ViewStructure, int)} in the root views |
| 86 | * of all application windows. By default, {@code dispatchProvideAutofillStructure()} results in |
| 87 | * subsequent calls to {@link View#onProvideAutofillStructure(android.view.ViewStructure, int)} and |
| 88 | * {@link View#onProvideAutofillVirtualStructure(android.view.ViewStructure, int)} for each view in |
| 89 | * the hierarchy. |
| 90 | * |
| 91 | * <p>The resulting {@link android.view.ViewStructure} is then passed to the autofill service, which |
| 92 | * parses it looking for views that can be autofilled. If the service finds such views, it returns |
| 93 | * a data structure to the Android System containing the following optional info: |
| 94 | * |
| 95 | * <ul> |
| 96 | * <li>Datasets used to autofill subsets of views in the activity. |
| 97 | * <li>Id of views that the service can save their values for future autofilling. |
| 98 | * </ul> |
| 99 | * |
| 100 | * <p>When the service returns datasets, the Android System displays an autofill dataset picker |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 101 | * UI associated with the view, when the view is focused on and is part of a dataset. |
| 102 | * The application can be notified when the UI is shown by registering an |
Felipe Leme | 744976e | 2017-07-31 11:34:14 -0700 | [diff] [blame] | 103 | * {@link AutofillCallback} through {@link #registerCallback(AutofillCallback)}. When the user |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 104 | * selects a dataset from the UI, all views present in the dataset are autofilled, through |
Felipe Leme | 744976e | 2017-07-31 11:34:14 -0700 | [diff] [blame] | 105 | * calls to {@link View#autofill(AutofillValue)} or {@link View#autofill(SparseArray)}. |
| 106 | * |
| 107 | * <p>When the service returns ids of savable views, the Android System keeps track of changes |
| 108 | * made to these views, so they can be used to determine if the autofill save UI is shown later. |
| 109 | * |
| 110 | * <p>The context is then finished when one of the following occurs: |
| 111 | * |
| 112 | * <ul> |
| 113 | * <li>{@link #commit()} is called or all savable views are gone. |
| 114 | * <li>{@link #cancel()} is called. |
| 115 | * </ul> |
| 116 | * |
| 117 | * <p>Finally, after the autofill context is commited (i.e., not cancelled), the Android System |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 118 | * shows an autofill save UI if the value of savable views have changed. If the user selects the |
Felipe Leme | 744976e | 2017-07-31 11:34:14 -0700 | [diff] [blame] | 119 | * option to Save, the current value of the views is then sent to the autofill service. |
| 120 | * |
| 121 | * <p>It is safe to call into its methods from any thread. |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 122 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 123 | @SystemService(Context.AUTOFILL_MANAGER_SERVICE) |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 124 | public final class AutofillManager { |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 125 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 126 | private static final String TAG = "AutofillManager"; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 127 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 128 | /** |
| 129 | * Intent extra: The assist structure which captures the filled screen. |
Felipe Leme | 7320ca9 | 2017-03-29 15:09:54 -0700 | [diff] [blame] | 130 | * |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 131 | * <p> |
| 132 | * Type: {@link android.app.assist.AssistStructure} |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 133 | */ |
| 134 | public static final String EXTRA_ASSIST_STRUCTURE = |
| 135 | "android.view.autofill.extra.ASSIST_STRUCTURE"; |
| 136 | |
| 137 | /** |
| 138 | * Intent extra: The result of an authentication operation. It is |
| 139 | * either a fully populated {@link android.service.autofill.FillResponse} |
| 140 | * or a fully populated {@link android.service.autofill.Dataset} if |
| 141 | * a response or a dataset is being authenticated respectively. |
| 142 | * |
| 143 | * <p> |
| 144 | * Type: {@link android.service.autofill.FillResponse} or a |
| 145 | * {@link android.service.autofill.Dataset} |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 146 | */ |
| 147 | public static final String EXTRA_AUTHENTICATION_RESULT = |
| 148 | "android.view.autofill.extra.AUTHENTICATION_RESULT"; |
| 149 | |
Felipe Leme | 7320ca9 | 2017-03-29 15:09:54 -0700 | [diff] [blame] | 150 | /** |
| 151 | * Intent extra: The optional extras provided by the |
| 152 | * {@link android.service.autofill.AutofillService}. |
| 153 | * |
| 154 | * <p>For example, when the service responds to a {@link |
| 155 | * android.service.autofill.FillCallback#onSuccess(android.service.autofill.FillResponse)} with |
| 156 | * a {@code FillResponse} that requires authentication, the Intent that launches the |
| 157 | * service authentication will contain the Bundle set by |
Felipe Leme | 49e9696 | 2017-04-20 15:46:18 -0700 | [diff] [blame] | 158 | * {@link android.service.autofill.FillResponse.Builder#setClientState(Bundle)} on this extra. |
Felipe Leme | 7320ca9 | 2017-03-29 15:09:54 -0700 | [diff] [blame] | 159 | * |
Felipe Leme | a937238 | 2017-10-09 14:42:36 -0700 | [diff] [blame] | 160 | * <p>On Android {@link android.os.Build.VERSION_CODES#P} and higher, the autofill service |
| 161 | * can also add this bundle to the {@link Intent} set as the |
| 162 | * {@link android.app.Activity#setResult(int, Intent) result} for an authentication request, |
| 163 | * so the bundle can be recovered later on |
| 164 | * {@link android.service.autofill.SaveRequest#getClientState()}. |
| 165 | * |
Felipe Leme | 7320ca9 | 2017-03-29 15:09:54 -0700 | [diff] [blame] | 166 | * <p> |
| 167 | * Type: {@link android.os.Bundle} |
| 168 | */ |
Felipe Leme | 37a440fd | 2017-04-28 10:50:20 -0700 | [diff] [blame] | 169 | public static final String EXTRA_CLIENT_STATE = |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 170 | "android.view.autofill.extra.CLIENT_STATE"; |
Felipe Leme | 7320ca9 | 2017-03-29 15:09:54 -0700 | [diff] [blame] | 171 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 172 | |
| 173 | /** @hide */ |
| 174 | public static final String EXTRA_RESTORE_SESSION_TOKEN = |
| 175 | "android.view.autofill.extra.RESTORE_SESSION_TOKEN"; |
| 176 | |
| 177 | private static final String SESSION_ID_TAG = "android:sessionId"; |
| 178 | private static final String STATE_TAG = "android:state"; |
| 179 | private static final String LAST_AUTOFILLED_DATA_TAG = "android:lastAutoFilledData"; |
| 180 | |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 181 | |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 182 | /** @hide */ public static final int ACTION_START_SESSION = 1; |
| 183 | /** @hide */ public static final int ACTION_VIEW_ENTERED = 2; |
| 184 | /** @hide */ public static final int ACTION_VIEW_EXITED = 3; |
| 185 | /** @hide */ public static final int ACTION_VALUE_CHANGED = 4; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 186 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 187 | |
| 188 | /** @hide */ public static final int FLAG_ADD_CLIENT_ENABLED = 0x1; |
| 189 | /** @hide */ public static final int FLAG_ADD_CLIENT_DEBUG = 0x2; |
| 190 | /** @hide */ public static final int FLAG_ADD_CLIENT_VERBOSE = 0x4; |
| 191 | |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 192 | /** Which bits in an authentication id are used for the dataset id */ |
| 193 | private static final int AUTHENTICATION_ID_DATASET_ID_MASK = 0xFFFF; |
| 194 | /** How many bits in an authentication id are used for the dataset id */ |
| 195 | private static final int AUTHENTICATION_ID_DATASET_ID_SHIFT = 16; |
| 196 | /** @hide The index for an undefined data set */ |
| 197 | public static final int AUTHENTICATION_ID_DATASET_ID_UNDEFINED = 0xFFFF; |
| 198 | |
| 199 | /** |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 200 | * Used on {@link #onPendingSaveUi(int, IBinder)} to cancel the pending UI. |
| 201 | * |
| 202 | * @hide |
| 203 | */ |
| 204 | public static final int PENDING_UI_OPERATION_CANCEL = 1; |
| 205 | |
| 206 | /** |
| 207 | * Used on {@link #onPendingSaveUi(int, IBinder)} to restore the pending UI. |
| 208 | * |
| 209 | * @hide |
| 210 | */ |
| 211 | public static final int PENDING_UI_OPERATION_RESTORE = 2; |
| 212 | |
| 213 | /** |
| 214 | * Initial state of the autofill context, set when there is no session (i.e., when |
| 215 | * {@link #mSessionId} is {@link #NO_SESSION}). |
| 216 | * |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 217 | * <p>In this state, app callbacks (such as {@link #notifyViewEntered(View)}) are notified to |
| 218 | * the server. |
| 219 | * |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 220 | * @hide |
| 221 | */ |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 222 | public static final int STATE_UNKNOWN = 0; |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 223 | |
| 224 | /** |
| 225 | * State where the autofill context hasn't been {@link #commit() finished} nor |
| 226 | * {@link #cancel() canceled} yet. |
| 227 | * |
| 228 | * @hide |
| 229 | */ |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 230 | public static final int STATE_ACTIVE = 1; |
| 231 | |
| 232 | /** |
| 233 | * State where the autofill context was finished by the server because the autofill |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 234 | * service could not autofill the activity. |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 235 | * |
| 236 | * <p>In this state, most apps callback (such as {@link #notifyViewEntered(View)}) are ignored, |
| 237 | * exception {@link #requestAutofill(View)} (and {@link #requestAutofill(View, int, Rect)}). |
| 238 | * |
| 239 | * @hide |
| 240 | */ |
| 241 | public static final int STATE_FINISHED = 2; |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 242 | |
| 243 | /** |
| 244 | * State where the autofill context has been {@link #commit() finished} but the server still has |
| 245 | * a session because the Save UI hasn't been dismissed yet. |
| 246 | * |
| 247 | * @hide |
| 248 | */ |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 249 | public static final int STATE_SHOWING_SAVE_UI = 3; |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 250 | |
| 251 | /** |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 252 | * State where the autofill is disabled because the service cannot autofill the activity at all. |
| 253 | * |
| 254 | * <p>In this state, every call is ignored, even {@link #requestAutofill(View)} |
| 255 | * (and {@link #requestAutofill(View, int, Rect)}). |
| 256 | * |
| 257 | * @hide |
| 258 | */ |
| 259 | public static final int STATE_DISABLED_BY_SERVICE = 4; |
| 260 | |
| 261 | /** |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 262 | * Makes an authentication id from a request id and a dataset id. |
| 263 | * |
| 264 | * @param requestId The request id. |
| 265 | * @param datasetId The dataset id. |
| 266 | * @return The authentication id. |
| 267 | * @hide |
| 268 | */ |
| 269 | public static int makeAuthenticationId(int requestId, int datasetId) { |
| 270 | return (requestId << AUTHENTICATION_ID_DATASET_ID_SHIFT) |
| 271 | | (datasetId & AUTHENTICATION_ID_DATASET_ID_MASK); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Gets the request id from an authentication id. |
| 276 | * |
| 277 | * @param authRequestId The authentication id. |
| 278 | * @return The request id. |
| 279 | * @hide |
| 280 | */ |
| 281 | public static int getRequestIdFromAuthenticationId(int authRequestId) { |
| 282 | return (authRequestId >> AUTHENTICATION_ID_DATASET_ID_SHIFT); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Gets the dataset id from an authentication id. |
| 287 | * |
| 288 | * @param authRequestId The authentication id. |
| 289 | * @return The dataset id. |
| 290 | * @hide |
| 291 | */ |
| 292 | public static int getDatasetIdFromAuthenticationId(int authRequestId) { |
| 293 | return (authRequestId & AUTHENTICATION_ID_DATASET_ID_MASK); |
| 294 | } |
| 295 | |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 296 | private final MetricsLogger mMetricsLogger = new MetricsLogger(); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 297 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 298 | /** |
| 299 | * There is currently no session running. |
| 300 | * {@hide} |
| 301 | */ |
| 302 | public static final int NO_SESSION = Integer.MIN_VALUE; |
| 303 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 304 | private final IAutoFillManager mService; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 305 | |
| 306 | private final Object mLock = new Object(); |
| 307 | |
| 308 | @GuardedBy("mLock") |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 309 | private IAutoFillManagerClient mServiceClient; |
| 310 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 311 | @GuardedBy("mLock") |
Koji Fukui | ccec6a6 | 2017-10-18 17:48:40 +0900 | [diff] [blame] | 312 | private Cleaner mServiceClientCleaner; |
| 313 | |
| 314 | @GuardedBy("mLock") |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 315 | private AutofillCallback mCallback; |
| 316 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 317 | private final Context mContext; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 318 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 319 | @GuardedBy("mLock") |
| 320 | private int mSessionId = NO_SESSION; |
| 321 | |
| 322 | @GuardedBy("mLock") |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 323 | private int mState = STATE_UNKNOWN; |
| 324 | |
| 325 | @GuardedBy("mLock") |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 326 | private boolean mEnabled; |
| 327 | |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 328 | /** If a view changes to this mapping the autofill operation was successful */ |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 329 | @GuardedBy("mLock") |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 330 | @Nullable private ParcelableMap mLastAutofilledData; |
| 331 | |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 332 | /** If view tracking is enabled, contains the tracking state */ |
| 333 | @GuardedBy("mLock") |
| 334 | @Nullable private TrackedViews mTrackedViews; |
| 335 | |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 336 | /** Views that are only tracked because they are fillable and could be anchoring the UI. */ |
| 337 | @GuardedBy("mLock") |
| 338 | @Nullable private ArraySet<AutofillId> mFillableIds; |
| 339 | |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 340 | /** If set, session is commited when the field is clicked. */ |
| 341 | @GuardedBy("mLock") |
| 342 | @Nullable private AutofillId mSaveTriggerId; |
| 343 | |
| 344 | /** If set, session is commited when the activity is finished; otherwise session is canceled. */ |
| 345 | @GuardedBy("mLock") |
| 346 | private boolean mSaveOnFinish; |
| 347 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 348 | /** @hide */ |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 349 | public interface AutofillClient { |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 350 | /** |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 351 | * Asks the client to start an authentication flow. |
| 352 | * |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 353 | * @param authenticationId A unique id of the authentication operation. |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 354 | * @param intent The authentication intent. |
| 355 | * @param fillInIntent The authentication fill-in intent. |
| 356 | */ |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 357 | void autofillCallbackAuthenticate(int authenticationId, IntentSender intent, |
| 358 | Intent fillInIntent); |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 359 | |
| 360 | /** |
| 361 | * Tells the client this manager has state to be reset. |
| 362 | */ |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 363 | void autofillCallbackResetableStateAvailable(); |
| 364 | |
| 365 | /** |
| 366 | * Request showing the autofill UI. |
| 367 | * |
| 368 | * @param anchor The real view the UI needs to anchor to. |
| 369 | * @param width The width of the fill UI content. |
| 370 | * @param height The height of the fill UI content. |
| 371 | * @param virtualBounds The bounds of the virtual decendant of the anchor. |
| 372 | * @param presenter The presenter that controls the fill UI window. |
| 373 | * @return Whether the UI was shown. |
| 374 | */ |
| 375 | boolean autofillCallbackRequestShowFillUi(@NonNull View anchor, int width, int height, |
| 376 | @Nullable Rect virtualBounds, IAutofillWindowPresenter presenter); |
| 377 | |
| 378 | /** |
| 379 | * Request hiding the autofill UI. |
| 380 | * |
| 381 | * @return Whether the UI was hidden. |
| 382 | */ |
| 383 | boolean autofillCallbackRequestHideFillUi(); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 384 | |
| 385 | /** |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 386 | * Checks if views are currently attached and visible. |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 387 | * |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 388 | * @return And array with {@code true} iff the view is attached or visible |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 389 | */ |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 390 | @NonNull boolean[] getViewVisibility(@NonNull int[] viewId); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 391 | |
| 392 | /** |
| 393 | * Checks is the client is currently visible as understood by autofill. |
| 394 | * |
| 395 | * @return {@code true} if the client is currently visible |
| 396 | */ |
| 397 | boolean isVisibleForAutofill(); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 398 | |
| 399 | /** |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 400 | * Finds views by traversing the hierarchies of the client. |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 401 | * |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 402 | * @param viewIds The autofill ids of the views to find |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 403 | * |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 404 | * @return And array containing the views (empty if no views found). |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 405 | */ |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 406 | @NonNull View[] findViewsByAutofillIdTraversal(@NonNull int[] viewIds); |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 407 | |
| 408 | /** |
| 409 | * Finds a view by traversing the hierarchies of the client. |
| 410 | * |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 411 | * @param viewId The autofill id of the views to find |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 412 | * |
| 413 | * @return The view, or {@code null} if not found |
| 414 | */ |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 415 | @Nullable View findViewByAutofillIdTraversal(int viewId); |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 416 | |
| 417 | /** |
| 418 | * Runs the specified action on the UI thread. |
| 419 | */ |
| 420 | void runOnUiThread(Runnable action); |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 421 | |
| 422 | /** |
| 423 | * Gets the complete component name of this client. |
| 424 | */ |
| 425 | ComponentName getComponentName(); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 426 | } |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 427 | |
| 428 | /** |
| 429 | * @hide |
| 430 | */ |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 431 | public AutofillManager(Context context, IAutoFillManager service) { |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 432 | mContext = Preconditions.checkNotNull(context, "context cannot be null"); |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 433 | mService = service; |
| 434 | } |
| 435 | |
| 436 | /** |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 437 | * Restore state after activity lifecycle |
| 438 | * |
| 439 | * @param savedInstanceState The state to be restored |
| 440 | * |
| 441 | * {@hide} |
| 442 | */ |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 443 | public void onCreate(Bundle savedInstanceState) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 444 | if (!hasAutofillFeature()) { |
| 445 | return; |
| 446 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 447 | synchronized (mLock) { |
| 448 | mLastAutofilledData = savedInstanceState.getParcelable(LAST_AUTOFILLED_DATA_TAG); |
| 449 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 450 | if (isActiveLocked()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 451 | Log.w(TAG, "New session was started before onCreate()"); |
| 452 | return; |
| 453 | } |
| 454 | |
| 455 | mSessionId = savedInstanceState.getInt(SESSION_ID_TAG, NO_SESSION); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 456 | mState = savedInstanceState.getInt(STATE_TAG, STATE_UNKNOWN); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 457 | |
| 458 | if (mSessionId != NO_SESSION) { |
| 459 | ensureServiceClientAddedIfNeededLocked(); |
| 460 | |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 461 | final AutofillClient client = getClient(); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 462 | if (client != null) { |
| 463 | try { |
| 464 | final boolean sessionWasRestored = mService.restoreSession(mSessionId, |
| 465 | mContext.getActivityToken(), mServiceClient.asBinder()); |
| 466 | |
| 467 | if (!sessionWasRestored) { |
| 468 | Log.w(TAG, "Session " + mSessionId + " could not be restored"); |
| 469 | mSessionId = NO_SESSION; |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 470 | mState = STATE_UNKNOWN; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 471 | } else { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 472 | if (sDebug) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 473 | Log.d(TAG, "session " + mSessionId + " was restored"); |
| 474 | } |
| 475 | |
| 476 | client.autofillCallbackResetableStateAvailable(); |
| 477 | } |
| 478 | } catch (RemoteException e) { |
| 479 | Log.e(TAG, "Could not figure out if there was an autofill session", e); |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | /** |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 487 | * Called once the client becomes visible. |
| 488 | * |
| 489 | * @see AutofillClient#isVisibleForAutofill() |
| 490 | * |
| 491 | * {@hide} |
| 492 | */ |
| 493 | public void onVisibleForAutofill() { |
| 494 | synchronized (mLock) { |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 495 | if (mEnabled && isActiveLocked() && mTrackedViews != null) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 496 | mTrackedViews.onVisibleForAutofillLocked(); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 497 | } |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /** |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 502 | * Save state before activity lifecycle |
| 503 | * |
| 504 | * @param outState Place to store the state |
| 505 | * |
| 506 | * {@hide} |
| 507 | */ |
| 508 | public void onSaveInstanceState(Bundle outState) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 509 | if (!hasAutofillFeature()) { |
| 510 | return; |
| 511 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 512 | synchronized (mLock) { |
| 513 | if (mSessionId != NO_SESSION) { |
| 514 | outState.putInt(SESSION_ID_TAG, mSessionId); |
| 515 | } |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 516 | if (mState != STATE_UNKNOWN) { |
| 517 | outState.putInt(STATE_TAG, mState); |
| 518 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 519 | if (mLastAutofilledData != null) { |
| 520 | outState.putParcelable(LAST_AUTOFILLED_DATA_TAG, mLastAutofilledData); |
| 521 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * Checks whether autofill is enabled for the current user. |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 527 | * |
| 528 | * <p>Typically used to determine whether the option to explicitly request autofill should |
| 529 | * be offered - see {@link #requestAutofill(View)}. |
| 530 | * |
| 531 | * @return whether autofill is enabled for the current user. |
| 532 | */ |
| 533 | public boolean isEnabled() { |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 534 | if (!hasAutofillFeature() || isDisabledByService()) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 535 | return false; |
| 536 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 537 | synchronized (mLock) { |
| 538 | ensureServiceClientAddedIfNeededLocked(); |
| 539 | return mEnabled; |
| 540 | } |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | /** |
Philip P. Moltmann | cc684ed | 2017-04-17 14:18:33 -0700 | [diff] [blame] | 544 | * Should always be called from {@link AutofillService#getFillEventHistory()}. |
| 545 | * |
| 546 | * @hide |
| 547 | */ |
| 548 | @Nullable public FillEventHistory getFillEventHistory() { |
| 549 | try { |
| 550 | return mService.getFillEventHistory(); |
| 551 | } catch (RemoteException e) { |
| 552 | e.rethrowFromSystemServer(); |
| 553 | return null; |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | /** |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 558 | * Explicitly requests a new autofill context. |
| 559 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 560 | * <p>Normally, the autofill context is automatically started if necessary when |
| 561 | * {@link #notifyViewEntered(View)} is called, but this method should be used in the |
| 562 | * cases where it must be explicitly started. For example, when the view offers an AUTOFILL |
| 563 | * option on its contextual overflow menu, and the user selects it. |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 564 | * |
| 565 | * @param view view requesting the new autofill context. |
| 566 | */ |
| 567 | public void requestAutofill(@NonNull View view) { |
Felipe Leme | d114642 | 2017-04-26 10:17:05 -0700 | [diff] [blame] | 568 | notifyViewEntered(view, FLAG_MANUAL_REQUEST); |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Explicitly requests a new autofill context for virtual views. |
| 573 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 574 | * <p>Normally, the autofill context is automatically started if necessary when |
| 575 | * {@link #notifyViewEntered(View, int, Rect)} is called, but this method should be used in the |
| 576 | * cases where it must be explicitly started. For example, when the virtual view offers an |
| 577 | * AUTOFILL option on its contextual overflow menu, and the user selects it. |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 578 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 579 | * <p>The virtual view boundaries must be absolute screen coordinates. For example, if the |
| 580 | * parent view uses {@code bounds} to draw the virtual view inside its Canvas, |
| 581 | * the absolute bounds could be calculated by: |
| 582 | * |
| 583 | * <pre class="prettyprint"> |
| 584 | * int offset[] = new int[2]; |
| 585 | * getLocationOnScreen(offset); |
| 586 | * Rect absBounds = new Rect(bounds.left + offset[0], |
| 587 | * bounds.top + offset[1], |
| 588 | * bounds.right + offset[0], bounds.bottom + offset[1]); |
| 589 | * </pre> |
| 590 | * |
| 591 | * @param view the virtual view parent. |
| 592 | * @param virtualId id identifying the virtual child inside the parent view. |
| 593 | * @param absBounds absolute boundaries of the virtual view in the screen. |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 594 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 595 | public void requestAutofill(@NonNull View view, int virtualId, @NonNull Rect absBounds) { |
| 596 | notifyViewEntered(view, virtualId, absBounds, FLAG_MANUAL_REQUEST); |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 599 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 600 | * Called when a {@link View} that supports autofill is entered. |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 601 | * |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 602 | * @param view {@link View} that was entered. |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 603 | */ |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 604 | public void notifyViewEntered(@NonNull View view) { |
Felipe Leme | d114642 | 2017-04-26 10:17:05 -0700 | [diff] [blame] | 605 | notifyViewEntered(view, 0); |
| 606 | } |
| 607 | |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 608 | private boolean shouldIgnoreViewEnteredLocked(@NonNull View view, int flags) { |
| 609 | if (isDisabledByService()) { |
| 610 | if (sVerbose) { |
| 611 | Log.v(TAG, "ignoring notifyViewEntered(flags=" + flags + ", view=" + view |
| 612 | + ") on state " + getStateAsStringLocked()); |
| 613 | } |
| 614 | return true; |
| 615 | } |
| 616 | if (mState == STATE_FINISHED && (flags & FLAG_MANUAL_REQUEST) == 0) { |
| 617 | if (sVerbose) { |
| 618 | Log.v(TAG, "ignoring notifyViewEntered(flags=" + flags + ", view=" + view |
| 619 | + ") on state " + getStateAsStringLocked()); |
| 620 | } |
| 621 | return true; |
| 622 | } |
| 623 | return false; |
| 624 | } |
| 625 | |
Felipe Leme | d114642 | 2017-04-26 10:17:05 -0700 | [diff] [blame] | 626 | private void notifyViewEntered(@NonNull View view, int flags) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 627 | if (!hasAutofillFeature()) { |
| 628 | return; |
| 629 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 630 | AutofillCallback callback = null; |
| 631 | synchronized (mLock) { |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 632 | if (shouldIgnoreViewEnteredLocked(view, flags)) return; |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 633 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 634 | ensureServiceClientAddedIfNeededLocked(); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 635 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 636 | if (!mEnabled) { |
| 637 | if (mCallback != null) { |
| 638 | callback = mCallback; |
| 639 | } |
| 640 | } else { |
| 641 | final AutofillId id = getAutofillId(view); |
| 642 | final AutofillValue value = view.getAutofillValue(); |
| 643 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 644 | if (!isActiveLocked()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 645 | // Starts new session. |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 646 | startSessionLocked(id, null, value, flags); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 647 | } else { |
| 648 | // Update focus on existing session. |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 649 | updateSessionLocked(id, null, value, ACTION_VIEW_ENTERED, flags); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 650 | } |
Felipe Leme | 24aae15 | 2017-03-15 12:33:01 -0700 | [diff] [blame] | 651 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 652 | } |
| 653 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 654 | if (callback != null) { |
| 655 | mCallback.onAutofillEvent(view, AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 656 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 660 | * Called when a {@link View} that supports autofill is exited. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 661 | * |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 662 | * @param view {@link View} that was exited. |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 663 | */ |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 664 | public void notifyViewExited(@NonNull View view) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 665 | if (!hasAutofillFeature()) { |
| 666 | return; |
| 667 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 668 | synchronized (mLock) { |
| 669 | ensureServiceClientAddedIfNeededLocked(); |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 670 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 671 | if (mEnabled && isActiveLocked()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 672 | final AutofillId id = getAutofillId(view); |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 673 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 674 | // Update focus on existing session. |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 675 | updateSessionLocked(id, null, null, ACTION_VIEW_EXITED, 0); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 676 | } |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
| 680 | /** |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame] | 681 | * Called when a {@link View view's} visibility changed. |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 682 | * |
| 683 | * @param view {@link View} that was exited. |
| 684 | * @param isVisible visible if the view is visible in the view hierarchy. |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 685 | */ |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame] | 686 | public void notifyViewVisibilityChanged(@NonNull View view, boolean isVisible) { |
| 687 | notifyViewVisibilityChangedInternal(view, 0, isVisible, false); |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * Called when a virtual view's visibility changed. |
| 692 | * |
| 693 | * @param view {@link View} that was exited. |
| 694 | * @param virtualId id identifying the virtual child inside the parent view. |
| 695 | * @param isVisible visible if the view is visible in the view hierarchy. |
| 696 | */ |
| 697 | public void notifyViewVisibilityChanged(@NonNull View view, int virtualId, boolean isVisible) { |
| 698 | notifyViewVisibilityChangedInternal(view, virtualId, isVisible, true); |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * Called when a view/virtual view's visibility changed. |
| 703 | * |
| 704 | * @param view {@link View} that was exited. |
| 705 | * @param virtualId id identifying the virtual child inside the parent view. |
| 706 | * @param isVisible visible if the view is visible in the view hierarchy. |
| 707 | * @param virtual Whether the view is virtual. |
| 708 | */ |
| 709 | private void notifyViewVisibilityChangedInternal(@NonNull View view, int virtualId, |
| 710 | boolean isVisible, boolean virtual) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 711 | synchronized (mLock) { |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 712 | if (mEnabled && isActiveLocked()) { |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame] | 713 | final AutofillId id = virtual ? getAutofillId(view, virtualId) |
| 714 | : view.getAutofillId(); |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 715 | if (!isVisible && mFillableIds != null) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 716 | if (mFillableIds.contains(id)) { |
| 717 | if (sDebug) Log.d(TAG, "Hidding UI when view " + id + " became invisible"); |
| 718 | requestHideFillUi(id, view); |
| 719 | } |
| 720 | } |
| 721 | if (mTrackedViews != null) { |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame] | 722 | mTrackedViews.notifyViewVisibilityChanged(id, isVisible); |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 723 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 724 | } |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 729 | * Called when a virtual view that supports autofill is entered. |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 730 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 731 | * <p>The virtual view boundaries must be absolute screen coordinates. For example, if the |
| 732 | * parent, non-virtual view uses {@code bounds} to draw the virtual view inside its Canvas, |
| 733 | * the absolute bounds could be calculated by: |
| 734 | * |
| 735 | * <pre class="prettyprint"> |
| 736 | * int offset[] = new int[2]; |
| 737 | * getLocationOnScreen(offset); |
| 738 | * Rect absBounds = new Rect(bounds.left + offset[0], |
| 739 | * bounds.top + offset[1], |
| 740 | * bounds.right + offset[0], bounds.bottom + offset[1]); |
| 741 | * </pre> |
| 742 | * |
| 743 | * @param view the virtual view parent. |
| 744 | * @param virtualId id identifying the virtual child inside the parent view. |
| 745 | * @param absBounds absolute boundaries of the virtual view in the screen. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 746 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 747 | public void notifyViewEntered(@NonNull View view, int virtualId, @NonNull Rect absBounds) { |
| 748 | notifyViewEntered(view, virtualId, absBounds, 0); |
Felipe Leme | d114642 | 2017-04-26 10:17:05 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 751 | private void notifyViewEntered(View view, int virtualId, Rect bounds, int flags) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 752 | if (!hasAutofillFeature()) { |
| 753 | return; |
| 754 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 755 | AutofillCallback callback = null; |
| 756 | synchronized (mLock) { |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 757 | if (shouldIgnoreViewEnteredLocked(view, flags)) return; |
| 758 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 759 | ensureServiceClientAddedIfNeededLocked(); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 760 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 761 | if (!mEnabled) { |
| 762 | if (mCallback != null) { |
| 763 | callback = mCallback; |
| 764 | } |
| 765 | } else { |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 766 | final AutofillId id = getAutofillId(view, virtualId); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 767 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 768 | if (!isActiveLocked()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 769 | // Starts new session. |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 770 | startSessionLocked(id, bounds, null, flags); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 771 | } else { |
| 772 | // Update focus on existing session. |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 773 | updateSessionLocked(id, bounds, null, ACTION_VIEW_ENTERED, flags); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 774 | } |
Felipe Leme | 24aae15 | 2017-03-15 12:33:01 -0700 | [diff] [blame] | 775 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 776 | } |
| 777 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 778 | if (callback != null) { |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 779 | callback.onAutofillEvent(view, virtualId, |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 780 | AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
| 784 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 785 | * Called when a virtual view that supports autofill is exited. |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 786 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 787 | * @param view the virtual view parent. |
| 788 | * @param virtualId id identifying the virtual child inside the parent view. |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 789 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 790 | public void notifyViewExited(@NonNull View view, int virtualId) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 791 | if (!hasAutofillFeature()) { |
| 792 | return; |
| 793 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 794 | synchronized (mLock) { |
| 795 | ensureServiceClientAddedIfNeededLocked(); |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 796 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 797 | if (mEnabled && isActiveLocked()) { |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 798 | final AutofillId id = getAutofillId(view, virtualId); |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 799 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 800 | // Update focus on existing session. |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 801 | updateSessionLocked(id, null, null, ACTION_VIEW_EXITED, 0); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 802 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 803 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | /** |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 807 | * Called to indicate the value of an autofillable {@link View} changed. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 808 | * |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 809 | * @param view view whose value changed. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 810 | */ |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 811 | public void notifyValueChanged(View view) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 812 | if (!hasAutofillFeature()) { |
| 813 | return; |
| 814 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 815 | AutofillId id = null; |
| 816 | boolean valueWasRead = false; |
| 817 | AutofillValue value = null; |
| 818 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 819 | synchronized (mLock) { |
| 820 | // If the session is gone some fields might still be highlighted, hence we have to |
| 821 | // remove the isAutofilled property even if no sessions are active. |
| 822 | if (mLastAutofilledData == null) { |
| 823 | view.setAutofilled(false); |
| 824 | } else { |
| 825 | id = getAutofillId(view); |
| 826 | if (mLastAutofilledData.containsKey(id)) { |
| 827 | value = view.getAutofillValue(); |
| 828 | valueWasRead = true; |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 829 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 830 | if (Objects.equals(mLastAutofilledData.get(id), value)) { |
| 831 | view.setAutofilled(true); |
| 832 | } else { |
| 833 | view.setAutofilled(false); |
| 834 | mLastAutofilledData.remove(id); |
| 835 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 836 | } else { |
| 837 | view.setAutofilled(false); |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 838 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 839 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 840 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 841 | if (!mEnabled || !isActiveLocked()) { |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 842 | if (sVerbose && mEnabled) { |
| 843 | Log.v(TAG, "notifyValueChanged(" + view + "): ignoring on state " |
| 844 | + getStateAsStringLocked()); |
| 845 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 846 | return; |
| 847 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 848 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 849 | if (id == null) { |
| 850 | id = getAutofillId(view); |
| 851 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 852 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 853 | if (!valueWasRead) { |
| 854 | value = view.getAutofillValue(); |
| 855 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 856 | |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 857 | updateSessionLocked(id, null, value, ACTION_VALUE_CHANGED, 0); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 858 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 859 | } |
| 860 | |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 861 | /** |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 862 | * Called to indicate the value of an autofillable virtual view has changed. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 863 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 864 | * @param view the virtual view parent. |
| 865 | * @param virtualId id identifying the virtual child inside the parent view. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 866 | * @param value new value of the child. |
| 867 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 868 | public void notifyValueChanged(View view, int virtualId, AutofillValue value) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 869 | if (!hasAutofillFeature()) { |
| 870 | return; |
| 871 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 872 | synchronized (mLock) { |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 873 | if (!mEnabled || !isActiveLocked()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 874 | return; |
| 875 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 876 | |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 877 | final AutofillId id = getAutofillId(view, virtualId); |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 878 | updateSessionLocked(id, null, value, ACTION_VALUE_CHANGED, 0); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 879 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 880 | } |
| 881 | |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 882 | |
| 883 | /** |
| 884 | * Called when a {@link View} is clicked. Currently only used by views that should trigger save. |
| 885 | * |
| 886 | * @hide |
| 887 | */ |
| 888 | public void notifyViewClicked(View view) { |
| 889 | final AutofillId id = view.getAutofillId(); |
| 890 | |
| 891 | if (sVerbose) Log.v(TAG, "notifyViewClicked(): id=" + id + ", trigger=" + mSaveTriggerId); |
| 892 | |
| 893 | synchronized (mLock) { |
| 894 | if (mSaveTriggerId != null && mSaveTriggerId.equals(id)) { |
| 895 | if (sDebug) Log.d(TAG, "triggering commit by click of " + id); |
| 896 | commitLocked(); |
| 897 | mMetricsLogger.action(MetricsEvent.AUTOFILL_SAVE_EXPLICITLY_TRIGGERED, |
| 898 | mContext.getPackageName()); |
| 899 | } |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | /** |
| 904 | * Called by {@link android.app.Activity} to commit or cancel the session on finish. |
| 905 | * |
| 906 | * @hide |
| 907 | */ |
| 908 | public void onActivityFinished() { |
| 909 | if (!hasAutofillFeature()) { |
| 910 | return; |
| 911 | } |
| 912 | synchronized (mLock) { |
| 913 | if (mSaveOnFinish) { |
Felipe Leme | 601d220 | 2017-11-17 08:21:23 -0800 | [diff] [blame] | 914 | if (sDebug) Log.d(TAG, "Committing session on finish() as requested by service"); |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 915 | commitLocked(); |
| 916 | } else { |
| 917 | if (sDebug) Log.d(TAG, "Cancelling session on finish() as requested by service"); |
| 918 | cancelLocked(); |
| 919 | } |
| 920 | } |
| 921 | } |
| 922 | |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 923 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 924 | * Called to indicate the current autofill context should be commited. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 925 | * |
Felipe Leme | afdfe76 | 2017-07-24 11:25:56 -0700 | [diff] [blame] | 926 | * <p>This method is typically called by {@link View Views} that manage virtual views; for |
| 927 | * example, when the view is rendering an {@code HTML} page with a form and virtual views |
| 928 | * that represent the HTML elements, it should call this method after the form is submitted and |
| 929 | * another page is rendered. |
| 930 | * |
| 931 | * <p><b>Note:</b> This method does not need to be called on regular application lifecycle |
| 932 | * methods such as {@link android.app.Activity#finish()}. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 933 | */ |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 934 | public void commit() { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 935 | if (!hasAutofillFeature()) { |
| 936 | return; |
| 937 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 938 | synchronized (mLock) { |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 939 | commitLocked(); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 940 | } |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 941 | } |
| 942 | |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 943 | private void commitLocked() { |
| 944 | if (!mEnabled && !isActiveLocked()) { |
| 945 | return; |
| 946 | } |
| 947 | finishSessionLocked(); |
| 948 | } |
| 949 | |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 950 | /** |
| 951 | * Called to indicate the current autofill context should be cancelled. |
| 952 | * |
Felipe Leme | afdfe76 | 2017-07-24 11:25:56 -0700 | [diff] [blame] | 953 | * <p>This method is typically called by {@link View Views} that manage virtual views; for |
| 954 | * example, when the view is rendering an {@code HTML} page with a form and virtual views |
| 955 | * that represent the HTML elements, it should call this method if the user does not post the |
| 956 | * form but moves to another form in this page. |
| 957 | * |
| 958 | * <p><b>Note:</b> This method does not need to be called on regular application lifecycle |
| 959 | * methods such as {@link android.app.Activity#finish()}. |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 960 | */ |
| 961 | public void cancel() { |
Felipe Leme | 601d220 | 2017-11-17 08:21:23 -0800 | [diff] [blame] | 962 | if (sVerbose) Log.v(TAG, "cancel() called by app"); |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 963 | if (!hasAutofillFeature()) { |
| 964 | return; |
| 965 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 966 | synchronized (mLock) { |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 967 | cancelLocked(); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 968 | } |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 969 | } |
| 970 | |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 971 | private void cancelLocked() { |
| 972 | if (!mEnabled && !isActiveLocked()) { |
| 973 | return; |
| 974 | } |
| 975 | cancelSessionLocked(); |
| 976 | } |
| 977 | |
Svet Ganov | f965b87 | 2017-04-28 16:34:02 -0700 | [diff] [blame] | 978 | /** @hide */ |
| 979 | public void disableOwnedAutofillServices() { |
| 980 | disableAutofillServices(); |
| 981 | } |
| 982 | |
Svet Ganov | f20a037 | 2017-04-10 17:08:05 -0700 | [diff] [blame] | 983 | /** |
| 984 | * If the app calling this API has enabled autofill services they |
| 985 | * will be disabled. |
| 986 | */ |
Svet Ganov | f965b87 | 2017-04-28 16:34:02 -0700 | [diff] [blame] | 987 | public void disableAutofillServices() { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 988 | if (!hasAutofillFeature()) { |
| 989 | return; |
| 990 | } |
Svet Ganov | f20a037 | 2017-04-10 17:08:05 -0700 | [diff] [blame] | 991 | try { |
| 992 | mService.disableOwnedAutofillServices(mContext.getUserId()); |
| 993 | } catch (RemoteException e) { |
| 994 | throw e.rethrowFromSystemServer(); |
| 995 | } |
| 996 | } |
| 997 | |
Felipe Leme | db04118 | 2017-04-21 17:33:38 -0700 | [diff] [blame] | 998 | /** |
| 999 | * Returns {@code true} if the calling application provides a {@link AutofillService} that is |
| 1000 | * enabled for the current user, or {@code false} otherwise. |
| 1001 | */ |
| 1002 | public boolean hasEnabledAutofillServices() { |
| 1003 | if (mService == null) return false; |
| 1004 | |
| 1005 | try { |
| 1006 | return mService.isServiceEnabled(mContext.getUserId(), mContext.getPackageName()); |
| 1007 | } catch (RemoteException e) { |
| 1008 | throw e.rethrowFromSystemServer(); |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | /** |
Felipe Leme | 452886a | 2017-11-27 13:09:13 -0800 | [diff] [blame] | 1013 | * Gets the user data used for <a href="#FieldsClassification">fields classification</a>. |
| 1014 | * |
| 1015 | * <p><b>Note:</b> This method should only be called by an app providing an autofill service. |
| 1016 | * |
| 1017 | * TODO(b/67867469): |
| 1018 | * - proper javadoc |
| 1019 | * - unhide / remove testApi |
| 1020 | * |
| 1021 | * @return value previously set by {@link #setUserData(UserData)} or {@code null} if it was |
| 1022 | * reset or if the caller currently does not have an enabled autofill service for the user. |
| 1023 | * |
| 1024 | * @hide |
| 1025 | */ |
| 1026 | @TestApi |
| 1027 | @Nullable public UserData getUserData() { |
| 1028 | try { |
| 1029 | return mService.getUserData(); |
| 1030 | } catch (RemoteException e) { |
| 1031 | e.rethrowFromSystemServer(); |
| 1032 | return null; |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | /** |
| 1037 | * Sets the user data used for <a href="#FieldsClassification">fields classification</a>. |
| 1038 | * |
| 1039 | * <p><b>Note:</b> This method should only be called by an app providing an autofill service, |
| 1040 | * and it's ignored if the caller currently doesn't have an enabled autofill service for |
| 1041 | * the user. |
| 1042 | * |
| 1043 | * TODO(b/67867469): |
| 1044 | * - proper javadoc |
| 1045 | * - unhide / remove testApi |
| 1046 | * - add unit tests: |
| 1047 | * - call set / get / verify |
| 1048 | * |
| 1049 | * @hide |
| 1050 | */ |
| 1051 | @TestApi |
| 1052 | public void setUserData(@Nullable UserData userData) { |
| 1053 | try { |
| 1054 | mService.setUserData(userData); |
| 1055 | } catch (RemoteException e) { |
| 1056 | e.rethrowFromSystemServer(); |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | /** |
Felipe Leme | 329d040 | 2017-12-06 09:22:43 -0800 | [diff] [blame] | 1061 | * TODO(b/67867469): |
| 1062 | * - proper javadoc |
| 1063 | * - mention this method in other places |
| 1064 | * - unhide / remove testApi |
| 1065 | * @hide |
| 1066 | */ |
| 1067 | @TestApi |
| 1068 | public boolean isFieldClassificationEnabled() { |
| 1069 | try { |
| 1070 | return mService.isFieldClassificationEnabled(); |
| 1071 | } catch (RemoteException e) { |
| 1072 | e.rethrowFromSystemServer(); |
| 1073 | return false; |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | /** |
Ricardo Loo | 33d226c | 2017-06-27 14:17:33 -0700 | [diff] [blame] | 1078 | * Returns {@code true} if autofill is supported by the current device and |
| 1079 | * is supported for this user. |
Felipe Leme | db04118 | 2017-04-21 17:33:38 -0700 | [diff] [blame] | 1080 | * |
| 1081 | * <p>Autofill is typically supported, but it could be unsupported in cases like: |
| 1082 | * <ol> |
| 1083 | * <li>Low-end devices. |
| 1084 | * <li>Device policy rules that forbid its usage. |
| 1085 | * </ol> |
| 1086 | */ |
| 1087 | public boolean isAutofillSupported() { |
| 1088 | if (mService == null) return false; |
| 1089 | |
| 1090 | try { |
| 1091 | return mService.isServiceSupported(mContext.getUserId()); |
| 1092 | } catch (RemoteException e) { |
| 1093 | throw e.rethrowFromSystemServer(); |
| 1094 | } |
| 1095 | } |
| 1096 | |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1097 | // Note: don't need to use locked suffix because mContext is final. |
| 1098 | private AutofillClient getClient() { |
Felipe Leme | 686128e | 2017-10-17 14:02:20 -0700 | [diff] [blame] | 1099 | final AutofillClient client = mContext.getAutofillClient(); |
| 1100 | if (client == null && sDebug) { |
| 1101 | Log.d(TAG, "No AutofillClient for " + mContext.getPackageName() + " on context " |
| 1102 | + mContext); |
| 1103 | } |
| 1104 | return client; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | /** @hide */ |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 1108 | public void onAuthenticationResult(int authenticationId, Intent data) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 1109 | if (!hasAutofillFeature()) { |
| 1110 | return; |
| 1111 | } |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 1112 | // TODO: the result code is being ignored, so this method is not reliably |
Felipe Leme | d633f07 | 2017-02-14 10:17:17 -0800 | [diff] [blame] | 1113 | // handling the cases where it's not RESULT_OK: it works fine if the service does not |
| 1114 | // set the EXTRA_AUTHENTICATION_RESULT extra, but it could cause weird results if the |
| 1115 | // service set the extra and returned RESULT_CANCELED... |
| 1116 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1117 | if (sDebug) Log.d(TAG, "onAuthenticationResult(): d=" + data); |
Felipe Leme | d633f07 | 2017-02-14 10:17:17 -0800 | [diff] [blame] | 1118 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1119 | synchronized (mLock) { |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1120 | if (!isActiveLocked() || data == null) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1121 | return; |
| 1122 | } |
| 1123 | final Parcelable result = data.getParcelableExtra(EXTRA_AUTHENTICATION_RESULT); |
| 1124 | final Bundle responseData = new Bundle(); |
| 1125 | responseData.putParcelable(EXTRA_AUTHENTICATION_RESULT, result); |
Felipe Leme | a937238 | 2017-10-09 14:42:36 -0700 | [diff] [blame] | 1126 | final Bundle newClientState = data.getBundleExtra(EXTRA_CLIENT_STATE); |
| 1127 | if (newClientState != null) { |
| 1128 | responseData.putBundle(EXTRA_CLIENT_STATE, newClientState); |
| 1129 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1130 | try { |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 1131 | mService.setAuthenticationResult(responseData, mSessionId, authenticationId, |
| 1132 | mContext.getUserId()); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1133 | } catch (RemoteException e) { |
| 1134 | Log.e(TAG, "Error delivering authentication result", e); |
| 1135 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1136 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 1137 | } |
| 1138 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1139 | private static AutofillId getAutofillId(View view) { |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1140 | return new AutofillId(view.getAutofillViewId()); |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 1141 | } |
| 1142 | |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 1143 | private static AutofillId getAutofillId(View parent, int virtualId) { |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1144 | return new AutofillId(parent.getAutofillViewId(), virtualId); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 1145 | } |
| 1146 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1147 | private void startSessionLocked(@NonNull AutofillId id, @NonNull Rect bounds, |
| 1148 | @NonNull AutofillValue value, int flags) { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1149 | if (sVerbose) { |
| 1150 | Log.v(TAG, "startSessionLocked(): id=" + id + ", bounds=" + bounds + ", value=" + value |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1151 | + ", flags=" + flags + ", state=" + getStateAsStringLocked()); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 1152 | } |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1153 | if (mState != STATE_UNKNOWN && (flags & FLAG_MANUAL_REQUEST) == 0) { |
| 1154 | if (sVerbose) { |
| 1155 | Log.v(TAG, "not automatically starting session for " + id |
| 1156 | + " on state " + getStateAsStringLocked()); |
| 1157 | } |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1158 | return; |
| 1159 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 1160 | try { |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1161 | final AutofillClient client = getClient(); |
| 1162 | if (client == null) return; // NOTE: getClient() already logd it.. |
| 1163 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1164 | mSessionId = mService.startSession(mContext.getActivityToken(), |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1165 | mServiceClient.asBinder(), id, bounds, value, mContext.getUserId(), |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1166 | mCallback != null, flags, client.getComponentName()); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1167 | if (mSessionId != NO_SESSION) { |
| 1168 | mState = STATE_ACTIVE; |
| 1169 | } |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1170 | client.autofillCallbackResetableStateAvailable(); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1171 | } catch (RemoteException e) { |
| 1172 | throw e.rethrowFromSystemServer(); |
| 1173 | } |
| 1174 | } |
| 1175 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1176 | private void finishSessionLocked() { |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1177 | if (sVerbose) Log.v(TAG, "finishSessionLocked(): " + getStateAsStringLocked()); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1178 | |
| 1179 | if (!isActiveLocked()) return; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1180 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1181 | try { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1182 | mService.finishSession(mSessionId, mContext.getUserId()); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 1183 | } catch (RemoteException e) { |
| 1184 | throw e.rethrowFromSystemServer(); |
| 1185 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1186 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1187 | resetSessionLocked(); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 1188 | } |
| 1189 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1190 | private void cancelSessionLocked() { |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1191 | if (sVerbose) Log.v(TAG, "cancelSessionLocked(): " + getStateAsStringLocked()); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1192 | |
| 1193 | if (!isActiveLocked()) return; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1194 | |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 1195 | try { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1196 | mService.cancelSession(mSessionId, mContext.getUserId()); |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 1197 | } catch (RemoteException e) { |
| 1198 | throw e.rethrowFromSystemServer(); |
| 1199 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1200 | |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1201 | resetSessionLocked(); |
| 1202 | } |
| 1203 | |
| 1204 | private void resetSessionLocked() { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1205 | mSessionId = NO_SESSION; |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1206 | mState = STATE_UNKNOWN; |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1207 | mTrackedViews = null; |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1208 | mFillableIds = null; |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 1209 | mSaveTriggerId = null; |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 1212 | private void updateSessionLocked(AutofillId id, Rect bounds, AutofillValue value, int action, |
| 1213 | int flags) { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1214 | if (sVerbose && action != ACTION_VIEW_EXITED) { |
| 1215 | Log.v(TAG, "updateSessionLocked(): id=" + id + ", bounds=" + bounds |
| 1216 | + ", value=" + value + ", action=" + action + ", flags=" + flags); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 1217 | } |
Felipe Leme | 7f33cd3 | 2017-05-11 10:10:49 -0700 | [diff] [blame] | 1218 | boolean restartIfNecessary = (flags & FLAG_MANUAL_REQUEST) != 0; |
| 1219 | |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 1220 | try { |
Felipe Leme | 7f33cd3 | 2017-05-11 10:10:49 -0700 | [diff] [blame] | 1221 | if (restartIfNecessary) { |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1222 | final AutofillClient client = getClient(); |
| 1223 | if (client == null) return; // NOTE: getClient() already logd it.. |
| 1224 | |
Felipe Leme | 7f33cd3 | 2017-05-11 10:10:49 -0700 | [diff] [blame] | 1225 | final int newId = mService.updateOrRestartSession(mContext.getActivityToken(), |
| 1226 | mServiceClient.asBinder(), id, bounds, value, mContext.getUserId(), |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1227 | mCallback != null, flags, client.getComponentName(), mSessionId, action); |
Felipe Leme | 7f33cd3 | 2017-05-11 10:10:49 -0700 | [diff] [blame] | 1228 | if (newId != mSessionId) { |
| 1229 | if (sDebug) Log.d(TAG, "Session restarted: " + mSessionId + "=>" + newId); |
| 1230 | mSessionId = newId; |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1231 | mState = (mSessionId == NO_SESSION) ? STATE_UNKNOWN : STATE_ACTIVE; |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1232 | client.autofillCallbackResetableStateAvailable(); |
Felipe Leme | 7f33cd3 | 2017-05-11 10:10:49 -0700 | [diff] [blame] | 1233 | } |
| 1234 | } else { |
| 1235 | mService.updateSession(mSessionId, id, bounds, value, action, flags, |
| 1236 | mContext.getUserId()); |
| 1237 | } |
| 1238 | |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 1239 | } catch (RemoteException e) { |
| 1240 | throw e.rethrowFromSystemServer(); |
| 1241 | } |
| 1242 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1243 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1244 | private void ensureServiceClientAddedIfNeededLocked() { |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1245 | if (getClient() == null) { |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1246 | return; |
| 1247 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1248 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1249 | if (mServiceClient == null) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1250 | mServiceClient = new AutofillManagerClient(this); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1251 | try { |
Koji Fukui | ccec6a6 | 2017-10-18 17:48:40 +0900 | [diff] [blame] | 1252 | final int userId = mContext.getUserId(); |
| 1253 | final int flags = mService.addClient(mServiceClient, userId); |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1254 | mEnabled = (flags & FLAG_ADD_CLIENT_ENABLED) != 0; |
| 1255 | sDebug = (flags & FLAG_ADD_CLIENT_DEBUG) != 0; |
| 1256 | sVerbose = (flags & FLAG_ADD_CLIENT_VERBOSE) != 0; |
Koji Fukui | ccec6a6 | 2017-10-18 17:48:40 +0900 | [diff] [blame] | 1257 | final IAutoFillManager service = mService; |
| 1258 | final IAutoFillManagerClient serviceClient = mServiceClient; |
| 1259 | mServiceClientCleaner = Cleaner.create(this, () -> { |
| 1260 | try { |
| 1261 | service.removeClient(serviceClient, userId); |
| 1262 | } catch (RemoteException e) { |
| 1263 | } |
| 1264 | }); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1265 | } catch (RemoteException e) { |
| 1266 | throw e.rethrowFromSystemServer(); |
| 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1271 | /** |
| 1272 | * Registers a {@link AutofillCallback} to receive autofill events. |
| 1273 | * |
| 1274 | * @param callback callback to receive events. |
| 1275 | */ |
| 1276 | public void registerCallback(@Nullable AutofillCallback callback) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 1277 | if (!hasAutofillFeature()) { |
| 1278 | return; |
| 1279 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1280 | synchronized (mLock) { |
| 1281 | if (callback == null) return; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1282 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1283 | final boolean hadCallback = mCallback != null; |
| 1284 | mCallback = callback; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1285 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1286 | if (!hadCallback) { |
| 1287 | try { |
| 1288 | mService.setHasCallback(mSessionId, mContext.getUserId(), true); |
| 1289 | } catch (RemoteException e) { |
| 1290 | throw e.rethrowFromSystemServer(); |
| 1291 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1292 | } |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | /** |
| 1297 | * Unregisters a {@link AutofillCallback} to receive autofill events. |
| 1298 | * |
| 1299 | * @param callback callback to stop receiving events. |
| 1300 | */ |
| 1301 | public void unregisterCallback(@Nullable AutofillCallback callback) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 1302 | if (!hasAutofillFeature()) { |
| 1303 | return; |
| 1304 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1305 | synchronized (mLock) { |
| 1306 | if (callback == null || mCallback == null || callback != mCallback) return; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1307 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1308 | mCallback = null; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1309 | |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1310 | try { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1311 | mService.setHasCallback(mSessionId, mContext.getUserId(), false); |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1312 | } catch (RemoteException e) { |
| 1313 | throw e.rethrowFromSystemServer(); |
| 1314 | } |
| 1315 | } |
| 1316 | } |
| 1317 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1318 | private void requestShowFillUi(int sessionId, AutofillId id, int width, int height, |
| 1319 | Rect anchorBounds, IAutofillWindowPresenter presenter) { |
| 1320 | final View anchor = findView(id); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1321 | if (anchor == null) { |
| 1322 | return; |
| 1323 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1324 | |
| 1325 | AutofillCallback callback = null; |
| 1326 | synchronized (mLock) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1327 | if (mSessionId == sessionId) { |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1328 | AutofillClient client = getClient(); |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1329 | |
| 1330 | if (client != null) { |
| 1331 | if (client.autofillCallbackRequestShowFillUi(anchor, width, height, |
| 1332 | anchorBounds, presenter) && mCallback != null) { |
| 1333 | callback = mCallback; |
| 1334 | } |
| 1335 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | if (callback != null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1340 | if (id.isVirtual()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1341 | callback.onAutofillEvent(anchor, id.getVirtualChildId(), |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1342 | AutofillCallback.EVENT_INPUT_SHOWN); |
| 1343 | } else { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1344 | callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_SHOWN); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | } |
| 1348 | |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 1349 | private void authenticate(int sessionId, int authenticationId, IntentSender intent, |
| 1350 | Intent fillInIntent) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1351 | synchronized (mLock) { |
| 1352 | if (sessionId == mSessionId) { |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1353 | final AutofillClient client = getClient(); |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1354 | if (client != null) { |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 1355 | client.autofillCallbackAuthenticate(authenticationId, intent, fillInIntent); |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | } |
| 1359 | } |
| 1360 | |
Felipe Leme | 51e29da | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1361 | /** @hide */ |
| 1362 | public static final int SET_STATE_FLAG_ENABLED = 0x01; |
| 1363 | /** @hide */ |
| 1364 | public static final int SET_STATE_FLAG_RESET_SESSION = 0x02; |
| 1365 | /** @hide */ |
| 1366 | public static final int SET_STATE_FLAG_RESET_CLIENT = 0x04; |
| 1367 | /** @hide */ |
| 1368 | public static final int SET_STATE_FLAG_DEBUG = 0x08; |
| 1369 | /** @hide */ |
| 1370 | public static final int SET_STATE_FLAG_VERBOSE = 0x10; |
| 1371 | |
| 1372 | private void setState(int flags) { |
| 1373 | if (sVerbose) Log.v(TAG, "setState(" + flags + ")"); |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1374 | synchronized (mLock) { |
Felipe Leme | 51e29da | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1375 | mEnabled = (flags & SET_STATE_FLAG_ENABLED) != 0; |
| 1376 | if (!mEnabled || (flags & SET_STATE_FLAG_RESET_SESSION) != 0) { |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1377 | // Reset the session state |
| 1378 | resetSessionLocked(); |
| 1379 | } |
Felipe Leme | 51e29da | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1380 | if ((flags & SET_STATE_FLAG_RESET_CLIENT) != 0) { |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1381 | // Reset connection to system |
| 1382 | mServiceClient = null; |
Koji Fukui | ccec6a6 | 2017-10-18 17:48:40 +0900 | [diff] [blame] | 1383 | if (mServiceClientCleaner != null) { |
| 1384 | mServiceClientCleaner.clean(); |
| 1385 | mServiceClientCleaner = null; |
| 1386 | } |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1387 | } |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1388 | } |
Felipe Leme | 51e29da | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1389 | sDebug = (flags & SET_STATE_FLAG_DEBUG) != 0; |
| 1390 | sVerbose = (flags & SET_STATE_FLAG_VERBOSE) != 0; |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1391 | } |
| 1392 | |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1393 | /** |
| 1394 | * Sets a view as autofilled if the current value is the {code targetValue}. |
| 1395 | * |
| 1396 | * @param view The view that is to be autofilled |
| 1397 | * @param targetValue The value we want to fill into view |
| 1398 | */ |
| 1399 | private void setAutofilledIfValuesIs(@NonNull View view, @Nullable AutofillValue targetValue) { |
| 1400 | AutofillValue currentValue = view.getAutofillValue(); |
| 1401 | if (Objects.equals(currentValue, targetValue)) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1402 | synchronized (mLock) { |
| 1403 | if (mLastAutofilledData == null) { |
| 1404 | mLastAutofilledData = new ParcelableMap(1); |
| 1405 | } |
| 1406 | mLastAutofilledData.put(getAutofillId(view), targetValue); |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1407 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1408 | view.setAutofilled(true); |
| 1409 | } |
| 1410 | } |
| 1411 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1412 | private void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1413 | synchronized (mLock) { |
| 1414 | if (sessionId != mSessionId) { |
| 1415 | return; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1416 | } |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1417 | |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1418 | final AutofillClient client = getClient(); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1419 | if (client == null) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1420 | return; |
| 1421 | } |
| 1422 | |
| 1423 | final int itemCount = ids.size(); |
| 1424 | int numApplied = 0; |
| 1425 | ArrayMap<View, SparseArray<AutofillValue>> virtualValues = null; |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1426 | final View[] views = client.findViewsByAutofillIdTraversal(getViewIds(ids)); |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1427 | |
| 1428 | for (int i = 0; i < itemCount; i++) { |
| 1429 | final AutofillId id = ids.get(i); |
| 1430 | final AutofillValue value = values.get(i); |
| 1431 | final int viewId = id.getViewId(); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1432 | final View view = views[i]; |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1433 | if (view == null) { |
| 1434 | Log.w(TAG, "autofill(): no View with id " + viewId); |
| 1435 | continue; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1436 | } |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1437 | if (id.isVirtual()) { |
| 1438 | if (virtualValues == null) { |
| 1439 | // Most likely there will be just one view with virtual children. |
| 1440 | virtualValues = new ArrayMap<>(1); |
| 1441 | } |
| 1442 | SparseArray<AutofillValue> valuesByParent = virtualValues.get(view); |
| 1443 | if (valuesByParent == null) { |
| 1444 | // We don't know the size yet, but usually it will be just a few fields... |
| 1445 | valuesByParent = new SparseArray<>(5); |
| 1446 | virtualValues.put(view, valuesByParent); |
| 1447 | } |
| 1448 | valuesByParent.put(id.getVirtualChildId(), value); |
| 1449 | } else { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1450 | // Mark the view as to be autofilled with 'value' |
| 1451 | if (mLastAutofilledData == null) { |
| 1452 | mLastAutofilledData = new ParcelableMap(itemCount - i); |
| 1453 | } |
| 1454 | mLastAutofilledData.put(id, value); |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1455 | |
| 1456 | view.autofill(value); |
| 1457 | |
| 1458 | // Set as autofilled if the values match now, e.g. when the value was updated |
| 1459 | // synchronously. |
| 1460 | // If autofill happens async, the view is set to autofilled in |
| 1461 | // notifyValueChanged. |
| 1462 | setAutofilledIfValuesIs(view, value); |
| 1463 | |
| 1464 | numApplied++; |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1465 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1466 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1467 | |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1468 | if (virtualValues != null) { |
| 1469 | for (int i = 0; i < virtualValues.size(); i++) { |
| 1470 | final View parent = virtualValues.keyAt(i); |
| 1471 | final SparseArray<AutofillValue> childrenValues = virtualValues.valueAt(i); |
| 1472 | parent.autofill(childrenValues); |
| 1473 | numApplied += childrenValues.size(); |
| 1474 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1475 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1476 | |
Felipe Leme | b22d635 | 2017-09-08 20:03:53 -0700 | [diff] [blame] | 1477 | final LogMaker log = new LogMaker(MetricsEvent.AUTOFILL_DATASET_APPLIED) |
| 1478 | .setPackageName(mContext.getPackageName()) |
| 1479 | .addTaggedData(MetricsEvent.FIELD_AUTOFILL_NUM_VALUES, itemCount) |
| 1480 | .addTaggedData(MetricsEvent.FIELD_AUTOFILL_NUM_VIEWS_FILLED, numApplied); |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1481 | mMetricsLogger.write(log); |
| 1482 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1485 | /** |
| 1486 | * Set the tracked views. |
| 1487 | * |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 1488 | * @param trackedIds The views to be tracked. |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1489 | * @param saveOnAllViewsInvisible Finish the session once all tracked views are invisible. |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 1490 | * @param saveOnFinish Finish the session once the activity is finished. |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1491 | * @param fillableIds Views that might anchor FillUI. |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 1492 | * @param saveTriggerId View that when clicked triggers commit(). |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1493 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1494 | private void setTrackedViews(int sessionId, @Nullable AutofillId[] trackedIds, |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 1495 | boolean saveOnAllViewsInvisible, boolean saveOnFinish, |
| 1496 | @Nullable AutofillId[] fillableIds, @Nullable AutofillId saveTriggerId) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1497 | synchronized (mLock) { |
| 1498 | if (mEnabled && mSessionId == sessionId) { |
| 1499 | if (saveOnAllViewsInvisible) { |
| 1500 | mTrackedViews = new TrackedViews(trackedIds); |
| 1501 | } else { |
| 1502 | mTrackedViews = null; |
| 1503 | } |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 1504 | mSaveOnFinish = saveOnFinish; |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1505 | if (fillableIds != null) { |
| 1506 | if (mFillableIds == null) { |
| 1507 | mFillableIds = new ArraySet<>(fillableIds.length); |
| 1508 | } |
| 1509 | for (AutofillId id : fillableIds) { |
| 1510 | mFillableIds.add(id); |
| 1511 | } |
| 1512 | if (sVerbose) { |
| 1513 | Log.v(TAG, "setTrackedViews(): fillableIds=" + fillableIds |
| 1514 | + ", mFillableIds" + mFillableIds); |
| 1515 | } |
| 1516 | } |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 1517 | |
| 1518 | if (mSaveTriggerId != null && !mSaveTriggerId.equals(saveTriggerId)) { |
| 1519 | // Turn off trigger on previous view id. |
| 1520 | setNotifyOnClickLocked(mSaveTriggerId, false); |
| 1521 | } |
| 1522 | |
| 1523 | if (saveTriggerId != null && !saveTriggerId.equals(mSaveTriggerId)) { |
| 1524 | // Turn on trigger on new view id. |
| 1525 | mSaveTriggerId = saveTriggerId; |
| 1526 | setNotifyOnClickLocked(mSaveTriggerId, true); |
| 1527 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1528 | } |
| 1529 | } |
| 1530 | } |
| 1531 | |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 1532 | private void setNotifyOnClickLocked(@NonNull AutofillId id, boolean notify) { |
| 1533 | final View view = findView(id); |
| 1534 | if (view == null) { |
| 1535 | Log.w(TAG, "setNotifyOnClick(): invalid id: " + id); |
| 1536 | return; |
| 1537 | } |
| 1538 | view.setNotifyAutofillManagerOnClick(notify); |
| 1539 | } |
| 1540 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1541 | private void setSaveUiState(int sessionId, boolean shown) { |
| 1542 | if (sDebug) Log.d(TAG, "setSaveUiState(" + sessionId + "): " + shown); |
| 1543 | synchronized (mLock) { |
| 1544 | if (mSessionId != NO_SESSION) { |
| 1545 | // Race condition: app triggered a new session after the previous session was |
| 1546 | // finished but before server called setSaveUiState() - need to cancel the new |
| 1547 | // session to avoid further inconsistent behavior. |
| 1548 | Log.w(TAG, "setSaveUiState(" + sessionId + ", " + shown |
| 1549 | + ") called on existing session " + mSessionId + "; cancelling it"); |
| 1550 | cancelSessionLocked(); |
| 1551 | } |
| 1552 | if (shown) { |
| 1553 | mSessionId = sessionId; |
| 1554 | mState = STATE_SHOWING_SAVE_UI; |
| 1555 | } else { |
| 1556 | mSessionId = NO_SESSION; |
| 1557 | mState = STATE_UNKNOWN; |
| 1558 | } |
| 1559 | } |
| 1560 | } |
| 1561 | |
Felipe Leme | 650f7ab | 2017-09-19 13:08:24 -0700 | [diff] [blame] | 1562 | /** |
| 1563 | * Marks the state of the session as finished. |
| 1564 | * |
| 1565 | * @param newState {@link #STATE_FINISHED} (because the autofill service returned a {@code null} |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1566 | * FillResponse), {@link #STATE_UNKNOWN} (because the session was removed), or |
| 1567 | * {@link #STATE_DISABLED_BY_SERVICE} (because the autofill service disabled further autofill |
| 1568 | * requests for the activity). |
Felipe Leme | 650f7ab | 2017-09-19 13:08:24 -0700 | [diff] [blame] | 1569 | */ |
| 1570 | private void setSessionFinished(int newState) { |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1571 | synchronized (mLock) { |
Felipe Leme | 650f7ab | 2017-09-19 13:08:24 -0700 | [diff] [blame] | 1572 | if (sVerbose) Log.v(TAG, "setSessionFinished(): from " + mState + " to " + newState); |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1573 | resetSessionLocked(); |
Felipe Leme | 650f7ab | 2017-09-19 13:08:24 -0700 | [diff] [blame] | 1574 | mState = newState; |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1575 | } |
| 1576 | } |
| 1577 | |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1578 | private void requestHideFillUi(AutofillId id) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1579 | final View anchor = findView(id); |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1580 | if (sVerbose) Log.v(TAG, "requestHideFillUi(" + id + "): anchor = " + anchor); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1581 | if (anchor == null) { |
| 1582 | return; |
| 1583 | } |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1584 | requestHideFillUi(id, anchor); |
| 1585 | } |
| 1586 | |
| 1587 | private void requestHideFillUi(AutofillId id, View anchor) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1588 | |
| 1589 | AutofillCallback callback = null; |
| 1590 | synchronized (mLock) { |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1591 | // We do not check the session id for two reasons: |
| 1592 | // 1. If local and remote session id are off sync the UI would be stuck shown |
| 1593 | // 2. There is a race between the user state being destroyed due the fill |
| 1594 | // service being uninstalled and the UI being dismissed. |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1595 | AutofillClient client = getClient(); |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1596 | if (client != null) { |
| 1597 | if (client.autofillCallbackRequestHideFillUi() && mCallback != null) { |
| 1598 | callback = mCallback; |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1599 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | if (callback != null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1604 | if (id.isVirtual()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1605 | callback.onAutofillEvent(anchor, id.getVirtualChildId(), |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1606 | AutofillCallback.EVENT_INPUT_HIDDEN); |
| 1607 | } else { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1608 | callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_HIDDEN); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1609 | } |
| 1610 | } |
| 1611 | } |
| 1612 | |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1613 | private void notifyNoFillUi(int sessionId, AutofillId id, int sessionFinishedState) { |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1614 | if (sVerbose) { |
| 1615 | Log.v(TAG, "notifyNoFillUi(): sessionId=" + sessionId + ", autofillId=" + id |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1616 | + ", sessionFinishedState=" + sessionFinishedState); |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1617 | } |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1618 | final View anchor = findView(id); |
| 1619 | if (anchor == null) { |
| 1620 | return; |
| 1621 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1622 | |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1623 | AutofillCallback callback = null; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1624 | synchronized (mLock) { |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1625 | if (mSessionId == sessionId && getClient() != null) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1626 | callback = mCallback; |
| 1627 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | if (callback != null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1631 | if (id.isVirtual()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1632 | callback.onAutofillEvent(anchor, id.getVirtualChildId(), |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1633 | AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
| 1634 | } else { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1635 | callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1636 | } |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1637 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1638 | |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1639 | if (sessionFinishedState != 0) { |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1640 | // Callback call was "hijacked" to also update the session state. |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1641 | setSessionFinished(sessionFinishedState); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1642 | } |
| 1643 | } |
| 1644 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1645 | /** |
| 1646 | * Get an array of viewIds from a List of {@link AutofillId}. |
| 1647 | * |
| 1648 | * @param autofillIds The autofill ids to convert |
| 1649 | * |
| 1650 | * @return The array of viewIds. |
| 1651 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1652 | // TODO: move to Helper as static method |
| 1653 | @NonNull private int[] getViewIds(@NonNull AutofillId[] autofillIds) { |
| 1654 | final int numIds = autofillIds.length; |
| 1655 | final int[] viewIds = new int[numIds]; |
| 1656 | for (int i = 0; i < numIds; i++) { |
| 1657 | viewIds[i] = autofillIds[i].getViewId(); |
| 1658 | } |
| 1659 | |
| 1660 | return viewIds; |
| 1661 | } |
| 1662 | |
| 1663 | // TODO: move to Helper as static method |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1664 | @NonNull private int[] getViewIds(@NonNull List<AutofillId> autofillIds) { |
| 1665 | final int numIds = autofillIds.size(); |
| 1666 | final int[] viewIds = new int[numIds]; |
| 1667 | for (int i = 0; i < numIds; i++) { |
| 1668 | viewIds[i] = autofillIds.get(i).getViewId(); |
| 1669 | } |
| 1670 | |
| 1671 | return viewIds; |
| 1672 | } |
| 1673 | |
| 1674 | /** |
| 1675 | * Find a single view by its id. |
| 1676 | * |
| 1677 | * @param autofillId The autofill id of the view |
| 1678 | * |
| 1679 | * @return The view or {@code null} if view was not found |
| 1680 | */ |
| 1681 | private View findView(@NonNull AutofillId autofillId) { |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1682 | final AutofillClient client = getClient(); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1683 | |
| 1684 | if (client == null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1685 | return null; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1686 | } |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1687 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1688 | return client.findViewByAutofillIdTraversal(autofillId.getViewId()); |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1689 | } |
| 1690 | |
Felipe Leme | bb81092 | 2017-04-25 15:54:06 -0700 | [diff] [blame] | 1691 | /** @hide */ |
| 1692 | public boolean hasAutofillFeature() { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 1693 | return mService != null; |
| 1694 | } |
| 1695 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1696 | /** @hide */ |
| 1697 | public void onPendingSaveUi(int operation, IBinder token) { |
| 1698 | if (sVerbose) Log.v(TAG, "onPendingSaveUi(" + operation + "): " + token); |
| 1699 | |
| 1700 | synchronized (mLock) { |
| 1701 | try { |
| 1702 | mService.onPendingSaveUi(operation, token); |
| 1703 | } catch (RemoteException e) { |
| 1704 | e.rethrowFromSystemServer(); |
| 1705 | } |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | /** @hide */ |
| 1710 | public void dump(String outerPrefix, PrintWriter pw) { |
| 1711 | pw.print(outerPrefix); pw.println("AutofillManager:"); |
| 1712 | final String pfx = outerPrefix + " "; |
| 1713 | pw.print(pfx); pw.print("sessionId: "); pw.println(mSessionId); |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1714 | pw.print(pfx); pw.print("state: "); pw.println(getStateAsStringLocked()); |
Felipe Leme | 686128e | 2017-10-17 14:02:20 -0700 | [diff] [blame] | 1715 | pw.print(pfx); pw.print("context: "); pw.println(mContext); |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1716 | pw.print(pfx); pw.print("client: "); pw.println(getClient()); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1717 | pw.print(pfx); pw.print("enabled: "); pw.println(mEnabled); |
| 1718 | pw.print(pfx); pw.print("hasService: "); pw.println(mService != null); |
| 1719 | pw.print(pfx); pw.print("hasCallback: "); pw.println(mCallback != null); |
| 1720 | pw.print(pfx); pw.print("last autofilled data: "); pw.println(mLastAutofilledData); |
| 1721 | pw.print(pfx); pw.print("tracked views: "); |
| 1722 | if (mTrackedViews == null) { |
| 1723 | pw.println("null"); |
| 1724 | } else { |
| 1725 | final String pfx2 = pfx + " "; |
| 1726 | pw.println(); |
| 1727 | pw.print(pfx2); pw.print("visible:"); pw.println(mTrackedViews.mVisibleTrackedIds); |
| 1728 | pw.print(pfx2); pw.print("invisible:"); pw.println(mTrackedViews.mInvisibleTrackedIds); |
| 1729 | } |
| 1730 | pw.print(pfx); pw.print("fillable ids: "); pw.println(mFillableIds); |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 1731 | pw.print(pfx); pw.print("save trigger id: "); pw.println(mSaveTriggerId); |
| 1732 | pw.print(pfx); pw.print("save on finish(): "); pw.println(mSaveOnFinish); |
Felipe Leme | 51e29da | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1733 | pw.print(pfx); pw.print("debug: "); pw.print(sDebug); |
| 1734 | pw.print(" verbose: "); pw.println(sVerbose); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1735 | } |
| 1736 | |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1737 | private String getStateAsStringLocked() { |
| 1738 | switch (mState) { |
| 1739 | case STATE_UNKNOWN: |
| 1740 | return "STATE_UNKNOWN"; |
| 1741 | case STATE_ACTIVE: |
| 1742 | return "STATE_ACTIVE"; |
| 1743 | case STATE_FINISHED: |
| 1744 | return "STATE_FINISHED"; |
| 1745 | case STATE_SHOWING_SAVE_UI: |
| 1746 | return "STATE_SHOWING_SAVE_UI"; |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1747 | case STATE_DISABLED_BY_SERVICE: |
| 1748 | return "STATE_DISABLED_BY_SERVICE"; |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1749 | default: |
| 1750 | return "INVALID:" + mState; |
| 1751 | } |
| 1752 | } |
| 1753 | |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 1754 | private boolean isActiveLocked() { |
| 1755 | return mState == STATE_ACTIVE; |
| 1756 | } |
| 1757 | |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 1758 | private boolean isDisabledByService() { |
| 1759 | return mState == STATE_DISABLED_BY_SERVICE; |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1762 | private void post(Runnable runnable) { |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1763 | final AutofillClient client = getClient(); |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1764 | if (client == null) { |
| 1765 | if (sVerbose) Log.v(TAG, "ignoring post() because client is null"); |
| 1766 | return; |
| 1767 | } |
| 1768 | client.runOnUiThread(runnable); |
| 1769 | } |
| 1770 | |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1771 | /** |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1772 | * View tracking information. Once all tracked views become invisible the session is finished. |
| 1773 | */ |
| 1774 | private class TrackedViews { |
| 1775 | /** Visible tracked views */ |
| 1776 | @Nullable private ArraySet<AutofillId> mVisibleTrackedIds; |
| 1777 | |
| 1778 | /** Invisible tracked views */ |
| 1779 | @Nullable private ArraySet<AutofillId> mInvisibleTrackedIds; |
| 1780 | |
| 1781 | /** |
| 1782 | * Check if set is null or value is in set. |
| 1783 | * |
| 1784 | * @param set The set or null (== empty set) |
| 1785 | * @param value The value that might be in the set |
| 1786 | * |
| 1787 | * @return {@code true} iff set is not empty and value is in set |
| 1788 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1789 | // TODO: move to Helper as static method |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1790 | private <T> boolean isInSet(@Nullable ArraySet<T> set, T value) { |
| 1791 | return set != null && set.contains(value); |
| 1792 | } |
| 1793 | |
| 1794 | /** |
| 1795 | * Add a value to a set. If set is null, create a new set. |
| 1796 | * |
| 1797 | * @param set The set or null (== empty set) |
| 1798 | * @param valueToAdd The value to add |
| 1799 | * |
| 1800 | * @return The set including the new value. If set was {@code null}, a set containing only |
| 1801 | * the new value. |
| 1802 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1803 | // TODO: move to Helper as static method |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1804 | @NonNull |
| 1805 | private <T> ArraySet<T> addToSet(@Nullable ArraySet<T> set, T valueToAdd) { |
| 1806 | if (set == null) { |
| 1807 | set = new ArraySet<>(1); |
| 1808 | } |
| 1809 | |
| 1810 | set.add(valueToAdd); |
| 1811 | |
| 1812 | return set; |
| 1813 | } |
| 1814 | |
| 1815 | /** |
| 1816 | * Remove a value from a set. |
| 1817 | * |
| 1818 | * @param set The set or null (== empty set) |
| 1819 | * @param valueToRemove The value to remove |
| 1820 | * |
| 1821 | * @return The set without the removed value. {@code null} if set was null, or is empty |
| 1822 | * after removal. |
| 1823 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1824 | // TODO: move to Helper as static method |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1825 | @Nullable |
| 1826 | private <T> ArraySet<T> removeFromSet(@Nullable ArraySet<T> set, T valueToRemove) { |
| 1827 | if (set == null) { |
| 1828 | return null; |
| 1829 | } |
| 1830 | |
| 1831 | set.remove(valueToRemove); |
| 1832 | |
| 1833 | if (set.isEmpty()) { |
| 1834 | return null; |
| 1835 | } |
| 1836 | |
| 1837 | return set; |
| 1838 | } |
| 1839 | |
| 1840 | /** |
| 1841 | * Set the tracked views. |
| 1842 | * |
| 1843 | * @param trackedIds The views to be tracked |
| 1844 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1845 | TrackedViews(@Nullable AutofillId[] trackedIds) { |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1846 | final AutofillClient client = getClient(); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1847 | if (trackedIds != null && client != null) { |
| 1848 | final boolean[] isVisible; |
| 1849 | |
| 1850 | if (client.isVisibleForAutofill()) { |
| 1851 | isVisible = client.getViewVisibility(getViewIds(trackedIds)); |
| 1852 | } else { |
| 1853 | // All false |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1854 | isVisible = new boolean[trackedIds.length]; |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1857 | final int numIds = trackedIds.length; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1858 | for (int i = 0; i < numIds; i++) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1859 | final AutofillId id = trackedIds[i]; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1860 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1861 | if (isVisible[i]) { |
Philip P. Moltmann | e0e2871 | 2017-04-20 15:19:06 -0700 | [diff] [blame] | 1862 | mVisibleTrackedIds = addToSet(mVisibleTrackedIds, id); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1863 | } else { |
| 1864 | mInvisibleTrackedIds = addToSet(mInvisibleTrackedIds, id); |
| 1865 | } |
| 1866 | } |
| 1867 | } |
| 1868 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1869 | if (sVerbose) { |
| 1870 | Log.v(TAG, "TrackedViews(trackedIds=" + trackedIds + "): " |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1871 | + " mVisibleTrackedIds=" + mVisibleTrackedIds |
| 1872 | + " mInvisibleTrackedIds=" + mInvisibleTrackedIds); |
| 1873 | } |
| 1874 | |
| 1875 | if (mVisibleTrackedIds == null) { |
| 1876 | finishSessionLocked(); |
| 1877 | } |
| 1878 | } |
| 1879 | |
| 1880 | /** |
| 1881 | * Called when a {@link View view's} visibility changes. |
| 1882 | * |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame] | 1883 | * @param id the id of the view/virtual view whose visibility changed. |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1884 | * @param isVisible visible if the view is visible in the view hierarchy. |
| 1885 | */ |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame] | 1886 | void notifyViewVisibilityChanged(@NonNull AutofillId id, boolean isVisible) { |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1887 | AutofillClient client = getClient(); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1888 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1889 | if (sDebug) { |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame] | 1890 | Log.d(TAG, "notifyViewVisibilityChanged(): id=" + id + " isVisible=" |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1891 | + isVisible); |
| 1892 | } |
| 1893 | |
| 1894 | if (client != null && client.isVisibleForAutofill()) { |
| 1895 | if (isVisible) { |
| 1896 | if (isInSet(mInvisibleTrackedIds, id)) { |
| 1897 | mInvisibleTrackedIds = removeFromSet(mInvisibleTrackedIds, id); |
| 1898 | mVisibleTrackedIds = addToSet(mVisibleTrackedIds, id); |
| 1899 | } |
| 1900 | } else { |
| 1901 | if (isInSet(mVisibleTrackedIds, id)) { |
| 1902 | mVisibleTrackedIds = removeFromSet(mVisibleTrackedIds, id); |
| 1903 | mInvisibleTrackedIds = addToSet(mInvisibleTrackedIds, id); |
| 1904 | } |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | if (mVisibleTrackedIds == null) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1909 | if (sVerbose) { |
| 1910 | Log.v(TAG, "No more visible ids. Invisibile = " + mInvisibleTrackedIds); |
| 1911 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1912 | finishSessionLocked(); |
| 1913 | } |
| 1914 | } |
| 1915 | |
| 1916 | /** |
| 1917 | * Called once the client becomes visible. |
| 1918 | * |
| 1919 | * @see AutofillClient#isVisibleForAutofill() |
| 1920 | */ |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1921 | void onVisibleForAutofillLocked() { |
| 1922 | // The visibility of the views might have changed while the client was not be visible, |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1923 | // hence update the visibility state for all views. |
Felipe Leme | 637e05e | 2017-12-06 12:09:37 -0800 | [diff] [blame] | 1924 | AutofillClient client = getClient(); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1925 | ArraySet<AutofillId> updatedVisibleTrackedIds = null; |
| 1926 | ArraySet<AutofillId> updatedInvisibleTrackedIds = null; |
| 1927 | if (client != null) { |
| 1928 | if (mInvisibleTrackedIds != null) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1929 | final ArrayList<AutofillId> orderedInvisibleIds = |
| 1930 | new ArrayList<>(mInvisibleTrackedIds); |
| 1931 | final boolean[] isVisible = client.getViewVisibility( |
| 1932 | getViewIds(orderedInvisibleIds)); |
| 1933 | |
| 1934 | final int numInvisibleTrackedIds = orderedInvisibleIds.size(); |
| 1935 | for (int i = 0; i < numInvisibleTrackedIds; i++) { |
| 1936 | final AutofillId id = orderedInvisibleIds.get(i); |
| 1937 | if (isVisible[i]) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1938 | updatedVisibleTrackedIds = addToSet(updatedVisibleTrackedIds, id); |
| 1939 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1940 | if (sDebug) { |
| 1941 | Log.d(TAG, "onVisibleForAutofill() " + id + " became visible"); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1942 | } |
| 1943 | } else { |
| 1944 | updatedInvisibleTrackedIds = addToSet(updatedInvisibleTrackedIds, id); |
| 1945 | } |
| 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | if (mVisibleTrackedIds != null) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1950 | final ArrayList<AutofillId> orderedVisibleIds = |
| 1951 | new ArrayList<>(mVisibleTrackedIds); |
| 1952 | final boolean[] isVisible = client.getViewVisibility( |
| 1953 | getViewIds(orderedVisibleIds)); |
| 1954 | |
| 1955 | final int numVisibleTrackedIds = orderedVisibleIds.size(); |
| 1956 | for (int i = 0; i < numVisibleTrackedIds; i++) { |
| 1957 | final AutofillId id = orderedVisibleIds.get(i); |
| 1958 | |
| 1959 | if (isVisible[i]) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1960 | updatedVisibleTrackedIds = addToSet(updatedVisibleTrackedIds, id); |
| 1961 | } else { |
| 1962 | updatedInvisibleTrackedIds = addToSet(updatedInvisibleTrackedIds, id); |
| 1963 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1964 | if (sDebug) { |
| 1965 | Log.d(TAG, "onVisibleForAutofill() " + id + " became invisible"); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1966 | } |
| 1967 | } |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | mInvisibleTrackedIds = updatedInvisibleTrackedIds; |
| 1972 | mVisibleTrackedIds = updatedVisibleTrackedIds; |
| 1973 | } |
| 1974 | |
| 1975 | if (mVisibleTrackedIds == null) { |
| 1976 | finishSessionLocked(); |
| 1977 | } |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | /** |
Felipe Leme | 744976e | 2017-07-31 11:34:14 -0700 | [diff] [blame] | 1982 | * Callback for autofill related events. |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1983 | * |
| 1984 | * <p>Typically used for applications that display their own "auto-complete" views, so they can |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 1985 | * enable / disable such views when the autofill UI is shown / hidden. |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1986 | */ |
| 1987 | public abstract static class AutofillCallback { |
| 1988 | |
| 1989 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame^] | 1990 | @IntDef(prefix = { "EVENT_INPUT_" }, value = { |
| 1991 | EVENT_INPUT_SHOWN, |
| 1992 | EVENT_INPUT_HIDDEN, |
| 1993 | EVENT_INPUT_UNAVAILABLE |
| 1994 | }) |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1995 | @Retention(RetentionPolicy.SOURCE) |
| 1996 | public @interface AutofillEventType {} |
| 1997 | |
| 1998 | /** |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 1999 | * The autofill input UI associated with the view was shown. |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 2000 | * |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 2001 | * <p>If the view provides its own auto-complete UI and its currently shown, it |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 2002 | * should be hidden upon receiving this event. |
| 2003 | */ |
| 2004 | public static final int EVENT_INPUT_SHOWN = 1; |
| 2005 | |
| 2006 | /** |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 2007 | * The autofill input UI associated with the view was hidden. |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 2008 | * |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 2009 | * <p>If the view provides its own auto-complete UI that was hidden upon a |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 2010 | * {@link #EVENT_INPUT_SHOWN} event, it could be shown again now. |
| 2011 | */ |
| 2012 | public static final int EVENT_INPUT_HIDDEN = 2; |
| 2013 | |
| 2014 | /** |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 2015 | * The autofill input UI associated with the view isn't shown because |
Felipe Leme | 24aae15 | 2017-03-15 12:33:01 -0700 | [diff] [blame] | 2016 | * autofill is not available. |
| 2017 | * |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 2018 | * <p>If the view provides its own auto-complete UI but was not displaying it |
Felipe Leme | 24aae15 | 2017-03-15 12:33:01 -0700 | [diff] [blame] | 2019 | * to avoid flickering, it could shown it upon receiving this event. |
| 2020 | */ |
| 2021 | public static final int EVENT_INPUT_UNAVAILABLE = 3; |
| 2022 | |
| 2023 | /** |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 2024 | * Called after a change in the autofill state associated with a view. |
| 2025 | * |
| 2026 | * @param view view associated with the change. |
| 2027 | * |
| 2028 | * @param event currently either {@link #EVENT_INPUT_SHOWN} or {@link #EVENT_INPUT_HIDDEN}. |
| 2029 | */ |
Felipe Leme | 81f01d9 | 2017-03-16 17:13:25 -0700 | [diff] [blame] | 2030 | public void onAutofillEvent(@NonNull View view, @AutofillEventType int event) { |
| 2031 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 2032 | |
| 2033 | /** |
| 2034 | * Called after a change in the autofill state associated with a virtual view. |
| 2035 | * |
| 2036 | * @param view parent view associated with the change. |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 2037 | * @param virtualId id identifying the virtual child inside the parent view. |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 2038 | * |
| 2039 | * @param event currently either {@link #EVENT_INPUT_SHOWN} or {@link #EVENT_INPUT_HIDDEN}. |
| 2040 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 2041 | public void onAutofillEvent(@NonNull View view, int virtualId, |
| 2042 | @AutofillEventType int event) { |
Felipe Leme | 81f01d9 | 2017-03-16 17:13:25 -0700 | [diff] [blame] | 2043 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 2044 | } |
| 2045 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 2046 | private static final class AutofillManagerClient extends IAutoFillManagerClient.Stub { |
| 2047 | private final WeakReference<AutofillManager> mAfm; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 2048 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 2049 | AutofillManagerClient(AutofillManager autofillManager) { |
| 2050 | mAfm = new WeakReference<>(autofillManager); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | @Override |
Felipe Leme | 51e29da | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 2054 | public void setState(int flags) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 2055 | final AutofillManager afm = mAfm.get(); |
| 2056 | if (afm != null) { |
Felipe Leme | 51e29da | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 2057 | afm.post(() -> afm.setState(flags)); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | @Override |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 2062 | public void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 2063 | final AutofillManager afm = mAfm.get(); |
| 2064 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 2065 | afm.post(() -> afm.autofill(sessionId, ids, values)); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 2066 | } |
| 2067 | } |
| 2068 | |
| 2069 | @Override |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 2070 | public void authenticate(int sessionId, int authenticationId, IntentSender intent, |
| 2071 | Intent fillInIntent) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 2072 | final AutofillManager afm = mAfm.get(); |
| 2073 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 2074 | afm.post(() -> afm.authenticate(sessionId, authenticationId, intent, fillInIntent)); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 2075 | } |
| 2076 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 2077 | |
| 2078 | @Override |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 2079 | public void requestShowFillUi(int sessionId, AutofillId id, int width, int height, |
| 2080 | Rect anchorBounds, IAutofillWindowPresenter presenter) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 2081 | final AutofillManager afm = mAfm.get(); |
| 2082 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 2083 | afm.post(() -> afm.requestShowFillUi(sessionId, id, width, height, anchorBounds, |
| 2084 | presenter)); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | @Override |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 2089 | public void requestHideFillUi(int sessionId, AutofillId id) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 2090 | final AutofillManager afm = mAfm.get(); |
| 2091 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 2092 | afm.post(() -> afm.requestHideFillUi(id)); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | @Override |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 2097 | public void notifyNoFillUi(int sessionId, AutofillId id, int sessionFinishedState) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 2098 | final AutofillManager afm = mAfm.get(); |
| 2099 | if (afm != null) { |
Felipe Leme | 17292d1 | 2017-10-24 14:03:10 -0700 | [diff] [blame] | 2100 | afm.post(() -> afm.notifyNoFillUi(sessionId, id, sessionFinishedState)); |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 2101 | } |
| 2102 | } |
Svet Ganov | c3d1c85 | 2017-04-12 22:34:28 -0700 | [diff] [blame] | 2103 | |
| 2104 | @Override |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 2105 | public void startIntentSender(IntentSender intentSender, Intent intent) { |
Svet Ganov | c3d1c85 | 2017-04-12 22:34:28 -0700 | [diff] [blame] | 2106 | final AutofillManager afm = mAfm.get(); |
| 2107 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 2108 | afm.post(() -> { |
Svet Ganov | c3d1c85 | 2017-04-12 22:34:28 -0700 | [diff] [blame] | 2109 | try { |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 2110 | afm.mContext.startIntentSender(intentSender, intent, 0, 0, 0); |
Svet Ganov | c3d1c85 | 2017-04-12 22:34:28 -0700 | [diff] [blame] | 2111 | } catch (IntentSender.SendIntentException e) { |
| 2112 | Log.e(TAG, "startIntentSender() failed for intent:" + intentSender, e); |
| 2113 | } |
| 2114 | }); |
| 2115 | } |
| 2116 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 2117 | |
| 2118 | @Override |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 2119 | public void setTrackedViews(int sessionId, AutofillId[] ids, |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 2120 | boolean saveOnAllViewsInvisible, boolean saveOnFinish, AutofillId[] fillableIds, |
| 2121 | AutofillId saveTriggerId) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 2122 | final AutofillManager afm = mAfm.get(); |
| 2123 | if (afm != null) { |
Felipe Leme | 2fe3ade | 2017-09-28 15:03:36 -0700 | [diff] [blame] | 2124 | afm.post(() -> afm.setTrackedViews(sessionId, ids, saveOnAllViewsInvisible, |
| 2125 | saveOnFinish, fillableIds, saveTriggerId)); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 2126 | } |
| 2127 | } |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 2128 | |
| 2129 | @Override |
| 2130 | public void setSaveUiState(int sessionId, boolean shown) { |
| 2131 | final AutofillManager afm = mAfm.get(); |
| 2132 | if (afm != null) { |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 2133 | afm.post(() -> afm.setSaveUiState(sessionId, shown)); |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | @Override |
Felipe Leme | 650f7ab | 2017-09-19 13:08:24 -0700 | [diff] [blame] | 2138 | public void setSessionFinished(int newState) { |
Felipe Leme | c7b4529 | 2017-09-19 09:06:20 -0700 | [diff] [blame] | 2139 | final AutofillManager afm = mAfm.get(); |
| 2140 | if (afm != null) { |
Felipe Leme | 650f7ab | 2017-09-19 13:08:24 -0700 | [diff] [blame] | 2141 | afm.post(() -> afm.setSessionFinished(newState)); |
Felipe Leme | c24a56a | 2017-08-03 14:27:57 -0700 | [diff] [blame] | 2142 | } |
| 2143 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 2144 | } |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 2145 | } |