Slide 1

Slide 1 text

Autofill Framework Divya Jain Gametime @divyajain2405

Slide 2

Slide 2 text

Time Consuming & Error Prone

Slide 3

Slide 3 text

Solution? Android Autofill Framework No User Retyping Minimal Errors

Slide 4

Slide 4 text

Components Service Client

Slide 5

Slide 5 text

Configure Autofill Service in your app Settings -> System/General Management -> Language and Input -> Autofill Service android.permission.BIND_AUTOFILL_SERVICE

Slide 6

Slide 6 text

Autofill Hints val password = findViewById(R.id.password) password.setAutofillHints(View.AUTOFILL_HINT_PASSWORD) https://developer.android.com/reference/android/view/View?authuser=1#setAutofillHints(java.lang.String...)

Slide 7

Slide 7 text

Field Importance val captcha = findViewById(R.id.captcha) captcha.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO) Auto noExcludeDescendants Yes yesExcludeDescendants No

Slide 8

Slide 8 text

Enable same Autofill across Web & App ● Create a Digital Asset Link JSON file ● "relation": ["delegate_permission/common.ge t_login_creds"] ● Host it at your web domain ● Declare this association to your Android Manifest file https://developers.google.com/identity/smartlock-passwords/android/associate-apps-and-sites?authuser=1

Slide 9

Slide 9 text

Autofill Manager isEnabled(), cancel() fun eventHandler(view: View) { val afm = requireContext().getSystemService(AutofillManager::class.java) afm?.requestAutofill(view) } AutofillManager.commit()

Slide 10

Slide 10 text

Autofill process under the hood ● AutofillManager#notifyViewEntered(android.view.View) ● ViewStructure containing all the screen views ● onConnected() ● onFillRequest(android.service.autofill.FillRequest, android.os.CancellationSignal, android.service.autofill.FillCallback) ● FillCallback#onSuccess(FillResponse) ● onDisconnected()

Slide 11

Slide 11 text

Building your own autofill service

Slide 12

Slide 12 text

Building your own Autofill Service hasEnabledAutofillServices() ACTION_REQUEST_SET_AUTOFILL_SERVICE AssistStructure Object Dataset Object ViewNode Object

Slide 13

Slide 13 text

SaveInfo Object SAVE_DATA val fillResponse: FillResponse = FillResponse.Builder() .addDataset( Dataset.Builder() .setValue(parsedStructure.usernameId, null, notUsed) .setValue(parsedStructure.passwordId, null, notUsed) .build() ) .setSaveInfo( SaveInfo.Builder( SaveInfo.SAVE_DATA_TYPE_USERNAME or SaveInfo.SAVE_DATA_TYPE_PASSWORD, arrayOf(parsedStructure.usernameId, parsedStructure.passwordId) ).build() ) .build() ...

Slide 14

Slide 14 text

Partitioned Datasets Credentials Address Payment Username Street Credit card number password City Expiry Email address State CVV Zip Code

Slide 15

Slide 15 text

Testing your app with Autofill - Summary ● Get an Autofill service ● Enable the service in System Settings Settings > System > Language & input > Input assistance > Autofill service ● Help the service with android:autofillHints & other attributes ● Save data in the service ● Trigger autofill in app https://github.com/googlesamples/android-AutofillFramework

Slide 16

Slide 16 text

Thank you! @divyajain2405