1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package com.android.settings.applications.defaultapps; 18 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; 25 26 import com.android.settingslib.applications.DefaultAppInfo; 27 28 public class DefaultAutofillPreferenceController extends DefaultAppPreferenceController { 29 30 private final AutofillManager mAutofillManager; 31 DefaultAutofillPreferenceController(Context context)32 public DefaultAutofillPreferenceController(Context context) { 33 super(context); 34 35 mAutofillManager = mContext.getSystemService(AutofillManager.class); 36 } 37 38 @Override isAvailable()39 public boolean isAvailable() { 40 return mAutofillManager != null 41 && mAutofillManager.hasAutofillFeature() 42 && mAutofillManager.isAutofillSupported(); 43 } 44 45 @Override getPreferenceKey()46 public String getPreferenceKey() { 47 return "default_autofill_main"; 48 } 49 50 @Override getSettingIntent(DefaultAppInfo info)51 protected Intent getSettingIntent(DefaultAppInfo info) { 52 if (info == null) { 53 return null; 54 } 55 final DefaultAutofillPicker.AutofillSettingIntentProvider intentProvider = 56 new DefaultAutofillPicker.AutofillSettingIntentProvider( 57 mContext, mUserId, info.getKey()); 58 return intentProvider.getIntent(); 59 } 60 61 @Override getDefaultAppInfo()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)); 68 return appInfo; 69 } 70 return null; 71 } 72 73 @Override showLabelAsTitle()74 protected boolean showLabelAsTitle() { 75 return true; 76 } 77 } 78