| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.service.autofill; |
| 18 |
|
| 19 |
import static android.service.autofill.AutofillServiceHelper.assertValid; |
| 20 |
import static android.service.autofill.FillRequest.INVALID_REQUEST_ID; |
| 21 |
import static android.view.autofill.Helper.sDebug; |
| 22 |
|
| 23 |
import android.annotation.IntDef; |
| 24 |
import android.annotation.NonNull; |
| 25 |
import android.annotation.Nullable; |
| 26 |
import android.annotation.SuppressLint; |
| 27 |
import android.annotation.TestApi; |
| 28 |
import android.app.Activity; |
| 29 |
import android.content.Intent; |
| 30 |
import android.content.IntentSender; |
| 31 |
import android.content.pm.ParceledListSlice; |
| 32 |
import android.os.Bundle; |
| 33 |
import android.os.Parcel; |
| 34 |
import android.os.Parcelable; |
| 35 |
import android.view.autofill.AutofillId; |
| 36 |
import android.widget.RemoteViews; |
| 37 |
|
| 38 |
import com.android.internal.util.Preconditions; |
| 39 |
|
| 40 |
import java.lang.annotation.Retention; |
| 41 |
import java.lang.annotation.RetentionPolicy; |
| 42 |
import java.util.ArrayList; |
| 43 |
import java.util.Arrays; |
| 44 |
import java.util.List; |
| 45 |
import java.util.Objects; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public final class FillResponse implements Parcelable { |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public static final int FLAG_TRACK_CONTEXT_COMMITED = 0x1; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public static final int FLAG_DISABLE_ACTIVITY_ONLY = 0x2; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public static final int FLAG_DELAY_FILL = 0x4; |
| 79 |
|
| 80 |
|
| 81 |
@IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 82 |
FLAG_TRACK_CONTEXT_COMMITED, |
| 83 |
FLAG_DISABLE_ACTIVITY_ONLY, |
| 84 |
FLAG_DELAY_FILL |
| 85 |
}) |
| 86 |
@Retention(RetentionPolicy.SOURCE) |
| 87 |
@interface FillResponseFlags {} |
| 88 |
|
| 89 |
private final @Nullable ParceledListSlice<Dataset> mDatasets; |
| 90 |
private final @Nullable SaveInfo mSaveInfo; |
| 91 |
private final @Nullable Bundle mClientState; |
| 92 |
private final @Nullable RemoteViews mPresentation; |
| 93 |
private final @Nullable InlinePresentation mInlinePresentation; |
| 94 |
private final @Nullable InlinePresentation mInlineTooltipPresentation; |
| 95 |
private final @Nullable RemoteViews mDialogPresentation; |
| 96 |
private final @Nullable RemoteViews mDialogHeader; |
| 97 |
private final @Nullable RemoteViews mHeader; |
| 98 |
private final @Nullable RemoteViews mFooter; |
| 99 |
private final @Nullable IntentSender mAuthentication; |
| 100 |
private final @Nullable AutofillId[] mAuthenticationIds; |
| 101 |
private final @Nullable AutofillId[] mIgnoredIds; |
| 102 |
private final @Nullable AutofillId[] mFillDialogTriggerIds; |
| 103 |
private final long mDisableDuration; |
| 104 |
private final @Nullable AutofillId[] mFieldClassificationIds; |
| 105 |
private final int mFlags; |
| 106 |
private int mRequestId; |
| 107 |
private final @Nullable UserData mUserData; |
| 108 |
private final @Nullable int[] mCancelIds; |
| 109 |
private final boolean mSupportsInlineSuggestions; |
| 110 |
|
| 111 |
private FillResponse(@NonNull Builder builder) { |
| 112 |
mDatasets = (builder.mDatasets != null) ? new ParceledListSlice<>(builder.mDatasets) : null; |
| 113 |
mSaveInfo = builder.mSaveInfo; |
| 114 |
mClientState = builder.mClientState; |
| 115 |
mPresentation = builder.mPresentation; |
| 116 |
mInlinePresentation = builder.mInlinePresentation; |
| 117 |
mInlineTooltipPresentation = builder.mInlineTooltipPresentation; |
| 118 |
mDialogPresentation = builder.mDialogPresentation; |
| 119 |
mDialogHeader = builder.mDialogHeader; |
| 120 |
mHeader = builder.mHeader; |
| 121 |
mFooter = builder.mFooter; |
| 122 |
mAuthentication = builder.mAuthentication; |
| 123 |
mAuthenticationIds = builder.mAuthenticationIds; |
| 124 |
mFillDialogTriggerIds = builder.mFillDialogTriggerIds; |
| 125 |
mIgnoredIds = builder.mIgnoredIds; |
| 126 |
mDisableDuration = builder.mDisableDuration; |
| 127 |
mFieldClassificationIds = builder.mFieldClassificationIds; |
| 128 |
mFlags = builder.mFlags; |
| 129 |
mRequestId = INVALID_REQUEST_ID; |
| 130 |
mUserData = builder.mUserData; |
| 131 |
mCancelIds = builder.mCancelIds; |
| 132 |
mSupportsInlineSuggestions = builder.mSupportsInlineSuggestions; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
public @Nullable Bundle getClientState() { |
| 137 |
return mClientState; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
public @Nullable List<Dataset> getDatasets() { |
| 142 |
return (mDatasets != null) ? mDatasets.getList() : null; |
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
public @Nullable SaveInfo getSaveInfo() { |
| 147 |
return mSaveInfo; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
public @Nullable RemoteViews getPresentation() { |
| 152 |
return mPresentation; |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
public @Nullable InlinePresentation getInlinePresentation() { |
| 157 |
return mInlinePresentation; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
public @Nullable InlinePresentation getInlineTooltipPresentation() { |
| 162 |
return mInlineTooltipPresentation; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
public @Nullable RemoteViews getDialogPresentation() { |
| 167 |
return mDialogPresentation; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
public @Nullable RemoteViews getDialogHeader() { |
| 172 |
return mDialogHeader; |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
public @Nullable RemoteViews getHeader() { |
| 177 |
return mHeader; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
public @Nullable RemoteViews getFooter() { |
| 182 |
return mFooter; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
public @Nullable IntentSender getAuthentication() { |
| 187 |
return mAuthentication; |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
public @Nullable AutofillId[] getAuthenticationIds() { |
| 192 |
return mAuthenticationIds; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
public @Nullable AutofillId[] getFillDialogTriggerIds() { |
| 197 |
return mFillDialogTriggerIds; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
public @Nullable AutofillId[] getIgnoredIds() { |
| 202 |
return mIgnoredIds; |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
public long getDisableDuration() { |
| 207 |
return mDisableDuration; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
public @Nullable AutofillId[] getFieldClassificationIds() { |
| 212 |
return mFieldClassificationIds; |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
public @Nullable UserData getUserData() { |
| 217 |
return mUserData; |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
@TestApi |
| 222 |
public int getFlags() { |
| 223 |
return mFlags; |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
public void setRequestId(int requestId) { |
| 236 |
mRequestId = requestId; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
public int getRequestId() { |
| 241 |
return mRequestId; |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
@Nullable |
| 246 |
public int[] getCancelIds() { |
| 247 |
return mCancelIds; |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
public boolean supportsInlineSuggestions() { |
| 252 |
return mSupportsInlineSuggestions; |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
public static final class Builder { |
| 260 |
private ArrayList<Dataset> mDatasets; |
| 261 |
private SaveInfo mSaveInfo; |
| 262 |
private Bundle mClientState; |
| 263 |
private RemoteViews mPresentation; |
| 264 |
private InlinePresentation mInlinePresentation; |
| 265 |
private InlinePresentation mInlineTooltipPresentation; |
| 266 |
private RemoteViews mDialogPresentation; |
| 267 |
private RemoteViews mDialogHeader; |
| 268 |
private RemoteViews mHeader; |
| 269 |
private RemoteViews mFooter; |
| 270 |
private IntentSender mAuthentication; |
| 271 |
private AutofillId[] mAuthenticationIds; |
| 272 |
private AutofillId[] mIgnoredIds; |
| 273 |
private long mDisableDuration; |
| 274 |
private AutofillId[] mFieldClassificationIds; |
| 275 |
private AutofillId[] mFillDialogTriggerIds; |
| 276 |
private int mFlags; |
| 277 |
private boolean mDestroyed; |
| 278 |
private UserData mUserData; |
| 279 |
private int[] mCancelIds; |
| 280 |
private boolean mSupportsInlineSuggestions; |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
@Deprecated |
| 358 |
@NonNull |
| 359 |
public Builder setAuthentication(@NonNull AutofillId[] ids, |
| 360 |
@Nullable IntentSender authentication, @Nullable RemoteViews presentation) { |
| 361 |
throwIfDestroyed(); |
| 362 |
throwIfDisableAutofillCalled(); |
| 363 |
if (mHeader != null || mFooter != null) { |
| 364 |
throw new IllegalStateException("Already called #setHeader() or #setFooter()"); |
| 365 |
} |
| 366 |
|
| 367 |
if (authentication == null ^ presentation == null) { |
| 368 |
throw new IllegalArgumentException("authentication and presentation" |
| 369 |
+ " must be both non-null or null"); |
| 370 |
} |
| 371 |
mAuthentication = authentication; |
| 372 |
mPresentation = presentation; |
| 373 |
mAuthenticationIds = assertValid(ids); |
| 374 |
return this; |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
@Deprecated |
| 421 |
@NonNull |
| 422 |
public Builder setAuthentication(@NonNull AutofillId[] ids, |
| 423 |
@Nullable IntentSender authentication, @Nullable RemoteViews presentation, |
| 424 |
@Nullable InlinePresentation inlinePresentation) { |
| 425 |
return setAuthentication(ids, authentication, presentation, inlinePresentation, null); |
| 426 |
} |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
@Deprecated |
| 441 |
@NonNull |
| 442 |
public Builder setAuthentication(@SuppressLint("ArrayReturn") @NonNull AutofillId[] ids, |
| 443 |
@Nullable IntentSender authentication, @Nullable RemoteViews presentation, |
| 444 |
@Nullable InlinePresentation inlinePresentation, |
| 445 |
@Nullable InlinePresentation inlineTooltipPresentation) { |
| 446 |
throwIfDestroyed(); |
| 447 |
throwIfDisableAutofillCalled(); |
| 448 |
return setAuthentication(ids, authentication, presentation, |
| 449 |
inlinePresentation, inlineTooltipPresentation, null); |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
@NonNull |
| 520 |
public Builder setAuthentication(@SuppressLint("ArrayReturn") @NonNull AutofillId[] ids, |
| 521 |
@Nullable IntentSender authentication, |
| 522 |
@Nullable Presentations presentations) { |
| 523 |
throwIfDestroyed(); |
| 524 |
throwIfDisableAutofillCalled(); |
| 525 |
if (presentations == null) { |
| 526 |
return setAuthentication(ids, authentication, null, null, null, null); |
| 527 |
} |
| 528 |
return setAuthentication(ids, authentication, |
| 529 |
presentations.getMenuPresentation(), |
| 530 |
presentations.getInlinePresentation(), |
| 531 |
presentations.getInlineTooltipPresentation(), |
| 532 |
presentations.getDialogPresentation()); |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
@NonNull |
| 540 |
private Builder setAuthentication(@SuppressLint("ArrayReturn") @NonNull AutofillId[] ids, |
| 541 |
@Nullable IntentSender authentication, @Nullable RemoteViews presentation, |
| 542 |
@Nullable InlinePresentation inlinePresentation, |
| 543 |
@Nullable InlinePresentation inlineTooltipPresentation, |
| 544 |
@Nullable RemoteViews dialogPresentation) { |
| 545 |
throwIfDestroyed(); |
| 546 |
throwIfDisableAutofillCalled(); |
| 547 |
if (mHeader != null || mFooter != null) { |
| 548 |
throw new IllegalStateException("Already called #setHeader() or #setFooter()"); |
| 549 |
} |
| 550 |
|
| 551 |
if (authentication == null ^ (presentation == null && inlinePresentation == null)) { |
| 552 |
throw new IllegalArgumentException("authentication and presentation " |
| 553 |
+ "(dropdown or inline), must be both non-null or null"); |
| 554 |
} |
| 555 |
mAuthentication = authentication; |
| 556 |
mPresentation = presentation; |
| 557 |
mInlinePresentation = inlinePresentation; |
| 558 |
mInlineTooltipPresentation = inlineTooltipPresentation; |
| 559 |
mDialogPresentation = dialogPresentation; |
| 560 |
mAuthenticationIds = assertValid(ids); |
| 561 |
return this; |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
@NonNull |
| 573 |
public Builder setIgnoredIds(AutofillId...ids) { |
| 574 |
throwIfDestroyed(); |
| 575 |
mIgnoredIds = ids; |
| 576 |
return this; |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
@NonNull |
| 594 |
public Builder addDataset(@Nullable Dataset dataset) { |
| 595 |
throwIfDestroyed(); |
| 596 |
throwIfDisableAutofillCalled(); |
| 597 |
if (dataset == null) { |
| 598 |
return this; |
| 599 |
} |
| 600 |
if (mDatasets == null) { |
| 601 |
mDatasets = new ArrayList<>(); |
| 602 |
} |
| 603 |
if (!mDatasets.add(dataset)) { |
| 604 |
return this; |
| 605 |
} |
| 606 |
return this; |
| 607 |
} |
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
public @NonNull Builder setSaveInfo(@NonNull SaveInfo saveInfo) { |
| 615 |
throwIfDestroyed(); |
| 616 |
throwIfDisableAutofillCalled(); |
| 617 |
mSaveInfo = saveInfo; |
| 618 |
return this; |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
@NonNull |
| 636 |
public Builder setClientState(@Nullable Bundle clientState) { |
| 637 |
throwIfDestroyed(); |
| 638 |
throwIfDisableAutofillCalled(); |
| 639 |
mClientState = clientState; |
| 640 |
return this; |
| 641 |
} |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
@NonNull |
| 657 |
public Builder setFieldClassificationIds(@NonNull AutofillId... ids) { |
| 658 |
throwIfDestroyed(); |
| 659 |
throwIfDisableAutofillCalled(); |
| 660 |
Preconditions.checkArrayElementsNotNull(ids, "ids"); |
| 661 |
Preconditions.checkArgumentInRange(ids.length, 1, |
| 662 |
UserData.getMaxFieldClassificationIdsSize(), "ids length"); |
| 663 |
mFieldClassificationIds = ids; |
| 664 |
mFlags |= FLAG_TRACK_CONTEXT_COMMITED; |
| 665 |
return this; |
| 666 |
} |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
@NonNull |
| 677 |
public Builder setFlags(@FillResponseFlags int flags) { |
| 678 |
throwIfDestroyed(); |
| 679 |
mFlags = Preconditions.checkFlagsArgument(flags, |
| 680 |
FLAG_TRACK_CONTEXT_COMMITED | FLAG_DISABLE_ACTIVITY_ONLY | FLAG_DELAY_FILL); |
| 681 |
return this; |
| 682 |
} |
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
@NonNull |
| 717 |
public Builder disableAutofill(long duration) { |
| 718 |
throwIfDestroyed(); |
| 719 |
if (duration <= 0) { |
| 720 |
throw new IllegalArgumentException("duration must be greater than 0"); |
| 721 |
} |
| 722 |
if (mAuthentication != null || mDatasets != null || mSaveInfo != null |
| 723 |
|| mFieldClassificationIds != null || mClientState != null) { |
| 724 |
throw new IllegalStateException("disableAutofill() must be the only method called"); |
| 725 |
} |
| 726 |
|
| 727 |
mDisableDuration = duration; |
| 728 |
return this; |
| 729 |
} |
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
@NonNull |
| 756 |
public Builder setHeader(@NonNull RemoteViews header) { |
| 757 |
throwIfDestroyed(); |
| 758 |
throwIfAuthenticationCalled(); |
| 759 |
mHeader = Objects.requireNonNull(header); |
| 760 |
return this; |
| 761 |
} |
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
@NonNull |
| 788 |
public Builder setFooter(@NonNull RemoteViews footer) { |
| 789 |
throwIfDestroyed(); |
| 790 |
throwIfAuthenticationCalled(); |
| 791 |
mFooter = Objects.requireNonNull(footer); |
| 792 |
return this; |
| 793 |
} |
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
@NonNull |
| 807 |
public Builder setUserData(@NonNull UserData userData) { |
| 808 |
throwIfDestroyed(); |
| 809 |
throwIfAuthenticationCalled(); |
| 810 |
mUserData = Objects.requireNonNull(userData); |
| 811 |
return this; |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
@NonNull |
| 827 |
public Builder setPresentationCancelIds(@Nullable int[] ids) { |
| 828 |
throwIfDestroyed(); |
| 829 |
mCancelIds = ids; |
| 830 |
return this; |
| 831 |
} |
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
@NonNull |
| 842 |
public Builder setDialogHeader(@NonNull RemoteViews header) { |
| 843 |
throwIfDestroyed(); |
| 844 |
Objects.requireNonNull(header); |
| 845 |
mDialogHeader = header; |
| 846 |
return this; |
| 847 |
} |
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
@NonNull |
| 859 |
public Builder setFillDialogTriggerIds(@NonNull AutofillId... ids) { |
| 860 |
throwIfDestroyed(); |
| 861 |
Preconditions.checkArrayElementsNotNull(ids, "ids"); |
| 862 |
mFillDialogTriggerIds = ids; |
| 863 |
return this; |
| 864 |
} |
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
@NonNull |
| 884 |
public FillResponse build() { |
| 885 |
throwIfDestroyed(); |
| 886 |
if (mAuthentication == null && mDatasets == null && mSaveInfo == null |
| 887 |
&& mDisableDuration == 0 && mFieldClassificationIds == null |
| 888 |
&& mClientState == null) { |
| 889 |
throw new IllegalStateException("need to provide: at least one DataSet, or a " |
| 890 |
+ "SaveInfo, or an authentication with a presentation, " |
| 891 |
+ "or a FieldsDetection, or a client state, or disable autofill"); |
| 892 |
} |
| 893 |
if (mDatasets == null && (mHeader != null || mFooter != null)) { |
| 894 |
throw new IllegalStateException( |
| 895 |
"must add at least 1 dataset when using header or footer"); |
| 896 |
} |
| 897 |
|
| 898 |
if (mDatasets != null) { |
| 899 |
for (final Dataset dataset : mDatasets) { |
| 900 |
if (dataset.getFieldInlinePresentation(0) != null) { |
| 901 |
mSupportsInlineSuggestions = true; |
| 902 |
break; |
| 903 |
} |
| 904 |
} |
| 905 |
} else if (mInlinePresentation != null) { |
| 906 |
mSupportsInlineSuggestions = true; |
| 907 |
} |
| 908 |
|
| 909 |
mDestroyed = true; |
| 910 |
return new FillResponse(this); |
| 911 |
} |
| 912 |
|
| 913 |
private void throwIfDestroyed() { |
| 914 |
if (mDestroyed) { |
| 915 |
throw new IllegalStateException("Already called #build()"); |
| 916 |
} |
| 917 |
} |
| 918 |
|
| 919 |
private void throwIfDisableAutofillCalled() { |
| 920 |
if (mDisableDuration > 0) { |
| 921 |
throw new IllegalStateException("Already called #disableAutofill()"); |
| 922 |
} |
| 923 |
} |
| 924 |
|
| 925 |
private void throwIfAuthenticationCalled() { |
| 926 |
if (mAuthentication != null) { |
| 927 |
throw new IllegalStateException("Already called #setAuthentication()"); |
| 928 |
} |
| 929 |
} |
| 930 |
} |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
@Override |
| 936 |
public String toString() { |
| 937 |
if (!sDebug) return super.toString(); |
| 938 |
|
| 939 |
|
| 940 |
final StringBuilder builder = new StringBuilder( |
| 941 |
"FillResponse : [mRequestId=" + mRequestId); |
| 942 |
if (mDatasets != null) { |
| 943 |
builder.append(", datasets=").append(mDatasets.getList()); |
| 944 |
} |
| 945 |
if (mSaveInfo != null) { |
| 946 |
builder.append(", saveInfo=").append(mSaveInfo); |
| 947 |
} |
| 948 |
if (mClientState != null) { |
| 949 |
builder.append(", hasClientState"); |
| 950 |
} |
| 951 |
if (mPresentation != null) { |
| 952 |
builder.append(", hasPresentation"); |
| 953 |
} |
| 954 |
if (mInlinePresentation != null) { |
| 955 |
builder.append(", hasInlinePresentation"); |
| 956 |
} |
| 957 |
if (mInlineTooltipPresentation != null) { |
| 958 |
builder.append(", hasInlineTooltipPresentation"); |
| 959 |
} |
| 960 |
if (mDialogPresentation != null) { |
| 961 |
builder.append(", hasDialogPresentation"); |
| 962 |
} |
| 963 |
if (mDialogHeader != null) { |
| 964 |
builder.append(", hasDialogHeader"); |
| 965 |
} |
| 966 |
if (mHeader != null) { |
| 967 |
builder.append(", hasHeader"); |
| 968 |
} |
| 969 |
if (mFooter != null) { |
| 970 |
builder.append(", hasFooter"); |
| 971 |
} |
| 972 |
if (mAuthentication != null) { |
| 973 |
builder.append(", hasAuthentication"); |
| 974 |
} |
| 975 |
if (mAuthenticationIds != null) { |
| 976 |
builder.append(", authenticationIds=").append(Arrays.toString(mAuthenticationIds)); |
| 977 |
} |
| 978 |
if (mFillDialogTriggerIds != null) { |
| 979 |
builder.append(", fillDialogTriggerIds=") |
| 980 |
.append(Arrays.toString(mFillDialogTriggerIds)); |
| 981 |
} |
| 982 |
builder.append(", disableDuration=").append(mDisableDuration); |
| 983 |
if (mFlags != 0) { |
| 984 |
builder.append(", flags=").append(mFlags); |
| 985 |
} |
| 986 |
if (mFieldClassificationIds != null) { |
| 987 |
builder.append(Arrays.toString(mFieldClassificationIds)); |
| 988 |
} |
| 989 |
if (mUserData != null) { |
| 990 |
builder.append(", userData=").append(mUserData); |
| 991 |
} |
| 992 |
if (mCancelIds != null) { |
| 993 |
builder.append(", mCancelIds=").append(mCancelIds.length); |
| 994 |
} |
| 995 |
builder.append(", mSupportInlinePresentations=").append(mSupportsInlineSuggestions); |
| 996 |
return builder.append("]").toString(); |
| 997 |
} |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
@Override |
| 1004 |
public int describeContents() { |
| 1005 |
return 0; |
| 1006 |
} |
| 1007 |
|
| 1008 |
@Override |
| 1009 |
public void writeToParcel(Parcel parcel, int flags) { |
| 1010 |
parcel.writeParcelable(mDatasets, flags); |
| 1011 |
parcel.writeParcelable(mSaveInfo, flags); |
| 1012 |
parcel.writeParcelable(mClientState, flags); |
| 1013 |
parcel.writeParcelableArray(mAuthenticationIds, flags); |
| 1014 |
parcel.writeParcelable(mAuthentication, flags); |
| 1015 |
parcel.writeParcelable(mPresentation, flags); |
| 1016 |
parcel.writeParcelable(mInlinePresentation, flags); |
| 1017 |
parcel.writeParcelable(mInlineTooltipPresentation, flags); |
| 1018 |
parcel.writeParcelable(mDialogPresentation, flags); |
| 1019 |
parcel.writeParcelable(mDialogHeader, flags); |
| 1020 |
parcel.writeParcelableArray(mFillDialogTriggerIds, flags); |
| 1021 |
parcel.writeParcelable(mHeader, flags); |
| 1022 |
parcel.writeParcelable(mFooter, flags); |
| 1023 |
parcel.writeParcelable(mUserData, flags); |
| 1024 |
parcel.writeParcelableArray(mIgnoredIds, flags); |
| 1025 |
parcel.writeLong(mDisableDuration); |
| 1026 |
parcel.writeParcelableArray(mFieldClassificationIds, flags); |
| 1027 |
parcel.writeInt(mFlags); |
| 1028 |
parcel.writeIntArray(mCancelIds); |
| 1029 |
parcel.writeInt(mRequestId); |
| 1030 |
} |
| 1031 |
|
| 1032 |
public static final @android.annotation.NonNull Parcelable.Creator<FillResponse> CREATOR = |
| 1033 |
new Parcelable.Creator<FillResponse>() { |
| 1034 |
@Override |
| 1035 |
public FillResponse createFromParcel(Parcel parcel) { |
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
final Builder builder = new Builder(); |
| 1040 |
final ParceledListSlice<Dataset> datasetSlice = parcel.readParcelable(null, android.content.pm.ParceledListSlice.class); |
| 1041 |
final List<Dataset> datasets = (datasetSlice != null) ? datasetSlice.getList() : null; |
| 1042 |
final int datasetCount = (datasets != null) ? datasets.size() : 0; |
| 1043 |
for (int i = 0; i < datasetCount; i++) { |
| 1044 |
builder.addDataset(datasets.get(i)); |
| 1045 |
} |
| 1046 |
builder.setSaveInfo(parcel.readParcelable(null, android.service.autofill.SaveInfo.class)); |
| 1047 |
builder.setClientState(parcel.readParcelable(null, android.os.Bundle.class)); |
| 1048 |
|
| 1049 |
|
| 1050 |
final AutofillId[] authenticationIds = parcel.readParcelableArray(null, |
| 1051 |
AutofillId.class); |
| 1052 |
final IntentSender authentication = parcel.readParcelable(null, android.content.IntentSender.class); |
| 1053 |
final RemoteViews presentation = parcel.readParcelable(null, android.widget.RemoteViews.class); |
| 1054 |
final InlinePresentation inlinePresentation = parcel.readParcelable(null, android.service.autofill.InlinePresentation.class); |
| 1055 |
final InlinePresentation inlineTooltipPresentation = parcel.readParcelable(null, android.service.autofill.InlinePresentation.class); |
| 1056 |
final RemoteViews dialogPresentation = parcel.readParcelable(null, android.widget.RemoteViews.class); |
| 1057 |
if (authenticationIds != null) { |
| 1058 |
builder.setAuthentication(authenticationIds, authentication, presentation, |
| 1059 |
inlinePresentation, inlineTooltipPresentation, dialogPresentation); |
| 1060 |
} |
| 1061 |
final RemoteViews dialogHeader = parcel.readParcelable(null, android.widget.RemoteViews.class); |
| 1062 |
if (dialogHeader != null) { |
| 1063 |
builder.setDialogHeader(dialogHeader); |
| 1064 |
} |
| 1065 |
final AutofillId[] triggerIds = parcel.readParcelableArray(null, AutofillId.class); |
| 1066 |
if (triggerIds != null) { |
| 1067 |
builder.setFillDialogTriggerIds(triggerIds); |
| 1068 |
} |
| 1069 |
final RemoteViews header = parcel.readParcelable(null, android.widget.RemoteViews.class); |
| 1070 |
if (header != null) { |
| 1071 |
builder.setHeader(header); |
| 1072 |
} |
| 1073 |
final RemoteViews footer = parcel.readParcelable(null, android.widget.RemoteViews.class); |
| 1074 |
if (footer != null) { |
| 1075 |
builder.setFooter(footer); |
| 1076 |
} |
| 1077 |
final UserData userData = parcel.readParcelable(null, android.service.autofill.UserData.class); |
| 1078 |
if (userData != null) { |
| 1079 |
builder.setUserData(userData); |
| 1080 |
} |
| 1081 |
|
| 1082 |
builder.setIgnoredIds(parcel.readParcelableArray(null, AutofillId.class)); |
| 1083 |
final long disableDuration = parcel.readLong(); |
| 1084 |
if (disableDuration > 0) { |
| 1085 |
builder.disableAutofill(disableDuration); |
| 1086 |
} |
| 1087 |
final AutofillId[] fieldClassifactionIds = |
| 1088 |
parcel.readParcelableArray(null, AutofillId.class); |
| 1089 |
if (fieldClassifactionIds != null) { |
| 1090 |
builder.setFieldClassificationIds(fieldClassifactionIds); |
| 1091 |
} |
| 1092 |
builder.setFlags(parcel.readInt()); |
| 1093 |
final int[] cancelIds = parcel.createIntArray(); |
| 1094 |
builder.setPresentationCancelIds(cancelIds); |
| 1095 |
|
| 1096 |
final FillResponse response = builder.build(); |
| 1097 |
response.setRequestId(parcel.readInt()); |
| 1098 |
|
| 1099 |
return response; |
| 1100 |
} |
| 1101 |
|
| 1102 |
@Override |
| 1103 |
public FillResponse[] newArray(int size) { |
| 1104 |
return new FillResponse[size]; |
| 1105 |
} |
| 1106 |
}; |
| 1107 |
} |