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