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

Android Autofill Framework

Android Autofill Framework


Divya Jain

July 18, 2019

More Decks by Divya Jain

Other Decks in Programming


  1. Autofill Framework Divya Jain Gametime @divyajain2405

  2. Time Consuming & Error Prone

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

  4. Components Service Client

  5. Configure Autofill Service in your app Settings -> System/General Management

    -> Language and Input -> Autofill Service android.permission.BIND_AUTOFILL_SERVICE
  6. Autofill Hints <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:autofillHints="password" /> val password =

    findViewById<EditText>(R.id.password) password.setAutofillHints(View.AUTOFILL_HINT_PASSWORD) https://developer.android.com/reference/android/view/View?authuser=1#setAutofillHints(java.lang.String...)
  7. Field Importance <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:importantForAutofill="no" /> val captcha =

    findViewById<TextView>(R.id.captcha) captcha.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO) Auto noExcludeDescendants Yes yesExcludeDescendants No
  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
  9. Autofill Manager isEnabled(), cancel() fun eventHandler(view: View) { val afm

    = requireContext().getSystemService(AutofillManager::class.java) afm?.requestAutofill(view) } AutofillManager.commit()
  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()
  11. Building your own autofill service <service android:name=".MyAutofillService" android:label="My Autofill Service"

    android:permission="android.permission.BIND_AUTOFILL_SERVICE"> <intent-filter> <action android:name="android.service.autofill.AutofillService" /> </intent-filter> <meta-data android:name="android.autofill" android:resource="@xml/service_configuration" /> </service>
  12. Building your own Autofill Service hasEnabledAutofillServices() ACTION_REQUEST_SET_AUTOFILL_SERVICE AssistStructure Object Dataset

    Object ViewNode Object
  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() ...
  14. Partitioned Datasets Credentials Address Payment Username Street Credit card number

    password City Expiry Email address State CVV Zip Code
  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
  16. Thank you! @divyajain2405