OSDN Git Service

Merge "Fix search indexing for encryption_and_credential page" into oc-dr1-dev
[android-x86/packages-apps-Settings.git] / src / com / android / settings / webview / WebViewAppPreferenceController.java
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14
15 package com.android.settings.webview;
16
17 import android.content.Context;
18 import android.content.pm.PackageInfo;
19 import android.support.v7.preference.Preference;
20 import android.support.v7.preference.PreferenceScreen;
21
22 import com.android.settings.applications.defaultapps.DefaultAppInfo;
23 import com.android.settings.applications.defaultapps.DefaultAppPreferenceController;
24
25 public class WebViewAppPreferenceController extends DefaultAppPreferenceController {
26
27     private static final String WEBVIEW_APP_KEY = "select_webview_provider";
28
29     private final Context mContext;
30     private final WebViewUpdateServiceWrapper mWebViewUpdateServiceWrapper;
31     private Preference mPreference;
32
33     public WebViewAppPreferenceController(Context context) {
34         this(context, new WebViewUpdateServiceWrapper());
35     }
36
37     public WebViewAppPreferenceController(Context context,
38             WebViewUpdateServiceWrapper webviewUpdateServiceWrapper) {
39         super(context);
40         mContext = context;
41         mWebViewUpdateServiceWrapper = webviewUpdateServiceWrapper;
42     }
43
44     @Override
45     public DefaultAppInfo getDefaultAppInfo() {
46         PackageInfo currentPackage = mWebViewUpdateServiceWrapper.getCurrentWebViewPackage();
47         return new DefaultAppInfo(mPackageManager,
48                 currentPackage == null ? null : currentPackage.applicationInfo);
49     }
50
51     @Override
52     public void displayPreference(PreferenceScreen screen) {
53         super.displayPreference(screen);
54         if (isAvailable()) {
55             mPreference = screen.findPreference(WEBVIEW_APP_KEY);
56         }
57     }
58
59     @Override
60     public String getPreferenceKey() {
61         return WEBVIEW_APP_KEY;
62     }
63
64     @Override
65     public boolean isAvailable() {
66         return true;
67     }
68
69     public void enablePreference(boolean enabled) {
70         if (isAvailable()) {
71             mPreference.setEnabled(enabled);
72         }
73     }
74 }