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. Configure Autofill Service in your app Settings -> System/General Management

    -> Language and Input -> Autofill Service android.permission.BIND_AUTOFILL_SERVICE
  2. 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...)
  3. 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
  4. 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
  5. Autofill Manager isEnabled(), cancel() fun eventHandler(view: View) { val afm

    = requireContext().getSystemService(AutofillManager::class.java) afm?.requestAutofill(view) } AutofillManager.commit()
  6. 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()
  7. 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>
  8. 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() ...
  9. Partitioned Datasets Credentials Address Payment Username Street Credit card number

    password City Expiry Email address State CVV Zip Code
  10. 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