Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Autofill Framework

Android Autofill Framework

Divya Jain

July 18, 2019
Tweet

More Decks by Divya Jain

Other Decks in Programming

Transcript

  1. Autofill Framework
    Divya Jain
    Gametime
    @divyajain2405

    View Slide

  2. Time Consuming & Error Prone

    View Slide

  3. Solution?
    Android Autofill Framework
    No User Retyping Minimal Errors

    View Slide

  4. Components
    Service Client

    View Slide

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

    View Slide

  6. Autofill Hints
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:autofillHints="password" />
    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...)

    View Slide

  7. Field Importance
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:importantForAutofill="no" />
    val captcha = findViewById(R.id.captcha)
    captcha.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO)
    Auto
    noExcludeDescendants
    Yes
    yesExcludeDescendants
    No

    View Slide

  8. 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

    View Slide

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

    View Slide

  10. 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()

    View Slide

  11. Building your own autofill service
    android:name=".MyAutofillService"
    android:label="My Autofill Service"
    android:permission="android.permission.BIND_AUTOFILL_SERVICE">



    android:name="android.autofill"
    android:resource="@xml/service_configuration" />

    View Slide

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

    View Slide

  13. 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()
    ...

    View Slide

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

    View Slide

  15. 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

    View Slide

  16. Thank you!
    @divyajain2405

    View Slide