| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view.autofill; |
| 18 |
|
| 19 |
import static android.service.autofill.FillRequest.FLAG_IME_SHOWING; |
| 20 |
import static android.service.autofill.FillRequest.FLAG_MANUAL_REQUEST; |
| 21 |
import static android.service.autofill.FillRequest.FLAG_PASSWORD_INPUT_TYPE; |
| 22 |
import static android.service.autofill.FillRequest.FLAG_RESET_FILL_DIALOG_STATE; |
| 23 |
import static android.service.autofill.FillRequest.FLAG_SUPPORTS_FILL_DIALOG; |
| 24 |
import static android.service.autofill.FillRequest.FLAG_VIEW_NOT_FOCUSED; |
| 25 |
import static android.view.ContentInfo.SOURCE_AUTOFILL; |
| 26 |
import static android.view.autofill.Helper.sDebug; |
| 27 |
import static android.view.autofill.Helper.sVerbose; |
| 28 |
import static android.view.autofill.Helper.toList; |
| 29 |
|
| 30 |
import android.accessibilityservice.AccessibilityServiceInfo; |
| 31 |
import android.annotation.IntDef; |
| 32 |
import android.annotation.NonNull; |
| 33 |
import android.annotation.Nullable; |
| 34 |
import android.annotation.RequiresFeature; |
| 35 |
import android.annotation.SystemApi; |
| 36 |
import android.annotation.SystemService; |
| 37 |
import android.annotation.TestApi; |
| 38 |
import android.app.assist.AssistStructure.ViewNode; |
| 39 |
import android.app.assist.AssistStructure.ViewNodeBuilder; |
| 40 |
import android.app.assist.AssistStructure.ViewNodeParcelable; |
| 41 |
import android.content.AutofillOptions; |
| 42 |
import android.content.ClipData; |
| 43 |
import android.content.ComponentName; |
| 44 |
import android.content.Context; |
| 45 |
import android.content.Intent; |
| 46 |
import android.content.IntentSender; |
| 47 |
import android.content.pm.PackageManager; |
| 48 |
import android.content.pm.ResolveInfo; |
| 49 |
import android.graphics.Rect; |
| 50 |
import android.metrics.LogMaker; |
| 51 |
import android.os.Build; |
| 52 |
import android.os.Bundle; |
| 53 |
import android.os.Handler; |
| 54 |
import android.os.IBinder; |
| 55 |
import android.os.Looper; |
| 56 |
import android.os.Parcelable; |
| 57 |
import android.os.RemoteException; |
| 58 |
import android.os.SystemClock; |
| 59 |
import android.provider.DeviceConfig; |
| 60 |
import android.service.autofill.AutofillService; |
| 61 |
import android.service.autofill.FillEventHistory; |
| 62 |
import android.service.autofill.UserData; |
| 63 |
import android.text.TextUtils; |
| 64 |
import android.util.ArrayMap; |
| 65 |
import android.util.ArraySet; |
| 66 |
import android.util.DebugUtils; |
| 67 |
import android.util.Log; |
| 68 |
import android.util.Slog; |
| 69 |
import android.util.SparseArray; |
| 70 |
import android.view.Choreographer; |
| 71 |
import android.view.ContentInfo; |
| 72 |
import android.view.KeyEvent; |
| 73 |
import android.view.View; |
| 74 |
import android.view.ViewRootImpl; |
| 75 |
import android.view.WindowInsets; |
| 76 |
import android.view.WindowManager; |
| 77 |
import android.view.accessibility.AccessibilityEvent; |
| 78 |
import android.view.accessibility.AccessibilityManager; |
| 79 |
import android.view.accessibility.AccessibilityNodeInfo; |
| 80 |
import android.view.accessibility.AccessibilityNodeProvider; |
| 81 |
import android.view.accessibility.AccessibilityWindowInfo; |
| 82 |
import android.view.inputmethod.InputMethodManager; |
| 83 |
import android.widget.EditText; |
| 84 |
import android.widget.TextView; |
| 85 |
|
| 86 |
import com.android.internal.annotations.GuardedBy; |
| 87 |
import com.android.internal.logging.MetricsLogger; |
| 88 |
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
| 89 |
import com.android.internal.os.IResultReceiver; |
| 90 |
import com.android.internal.util.ArrayUtils; |
| 91 |
import com.android.internal.util.SyncResultReceiver; |
| 92 |
|
| 93 |
import org.xmlpull.v1.XmlPullParserException; |
| 94 |
|
| 95 |
import java.io.IOException; |
| 96 |
import java.io.PrintWriter; |
| 97 |
import java.lang.annotation.Retention; |
| 98 |
import java.lang.annotation.RetentionPolicy; |
| 99 |
import java.lang.ref.WeakReference; |
| 100 |
import java.util.ArrayList; |
| 101 |
import java.util.Arrays; |
| 102 |
import java.util.Collections; |
| 103 |
import java.util.List; |
| 104 |
import java.util.Objects; |
| 105 |
import java.util.Set; |
| 106 |
import java.util.concurrent.atomic.AtomicBoolean; |
| 107 |
|
| 108 |
import sun.misc.Cleaner; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
@SystemService(Context.AUTOFILL_MANAGER_SERVICE) |
| 180 |
@RequiresFeature(PackageManager.FEATURE_AUTOFILL) |
| 181 |
public final class AutofillManager { |
| 182 |
|
| 183 |
private static final String TAG = "AutofillManager"; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
public static final String EXTRA_ASSIST_STRUCTURE = |
| 192 |
"android.view.autofill.extra.ASSIST_STRUCTURE"; |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
public static final String EXTRA_AUTHENTICATION_RESULT = |
| 205 |
"android.view.autofill.extra.AUTHENTICATION_RESULT"; |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
public static final String EXTRA_AUTHENTICATION_RESULT_EPHEMERAL_DATASET = |
| 233 |
"android.view.autofill.extra.AUTHENTICATION_RESULT_EPHEMERAL_DATASET"; |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
public static final String EXTRA_CLIENT_STATE = |
| 255 |
"android.view.autofill.extra.CLIENT_STATE"; |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
public static final String EXTRA_INLINE_SUGGESTIONS_REQUEST = |
| 267 |
"android.view.autofill.extra.INLINE_SUGGESTIONS_REQUEST"; |
| 268 |
|
| 269 |
|
| 270 |
public static final String EXTRA_RESTORE_SESSION_TOKEN = |
| 271 |
"android.view.autofill.extra.RESTORE_SESSION_TOKEN"; |
| 272 |
|
| 273 |
|
| 274 |
public static final String EXTRA_RESTORE_CROSS_ACTIVITY = |
| 275 |
"android.view.autofill.extra.RESTORE_CROSS_ACTIVITY"; |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
public static final String EXTRA_AUGMENTED_AUTOFILL_CLIENT = |
| 283 |
"android.view.autofill.extra.AUGMENTED_AUTOFILL_CLIENT"; |
| 284 |
|
| 285 |
private static final String SESSION_ID_TAG = "android:sessionId"; |
| 286 |
private static final String STATE_TAG = "android:state"; |
| 287 |
private static final String LAST_AUTOFILLED_DATA_TAG = "android:lastAutoFilledData"; |
| 288 |
|
| 289 |
public static final int ACTION_START_SESSION = 1; |
| 290 |
public static final int ACTION_VIEW_ENTERED = 2; |
| 291 |
public static final int ACTION_VIEW_EXITED = 3; |
| 292 |
public static final int ACTION_VALUE_CHANGED = 4; |
| 293 |
public static final int ACTION_RESPONSE_EXPIRED = 5; |
| 294 |
|
| 295 |
public static final int NO_LOGGING = 0; |
| 296 |
public static final int FLAG_ADD_CLIENT_ENABLED = 0x1; |
| 297 |
public static final int FLAG_ADD_CLIENT_DEBUG = 0x2; |
| 298 |
public static final int FLAG_ADD_CLIENT_VERBOSE = 0x4; |
| 299 |
public static final int FLAG_ADD_CLIENT_ENABLED_FOR_AUGMENTED_AUTOFILL_ONLY = 0x8; |
| 300 |
|
| 301 |
|
| 302 |
public static final int RECEIVER_FLAG_SESSION_FOR_AUGMENTED_AUTOFILL_ONLY = 0x1; |
| 303 |
|
| 304 |
|
| 305 |
public static final int DEFAULT_LOGGING_LEVEL = Build.IS_DEBUGGABLE |
| 306 |
? AutofillManager.FLAG_ADD_CLIENT_DEBUG |
| 307 |
: AutofillManager.NO_LOGGING; |
| 308 |
|
| 309 |
|
| 310 |
public static final int DEFAULT_MAX_PARTITIONS_SIZE = 10; |
| 311 |
|
| 312 |
|
| 313 |
private static final int AUTHENTICATION_ID_DATASET_ID_MASK = 0xFFFF; |
| 314 |
|
| 315 |
private static final int AUTHENTICATION_ID_DATASET_ID_SHIFT = 16; |
| 316 |
|
| 317 |
public static final int AUTHENTICATION_ID_DATASET_ID_UNDEFINED = 0xFFFF; |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
public static final int PENDING_UI_OPERATION_CANCEL = 1; |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
public static final int PENDING_UI_OPERATION_RESTORE = 2; |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
public static final int STATE_UNKNOWN = 0; |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
public static final int STATE_ACTIVE = 1; |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
public static final int STATE_FINISHED = 2; |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
public static final int STATE_SHOWING_SAVE_UI = 3; |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
public static final int STATE_DISABLED_BY_SERVICE = 4; |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
public static final int STATE_UNKNOWN_COMPAT_MODE = 5; |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
public static final int STATE_UNKNOWN_FAILED = 6; |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
public static final int FC_SERVICE_TIMEOUT = 5000; |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
private static final int SYNC_CALLS_TIMEOUT_MS = 5000; |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
@TestApi |
| 414 |
public static final int MAX_TEMP_AUGMENTED_SERVICE_DURATION_MS = 1_000 * 60 * 2; |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
@TestApi |
| 422 |
public static final int FLAG_SMART_SUGGESTION_OFF = 0x0; |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
@TestApi |
| 431 |
public static final int FLAG_SMART_SUGGESTION_SYSTEM = 0x1; |
| 432 |
|
| 433 |
|
| 434 |
@IntDef(flag = false, value = { FLAG_SMART_SUGGESTION_OFF, FLAG_SMART_SUGGESTION_SYSTEM }) |
| 435 |
@Retention(RetentionPolicy.SOURCE) |
| 436 |
public @interface SmartSuggestionMode {} |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
@TestApi |
| 445 |
public static final String DEVICE_CONFIG_AUTOFILL_SMART_SUGGESTION_SUPPORTED_MODES = |
| 446 |
"smart_suggestion_supported_modes"; |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
public static final String DEVICE_CONFIG_AUGMENTED_SERVICE_IDLE_UNBIND_TIMEOUT = |
| 456 |
"augmented_service_idle_unbind_timeout"; |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
public static final String DEVICE_CONFIG_AUGMENTED_SERVICE_REQUEST_TIMEOUT = |
| 464 |
"augmented_service_request_timeout"; |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
@TestApi |
| 481 |
public static final String DEVICE_CONFIG_AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES = |
| 482 |
"compat_mode_allowed_packages"; |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
@TestApi |
| 490 |
public static final String DEVICE_CONFIG_AUTOFILL_DIALOG_ENABLED = |
| 491 |
"autofill_dialog_enabled"; |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
public static final String DEVICE_CONFIG_AUTOFILL_DIALOG_HINTS = |
| 508 |
"autofill_dialog_hints"; |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
public static final String DEVICE_CONFIG_AUTOFILL_TOOLTIP_SHOW_UP_DELAY = |
| 516 |
"autofill_inline_tooltip_first_show_delay"; |
| 517 |
|
| 518 |
private static final String DIALOG_HINTS_DELIMITER = ":"; |
| 519 |
|
| 520 |
|
| 521 |
public static final int RESULT_OK = 0; |
| 522 |
|
| 523 |
public static final int RESULT_CODE_NOT_SERVICE = -1; |
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
@IntDef(prefix = { "COMMIT_REASON_" }, value = { |
| 536 |
COMMIT_REASON_UNKNOWN, |
| 537 |
COMMIT_REASON_ACTIVITY_FINISHED, |
| 538 |
COMMIT_REASON_VIEW_COMMITTED, |
| 539 |
COMMIT_REASON_VIEW_CLICKED, |
| 540 |
COMMIT_REASON_VIEW_CHANGED |
| 541 |
}) |
| 542 |
@Retention(RetentionPolicy.SOURCE) |
| 543 |
public @interface AutofillCommitReason {} |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
public static final int COMMIT_REASON_UNKNOWN = 0; |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
public static final int COMMIT_REASON_ACTIVITY_FINISHED = 1; |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
public static final int COMMIT_REASON_VIEW_COMMITTED = 2; |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
public static final int COMMIT_REASON_VIEW_CLICKED = 3; |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
public static final int COMMIT_REASON_VIEW_CHANGED = 4; |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
public static int makeAuthenticationId(int requestId, int datasetId) { |
| 589 |
return (requestId << AUTHENTICATION_ID_DATASET_ID_SHIFT) |
| 590 |
| (datasetId & AUTHENTICATION_ID_DATASET_ID_MASK); |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
public static int getRequestIdFromAuthenticationId(int authRequestId) { |
| 601 |
return (authRequestId >> AUTHENTICATION_ID_DATASET_ID_SHIFT); |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
public static int getDatasetIdFromAuthenticationId(int authRequestId) { |
| 612 |
return (authRequestId & AUTHENTICATION_ID_DATASET_ID_MASK); |
| 613 |
} |
| 614 |
|
| 615 |
private final MetricsLogger mMetricsLogger = new MetricsLogger(); |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
public static final int NO_SESSION = Integer.MAX_VALUE; |
| 622 |
|
| 623 |
private static final boolean HAS_FILL_DIALOG_UI_FEATURE_DEFAULT = false; |
| 624 |
private static final String FILL_DIALOG_ENABLED_DEFAULT_HINTS = ""; |
| 625 |
|
| 626 |
private final IAutoFillManager mService; |
| 627 |
|
| 628 |
private final Object mLock = new Object(); |
| 629 |
|
| 630 |
@GuardedBy("mLock") |
| 631 |
private IAutoFillManagerClient mServiceClient; |
| 632 |
|
| 633 |
@GuardedBy("mLock") |
| 634 |
private Cleaner mServiceClientCleaner; |
| 635 |
|
| 636 |
@GuardedBy("mLock") |
| 637 |
private IAugmentedAutofillManagerClient mAugmentedAutofillServiceClient; |
| 638 |
|
| 639 |
@GuardedBy("mLock") |
| 640 |
private AutofillCallback mCallback; |
| 641 |
|
| 642 |
private final Context mContext; |
| 643 |
|
| 644 |
@GuardedBy("mLock") |
| 645 |
private int mSessionId = NO_SESSION; |
| 646 |
|
| 647 |
@GuardedBy("mLock") |
| 648 |
private int mState = STATE_UNKNOWN; |
| 649 |
|
| 650 |
@GuardedBy("mLock") |
| 651 |
private boolean mEnabled; |
| 652 |
|
| 653 |
|
| 654 |
@GuardedBy("mLock") |
| 655 |
@Nullable private ParcelableMap mLastAutofilledData; |
| 656 |
|
| 657 |
|
| 658 |
@GuardedBy("mLock") |
| 659 |
@Nullable private TrackedViews mTrackedViews; |
| 660 |
|
| 661 |
|
| 662 |
@GuardedBy("mLock") |
| 663 |
@Nullable private ArraySet<AutofillId> mFillableIds; |
| 664 |
|
| 665 |
|
| 666 |
@Nullable private AutofillId mIdShownFillUi; |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
@GuardedBy("mLock") |
| 673 |
@Nullable private ArraySet<AutofillId> mEnteredIds; |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
@GuardedBy("mLock") |
| 680 |
@Nullable private Set<AutofillId> mEnteredForAugmentedAutofillIds; |
| 681 |
|
| 682 |
|
| 683 |
@GuardedBy("mLock") |
| 684 |
@Nullable private AutofillId mSaveTriggerId; |
| 685 |
|
| 686 |
|
| 687 |
@GuardedBy("mLock") |
| 688 |
private boolean mOnInvisibleCalled; |
| 689 |
|
| 690 |
|
| 691 |
@GuardedBy("mLock") |
| 692 |
private boolean mSaveOnFinish; |
| 693 |
|
| 694 |
|
| 695 |
@GuardedBy("mLock") |
| 696 |
private CompatibilityBridge mCompatibilityBridge; |
| 697 |
|
| 698 |
@Nullable |
| 699 |
private final AutofillOptions mOptions; |
| 700 |
|
| 701 |
|
| 702 |
@GuardedBy("mLock") |
| 703 |
private boolean mForAugmentedAutofillOnly; |
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
@GuardedBy("mLock") |
| 710 |
private boolean mEnabledForAugmentedAutofillOnly; |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
private AtomicBoolean mIsFillRequested; |
| 722 |
|
| 723 |
@Nullable private List<AutofillId> mFillDialogTriggerIds; |
| 724 |
|
| 725 |
private final boolean mIsFillDialogEnabled; |
| 726 |
|
| 727 |
|
| 728 |
private boolean mShowAutofillDialogCalled = false; |
| 729 |
|
| 730 |
private final String[] mFillDialogEnabledHints; |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
private final ArraySet<AutofillId> mAllTrackedViews = new ArraySet<>(); |
| 735 |
|
| 736 |
|
| 737 |
public interface AutofillClient { |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
void autofillClientAuthenticate(int authenticationId, IntentSender intent, |
| 746 |
Intent fillInIntent, boolean authenticateInline); |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
void autofillClientResetableStateAvailable(); |
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
boolean autofillClientRequestShowFillUi(@NonNull View anchor, int width, int height, |
| 764 |
@Nullable Rect virtualBounds, IAutofillWindowPresenter presenter); |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
void autofillClientDispatchUnhandledKey(@NonNull View anchor, @NonNull KeyEvent keyEvent); |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
boolean autofillClientRequestHideFillUi(); |
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
boolean autofillClientIsFillUiShowing(); |
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
@NonNull boolean[] autofillClientGetViewVisibility(@NonNull AutofillId[] autofillIds); |
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
boolean autofillClientIsVisibleForAutofill(); |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
boolean isDisablingEnterExitEventForAutofill(); |
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
@NonNull View[] autofillClientFindViewsByAutofillIdTraversal( |
| 814 |
@NonNull AutofillId[] autofillIds); |
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
@Nullable View autofillClientFindViewByAutofillIdTraversal(@NonNull AutofillId autofillId); |
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
@Nullable View autofillClientFindViewByAccessibilityIdTraversal(int viewId, int windowId); |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
void autofillClientRunOnUiThread(Runnable action); |
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
ComponentName autofillClientGetComponentName(); |
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
@Nullable IBinder autofillClientGetActivityToken(); |
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
boolean autofillClientIsCompatibilityModeEnabled(); |
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
@Nullable AutofillId autofillClientGetNextAutofillId(); |
| 864 |
} |
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
public AutofillManager(Context context, IAutoFillManager service) { |
| 870 |
mContext = Objects.requireNonNull(context, "context cannot be null"); |
| 871 |
mService = service; |
| 872 |
mOptions = context.getAutofillOptions(); |
| 873 |
mIsFillRequested = new AtomicBoolean(false); |
| 874 |
|
| 875 |
mIsFillDialogEnabled = DeviceConfig.getBoolean( |
| 876 |
DeviceConfig.NAMESPACE_AUTOFILL, |
| 877 |
DEVICE_CONFIG_AUTOFILL_DIALOG_ENABLED, |
| 878 |
HAS_FILL_DIALOG_UI_FEATURE_DEFAULT); |
| 879 |
mFillDialogEnabledHints = getFillDialogEnabledHints(); |
| 880 |
if (sDebug) { |
| 881 |
Log.d(TAG, "Fill dialog is enabled:" + mIsFillDialogEnabled |
| 882 |
+ ", hints=" + Arrays.toString(mFillDialogEnabledHints)); |
| 883 |
} |
| 884 |
|
| 885 |
if (mOptions != null) { |
| 886 |
sDebug = (mOptions.loggingLevel & FLAG_ADD_CLIENT_DEBUG) != 0; |
| 887 |
sVerbose = (mOptions.loggingLevel & FLAG_ADD_CLIENT_VERBOSE) != 0; |
| 888 |
} |
| 889 |
} |
| 890 |
|
| 891 |
private String[] getFillDialogEnabledHints() { |
| 892 |
final String dialogHints = DeviceConfig.getString( |
| 893 |
DeviceConfig.NAMESPACE_AUTOFILL, |
| 894 |
DEVICE_CONFIG_AUTOFILL_DIALOG_HINTS, |
| 895 |
FILL_DIALOG_ENABLED_DEFAULT_HINTS); |
| 896 |
if (TextUtils.isEmpty(dialogHints)) { |
| 897 |
return new String[0]; |
| 898 |
} |
| 899 |
|
| 900 |
return ArrayUtils.filter(dialogHints.split(DIALOG_HINTS_DELIMITER), String[]::new, |
| 901 |
(str) -> !TextUtils.isEmpty(str)); |
| 902 |
} |
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
public void enableCompatibilityMode() { |
| 908 |
synchronized (mLock) { |
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
if (sDebug) { |
| 914 |
Slog.d(TAG, "creating CompatibilityBridge for " + mContext); |
| 915 |
} |
| 916 |
mCompatibilityBridge = new CompatibilityBridge(); |
| 917 |
} |
| 918 |
} |
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
public void onCreate(Bundle savedInstanceState) { |
| 928 |
if (!hasAutofillFeature()) { |
| 929 |
return; |
| 930 |
} |
| 931 |
synchronized (mLock) { |
| 932 |
mLastAutofilledData = savedInstanceState.getParcelable(LAST_AUTOFILLED_DATA_TAG); |
| 933 |
|
| 934 |
if (isActiveLocked()) { |
| 935 |
Log.w(TAG, "New session was started before onCreate()"); |
| 936 |
return; |
| 937 |
} |
| 938 |
|
| 939 |
mSessionId = savedInstanceState.getInt(SESSION_ID_TAG, NO_SESSION); |
| 940 |
mState = savedInstanceState.getInt(STATE_TAG, STATE_UNKNOWN); |
| 941 |
|
| 942 |
if (mSessionId != NO_SESSION) { |
| 943 |
final boolean clientAdded = tryAddServiceClientIfNeededLocked(); |
| 944 |
|
| 945 |
final AutofillClient client = getClient(); |
| 946 |
if (client != null) { |
| 947 |
final SyncResultReceiver receiver = new SyncResultReceiver( |
| 948 |
SYNC_CALLS_TIMEOUT_MS); |
| 949 |
try { |
| 950 |
boolean sessionWasRestored = false; |
| 951 |
if (clientAdded) { |
| 952 |
mService.restoreSession(mSessionId, |
| 953 |
client.autofillClientGetActivityToken(), |
| 954 |
mServiceClient.asBinder(), receiver); |
| 955 |
sessionWasRestored = receiver.getIntResult() == 1; |
| 956 |
} else { |
| 957 |
Log.w(TAG, "No service client for session " + mSessionId); |
| 958 |
} |
| 959 |
|
| 960 |
if (!sessionWasRestored) { |
| 961 |
Log.w(TAG, "Session " + mSessionId + " could not be restored"); |
| 962 |
mSessionId = NO_SESSION; |
| 963 |
mState = STATE_UNKNOWN; |
| 964 |
} else { |
| 965 |
if (sDebug) { |
| 966 |
Log.d(TAG, "session " + mSessionId + " was restored"); |
| 967 |
} |
| 968 |
|
| 969 |
client.autofillClientResetableStateAvailable(); |
| 970 |
} |
| 971 |
} catch (RemoteException e) { |
| 972 |
Log.e(TAG, "Could not figure out if there was an autofill session", e); |
| 973 |
} catch (SyncResultReceiver.TimeoutException e) { |
| 974 |
Log.e(TAG, "Fail to get session restore status: " + e); |
| 975 |
} |
| 976 |
} |
| 977 |
} |
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
public void onVisibleForAutofill() { |
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
Choreographer.getInstance().postCallback(Choreographer.CALLBACK_COMMIT, () -> { |
| 995 |
synchronized (mLock) { |
| 996 |
if (mEnabled && isActiveLocked() && mTrackedViews != null) { |
| 997 |
mTrackedViews.onVisibleForAutofillChangedLocked(); |
| 998 |
} |
| 999 |
} |
| 1000 |
}, null); |
| 1001 |
} |
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
public void onInvisibleForAutofill(boolean isExpiredResponse) { |
| 1013 |
synchronized (mLock) { |
| 1014 |
mOnInvisibleCalled = true; |
| 1015 |
|
| 1016 |
if (isExpiredResponse) { |
| 1017 |
|
| 1018 |
updateSessionLocked( null, null, null, |
| 1019 |
ACTION_RESPONSE_EXPIRED, 0); |
| 1020 |
} |
| 1021 |
} |
| 1022 |
} |
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
public void onSaveInstanceState(Bundle outState) { |
| 1032 |
if (!hasAutofillFeature()) { |
| 1033 |
return; |
| 1034 |
} |
| 1035 |
synchronized (mLock) { |
| 1036 |
if (mSessionId != NO_SESSION) { |
| 1037 |
outState.putInt(SESSION_ID_TAG, mSessionId); |
| 1038 |
} |
| 1039 |
if (mState != STATE_UNKNOWN) { |
| 1040 |
outState.putInt(STATE_TAG, mState); |
| 1041 |
} |
| 1042 |
if (mLastAutofilledData != null) { |
| 1043 |
outState.putParcelable(LAST_AUTOFILLED_DATA_TAG, mLastAutofilledData); |
| 1044 |
} |
| 1045 |
} |
| 1046 |
} |
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
@GuardedBy("mLock") |
| 1052 |
public boolean isCompatibilityModeEnabledLocked() { |
| 1053 |
return mCompatibilityBridge != null; |
| 1054 |
} |
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
public boolean isEnabled() { |
| 1065 |
if (!hasAutofillFeature()) { |
| 1066 |
return false; |
| 1067 |
} |
| 1068 |
synchronized (mLock) { |
| 1069 |
if (isDisabledByServiceLocked()) { |
| 1070 |
return false; |
| 1071 |
} |
| 1072 |
final boolean clientAdded = tryAddServiceClientIfNeededLocked(); |
| 1073 |
return clientAdded ? mEnabled : false; |
| 1074 |
} |
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
@Nullable public FillEventHistory getFillEventHistory() { |
| 1083 |
try { |
| 1084 |
final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS); |
| 1085 |
mService.getFillEventHistory(receiver); |
| 1086 |
return receiver.getParcelableResult(); |
| 1087 |
} catch (RemoteException e) { |
| 1088 |
throw e.rethrowFromSystemServer(); |
| 1089 |
} catch (SyncResultReceiver.TimeoutException e) { |
| 1090 |
Log.e(TAG, "Fail to get fill event history: " + e); |
| 1091 |
return null; |
| 1092 |
} |
| 1093 |
} |
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
public void requestAutofill(@NonNull View view) { |
| 1106 |
int flags = FLAG_MANUAL_REQUEST; |
| 1107 |
if (!view.isFocused()) { |
| 1108 |
flags |= FLAG_VIEW_NOT_FOCUSED; |
| 1109 |
} |
| 1110 |
notifyViewEntered(view, flags); |
| 1111 |
} |
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
void requestAutofillFromNewSession(@NonNull View view) { |
| 1128 |
cancel(); |
| 1129 |
notifyViewEntered(view); |
| 1130 |
} |
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
public void requestAutofill(@NonNull View view, int virtualId, @NonNull Rect absBounds) { |
| 1157 |
int flags = FLAG_MANUAL_REQUEST; |
| 1158 |
if (!view.isFocused()) { |
| 1159 |
flags |= FLAG_VIEW_NOT_FOCUSED; |
| 1160 |
} |
| 1161 |
notifyViewEntered(view, virtualId, absBounds, flags); |
| 1162 |
} |
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
public void notifyViewEntered(@NonNull View view) { |
| 1170 |
notifyViewEntered(view, 0); |
| 1171 |
} |
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
public void notifyViewEnteredForFillDialog(View v) { |
| 1181 |
synchronized (mLock) { |
| 1182 |
if (mTrackedViews != null) { |
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
mTrackedViews.checkViewState(v.getAutofillId()); |
| 1188 |
} |
| 1189 |
} |
| 1190 |
|
| 1191 |
|
| 1192 |
if (mIsFillRequested.get()) { |
| 1193 |
return; |
| 1194 |
} |
| 1195 |
|
| 1196 |
if (mIsFillDialogEnabled |
| 1197 |
|| ArrayUtils.containsAny(v.getAutofillHints(), mFillDialogEnabledHints)) { |
| 1198 |
if (sDebug) { |
| 1199 |
Log.d(TAG, "Trigger fill request at view entered"); |
| 1200 |
} |
| 1201 |
|
| 1202 |
|
| 1203 |
mIsFillRequested.set(true); |
| 1204 |
|
| 1205 |
int flags = FLAG_SUPPORTS_FILL_DIALOG; |
| 1206 |
flags |= FLAG_VIEW_NOT_FOCUSED; |
| 1207 |
|
| 1208 |
notifyViewEntered(v.getRootView(), flags); |
| 1209 |
} |
| 1210 |
} |
| 1211 |
|
| 1212 |
private boolean hasFillDialogUiFeature() { |
| 1213 |
return mIsFillDialogEnabled || !ArrayUtils.isEmpty(mFillDialogEnabledHints); |
| 1214 |
} |
| 1215 |
|
| 1216 |
private int getImeStateFlag(View v) { |
| 1217 |
final WindowInsets rootWindowInsets = v.getRootWindowInsets(); |
| 1218 |
if (rootWindowInsets != null && rootWindowInsets.isVisible(WindowInsets.Type.ime())) { |
| 1219 |
return FLAG_IME_SHOWING; |
| 1220 |
} |
| 1221 |
return 0; |
| 1222 |
} |
| 1223 |
|
| 1224 |
@GuardedBy("mLock") |
| 1225 |
private boolean shouldIgnoreViewEnteredLocked(@NonNull AutofillId id, int flags) { |
| 1226 |
if (isDisabledByServiceLocked()) { |
| 1227 |
if (sVerbose) { |
| 1228 |
Log.v(TAG, "ignoring notifyViewEntered(flags=" + flags + ", view=" + id |
| 1229 |
+ ") on state " + getStateAsStringLocked() + " because disabled by svc"); |
| 1230 |
} |
| 1231 |
return true; |
| 1232 |
} |
| 1233 |
if (isFinishedLocked()) { |
| 1234 |
|
| 1235 |
if ((flags & FLAG_MANUAL_REQUEST) == 0 && mEnteredIds != null |
| 1236 |
&& mEnteredIds.contains(id)) { |
| 1237 |
if (sVerbose) { |
| 1238 |
Log.v(TAG, "ignoring notifyViewEntered(flags=" + flags + ", view=" + id |
| 1239 |
+ ") on state " + getStateAsStringLocked() |
| 1240 |
+ " because view was already entered: " + mEnteredIds); |
| 1241 |
} |
| 1242 |
return true; |
| 1243 |
} |
| 1244 |
} |
| 1245 |
return false; |
| 1246 |
} |
| 1247 |
|
| 1248 |
private boolean isClientVisibleForAutofillLocked() { |
| 1249 |
final AutofillClient client = getClient(); |
| 1250 |
return client != null && client.autofillClientIsVisibleForAutofill(); |
| 1251 |
} |
| 1252 |
|
| 1253 |
private boolean isClientDisablingEnterExitEvent() { |
| 1254 |
final AutofillClient client = getClient(); |
| 1255 |
return client != null && client.isDisablingEnterExitEventForAutofill(); |
| 1256 |
} |
| 1257 |
|
| 1258 |
private void notifyViewEntered(@NonNull View view, int flags) { |
| 1259 |
if (!hasAutofillFeature()) { |
| 1260 |
return; |
| 1261 |
} |
| 1262 |
AutofillCallback callback; |
| 1263 |
synchronized (mLock) { |
| 1264 |
mIsFillRequested.set(true); |
| 1265 |
callback = notifyViewEnteredLocked(view, flags); |
| 1266 |
} |
| 1267 |
|
| 1268 |
if (callback != null) { |
| 1269 |
mCallback.onAutofillEvent(view, AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
| 1270 |
} |
| 1271 |
} |
| 1272 |
|
| 1273 |
|
| 1274 |
@GuardedBy("mLock") |
| 1275 |
private AutofillCallback notifyViewEnteredLocked(@NonNull View view, int flags) { |
| 1276 |
final AutofillId id = view.getAutofillId(); |
| 1277 |
if (shouldIgnoreViewEnteredLocked(id, flags)) return null; |
| 1278 |
|
| 1279 |
AutofillCallback callback = null; |
| 1280 |
|
| 1281 |
final boolean clientAdded = tryAddServiceClientIfNeededLocked(); |
| 1282 |
|
| 1283 |
if (!clientAdded) { |
| 1284 |
if (sVerbose) Log.v(TAG, "ignoring notifyViewEntered(" + id + "): no service client"); |
| 1285 |
return callback; |
| 1286 |
} |
| 1287 |
|
| 1288 |
if (!mEnabled && !mEnabledForAugmentedAutofillOnly) { |
| 1289 |
if (sVerbose) Log.v(TAG, "ignoring notifyViewEntered(" + id + "): disabled"); |
| 1290 |
|
| 1291 |
if (mCallback != null) { |
| 1292 |
callback = mCallback; |
| 1293 |
} |
| 1294 |
} else { |
| 1295 |
|
| 1296 |
if (!isClientDisablingEnterExitEvent()) { |
| 1297 |
final AutofillValue value = view.getAutofillValue(); |
| 1298 |
|
| 1299 |
if (view instanceof TextView && ((TextView) view).isAnyPasswordInputType()) { |
| 1300 |
flags |= FLAG_PASSWORD_INPUT_TYPE; |
| 1301 |
} |
| 1302 |
|
| 1303 |
flags |= getImeStateFlag(view); |
| 1304 |
|
| 1305 |
if (!isActiveLocked()) { |
| 1306 |
|
| 1307 |
startSessionLocked(id, null, value, flags); |
| 1308 |
} else { |
| 1309 |
|
| 1310 |
if (mForAugmentedAutofillOnly && (flags & FLAG_MANUAL_REQUEST) != 0) { |
| 1311 |
if (sDebug) { |
| 1312 |
Log.d(TAG, "notifyViewEntered(" + id + "): resetting " |
| 1313 |
+ "mForAugmentedAutofillOnly on manual request"); |
| 1314 |
} |
| 1315 |
mForAugmentedAutofillOnly = false; |
| 1316 |
} |
| 1317 |
|
| 1318 |
if ((flags & FLAG_SUPPORTS_FILL_DIALOG) != 0) { |
| 1319 |
flags |= FLAG_RESET_FILL_DIALOG_STATE; |
| 1320 |
} |
| 1321 |
updateSessionLocked(id, null, value, ACTION_VIEW_ENTERED, flags); |
| 1322 |
} |
| 1323 |
addEnteredIdLocked(id); |
| 1324 |
} |
| 1325 |
} |
| 1326 |
return callback; |
| 1327 |
} |
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
public void notifyViewExited(@NonNull View view) { |
| 1335 |
if (!hasAutofillFeature()) { |
| 1336 |
return; |
| 1337 |
} |
| 1338 |
synchronized (mLock) { |
| 1339 |
notifyViewExitedLocked(view); |
| 1340 |
} |
| 1341 |
} |
| 1342 |
|
| 1343 |
@GuardedBy("mLock") |
| 1344 |
void notifyViewExitedLocked(@NonNull View view) { |
| 1345 |
final boolean clientAdded = tryAddServiceClientIfNeededLocked(); |
| 1346 |
|
| 1347 |
if (clientAdded && (mEnabled || mEnabledForAugmentedAutofillOnly) |
| 1348 |
&& isActiveLocked()) { |
| 1349 |
|
| 1350 |
if (!isClientDisablingEnterExitEvent()) { |
| 1351 |
final AutofillId id = view.getAutofillId(); |
| 1352 |
|
| 1353 |
|
| 1354 |
updateSessionLocked(id, null, null, ACTION_VIEW_EXITED, 0); |
| 1355 |
} |
| 1356 |
} |
| 1357 |
} |
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
public void notifyViewVisibilityChanged(@NonNull View view, boolean isVisible) { |
| 1366 |
notifyViewVisibilityChangedInternal(view, 0, isVisible, false); |
| 1367 |
} |
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
public void notifyViewVisibilityChanged(@NonNull View view, int virtualId, boolean isVisible) { |
| 1377 |
notifyViewVisibilityChangedInternal(view, virtualId, isVisible, true); |
| 1378 |
} |
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
private void notifyViewVisibilityChangedInternal(@NonNull View view, int virtualId, |
| 1389 |
boolean isVisible, boolean virtual) { |
| 1390 |
synchronized (mLock) { |
| 1391 |
if (mForAugmentedAutofillOnly) { |
| 1392 |
if (sVerbose) { |
| 1393 |
Log.v(TAG, "notifyViewVisibilityChanged(): ignoring on augmented only mode"); |
| 1394 |
} |
| 1395 |
return; |
| 1396 |
} |
| 1397 |
if (mEnabled && isActiveLocked()) { |
| 1398 |
final AutofillId id = virtual ? getAutofillId(view, virtualId) |
| 1399 |
: view.getAutofillId(); |
| 1400 |
if (sVerbose) Log.v(TAG, "visibility changed for " + id + ": " + isVisible); |
| 1401 |
if (!isVisible && mFillableIds != null) { |
| 1402 |
if (mFillableIds.contains(id)) { |
| 1403 |
if (sDebug) Log.d(TAG, "Hidding UI when view " + id + " became invisible"); |
| 1404 |
requestHideFillUi(id, view); |
| 1405 |
} |
| 1406 |
} |
| 1407 |
if (mTrackedViews != null) { |
| 1408 |
mTrackedViews.notifyViewVisibilityChangedLocked(id, isVisible); |
| 1409 |
} else if (sVerbose) { |
| 1410 |
Log.v(TAG, "Ignoring visibility change on " + id + ": no tracked views"); |
| 1411 |
} |
| 1412 |
} else if (!virtual && isVisible) { |
| 1413 |
startAutofillIfNeededLocked(view); |
| 1414 |
} |
| 1415 |
} |
| 1416 |
} |
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
public void notifyViewEntered(@NonNull View view, int virtualId, @NonNull Rect absBounds) { |
| 1438 |
notifyViewEntered(view, virtualId, absBounds, 0); |
| 1439 |
} |
| 1440 |
|
| 1441 |
private void notifyViewEntered(View view, int virtualId, Rect bounds, int flags) { |
| 1442 |
if (!hasAutofillFeature()) { |
| 1443 |
return; |
| 1444 |
} |
| 1445 |
AutofillCallback callback; |
| 1446 |
synchronized (mLock) { |
| 1447 |
callback = notifyViewEnteredLocked(view, virtualId, bounds, flags); |
| 1448 |
} |
| 1449 |
|
| 1450 |
if (callback != null) { |
| 1451 |
callback.onAutofillEvent(view, virtualId, |
| 1452 |
AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
| 1453 |
} |
| 1454 |
} |
| 1455 |
|
| 1456 |
|
| 1457 |
@GuardedBy("mLock") |
| 1458 |
private AutofillCallback notifyViewEnteredLocked(View view, int virtualId, Rect bounds, |
| 1459 |
int flags) { |
| 1460 |
final AutofillId id = getAutofillId(view, virtualId); |
| 1461 |
AutofillCallback callback = null; |
| 1462 |
if (shouldIgnoreViewEnteredLocked(id, flags)) return callback; |
| 1463 |
|
| 1464 |
final boolean clientAdded = tryAddServiceClientIfNeededLocked(); |
| 1465 |
|
| 1466 |
if (!clientAdded) { |
| 1467 |
if (sVerbose) Log.v(TAG, "ignoring notifyViewEntered(" + id + "): no service client"); |
| 1468 |
return callback; |
| 1469 |
} |
| 1470 |
|
| 1471 |
if (!mEnabled && !mEnabledForAugmentedAutofillOnly) { |
| 1472 |
if (sVerbose) { |
| 1473 |
Log.v(TAG, "ignoring notifyViewEntered(" + id + "): disabled"); |
| 1474 |
} |
| 1475 |
if (mCallback != null) { |
| 1476 |
callback = mCallback; |
| 1477 |
} |
| 1478 |
} else { |
| 1479 |
|
| 1480 |
if (!isClientDisablingEnterExitEvent()) { |
| 1481 |
if (view instanceof TextView && ((TextView) view).isAnyPasswordInputType()) { |
| 1482 |
flags |= FLAG_PASSWORD_INPUT_TYPE; |
| 1483 |
} |
| 1484 |
|
| 1485 |
flags |= getImeStateFlag(view); |
| 1486 |
|
| 1487 |
if (!isActiveLocked()) { |
| 1488 |
|
| 1489 |
startSessionLocked(id, bounds, null, flags); |
| 1490 |
} else { |
| 1491 |
|
| 1492 |
if (mForAugmentedAutofillOnly && (flags & FLAG_MANUAL_REQUEST) != 0) { |
| 1493 |
if (sDebug) { |
| 1494 |
Log.d(TAG, "notifyViewEntered(" + id + "): resetting " |
| 1495 |
+ "mForAugmentedAutofillOnly on manual request"); |
| 1496 |
} |
| 1497 |
mForAugmentedAutofillOnly = false; |
| 1498 |
} |
| 1499 |
updateSessionLocked(id, bounds, null, ACTION_VIEW_ENTERED, flags); |
| 1500 |
} |
| 1501 |
addEnteredIdLocked(id); |
| 1502 |
} |
| 1503 |
} |
| 1504 |
return callback; |
| 1505 |
} |
| 1506 |
|
| 1507 |
@GuardedBy("mLock") |
| 1508 |
private void addEnteredIdLocked(@NonNull AutofillId id) { |
| 1509 |
if (mEnteredIds == null) { |
| 1510 |
mEnteredIds = new ArraySet<>(1); |
| 1511 |
} |
| 1512 |
id.resetSessionId(); |
| 1513 |
mEnteredIds.add(id); |
| 1514 |
} |
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
public void notifyViewExited(@NonNull View view, int virtualId) { |
| 1523 |
if (sVerbose) Log.v(TAG, "notifyViewExited(" + view.getAutofillId() + ", " + virtualId); |
| 1524 |
if (!hasAutofillFeature()) { |
| 1525 |
return; |
| 1526 |
} |
| 1527 |
synchronized (mLock) { |
| 1528 |
notifyViewExitedLocked(view, virtualId); |
| 1529 |
} |
| 1530 |
} |
| 1531 |
|
| 1532 |
@GuardedBy("mLock") |
| 1533 |
private void notifyViewExitedLocked(@NonNull View view, int virtualId) { |
| 1534 |
final boolean clientAdded = tryAddServiceClientIfNeededLocked(); |
| 1535 |
|
| 1536 |
if (clientAdded && (mEnabled || mEnabledForAugmentedAutofillOnly) |
| 1537 |
&& isActiveLocked()) { |
| 1538 |
|
| 1539 |
if (!isClientDisablingEnterExitEvent()) { |
| 1540 |
final AutofillId id = getAutofillId(view, virtualId); |
| 1541 |
|
| 1542 |
|
| 1543 |
updateSessionLocked(id, null, null, ACTION_VIEW_EXITED, 0); |
| 1544 |
} |
| 1545 |
} |
| 1546 |
} |
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
public void notifyValueChanged(View view) { |
| 1554 |
if (!hasAutofillFeature()) { |
| 1555 |
return; |
| 1556 |
} |
| 1557 |
AutofillId id = null; |
| 1558 |
boolean valueWasRead = false; |
| 1559 |
AutofillValue value = null; |
| 1560 |
|
| 1561 |
synchronized (mLock) { |
| 1562 |
|
| 1563 |
|
| 1564 |
if (mLastAutofilledData == null) { |
| 1565 |
view.setAutofilled(false, false); |
| 1566 |
} else { |
| 1567 |
id = view.getAutofillId(); |
| 1568 |
if (mLastAutofilledData.containsKey(id)) { |
| 1569 |
value = view.getAutofillValue(); |
| 1570 |
valueWasRead = true; |
| 1571 |
final boolean hideHighlight = mLastAutofilledData.keySet().size() == 1; |
| 1572 |
|
| 1573 |
if (Objects.equals(mLastAutofilledData.get(id), value)) { |
| 1574 |
view.setAutofilled(true, hideHighlight); |
| 1575 |
} else { |
| 1576 |
view.setAutofilled(false, false); |
| 1577 |
mLastAutofilledData.remove(id); |
| 1578 |
} |
| 1579 |
} else { |
| 1580 |
view.setAutofilled(false, false); |
| 1581 |
} |
| 1582 |
} |
| 1583 |
|
| 1584 |
if (!mEnabled || !isActiveLocked()) { |
| 1585 |
if (!startAutofillIfNeededLocked(view)) { |
| 1586 |
if (sVerbose) { |
| 1587 |
Log.v(TAG, "notifyValueChanged(" + view.getAutofillId() |
| 1588 |
+ "): ignoring on state " + getStateAsStringLocked()); |
| 1589 |
} |
| 1590 |
} |
| 1591 |
return; |
| 1592 |
} |
| 1593 |
|
| 1594 |
if (id == null) { |
| 1595 |
id = view.getAutofillId(); |
| 1596 |
} |
| 1597 |
|
| 1598 |
if (!valueWasRead) { |
| 1599 |
value = view.getAutofillValue(); |
| 1600 |
} |
| 1601 |
|
| 1602 |
updateSessionLocked(id, null, value, ACTION_VALUE_CHANGED, getImeStateFlag(view)); |
| 1603 |
} |
| 1604 |
} |
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
public void notifyValueChanged(View view, int virtualId, AutofillValue value) { |
| 1614 |
if (!hasAutofillFeature()) { |
| 1615 |
return; |
| 1616 |
} |
| 1617 |
synchronized (mLock) { |
| 1618 |
if (!mEnabled || !isActiveLocked()) { |
| 1619 |
if (sVerbose) { |
| 1620 |
Log.v(TAG, "notifyValueChanged(" + view.getAutofillId() + ":" + virtualId |
| 1621 |
+ "): ignoring on state " + getStateAsStringLocked()); |
| 1622 |
} |
| 1623 |
return; |
| 1624 |
} |
| 1625 |
|
| 1626 |
final AutofillId id = getAutofillId(view, virtualId); |
| 1627 |
updateSessionLocked(id, null, value, ACTION_VALUE_CHANGED, getImeStateFlag(view)); |
| 1628 |
} |
| 1629 |
} |
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
public void notifyViewClicked(@NonNull View view) { |
| 1637 |
notifyViewClicked(view.getAutofillId()); |
| 1638 |
} |
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
public void notifyViewClicked(@NonNull View view, int virtualId) { |
| 1647 |
notifyViewClicked(getAutofillId(view, virtualId)); |
| 1648 |
} |
| 1649 |
|
| 1650 |
private void notifyViewClicked(AutofillId id) { |
| 1651 |
if (!hasAutofillFeature()) { |
| 1652 |
return; |
| 1653 |
} |
| 1654 |
if (sVerbose) Log.v(TAG, "notifyViewClicked(): id=" + id + ", trigger=" + mSaveTriggerId); |
| 1655 |
|
| 1656 |
synchronized (mLock) { |
| 1657 |
if (!mEnabled || !isActiveLocked()) { |
| 1658 |
return; |
| 1659 |
} |
| 1660 |
if (mSaveTriggerId != null && mSaveTriggerId.equals(id)) { |
| 1661 |
if (sDebug) Log.d(TAG, "triggering commit by click of " + id); |
| 1662 |
commitLocked( COMMIT_REASON_VIEW_CLICKED); |
| 1663 |
mMetricsLogger.write(newLog(MetricsEvent.AUTOFILL_SAVE_EXPLICITLY_TRIGGERED)); |
| 1664 |
} |
| 1665 |
} |
| 1666 |
} |
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
public void onActivityFinishing() { |
| 1674 |
if (!hasAutofillFeature()) { |
| 1675 |
return; |
| 1676 |
} |
| 1677 |
synchronized (mLock) { |
| 1678 |
if (mSaveOnFinish) { |
| 1679 |
if (sDebug) Log.d(TAG, "onActivityFinishing(): calling commitLocked()"); |
| 1680 |
commitLocked( COMMIT_REASON_ACTIVITY_FINISHED); |
| 1681 |
} else { |
| 1682 |
if (sDebug) Log.d(TAG, "onActivityFinishing(): calling cancelLocked()"); |
| 1683 |
cancelLocked(); |
| 1684 |
} |
| 1685 |
} |
| 1686 |
} |
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
public void commit() { |
| 1700 |
if (!hasAutofillFeature()) { |
| 1701 |
return; |
| 1702 |
} |
| 1703 |
if (sVerbose) Log.v(TAG, "commit() called by app"); |
| 1704 |
synchronized (mLock) { |
| 1705 |
commitLocked( COMMIT_REASON_VIEW_COMMITTED); |
| 1706 |
} |
| 1707 |
} |
| 1708 |
|
| 1709 |
@GuardedBy("mLock") |
| 1710 |
private void commitLocked(@AutofillCommitReason int commitReason) { |
| 1711 |
if (!mEnabled && !isActiveLocked()) { |
| 1712 |
return; |
| 1713 |
} |
| 1714 |
finishSessionLocked( commitReason); |
| 1715 |
} |
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
public void cancel() { |
| 1729 |
if (sVerbose) Log.v(TAG, "cancel() called by app or augmented autofill service"); |
| 1730 |
if (!hasAutofillFeature()) { |
| 1731 |
return; |
| 1732 |
} |
| 1733 |
synchronized (mLock) { |
| 1734 |
cancelLocked(); |
| 1735 |
} |
| 1736 |
} |
| 1737 |
|
| 1738 |
@GuardedBy("mLock") |
| 1739 |
private void cancelLocked() { |
| 1740 |
if (!mEnabled && !isActiveLocked()) { |
| 1741 |
return; |
| 1742 |
} |
| 1743 |
cancelSessionLocked(); |
| 1744 |
} |
| 1745 |
|
| 1746 |
|
| 1747 |
public void disableOwnedAutofillServices() { |
| 1748 |
disableAutofillServices(); |
| 1749 |
} |
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
public void disableAutofillServices() { |
| 1756 |
if (!hasAutofillFeature()) { |
| 1757 |
return; |
| 1758 |
} |
| 1759 |
try { |
| 1760 |
mService.disableOwnedAutofillServices(mContext.getUserId()); |
| 1761 |
} catch (RemoteException e) { |
| 1762 |
throw e.rethrowFromSystemServer(); |
| 1763 |
} |
| 1764 |
} |
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
public boolean hasEnabledAutofillServices() { |
| 1771 |
if (mService == null) return false; |
| 1772 |
|
| 1773 |
final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS); |
| 1774 |
try { |
| 1775 |
mService.isServiceEnabled(mContext.getUserId(), mContext.getPackageName(), |
| 1776 |
receiver); |
| 1777 |
return receiver.getIntResult() == 1; |
| 1778 |
} catch (RemoteException e) { |
| 1779 |
throw e.rethrowFromSystemServer(); |
| 1780 |
} catch (SyncResultReceiver.TimeoutException e) { |
| 1781 |
throw new RuntimeException("Fail to get enabled autofill services status."); |
| 1782 |
} |
| 1783 |
} |
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
@Nullable |
| 1790 |
public ComponentName getAutofillServiceComponentName() { |
| 1791 |
if (mService == null) return null; |
| 1792 |
|
| 1793 |
final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS); |
| 1794 |
try { |
| 1795 |
mService.getAutofillServiceComponentName(receiver); |
| 1796 |
return receiver.getParcelableResult(); |
| 1797 |
} catch (RemoteException e) { |
| 1798 |
throw e.rethrowFromSystemServer(); |
| 1799 |
} catch (SyncResultReceiver.TimeoutException e) { |
| 1800 |
throw new RuntimeException("Fail to get autofill services component name."); |
| 1801 |
} |
| 1802 |
} |
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
@Nullable public String getUserDataId() { |
| 1820 |
try { |
| 1821 |
final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS); |
| 1822 |
mService.getUserDataId(receiver); |
| 1823 |
return receiver.getStringResult(); |
| 1824 |
} catch (RemoteException e) { |
| 1825 |
throw e.rethrowFromSystemServer(); |
| 1826 |
} catch (SyncResultReceiver.TimeoutException e) { |
| 1827 |
throw new RuntimeException("Fail to get user data id for field classification."); |
| 1828 |
} |
| 1829 |
} |
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
@Nullable public UserData getUserData() { |
| 1843 |
try { |
| 1844 |
final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS); |
| 1845 |
mService.getUserData(receiver); |
| 1846 |
return receiver.getParcelableResult(); |
| 1847 |
} catch (RemoteException e) { |
| 1848 |
throw e.rethrowFromSystemServer(); |
| 1849 |
} catch (SyncResultReceiver.TimeoutException e) { |
| 1850 |
throw new RuntimeException("Fail to get user data for field classification."); |
| 1851 |
} |
| 1852 |
} |
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
public void setUserData(@Nullable UserData userData) { |
| 1863 |
try { |
| 1864 |
mService.setUserData(userData); |
| 1865 |
} catch (RemoteException e) { |
| 1866 |
throw e.rethrowFromSystemServer(); |
| 1867 |
} |
| 1868 |
} |
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
public boolean isFieldClassificationEnabled() { |
| 1883 |
final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS); |
| 1884 |
try { |
| 1885 |
mService.isFieldClassificationEnabled(receiver); |
| 1886 |
return receiver.getIntResult() == 1; |
| 1887 |
} catch (RemoteException e) { |
| 1888 |
throw e.rethrowFromSystemServer(); |
| 1889 |
} catch (SyncResultReceiver.TimeoutException e) { |
| 1890 |
throw new RuntimeException("Fail to get field classification enabled status."); |
| 1891 |
} |
| 1892 |
} |
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
@Nullable |
| 1906 |
public String getDefaultFieldClassificationAlgorithm() { |
| 1907 |
final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS); |
| 1908 |
try { |
| 1909 |
mService.getDefaultFieldClassificationAlgorithm(receiver); |
| 1910 |
return receiver.getStringResult(); |
| 1911 |
} catch (RemoteException e) { |
| 1912 |
throw e.rethrowFromSystemServer(); |
| 1913 |
} catch (SyncResultReceiver.TimeoutException e) { |
| 1914 |
throw new RuntimeException("Fail to get default field classification algorithm."); |
| 1915 |
} |
| 1916 |
} |
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
@NonNull |
| 1927 |
public List<String> getAvailableFieldClassificationAlgorithms() { |
| 1928 |
final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS); |
| 1929 |
try { |
| 1930 |
mService.getAvailableFieldClassificationAlgorithms(receiver); |
| 1931 |
final String[] algorithms = receiver.getStringArrayResult(); |
| 1932 |
return algorithms != null ? Arrays.asList(algorithms) : Collections.emptyList(); |
| 1933 |
} catch (RemoteException e) { |
| 1934 |
throw e.rethrowFromSystemServer(); |
| 1935 |
} catch (SyncResultReceiver.TimeoutException e) { |
| 1936 |
throw new RuntimeException("Fail to get available field classification algorithms."); |
| 1937 |
} |
| 1938 |
} |
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
public boolean isAutofillSupported() { |
| 1951 |
if (mService == null) return false; |
| 1952 |
|
| 1953 |
final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS); |
| 1954 |
try { |
| 1955 |
mService.isServiceSupported(mContext.getUserId(), receiver); |
| 1956 |
return receiver.getIntResult() == 1; |
| 1957 |
} catch (RemoteException e) { |
| 1958 |
throw e.rethrowFromSystemServer(); |
| 1959 |
} catch (SyncResultReceiver.TimeoutException e) { |
| 1960 |
throw new RuntimeException("Fail to get autofill supported status."); |
| 1961 |
} |
| 1962 |
} |
| 1963 |
|
| 1964 |
|
| 1965 |
private AutofillClient getClient() { |
| 1966 |
final AutofillClient client = mContext.getAutofillClient(); |
| 1967 |
if (client == null && sVerbose) { |
| 1968 |
Log.v(TAG, "No AutofillClient for " + mContext.getPackageName() + " on context " |
| 1969 |
+ mContext); |
| 1970 |
} |
| 1971 |
return client; |
| 1972 |
} |
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
|
| 1978 |
public boolean isAutofillUiShowing() { |
| 1979 |
final AutofillClient client = mContext.getAutofillClient(); |
| 1980 |
return client != null && client.autofillClientIsFillUiShowing(); |
| 1981 |
} |
| 1982 |
|
| 1983 |
|
| 1984 |
public void onAuthenticationResult(int authenticationId, Intent data, View focusView) { |
| 1985 |
if (!hasAutofillFeature()) { |
| 1986 |
return; |
| 1987 |
} |
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
if (sDebug) { |
| 1994 |
Log.d(TAG, "onAuthenticationResult(): id= " + authenticationId + ", data=" + data); |
| 1995 |
} |
| 1996 |
|
| 1997 |
synchronized (mLock) { |
| 1998 |
if (!isActiveLocked()) { |
| 1999 |
return; |
| 2000 |
} |
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
if (!mOnInvisibleCalled && focusView != null |
| 2007 |
&& focusView.canNotifyAutofillEnterExitEvent()) { |
| 2008 |
notifyViewExitedLocked(focusView); |
| 2009 |
notifyViewEnteredLocked(focusView, 0); |
| 2010 |
} |
| 2011 |
if (data == null) { |
| 2012 |
|
| 2013 |
return; |
| 2014 |
} |
| 2015 |
|
| 2016 |
final Parcelable result = data.getParcelableExtra(EXTRA_AUTHENTICATION_RESULT); |
| 2017 |
final Bundle responseData = new Bundle(); |
| 2018 |
responseData.putParcelable(EXTRA_AUTHENTICATION_RESULT, result); |
| 2019 |
final Bundle newClientState = data.getBundleExtra(EXTRA_CLIENT_STATE); |
| 2020 |
if (newClientState != null) { |
| 2021 |
responseData.putBundle(EXTRA_CLIENT_STATE, newClientState); |
| 2022 |
} |
| 2023 |
if (data.hasExtra(EXTRA_AUTHENTICATION_RESULT_EPHEMERAL_DATASET)) { |
| 2024 |
responseData.putBoolean(EXTRA_AUTHENTICATION_RESULT_EPHEMERAL_DATASET, |
| 2025 |
data.getBooleanExtra(EXTRA_AUTHENTICATION_RESULT_EPHEMERAL_DATASET, |
| 2026 |
false)); |
| 2027 |
} |
| 2028 |
try { |
| 2029 |
mService.setAuthenticationResult(responseData, mSessionId, authenticationId, |
| 2030 |
mContext.getUserId()); |
| 2031 |
} catch (RemoteException e) { |
| 2032 |
Log.e(TAG, "Error delivering authentication result", e); |
| 2033 |
} |
| 2034 |
} |
| 2035 |
} |
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
@Nullable |
| 2047 |
public AutofillId getNextAutofillId() { |
| 2048 |
final AutofillClient client = getClient(); |
| 2049 |
if (client == null) return null; |
| 2050 |
|
| 2051 |
final AutofillId id = client.autofillClientGetNextAutofillId(); |
| 2052 |
|
| 2053 |
if (id == null && sDebug) { |
| 2054 |
Log.d(TAG, "getNextAutofillId(): client " + client + " returned null"); |
| 2055 |
} |
| 2056 |
|
| 2057 |
return id; |
| 2058 |
} |
| 2059 |
|
| 2060 |
private static AutofillId getAutofillId(View parent, int virtualId) { |
| 2061 |
return new AutofillId(parent.getAutofillViewId(), virtualId); |
| 2062 |
} |
| 2063 |
|
| 2064 |
@GuardedBy("mLock") |
| 2065 |
private void startSessionLocked(@NonNull AutofillId id, @NonNull Rect bounds, |
| 2066 |
@NonNull AutofillValue value, int flags) { |
| 2067 |
if (mEnteredForAugmentedAutofillIds != null |
| 2068 |
&& mEnteredForAugmentedAutofillIds.contains(id) |
| 2069 |
|| mEnabledForAugmentedAutofillOnly) { |
| 2070 |
if (sVerbose) Log.v(TAG, "Starting session for augmented autofill on " + id); |
| 2071 |
flags |= FLAG_ADD_CLIENT_ENABLED_FOR_AUGMENTED_AUTOFILL_ONLY; |
| 2072 |
} |
| 2073 |
if (sVerbose) { |
| 2074 |
Log.v(TAG, "startSessionLocked(): id=" + id + ", bounds=" + bounds + ", value=" + value |
| 2075 |
+ ", flags=" + flags + ", state=" + getStateAsStringLocked() |
| 2076 |
+ ", compatMode=" + isCompatibilityModeEnabledLocked() |
| 2077 |
+ ", augmentedOnly=" + mForAugmentedAutofillOnly |
| 2078 |
+ ", enabledAugmentedOnly=" + mEnabledForAugmentedAutofillOnly |
| 2079 |
+ ", enteredIds=" + mEnteredIds); |
| 2080 |
} |
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
if (mForAugmentedAutofillOnly && !mEnabledForAugmentedAutofillOnly |
| 2085 |
&& (flags & FLAG_MANUAL_REQUEST) != 0) { |
| 2086 |
if (sVerbose) { |
| 2087 |
Log.v(TAG, "resetting mForAugmentedAutofillOnly on manual autofill request"); |
| 2088 |
} |
| 2089 |
mForAugmentedAutofillOnly = false; |
| 2090 |
} |
| 2091 |
if (mState != STATE_UNKNOWN && !isFinishedLocked() && (flags & FLAG_MANUAL_REQUEST) == 0) { |
| 2092 |
if (sVerbose) { |
| 2093 |
Log.v(TAG, "not automatically starting session for " + id |
| 2094 |
+ " on state " + getStateAsStringLocked() + " and flags " + flags); |
| 2095 |
} |
| 2096 |
return; |
| 2097 |
} |
| 2098 |
try { |
| 2099 |
final AutofillClient client = getClient(); |
| 2100 |
if (client == null) return; |
| 2101 |
|
| 2102 |
final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS); |
| 2103 |
final ComponentName clientActivity = client.autofillClientGetComponentName(); |
| 2104 |
|
| 2105 |
if (!mEnabledForAugmentedAutofillOnly && mOptions != null |
| 2106 |
&& mOptions.isAutofillDisabledLocked(clientActivity)) { |
| 2107 |
if (mOptions.isAugmentedAutofillEnabled(mContext)) { |
| 2108 |
if (sDebug) { |
| 2109 |
Log.d(TAG, "startSession(" + clientActivity + "): disabled by service but " |
| 2110 |
+ "allowlisted for augmented autofill"); |
| 2111 |
flags |= FLAG_ADD_CLIENT_ENABLED_FOR_AUGMENTED_AUTOFILL_ONLY; |
| 2112 |
} |
| 2113 |
} else { |
| 2114 |
if (sDebug) { |
| 2115 |
Log.d(TAG, "startSession(" + clientActivity + "): ignored because " |
| 2116 |
+ "disabled by service and not allowlisted for augmented autofill"); |
| 2117 |
} |
| 2118 |
setSessionFinished(AutofillManager.STATE_DISABLED_BY_SERVICE, null); |
| 2119 |
client.autofillClientResetableStateAvailable(); |
| 2120 |
return; |
| 2121 |
} |
| 2122 |
} |
| 2123 |
|
| 2124 |
mService.startSession(client.autofillClientGetActivityToken(), |
| 2125 |
mServiceClient.asBinder(), id, bounds, value, mContext.getUserId(), |
| 2126 |
mCallback != null, flags, clientActivity, |
| 2127 |
isCompatibilityModeEnabledLocked(), receiver); |
| 2128 |
mSessionId = receiver.getIntResult(); |
| 2129 |
if (mSessionId != NO_SESSION) { |
| 2130 |
mState = STATE_ACTIVE; |
| 2131 |
} |
| 2132 |
final int extraFlags = receiver.getOptionalExtraIntResult(0); |
| 2133 |
if ((extraFlags & RECEIVER_FLAG_SESSION_FOR_AUGMENTED_AUTOFILL_ONLY) != 0) { |
| 2134 |
if (sDebug) Log.d(TAG, "startSession(" + clientActivity + "): for augmented only"); |
| 2135 |
mForAugmentedAutofillOnly = true; |
| 2136 |
} |
| 2137 |
client.autofillClientResetableStateAvailable(); |
| 2138 |
} catch (RemoteException e) { |
| 2139 |
throw e.rethrowFromSystemServer(); |
| 2140 |
} catch (SyncResultReceiver.TimeoutException e) { |
| 2141 |
|
| 2142 |
Log.w(TAG, "Exception getting result from SyncResultReceiver: " + e); |
| 2143 |
} |
| 2144 |
} |
| 2145 |
|
| 2146 |
@GuardedBy("mLock") |
| 2147 |
private void finishSessionLocked(@AutofillCommitReason int commitReason) { |
| 2148 |
if (sVerbose) Log.v(TAG, "finishSessionLocked(): " + getStateAsStringLocked()); |
| 2149 |
|
| 2150 |
if (!isActiveLocked()) return; |
| 2151 |
|
| 2152 |
try { |
| 2153 |
mService.finishSession(mSessionId, mContext.getUserId(), commitReason); |
| 2154 |
} catch (RemoteException e) { |
| 2155 |
throw e.rethrowFromSystemServer(); |
| 2156 |
} |
| 2157 |
|
| 2158 |
resetSessionLocked( true); |
| 2159 |
} |
| 2160 |
|
| 2161 |
@GuardedBy("mLock") |
| 2162 |
private void cancelSessionLocked() { |
| 2163 |
if (sVerbose) Log.v(TAG, "cancelSessionLocked(): " + getStateAsStringLocked()); |
| 2164 |
|
| 2165 |
if (!isActiveLocked()) return; |
| 2166 |
|
| 2167 |
try { |
| 2168 |
mService.cancelSession(mSessionId, mContext.getUserId()); |
| 2169 |
} catch (RemoteException e) { |
| 2170 |
throw e.rethrowFromSystemServer(); |
| 2171 |
} |
| 2172 |
|
| 2173 |
resetSessionLocked( true); |
| 2174 |
} |
| 2175 |
|
| 2176 |
@GuardedBy("mLock") |
| 2177 |
private void resetSessionLocked(boolean resetEnteredIds) { |
| 2178 |
mSessionId = NO_SESSION; |
| 2179 |
mState = STATE_UNKNOWN; |
| 2180 |
mTrackedViews = null; |
| 2181 |
mFillableIds = null; |
| 2182 |
mSaveTriggerId = null; |
| 2183 |
mIdShownFillUi = null; |
| 2184 |
mIsFillRequested.set(false); |
| 2185 |
mShowAutofillDialogCalled = false; |
| 2186 |
mFillDialogTriggerIds = null; |
| 2187 |
mAllTrackedViews.clear(); |
| 2188 |
if (resetEnteredIds) { |
| 2189 |
mEnteredIds = null; |
| 2190 |
} |
| 2191 |
} |
| 2192 |
|
| 2193 |
@GuardedBy("mLock") |
| 2194 |
private void updateSessionLocked(AutofillId id, Rect bounds, AutofillValue value, int action, |
| 2195 |
int flags) { |
| 2196 |
if (sVerbose) { |
| 2197 |
Log.v(TAG, "updateSessionLocked(): id=" + id + ", bounds=" + bounds |
| 2198 |
+ ", value=" + value + ", action=" + action + ", flags=" + flags); |
| 2199 |
} |
| 2200 |
try { |
| 2201 |
mService.updateSession(mSessionId, id, bounds, value, action, flags, |
| 2202 |
mContext.getUserId()); |
| 2203 |
} catch (RemoteException e) { |
| 2204 |
throw e.rethrowFromSystemServer(); |
| 2205 |
} |
| 2206 |
} |
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
@GuardedBy("mLock") |
| 2214 |
private boolean tryAddServiceClientIfNeededLocked() { |
| 2215 |
final AutofillClient client = getClient(); |
| 2216 |
if (client == null) { |
| 2217 |
return false; |
| 2218 |
} |
| 2219 |
if (mService == null) { |
| 2220 |
Log.w(TAG, "Autofill service is null!"); |
| 2221 |
return false; |
| 2222 |
} |
| 2223 |
if (mServiceClient == null) { |
| 2224 |
mServiceClient = new AutofillManagerClient(this); |
| 2225 |
try { |
| 2226 |
final int userId = mContext.getUserId(); |
| 2227 |
final SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS); |
| 2228 |
mService.addClient(mServiceClient, client.autofillClientGetComponentName(), |
| 2229 |
userId, receiver); |
| 2230 |
int flags = 0; |
| 2231 |
try { |
| 2232 |
flags = receiver.getIntResult(); |
| 2233 |
} catch (SyncResultReceiver.TimeoutException e) { |
| 2234 |
Log.w(TAG, "Failed to initialize autofill: " + e); |
| 2235 |
|
| 2236 |
mService.removeClient(mServiceClient, userId); |
| 2237 |
mServiceClient = null; |
| 2238 |
return false; |
| 2239 |
} |
| 2240 |
mEnabled = (flags & FLAG_ADD_CLIENT_ENABLED) != 0; |
| 2241 |
sDebug = (flags & FLAG_ADD_CLIENT_DEBUG) != 0; |
| 2242 |
sVerbose = (flags & FLAG_ADD_CLIENT_VERBOSE) != 0; |
| 2243 |
mEnabledForAugmentedAutofillOnly = (flags |
| 2244 |
& FLAG_ADD_CLIENT_ENABLED_FOR_AUGMENTED_AUTOFILL_ONLY) != 0; |
| 2245 |
if (sVerbose) { |
| 2246 |
Log.v(TAG, "receiver results: flags=" + flags + " enabled=" + mEnabled |
| 2247 |
+ ", enabledForAugmentedOnly: " + mEnabledForAugmentedAutofillOnly); |
| 2248 |
} |
| 2249 |
final IAutoFillManager service = mService; |
| 2250 |
final IAutoFillManagerClient serviceClient = mServiceClient; |
| 2251 |
mServiceClientCleaner = Cleaner.create(this, () -> { |
| 2252 |
|
| 2253 |
|
| 2254 |
try { |
| 2255 |
service.removeClient(serviceClient, userId); |
| 2256 |
} catch (RemoteException e) { |
| 2257 |
} |
| 2258 |
}); |
| 2259 |
} catch (RemoteException e) { |
| 2260 |
throw e.rethrowFromSystemServer(); |
| 2261 |
} |
| 2262 |
} |
| 2263 |
return true; |
| 2264 |
} |
| 2265 |
|
| 2266 |
@GuardedBy("mLock") |
| 2267 |
private boolean startAutofillIfNeededLocked(View view) { |
| 2268 |
if (mState == STATE_UNKNOWN |
| 2269 |
&& mSessionId == NO_SESSION |
| 2270 |
&& view instanceof EditText |
| 2271 |
&& !TextUtils.isEmpty(((EditText) view).getText()) |
| 2272 |
&& !view.isFocused() |
| 2273 |
&& view.isImportantForAutofill() |
| 2274 |
&& view.isLaidOut() |
| 2275 |
&& view.isVisibleToUser()) { |
| 2276 |
|
| 2277 |
final boolean clientAdded = tryAddServiceClientIfNeededLocked(); |
| 2278 |
|
| 2279 |
if (sVerbose) { |
| 2280 |
Log.v(TAG, "startAutofillIfNeededLocked(): enabled=" + mEnabled + " mServiceClient=" |
| 2281 |
+ mServiceClient); |
| 2282 |
} |
| 2283 |
if (clientAdded && mEnabled && !isClientDisablingEnterExitEvent()) { |
| 2284 |
final AutofillId id = view.getAutofillId(); |
| 2285 |
final AutofillValue value = view.getAutofillValue(); |
| 2286 |
|
| 2287 |
startSessionLocked(id, null, null, 0); |
| 2288 |
|
| 2289 |
updateSessionLocked(id, null, value, ACTION_VALUE_CHANGED, |
| 2290 |
0); |
| 2291 |
addEnteredIdLocked(id); |
| 2292 |
return true; |
| 2293 |
} |
| 2294 |
} |
| 2295 |
return false; |
| 2296 |
} |
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
public void registerCallback(@Nullable AutofillCallback callback) { |
| 2304 |
if (!hasAutofillFeature()) { |
| 2305 |
return; |
| 2306 |
} |
| 2307 |
synchronized (mLock) { |
| 2308 |
if (callback == null) return; |
| 2309 |
|
| 2310 |
final boolean hadCallback = mCallback != null; |
| 2311 |
mCallback = callback; |
| 2312 |
|
| 2313 |
if (!hadCallback) { |
| 2314 |
try { |
| 2315 |
mService.setHasCallback(mSessionId, mContext.getUserId(), true); |
| 2316 |
} catch (RemoteException e) { |
| 2317 |
throw e.rethrowFromSystemServer(); |
| 2318 |
} |
| 2319 |
} |
| 2320 |
} |
| 2321 |
} |
| 2322 |
|
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
|
| 2327 |
|
| 2328 |
public void unregisterCallback(@Nullable AutofillCallback callback) { |
| 2329 |
if (!hasAutofillFeature()) { |
| 2330 |
return; |
| 2331 |
} |
| 2332 |
synchronized (mLock) { |
| 2333 |
if (callback == null || mCallback == null || callback != mCallback) return; |
| 2334 |
|
| 2335 |
mCallback = null; |
| 2336 |
|
| 2337 |
try { |
| 2338 |
mService.setHasCallback(mSessionId, mContext.getUserId(), false); |
| 2339 |
} catch (RemoteException e) { |
| 2340 |
throw e.rethrowFromSystemServer(); |
| 2341 |
} |
| 2342 |
} |
| 2343 |
} |
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
|
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
@SystemApi |
| 2364 |
public void setAugmentedAutofillWhitelist(@Nullable Set<String> packages, |
| 2365 |
@Nullable Set<ComponentName> activities) { |
| 2366 |
if (!hasAutofillFeature()) { |
| 2367 |
return; |
| 2368 |
} |
| 2369 |
|
| 2370 |
final SyncResultReceiver resultReceiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS); |
| 2371 |
int resultCode; |
| 2372 |
try { |
| 2373 |
mService.setAugmentedAutofillWhitelist(toList(packages), toList(activities), |
| 2374 |
resultReceiver); |
| 2375 |
resultCode = resultReceiver.getIntResult(); |
| 2376 |
} catch (RemoteException e) { |
| 2377 |
throw e.rethrowFromSystemServer(); |
| 2378 |
} catch (SyncResultReceiver.TimeoutException e) { |
| 2379 |
Log.e(TAG, "Fail to get the result of set AugmentedAutofill whitelist. " + e); |
| 2380 |
return; |
| 2381 |
} |
| 2382 |
switch (resultCode) { |
| 2383 |
case RESULT_OK: |
| 2384 |
return; |
| 2385 |
case RESULT_CODE_NOT_SERVICE: |
| 2386 |
throw new SecurityException("caller is not user's Augmented Autofill Service"); |
| 2387 |
default: |
| 2388 |
Log.wtf(TAG, "setAugmentedAutofillWhitelist(): received invalid result: " |
| 2389 |
+ resultCode); |
| 2390 |
} |
| 2391 |
} |
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
public void notifyViewEnteredForAugmentedAutofill(@NonNull View view) { |
| 2403 |
final AutofillId id = view.getAutofillId(); |
| 2404 |
synchronized (mLock) { |
| 2405 |
if (mEnteredForAugmentedAutofillIds == null) { |
| 2406 |
mEnteredForAugmentedAutofillIds = new ArraySet<>(1); |
| 2407 |
} |
| 2408 |
mEnteredForAugmentedAutofillIds.add(id); |
| 2409 |
} |
| 2410 |
} |
| 2411 |
|
| 2412 |
private void requestShowFillUi(int sessionId, AutofillId id, int width, int height, |
| 2413 |
Rect anchorBounds, IAutofillWindowPresenter presenter) { |
| 2414 |
final View anchor = findView(id); |
| 2415 |
if (anchor == null) { |
| 2416 |
return; |
| 2417 |
} |
| 2418 |
|
| 2419 |
AutofillCallback callback = null; |
| 2420 |
synchronized (mLock) { |
| 2421 |
if (mSessionId == sessionId) { |
| 2422 |
AutofillClient client = getClient(); |
| 2423 |
|
| 2424 |
if (client != null) { |
| 2425 |
if (client.autofillClientRequestShowFillUi(anchor, width, height, |
| 2426 |
anchorBounds, presenter)) { |
| 2427 |
callback = mCallback; |
| 2428 |
mIdShownFillUi = id; |
| 2429 |
} |
| 2430 |
} |
| 2431 |
} |
| 2432 |
} |
| 2433 |
|
| 2434 |
if (callback != null) { |
| 2435 |
if (id.isVirtualInt()) { |
| 2436 |
callback.onAutofillEvent(anchor, id.getVirtualChildIntId(), |
| 2437 |
AutofillCallback.EVENT_INPUT_SHOWN); |
| 2438 |
} else { |
| 2439 |
callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_SHOWN); |
| 2440 |
} |
| 2441 |
} |
| 2442 |
} |
| 2443 |
|
| 2444 |
private void authenticate(int sessionId, int authenticationId, IntentSender intent, |
| 2445 |
Intent fillInIntent, boolean authenticateInline) { |
| 2446 |
synchronized (mLock) { |
| 2447 |
if (sessionId == mSessionId) { |
| 2448 |
final AutofillClient client = getClient(); |
| 2449 |
if (client != null) { |
| 2450 |
|
| 2451 |
|
| 2452 |
mOnInvisibleCalled = false; |
| 2453 |
client.autofillClientAuthenticate(authenticationId, intent, fillInIntent, |
| 2454 |
authenticateInline); |
| 2455 |
} |
| 2456 |
} |
| 2457 |
} |
| 2458 |
} |
| 2459 |
|
| 2460 |
private void dispatchUnhandledKey(int sessionId, AutofillId id, KeyEvent keyEvent) { |
| 2461 |
final View anchor = findView(id); |
| 2462 |
if (anchor == null) { |
| 2463 |
return; |
| 2464 |
} |
| 2465 |
|
| 2466 |
synchronized (mLock) { |
| 2467 |
if (mSessionId == sessionId) { |
| 2468 |
AutofillClient client = getClient(); |
| 2469 |
|
| 2470 |
if (client != null) { |
| 2471 |
client.autofillClientDispatchUnhandledKey(anchor, keyEvent); |
| 2472 |
} |
| 2473 |
} |
| 2474 |
} |
| 2475 |
} |
| 2476 |
|
| 2477 |
|
| 2478 |
public static final int SET_STATE_FLAG_ENABLED = 0x01; |
| 2479 |
|
| 2480 |
public static final int SET_STATE_FLAG_RESET_SESSION = 0x02; |
| 2481 |
|
| 2482 |
public static final int SET_STATE_FLAG_RESET_CLIENT = 0x04; |
| 2483 |
|
| 2484 |
public static final int SET_STATE_FLAG_DEBUG = 0x08; |
| 2485 |
|
| 2486 |
public static final int SET_STATE_FLAG_VERBOSE = 0x10; |
| 2487 |
|
| 2488 |
public static final int SET_STATE_FLAG_FOR_AUTOFILL_ONLY = 0x20; |
| 2489 |
|
| 2490 |
private void setState(int flags) { |
| 2491 |
if (sVerbose) { |
| 2492 |
Log.v(TAG, "setState(" + flags + ": " + DebugUtils.flagsToString(AutofillManager.class, |
| 2493 |
"SET_STATE_FLAG_", flags) + ")"); |
| 2494 |
} |
| 2495 |
synchronized (mLock) { |
| 2496 |
if ((flags & SET_STATE_FLAG_FOR_AUTOFILL_ONLY) != 0) { |
| 2497 |
mForAugmentedAutofillOnly = true; |
| 2498 |
|
| 2499 |
return; |
| 2500 |
} |
| 2501 |
mEnabled = (flags & SET_STATE_FLAG_ENABLED) != 0; |
| 2502 |
if (!mEnabled || (flags & SET_STATE_FLAG_RESET_SESSION) != 0) { |
| 2503 |
|
| 2504 |
resetSessionLocked( true); |
| 2505 |
} |
| 2506 |
if ((flags & SET_STATE_FLAG_RESET_CLIENT) != 0) { |
| 2507 |
|
| 2508 |
mServiceClient = null; |
| 2509 |
mAugmentedAutofillServiceClient = null; |
| 2510 |
if (mServiceClientCleaner != null) { |
| 2511 |
mServiceClientCleaner.clean(); |
| 2512 |
mServiceClientCleaner = null; |
| 2513 |
} |
| 2514 |
notifyReenableAutofill(); |
| 2515 |
} |
| 2516 |
} |
| 2517 |
sDebug = (flags & SET_STATE_FLAG_DEBUG) != 0; |
| 2518 |
sVerbose = (flags & SET_STATE_FLAG_VERBOSE) != 0; |
| 2519 |
} |
| 2520 |
|
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
|
| 2525 |
|
| 2526 |
|
| 2527 |
private void setAutofilledIfValuesIs(@NonNull View view, @Nullable AutofillValue targetValue, |
| 2528 |
boolean hideHighlight) { |
| 2529 |
AutofillValue currentValue = view.getAutofillValue(); |
| 2530 |
if (Objects.equals(currentValue, targetValue)) { |
| 2531 |
synchronized (mLock) { |
| 2532 |
if (mLastAutofilledData == null) { |
| 2533 |
mLastAutofilledData = new ParcelableMap(1); |
| 2534 |
} |
| 2535 |
mLastAutofilledData.put(view.getAutofillId(), targetValue); |
| 2536 |
} |
| 2537 |
view.setAutofilled(true, hideHighlight); |
| 2538 |
} |
| 2539 |
} |
| 2540 |
|
| 2541 |
private void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values, |
| 2542 |
boolean hideHighlight) { |
| 2543 |
synchronized (mLock) { |
| 2544 |
if (sessionId != mSessionId) { |
| 2545 |
return; |
| 2546 |
} |
| 2547 |
|
| 2548 |
final AutofillClient client = getClient(); |
| 2549 |
if (client == null) { |
| 2550 |
return; |
| 2551 |
} |
| 2552 |
|
| 2553 |
final int itemCount = ids.size(); |
| 2554 |
int numApplied = 0; |
| 2555 |
ArrayMap<View, SparseArray<AutofillValue>> virtualValues = null; |
| 2556 |
final View[] views = client.autofillClientFindViewsByAutofillIdTraversal( |
| 2557 |
Helper.toArray(ids)); |
| 2558 |
|
| 2559 |
ArrayList<AutofillId> failedIds = null; |
| 2560 |
|
| 2561 |
for (int i = 0; i < itemCount; i++) { |
| 2562 |
final AutofillId id = ids.get(i); |
| 2563 |
final AutofillValue value = values.get(i); |
| 2564 |
final View view = views[i]; |
| 2565 |
if (view == null) { |
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
Log.d(TAG, "autofill(): no View with id " + id); |
| 2570 |
if (failedIds == null) { |
| 2571 |
failedIds = new ArrayList<>(); |
| 2572 |
} |
| 2573 |
failedIds.add(id); |
| 2574 |
continue; |
| 2575 |
} |
| 2576 |
if (id.isVirtualInt()) { |
| 2577 |
if (virtualValues == null) { |
| 2578 |
|
| 2579 |
virtualValues = new ArrayMap<>(1); |
| 2580 |
} |
| 2581 |
SparseArray<AutofillValue> valuesByParent = virtualValues.get(view); |
| 2582 |
if (valuesByParent == null) { |
| 2583 |
|
| 2584 |
valuesByParent = new SparseArray<>(5); |
| 2585 |
virtualValues.put(view, valuesByParent); |
| 2586 |
} |
| 2587 |
valuesByParent.put(id.getVirtualChildIntId(), value); |
| 2588 |
} else { |
| 2589 |
|
| 2590 |
if (mLastAutofilledData == null) { |
| 2591 |
mLastAutofilledData = new ParcelableMap(itemCount - i); |
| 2592 |
} |
| 2593 |
mLastAutofilledData.put(id, value); |
| 2594 |
|
| 2595 |
view.autofill(value); |
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
setAutofilledIfValuesIs(view, value, hideHighlight); |
| 2602 |
|
| 2603 |
numApplied++; |
| 2604 |
} |
| 2605 |
} |
| 2606 |
|
| 2607 |
if (failedIds != null) { |
| 2608 |
if (sVerbose) { |
| 2609 |
Log.v(TAG, "autofill(): total failed views: " + failedIds); |
| 2610 |
} |
| 2611 |
try { |
| 2612 |
mService.setAutofillFailure(mSessionId, failedIds, mContext.getUserId()); |
| 2613 |
} catch (RemoteException e) { |
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
throw e.rethrowFromSystemServer(); |
| 2618 |
} |
| 2619 |
} |
| 2620 |
|
| 2621 |
if (virtualValues != null) { |
| 2622 |
for (int i = 0; i < virtualValues.size(); i++) { |
| 2623 |
final View parent = virtualValues.keyAt(i); |
| 2624 |
final SparseArray<AutofillValue> childrenValues = virtualValues.valueAt(i); |
| 2625 |
parent.autofill(childrenValues); |
| 2626 |
numApplied += childrenValues.size(); |
| 2627 |
|
| 2628 |
|
| 2629 |
} |
| 2630 |
} |
| 2631 |
|
| 2632 |
mMetricsLogger.write(newLog(MetricsEvent.AUTOFILL_DATASET_APPLIED) |
| 2633 |
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_NUM_VALUES, itemCount) |
| 2634 |
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_NUM_VIEWS_FILLED, numApplied)); |
| 2635 |
} |
| 2636 |
} |
| 2637 |
|
| 2638 |
private void autofillContent(int sessionId, AutofillId id, ClipData clip) { |
| 2639 |
synchronized (mLock) { |
| 2640 |
if (sessionId != mSessionId) { |
| 2641 |
return; |
| 2642 |
} |
| 2643 |
final AutofillClient client = getClient(); |
| 2644 |
if (client == null) { |
| 2645 |
return; |
| 2646 |
} |
| 2647 |
final View view = client.autofillClientFindViewByAutofillIdTraversal(id); |
| 2648 |
if (view == null) { |
| 2649 |
|
| 2650 |
|
| 2651 |
|
| 2652 |
Log.d(TAG, "autofillContent(): no view with id " + id); |
| 2653 |
reportAutofillContentFailure(id); |
| 2654 |
return; |
| 2655 |
} |
| 2656 |
ContentInfo payload = new ContentInfo.Builder(clip, SOURCE_AUTOFILL).build(); |
| 2657 |
ContentInfo result = view.performReceiveContent(payload); |
| 2658 |
if (result != null) { |
| 2659 |
Log.w(TAG, "autofillContent(): receiver could not insert content: id=" + id |
| 2660 |
+ ", view=" + view + ", clip=" + clip); |
| 2661 |
reportAutofillContentFailure(id); |
| 2662 |
return; |
| 2663 |
} |
| 2664 |
mMetricsLogger.write(newLog(MetricsEvent.AUTOFILL_DATASET_APPLIED) |
| 2665 |
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_NUM_VALUES, 1) |
| 2666 |
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_NUM_VIEWS_FILLED, 1)); |
| 2667 |
} |
| 2668 |
} |
| 2669 |
|
| 2670 |
private void reportAutofillContentFailure(AutofillId id) { |
| 2671 |
try { |
| 2672 |
mService.setAutofillFailure(mSessionId, Collections.singletonList(id), |
| 2673 |
mContext.getUserId()); |
| 2674 |
} catch (RemoteException e) { |
| 2675 |
throw e.rethrowFromSystemServer(); |
| 2676 |
} |
| 2677 |
} |
| 2678 |
|
| 2679 |
private LogMaker newLog(int category) { |
| 2680 |
final LogMaker log = new LogMaker(category) |
| 2681 |
.addTaggedData(MetricsEvent.FIELD_AUTOFILL_SESSION_ID, mSessionId); |
| 2682 |
|
| 2683 |
if (isCompatibilityModeEnabledLocked()) { |
| 2684 |
log.addTaggedData(MetricsEvent.FIELD_AUTOFILL_COMPAT_MODE, 1); |
| 2685 |
} |
| 2686 |
final AutofillClient client = getClient(); |
| 2687 |
if (client == null) { |
| 2688 |
|
| 2689 |
log.setPackageName(mContext.getPackageName()); |
| 2690 |
} else { |
| 2691 |
|
| 2692 |
final ComponentName sanitizedComponentName = |
| 2693 |
new ComponentName(client.autofillClientGetComponentName().getPackageName(), ""); |
| 2694 |
log.setComponentName(sanitizedComponentName); |
| 2695 |
} |
| 2696 |
return log; |
| 2697 |
} |
| 2698 |
|
| 2699 |
|
| 2700 |
|
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
|
| 2705 |
|
| 2706 |
|
| 2707 |
|
| 2708 |
private void setTrackedViews(int sessionId, @Nullable AutofillId[] trackedIds, |
| 2709 |
boolean saveOnAllViewsInvisible, boolean saveOnFinish, |
| 2710 |
@Nullable AutofillId[] fillableIds, @Nullable AutofillId saveTriggerId) { |
| 2711 |
if (saveTriggerId != null) { |
| 2712 |
saveTriggerId.resetSessionId(); |
| 2713 |
} |
| 2714 |
synchronized (mLock) { |
| 2715 |
if (sVerbose) { |
| 2716 |
Log.v(TAG, "setTrackedViews(): sessionId=" + sessionId |
| 2717 |
+ ", trackedIds=" + Arrays.toString(trackedIds) |
| 2718 |
+ ", saveOnAllViewsInvisible=" + saveOnAllViewsInvisible |
| 2719 |
+ ", saveOnFinish=" + saveOnFinish |
| 2720 |
+ ", fillableIds=" + Arrays.toString(fillableIds) |
| 2721 |
+ ", saveTrigerId=" + saveTriggerId |
| 2722 |
+ ", mFillableIds=" + mFillableIds |
| 2723 |
+ ", mEnabled=" + mEnabled |
| 2724 |
+ ", mSessionId=" + mSessionId); |
| 2725 |
} |
| 2726 |
|
| 2727 |
if (mEnabled && mSessionId == sessionId) { |
| 2728 |
mSaveOnFinish = saveOnFinish; |
| 2729 |
if (fillableIds != null) { |
| 2730 |
if (mFillableIds == null) { |
| 2731 |
mFillableIds = new ArraySet<>(fillableIds.length); |
| 2732 |
} |
| 2733 |
for (AutofillId id : fillableIds) { |
| 2734 |
id.resetSessionId(); |
| 2735 |
mFillableIds.add(id); |
| 2736 |
} |
| 2737 |
} |
| 2738 |
|
| 2739 |
if (mSaveTriggerId != null && !mSaveTriggerId.equals(saveTriggerId)) { |
| 2740 |
|
| 2741 |
setNotifyOnClickLocked(mSaveTriggerId, false); |
| 2742 |
} |
| 2743 |
|
| 2744 |
if (saveTriggerId != null && !saveTriggerId.equals(mSaveTriggerId)) { |
| 2745 |
|
| 2746 |
mSaveTriggerId = saveTriggerId; |
| 2747 |
setNotifyOnClickLocked(mSaveTriggerId, true); |
| 2748 |
} |
| 2749 |
|
| 2750 |
if (!saveOnAllViewsInvisible) { |
| 2751 |
trackedIds = null; |
| 2752 |
} |
| 2753 |
|
| 2754 |
final ArraySet<AutofillId> allFillableIds = new ArraySet<>(); |
| 2755 |
if (mFillableIds != null) { |
| 2756 |
allFillableIds.addAll(mFillableIds); |
| 2757 |
} |
| 2758 |
if (trackedIds != null) { |
| 2759 |
for (AutofillId id : trackedIds) { |
| 2760 |
id.resetSessionId(); |
| 2761 |
allFillableIds.add(id); |
| 2762 |
} |
| 2763 |
} |
| 2764 |
|
| 2765 |
if (!allFillableIds.isEmpty()) { |
| 2766 |
mTrackedViews = new TrackedViews(trackedIds, Helper.toArray(allFillableIds)); |
| 2767 |
} else { |
| 2768 |
mTrackedViews = null; |
| 2769 |
} |
| 2770 |
} |
| 2771 |
} |
| 2772 |
} |
| 2773 |
|
| 2774 |
private void setNotifyOnClickLocked(@NonNull AutofillId id, boolean notify) { |
| 2775 |
final View view = findView(id); |
| 2776 |
if (view == null) { |
| 2777 |
Log.w(TAG, "setNotifyOnClick(): invalid id: " + id); |
| 2778 |
return; |
| 2779 |
} |
| 2780 |
view.setNotifyAutofillManagerOnClick(notify); |
| 2781 |
} |
| 2782 |
|
| 2783 |
private void setSaveUiState(int sessionId, boolean shown) { |
| 2784 |
if (sDebug) Log.d(TAG, "setSaveUiState(" + sessionId + "): " + shown); |
| 2785 |
synchronized (mLock) { |
| 2786 |
if (mSessionId != NO_SESSION) { |
| 2787 |
|
| 2788 |
|
| 2789 |
|
| 2790 |
Log.w(TAG, "setSaveUiState(" + sessionId + ", " + shown |
| 2791 |
+ ") called on existing session " + mSessionId + "; cancelling it"); |
| 2792 |
cancelSessionLocked(); |
| 2793 |
} |
| 2794 |
if (shown) { |
| 2795 |
mSessionId = sessionId; |
| 2796 |
mState = STATE_SHOWING_SAVE_UI; |
| 2797 |
} else { |
| 2798 |
mSessionId = NO_SESSION; |
| 2799 |
mState = STATE_UNKNOWN; |
| 2800 |
} |
| 2801 |
} |
| 2802 |
} |
| 2803 |
|
| 2804 |
|
| 2805 |
|
| 2806 |
|
| 2807 |
|
| 2808 |
|
| 2809 |
|
| 2810 |
|
| 2811 |
|
| 2812 |
|
| 2813 |
|
| 2814 |
|
| 2815 |
|
| 2816 |
private void setSessionFinished(int newState, @Nullable List<AutofillId> autofillableIds) { |
| 2817 |
if (autofillableIds != null) { |
| 2818 |
for (int i = 0; i < autofillableIds.size(); i++) { |
| 2819 |
autofillableIds.get(i).resetSessionId(); |
| 2820 |
} |
| 2821 |
} |
| 2822 |
synchronized (mLock) { |
| 2823 |
if (sVerbose) { |
| 2824 |
Log.v(TAG, "setSessionFinished(): from " + getStateAsStringLocked() + " to " |
| 2825 |
+ getStateAsString(newState) + "; autofillableIds=" + autofillableIds); |
| 2826 |
} |
| 2827 |
if (autofillableIds != null) { |
| 2828 |
mEnteredIds = new ArraySet<>(autofillableIds); |
| 2829 |
} |
| 2830 |
if (newState == STATE_UNKNOWN_COMPAT_MODE || newState == STATE_UNKNOWN_FAILED) { |
| 2831 |
resetSessionLocked( true); |
| 2832 |
mState = STATE_UNKNOWN; |
| 2833 |
} else { |
| 2834 |
resetSessionLocked( false); |
| 2835 |
mState = newState; |
| 2836 |
} |
| 2837 |
} |
| 2838 |
} |
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
|
| 2846 |
private void getAugmentedAutofillClient(@NonNull IResultReceiver result) { |
| 2847 |
synchronized (mLock) { |
| 2848 |
if (mAugmentedAutofillServiceClient == null) { |
| 2849 |
mAugmentedAutofillServiceClient = new AugmentedAutofillManagerClient(this); |
| 2850 |
} |
| 2851 |
final Bundle resultData = new Bundle(); |
| 2852 |
resultData.putBinder(EXTRA_AUGMENTED_AUTOFILL_CLIENT, |
| 2853 |
mAugmentedAutofillServiceClient.asBinder()); |
| 2854 |
|
| 2855 |
try { |
| 2856 |
result.send(0, resultData); |
| 2857 |
} catch (RemoteException e) { |
| 2858 |
Log.w(TAG, "Could not send AugmentedAutofillClient back: " + e); |
| 2859 |
} |
| 2860 |
} |
| 2861 |
} |
| 2862 |
|
| 2863 |
private void requestShowSoftInput(@NonNull AutofillId id) { |
| 2864 |
if (sVerbose) Log.v(TAG, "requestShowSoftInput(" + id + ")"); |
| 2865 |
final AutofillClient client = getClient(); |
| 2866 |
if (client == null) { |
| 2867 |
return; |
| 2868 |
} |
| 2869 |
final View view = client.autofillClientFindViewByAutofillIdTraversal(id); |
| 2870 |
if (view == null) { |
| 2871 |
if (sVerbose) Log.v(TAG, "View is not found"); |
| 2872 |
return; |
| 2873 |
} |
| 2874 |
final Handler handler = view.getHandler(); |
| 2875 |
if (handler == null) { |
| 2876 |
if (sVerbose) Log.v(TAG, "Ignoring requestShowSoftInput due to no handler in view"); |
| 2877 |
return; |
| 2878 |
} |
| 2879 |
if (handler.getLooper() != Looper.myLooper()) { |
| 2880 |
|
| 2881 |
|
| 2882 |
if (sVerbose) Log.v(TAG, "Scheduling showSoftInput() on the view UI thread"); |
| 2883 |
handler.post(() -> requestShowSoftInputInViewThread(view)); |
| 2884 |
} else { |
| 2885 |
requestShowSoftInputInViewThread(view); |
| 2886 |
} |
| 2887 |
} |
| 2888 |
|
| 2889 |
|
| 2890 |
private static void requestShowSoftInputInViewThread(@NonNull View view) { |
| 2891 |
if (!view.isFocused()) { |
| 2892 |
Log.w(TAG, "Ignoring requestShowSoftInput() due to non-focused view"); |
| 2893 |
return; |
| 2894 |
} |
| 2895 |
final InputMethodManager inputMethodManager = view.getContext().getSystemService( |
| 2896 |
InputMethodManager.class); |
| 2897 |
boolean ret = inputMethodManager.showSoftInput(view, 0); |
| 2898 |
if (sVerbose) Log.v(TAG, " InputMethodManager.showSoftInput returns " + ret); |
| 2899 |
} |
| 2900 |
|
| 2901 |
|
| 2902 |
public void requestHideFillUi() { |
| 2903 |
requestHideFillUi(mIdShownFillUi, true); |
| 2904 |
} |
| 2905 |
|
| 2906 |
private void requestHideFillUi(AutofillId id, boolean force) { |
| 2907 |
final View anchor = id == null ? null : findView(id); |
| 2908 |
if (sVerbose) Log.v(TAG, "requestHideFillUi(" + id + "): anchor = " + anchor); |
| 2909 |
if (anchor == null) { |
| 2910 |
if (force) { |
| 2911 |
|
| 2912 |
|
| 2913 |
AutofillClient client = getClient(); |
| 2914 |
if (client != null) { |
| 2915 |
client.autofillClientRequestHideFillUi(); |
| 2916 |
} |
| 2917 |
} |
| 2918 |
return; |
| 2919 |
} |
| 2920 |
requestHideFillUi(id, anchor); |
| 2921 |
} |
| 2922 |
|
| 2923 |
private void requestHideFillUi(AutofillId id, View anchor) { |
| 2924 |
|
| 2925 |
AutofillCallback callback = null; |
| 2926 |
synchronized (mLock) { |
| 2927 |
|
| 2928 |
|
| 2929 |
|
| 2930 |
|
| 2931 |
AutofillClient client = getClient(); |
| 2932 |
if (client != null) { |
| 2933 |
if (client.autofillClientRequestHideFillUi()) { |
| 2934 |
mIdShownFillUi = null; |
| 2935 |
callback = mCallback; |
| 2936 |
} |
| 2937 |
} |
| 2938 |
} |
| 2939 |
|
| 2940 |
if (callback != null) { |
| 2941 |
if (id.isVirtualInt()) { |
| 2942 |
callback.onAutofillEvent(anchor, id.getVirtualChildIntId(), |
| 2943 |
AutofillCallback.EVENT_INPUT_HIDDEN); |
| 2944 |
} else { |
| 2945 |
callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_HIDDEN); |
| 2946 |
} |
| 2947 |
} |
| 2948 |
} |
| 2949 |
|
| 2950 |
private void notifyDisableAutofill(long disableDuration, ComponentName componentName) { |
| 2951 |
synchronized (mLock) { |
| 2952 |
if (mOptions == null) { |
| 2953 |
return; |
| 2954 |
} |
| 2955 |
long expiration = SystemClock.elapsedRealtime() + disableDuration; |
| 2956 |
|
| 2957 |
if (expiration < 0) { |
| 2958 |
expiration = Long.MAX_VALUE; |
| 2959 |
} |
| 2960 |
if (componentName != null) { |
| 2961 |
if (mOptions.disabledActivities == null) { |
| 2962 |
mOptions.disabledActivities = new ArrayMap<>(); |
| 2963 |
} |
| 2964 |
mOptions.disabledActivities.put(componentName.flattenToString(), expiration); |
| 2965 |
} else { |
| 2966 |
mOptions.appDisabledExpiration = expiration; |
| 2967 |
} |
| 2968 |
} |
| 2969 |
} |
| 2970 |
|
| 2971 |
void notifyReenableAutofill() { |
| 2972 |
synchronized (mLock) { |
| 2973 |
if (mOptions == null) { |
| 2974 |
return; |
| 2975 |
} |
| 2976 |
mOptions.appDisabledExpiration = 0; |
| 2977 |
mOptions.disabledActivities = null; |
| 2978 |
} |
| 2979 |
} |
| 2980 |
|
| 2981 |
private void notifyNoFillUi(int sessionId, AutofillId id, int sessionFinishedState) { |
| 2982 |
if (sVerbose) { |
| 2983 |
Log.v(TAG, "notifyNoFillUi(): sessionFinishedState=" + sessionFinishedState); |
| 2984 |
} |
| 2985 |
final View anchor = findView(id); |
| 2986 |
if (anchor == null) { |
| 2987 |
return; |
| 2988 |
} |
| 2989 |
|
| 2990 |
notifyCallback(sessionId, id, AutofillCallback.EVENT_INPUT_UNAVAILABLE); |
| 2991 |
|
| 2992 |
if (sessionFinishedState != STATE_UNKNOWN) { |
| 2993 |
|
| 2994 |
setSessionFinished(sessionFinishedState, null); |
| 2995 |
} |
| 2996 |
} |
| 2997 |
|
| 2998 |
private void notifyCallback( |
| 2999 |
int sessionId, AutofillId id, @AutofillCallback.AutofillEventType int event) { |
| 3000 |
if (sVerbose) { |
| 3001 |
Log.v(TAG, "notifyCallback(): sessionId=" + sessionId + ", autofillId=" + id |
| 3002 |
+ ", event=" + event); |
| 3003 |
} |
| 3004 |
final View anchor = findView(id); |
| 3005 |
if (anchor == null) { |
| 3006 |
return; |
| 3007 |
} |
| 3008 |
|
| 3009 |
AutofillCallback callback = null; |
| 3010 |
synchronized (mLock) { |
| 3011 |
if (mSessionId == sessionId && getClient() != null) { |
| 3012 |
callback = mCallback; |
| 3013 |
} |
| 3014 |
} |
| 3015 |
|
| 3016 |
if (callback != null) { |
| 3017 |
if (id.isVirtualInt()) { |
| 3018 |
callback.onAutofillEvent( |
| 3019 |
anchor, id.getVirtualChildIntId(), event); |
| 3020 |
} else { |
| 3021 |
callback.onAutofillEvent(anchor, event); |
| 3022 |
} |
| 3023 |
} |
| 3024 |
} |
| 3025 |
|
| 3026 |
|
| 3027 |
|
| 3028 |
|
| 3029 |
|
| 3030 |
|
| 3031 |
|
| 3032 |
|
| 3033 |
private View findView(@NonNull AutofillId autofillId) { |
| 3034 |
final AutofillClient client = getClient(); |
| 3035 |
if (client != null) { |
| 3036 |
return client.autofillClientFindViewByAutofillIdTraversal(autofillId); |
| 3037 |
} |
| 3038 |
return null; |
| 3039 |
} |
| 3040 |
|
| 3041 |
|
| 3042 |
public boolean hasAutofillFeature() { |
| 3043 |
return mService != null; |
| 3044 |
} |
| 3045 |
|
| 3046 |
|
| 3047 |
public void onPendingSaveUi(int operation, IBinder token) { |
| 3048 |
if (sVerbose) Log.v(TAG, "onPendingSaveUi(" + operation + "): " + token); |
| 3049 |
|
| 3050 |
synchronized (mLock) { |
| 3051 |
try { |
| 3052 |
mService.onPendingSaveUi(operation, token); |
| 3053 |
} catch (RemoteException e) { |
| 3054 |
Log.e(TAG, "Error in onPendingSaveUi: ", e); |
| 3055 |
} |
| 3056 |
} |
| 3057 |
} |
| 3058 |
|
| 3059 |
|
| 3060 |
public void dump(String outerPrefix, PrintWriter pw) { |
| 3061 |
pw.print(outerPrefix); pw.println("AutofillManager:"); |
| 3062 |
final String pfx = outerPrefix + " "; |
| 3063 |
pw.print(pfx); pw.print("sessionId: "); pw.println(mSessionId); |
| 3064 |
pw.print(pfx); pw.print("state: "); pw.println(getStateAsStringLocked()); |
| 3065 |
pw.print(pfx); pw.print("context: "); pw.println(mContext); |
| 3066 |
pw.print(pfx); pw.print("service client: "); pw.println(mServiceClient); |
| 3067 |
final AutofillClient client = getClient(); |
| 3068 |
if (client != null) { |
| 3069 |
pw.print(pfx); pw.print("client: "); pw.print(client); |
| 3070 |
pw.print(" ("); pw.print(client.autofillClientGetActivityToken()); pw.println(')'); |
| 3071 |
} |
| 3072 |
pw.print(pfx); pw.print("enabled: "); pw.println(mEnabled); |
| 3073 |
pw.print(pfx); pw.print("enabledAugmentedOnly: "); pw.println(mForAugmentedAutofillOnly); |
| 3074 |
pw.print(pfx); pw.print("hasService: "); pw.println(mService != null); |
| 3075 |
pw.print(pfx); pw.print("hasCallback: "); pw.println(mCallback != null); |
| 3076 |
pw.print(pfx); pw.print("onInvisibleCalled "); pw.println(mOnInvisibleCalled); |
| 3077 |
pw.print(pfx); pw.print("last autofilled data: "); pw.println(mLastAutofilledData); |
| 3078 |
pw.print(pfx); pw.print("id of last fill UI shown: "); pw.println(mIdShownFillUi); |
| 3079 |
pw.print(pfx); pw.print("tracked views: "); |
| 3080 |
if (mTrackedViews == null) { |
| 3081 |
pw.println("null"); |
| 3082 |
} else { |
| 3083 |
final String pfx2 = pfx + " "; |
| 3084 |
pw.println(); |
| 3085 |
pw.print(pfx2); pw.print("visible:"); pw.println(mTrackedViews.mVisibleTrackedIds); |
| 3086 |
pw.print(pfx2); pw.print("invisible:"); pw.println(mTrackedViews.mInvisibleTrackedIds); |
| 3087 |
} |
| 3088 |
pw.print(pfx); pw.print("fillable ids: "); pw.println(mFillableIds); |
| 3089 |
pw.print(pfx); pw.print("entered ids: "); pw.println(mEnteredIds); |
| 3090 |
if (mEnteredForAugmentedAutofillIds != null) { |
| 3091 |
pw.print(pfx); pw.print("entered ids for augmented autofill: "); |
| 3092 |
pw.println(mEnteredForAugmentedAutofillIds); |
| 3093 |
} |
| 3094 |
if (mForAugmentedAutofillOnly) { |
| 3095 |
pw.print(pfx); pw.println("For Augmented Autofill Only"); |
| 3096 |
} |
| 3097 |
pw.print(pfx); pw.print("save trigger id: "); pw.println(mSaveTriggerId); |
| 3098 |
pw.print(pfx); pw.print("save on finish(): "); pw.println(mSaveOnFinish); |
| 3099 |
if (mOptions != null) { |
| 3100 |
pw.print(pfx); pw.print("options: "); mOptions.dumpShort(pw); pw.println(); |
| 3101 |
} |
| 3102 |
pw.print(pfx); pw.print("compat mode enabled: "); |
| 3103 |
synchronized (mLock) { |
| 3104 |
pw.print(pfx); pw.print("fill dialog enabled: "); pw.println(mIsFillDialogEnabled); |
| 3105 |
pw.print(pfx); pw.print("fill dialog enabled hints: "); |
| 3106 |
pw.println(Arrays.toString(mFillDialogEnabledHints)); |
| 3107 |
if (mCompatibilityBridge != null) { |
| 3108 |
final String pfx2 = pfx + " "; |
| 3109 |
pw.println("true"); |
| 3110 |
pw.print(pfx2); pw.print("windowId: "); |
| 3111 |
pw.println(mCompatibilityBridge.mFocusedWindowId); |
| 3112 |
pw.print(pfx2); pw.print("nodeId: "); |
| 3113 |
pw.println(mCompatibilityBridge.mFocusedNodeId); |
| 3114 |
pw.print(pfx2); pw.print("virtualId: "); |
| 3115 |
pw.println(AccessibilityNodeInfo |
| 3116 |
.getVirtualDescendantId(mCompatibilityBridge.mFocusedNodeId)); |
| 3117 |
pw.print(pfx2); pw.print("focusedBounds: "); |
| 3118 |
pw.println(mCompatibilityBridge.mFocusedBounds); |
| 3119 |
} else { |
| 3120 |
pw.println("false"); |
| 3121 |
} |
| 3122 |
} |
| 3123 |
pw.print(pfx); pw.print("debug: "); pw.print(sDebug); |
| 3124 |
pw.print(" verbose: "); pw.println(sVerbose); |
| 3125 |
} |
| 3126 |
|
| 3127 |
@GuardedBy("mLock") |
| 3128 |
private String getStateAsStringLocked() { |
| 3129 |
return getStateAsString(mState); |
| 3130 |
} |
| 3131 |
|
| 3132 |
@NonNull |
| 3133 |
private static String getStateAsString(int state) { |
| 3134 |
switch (state) { |
| 3135 |
case STATE_UNKNOWN: |
| 3136 |
return "UNKNOWN"; |
| 3137 |
case STATE_ACTIVE: |
| 3138 |
return "ACTIVE"; |
| 3139 |
case STATE_FINISHED: |
| 3140 |
return "FINISHED"; |
| 3141 |
case STATE_SHOWING_SAVE_UI: |
| 3142 |
return "SHOWING_SAVE_UI"; |
| 3143 |
case STATE_DISABLED_BY_SERVICE: |
| 3144 |
return "DISABLED_BY_SERVICE"; |
| 3145 |
case STATE_UNKNOWN_COMPAT_MODE: |
| 3146 |
return "UNKNOWN_COMPAT_MODE"; |
| 3147 |
case STATE_UNKNOWN_FAILED: |
| 3148 |
return "UNKNOWN_FAILED"; |
| 3149 |
default: |
| 3150 |
return "INVALID:" + state; |
| 3151 |
} |
| 3152 |
} |
| 3153 |
|
| 3154 |
|
| 3155 |
public static String getSmartSuggestionModeToString(@SmartSuggestionMode int flags) { |
| 3156 |
switch (flags) { |
| 3157 |
case FLAG_SMART_SUGGESTION_OFF: |
| 3158 |
return "OFF"; |
| 3159 |
case FLAG_SMART_SUGGESTION_SYSTEM: |
| 3160 |
return "SYSTEM"; |
| 3161 |
default: |
| 3162 |
return "INVALID:" + flags; |
| 3163 |
} |
| 3164 |
} |
| 3165 |
|
| 3166 |
@GuardedBy("mLock") |
| 3167 |
private boolean isActiveLocked() { |
| 3168 |
return mState == STATE_ACTIVE; |
| 3169 |
} |
| 3170 |
|
| 3171 |
@GuardedBy("mLock") |
| 3172 |
private boolean isDisabledByServiceLocked() { |
| 3173 |
return mState == STATE_DISABLED_BY_SERVICE; |
| 3174 |
} |
| 3175 |
|
| 3176 |
@GuardedBy("mLock") |
| 3177 |
private boolean isFinishedLocked() { |
| 3178 |
return mState == STATE_FINISHED; |
| 3179 |
} |
| 3180 |
|
| 3181 |
private void post(Runnable runnable) { |
| 3182 |
final AutofillClient client = getClient(); |
| 3183 |
if (client == null) { |
| 3184 |
if (sVerbose) Log.v(TAG, "ignoring post() because client is null"); |
| 3185 |
return; |
| 3186 |
} |
| 3187 |
client.autofillClientRunOnUiThread(runnable); |
| 3188 |
} |
| 3189 |
|
| 3190 |
private void setFillDialogTriggerIds(@Nullable List<AutofillId> ids) { |
| 3191 |
mFillDialogTriggerIds = ids; |
| 3192 |
} |
| 3193 |
|
| 3194 |
|
| 3195 |
|
| 3196 |
|
| 3197 |
|
| 3198 |
|
| 3199 |
|
| 3200 |
|
| 3201 |
|
| 3202 |
|
| 3203 |
|
| 3204 |
|
| 3205 |
|
| 3206 |
|
| 3207 |
|
| 3208 |
|
| 3209 |
|
| 3210 |
|
| 3211 |
|
| 3212 |
|
| 3213 |
|
| 3214 |
|
| 3215 |
|
| 3216 |
public boolean showAutofillDialog(@NonNull View view) { |
| 3217 |
Objects.requireNonNull(view); |
| 3218 |
if (shouldShowAutofillDialog(view, view.getAutofillId())) { |
| 3219 |
mShowAutofillDialogCalled = true; |
| 3220 |
final WeakReference<View> wrView = new WeakReference<>(view); |
| 3221 |
|
| 3222 |
post(() -> { |
| 3223 |
final View v = wrView.get(); |
| 3224 |
if (v != null) { |
| 3225 |
notifyViewEntered(v); |
| 3226 |
} |
| 3227 |
}); |
| 3228 |
return true; |
| 3229 |
} |
| 3230 |
return false; |
| 3231 |
} |
| 3232 |
|
| 3233 |
|
| 3234 |
|
| 3235 |
|
| 3236 |
|
| 3237 |
|
| 3238 |
|
| 3239 |
|
| 3240 |
|
| 3241 |
|
| 3242 |
|
| 3243 |
|
| 3244 |
|
| 3245 |
|
| 3246 |
|
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
|
| 3253 |
|
| 3254 |
public boolean showAutofillDialog(@NonNull View view, int virtualId) { |
| 3255 |
Objects.requireNonNull(view); |
| 3256 |
if (shouldShowAutofillDialog(view, getAutofillId(view, virtualId))) { |
| 3257 |
mShowAutofillDialogCalled = true; |
| 3258 |
final WeakReference<View> wrView = new WeakReference<>(view); |
| 3259 |
|
| 3260 |
post(() -> { |
| 3261 |
final View v = wrView.get(); |
| 3262 |
if (v != null) { |
| 3263 |
notifyViewEntered(v, virtualId, null, 0); |
| 3264 |
} |
| 3265 |
}); |
| 3266 |
return true; |
| 3267 |
} |
| 3268 |
return false; |
| 3269 |
} |
| 3270 |
|
| 3271 |
private boolean shouldShowAutofillDialog(View view, AutofillId id) { |
| 3272 |
if (!hasFillDialogUiFeature() |
| 3273 |
|| mShowAutofillDialogCalled |
| 3274 |
|| mFillDialogTriggerIds == null) { |
| 3275 |
return false; |
| 3276 |
} |
| 3277 |
|
| 3278 |
if (getImeStateFlag(view) == FLAG_IME_SHOWING) { |
| 3279 |
|
| 3280 |
return false; |
| 3281 |
} |
| 3282 |
|
| 3283 |
final int size = mFillDialogTriggerIds.size(); |
| 3284 |
for (int i = 0; i < size; i++) { |
| 3285 |
AutofillId fillId = mFillDialogTriggerIds.get(i); |
| 3286 |
if (fillId.equalsIgnoreSession(id)) { |
| 3287 |
return true; |
| 3288 |
} |
| 3289 |
} |
| 3290 |
return false; |
| 3291 |
} |
| 3292 |
|
| 3293 |
|
| 3294 |
|
| 3295 |
|
| 3296 |
private final class CompatibilityBridge implements AccessibilityManager.AccessibilityPolicy { |
| 3297 |
@GuardedBy("mLock") |
| 3298 |
private final Rect mFocusedBounds = new Rect(); |
| 3299 |
@GuardedBy("mLock") |
| 3300 |
private final Rect mTempBounds = new Rect(); |
| 3301 |
|
| 3302 |
@GuardedBy("mLock") |
| 3303 |
private int mFocusedWindowId = AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
| 3304 |
@GuardedBy("mLock") |
| 3305 |
private long mFocusedNodeId = AccessibilityNodeInfo.UNDEFINED_NODE_ID; |
| 3306 |
|
| 3307 |
|
| 3308 |
@NonNull |
| 3309 |
@GuardedBy("mLock") |
| 3310 |
AccessibilityServiceInfo mCompatServiceInfo; |
| 3311 |
|
| 3312 |
CompatibilityBridge() { |
| 3313 |
final AccessibilityManager am = AccessibilityManager.getInstance(mContext); |
| 3314 |
am.setAccessibilityPolicy(this); |
| 3315 |
} |
| 3316 |
|
| 3317 |
private AccessibilityServiceInfo getCompatServiceInfo() { |
| 3318 |
synchronized (mLock) { |
| 3319 |
if (mCompatServiceInfo != null) { |
| 3320 |
return mCompatServiceInfo; |
| 3321 |
} |
| 3322 |
final Intent intent = new Intent(); |
| 3323 |
intent.setComponent(new ComponentName("android", |
| 3324 |
"com.android.server.autofill.AutofillCompatAccessibilityService")); |
| 3325 |
final ResolveInfo resolveInfo = mContext.getPackageManager().resolveService( |
| 3326 |
intent, PackageManager.MATCH_SYSTEM_ONLY | PackageManager.GET_META_DATA); |
| 3327 |
try { |
| 3328 |
mCompatServiceInfo = new AccessibilityServiceInfo(resolveInfo, mContext); |
| 3329 |
} catch (XmlPullParserException | IOException e) { |
| 3330 |
Log.e(TAG, "Cannot find compat autofill service:" + intent); |
| 3331 |
throw new IllegalStateException("Cannot find compat autofill service"); |
| 3332 |
} |
| 3333 |
return mCompatServiceInfo; |
| 3334 |
} |
| 3335 |
} |
| 3336 |
|
| 3337 |
@Override |
| 3338 |
public boolean isEnabled(boolean accessibilityEnabled) { |
| 3339 |
return true; |
| 3340 |
} |
| 3341 |
|
| 3342 |
@Override |
| 3343 |
public int getRelevantEventTypes(int relevantEventTypes) { |
| 3344 |
return relevantEventTypes | AccessibilityEvent.TYPE_VIEW_FOCUSED |
| 3345 |
| AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED |
| 3346 |
| AccessibilityEvent.TYPE_VIEW_CLICKED |
| 3347 |
| AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED; |
| 3348 |
} |
| 3349 |
|
| 3350 |
@Override |
| 3351 |
public List<AccessibilityServiceInfo> getInstalledAccessibilityServiceList( |
| 3352 |
List<AccessibilityServiceInfo> installedServices) { |
| 3353 |
if (installedServices == null) { |
| 3354 |
installedServices = new ArrayList<>(); |
| 3355 |
} |
| 3356 |
installedServices.add(getCompatServiceInfo()); |
| 3357 |
return installedServices; |
| 3358 |
} |
| 3359 |
|
| 3360 |
@Override |
| 3361 |
public List<AccessibilityServiceInfo> getEnabledAccessibilityServiceList( |
| 3362 |
int feedbackTypeFlags, List<AccessibilityServiceInfo> enabledService) { |
| 3363 |
if (enabledService == null) { |
| 3364 |
enabledService = new ArrayList<>(); |
| 3365 |
} |
| 3366 |
enabledService.add(getCompatServiceInfo()); |
| 3367 |
return enabledService; |
| 3368 |
} |
| 3369 |
|
| 3370 |
@Override |
| 3371 |
public AccessibilityEvent onAccessibilityEvent(AccessibilityEvent event, |
| 3372 |
boolean accessibilityEnabled, int relevantEventTypes) { |
| 3373 |
final int type = event.getEventType(); |
| 3374 |
if (sVerbose) { |
| 3375 |
|
| 3376 |
Log.v(TAG, "onAccessibilityEvent(" + AccessibilityEvent.eventTypeToString(type) |
| 3377 |
+ "): virtualId=" |
| 3378 |
+ AccessibilityNodeInfo.getVirtualDescendantId(event.getSourceNodeId()) |
| 3379 |
+ ", client=" + getClient()); |
| 3380 |
} |
| 3381 |
switch (type) { |
| 3382 |
case AccessibilityEvent.TYPE_VIEW_FOCUSED: { |
| 3383 |
synchronized (mLock) { |
| 3384 |
if (mFocusedWindowId == event.getWindowId() |
| 3385 |
&& mFocusedNodeId == event.getSourceNodeId()) { |
| 3386 |
return event; |
| 3387 |
} |
| 3388 |
if (mFocusedWindowId != AccessibilityWindowInfo.UNDEFINED_WINDOW_ID |
| 3389 |
&& mFocusedNodeId != AccessibilityNodeInfo.UNDEFINED_NODE_ID) { |
| 3390 |
notifyViewExited(mFocusedWindowId, mFocusedNodeId); |
| 3391 |
mFocusedWindowId = AccessibilityWindowInfo.UNDEFINED_WINDOW_ID; |
| 3392 |
mFocusedNodeId = AccessibilityNodeInfo.UNDEFINED_NODE_ID; |
| 3393 |
mFocusedBounds.set(0, 0, 0, 0); |
| 3394 |
} |
| 3395 |
final int windowId = event.getWindowId(); |
| 3396 |
final long nodeId = event.getSourceNodeId(); |
| 3397 |
if (notifyViewEntered(windowId, nodeId, mFocusedBounds)) { |
| 3398 |
mFocusedWindowId = windowId; |
| 3399 |
mFocusedNodeId = nodeId; |
| 3400 |
} |
| 3401 |
} |
| 3402 |
} break; |
| 3403 |
|
| 3404 |
case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED: { |
| 3405 |
synchronized (mLock) { |
| 3406 |
if (mFocusedWindowId == event.getWindowId() |
| 3407 |
&& mFocusedNodeId == event.getSourceNodeId()) { |
| 3408 |
notifyValueChanged(event.getWindowId(), event.getSourceNodeId()); |
| 3409 |
} |
| 3410 |
} |
| 3411 |
} break; |
| 3412 |
|
| 3413 |
case AccessibilityEvent.TYPE_VIEW_CLICKED: { |
| 3414 |
synchronized (mLock) { |
| 3415 |
notifyViewClicked(event.getWindowId(), event.getSourceNodeId()); |
| 3416 |
} |
| 3417 |
} break; |
| 3418 |
|
| 3419 |
case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: { |
| 3420 |
final AutofillClient client = getClient(); |
| 3421 |
if (client != null) { |
| 3422 |
synchronized (mLock) { |
| 3423 |
if (client.autofillClientIsFillUiShowing()) { |
| 3424 |
notifyViewEntered(mFocusedWindowId, mFocusedNodeId, mFocusedBounds); |
| 3425 |
} |
| 3426 |
updateTrackedViewsLocked(); |
| 3427 |
} |
| 3428 |
} |
| 3429 |
} break; |
| 3430 |
} |
| 3431 |
|
| 3432 |
return accessibilityEnabled ? event : null; |
| 3433 |
} |
| 3434 |
|
| 3435 |
private boolean notifyViewEntered(int windowId, long nodeId, Rect focusedBounds) { |
| 3436 |
final int virtualId = AccessibilityNodeInfo.getVirtualDescendantId(nodeId); |
| 3437 |
if (!isVirtualNode(virtualId)) { |
| 3438 |
return false; |
| 3439 |
} |
| 3440 |
final View view = findViewByAccessibilityId(windowId, nodeId); |
| 3441 |
if (view == null) { |
| 3442 |
return false; |
| 3443 |
} |
| 3444 |
final AccessibilityNodeInfo node = findVirtualNodeByAccessibilityId(view, virtualId); |
| 3445 |
if (node == null) { |
| 3446 |
return false; |
| 3447 |
} |
| 3448 |
if (!node.isEditable()) { |
| 3449 |
return false; |
| 3450 |
} |
| 3451 |
final Rect newBounds = mTempBounds; |
| 3452 |
node.getBoundsInScreen(newBounds); |
| 3453 |
if (newBounds.equals(focusedBounds)) { |
| 3454 |
return false; |
| 3455 |
} |
| 3456 |
focusedBounds.set(newBounds); |
| 3457 |
AutofillManager.this.notifyViewEntered(view, virtualId, newBounds); |
| 3458 |
return true; |
| 3459 |
} |
| 3460 |
|
| 3461 |
private void notifyViewExited(int windowId, long nodeId) { |
| 3462 |
final int virtualId = AccessibilityNodeInfo.getVirtualDescendantId(nodeId); |
| 3463 |
if (!isVirtualNode(virtualId)) { |
| 3464 |
return; |
| 3465 |
} |
| 3466 |
final View view = findViewByAccessibilityId(windowId, nodeId); |
| 3467 |
if (view == null) { |
| 3468 |
return; |
| 3469 |
} |
| 3470 |
AutofillManager.this.notifyViewExited(view, virtualId); |
| 3471 |
} |
| 3472 |
|
| 3473 |
private void notifyValueChanged(int windowId, long nodeId) { |
| 3474 |
final int virtualId = AccessibilityNodeInfo.getVirtualDescendantId(nodeId); |
| 3475 |
if (!isVirtualNode(virtualId)) { |
| 3476 |
return; |
| 3477 |
} |
| 3478 |
final View view = findViewByAccessibilityId(windowId, nodeId); |
| 3479 |
if (view == null) { |
| 3480 |
return; |
| 3481 |
} |
| 3482 |
final AccessibilityNodeInfo node = findVirtualNodeByAccessibilityId(view, virtualId); |
| 3483 |
if (node == null) { |
| 3484 |
return; |
| 3485 |
} |
| 3486 |
AutofillManager.this.notifyValueChanged(view, virtualId, |
| 3487 |
AutofillValue.forText(node.getText())); |
| 3488 |
} |
| 3489 |
|
| 3490 |
private void notifyViewClicked(int windowId, long nodeId) { |
| 3491 |
final int virtualId = AccessibilityNodeInfo.getVirtualDescendantId(nodeId); |
| 3492 |
if (!isVirtualNode(virtualId)) { |
| 3493 |
return; |
| 3494 |
} |
| 3495 |
final View view = findViewByAccessibilityId(windowId, nodeId); |
| 3496 |
if (view == null) { |
| 3497 |
return; |
| 3498 |
} |
| 3499 |
final AccessibilityNodeInfo node = findVirtualNodeByAccessibilityId(view, virtualId); |
| 3500 |
if (node == null) { |
| 3501 |
return; |
| 3502 |
} |
| 3503 |
AutofillManager.this.notifyViewClicked(view, virtualId); |
| 3504 |
} |
| 3505 |
|
| 3506 |
@GuardedBy("mLock") |
| 3507 |
private void updateTrackedViewsLocked() { |
| 3508 |
if (mTrackedViews != null) { |
| 3509 |
mTrackedViews.onVisibleForAutofillChangedLocked(); |
| 3510 |
} |
| 3511 |
} |
| 3512 |
|
| 3513 |
private View findViewByAccessibilityId(int windowId, long nodeId) { |
| 3514 |
final AutofillClient client = getClient(); |
| 3515 |
if (client == null) { |
| 3516 |
return null; |
| 3517 |
} |
| 3518 |
final int viewId = AccessibilityNodeInfo.getAccessibilityViewId(nodeId); |
| 3519 |
return client.autofillClientFindViewByAccessibilityIdTraversal(viewId, windowId); |
| 3520 |
} |
| 3521 |
|
| 3522 |
private AccessibilityNodeInfo findVirtualNodeByAccessibilityId(View view, int virtualId) { |
| 3523 |
final AccessibilityNodeProvider provider = view.getAccessibilityNodeProvider(); |
| 3524 |
if (provider == null) { |
| 3525 |
return null; |
| 3526 |
} |
| 3527 |
return provider.createAccessibilityNodeInfo(virtualId); |
| 3528 |
} |
| 3529 |
|
| 3530 |
private boolean isVirtualNode(int nodeId) { |
| 3531 |
return nodeId != AccessibilityNodeProvider.HOST_VIEW_ID |
| 3532 |
&& nodeId != AccessibilityNodeInfo.UNDEFINED_ITEM_ID; |
| 3533 |
} |
| 3534 |
} |
| 3535 |
|
| 3536 |
|
| 3537 |
|
| 3538 |
|
| 3539 |
private class TrackedViews { |
| 3540 |
|
| 3541 |
@NonNull private final ArraySet<AutofillId> mVisibleTrackedIds; |
| 3542 |
|
| 3543 |
|
| 3544 |
@NonNull private final ArraySet<AutofillId> mInvisibleTrackedIds; |
| 3545 |
|
| 3546 |
|
| 3547 |
@NonNull private final ArraySet<AutofillId> mVisibleDialogTrackedIds; |
| 3548 |
|
| 3549 |
|
| 3550 |
@NonNull private final ArraySet<AutofillId> mInvisibleDialogTrackedIds; |
| 3551 |
|
| 3552 |
boolean mHasNewTrackedView; |
| 3553 |
boolean mIsTrackedSaveView; |
| 3554 |
|
| 3555 |
|
| 3556 |
|
| 3557 |
|
| 3558 |
|
| 3559 |
|
| 3560 |
|
| 3561 |
|
| 3562 |
|
| 3563 |
|
| 3564 |
private <T> boolean isInSet(@Nullable ArraySet<T> set, T value) { |
| 3565 |
return set != null && set.contains(value); |
| 3566 |
} |
| 3567 |
|
| 3568 |
|
| 3569 |
|
| 3570 |
|
| 3571 |
|
| 3572 |
|
| 3573 |
|
| 3574 |
|
| 3575 |
|
| 3576 |
|
| 3577 |
|
| 3578 |
@NonNull |
| 3579 |
private <T> ArraySet<T> addToSet(@Nullable ArraySet<T> set, T valueToAdd) { |
| 3580 |
if (set == null) { |
| 3581 |
set = new ArraySet<>(1); |
| 3582 |
} |
| 3583 |
|
| 3584 |
set.add(valueToAdd); |
| 3585 |
|
| 3586 |
return set; |
| 3587 |
} |
| 3588 |
|
| 3589 |
|
| 3590 |
|
| 3591 |
|
| 3592 |
|
| 3593 |
|
| 3594 |
|
| 3595 |
|
| 3596 |
|
| 3597 |
|
| 3598 |
|
| 3599 |
@Nullable |
| 3600 |
private <T> ArraySet<T> removeFromSet(@Nullable ArraySet<T> set, T valueToRemove) { |
| 3601 |
if (set == null) { |
| 3602 |
return null; |
| 3603 |
} |
| 3604 |
|
| 3605 |
set.remove(valueToRemove); |
| 3606 |
|
| 3607 |
if (set.isEmpty()) { |
| 3608 |
return null; |
| 3609 |
} |
| 3610 |
|
| 3611 |
return set; |
| 3612 |
} |
| 3613 |
|
| 3614 |
|
| 3615 |
|
| 3616 |
|
| 3617 |
|
| 3618 |
|
| 3619 |
TrackedViews(@Nullable AutofillId[] trackedIds, @Nullable AutofillId[] allTrackedIds) { |
| 3620 |
mVisibleTrackedIds = new ArraySet<>(); |
| 3621 |
mInvisibleTrackedIds = new ArraySet<>(); |
| 3622 |
if (!ArrayUtils.isEmpty(trackedIds)) { |
| 3623 |
mIsTrackedSaveView = true; |
| 3624 |
initialTrackedViews(trackedIds, mVisibleTrackedIds, mInvisibleTrackedIds); |
| 3625 |
} |
| 3626 |
|
| 3627 |
mVisibleDialogTrackedIds = new ArraySet<>(); |
| 3628 |
mInvisibleDialogTrackedIds = new ArraySet<>(); |
| 3629 |
if (!ArrayUtils.isEmpty(allTrackedIds)) { |
| 3630 |
initialTrackedViews(allTrackedIds, mVisibleDialogTrackedIds, |
| 3631 |
mInvisibleDialogTrackedIds); |
| 3632 |
mAllTrackedViews.addAll(Arrays.asList(allTrackedIds)); |
| 3633 |
} |
| 3634 |
|
| 3635 |
if (sVerbose) { |
| 3636 |
Log.v(TAG, "TrackedViews(trackedIds=" + Arrays.toString(trackedIds) + "): " |
| 3637 |
+ " mVisibleTrackedIds=" + mVisibleTrackedIds |
| 3638 |
+ " mInvisibleTrackedIds=" + mInvisibleTrackedIds |
| 3639 |
+ " allTrackedIds=" + Arrays.toString(allTrackedIds) |
| 3640 |
+ " mVisibleDialogTrackedIds=" + mVisibleDialogTrackedIds |
| 3641 |
+ " mInvisibleDialogTrackedIds=" + mInvisibleDialogTrackedIds); |
| 3642 |
} |
| 3643 |
|
| 3644 |
if (mIsTrackedSaveView && mVisibleTrackedIds.isEmpty()) { |
| 3645 |
finishSessionLocked( COMMIT_REASON_VIEW_CHANGED); |
| 3646 |
} |
| 3647 |
} |
| 3648 |
|
| 3649 |
private void initialTrackedViews(AutofillId[] trackedIds, |
| 3650 |
@NonNull ArraySet<AutofillId> visibleSet, |
| 3651 |
@NonNull ArraySet<AutofillId> invisibleSet) { |
| 3652 |
final boolean[] isVisible; |
| 3653 |
final AutofillClient client = getClient(); |
| 3654 |
if (ArrayUtils.isEmpty(trackedIds) || client == null) { |
| 3655 |
return; |
| 3656 |
} |
| 3657 |
if (client.autofillClientIsVisibleForAutofill()) { |
| 3658 |
if (sVerbose) Log.v(TAG, "client is visible, check tracked ids"); |
| 3659 |
isVisible = client.autofillClientGetViewVisibility(trackedIds); |
| 3660 |
} else { |
| 3661 |
|
| 3662 |
isVisible = new boolean[trackedIds.length]; |
| 3663 |
} |
| 3664 |
|
| 3665 |
final int numIds = trackedIds.length; |
| 3666 |
for (int i = 0; i < numIds; i++) { |
| 3667 |
final AutofillId id = trackedIds[i]; |
| 3668 |
id.resetSessionId(); |
| 3669 |
|
| 3670 |
if (isVisible[i]) { |
| 3671 |
addToSet(visibleSet, id); |
| 3672 |
} else { |
| 3673 |
addToSet(invisibleSet, id); |
| 3674 |
} |
| 3675 |
} |
| 3676 |
} |
| 3677 |
|
| 3678 |
|
| 3679 |
|
| 3680 |
|
| 3681 |
|
| 3682 |
|
| 3683 |
|
| 3684 |
@GuardedBy("mLock") |
| 3685 |
void notifyViewVisibilityChangedLocked(@NonNull AutofillId id, boolean isVisible) { |
| 3686 |
if (sDebug) { |
| 3687 |
Log.d(TAG, "notifyViewVisibilityChangedLocked(): id=" + id + " isVisible=" |
| 3688 |
+ isVisible); |
| 3689 |
} |
| 3690 |
|
| 3691 |
if (isClientVisibleForAutofillLocked()) { |
| 3692 |
if (isVisible) { |
| 3693 |
if (isInSet(mInvisibleTrackedIds, id)) { |
| 3694 |
removeFromSet(mInvisibleTrackedIds, id); |
| 3695 |
addToSet(mVisibleTrackedIds, id); |
| 3696 |
} |
| 3697 |
if (isInSet(mInvisibleDialogTrackedIds, id)) { |
| 3698 |
removeFromSet(mInvisibleDialogTrackedIds, id); |
| 3699 |
addToSet(mVisibleDialogTrackedIds, id); |
| 3700 |
} |
| 3701 |
} else { |
| 3702 |
if (isInSet(mVisibleTrackedIds, id)) { |
| 3703 |
removeFromSet(mVisibleTrackedIds, id); |
| 3704 |
addToSet(mInvisibleTrackedIds, id); |
| 3705 |
} |
| 3706 |
if (isInSet(mVisibleDialogTrackedIds, id)) { |
| 3707 |
removeFromSet(mVisibleDialogTrackedIds, id); |
| 3708 |
addToSet(mInvisibleDialogTrackedIds, id); |
| 3709 |
} |
| 3710 |
} |
| 3711 |
} |
| 3712 |
|
| 3713 |
if (mIsTrackedSaveView && mVisibleTrackedIds.isEmpty()) { |
| 3714 |
if (sVerbose) { |
| 3715 |
Log.v(TAG, "No more visible ids. Invisible = " + mInvisibleTrackedIds); |
| 3716 |
} |
| 3717 |
finishSessionLocked( COMMIT_REASON_VIEW_CHANGED); |
| 3718 |
|
| 3719 |
} |
| 3720 |
if (mVisibleDialogTrackedIds.isEmpty()) { |
| 3721 |
if (sVerbose) { |
| 3722 |
Log.v(TAG, "No more visible ids. Invisible = " + mInvisibleDialogTrackedIds); |
| 3723 |
} |
| 3724 |
processNoVisibleTrackedAllViews(); |
| 3725 |
} |
| 3726 |
} |
| 3727 |
|
| 3728 |
|
| 3729 |
|
| 3730 |
|
| 3731 |
|
| 3732 |
|
| 3733 |
@GuardedBy("mLock") |
| 3734 |
void onVisibleForAutofillChangedLocked() { |
| 3735 |
|
| 3736 |
|
| 3737 |
AutofillClient client = getClient(); |
| 3738 |
if (client != null) { |
| 3739 |
if (sVerbose) { |
| 3740 |
Log.v(TAG, "onVisibleForAutofillChangedLocked(): inv= " + mInvisibleTrackedIds |
| 3741 |
+ " vis=" + mVisibleTrackedIds); |
| 3742 |
} |
| 3743 |
|
| 3744 |
onVisibleForAutofillChangedInternalLocked(mVisibleTrackedIds, mInvisibleTrackedIds); |
| 3745 |
onVisibleForAutofillChangedInternalLocked( |
| 3746 |
mVisibleDialogTrackedIds, mInvisibleDialogTrackedIds); |
| 3747 |
} |
| 3748 |
|
| 3749 |
if (mIsTrackedSaveView && mVisibleTrackedIds.isEmpty()) { |
| 3750 |
if (sVerbose) { |
| 3751 |
Log.v(TAG, "onVisibleForAutofillChangedLocked(): no more visible ids"); |
| 3752 |
} |
| 3753 |
finishSessionLocked( COMMIT_REASON_VIEW_CHANGED); |
| 3754 |
} |
| 3755 |
if (mVisibleDialogTrackedIds.isEmpty()) { |
| 3756 |
if (sVerbose) { |
| 3757 |
Log.v(TAG, "onVisibleForAutofillChangedLocked(): no more visible ids"); |
| 3758 |
} |
| 3759 |
processNoVisibleTrackedAllViews(); |
| 3760 |
} |
| 3761 |
} |
| 3762 |
|
| 3763 |
void onVisibleForAutofillChangedInternalLocked(@NonNull ArraySet<AutofillId> visibleSet, |
| 3764 |
@NonNull ArraySet<AutofillId> invisibleSet) { |
| 3765 |
|
| 3766 |
|
| 3767 |
if (sVerbose) { |
| 3768 |
Log.v(TAG, "onVisibleForAutofillChangedLocked(): inv= " + invisibleSet |
| 3769 |
+ " vis=" + visibleSet); |
| 3770 |
} |
| 3771 |
|
| 3772 |
ArraySet<AutofillId> allTrackedIds = new ArraySet<>(); |
| 3773 |
allTrackedIds.addAll(visibleSet); |
| 3774 |
allTrackedIds.addAll(invisibleSet); |
| 3775 |
if (!allTrackedIds.isEmpty()) { |
| 3776 |
visibleSet.clear(); |
| 3777 |
invisibleSet.clear(); |
| 3778 |
initialTrackedViews(Helper.toArray(allTrackedIds), visibleSet, invisibleSet); |
| 3779 |
} |
| 3780 |
} |
| 3781 |
|
| 3782 |
private void processNoVisibleTrackedAllViews() { |
| 3783 |
mShowAutofillDialogCalled = false; |
| 3784 |
} |
| 3785 |
|
| 3786 |
void checkViewState(AutofillId id) { |
| 3787 |
if (mAllTrackedViews.contains(id)) { |
| 3788 |
return; |
| 3789 |
} |
| 3790 |
|
| 3791 |
mAllTrackedViews.add(id); |
| 3792 |
if (mHasNewTrackedView) { |
| 3793 |
return; |
| 3794 |
} |
| 3795 |
|
| 3796 |
mIsFillRequested.set(false); |
| 3797 |
mHasNewTrackedView = true; |
| 3798 |
} |
| 3799 |
} |
| 3800 |
|
| 3801 |
|
| 3802 |
|
| 3803 |
|
| 3804 |
|
| 3805 |
|
| 3806 |
|
| 3807 |
public abstract static class AutofillCallback { |
| 3808 |
|
| 3809 |
|
| 3810 |
@IntDef(prefix = { "EVENT_INPUT_" }, value = { |
| 3811 |
EVENT_INPUT_SHOWN, |
| 3812 |
EVENT_INPUT_HIDDEN, |
| 3813 |
EVENT_INPUT_UNAVAILABLE |
| 3814 |
}) |
| 3815 |
@Retention(RetentionPolicy.SOURCE) |
| 3816 |
public @interface AutofillEventType {} |
| 3817 |
|
| 3818 |
|
| 3819 |
|
| 3820 |
|
| 3821 |
|
| 3822 |
|
| 3823 |
|
| 3824 |
public static final int EVENT_INPUT_SHOWN = 1; |
| 3825 |
|
| 3826 |
|
| 3827 |
|
| 3828 |
|
| 3829 |
|
| 3830 |
|
| 3831 |
|
| 3832 |
public static final int EVENT_INPUT_HIDDEN = 2; |
| 3833 |
|
| 3834 |
|
| 3835 |
|
| 3836 |
|
| 3837 |
|
| 3838 |
|
| 3839 |
|
| 3840 |
|
| 3841 |
public static final int EVENT_INPUT_UNAVAILABLE = 3; |
| 3842 |
|
| 3843 |
|
| 3844 |
|
| 3845 |
|
| 3846 |
|
| 3847 |
|
| 3848 |
|
| 3849 |
|
| 3850 |
public void onAutofillEvent(@NonNull View view, @AutofillEventType int event) { |
| 3851 |
} |
| 3852 |
|
| 3853 |
|
| 3854 |
|
| 3855 |
|
| 3856 |
|
| 3857 |
|
| 3858 |
|
| 3859 |
|
| 3860 |
|
| 3861 |
public void onAutofillEvent(@NonNull View view, int virtualId, |
| 3862 |
@AutofillEventType int event) { |
| 3863 |
} |
| 3864 |
} |
| 3865 |
|
| 3866 |
private static final class AutofillManagerClient extends IAutoFillManagerClient.Stub { |
| 3867 |
private final WeakReference<AutofillManager> mAfm; |
| 3868 |
|
| 3869 |
private AutofillManagerClient(AutofillManager autofillManager) { |
| 3870 |
mAfm = new WeakReference<>(autofillManager); |
| 3871 |
} |
| 3872 |
|
| 3873 |
@Override |
| 3874 |
public void setState(int flags) { |
| 3875 |
final AutofillManager afm = mAfm.get(); |
| 3876 |
if (afm != null) { |
| 3877 |
afm.post(() -> afm.setState(flags)); |
| 3878 |
} |
| 3879 |
} |
| 3880 |
|
| 3881 |
@Override |
| 3882 |
public void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values, |
| 3883 |
boolean hideHighlight) { |
| 3884 |
final AutofillManager afm = mAfm.get(); |
| 3885 |
if (afm != null) { |
| 3886 |
afm.post(() -> afm.autofill(sessionId, ids, values, hideHighlight)); |
| 3887 |
} |
| 3888 |
} |
| 3889 |
|
| 3890 |
@Override |
| 3891 |
public void autofillContent(int sessionId, AutofillId id, ClipData content) { |
| 3892 |
final AutofillManager afm = mAfm.get(); |
| 3893 |
if (afm != null) { |
| 3894 |
afm.post(() -> afm.autofillContent(sessionId, id, content)); |
| 3895 |
} |
| 3896 |
} |
| 3897 |
|
| 3898 |
@Override |
| 3899 |
public void authenticate(int sessionId, int authenticationId, IntentSender intent, |
| 3900 |
Intent fillInIntent, boolean authenticateInline) { |
| 3901 |
final AutofillManager afm = mAfm.get(); |
| 3902 |
if (afm != null) { |
| 3903 |
afm.post(() -> afm.authenticate(sessionId, authenticationId, intent, fillInIntent, |
| 3904 |
authenticateInline)); |
| 3905 |
} |
| 3906 |
} |
| 3907 |
|
| 3908 |
@Override |
| 3909 |
public void requestShowFillUi(int sessionId, AutofillId id, int width, int height, |
| 3910 |
Rect anchorBounds, IAutofillWindowPresenter presenter) { |
| 3911 |
final AutofillManager afm = mAfm.get(); |
| 3912 |
if (afm != null) { |
| 3913 |
afm.post(() -> afm.requestShowFillUi(sessionId, id, width, height, anchorBounds, |
| 3914 |
presenter)); |
| 3915 |
} |
| 3916 |
} |
| 3917 |
|
| 3918 |
@Override |
| 3919 |
public void requestHideFillUi(int sessionId, AutofillId id) { |
| 3920 |
final AutofillManager afm = mAfm.get(); |
| 3921 |
if (afm != null) { |
| 3922 |
afm.post(() -> afm.requestHideFillUi(id, false)); |
| 3923 |
} |
| 3924 |
} |
| 3925 |
|
| 3926 |
@Override |
| 3927 |
public void notifyNoFillUi(int sessionId, AutofillId id, int sessionFinishedState) { |
| 3928 |
final AutofillManager afm = mAfm.get(); |
| 3929 |
if (afm != null) { |
| 3930 |
afm.post(() -> afm.notifyNoFillUi(sessionId, id, sessionFinishedState)); |
| 3931 |
} |
| 3932 |
} |
| 3933 |
|
| 3934 |
@Override |
| 3935 |
public void notifyFillUiShown(int sessionId, AutofillId id) { |
| 3936 |
final AutofillManager afm = mAfm.get(); |
| 3937 |
if (afm != null) { |
| 3938 |
afm.post( |
| 3939 |
() -> afm.notifyCallback( |
| 3940 |
sessionId, id, AutofillCallback.EVENT_INPUT_SHOWN)); |
| 3941 |
} |
| 3942 |
} |
| 3943 |
|
| 3944 |
@Override |
| 3945 |
public void notifyFillUiHidden(int sessionId, AutofillId id) { |
| 3946 |
final AutofillManager afm = mAfm.get(); |
| 3947 |
if (afm != null) { |
| 3948 |
afm.post( |
| 3949 |
() -> afm.notifyCallback( |
| 3950 |
sessionId, id, AutofillCallback.EVENT_INPUT_HIDDEN)); |
| 3951 |
} |
| 3952 |
} |
| 3953 |
|
| 3954 |
@Override |
| 3955 |
public void notifyDisableAutofill(long disableDuration, ComponentName componentName) |
| 3956 |
throws RemoteException { |
| 3957 |
final AutofillManager afm = mAfm.get(); |
| 3958 |
if (afm != null) { |
| 3959 |
afm.post(() -> afm.notifyDisableAutofill(disableDuration, componentName)); |
| 3960 |
} |
| 3961 |
} |
| 3962 |
|
| 3963 |
@Override |
| 3964 |
public void dispatchUnhandledKey(int sessionId, AutofillId id, KeyEvent fullScreen) { |
| 3965 |
final AutofillManager afm = mAfm.get(); |
| 3966 |
if (afm != null) { |
| 3967 |
afm.post(() -> afm.dispatchUnhandledKey(sessionId, id, fullScreen)); |
| 3968 |
} |
| 3969 |
} |
| 3970 |
|
| 3971 |
@Override |
| 3972 |
public void startIntentSender(IntentSender intentSender, Intent intent) { |
| 3973 |
final AutofillManager afm = mAfm.get(); |
| 3974 |
if (afm != null) { |
| 3975 |
afm.post(() -> { |
| 3976 |
try { |
| 3977 |
afm.mContext.startIntentSender(intentSender, intent, 0, 0, 0); |
| 3978 |
} catch (IntentSender.SendIntentException e) { |
| 3979 |
Log.e(TAG, "startIntentSender() failed for intent:" + intentSender, e); |
| 3980 |
} |
| 3981 |
}); |
| 3982 |
} |
| 3983 |
} |
| 3984 |
|
| 3985 |
@Override |
| 3986 |
public void setTrackedViews(int sessionId, AutofillId[] ids, |
| 3987 |
boolean saveOnAllViewsInvisible, boolean saveOnFinish, AutofillId[] fillableIds, |
| 3988 |
AutofillId saveTriggerId) { |
| 3989 |
final AutofillManager afm = mAfm.get(); |
| 3990 |
if (afm != null) { |
| 3991 |
afm.post(() -> afm.setTrackedViews(sessionId, ids, saveOnAllViewsInvisible, |
| 3992 |
saveOnFinish, fillableIds, saveTriggerId)); |
| 3993 |
} |
| 3994 |
} |
| 3995 |
|
| 3996 |
@Override |
| 3997 |
public void setSaveUiState(int sessionId, boolean shown) { |
| 3998 |
final AutofillManager afm = mAfm.get(); |
| 3999 |
if (afm != null) { |
| 4000 |
afm.post(() -> afm.setSaveUiState(sessionId, shown)); |
| 4001 |
} |
| 4002 |
} |
| 4003 |
|
| 4004 |
@Override |
| 4005 |
public void setSessionFinished(int newState, List<AutofillId> autofillableIds) { |
| 4006 |
final AutofillManager afm = mAfm.get(); |
| 4007 |
if (afm != null) { |
| 4008 |
afm.post(() -> afm.setSessionFinished(newState, autofillableIds)); |
| 4009 |
} |
| 4010 |
} |
| 4011 |
|
| 4012 |
@Override |
| 4013 |
public void getAugmentedAutofillClient(IResultReceiver result) { |
| 4014 |
final AutofillManager afm = mAfm.get(); |
| 4015 |
if (afm != null) { |
| 4016 |
afm.post(() -> afm.getAugmentedAutofillClient(result)); |
| 4017 |
} |
| 4018 |
} |
| 4019 |
|
| 4020 |
@Override |
| 4021 |
public void requestShowSoftInput(@NonNull AutofillId id) { |
| 4022 |
final AutofillManager afm = mAfm.get(); |
| 4023 |
if (afm != null) { |
| 4024 |
afm.post(() -> afm.requestShowSoftInput(id)); |
| 4025 |
} |
| 4026 |
} |
| 4027 |
|
| 4028 |
public void notifyFillDialogTriggerIds(List<AutofillId> ids) { |
| 4029 |
final AutofillManager afm = mAfm.get(); |
| 4030 |
if (afm != null) { |
| 4031 |
afm.post(() -> afm.setFillDialogTriggerIds(ids)); |
| 4032 |
} |
| 4033 |
} |
| 4034 |
} |
| 4035 |
|
| 4036 |
private static final class AugmentedAutofillManagerClient |
| 4037 |
extends IAugmentedAutofillManagerClient.Stub { |
| 4038 |
private final WeakReference<AutofillManager> mAfm; |
| 4039 |
|
| 4040 |
private AugmentedAutofillManagerClient(AutofillManager autofillManager) { |
| 4041 |
mAfm = new WeakReference<>(autofillManager); |
| 4042 |
} |
| 4043 |
|
| 4044 |
@Nullable |
| 4045 |
@Override |
| 4046 |
public ViewNodeParcelable getViewNodeParcelable(@NonNull AutofillId id) { |
| 4047 |
final AutofillManager afm = mAfm.get(); |
| 4048 |
if (afm == null) return null; |
| 4049 |
|
| 4050 |
final View view = getView(afm, id); |
| 4051 |
if (view == null) { |
| 4052 |
Log.w(TAG, "getViewNodeParcelable(" + id + "): could not find view"); |
| 4053 |
return null; |
| 4054 |
} |
| 4055 |
final ViewRootImpl root = view.getViewRootImpl(); |
| 4056 |
if (root != null |
| 4057 |
&& (root.getWindowFlags() & WindowManager.LayoutParams.FLAG_SECURE) == 0) { |
| 4058 |
ViewNodeBuilder viewStructure = new ViewNodeBuilder(); |
| 4059 |
viewStructure.setAutofillId(view.getAutofillId()); |
| 4060 |
view.onProvideAutofillStructure(viewStructure, 0); |
| 4061 |
|
| 4062 |
|
| 4063 |
|
| 4064 |
|
| 4065 |
ViewNode viewNode = viewStructure.getViewNode(); |
| 4066 |
if (viewNode != null && id.equals(viewNode.getAutofillId())) { |
| 4067 |
return new ViewNodeParcelable(viewNode); |
| 4068 |
} |
| 4069 |
} |
| 4070 |
return null; |
| 4071 |
} |
| 4072 |
|
| 4073 |
@Override |
| 4074 |
public Rect getViewCoordinates(@NonNull AutofillId id) { |
| 4075 |
final AutofillManager afm = mAfm.get(); |
| 4076 |
if (afm == null) return null; |
| 4077 |
|
| 4078 |
final View view = getView(afm, id); |
| 4079 |
if (view == null) { |
| 4080 |
return null; |
| 4081 |
} |
| 4082 |
final Rect windowVisibleDisplayFrame = new Rect(); |
| 4083 |
view.getWindowVisibleDisplayFrame(windowVisibleDisplayFrame); |
| 4084 |
final int[] location = new int[2]; |
| 4085 |
view.getLocationOnScreen(location); |
| 4086 |
final Rect rect = new Rect(location[0], location[1] - windowVisibleDisplayFrame.top, |
| 4087 |
location[0] + view.getWidth(), |
| 4088 |
location[1] - windowVisibleDisplayFrame.top + view.getHeight()); |
| 4089 |
if (sVerbose) { |
| 4090 |
Log.v(TAG, "Coordinates for " + id + ": " + rect); |
| 4091 |
} |
| 4092 |
return rect; |
| 4093 |
} |
| 4094 |
|
| 4095 |
@Override |
| 4096 |
public void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values, |
| 4097 |
boolean hideHighlight) { |
| 4098 |
final AutofillManager afm = mAfm.get(); |
| 4099 |
if (afm != null) { |
| 4100 |
afm.post(() -> afm.autofill(sessionId, ids, values, hideHighlight)); |
| 4101 |
} |
| 4102 |
} |
| 4103 |
|
| 4104 |
@Override |
| 4105 |
public void requestShowFillUi(int sessionId, AutofillId id, int width, int height, |
| 4106 |
Rect anchorBounds, IAutofillWindowPresenter presenter) { |
| 4107 |
final AutofillManager afm = mAfm.get(); |
| 4108 |
if (afm != null) { |
| 4109 |
afm.post(() -> afm.requestShowFillUi(sessionId, id, width, height, anchorBounds, |
| 4110 |
presenter)); |
| 4111 |
} |
| 4112 |
} |
| 4113 |
|
| 4114 |
@Override |
| 4115 |
public void requestHideFillUi(int sessionId, AutofillId id) { |
| 4116 |
final AutofillManager afm = mAfm.get(); |
| 4117 |
if (afm != null) { |
| 4118 |
afm.post(() -> afm.requestHideFillUi(id, false)); |
| 4119 |
} |
| 4120 |
} |
| 4121 |
|
| 4122 |
@Override |
| 4123 |
public boolean requestAutofill(int sessionId, AutofillId id) { |
| 4124 |
final AutofillManager afm = mAfm.get(); |
| 4125 |
if (afm == null || afm.mSessionId != sessionId) { |
| 4126 |
if (sDebug) { |
| 4127 |
Slog.d(TAG, "Autofill not available or sessionId doesn't match"); |
| 4128 |
} |
| 4129 |
return false; |
| 4130 |
} |
| 4131 |
final View view = getView(afm, id); |
| 4132 |
if (view == null || !view.isFocused()) { |
| 4133 |
if (sDebug) { |
| 4134 |
Slog.d(TAG, "View not available or is not on focus"); |
| 4135 |
} |
| 4136 |
return false; |
| 4137 |
} |
| 4138 |
if (sVerbose) { |
| 4139 |
Log.v(TAG, "requestAutofill() by AugmentedAutofillService."); |
| 4140 |
} |
| 4141 |
afm.post(() -> afm.requestAutofillFromNewSession(view)); |
| 4142 |
return true; |
| 4143 |
} |
| 4144 |
|
| 4145 |
@Nullable |
| 4146 |
private View getView(@NonNull AutofillManager afm, @NonNull AutofillId id) { |
| 4147 |
final AutofillClient client = afm.getClient(); |
| 4148 |
if (client == null) { |
| 4149 |
Log.w(TAG, "getView(" + id + "): no autofill client"); |
| 4150 |
return null; |
| 4151 |
} |
| 4152 |
View view = client.autofillClientFindViewByAutofillIdTraversal(id); |
| 4153 |
if (view == null) { |
| 4154 |
Log.w(TAG, "getView(" + id + "): could not find view"); |
| 4155 |
} |
| 4156 |
return view; |
| 4157 |
} |
| 4158 |
} |
| 4159 |
} |