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 | /** |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 499 | * Called when a {@link View view's} visibility changes. |
| 500 | * |
| 501 | * @param view {@link View} that was exited. |
| 502 | * @param isVisible visible if the view is visible in the view hierarchy. |
| 503 | * |
| 504 | * @hide |
| 505 | */ |
| 506 | public void notifyViewVisibilityChange(@NonNull View view, boolean isVisible) { |
| 507 | synchronized (mLock) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 508 | if (mEnabled && mSessionId != NO_SESSION) { |
| 509 | if (!isVisible && mFillableIds != null) { |
| 510 | final AutofillId id = view.getAutofillId(); |
| 511 | if (mFillableIds.contains(id)) { |
| 512 | if (sDebug) Log.d(TAG, "Hidding UI when view " + id + " became invisible"); |
| 513 | requestHideFillUi(id, view); |
| 514 | } |
| 515 | } |
| 516 | if (mTrackedViews != null) { |
| 517 | mTrackedViews.notifyViewVisibilityChange(view, isVisible); |
| 518 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 524 | * Called when a virtual view that supports autofill is entered. |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 525 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 526 | * <p>The virtual view boundaries must be absolute screen coordinates. For example, if the |
| 527 | * parent, non-virtual view uses {@code bounds} to draw the virtual view inside its Canvas, |
| 528 | * the absolute bounds could be calculated by: |
| 529 | * |
| 530 | * <pre class="prettyprint"> |
| 531 | * int offset[] = new int[2]; |
| 532 | * getLocationOnScreen(offset); |
| 533 | * Rect absBounds = new Rect(bounds.left + offset[0], |
| 534 | * bounds.top + offset[1], |
| 535 | * bounds.right + offset[0], bounds.bottom + offset[1]); |
| 536 | * </pre> |
| 537 | * |
| 538 | * @param view the virtual view parent. |
| 539 | * @param virtualId id identifying the virtual child inside the parent view. |
| 540 | * @param absBounds absolute boundaries of the virtual view in the screen. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 541 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 542 | public void notifyViewEntered(@NonNull View view, int virtualId, @NonNull Rect absBounds) { |
| 543 | notifyViewEntered(view, virtualId, absBounds, 0); |
Felipe Leme | d114642 | 2017-04-26 10:17:05 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 546 | private void notifyViewEntered(View view, int virtualId, Rect bounds, int flags) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 547 | if (!hasAutofillFeature()) { |
| 548 | return; |
| 549 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 550 | AutofillCallback callback = null; |
| 551 | synchronized (mLock) { |
| 552 | ensureServiceClientAddedIfNeededLocked(); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 553 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 554 | if (!mEnabled) { |
| 555 | if (mCallback != null) { |
| 556 | callback = mCallback; |
| 557 | } |
| 558 | } else { |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 559 | final AutofillId id = getAutofillId(view, virtualId); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 560 | |
| 561 | if (mSessionId == NO_SESSION) { |
| 562 | // Starts new session. |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 563 | startSessionLocked(id, bounds, null, flags); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 564 | } else { |
| 565 | // Update focus on existing session. |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 566 | updateSessionLocked(id, bounds, null, ACTION_VIEW_ENTERED, flags); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 567 | } |
Felipe Leme | 24aae15 | 2017-03-15 12:33:01 -0700 | [diff] [blame] | 568 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 569 | } |
| 570 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 571 | if (callback != null) { |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 572 | callback.onAutofillEvent(view, virtualId, |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 573 | AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
| 577 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 578 | * Called when a virtual view that supports autofill is exited. |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 579 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 580 | * @param view the virtual view parent. |
| 581 | * @param virtualId id identifying the virtual child inside the parent view. |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 582 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 583 | public void notifyViewExited(@NonNull View view, int virtualId) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 584 | if (!hasAutofillFeature()) { |
| 585 | return; |
| 586 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 587 | synchronized (mLock) { |
| 588 | ensureServiceClientAddedIfNeededLocked(); |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 589 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 590 | if (mEnabled && mSessionId != NO_SESSION) { |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 591 | final AutofillId id = getAutofillId(view, virtualId); |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 592 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 593 | // Update focus on existing session. |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 594 | updateSessionLocked(id, null, null, ACTION_VIEW_EXITED, 0); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 595 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 596 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /** |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 600 | * Called to indicate the value of an autofillable {@link View} changed. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 601 | * |
Philip P. Moltmann | 4461181 | 2017-02-23 12:52:46 -0800 | [diff] [blame] | 602 | * @param view view whose value changed. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 603 | */ |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 604 | public void notifyValueChanged(View view) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 605 | if (!hasAutofillFeature()) { |
| 606 | return; |
| 607 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 608 | AutofillId id = null; |
| 609 | boolean valueWasRead = false; |
| 610 | AutofillValue value = null; |
| 611 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 612 | synchronized (mLock) { |
| 613 | // If the session is gone some fields might still be highlighted, hence we have to |
| 614 | // remove the isAutofilled property even if no sessions are active. |
| 615 | if (mLastAutofilledData == null) { |
| 616 | view.setAutofilled(false); |
| 617 | } else { |
| 618 | id = getAutofillId(view); |
| 619 | if (mLastAutofilledData.containsKey(id)) { |
| 620 | value = view.getAutofillValue(); |
| 621 | valueWasRead = true; |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 622 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 623 | if (Objects.equals(mLastAutofilledData.get(id), value)) { |
| 624 | view.setAutofilled(true); |
| 625 | } else { |
| 626 | view.setAutofilled(false); |
| 627 | mLastAutofilledData.remove(id); |
| 628 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 629 | } else { |
| 630 | view.setAutofilled(false); |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 631 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 632 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 633 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 634 | if (!mEnabled || mSessionId == NO_SESSION) { |
| 635 | return; |
| 636 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 637 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 638 | if (id == null) { |
| 639 | id = getAutofillId(view); |
| 640 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 641 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 642 | if (!valueWasRead) { |
| 643 | value = view.getAutofillValue(); |
| 644 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 645 | |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 646 | updateSessionLocked(id, null, value, ACTION_VALUE_CHANGED, 0); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 647 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 648 | } |
| 649 | |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 650 | /** |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 651 | * Called to indicate the value of an autofillable virtual view has changed. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 652 | * |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 653 | * @param view the virtual view parent. |
| 654 | * @param virtualId id identifying the virtual child inside the parent view. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 655 | * @param value new value of the child. |
| 656 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 657 | public void notifyValueChanged(View view, int virtualId, AutofillValue value) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 658 | if (!hasAutofillFeature()) { |
| 659 | return; |
| 660 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 661 | synchronized (mLock) { |
| 662 | if (!mEnabled || mSessionId == NO_SESSION) { |
| 663 | return; |
| 664 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 665 | |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 666 | final AutofillId id = getAutofillId(view, virtualId); |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 667 | updateSessionLocked(id, null, value, ACTION_VALUE_CHANGED, 0); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 668 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | /** |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 672 | * Called to indicate the current autofill context should be commited. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 673 | * |
Felipe Leme | 33681a9 | 2017-07-28 09:14:38 -0700 | [diff] [blame^] | 674 | * <p>This method is typically called by {@link View Views} that manage virtual views; for |
| 675 | * example, when the view is rendering an {@code HTML} page with a form and virtual views |
| 676 | * that represent the HTML elements, it should call this method after the form is submitted and |
| 677 | * another page is rendered. |
| 678 | * |
| 679 | * <p><b>Note:</b> This method does not need to be called on regular application lifecycle |
| 680 | * methods such as {@link android.app.Activity#finish()}. |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 681 | */ |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 682 | public void commit() { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 683 | if (!hasAutofillFeature()) { |
| 684 | return; |
| 685 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 686 | synchronized (mLock) { |
| 687 | if (!mEnabled && mSessionId == NO_SESSION) { |
| 688 | return; |
| 689 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 690 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 691 | finishSessionLocked(); |
| 692 | } |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 693 | } |
| 694 | |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 695 | /** |
| 696 | * Called to indicate the current autofill context should be cancelled. |
| 697 | * |
Felipe Leme | 33681a9 | 2017-07-28 09:14:38 -0700 | [diff] [blame^] | 698 | * <p>This method is typically called by {@link View Views} that manage virtual views; for |
| 699 | * example, when the view is rendering an {@code HTML} page with a form and virtual views |
| 700 | * that represent the HTML elements, it should call this method if the user does not post the |
| 701 | * form but moves to another form in this page. |
| 702 | * |
| 703 | * <p><b>Note:</b> This method does not need to be called on regular application lifecycle |
| 704 | * methods such as {@link android.app.Activity#finish()}. |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 705 | */ |
| 706 | public void cancel() { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 707 | if (!hasAutofillFeature()) { |
| 708 | return; |
| 709 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 710 | synchronized (mLock) { |
| 711 | if (!mEnabled && mSessionId == NO_SESSION) { |
| 712 | return; |
| 713 | } |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 714 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 715 | cancelSessionLocked(); |
| 716 | } |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Svet Ganov | f965b87 | 2017-04-28 16:34:02 -0700 | [diff] [blame] | 719 | /** @hide */ |
| 720 | public void disableOwnedAutofillServices() { |
| 721 | disableAutofillServices(); |
| 722 | } |
| 723 | |
Svet Ganov | f20a037 | 2017-04-10 17:08:05 -0700 | [diff] [blame] | 724 | /** |
| 725 | * If the app calling this API has enabled autofill services they |
| 726 | * will be disabled. |
| 727 | */ |
Svet Ganov | f965b87 | 2017-04-28 16:34:02 -0700 | [diff] [blame] | 728 | public void disableAutofillServices() { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 729 | if (!hasAutofillFeature()) { |
| 730 | return; |
| 731 | } |
Svet Ganov | f20a037 | 2017-04-10 17:08:05 -0700 | [diff] [blame] | 732 | try { |
| 733 | mService.disableOwnedAutofillServices(mContext.getUserId()); |
| 734 | } catch (RemoteException e) { |
| 735 | throw e.rethrowFromSystemServer(); |
| 736 | } |
| 737 | } |
| 738 | |
Felipe Leme | db04118 | 2017-04-21 17:33:38 -0700 | [diff] [blame] | 739 | /** |
| 740 | * Returns {@code true} if the calling application provides a {@link AutofillService} that is |
| 741 | * enabled for the current user, or {@code false} otherwise. |
| 742 | */ |
| 743 | public boolean hasEnabledAutofillServices() { |
| 744 | if (mService == null) return false; |
| 745 | |
| 746 | try { |
| 747 | return mService.isServiceEnabled(mContext.getUserId(), mContext.getPackageName()); |
| 748 | } catch (RemoteException e) { |
| 749 | throw e.rethrowFromSystemServer(); |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | /** |
Ricardo Loo | 33d226c | 2017-06-27 14:17:33 -0700 | [diff] [blame] | 754 | * Returns {@code true} if autofill is supported by the current device and |
| 755 | * is supported for this user. |
Felipe Leme | db04118 | 2017-04-21 17:33:38 -0700 | [diff] [blame] | 756 | * |
| 757 | * <p>Autofill is typically supported, but it could be unsupported in cases like: |
| 758 | * <ol> |
| 759 | * <li>Low-end devices. |
| 760 | * <li>Device policy rules that forbid its usage. |
| 761 | * </ol> |
| 762 | */ |
| 763 | public boolean isAutofillSupported() { |
| 764 | if (mService == null) return false; |
| 765 | |
| 766 | try { |
| 767 | return mService.isServiceSupported(mContext.getUserId()); |
| 768 | } catch (RemoteException e) { |
| 769 | throw e.rethrowFromSystemServer(); |
| 770 | } |
| 771 | } |
| 772 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 773 | private AutofillClient getClientLocked() { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 774 | if (mContext instanceof AutofillClient) { |
| 775 | return (AutofillClient) mContext; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 776 | } |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 777 | return null; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | /** @hide */ |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 781 | public void onAuthenticationResult(int authenticationId, Intent data) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 782 | if (!hasAutofillFeature()) { |
| 783 | return; |
| 784 | } |
Felipe Leme | 85d1c2d | 2017-04-21 08:56:04 -0700 | [diff] [blame] | 785 | // 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] | 786 | // handling the cases where it's not RESULT_OK: it works fine if the service does not |
| 787 | // set the EXTRA_AUTHENTICATION_RESULT extra, but it could cause weird results if the |
| 788 | // service set the extra and returned RESULT_CANCELED... |
| 789 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 790 | if (sDebug) Log.d(TAG, "onAuthenticationResult(): d=" + data); |
Felipe Leme | d633f07 | 2017-02-14 10:17:17 -0800 | [diff] [blame] | 791 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 792 | synchronized (mLock) { |
| 793 | if (mSessionId == NO_SESSION || data == null) { |
| 794 | return; |
| 795 | } |
| 796 | final Parcelable result = data.getParcelableExtra(EXTRA_AUTHENTICATION_RESULT); |
| 797 | final Bundle responseData = new Bundle(); |
| 798 | responseData.putParcelable(EXTRA_AUTHENTICATION_RESULT, result); |
| 799 | try { |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 800 | mService.setAuthenticationResult(responseData, mSessionId, authenticationId, |
| 801 | mContext.getUserId()); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 802 | } catch (RemoteException e) { |
| 803 | Log.e(TAG, "Error delivering authentication result", e); |
| 804 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 805 | } |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 806 | } |
| 807 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 808 | private static AutofillId getAutofillId(View view) { |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 809 | return new AutofillId(view.getAutofillViewId()); |
Felipe Leme | 0200d9e | 2017-01-24 15:10:26 -0800 | [diff] [blame] | 810 | } |
| 811 | |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 812 | private static AutofillId getAutofillId(View parent, int virtualId) { |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 813 | return new AutofillId(parent.getAutofillViewId(), virtualId); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 814 | } |
| 815 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 816 | private void startSessionLocked(@NonNull AutofillId id, @NonNull Rect bounds, |
| 817 | @NonNull AutofillValue value, int flags) { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 818 | if (sVerbose) { |
| 819 | Log.v(TAG, "startSessionLocked(): id=" + id + ", bounds=" + bounds + ", value=" + value |
Felipe Leme | 2ac463e | 2017-03-13 14:06:25 -0700 | [diff] [blame] | 820 | + ", flags=" + flags); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 821 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 822 | |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 823 | try { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 824 | mSessionId = mService.startSession(mContext.getActivityToken(), |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 825 | mServiceClient.asBinder(), id, bounds, value, mContext.getUserId(), |
Philip P. Moltmann | 7b77116 | 2017-03-03 17:22:57 -0800 | [diff] [blame] | 826 | mCallback != null, flags, mContext.getOpPackageName()); |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 827 | final AutofillClient client = getClientLocked(); |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 828 | if (client != null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 829 | client.autofillCallbackResetableStateAvailable(); |
Svet Ganov | 17db9dc | 2017-02-21 19:54:31 -0800 | [diff] [blame] | 830 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 831 | } catch (RemoteException e) { |
| 832 | throw e.rethrowFromSystemServer(); |
| 833 | } |
| 834 | } |
| 835 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 836 | private void finishSessionLocked() { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 837 | if (sVerbose) Log.v(TAG, "finishSessionLocked()"); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 838 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 839 | try { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 840 | mService.finishSession(mSessionId, mContext.getUserId()); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 841 | } catch (RemoteException e) { |
| 842 | throw e.rethrowFromSystemServer(); |
| 843 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 844 | |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 845 | mTrackedViews = null; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 846 | mSessionId = NO_SESSION; |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 847 | } |
| 848 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 849 | private void cancelSessionLocked() { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 850 | if (sVerbose) Log.v(TAG, "cancelSessionLocked()"); |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 851 | |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 852 | try { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 853 | mService.cancelSession(mSessionId, mContext.getUserId()); |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 854 | } catch (RemoteException e) { |
| 855 | throw e.rethrowFromSystemServer(); |
| 856 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 857 | |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 858 | resetSessionLocked(); |
| 859 | } |
| 860 | |
| 861 | private void resetSessionLocked() { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 862 | mSessionId = NO_SESSION; |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 863 | mTrackedViews = null; |
Svet Ganov | 2f8fb1f | 2017-03-13 00:21:04 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Felipe Leme | 0aa4c50 | 2017-04-26 12:36:01 -0700 | [diff] [blame] | 866 | private void updateSessionLocked(AutofillId id, Rect bounds, AutofillValue value, int action, |
| 867 | int flags) { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 868 | if (sVerbose && action != ACTION_VIEW_EXITED) { |
| 869 | Log.v(TAG, "updateSessionLocked(): id=" + id + ", bounds=" + bounds |
| 870 | + ", value=" + value + ", action=" + action + ", flags=" + flags); |
Felipe Leme | bab851c | 2017-02-03 18:45:08 -0800 | [diff] [blame] | 871 | } |
Felipe Leme | 0ab53dc | 2017-02-23 08:33:18 -0800 | [diff] [blame] | 872 | |
Felipe Leme | 7f33cd3 | 2017-05-11 10:10:49 -0700 | [diff] [blame] | 873 | boolean restartIfNecessary = (flags & FLAG_MANUAL_REQUEST) != 0; |
| 874 | |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 875 | try { |
Felipe Leme | 7f33cd3 | 2017-05-11 10:10:49 -0700 | [diff] [blame] | 876 | if (restartIfNecessary) { |
| 877 | final int newId = mService.updateOrRestartSession(mContext.getActivityToken(), |
| 878 | mServiceClient.asBinder(), id, bounds, value, mContext.getUserId(), |
| 879 | mCallback != null, flags, mContext.getOpPackageName(), mSessionId, action); |
| 880 | if (newId != mSessionId) { |
| 881 | if (sDebug) Log.d(TAG, "Session restarted: " + mSessionId + "=>" + newId); |
| 882 | mSessionId = newId; |
| 883 | final AutofillClient client = getClientLocked(); |
| 884 | if (client != null) { |
| 885 | client.autofillCallbackResetableStateAvailable(); |
| 886 | } |
| 887 | } |
| 888 | } else { |
| 889 | mService.updateSession(mSessionId, id, bounds, value, action, flags, |
| 890 | mContext.getUserId()); |
| 891 | } |
| 892 | |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 893 | } catch (RemoteException e) { |
| 894 | throw e.rethrowFromSystemServer(); |
| 895 | } |
| 896 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 897 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 898 | private void ensureServiceClientAddedIfNeededLocked() { |
| 899 | if (getClientLocked() == null) { |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 900 | return; |
| 901 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 902 | |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 903 | if (mServiceClient == null) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 904 | mServiceClient = new AutofillManagerClient(this); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 905 | try { |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 906 | final int flags = mService.addClient(mServiceClient, mContext.getUserId()); |
| 907 | mEnabled = (flags & FLAG_ADD_CLIENT_ENABLED) != 0; |
| 908 | sDebug = (flags & FLAG_ADD_CLIENT_DEBUG) != 0; |
| 909 | sVerbose = (flags & FLAG_ADD_CLIENT_VERBOSE) != 0; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 910 | } catch (RemoteException e) { |
| 911 | throw e.rethrowFromSystemServer(); |
| 912 | } |
| 913 | } |
| 914 | } |
| 915 | |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 916 | /** |
| 917 | * Registers a {@link AutofillCallback} to receive autofill events. |
| 918 | * |
| 919 | * @param callback callback to receive events. |
| 920 | */ |
| 921 | public void registerCallback(@Nullable AutofillCallback callback) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 922 | if (!hasAutofillFeature()) { |
| 923 | return; |
| 924 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 925 | synchronized (mLock) { |
| 926 | if (callback == null) return; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 927 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 928 | final boolean hadCallback = mCallback != null; |
| 929 | mCallback = callback; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 930 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 931 | if (!hadCallback) { |
| 932 | try { |
| 933 | mService.setHasCallback(mSessionId, mContext.getUserId(), true); |
| 934 | } catch (RemoteException e) { |
| 935 | throw e.rethrowFromSystemServer(); |
| 936 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | /** |
| 942 | * Unregisters a {@link AutofillCallback} to receive autofill events. |
| 943 | * |
| 944 | * @param callback callback to stop receiving events. |
| 945 | */ |
| 946 | public void unregisterCallback(@Nullable AutofillCallback callback) { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 947 | if (!hasAutofillFeature()) { |
| 948 | return; |
| 949 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 950 | synchronized (mLock) { |
| 951 | if (callback == null || mCallback == null || callback != mCallback) return; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 952 | |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 953 | mCallback = null; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 954 | |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 955 | try { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 956 | mService.setHasCallback(mSessionId, mContext.getUserId(), false); |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 957 | } catch (RemoteException e) { |
| 958 | throw e.rethrowFromSystemServer(); |
| 959 | } |
| 960 | } |
| 961 | } |
| 962 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 963 | private void requestShowFillUi(int sessionId, AutofillId id, int width, int height, |
| 964 | Rect anchorBounds, IAutofillWindowPresenter presenter) { |
| 965 | final View anchor = findView(id); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 966 | if (anchor == null) { |
| 967 | return; |
| 968 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 969 | |
| 970 | AutofillCallback callback = null; |
| 971 | synchronized (mLock) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 972 | if (mSessionId == sessionId) { |
| 973 | AutofillClient client = getClientLocked(); |
| 974 | |
| 975 | if (client != null) { |
| 976 | if (client.autofillCallbackRequestShowFillUi(anchor, width, height, |
| 977 | anchorBounds, presenter) && mCallback != null) { |
| 978 | callback = mCallback; |
| 979 | } |
| 980 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 981 | } |
| 982 | } |
| 983 | |
| 984 | if (callback != null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 985 | if (id.isVirtual()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 986 | callback.onAutofillEvent(anchor, id.getVirtualChildId(), |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 987 | AutofillCallback.EVENT_INPUT_SHOWN); |
| 988 | } else { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 989 | callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_SHOWN); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | } |
| 993 | |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 994 | private void authenticate(int sessionId, int authenticationId, IntentSender intent, |
| 995 | Intent fillInIntent) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 996 | synchronized (mLock) { |
| 997 | if (sessionId == mSessionId) { |
| 998 | AutofillClient client = getClientLocked(); |
| 999 | if (client != null) { |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 1000 | client.autofillCallbackAuthenticate(authenticationId, intent, fillInIntent); |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | } |
| 1005 | |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1006 | private void setState(boolean enabled, boolean resetSession, boolean resetClient) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1007 | synchronized (mLock) { |
| 1008 | mEnabled = enabled; |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1009 | if (!mEnabled || resetSession) { |
| 1010 | // Reset the session state |
| 1011 | resetSessionLocked(); |
| 1012 | } |
| 1013 | if (resetClient) { |
| 1014 | // Reset connection to system |
| 1015 | mServiceClient = null; |
| 1016 | } |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1020 | /** |
| 1021 | * Sets a view as autofilled if the current value is the {code targetValue}. |
| 1022 | * |
| 1023 | * @param view The view that is to be autofilled |
| 1024 | * @param targetValue The value we want to fill into view |
| 1025 | */ |
| 1026 | private void setAutofilledIfValuesIs(@NonNull View view, @Nullable AutofillValue targetValue) { |
| 1027 | AutofillValue currentValue = view.getAutofillValue(); |
| 1028 | if (Objects.equals(currentValue, targetValue)) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1029 | synchronized (mLock) { |
| 1030 | if (mLastAutofilledData == null) { |
| 1031 | mLastAutofilledData = new ParcelableMap(1); |
| 1032 | } |
| 1033 | mLastAutofilledData.put(getAutofillId(view), targetValue); |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1034 | } |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1035 | view.setAutofilled(true); |
| 1036 | } |
| 1037 | } |
| 1038 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1039 | private void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1040 | synchronized (mLock) { |
| 1041 | if (sessionId != mSessionId) { |
| 1042 | return; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1043 | } |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1044 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1045 | final AutofillClient client = getClientLocked(); |
| 1046 | if (client == null) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1047 | return; |
| 1048 | } |
| 1049 | |
| 1050 | final int itemCount = ids.size(); |
| 1051 | int numApplied = 0; |
| 1052 | ArrayMap<View, SparseArray<AutofillValue>> virtualValues = null; |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1053 | final View[] views = client.findViewsByAutofillIdTraversal(getViewIds(ids)); |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1054 | |
| 1055 | for (int i = 0; i < itemCount; i++) { |
| 1056 | final AutofillId id = ids.get(i); |
| 1057 | final AutofillValue value = values.get(i); |
| 1058 | final int viewId = id.getViewId(); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1059 | final View view = views[i]; |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1060 | if (view == null) { |
| 1061 | Log.w(TAG, "autofill(): no View with id " + viewId); |
| 1062 | continue; |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1063 | } |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1064 | if (id.isVirtual()) { |
| 1065 | if (virtualValues == null) { |
| 1066 | // Most likely there will be just one view with virtual children. |
| 1067 | virtualValues = new ArrayMap<>(1); |
| 1068 | } |
| 1069 | SparseArray<AutofillValue> valuesByParent = virtualValues.get(view); |
| 1070 | if (valuesByParent == null) { |
| 1071 | // We don't know the size yet, but usually it will be just a few fields... |
| 1072 | valuesByParent = new SparseArray<>(5); |
| 1073 | virtualValues.put(view, valuesByParent); |
| 1074 | } |
| 1075 | valuesByParent.put(id.getVirtualChildId(), value); |
| 1076 | } else { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1077 | // Mark the view as to be autofilled with 'value' |
| 1078 | if (mLastAutofilledData == null) { |
| 1079 | mLastAutofilledData = new ParcelableMap(itemCount - i); |
| 1080 | } |
| 1081 | mLastAutofilledData.put(id, value); |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1082 | |
| 1083 | view.autofill(value); |
| 1084 | |
| 1085 | // Set as autofilled if the values match now, e.g. when the value was updated |
| 1086 | // synchronously. |
| 1087 | // If autofill happens async, the view is set to autofilled in |
| 1088 | // notifyValueChanged. |
| 1089 | setAutofilledIfValuesIs(view, value); |
| 1090 | |
| 1091 | numApplied++; |
Philip P. Moltmann | b42d133 | 2017-03-27 09:55:30 -0700 | [diff] [blame] | 1092 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1093 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1094 | |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1095 | if (virtualValues != null) { |
| 1096 | for (int i = 0; i < virtualValues.size(); i++) { |
| 1097 | final View parent = virtualValues.keyAt(i); |
| 1098 | final SparseArray<AutofillValue> childrenValues = virtualValues.valueAt(i); |
| 1099 | parent.autofill(childrenValues); |
| 1100 | numApplied += childrenValues.size(); |
| 1101 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1102 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1103 | |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1104 | final LogMaker log = new LogMaker(MetricsProto.MetricsEvent.AUTOFILL_DATASET_APPLIED); |
| 1105 | log.addTaggedData(MetricsProto.MetricsEvent.FIELD_AUTOFILL_NUM_VALUES, itemCount); |
| 1106 | log.addTaggedData(MetricsProto.MetricsEvent.FIELD_AUTOFILL_NUM_VIEWS_FILLED, |
| 1107 | numApplied); |
| 1108 | mMetricsLogger.write(log); |
| 1109 | } |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1112 | /** |
| 1113 | * Set the tracked views. |
| 1114 | * |
| 1115 | * @param trackedIds The views to be tracked |
| 1116 | * @param saveOnAllViewsInvisible Finish the session once all tracked views are invisible. |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1117 | * @param fillableIds Views that might anchor FillUI. |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1118 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1119 | private void setTrackedViews(int sessionId, @Nullable AutofillId[] trackedIds, |
| 1120 | boolean saveOnAllViewsInvisible, @Nullable AutofillId[] fillableIds) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1121 | synchronized (mLock) { |
| 1122 | if (mEnabled && mSessionId == sessionId) { |
| 1123 | if (saveOnAllViewsInvisible) { |
| 1124 | mTrackedViews = new TrackedViews(trackedIds); |
| 1125 | } else { |
| 1126 | mTrackedViews = null; |
| 1127 | } |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1128 | if (fillableIds != null) { |
| 1129 | if (mFillableIds == null) { |
| 1130 | mFillableIds = new ArraySet<>(fillableIds.length); |
| 1131 | } |
| 1132 | for (AutofillId id : fillableIds) { |
| 1133 | mFillableIds.add(id); |
| 1134 | } |
| 1135 | if (sVerbose) { |
| 1136 | Log.v(TAG, "setTrackedViews(): fillableIds=" + fillableIds |
| 1137 | + ", mFillableIds" + mFillableIds); |
| 1138 | } |
| 1139 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1140 | } |
| 1141 | } |
| 1142 | } |
| 1143 | |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1144 | private void requestHideFillUi(AutofillId id) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1145 | final View anchor = findView(id); |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1146 | if (sVerbose) Log.v(TAG, "requestHideFillUi(" + id + "): anchor = " + anchor); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1147 | if (anchor == null) { |
| 1148 | return; |
| 1149 | } |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1150 | requestHideFillUi(id, anchor); |
| 1151 | } |
| 1152 | |
| 1153 | private void requestHideFillUi(AutofillId id, View anchor) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1154 | |
| 1155 | AutofillCallback callback = null; |
| 1156 | synchronized (mLock) { |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1157 | // We do not check the session id for two reasons: |
| 1158 | // 1. If local and remote session id are off sync the UI would be stuck shown |
| 1159 | // 2. There is a race between the user state being destroyed due the fill |
| 1160 | // service being uninstalled and the UI being dismissed. |
| 1161 | AutofillClient client = getClientLocked(); |
| 1162 | if (client != null) { |
| 1163 | if (client.autofillCallbackRequestHideFillUi() && mCallback != null) { |
| 1164 | callback = mCallback; |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1165 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | if (callback != null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1170 | if (id.isVirtual()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1171 | callback.onAutofillEvent(anchor, id.getVirtualChildId(), |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1172 | AutofillCallback.EVENT_INPUT_HIDDEN); |
| 1173 | } else { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1174 | callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_HIDDEN); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1179 | private void notifyNoFillUi(int sessionId, AutofillId id) { |
| 1180 | final View anchor = findView(id); |
| 1181 | if (anchor == null) { |
| 1182 | return; |
| 1183 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1184 | |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1185 | AutofillCallback callback = null; |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1186 | synchronized (mLock) { |
Philip P. Moltmann | e048a65 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1187 | if (mSessionId == sessionId && getClientLocked() != null) { |
| 1188 | callback = mCallback; |
| 1189 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | if (callback != null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1193 | if (id.isVirtual()) { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1194 | callback.onAutofillEvent(anchor, id.getVirtualChildId(), |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1195 | AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
| 1196 | } else { |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1197 | callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1198 | } |
Philip P. Moltmann | eab62ba | 2017-03-20 10:55:43 -0700 | [diff] [blame] | 1199 | |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1200 | } |
| 1201 | } |
| 1202 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1203 | /** |
| 1204 | * Get an array of viewIds from a List of {@link AutofillId}. |
| 1205 | * |
| 1206 | * @param autofillIds The autofill ids to convert |
| 1207 | * |
| 1208 | * @return The array of viewIds. |
| 1209 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1210 | // TODO: move to Helper as static method |
| 1211 | @NonNull private int[] getViewIds(@NonNull AutofillId[] autofillIds) { |
| 1212 | final int numIds = autofillIds.length; |
| 1213 | final int[] viewIds = new int[numIds]; |
| 1214 | for (int i = 0; i < numIds; i++) { |
| 1215 | viewIds[i] = autofillIds[i].getViewId(); |
| 1216 | } |
| 1217 | |
| 1218 | return viewIds; |
| 1219 | } |
| 1220 | |
| 1221 | // TODO: move to Helper as static method |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1222 | @NonNull private int[] getViewIds(@NonNull List<AutofillId> autofillIds) { |
| 1223 | final int numIds = autofillIds.size(); |
| 1224 | final int[] viewIds = new int[numIds]; |
| 1225 | for (int i = 0; i < numIds; i++) { |
| 1226 | viewIds[i] = autofillIds.get(i).getViewId(); |
| 1227 | } |
| 1228 | |
| 1229 | return viewIds; |
| 1230 | } |
| 1231 | |
| 1232 | /** |
| 1233 | * Find a single view by its id. |
| 1234 | * |
| 1235 | * @param autofillId The autofill id of the view |
| 1236 | * |
| 1237 | * @return The view or {@code null} if view was not found |
| 1238 | */ |
| 1239 | private View findView(@NonNull AutofillId autofillId) { |
| 1240 | final AutofillClient client = getClientLocked(); |
| 1241 | |
| 1242 | if (client == null) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1243 | return null; |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1244 | } |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1245 | |
Phil Weaver | 846cda93 | 2017-06-15 10:10:06 -0700 | [diff] [blame] | 1246 | return client.findViewByAutofillIdTraversal(autofillId.getViewId()); |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1247 | } |
| 1248 | |
Felipe Leme | bb81092 | 2017-04-25 15:54:06 -0700 | [diff] [blame] | 1249 | /** @hide */ |
| 1250 | public boolean hasAutofillFeature() { |
Svet Ganov | 43574b0 | 2017-04-12 09:25:20 -0700 | [diff] [blame] | 1251 | return mService != null; |
| 1252 | } |
| 1253 | |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1254 | private void post(Runnable runnable) { |
| 1255 | final AutofillClient client = getClientLocked(); |
| 1256 | if (client == null) { |
| 1257 | if (sVerbose) Log.v(TAG, "ignoring post() because client is null"); |
| 1258 | return; |
| 1259 | } |
| 1260 | client.runOnUiThread(runnable); |
| 1261 | } |
| 1262 | |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1263 | /** |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1264 | * View tracking information. Once all tracked views become invisible the session is finished. |
| 1265 | */ |
| 1266 | private class TrackedViews { |
| 1267 | /** Visible tracked views */ |
| 1268 | @Nullable private ArraySet<AutofillId> mVisibleTrackedIds; |
| 1269 | |
| 1270 | /** Invisible tracked views */ |
| 1271 | @Nullable private ArraySet<AutofillId> mInvisibleTrackedIds; |
| 1272 | |
| 1273 | /** |
| 1274 | * Check if set is null or value is in set. |
| 1275 | * |
| 1276 | * @param set The set or null (== empty set) |
| 1277 | * @param value The value that might be in the set |
| 1278 | * |
| 1279 | * @return {@code true} iff set is not empty and value is in set |
| 1280 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1281 | // TODO: move to Helper as static method |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1282 | private <T> boolean isInSet(@Nullable ArraySet<T> set, T value) { |
| 1283 | return set != null && set.contains(value); |
| 1284 | } |
| 1285 | |
| 1286 | /** |
| 1287 | * Add a value to a set. If set is null, create a new set. |
| 1288 | * |
| 1289 | * @param set The set or null (== empty set) |
| 1290 | * @param valueToAdd The value to add |
| 1291 | * |
| 1292 | * @return The set including the new value. If set was {@code null}, a set containing only |
| 1293 | * the new value. |
| 1294 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1295 | // TODO: move to Helper as static method |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1296 | @NonNull |
| 1297 | private <T> ArraySet<T> addToSet(@Nullable ArraySet<T> set, T valueToAdd) { |
| 1298 | if (set == null) { |
| 1299 | set = new ArraySet<>(1); |
| 1300 | } |
| 1301 | |
| 1302 | set.add(valueToAdd); |
| 1303 | |
| 1304 | return set; |
| 1305 | } |
| 1306 | |
| 1307 | /** |
| 1308 | * Remove a value from a set. |
| 1309 | * |
| 1310 | * @param set The set or null (== empty set) |
| 1311 | * @param valueToRemove The value to remove |
| 1312 | * |
| 1313 | * @return The set without the removed value. {@code null} if set was null, or is empty |
| 1314 | * after removal. |
| 1315 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1316 | // TODO: move to Helper as static method |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1317 | @Nullable |
| 1318 | private <T> ArraySet<T> removeFromSet(@Nullable ArraySet<T> set, T valueToRemove) { |
| 1319 | if (set == null) { |
| 1320 | return null; |
| 1321 | } |
| 1322 | |
| 1323 | set.remove(valueToRemove); |
| 1324 | |
| 1325 | if (set.isEmpty()) { |
| 1326 | return null; |
| 1327 | } |
| 1328 | |
| 1329 | return set; |
| 1330 | } |
| 1331 | |
| 1332 | /** |
| 1333 | * Set the tracked views. |
| 1334 | * |
| 1335 | * @param trackedIds The views to be tracked |
| 1336 | */ |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1337 | TrackedViews(@Nullable AutofillId[] trackedIds) { |
| 1338 | final AutofillClient client = getClientLocked(); |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1339 | if (trackedIds != null && client != null) { |
| 1340 | final boolean[] isVisible; |
| 1341 | |
| 1342 | if (client.isVisibleForAutofill()) { |
| 1343 | isVisible = client.getViewVisibility(getViewIds(trackedIds)); |
| 1344 | } else { |
| 1345 | // All false |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1346 | isVisible = new boolean[trackedIds.length]; |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1349 | final int numIds = trackedIds.length; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1350 | for (int i = 0; i < numIds; i++) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1351 | final AutofillId id = trackedIds[i]; |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1352 | |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1353 | if (isVisible[i]) { |
Philip P. Moltmann | e0e2871 | 2017-04-20 15:19:06 -0700 | [diff] [blame] | 1354 | mVisibleTrackedIds = addToSet(mVisibleTrackedIds, id); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1355 | } else { |
| 1356 | mInvisibleTrackedIds = addToSet(mInvisibleTrackedIds, id); |
| 1357 | } |
| 1358 | } |
| 1359 | } |
| 1360 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1361 | if (sVerbose) { |
| 1362 | Log.v(TAG, "TrackedViews(trackedIds=" + trackedIds + "): " |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1363 | + " mVisibleTrackedIds=" + mVisibleTrackedIds |
| 1364 | + " mInvisibleTrackedIds=" + mInvisibleTrackedIds); |
| 1365 | } |
| 1366 | |
| 1367 | if (mVisibleTrackedIds == null) { |
| 1368 | finishSessionLocked(); |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | /** |
| 1373 | * Called when a {@link View view's} visibility changes. |
| 1374 | * |
| 1375 | * @param view {@link View} that was exited. |
| 1376 | * @param isVisible visible if the view is visible in the view hierarchy. |
| 1377 | */ |
| 1378 | void notifyViewVisibilityChange(@NonNull View view, boolean isVisible) { |
| 1379 | AutofillId id = getAutofillId(view); |
| 1380 | AutofillClient client = getClientLocked(); |
| 1381 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1382 | if (sDebug) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1383 | Log.d(TAG, "notifyViewVisibilityChange(): id=" + id + " isVisible=" |
| 1384 | + isVisible); |
| 1385 | } |
| 1386 | |
| 1387 | if (client != null && client.isVisibleForAutofill()) { |
| 1388 | if (isVisible) { |
| 1389 | if (isInSet(mInvisibleTrackedIds, id)) { |
| 1390 | mInvisibleTrackedIds = removeFromSet(mInvisibleTrackedIds, id); |
| 1391 | mVisibleTrackedIds = addToSet(mVisibleTrackedIds, id); |
| 1392 | } |
| 1393 | } else { |
| 1394 | if (isInSet(mVisibleTrackedIds, id)) { |
| 1395 | mVisibleTrackedIds = removeFromSet(mVisibleTrackedIds, id); |
| 1396 | mInvisibleTrackedIds = addToSet(mInvisibleTrackedIds, id); |
| 1397 | } |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | if (mVisibleTrackedIds == null) { |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1402 | if (sVerbose) { |
| 1403 | Log.v(TAG, "No more visible ids. Invisibile = " + mInvisibleTrackedIds); |
| 1404 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1405 | finishSessionLocked(); |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | /** |
| 1410 | * Called once the client becomes visible. |
| 1411 | * |
| 1412 | * @see AutofillClient#isVisibleForAutofill() |
| 1413 | */ |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1414 | void onVisibleForAutofillLocked() { |
| 1415 | // 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] | 1416 | // hence update the visibility state for all views. |
| 1417 | AutofillClient client = getClientLocked(); |
| 1418 | ArraySet<AutofillId> updatedVisibleTrackedIds = null; |
| 1419 | ArraySet<AutofillId> updatedInvisibleTrackedIds = null; |
| 1420 | if (client != null) { |
| 1421 | if (mInvisibleTrackedIds != null) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1422 | final ArrayList<AutofillId> orderedInvisibleIds = |
| 1423 | new ArrayList<>(mInvisibleTrackedIds); |
| 1424 | final boolean[] isVisible = client.getViewVisibility( |
| 1425 | getViewIds(orderedInvisibleIds)); |
| 1426 | |
| 1427 | final int numInvisibleTrackedIds = orderedInvisibleIds.size(); |
| 1428 | for (int i = 0; i < numInvisibleTrackedIds; i++) { |
| 1429 | final AutofillId id = orderedInvisibleIds.get(i); |
| 1430 | if (isVisible[i]) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1431 | updatedVisibleTrackedIds = addToSet(updatedVisibleTrackedIds, id); |
| 1432 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1433 | if (sDebug) { |
| 1434 | Log.d(TAG, "onVisibleForAutofill() " + id + " became visible"); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1435 | } |
| 1436 | } else { |
| 1437 | updatedInvisibleTrackedIds = addToSet(updatedInvisibleTrackedIds, id); |
| 1438 | } |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | if (mVisibleTrackedIds != null) { |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1443 | final ArrayList<AutofillId> orderedVisibleIds = |
| 1444 | new ArrayList<>(mVisibleTrackedIds); |
| 1445 | final boolean[] isVisible = client.getViewVisibility( |
| 1446 | getViewIds(orderedVisibleIds)); |
| 1447 | |
| 1448 | final int numVisibleTrackedIds = orderedVisibleIds.size(); |
| 1449 | for (int i = 0; i < numVisibleTrackedIds; i++) { |
| 1450 | final AutofillId id = orderedVisibleIds.get(i); |
| 1451 | |
| 1452 | if (isVisible[i]) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1453 | updatedVisibleTrackedIds = addToSet(updatedVisibleTrackedIds, id); |
| 1454 | } else { |
| 1455 | updatedInvisibleTrackedIds = addToSet(updatedInvisibleTrackedIds, id); |
| 1456 | |
Felipe Leme | 9f9ee25 | 2017-04-27 13:56:22 -0700 | [diff] [blame] | 1457 | if (sDebug) { |
| 1458 | Log.d(TAG, "onVisibleForAutofill() " + id + " became invisible"); |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1459 | } |
| 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | mInvisibleTrackedIds = updatedInvisibleTrackedIds; |
| 1465 | mVisibleTrackedIds = updatedVisibleTrackedIds; |
| 1466 | } |
| 1467 | |
| 1468 | if (mVisibleTrackedIds == null) { |
| 1469 | finishSessionLocked(); |
| 1470 | } |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | /** |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1475 | * Callback for auto-fill related events. |
| 1476 | * |
| 1477 | * <p>Typically used for applications that display their own "auto-complete" views, so they can |
| 1478 | * enable / disable such views when the auto-fill UI affordance is shown / hidden. |
| 1479 | */ |
| 1480 | public abstract static class AutofillCallback { |
| 1481 | |
| 1482 | /** @hide */ |
| 1483 | @IntDef({EVENT_INPUT_SHOWN, EVENT_INPUT_HIDDEN}) |
| 1484 | @Retention(RetentionPolicy.SOURCE) |
| 1485 | public @interface AutofillEventType {} |
| 1486 | |
| 1487 | /** |
| 1488 | * The auto-fill input UI affordance associated with the view was shown. |
| 1489 | * |
| 1490 | * <p>If the view provides its own auto-complete UI affordance and its currently shown, it |
| 1491 | * should be hidden upon receiving this event. |
| 1492 | */ |
| 1493 | public static final int EVENT_INPUT_SHOWN = 1; |
| 1494 | |
| 1495 | /** |
| 1496 | * The auto-fill input UI affordance associated with the view was hidden. |
| 1497 | * |
| 1498 | * <p>If the view provides its own auto-complete UI affordance that was hidden upon a |
| 1499 | * {@link #EVENT_INPUT_SHOWN} event, it could be shown again now. |
| 1500 | */ |
| 1501 | public static final int EVENT_INPUT_HIDDEN = 2; |
| 1502 | |
| 1503 | /** |
Felipe Leme | 24aae15 | 2017-03-15 12:33:01 -0700 | [diff] [blame] | 1504 | * The auto-fill input UI affordance associated with the view won't be shown because |
| 1505 | * autofill is not available. |
| 1506 | * |
| 1507 | * <p>If the view provides its own auto-complete UI affordance but was not displaying it |
| 1508 | * to avoid flickering, it could shown it upon receiving this event. |
| 1509 | */ |
| 1510 | public static final int EVENT_INPUT_UNAVAILABLE = 3; |
| 1511 | |
| 1512 | /** |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1513 | * Called after a change in the autofill state associated with a view. |
| 1514 | * |
| 1515 | * @param view view associated with the change. |
| 1516 | * |
| 1517 | * @param event currently either {@link #EVENT_INPUT_SHOWN} or {@link #EVENT_INPUT_HIDDEN}. |
| 1518 | */ |
Felipe Leme | 81f01d9 | 2017-03-16 17:13:25 -0700 | [diff] [blame] | 1519 | public void onAutofillEvent(@NonNull View view, @AutofillEventType int event) { |
| 1520 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1521 | |
| 1522 | /** |
| 1523 | * Called after a change in the autofill state associated with a virtual view. |
| 1524 | * |
| 1525 | * @param view parent view associated with the change. |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 1526 | * @param virtualId id identifying the virtual child inside the parent view. |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1527 | * |
| 1528 | * @param event currently either {@link #EVENT_INPUT_SHOWN} or {@link #EVENT_INPUT_HIDDEN}. |
| 1529 | */ |
Felipe Leme | 6dcec87 | 2017-05-25 11:24:23 -0700 | [diff] [blame] | 1530 | public void onAutofillEvent(@NonNull View view, int virtualId, |
| 1531 | @AutofillEventType int event) { |
Felipe Leme | 81f01d9 | 2017-03-16 17:13:25 -0700 | [diff] [blame] | 1532 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1533 | } |
| 1534 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1535 | private static final class AutofillManagerClient extends IAutoFillManagerClient.Stub { |
| 1536 | private final WeakReference<AutofillManager> mAfm; |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1537 | |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1538 | AutofillManagerClient(AutofillManager autofillManager) { |
| 1539 | mAfm = new WeakReference<>(autofillManager); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | @Override |
Svet Ganov | 48f10a2 | 2017-04-26 18:49:30 -0700 | [diff] [blame] | 1543 | public void setState(boolean enabled, boolean resetSession, boolean resetClient) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1544 | final AutofillManager afm = mAfm.get(); |
| 1545 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1546 | afm.post(() -> afm.setState(enabled, resetSession, resetClient)); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | |
| 1550 | @Override |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1551 | public void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1552 | final AutofillManager afm = mAfm.get(); |
| 1553 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1554 | afm.post(() -> afm.autofill(sessionId, ids, values)); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | @Override |
Svetoslav Ganov | a9379d0 | 2017-05-09 17:40:24 -0700 | [diff] [blame] | 1559 | public void authenticate(int sessionId, int authenticationId, IntentSender intent, |
| 1560 | Intent fillInIntent) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1561 | final AutofillManager afm = mAfm.get(); |
| 1562 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1563 | afm.post(() -> afm.authenticate(sessionId, authenticationId, intent, fillInIntent)); |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1564 | } |
| 1565 | } |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1566 | |
| 1567 | @Override |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1568 | public void requestShowFillUi(int sessionId, AutofillId id, int width, int height, |
| 1569 | Rect anchorBounds, IAutofillWindowPresenter presenter) { |
Felipe Leme | 640f30a | 2017-03-06 15:44:06 -0800 | [diff] [blame] | 1570 | final AutofillManager afm = mAfm.get(); |
| 1571 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1572 | afm.post(() -> afm.requestShowFillUi(sessionId, id, width, height, anchorBounds, |
| 1573 | presenter)); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | @Override |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1578 | public void requestHideFillUi(int sessionId, AutofillId id) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1579 | final AutofillManager afm = mAfm.get(); |
| 1580 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1581 | afm.post(() -> afm.requestHideFillUi(id)); |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | @Override |
Philip P. Moltmann | 134cee2 | 2017-05-06 11:28:38 -0700 | [diff] [blame] | 1586 | public void notifyNoFillUi(int sessionId, AutofillId id) { |
Felipe Leme | 4753bb0 | 2017-03-22 20:24:00 -0700 | [diff] [blame] | 1587 | final AutofillManager afm = mAfm.get(); |
| 1588 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1589 | afm.post(() -> afm.notifyNoFillUi(sessionId, id)); |
Felipe Leme | e6010f2 | 2017-03-03 11:19:51 -0800 | [diff] [blame] | 1590 | } |
| 1591 | } |
Svet Ganov | c3d1c85 | 2017-04-12 22:34:28 -0700 | [diff] [blame] | 1592 | |
| 1593 | @Override |
| 1594 | public void startIntentSender(IntentSender intentSender) { |
| 1595 | final AutofillManager afm = mAfm.get(); |
| 1596 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1597 | afm.post(() -> { |
Svet Ganov | c3d1c85 | 2017-04-12 22:34:28 -0700 | [diff] [blame] | 1598 | try { |
| 1599 | afm.mContext.startIntentSender(intentSender, null, 0, 0, 0); |
| 1600 | } catch (IntentSender.SendIntentException e) { |
| 1601 | Log.e(TAG, "startIntentSender() failed for intent:" + intentSender, e); |
| 1602 | } |
| 1603 | }); |
| 1604 | } |
| 1605 | } |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1606 | |
| 1607 | @Override |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1608 | public void setTrackedViews(int sessionId, AutofillId[] ids, |
| 1609 | boolean saveOnAllViewsInvisible, AutofillId[] fillableIds) { |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1610 | final AutofillManager afm = mAfm.get(); |
| 1611 | if (afm != null) { |
Felipe Leme | 9876a6f | 2017-05-30 15:47:28 -0700 | [diff] [blame] | 1612 | afm.post(() -> |
Felipe Leme | 27e2022 | 2017-05-18 15:24:11 -0700 | [diff] [blame] | 1613 | afm.setTrackedViews(sessionId, ids, saveOnAllViewsInvisible, fillableIds) |
Philip P. Moltmann | 494c3f5 | 2017-04-11 10:13:33 -0700 | [diff] [blame] | 1614 | ); |
| 1615 | } |
| 1616 | } |
Svet Ganov | 782043c | 2017-02-11 00:52:02 +0000 | [diff] [blame] | 1617 | } |
Felipe Leme | 3461d3c | 2017-01-19 08:54:55 -0800 | [diff] [blame] | 1618 | } |