Home | History | Annotate | Download | only in defaultapps
      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.settings.applications.AutofillManagerWrapper;
     27 import com.android.settings.applications.AutofillManagerWrapperImpl;
     28 
     29 public class DefaultAutofillPreferenceController extends DefaultAppPreferenceController {
     30     private AutofillManagerWrapper mAutofillManager;
     31 
     32     public DefaultAutofillPreferenceController(Context context) {
     33         super(context);
     34 
     35         mAutofillManager = new AutofillManagerWrapperImpl(
     36                 mContext.getSystemService(AutofillManager.class));
     37     }
     38 
     39     @Override
     40     public boolean isAvailable() {
     41         return mAutofillManager.hasAutofillFeature()
     42                 && mAutofillManager.isAutofillSupported();
     43     }
     44 
     45     @Override
     46     public String getPreferenceKey() {
     47         return "default_autofill";
     48     }
     49 
     50     @Override
     51     protected Intent getSettingIntent(DefaultAppInfo info) {
     52         if (info == null) {
     53             return null;
     54         }
     55         final DefaultAutofillPicker.AutofillSettingIntentProvider intentProvider =
     56                 new DefaultAutofillPicker.AutofillSettingIntentProvider(
     57                         mPackageManager.getPackageManager(), info.getKey());
     58         return intentProvider.getIntent();
     59     }
     60 
     61     @Override
     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(mPackageManager,
     67                     mUserId, ComponentName.unflattenFromString(flattenComponent));
     68             return appInfo;
     69         }
     70         return null;
     71     }
     72 }
     73