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 | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 27 | import android.content.Context; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 28 | import android.content.Intent; |
| 29 | import android.content.IntentSender; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 30 | import android.graphics.Rect; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 31 | import android.metrics.LogMaker; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 32 | import android.os.Bundle; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 33 | import android.os.Parcelable; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 34 | import android.os.RemoteException; |
Philip P. Moltmann | cc684ed | 2017-04-17 14:18:33 -0700 | [diff] [blame] | 35 | import android.service.autofill.AutofillService; |
| 36 | import android.service.autofill.FillEventHistory; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 37 | import android.util.ArrayMap; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 38 | import android.util.ArraySet; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 39 | import android.util.Log; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 40 | import android.util.SparseArray; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 41 | import android.view.View; |
| 42 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 43 | import com.android.internal.annotations.GuardedBy; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 44 | import com.android.internal.logging.MetricsLogger; |
| 45 | import com.android.internal.logging.nano.MetricsProto; |
| 46 | |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 47 | import java.lang.annotation.Retention; |
| 48 | import java.lang.annotation.RetentionPolicy; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 49 | import java.lang.ref.WeakReference; |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 50 | import java.util.ArrayList; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 51 | import java.util.List; |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 52 | import java.util.Objects; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 53 | |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 54 | /** |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 55 | * App entry point to the Autofill Framework. |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 56 | * |
| 57 | * <p>It is safe to call into this from any thread. |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 58 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 59 | @SystemService(Context.AUTOFILL_MANAGER_SERVICE) |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 60 | public final class AutofillManager { |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 61 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 62 | private static final String TAG = "AutofillManager"; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 63 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 64 | /** |
| 65 | * Intent extra: The assist structure which captures the filled screen. |
Felipe Leme | 7320ca9 | 2017-03-29 15:09:54 -0700 | [diff] [blame] | 66 | * |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 67 | * <p> |
| 68 | * Type: {@link android.app.assist.AssistStructure} |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 69 | */ |
| 70 | public static final String EXTRA_ASSIST_STRUCTURE = |
| 71 | "android.view.autofill.extra.ASSIST_STRUCTURE"; |
| 72 | |
| 73 | /** |
| 74 | * Intent extra: The result of an authentication operation. It is |
| 75 | * either a fully populated {@link android.service.autofill.FillResponse} |
| 76 | * or a fully populated {@link android.service.autofill.Dataset} if |
| 77 | * a response or a dataset is being authenticated respectively. |
| 78 | * |
| 79 | * <p> |
| 80 | * Type: {@link android.service.autofill.FillResponse} or a |
| 81 | * {@link android.service.autofill.Dataset} |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 82 | */ |
| 83 | public static final String EXTRA_AUTHENTICATION_RESULT = |
| 84 | "android.view.autofill.extra.AUTHENTICATION_RESULT"; |
| 85 | |
Felipe Leme | 7320ca9 | 2017-03-29 15:09:54 -0700 | [diff] [blame] | 86 | /** |
| 87 | * Intent extra: The optional extras provided by the |
| 88 | * {@link android.service.autofill.AutofillService}. |
| 89 | * |
| 90 | * <p>For example, when the service responds to a {@link |
| 91 | * android.service.autofill.FillCallback#onSuccess(android.service.autofill.FillResponse)} with |
| 92 | * a {@code FillResponse} that requires authentication, the Intent that launches the |
| 93 | * service authentication will contain the Bundle set by |
Felipe Leme | 49e9696 | 2017-04-20 15:46:18 -0700 | [diff] [blame] | 94 | * {@link android.service.autofill.FillResponse.Builder#setClientState(Bundle)} on this extra. |
Felipe Leme | 7320ca9 | 2017-03-29 15:09:54 -0700 | [diff] [blame] | 95 | * |
| 96 | * <p> |
| 97 | * Type: {@link android.os.Bundle} |
| 98 | */ |
Felipe Leme | 37a440fd | 2017-04-28 10:50:20 -0700 | [diff] [blame] | 99 | public static final String EXTRA_CLIENT_STATE = |
Jeff Sharkey | 000ce80 | 2017-04-29 13:13:27 -0600 | [diff] [blame] | 100 | "android.view.autofill.extra.CLIENT_STATE"; |
Felipe Leme | 7320ca9 | 2017-03-29 15:09:54 -0700 | [diff] [blame] | 101 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 102 | static final String SESSION_ID_TAG = "android:sessionId"; |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 103 | static final String LAST_AUTOFILLED_DATA_TAG = "android:lastAutoFilledData"; |
| 104 | |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 105 | /** @hide */ public static final int ACTION_START_SESSION = 1; |
| 106 | /** @hide */ public static final int ACTION_VIEW_ENTERED = 2; |
| 107 | /** @hide */ public static final int ACTION_VIEW_EXITED = 3; |
| 108 | /** @hide */ public static final int ACTION_VALUE_CHANGED = 4; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 109 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 110 | |
| 111 | /** @hide */ public static final int FLAG_ADD_CLIENT_ENABLED = 0x1; |
| 112 | /** @hide */ public static final int FLAG_ADD_CLIENT_DEBUG = 0x2; |
| 113 | /** @hide */ public static final int FLAG_ADD_CLIENT_VERBOSE = 0x4; |
| 114 | |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 115 | /** Which bits in an authentication id are used for the dataset id */ |
| 116 | private static final int AUTHENTICATION_ID_DATASET_ID_MASK = 0xFFFF; |
| 117 | /** How many bits in an authentication id are used for the dataset id */ |
| 118 | private static final int AUTHENTICATION_ID_DATASET_ID_SHIFT = 16; |
| 119 | /** @hide The index for an undefined data set */ |
| 120 | public static final int AUTHENTICATION_ID_DATASET_ID_UNDEFINED = 0xFFFF; |
| 121 | |
| 122 | /** |
| 123 | * Makes an authentication id from a request id and a dataset id. |
| 124 | * |
| 125 | * @param requestId The request id. |
| 126 | * @param datasetId The dataset id. |
| 127 | * @return The authentication id. |
| 128 | * @hide |
| 129 | */ |
| 130 | public static int makeAuthenticationId(int requestId, int datasetId) { |
| 131 | return (requestId << AUTHENTICATION_ID_DATASET_ID_SHIFT) |
| 132 | | (datasetId & AUTHENTICATION_ID_DATASET_ID_MASK); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Gets the request id from an authentication id. |
| 137 | * |
| 138 | * @param authRequestId The authentication id. |
| 139 | * @return The request id. |
| 140 | * @hide |
| 141 | */ |
| 142 | public static int getRequestIdFromAuthenticationId(int authRequestId) { |
| 143 | return (authRequestId >> AUTHENTICATION_ID_DATASET_ID_SHIFT); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Gets the dataset id from an authentication id. |
| 148 | * |
| 149 | * @param authRequestId The authentication id. |
| 150 | * @return The dataset id. |
| 151 | * @hide |
| 152 | */ |
| 153 | public static int getDatasetIdFromAuthenticationId(int authRequestId) { |
| 154 | return (authRequestId & AUTHENTICATION_ID_DATASET_ID_MASK); |
| 155 | } |
| 156 | |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 157 | private final MetricsLogger mMetricsLogger = new MetricsLogger(); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 158 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 159 | /** |
| 160 | * There is currently no session running. |
| 161 | * {@hide} |
| 162 | */ |
| 163 | public static final int NO_SESSION = Integer.MIN_VALUE; |
| 164 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 165 | private final IAutoFillManager mService; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 166 | |
| 167 | private final Object mLock = new Object(); |
| 168 | |
| 169 | @GuardedBy("mLock") |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 170 | private IAutoFillManagerClient mServiceClient; |
| 171 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 172 | @GuardedBy("mLock") |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 173 | private AutofillCallback mCallback; |
| 174 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 175 | private final Context mContext; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 176 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 177 | @GuardedBy("mLock") |
| 178 | private int mSessionId = NO_SESSION; |
| 179 | |
| 180 | @GuardedBy("mLock") |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 181 | private boolean mEnabled; |
| 182 | |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 183 | /** 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] | 184 | @GuardedBy("mLock") |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 185 | @Nullable private ParcelableMap mLastAutofilledData; |
| 186 | |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 187 | /** If view tracking is enabled, contains the tracking state */ |
| 188 | @GuardedBy("mLock") |
| 189 | @Nullable private TrackedViews mTrackedViews; |
| 190 | |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 191 | /** Views that are only tracked because they are fillable and could be anchoring the UI. */ |
| 192 | @GuardedBy("mLock") |
| 193 | @Nullable private ArraySet<AutofillId> mFillableIds; |
| 194 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 195 | /** @hide */ |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 196 | public interface AutofillClient { |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 197 | /** |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 198 | * Asks the client to start an authentication flow. |
| 199 | * |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 200 | * @param authenticationId A unique id of the authentication operation. |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 201 | * @param intent The authentication intent. |
| 202 | * @param fillInIntent The authentication fill-in intent. |
| 203 | */ |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 204 | void autofillCallbackAuthenticate(int authenticationId, IntentSender intent, |
| 205 | Intent fillInIntent); |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 206 | |
| 207 | /** |
| 208 | * Tells the client this manager has state to be reset. |
| 209 | */ |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 210 | void autofillCallbackResetableStateAvailable(); |
| 211 | |
| 212 | /** |
| 213 | * Request showing the autofill UI. |
| 214 | * |
| 215 | * @param anchor The real view the UI needs to anchor to. |
| 216 | * @param width The width of the fill UI content. |
| 217 | * @param height The height of the fill UI content. |
| 218 | * @param virtualBounds The bounds of the virtual decendant of the anchor. |
| 219 | * @param presenter The presenter that controls the fill UI window. |
| 220 | * @return Whether the UI was shown. |
| 221 | */ |
| 222 | boolean autofillCallbackRequestShowFillUi(@NonNull View anchor, int width, int height, |
| 223 | @Nullable Rect virtualBounds, IAutofillWindowPresenter presenter); |
| 224 | |
| 225 | /** |
| 226 | * Request hiding the autofill UI. |
| 227 | * |
| 228 | * @return Whether the UI was hidden. |
| 229 | */ |
| 230 | boolean autofillCallbackRequestHideFillUi(); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 231 | |
| 232 | /** |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 233 | * Checks if views are currently attached and visible. |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 234 | * |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 235 | * @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] | 236 | */ |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 237 | @NonNull boolean[] getViewVisibility(@NonNull int[] viewId); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 238 | |
| 239 | /** |
| 240 | * Checks is the client is currently visible as understood by autofill. |
| 241 | * |
| 242 | * @return {@code true} if the client is currently visible |
| 243 | */ |
| 244 | boolean isVisibleForAutofill(); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 245 | |
| 246 | /** |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 247 | * Finds views by traversing the hierarchies of the client. |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 248 | * |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 249 | * @param viewIds The autofill ids of the views to find |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 250 | * |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 251 | * @return And array containing the views (empty if no views found). |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 252 | */ |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 253 | @NonNull View[] findViewsByAutofillIdTraversal(@NonNull int[] viewIds); |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 254 | |
| 255 | /** |
| 256 | * Finds a view by traversing the hierarchies of the client. |
| 257 | * |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 258 | * @param viewId The autofill id of the views to find |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 259 | * |
| 260 | * @return The view, or {@code null} if not found |
| 261 | */ |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 262 | @Nullable View findViewByAutofillIdTraversal(int viewId); |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 263 | |
| 264 | /** |
| 265 | * Runs the specified action on the UI thread. |
| 266 | */ |
| 267 | void runOnUiThread(Runnable action); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 268 | } |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 269 | |
| 270 | /** |
| 271 | * @hide |
| 272 | */ |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 273 | public AutofillManager(Context context, IAutoFillManager service) { |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 274 | mContext = context; |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 275 | mService = service; |
| 276 | } |
| 277 | |
| 278 | /** |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 279 | * Restore state after activity lifecycle |
| 280 | * |
| 281 | * @param savedInstanceState The state to be restored |
| 282 | * |
| 283 | * {@hide} |
| 284 | */ |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 285 | public void onCreate(Bundle savedInstanceState) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 286 | if (!hasAutofillFeature()) { |
| 287 | return; |
| 288 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 289 | synchronized (mLock) { |
| 290 | mLastAutofilledData = savedInstanceState.getParcelable(LAST_AUTOFILLED_DATA_TAG); |
| 291 | |
| 292 | if (mSessionId != NO_SESSION) { |
| 293 | Log.w(TAG, "New session was started before onCreate()"); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | mSessionId = savedInstanceState.getInt(SESSION_ID_TAG, NO_SESSION); |
| 298 | |
| 299 | if (mSessionId != NO_SESSION) { |
| 300 | ensureServiceClientAddedIfNeededLocked(); |
| 301 | |
| 302 | final AutofillClient client = getClientLocked(); |
| 303 | if (client != null) { |
| 304 | try { |
| 305 | final boolean sessionWasRestored = mService.restoreSession(mSessionId, |
| 306 | mContext.getActivityToken(), mServiceClient.asBinder()); |
| 307 | |
| 308 | if (!sessionWasRestored) { |
| 309 | Log.w(TAG, "Session " + mSessionId + " could not be restored"); |
| 310 | mSessionId = NO_SESSION; |
| 311 | } else { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 312 | if (sDebug) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 313 | Log.d(TAG, "session " + mSessionId + " was restored"); |
| 314 | } |
| 315 | |
| 316 | client.autofillCallbackResetableStateAvailable(); |
| 317 | } |
| 318 | } catch (RemoteException e) { |
| 319 | Log.e(TAG, "Could not figure out if there was an autofill session", e); |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | /** |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 327 | * Called once the client becomes visible. |
| 328 | * |
| 329 | * @see AutofillClient#isVisibleForAutofill() |
| 330 | * |
| 331 | * {@hide} |
| 332 | */ |
| 333 | public void onVisibleForAutofill() { |
| 334 | synchronized (mLock) { |
| 335 | if (mEnabled && mSessionId != NO_SESSION && mTrackedViews != null) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 336 | mTrackedViews.onVisibleForAutofillLocked(); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | /** |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 342 | * Save state before activity lifecycle |
| 343 | * |
| 344 | * @param outState Place to store the state |
| 345 | * |
| 346 | * {@hide} |
| 347 | */ |
| 348 | public void onSaveInstanceState(Bundle outState) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 349 | if (!hasAutofillFeature()) { |
| 350 | return; |
| 351 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 352 | synchronized (mLock) { |
| 353 | if (mSessionId != NO_SESSION) { |
| 354 | outState.putInt(SESSION_ID_TAG, mSessionId); |
| 355 | } |
| 356 | |
| 357 | if (mLastAutofilledData != null) { |
| 358 | outState.putParcelable(LAST_AUTOFILLED_DATA_TAG, mLastAutofilledData); |
| 359 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Checks whether autofill is enabled for the current user. |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 365 | * |
| 366 | * <p>Typically used to determine whether the option to explicitly request autofill should |
| 367 | * be offered - see {@link #requestAutofill(View)}. |
| 368 | * |
| 369 | * @return whether autofill is enabled for the current user. |
| 370 | */ |
| 371 | public boolean isEnabled() { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 372 | if (!hasAutofillFeature()) { |
| 373 | return false; |
| 374 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 375 | synchronized (mLock) { |
| 376 | ensureServiceClientAddedIfNeededLocked(); |
| 377 | return mEnabled; |
| 378 | } |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /** |
Philip P. Moltmann | cc684ed | 2017-04-17 14:18:33 -0700 | [diff] [blame] | 382 | * Should always be called from {@link AutofillService#getFillEventHistory()}. |
| 383 | * |
| 384 | * @hide |
| 385 | */ |
| 386 | @Nullable public FillEventHistory getFillEventHistory() { |
| 387 | try { |
| 388 | return mService.getFillEventHistory(); |
| 389 | } catch (RemoteException e) { |
| 390 | e.rethrowFromSystemServer(); |
| 391 | return null; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | /** |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 396 | * Explicitly requests a new autofill context. |
| 397 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 398 | * <p>Normally, the autofill context is automatically started if necessary when |
| 399 | * {@link #notifyViewEntered(View)} is called, but this method should be used in the |
| 400 | * cases where it must be explicitly started. For example, when the view offers an AUTOFILL |
| 401 | * option on its contextual overflow menu, and the user selects it. |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 402 | * |
| 403 | * @param view view requesting the new autofill context. |
| 404 | */ |
| 405 | public void requestAutofill(@NonNull View view) { |
Felipe Leme | d114642 | 2017-04-26 10:17:05 -0700 | [diff] [blame] | 406 | notifyViewEntered(view, FLAG_MANUAL_REQUEST); |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | /** |
| 410 | * Explicitly requests a new autofill context for virtual views. |
| 411 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 412 | * <p>Normally, the autofill context is automatically started if necessary when |
| 413 | * {@link #notifyViewEntered(View, int, Rect)} is called, but this method should be used in the |
| 414 | * cases where it must be explicitly started. For example, when the virtual view offers an |
| 415 | * AUTOFILL option on its contextual overflow menu, and the user selects it. |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 416 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 417 | * <p>The virtual view boundaries must be absolute screen coordinates. For example, if the |
| 418 | * parent view uses {@code bounds} to draw the virtual view inside its Canvas, |
| 419 | * the absolute bounds could be calculated by: |
| 420 | * |
| 421 | * <pre class="prettyprint"> |
| 422 | * int offset[] = new int[2]; |
| 423 | * getLocationOnScreen(offset); |
| 424 | * Rect absBounds = new Rect(bounds.left + offset[0], |
| 425 | * bounds.top + offset[1], |
| 426 | * bounds.right + offset[0], bounds.bottom + offset[1]); |
| 427 | * </pre> |
| 428 | * |
| 429 | * @param view the virtual view parent. |
| 430 | * @param virtualId id identifying the virtual child inside the parent view. |
| 431 | * @param absBounds absolute boundaries of the virtual view in the screen. |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 432 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 433 | public void requestAutofill(@NonNull View view, int virtualId, @NonNull Rect absBounds) { |
| 434 | notifyViewEntered(view, virtualId, absBounds, FLAG_MANUAL_REQUEST); |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 437 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 438 | * Called when a {@link View} that supports autofill is entered. |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 439 | * |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 440 | * @param view {@link View} that was entered. |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 441 | */ |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 442 | public void notifyViewEntered(@NonNull View view) { |
Felipe Leme | d114642 | 2017-04-26 10:17:05 -0700 | [diff] [blame] | 443 | notifyViewEntered(view, 0); |
| 444 | } |
| 445 | |
| 446 | private void notifyViewEntered(@NonNull View view, int flags) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 447 | if (!hasAutofillFeature()) { |
| 448 | return; |
| 449 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 450 | AutofillCallback callback = null; |
| 451 | synchronized (mLock) { |
| 452 | ensureServiceClientAddedIfNeededLocked(); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 453 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 454 | if (!mEnabled) { |
| 455 | if (mCallback != null) { |
| 456 | callback = mCallback; |
| 457 | } |
| 458 | } else { |
| 459 | final AutofillId id = getAutofillId(view); |
| 460 | final AutofillValue value = view.getAutofillValue(); |
| 461 | |
| 462 | if (mSessionId == NO_SESSION) { |
| 463 | // Starts new session. |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 464 | startSessionLocked(id, null, value, flags); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 465 | } else { |
| 466 | // Update focus on existing session. |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 467 | updateSessionLocked(id, null, value, ACTION_VIEW_ENTERED, flags); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 468 | } |
Felipe Leme | 24aae15 | 2017-03-15 12:33:01 -0700 | [diff] [blame] | 469 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 470 | } |
| 471 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 472 | if (callback != null) { |
| 473 | mCallback.onAutofillEvent(view, AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 474 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 478 | * Called when a {@link View} that supports autofill is exited. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 479 | * |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 480 | * @param view {@link View} that was exited. |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 481 | */ |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 482 | public void notifyViewExited(@NonNull View view) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 483 | if (!hasAutofillFeature()) { |
| 484 | return; |
| 485 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 486 | synchronized (mLock) { |
| 487 | ensureServiceClientAddedIfNeededLocked(); |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 488 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 489 | if (mEnabled && mSessionId != NO_SESSION) { |
| 490 | final AutofillId id = getAutofillId(view); |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 491 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 492 | // Update focus on existing session. |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 493 | updateSessionLocked(id, null, null, ACTION_VIEW_EXITED, 0); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 494 | } |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
| 498 | /** |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame^] | 499 | * Called when a {@link View view's} visibility changed. |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 500 | * |
| 501 | * @param view {@link View} that was exited. |
| 502 | * @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] | 503 | */ |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame^] | 504 | public void notifyViewVisibilityChanged(@NonNull View view, boolean isVisible) { |
| 505 | notifyViewVisibilityChangedInternal(view, 0, isVisible, false); |
| 506 | } |
| 507 | |
| 508 | /** |
| 509 | * Called when a virtual view's visibility changed. |
| 510 | * |
| 511 | * @param view {@link View} that was exited. |
| 512 | * @param virtualId id identifying the virtual child inside the parent view. |
| 513 | * @param isVisible visible if the view is visible in the view hierarchy. |
| 514 | */ |
| 515 | public void notifyViewVisibilityChanged(@NonNull View view, int virtualId, boolean isVisible) { |
| 516 | notifyViewVisibilityChangedInternal(view, virtualId, isVisible, true); |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * Called when a view/virtual view's visibility changed. |
| 521 | * |
| 522 | * @param view {@link View} that was exited. |
| 523 | * @param virtualId id identifying the virtual child inside the parent view. |
| 524 | * @param isVisible visible if the view is visible in the view hierarchy. |
| 525 | * @param virtual Whether the view is virtual. |
| 526 | */ |
| 527 | private void notifyViewVisibilityChangedInternal(@NonNull View view, int virtualId, |
| 528 | boolean isVisible, boolean virtual) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 529 | synchronized (mLock) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 530 | if (mEnabled && mSessionId != NO_SESSION) { |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame^] | 531 | final AutofillId id = virtual ? getAutofillId(view, virtualId) |
| 532 | : view.getAutofillId(); |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 533 | if (!isVisible && mFillableIds != null) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 534 | if (mFillableIds.contains(id)) { |
| 535 | if (sDebug) Log.d(TAG, "Hidding UI when view " + id + " became invisible"); |
| 536 | requestHideFillUi(id, view); |
| 537 | } |
| 538 | } |
| 539 | if (mTrackedViews != null) { |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame^] | 540 | mTrackedViews.notifyViewVisibilityChanged(id, isVisible); |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 541 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 547 | * Called when a virtual view that supports autofill is entered. |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 548 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 549 | * <p>The virtual view boundaries must be absolute screen coordinates. For example, if the |
| 550 | * parent, non-virtual view uses {@code bounds} to draw the virtual view inside its Canvas, |
| 551 | * the absolute bounds could be calculated by: |
| 552 | * |
| 553 | * <pre class="prettyprint"> |
| 554 | * int offset[] = new int[2]; |
| 555 | * getLocationOnScreen(offset); |
| 556 | * Rect absBounds = new Rect(bounds.left + offset[0], |
| 557 | * bounds.top + offset[1], |
| 558 | * bounds.right + offset[0], bounds.bottom + offset[1]); |
| 559 | * </pre> |
| 560 | * |
| 561 | * @param view the virtual view parent. |
| 562 | * @param virtualId id identifying the virtual child inside the parent view. |
| 563 | * @param absBounds absolute boundaries of the virtual view in the screen. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 564 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 565 | public void notifyViewEntered(@NonNull View view, int virtualId, @NonNull Rect absBounds) { |
| 566 | notifyViewEntered(view, virtualId, absBounds, 0); |
Felipe Leme | d114642 | 2017-04-26 10:17:05 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 569 | private void notifyViewEntered(View view, int virtualId, Rect bounds, int flags) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 570 | if (!hasAutofillFeature()) { |
| 571 | return; |
| 572 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 573 | AutofillCallback callback = null; |
| 574 | synchronized (mLock) { |
| 575 | ensureServiceClientAddedIfNeededLocked(); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 576 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 577 | if (!mEnabled) { |
| 578 | if (mCallback != null) { |
| 579 | callback = mCallback; |
| 580 | } |
| 581 | } else { |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 582 | final AutofillId id = getAutofillId(view, virtualId); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 583 | |
| 584 | if (mSessionId == NO_SESSION) { |
| 585 | // Starts new session. |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 586 | startSessionLocked(id, bounds, null, flags); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 587 | } else { |
| 588 | // Update focus on existing session. |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 589 | updateSessionLocked(id, bounds, null, ACTION_VIEW_ENTERED, flags); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 590 | } |
Felipe Leme | 24aae15 | 2017-03-15 12:33:01 -0700 | [diff] [blame] | 591 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 592 | } |
| 593 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 594 | if (callback != null) { |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 595 | callback.onAutofillEvent(view, virtualId, |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 596 | AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
| 600 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 601 | * Called when a virtual view that supports autofill is exited. |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 602 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 603 | * @param view the virtual view parent. |
| 604 | * @param virtualId id identifying the virtual child inside the parent view. |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 605 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 606 | public void notifyViewExited(@NonNull View view, int virtualId) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 607 | if (!hasAutofillFeature()) { |
| 608 | return; |
| 609 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 610 | synchronized (mLock) { |
| 611 | ensureServiceClientAddedIfNeededLocked(); |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 612 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 613 | if (mEnabled && mSessionId != NO_SESSION) { |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 614 | final AutofillId id = getAutofillId(view, virtualId); |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 615 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 616 | // Update focus on existing session. |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 617 | updateSessionLocked(id, null, null, ACTION_VIEW_EXITED, 0); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 618 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 619 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | /** |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 623 | * Called to indicate the value of an autofillable {@link View} changed. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 624 | * |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 625 | * @param view view whose value changed. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 626 | */ |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 627 | public void notifyValueChanged(View view) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 628 | if (!hasAutofillFeature()) { |
| 629 | return; |
| 630 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 631 | AutofillId id = null; |
| 632 | boolean valueWasRead = false; |
| 633 | AutofillValue value = null; |
| 634 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 635 | synchronized (mLock) { |
| 636 | // If the session is gone some fields might still be highlighted, hence we have to |
| 637 | // remove the isAutofilled property even if no sessions are active. |
| 638 | if (mLastAutofilledData == null) { |
| 639 | view.setAutofilled(false); |
| 640 | } else { |
| 641 | id = getAutofillId(view); |
| 642 | if (mLastAutofilledData.containsKey(id)) { |
| 643 | value = view.getAutofillValue(); |
| 644 | valueWasRead = true; |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 645 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 646 | if (Objects.equals(mLastAutofilledData.get(id), value)) { |
| 647 | view.setAutofilled(true); |
| 648 | } else { |
| 649 | view.setAutofilled(false); |
| 650 | mLastAutofilledData.remove(id); |
| 651 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 652 | } else { |
| 653 | view.setAutofilled(false); |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 654 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 655 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 656 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 657 | if (!mEnabled || mSessionId == NO_SESSION) { |
| 658 | return; |
| 659 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 660 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 661 | if (id == null) { |
| 662 | id = getAutofillId(view); |
| 663 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 664 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 665 | if (!valueWasRead) { |
| 666 | value = view.getAutofillValue(); |
| 667 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 668 | |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 669 | updateSessionLocked(id, null, value, ACTION_VALUE_CHANGED, 0); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 670 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 671 | } |
| 672 | |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 673 | /** |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 674 | * Called to indicate the value of an autofillable virtual view has changed. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 675 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 676 | * @param view the virtual view parent. |
| 677 | * @param virtualId id identifying the virtual child inside the parent view. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 678 | * @param value new value of the child. |
| 679 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 680 | public void notifyValueChanged(View view, int virtualId, AutofillValue value) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 681 | if (!hasAutofillFeature()) { |
| 682 | return; |
| 683 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 684 | synchronized (mLock) { |
| 685 | if (!mEnabled || mSessionId == NO_SESSION) { |
| 686 | return; |
| 687 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 688 | |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 689 | final AutofillId id = getAutofillId(view, virtualId); |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 690 | updateSessionLocked(id, null, value, ACTION_VALUE_CHANGED, 0); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 691 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 695 | * Called to indicate the current autofill context should be commited. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 696 | * |
| 697 | * <p>For example, when a virtual view is rendering an {@code HTML} page with a form, it should |
| 698 | * call this method after the form is submitted and another page is rendered. |
| 699 | */ |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 700 | public void commit() { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 701 | if (!hasAutofillFeature()) { |
| 702 | return; |
| 703 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 704 | synchronized (mLock) { |
| 705 | if (!mEnabled && mSessionId == NO_SESSION) { |
| 706 | return; |
| 707 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 708 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 709 | finishSessionLocked(); |
| 710 | } |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 711 | } |
| 712 | |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 713 | /** |
| 714 | * Called to indicate the current autofill context should be cancelled. |
| 715 | * |
| 716 | * <p>For example, when a virtual view is rendering an {@code HTML} page with a form, it should |
| 717 | * call this method if the user does not post the form but moves to another form in this page. |
| 718 | */ |
| 719 | public void cancel() { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 720 | if (!hasAutofillFeature()) { |
| 721 | return; |
| 722 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 723 | synchronized (mLock) { |
| 724 | if (!mEnabled && mSessionId == NO_SESSION) { |
| 725 | return; |
| 726 | } |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 727 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 728 | cancelSessionLocked(); |
| 729 | } |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Svet Ganov | f965b87 | 2017-04-28 16:34:02 -0700 | [diff] [blame] | 732 | /** @hide */ |
| 733 | public void disableOwnedAutofillServices() { |
| 734 | disableAutofillServices(); |
| 735 | } |
| 736 | |
Svet Ganov | f20a037 | 2017-04-10 17:08:05 -0700 | [diff] [blame] | 737 | /** |
| 738 | * If the app calling this API has enabled autofill services they |
| 739 | * will be disabled. |
| 740 | */ |
Svet Ganov | f965b87 | 2017-04-28 16:34:02 -0700 | [diff] [blame] | 741 | public void disableAutofillServices() { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 742 | if (!hasAutofillFeature()) { |
| 743 | return; |
| 744 | } |
Svet Ganov | f20a037 | 2017-04-10 17:08:05 -0700 | [diff] [blame] | 745 | try { |
| 746 | mService.disableOwnedAutofillServices(mContext.getUserId()); |
| 747 | } catch (RemoteException e) { |
| 748 | throw e.rethrowFromSystemServer(); |
| 749 | } |
| 750 | } |
| 751 | |
Felipe Leme | db04118 | 2017-04-21 17:33:38 -0700 | [diff] [blame] | 752 | /** |
| 753 | * Returns {@code true} if the calling application provides a {@link AutofillService} that is |
| 754 | * enabled for the current user, or {@code false} otherwise. |
| 755 | */ |
| 756 | public boolean hasEnabledAutofillServices() { |
| 757 | if (mService == null) return false; |
| 758 | |
| 759 | try { |
| 760 | return mService.isServiceEnabled(mContext.getUserId(), mContext.getPackageName()); |
| 761 | } catch (RemoteException e) { |
| 762 | throw e.rethrowFromSystemServer(); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | /** |
| 767 | * Returns {@code true} if Autofill is supported for this user. |
| 768 | * |
| 769 | * <p>Autofill is typically supported, but it could be unsupported in cases like: |
| 770 | * <ol> |
| 771 | * <li>Low-end devices. |
| 772 | * <li>Device policy rules that forbid its usage. |
| 773 | * </ol> |
| 774 | */ |
| 775 | public boolean isAutofillSupported() { |
| 776 | if (mService == null) return false; |
| 777 | |
| 778 | try { |
| 779 | return mService.isServiceSupported(mContext.getUserId()); |
| 780 | } catch (RemoteException e) { |
| 781 | throw e.rethrowFromSystemServer(); |
| 782 | } |
| 783 | } |
| 784 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 785 | private AutofillClient getClientLocked() { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 786 | if (mContext instanceof AutofillClient) { |
| 787 | return (AutofillClient) mContext; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 788 | } |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 789 | return null; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | /** @hide */ |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 793 | public void onAuthenticationResult(int authenticationId, Intent data) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 794 | if (!hasAutofillFeature()) { |
| 795 | return; |
| 796 | } |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 797 | // 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] | 798 | // handling the cases where it's not RESULT_OK: it works fine if the service does not |
| 799 | // set the EXTRA_AUTHENTICATION_RESULT extra, but it could cause weird results if the |
| 800 | // service set the extra and returned RESULT_CANCELED... |
| 801 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 802 | if (sDebug) Log.d(TAG, "onAuthenticationResult(): d=" + data); |
Felipe Leme | d633f07 | 2017-02-14 10:17:17 -0800 | [diff] [blame] | 803 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 804 | synchronized (mLock) { |
| 805 | if (mSessionId == NO_SESSION || data == null) { |
| 806 | return; |
| 807 | } |
| 808 | final Parcelable result = data.getParcelableExtra(EXTRA_AUTHENTICATION_RESULT); |
| 809 | final Bundle responseData = new Bundle(); |
| 810 | responseData.putParcelable(EXTRA_AUTHENTICATION_RESULT, result); |
| 811 | try { |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 812 | mService.setAuthenticationResult(responseData, mSessionId, authenticationId, |
| 813 | mContext.getUserId()); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 814 | } catch (RemoteException e) { |
| 815 | Log.e(TAG, "Error delivering authentication result", e); |
| 816 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 817 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 818 | } |
| 819 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 820 | private static AutofillId getAutofillId(View view) { |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 821 | return new AutofillId(view.getAutofillViewId()); |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 822 | } |
| 823 | |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 824 | private static AutofillId getAutofillId(View parent, int virtualId) { |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 825 | return new AutofillId(parent.getAutofillViewId(), virtualId); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 826 | } |
| 827 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 828 | private void startSessionLocked(@NonNull AutofillId id, @NonNull Rect bounds, |
| 829 | @NonNull AutofillValue value, int flags) { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 830 | if (sVerbose) { |
| 831 | Log.v(TAG, "startSessionLocked(): id=" + id + ", bounds=" + bounds + ", value=" + value |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 832 | + ", flags=" + flags); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 833 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 834 | |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 835 | try { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 836 | mSessionId = mService.startSession(mContext.getActivityToken(), |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 837 | mServiceClient.asBinder(), id, bounds, value, mContext.getUserId(), |
Philip P. Moltmann | 7b77116 | 2017-03-03 17:22:57 -0800 | [diff] [blame] | 838 | mCallback != null, flags, mContext.getOpPackageName()); |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 839 | final AutofillClient client = getClientLocked(); |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 840 | if (client != null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 841 | client.autofillCallbackResetableStateAvailable(); |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 842 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 843 | } catch (RemoteException e) { |
| 844 | throw e.rethrowFromSystemServer(); |
| 845 | } |
| 846 | } |
| 847 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 848 | private void finishSessionLocked() { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 849 | if (sVerbose) Log.v(TAG, "finishSessionLocked()"); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 850 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 851 | try { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 852 | mService.finishSession(mSessionId, mContext.getUserId()); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 853 | } catch (RemoteException e) { |
| 854 | throw e.rethrowFromSystemServer(); |
| 855 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 856 | |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 857 | mTrackedViews = null; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 858 | mSessionId = NO_SESSION; |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 859 | } |
| 860 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 861 | private void cancelSessionLocked() { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 862 | if (sVerbose) Log.v(TAG, "cancelSessionLocked()"); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 863 | |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 864 | try { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 865 | mService.cancelSession(mSessionId, mContext.getUserId()); |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 866 | } catch (RemoteException e) { |
| 867 | throw e.rethrowFromSystemServer(); |
| 868 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 869 | |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 870 | resetSessionLocked(); |
| 871 | } |
| 872 | |
| 873 | private void resetSessionLocked() { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 874 | mSessionId = NO_SESSION; |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 875 | mTrackedViews = null; |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 878 | private void updateSessionLocked(AutofillId id, Rect bounds, AutofillValue value, int action, |
| 879 | int flags) { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 880 | if (sVerbose && action != ACTION_VIEW_EXITED) { |
| 881 | Log.v(TAG, "updateSessionLocked(): id=" + id + ", bounds=" + bounds |
| 882 | + ", value=" + value + ", action=" + action + ", flags=" + flags); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 883 | } |
Felipe Leme | 0ab53dc | 2017-02-23 08:33:18 -0800 | [diff] [blame] | 884 | |
Felipe Leme | 7f33cd3 | 2017-05-11 10:10:49 -0700 | [diff] [blame] | 885 | boolean restartIfNecessary = (flags & FLAG_MANUAL_REQUEST) != 0; |
| 886 | |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 887 | try { |
Felipe Leme | 7f33cd3 | 2017-05-11 10:10:49 -0700 | [diff] [blame] | 888 | if (restartIfNecessary) { |
| 889 | final int newId = mService.updateOrRestartSession(mContext.getActivityToken(), |
| 890 | mServiceClient.asBinder(), id, bounds, value, mContext.getUserId(), |
| 891 | mCallback != null, flags, mContext.getOpPackageName(), mSessionId, action); |
| 892 | if (newId != mSessionId) { |
| 893 | if (sDebug) Log.d(TAG, "Session restarted: " + mSessionId + "=>" + newId); |
| 894 | mSessionId = newId; |
| 895 | final AutofillClient client = getClientLocked(); |
| 896 | if (client != null) { |
| 897 | client.autofillCallbackResetableStateAvailable(); |
| 898 | } |
| 899 | } |
| 900 | } else { |
| 901 | mService.updateSession(mSessionId, id, bounds, value, action, flags, |
| 902 | mContext.getUserId()); |
| 903 | } |
| 904 | |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 905 | } catch (RemoteException e) { |
| 906 | throw e.rethrowFromSystemServer(); |
| 907 | } |
| 908 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 909 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 910 | private void ensureServiceClientAddedIfNeededLocked() { |
| 911 | if (getClientLocked() == null) { |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 912 | return; |
| 913 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 914 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 915 | if (mServiceClient == null) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 916 | mServiceClient = new AutofillManagerClient(this); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 917 | try { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 918 | final int flags = mService.addClient(mServiceClient, mContext.getUserId()); |
| 919 | mEnabled = (flags & FLAG_ADD_CLIENT_ENABLED) != 0; |
| 920 | sDebug = (flags & FLAG_ADD_CLIENT_DEBUG) != 0; |
| 921 | sVerbose = (flags & FLAG_ADD_CLIENT_VERBOSE) != 0; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 922 | } catch (RemoteException e) { |
| 923 | throw e.rethrowFromSystemServer(); |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 928 | /** |
| 929 | * Registers a {@link AutofillCallback} to receive autofill events. |
| 930 | * |
| 931 | * @param callback callback to receive events. |
| 932 | */ |
| 933 | public void registerCallback(@Nullable AutofillCallback callback) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 934 | if (!hasAutofillFeature()) { |
| 935 | return; |
| 936 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 937 | synchronized (mLock) { |
| 938 | if (callback == null) return; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 939 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 940 | final boolean hadCallback = mCallback != null; |
| 941 | mCallback = callback; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 942 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 943 | if (!hadCallback) { |
| 944 | try { |
| 945 | mService.setHasCallback(mSessionId, mContext.getUserId(), true); |
| 946 | } catch (RemoteException e) { |
| 947 | throw e.rethrowFromSystemServer(); |
| 948 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 949 | } |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | /** |
| 954 | * Unregisters a {@link AutofillCallback} to receive autofill events. |
| 955 | * |
| 956 | * @param callback callback to stop receiving events. |
| 957 | */ |
| 958 | public void unregisterCallback(@Nullable AutofillCallback callback) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 959 | if (!hasAutofillFeature()) { |
| 960 | return; |
| 961 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 962 | synchronized (mLock) { |
| 963 | if (callback == null || mCallback == null || callback != mCallback) return; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 964 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 965 | mCallback = null; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 966 | |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 967 | try { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 968 | mService.setHasCallback(mSessionId, mContext.getUserId(), false); |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 969 | } catch (RemoteException e) { |
| 970 | throw e.rethrowFromSystemServer(); |
| 971 | } |
| 972 | } |
| 973 | } |
| 974 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 975 | private void requestShowFillUi(int sessionId, AutofillId id, int width, int height, |
| 976 | Rect anchorBounds, IAutofillWindowPresenter presenter) { |
| 977 | final View anchor = findView(id); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 978 | if (anchor == null) { |
| 979 | return; |
| 980 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 981 | |
| 982 | AutofillCallback callback = null; |
| 983 | synchronized (mLock) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 984 | if (mSessionId == sessionId) { |
| 985 | AutofillClient client = getClientLocked(); |
| 986 | |
| 987 | if (client != null) { |
| 988 | if (client.autofillCallbackRequestShowFillUi(anchor, width, height, |
| 989 | anchorBounds, presenter) && mCallback != null) { |
| 990 | callback = mCallback; |
| 991 | } |
| 992 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 993 | } |
| 994 | } |
| 995 | |
| 996 | if (callback != null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 997 | if (id.isVirtual()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 998 | callback.onAutofillEvent(anchor, id.getVirtualChildId(), |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 999 | AutofillCallback.EVENT_INPUT_SHOWN); |
| 1000 | } else { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1001 | callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_SHOWN); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1002 | } |
| 1003 | } |
| 1004 | } |
| 1005 | |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 1006 | private void authenticate(int sessionId, int authenticationId, IntentSender intent, |
| 1007 | Intent fillInIntent) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1008 | synchronized (mLock) { |
| 1009 | if (sessionId == mSessionId) { |
| 1010 | AutofillClient client = getClientLocked(); |
| 1011 | if (client != null) { |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 1012 | client.autofillCallbackAuthenticate(authenticationId, intent, fillInIntent); |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1013 | } |
| 1014 | } |
| 1015 | } |
| 1016 | } |
| 1017 | |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1018 | private void setState(boolean enabled, boolean resetSession, boolean resetClient) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1019 | synchronized (mLock) { |
| 1020 | mEnabled = enabled; |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1021 | if (!mEnabled || resetSession) { |
| 1022 | // Reset the session state |
| 1023 | resetSessionLocked(); |
| 1024 | } |
| 1025 | if (resetClient) { |
| 1026 | // Reset connection to system |
| 1027 | mServiceClient = null; |
| 1028 | } |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1032 | /** |
| 1033 | * Sets a view as autofilled if the current value is the {code targetValue}. |
| 1034 | * |
| 1035 | * @param view The view that is to be autofilled |
| 1036 | * @param targetValue The value we want to fill into view |
| 1037 | */ |
| 1038 | private void setAutofilledIfValuesIs(@NonNull View view, @Nullable AutofillValue targetValue) { |
| 1039 | AutofillValue currentValue = view.getAutofillValue(); |
| 1040 | if (Objects.equals(currentValue, targetValue)) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1041 | synchronized (mLock) { |
| 1042 | if (mLastAutofilledData == null) { |
| 1043 | mLastAutofilledData = new ParcelableMap(1); |
| 1044 | } |
| 1045 | mLastAutofilledData.put(getAutofillId(view), targetValue); |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1046 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1047 | view.setAutofilled(true); |
| 1048 | } |
| 1049 | } |
| 1050 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1051 | private void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1052 | synchronized (mLock) { |
| 1053 | if (sessionId != mSessionId) { |
| 1054 | return; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1055 | } |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1056 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1057 | final AutofillClient client = getClientLocked(); |
| 1058 | if (client == null) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1059 | return; |
| 1060 | } |
| 1061 | |
| 1062 | final int itemCount = ids.size(); |
| 1063 | int numApplied = 0; |
| 1064 | ArrayMap<View, SparseArray<AutofillValue>> virtualValues = null; |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1065 | final View[] views = client.findViewsByAutofillIdTraversal(getViewIds(ids)); |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1066 | |
| 1067 | for (int i = 0; i < itemCount; i++) { |
| 1068 | final AutofillId id = ids.get(i); |
| 1069 | final AutofillValue value = values.get(i); |
| 1070 | final int viewId = id.getViewId(); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1071 | final View view = views[i]; |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1072 | if (view == null) { |
| 1073 | Log.w(TAG, "autofill(): no View with id " + viewId); |
| 1074 | continue; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1075 | } |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1076 | if (id.isVirtual()) { |
| 1077 | if (virtualValues == null) { |
| 1078 | // Most likely there will be just one view with virtual children. |
| 1079 | virtualValues = new ArrayMap<>(1); |
| 1080 | } |
| 1081 | SparseArray<AutofillValue> valuesByParent = virtualValues.get(view); |
| 1082 | if (valuesByParent == null) { |
| 1083 | // We don't know the size yet, but usually it will be just a few fields... |
| 1084 | valuesByParent = new SparseArray<>(5); |
| 1085 | virtualValues.put(view, valuesByParent); |
| 1086 | } |
| 1087 | valuesByParent.put(id.getVirtualChildId(), value); |
| 1088 | } else { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1089 | // Mark the view as to be autofilled with 'value' |
| 1090 | if (mLastAutofilledData == null) { |
| 1091 | mLastAutofilledData = new ParcelableMap(itemCount - i); |
| 1092 | } |
| 1093 | mLastAutofilledData.put(id, value); |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1094 | |
| 1095 | view.autofill(value); |
| 1096 | |
| 1097 | // Set as autofilled if the values match now, e.g. when the value was updated |
| 1098 | // synchronously. |
| 1099 | // If autofill happens async, the view is set to autofilled in |
| 1100 | // notifyValueChanged. |
| 1101 | setAutofilledIfValuesIs(view, value); |
| 1102 | |
| 1103 | numApplied++; |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1104 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1105 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1106 | |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1107 | if (virtualValues != null) { |
| 1108 | for (int i = 0; i < virtualValues.size(); i++) { |
| 1109 | final View parent = virtualValues.keyAt(i); |
| 1110 | final SparseArray<AutofillValue> childrenValues = virtualValues.valueAt(i); |
| 1111 | parent.autofill(childrenValues); |
| 1112 | numApplied += childrenValues.size(); |
| 1113 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1114 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1115 | |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1116 | final LogMaker log = new LogMaker(MetricsProto.MetricsEvent.AUTOFILL_DATASET_APPLIED); |
| 1117 | log.addTaggedData(MetricsProto.MetricsEvent.FIELD_AUTOFILL_NUM_VALUES, itemCount); |
| 1118 | log.addTaggedData(MetricsProto.MetricsEvent.FIELD_AUTOFILL_NUM_VIEWS_FILLED, |
| 1119 | numApplied); |
| 1120 | mMetricsLogger.write(log); |
| 1121 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1124 | /** |
| 1125 | * Set the tracked views. |
| 1126 | * |
| 1127 | * @param trackedIds The views to be tracked |
| 1128 | * @param saveOnAllViewsInvisible Finish the session once all tracked views are invisible. |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1129 | * @param fillableIds Views that might anchor FillUI. |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1130 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1131 | private void setTrackedViews(int sessionId, @Nullable AutofillId[] trackedIds, |
| 1132 | boolean saveOnAllViewsInvisible, @Nullable AutofillId[] fillableIds) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1133 | synchronized (mLock) { |
| 1134 | if (mEnabled && mSessionId == sessionId) { |
| 1135 | if (saveOnAllViewsInvisible) { |
| 1136 | mTrackedViews = new TrackedViews(trackedIds); |
| 1137 | } else { |
| 1138 | mTrackedViews = null; |
| 1139 | } |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1140 | if (fillableIds != null) { |
| 1141 | if (mFillableIds == null) { |
| 1142 | mFillableIds = new ArraySet<>(fillableIds.length); |
| 1143 | } |
| 1144 | for (AutofillId id : fillableIds) { |
| 1145 | mFillableIds.add(id); |
| 1146 | } |
| 1147 | if (sVerbose) { |
| 1148 | Log.v(TAG, "setTrackedViews(): fillableIds=" + fillableIds |
| 1149 | + ", mFillableIds" + mFillableIds); |
| 1150 | } |
| 1151 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | } |
| 1155 | |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1156 | private void requestHideFillUi(AutofillId id) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1157 | final View anchor = findView(id); |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1158 | if (sVerbose) Log.v(TAG, "requestHideFillUi(" + id + "): anchor = " + anchor); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1159 | if (anchor == null) { |
| 1160 | return; |
| 1161 | } |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1162 | requestHideFillUi(id, anchor); |
| 1163 | } |
| 1164 | |
| 1165 | private void requestHideFillUi(AutofillId id, View anchor) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1166 | |
| 1167 | AutofillCallback callback = null; |
| 1168 | synchronized (mLock) { |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1169 | // We do not check the session id for two reasons: |
| 1170 | // 1. If local and remote session id are off sync the UI would be stuck shown |
| 1171 | // 2. There is a race between the user state being destroyed due the fill |
| 1172 | // service being uninstalled and the UI being dismissed. |
| 1173 | AutofillClient client = getClientLocked(); |
| 1174 | if (client != null) { |
| 1175 | if (client.autofillCallbackRequestHideFillUi() && mCallback != null) { |
| 1176 | callback = mCallback; |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1177 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | if (callback != null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1182 | if (id.isVirtual()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1183 | callback.onAutofillEvent(anchor, id.getVirtualChildId(), |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1184 | AutofillCallback.EVENT_INPUT_HIDDEN); |
| 1185 | } else { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1186 | callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_HIDDEN); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1187 | } |
| 1188 | } |
| 1189 | } |
| 1190 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1191 | private void notifyNoFillUi(int sessionId, AutofillId id) { |
| 1192 | final View anchor = findView(id); |
| 1193 | if (anchor == null) { |
| 1194 | return; |
| 1195 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1196 | |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1197 | AutofillCallback callback = null; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1198 | synchronized (mLock) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1199 | if (mSessionId == sessionId && getClientLocked() != null) { |
| 1200 | callback = mCallback; |
| 1201 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | if (callback != null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1205 | if (id.isVirtual()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1206 | callback.onAutofillEvent(anchor, id.getVirtualChildId(), |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1207 | AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
| 1208 | } else { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1209 | callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1210 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1211 | |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1215 | /** |
| 1216 | * Get an array of viewIds from a List of {@link AutofillId}. |
| 1217 | * |
| 1218 | * @param autofillIds The autofill ids to convert |
| 1219 | * |
| 1220 | * @return The array of viewIds. |
| 1221 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1222 | // TODO: move to Helper as static method |
| 1223 | @NonNull private int[] getViewIds(@NonNull AutofillId[] autofillIds) { |
| 1224 | final int numIds = autofillIds.length; |
| 1225 | final int[] viewIds = new int[numIds]; |
| 1226 | for (int i = 0; i < numIds; i++) { |
| 1227 | viewIds[i] = autofillIds[i].getViewId(); |
| 1228 | } |
| 1229 | |
| 1230 | return viewIds; |
| 1231 | } |
| 1232 | |
| 1233 | // TODO: move to Helper as static method |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1234 | @NonNull private int[] getViewIds(@NonNull List<AutofillId> autofillIds) { |
| 1235 | final int numIds = autofillIds.size(); |
| 1236 | final int[] viewIds = new int[numIds]; |
| 1237 | for (int i = 0; i < numIds; i++) { |
| 1238 | viewIds[i] = autofillIds.get(i).getViewId(); |
| 1239 | } |
| 1240 | |
| 1241 | return viewIds; |
| 1242 | } |
| 1243 | |
| 1244 | /** |
| 1245 | * Find a single view by its id. |
| 1246 | * |
| 1247 | * @param autofillId The autofill id of the view |
| 1248 | * |
| 1249 | * @return The view or {@code null} if view was not found |
| 1250 | */ |
| 1251 | private View findView(@NonNull AutofillId autofillId) { |
| 1252 | final AutofillClient client = getClientLocked(); |
| 1253 | |
| 1254 | if (client == null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1255 | return null; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1256 | } |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1257 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1258 | return client.findViewByAutofillIdTraversal(autofillId.getViewId()); |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1259 | } |
| 1260 | |
Felipe Leme | bb81092 | 2017-04-25 15:54:06 -0700 | [diff] [blame] | 1261 | /** @hide */ |
| 1262 | public boolean hasAutofillFeature() { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 1263 | return mService != null; |
| 1264 | } |
| 1265 | |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1266 | private void post(Runnable runnable) { |
| 1267 | final AutofillClient client = getClientLocked(); |
| 1268 | if (client == null) { |
| 1269 | if (sVerbose) Log.v(TAG, "ignoring post() because client is null"); |
| 1270 | return; |
| 1271 | } |
| 1272 | client.runOnUiThread(runnable); |
| 1273 | } |
| 1274 | |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1275 | /** |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1276 | * View tracking information. Once all tracked views become invisible the session is finished. |
| 1277 | */ |
| 1278 | private class TrackedViews { |
| 1279 | /** Visible tracked views */ |
| 1280 | @Nullable private ArraySet<AutofillId> mVisibleTrackedIds; |
| 1281 | |
| 1282 | /** Invisible tracked views */ |
| 1283 | @Nullable private ArraySet<AutofillId> mInvisibleTrackedIds; |
| 1284 | |
| 1285 | /** |
| 1286 | * Check if set is null or value is in set. |
| 1287 | * |
| 1288 | * @param set The set or null (== empty set) |
| 1289 | * @param value The value that might be in the set |
| 1290 | * |
| 1291 | * @return {@code true} iff set is not empty and value is in set |
| 1292 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1293 | // TODO: move to Helper as static method |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1294 | private <T> boolean isInSet(@Nullable ArraySet<T> set, T value) { |
| 1295 | return set != null && set.contains(value); |
| 1296 | } |
| 1297 | |
| 1298 | /** |
| 1299 | * Add a value to a set. If set is null, create a new set. |
| 1300 | * |
| 1301 | * @param set The set or null (== empty set) |
| 1302 | * @param valueToAdd The value to add |
| 1303 | * |
| 1304 | * @return The set including the new value. If set was {@code null}, a set containing only |
| 1305 | * the new value. |
| 1306 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1307 | // TODO: move to Helper as static method |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1308 | @NonNull |
| 1309 | private <T> ArraySet<T> addToSet(@Nullable ArraySet<T> set, T valueToAdd) { |
| 1310 | if (set == null) { |
| 1311 | set = new ArraySet<>(1); |
| 1312 | } |
| 1313 | |
| 1314 | set.add(valueToAdd); |
| 1315 | |
| 1316 | return set; |
| 1317 | } |
| 1318 | |
| 1319 | /** |
| 1320 | * Remove a value from a set. |
| 1321 | * |
| 1322 | * @param set The set or null (== empty set) |
| 1323 | * @param valueToRemove The value to remove |
| 1324 | * |
| 1325 | * @return The set without the removed value. {@code null} if set was null, or is empty |
| 1326 | * after removal. |
| 1327 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1328 | // TODO: move to Helper as static method |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1329 | @Nullable |
| 1330 | private <T> ArraySet<T> removeFromSet(@Nullable ArraySet<T> set, T valueToRemove) { |
| 1331 | if (set == null) { |
| 1332 | return null; |
| 1333 | } |
| 1334 | |
| 1335 | set.remove(valueToRemove); |
| 1336 | |
| 1337 | if (set.isEmpty()) { |
| 1338 | return null; |
| 1339 | } |
| 1340 | |
| 1341 | return set; |
| 1342 | } |
| 1343 | |
| 1344 | /** |
| 1345 | * Set the tracked views. |
| 1346 | * |
| 1347 | * @param trackedIds The views to be tracked |
| 1348 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1349 | TrackedViews(@Nullable AutofillId[] trackedIds) { |
| 1350 | final AutofillClient client = getClientLocked(); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1351 | if (trackedIds != null && client != null) { |
| 1352 | final boolean[] isVisible; |
| 1353 | |
| 1354 | if (client.isVisibleForAutofill()) { |
| 1355 | isVisible = client.getViewVisibility(getViewIds(trackedIds)); |
| 1356 | } else { |
| 1357 | // All false |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1358 | isVisible = new boolean[trackedIds.length]; |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1361 | final int numIds = trackedIds.length; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1362 | for (int i = 0; i < numIds; i++) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1363 | final AutofillId id = trackedIds[i]; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1364 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1365 | if (isVisible[i]) { |
Philip P. Moltmann | e0e2871 | 2017-04-20 15:19:06 -0700 | [diff] [blame] | 1366 | mVisibleTrackedIds = addToSet(mVisibleTrackedIds, id); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1367 | } else { |
| 1368 | mInvisibleTrackedIds = addToSet(mInvisibleTrackedIds, id); |
| 1369 | } |
| 1370 | } |
| 1371 | } |
| 1372 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1373 | if (sVerbose) { |
| 1374 | Log.v(TAG, "TrackedViews(trackedIds=" + trackedIds + "): " |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1375 | + " mVisibleTrackedIds=" + mVisibleTrackedIds |
| 1376 | + " mInvisibleTrackedIds=" + mInvisibleTrackedIds); |
| 1377 | } |
| 1378 | |
| 1379 | if (mVisibleTrackedIds == null) { |
| 1380 | finishSessionLocked(); |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | /** |
| 1385 | * Called when a {@link View view's} visibility changes. |
| 1386 | * |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame^] | 1387 | * @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] | 1388 | * @param isVisible visible if the view is visible in the view hierarchy. |
| 1389 | */ |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame^] | 1390 | void notifyViewVisibilityChanged(@NonNull AutofillId id, boolean isVisible) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1391 | AutofillClient client = getClientLocked(); |
| 1392 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1393 | if (sDebug) { |
Svetoslav Ganov | 4db89ba | 2017-06-28 16:50:37 -0700 | [diff] [blame^] | 1394 | Log.d(TAG, "notifyViewVisibilityChanged(): id=" + id + " isVisible=" |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1395 | + isVisible); |
| 1396 | } |
| 1397 | |
| 1398 | if (client != null && client.isVisibleForAutofill()) { |
| 1399 | if (isVisible) { |
| 1400 | if (isInSet(mInvisibleTrackedIds, id)) { |
| 1401 | mInvisibleTrackedIds = removeFromSet(mInvisibleTrackedIds, id); |
| 1402 | mVisibleTrackedIds = addToSet(mVisibleTrackedIds, id); |
| 1403 | } |
| 1404 | } else { |
| 1405 | if (isInSet(mVisibleTrackedIds, id)) { |
| 1406 | mVisibleTrackedIds = removeFromSet(mVisibleTrackedIds, id); |
| 1407 | mInvisibleTrackedIds = addToSet(mInvisibleTrackedIds, id); |
| 1408 | } |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | if (mVisibleTrackedIds == null) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1413 | if (sVerbose) { |
| 1414 | Log.v(TAG, "No more visible ids. Invisibile = " + mInvisibleTrackedIds); |
| 1415 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1416 | finishSessionLocked(); |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | /** |
| 1421 | * Called once the client becomes visible. |
| 1422 | * |
| 1423 | * @see AutofillClient#isVisibleForAutofill() |
| 1424 | */ |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1425 | void onVisibleForAutofillLocked() { |
| 1426 | // 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] | 1427 | // hence update the visibility state for all views. |
| 1428 | AutofillClient client = getClientLocked(); |
| 1429 | ArraySet<AutofillId> updatedVisibleTrackedIds = null; |
| 1430 | ArraySet<AutofillId> updatedInvisibleTrackedIds = null; |
| 1431 | if (client != null) { |
| 1432 | if (mInvisibleTrackedIds != null) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1433 | final ArrayList<AutofillId> orderedInvisibleIds = |
| 1434 | new ArrayList<>(mInvisibleTrackedIds); |
| 1435 | final boolean[] isVisible = client.getViewVisibility( |
| 1436 | getViewIds(orderedInvisibleIds)); |
| 1437 | |
| 1438 | final int numInvisibleTrackedIds = orderedInvisibleIds.size(); |
| 1439 | for (int i = 0; i < numInvisibleTrackedIds; i++) { |
| 1440 | final AutofillId id = orderedInvisibleIds.get(i); |
| 1441 | if (isVisible[i]) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1442 | updatedVisibleTrackedIds = addToSet(updatedVisibleTrackedIds, id); |
| 1443 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1444 | if (sDebug) { |
| 1445 | Log.d(TAG, "onVisibleForAutofill() " + id + " became visible"); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1446 | } |
| 1447 | } else { |
| 1448 | updatedInvisibleTrackedIds = addToSet(updatedInvisibleTrackedIds, id); |
| 1449 | } |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | if (mVisibleTrackedIds != null) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1454 | final ArrayList<AutofillId> orderedVisibleIds = |
| 1455 | new ArrayList<>(mVisibleTrackedIds); |
| 1456 | final boolean[] isVisible = client.getViewVisibility( |
| 1457 | getViewIds(orderedVisibleIds)); |
| 1458 | |
| 1459 | final int numVisibleTrackedIds = orderedVisibleIds.size(); |
| 1460 | for (int i = 0; i < numVisibleTrackedIds; i++) { |
| 1461 | final AutofillId id = orderedVisibleIds.get(i); |
| 1462 | |
| 1463 | if (isVisible[i]) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1464 | updatedVisibleTrackedIds = addToSet(updatedVisibleTrackedIds, id); |
| 1465 | } else { |
| 1466 | updatedInvisibleTrackedIds = addToSet(updatedInvisibleTrackedIds, id); |
| 1467 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1468 | if (sDebug) { |
| 1469 | Log.d(TAG, "onVisibleForAutofill() " + id + " became invisible"); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1470 | } |
| 1471 | } |
| 1472 | } |
| 1473 | } |
| 1474 | |
| 1475 | mInvisibleTrackedIds = updatedInvisibleTrackedIds; |
| 1476 | mVisibleTrackedIds = updatedVisibleTrackedIds; |
| 1477 | } |
| 1478 | |
| 1479 | if (mVisibleTrackedIds == null) { |
| 1480 | finishSessionLocked(); |
| 1481 | } |
| 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | /** |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1486 | * Callback for auto-fill related events. |
| 1487 | * |
| 1488 | * <p>Typically used for applications that display their own "auto-complete" views, so they can |
| 1489 | * enable / disable such views when the auto-fill UI affordance is shown / hidden. |
| 1490 | */ |
| 1491 | public abstract static class AutofillCallback { |
| 1492 | |
| 1493 | /** @hide */ |
| 1494 | @IntDef({EVENT_INPUT_SHOWN, EVENT_INPUT_HIDDEN}) |
| 1495 | @Retention(RetentionPolicy.SOURCE) |
| 1496 | public @interface AutofillEventType {} |
| 1497 | |
| 1498 | /** |
| 1499 | * The auto-fill input UI affordance associated with the view was shown. |
| 1500 | * |
| 1501 | * <p>If the view provides its own auto-complete UI affordance and its currently shown, it |
| 1502 | * should be hidden upon receiving this event. |
| 1503 | */ |
| 1504 | public static final int EVENT_INPUT_SHOWN = 1; |
| 1505 | |
| 1506 | /** |
| 1507 | * The auto-fill input UI affordance associated with the view was hidden. |
| 1508 | * |
| 1509 | * <p>If the view provides its own auto-complete UI affordance that was hidden upon a |
| 1510 | * {@link #EVENT_INPUT_SHOWN} event, it could be shown again now. |
| 1511 | */ |
| 1512 | public static final int EVENT_INPUT_HIDDEN = 2; |
| 1513 | |
| 1514 | /** |
Felipe Leme | 24aae15 | 2017-03-15 12:33:01 -0700 | [diff] [blame] | 1515 | * The auto-fill input UI affordance associated with the view won't be shown because |
| 1516 | * autofill is not available. |
| 1517 | * |
| 1518 | * <p>If the view provides its own auto-complete UI affordance but was not displaying it |
| 1519 | * to avoid flickering, it could shown it upon receiving this event. |
| 1520 | */ |
| 1521 | public static final int EVENT_INPUT_UNAVAILABLE = 3; |
| 1522 | |
| 1523 | /** |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1524 | * Called after a change in the autofill state associated with a view. |
| 1525 | * |
| 1526 | * @param view view associated with the change. |
| 1527 | * |
| 1528 | * @param event currently either {@link #EVENT_INPUT_SHOWN} or {@link #EVENT_INPUT_HIDDEN}. |
| 1529 | */ |
Felipe Leme | 81f01d9 | 2017-03-16 17:13:25 -0700 | [diff] [blame] | 1530 | public void onAutofillEvent(@NonNull View view, @AutofillEventType int event) { |
| 1531 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1532 | |
| 1533 | /** |
| 1534 | * Called after a change in the autofill state associated with a virtual view. |
| 1535 | * |
| 1536 | * @param view parent view associated with the change. |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 1537 | * @param virtualId id identifying the virtual child inside the parent view. |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1538 | * |
| 1539 | * @param event currently either {@link #EVENT_INPUT_SHOWN} or {@link #EVENT_INPUT_HIDDEN}. |
| 1540 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 1541 | public void onAutofillEvent(@NonNull View view, int virtualId, |
| 1542 | @AutofillEventType int event) { |
Felipe Leme | 81f01d9 | 2017-03-16 17:13:25 -0700 | [diff] [blame] | 1543 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1544 | } |
| 1545 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1546 | private static final class AutofillManagerClient extends IAutoFillManagerClient.Stub { |
| 1547 | private final WeakReference<AutofillManager> mAfm; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1548 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1549 | AutofillManagerClient(AutofillManager autofillManager) { |
| 1550 | mAfm = new WeakReference<>(autofillManager); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | @Override |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1554 | public void setState(boolean enabled, boolean resetSession, boolean resetClient) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1555 | final AutofillManager afm = mAfm.get(); |
| 1556 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1557 | afm.post(() -> afm.setState(enabled, resetSession, resetClient)); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1558 | } |
| 1559 | } |
| 1560 | |
| 1561 | @Override |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1562 | public void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1563 | final AutofillManager afm = mAfm.get(); |
| 1564 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1565 | afm.post(() -> afm.autofill(sessionId, ids, values)); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | @Override |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 1570 | public void authenticate(int sessionId, int authenticationId, IntentSender intent, |
| 1571 | Intent fillInIntent) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1572 | final AutofillManager afm = mAfm.get(); |
| 1573 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1574 | afm.post(() -> afm.authenticate(sessionId, authenticationId, intent, fillInIntent)); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1575 | } |
| 1576 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1577 | |
| 1578 | @Override |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1579 | public void requestShowFillUi(int sessionId, AutofillId id, int width, int height, |
| 1580 | Rect anchorBounds, IAutofillWindowPresenter presenter) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1581 | final AutofillManager afm = mAfm.get(); |
| 1582 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1583 | afm.post(() -> afm.requestShowFillUi(sessionId, id, width, height, anchorBounds, |
| 1584 | presenter)); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | @Override |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1589 | public void requestHideFillUi(int sessionId, AutofillId id) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1590 | final AutofillManager afm = mAfm.get(); |
| 1591 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1592 | afm.post(() -> afm.requestHideFillUi(id)); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | @Override |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1597 | public void notifyNoFillUi(int sessionId, AutofillId id) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1598 | final AutofillManager afm = mAfm.get(); |
| 1599 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1600 | afm.post(() -> afm.notifyNoFillUi(sessionId, id)); |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1601 | } |
| 1602 | } |
Svet Ganov | c3d1c85 | 2017-04-12 22:34:28 -0700 | [diff] [blame] | 1603 | |
| 1604 | @Override |
| 1605 | public void startIntentSender(IntentSender intentSender) { |
| 1606 | final AutofillManager afm = mAfm.get(); |
| 1607 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1608 | afm.post(() -> { |
Svet Ganov | c3d1c85 | 2017-04-12 22:34:28 -0700 | [diff] [blame] | 1609 | try { |
| 1610 | afm.mContext.startIntentSender(intentSender, null, 0, 0, 0); |
| 1611 | } catch (IntentSender.SendIntentException e) { |
| 1612 | Log.e(TAG, "startIntentSender() failed for intent:" + intentSender, e); |
| 1613 | } |
| 1614 | }); |
| 1615 | } |
| 1616 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1617 | |
| 1618 | @Override |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1619 | public void setTrackedViews(int sessionId, AutofillId[] ids, |
| 1620 | boolean saveOnAllViewsInvisible, AutofillId[] fillableIds) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1621 | final AutofillManager afm = mAfm.get(); |
| 1622 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1623 | afm.post(() -> |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1624 | afm.setTrackedViews(sessionId, ids, saveOnAllViewsInvisible, fillableIds) |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1625 | ); |
| 1626 | } |
| 1627 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1628 | } |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 1629 | } |