1 /*
2  * Copyright (C) 2018 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.development.autofill;
18 
19 import android.content.ContentResolver;
20 import android.content.Context;
21 import android.provider.Settings;
22 import android.text.TextUtils;
23 import android.view.autofill.AutofillManager;
24 import android.widget.Toast;
25 
26 import androidx.preference.Preference;
27 
28 import com.android.settings.R;
29 import com.android.settings.core.PreferenceControllerMixin;
30 import com.android.settingslib.development.DeveloperOptionsPreferenceController;
31 
32 public final class AutofillResetOptionsPreferenceController
33         extends DeveloperOptionsPreferenceController
34         implements PreferenceControllerMixin {
35 
36     private static final String AUTOFILL_RESET_OPTIONS_KEY = "autofill_reset_developer_options";
37 
AutofillResetOptionsPreferenceController(Context context)38     public AutofillResetOptionsPreferenceController(Context context) {
39         super(context);
40     }
41 
42     @Override
getPreferenceKey()43     public String getPreferenceKey() {
44         return AUTOFILL_RESET_OPTIONS_KEY;
45     }
46 
47     @Override
handlePreferenceTreeClick(Preference preference)48     public boolean handlePreferenceTreeClick(Preference preference) {
49         if (!TextUtils.equals(AUTOFILL_RESET_OPTIONS_KEY, preference.getKey())) {
50             return false;
51         }
52         final ContentResolver contentResolver = mContext.getContentResolver();
53         Settings.Global.putInt(contentResolver, Settings.Global.AUTOFILL_LOGGING_LEVEL,
54                 AutofillManager.DEFAULT_LOGGING_LEVEL);
55         Settings.Global.putInt(contentResolver, Settings.Global.AUTOFILL_MAX_PARTITIONS_SIZE,
56                 AutofillManager.DEFAULT_MAX_PARTITIONS_SIZE);
57         Settings.Global.putInt(contentResolver, Settings.Global.AUTOFILL_MAX_VISIBLE_DATASETS, 0);
58         Toast.makeText(mContext, R.string.autofill_reset_developer_options_complete,
59                 Toast.LENGTH_SHORT).show();
60         return true;
61     }
62 }
63