Implemented ACTION_REQUEST_SET_AUTOFILL_SERVICE.

Bug: 37673809
Fixes: 37576671
Test: manual verification
Test: make RunSettingsRoboTests -j90

Change-Id: I36170cb715473dfbf598deedd9719a46168aabc8
This commit is contained in:
Felipe Leme
2017-04-24 18:10:09 -07:00
parent 0cdade8a78
commit db2b55a244
3 changed files with 71 additions and 1 deletions

View File

@@ -16,6 +16,7 @@
package com.android.settings.applications.defaultapps;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -38,6 +39,8 @@ public class DefaultAutofillPicker extends DefaultAppPickerFragment {
static final String SETTING = Settings.Secure.AUTOFILL_SERVICE;
static final Intent AUTOFILL_PROBE = new Intent(AutofillService.SERVICE_INTERFACE);
static final String EXTRA_PACKAGE_NAME = "package_name";
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.DEFAULT_AUTOFILL_PICKER;
@@ -79,11 +82,24 @@ public class DefaultAutofillPicker extends DefaultAppPickerFragment {
@Override
protected boolean setDefaultKey(String key) {
Settings.Secure.putString(getContext().getContentResolver(), SETTING, key);
// Check if activity was launched from Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE
// intent, and set proper result if so...
final Activity activity = getActivity();
if (activity != null) {
final String packageName = activity.getIntent().getStringExtra(EXTRA_PACKAGE_NAME);
if (packageName != null) {
final int result = key != null && key.startsWith(packageName) ? Activity.RESULT_OK
: Activity.RESULT_CANCELED;
activity.setResult(result);
activity.finish();
}
}
return true;
}
/**
* Provides Intent to setting activity for the specified auto-fill service.
* Provides Intent to setting activity for the specified autofill service.
*/
static final class AutofillSettingIntentProvider implements SettingIntentProvider {