2 * Copyright (C) 2017 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.settings.applications.defaultapps;
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.provider.Settings;
23 import android.text.TextUtils;
24 import android.view.autofill.AutofillManager;
26 import com.android.settingslib.applications.DefaultAppInfo;
28 public class DefaultAutofillPreferenceController extends DefaultAppPreferenceController {
30 private final AutofillManager mAutofillManager;
32 public DefaultAutofillPreferenceController(Context context) {
35 mAutofillManager = mContext.getSystemService(AutofillManager.class);
39 public boolean isAvailable() {
40 return mAutofillManager != null
41 && mAutofillManager.hasAutofillFeature()
42 && mAutofillManager.isAutofillSupported();
46 public String getPreferenceKey() {
47 return "default_autofill";
51 protected Intent getSettingIntent(DefaultAppInfo info) {
55 final DefaultAutofillPicker.AutofillSettingIntentProvider intentProvider =
56 new DefaultAutofillPicker.AutofillSettingIntentProvider(
57 mContext, info.getKey());
58 return intentProvider.getIntent();
62 protected DefaultAppInfo getDefaultAppInfo() {
63 final String flattenComponent = Settings.Secure.getString(mContext.getContentResolver(),
64 DefaultAutofillPicker.SETTING);
65 if (!TextUtils.isEmpty(flattenComponent)) {
66 DefaultAppInfo appInfo = new DefaultAppInfo(mContext, mPackageManager,
67 mUserId, ComponentName.unflattenFromString(flattenComponent));