DefaultAutofillPreferenceController.java revision 4fa4a2e3f5383dfa0f82470188ba2ea12601f689
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
17package com.android.settings.applications.defaultapps;
18
19import android.content.ComponentName;
20import android.content.Context;
21import android.content.Intent;
22import android.provider.Settings;
23import android.text.TextUtils;
24
25public class DefaultAutofillPreferenceController extends DefaultAppPreferenceController {
26
27    public DefaultAutofillPreferenceController(Context context) {
28        super(context);
29    }
30
31    @Override
32    public boolean isAvailable() {
33        return true;
34    }
35
36    @Override
37    public String getPreferenceKey() {
38        return "default_autofill";
39    }
40
41    @Override
42    protected Intent getSettingIntent(DefaultAppInfo info) {
43        if (info == null) {
44            return null;
45        }
46        final DefaultAutofillPicker.AutofillSettingIntentProvider intentProvider =
47                new DefaultAutofillPicker.AutofillSettingIntentProvider(
48                        mPackageManager.getPackageManager(), info.getKey());
49        return intentProvider.getIntent();
50    }
51
52    @Override
53    protected DefaultAppInfo getDefaultAppInfo() {
54        final String flattenComponent = Settings.Secure.getString(mContext.getContentResolver(),
55                DefaultAutofillPicker.SETTING);
56        if (!TextUtils.isEmpty(flattenComponent)) {
57            DefaultAppInfo appInfo = new DefaultAppInfo(
58                    mUserId, ComponentName.unflattenFromString(flattenComponent));
59            return appInfo;
60        }
61        return null;
62    }
63}
64