1 /*
2  * Copyright (C) 2016 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 package com.android.settings.network;
17 
18 import android.app.admin.DevicePolicyManager;
19 import android.content.Context;
20 
21 import androidx.preference.Preference;
22 import androidx.preference.PreferenceScreen;
23 
24 import com.android.settings.core.PreferenceControllerMixin;
25 import com.android.settingslib.core.AbstractPreferenceController;
26 
27 public class ProxyPreferenceController extends AbstractPreferenceController
28         implements PreferenceControllerMixin {
29 
30     private static final String KEY_PROXY_SETTINGS = "proxy_settings";
31 
ProxyPreferenceController(Context context)32     public ProxyPreferenceController(Context context) {
33         super(context);
34     }
35 
36     @Override
isAvailable()37     public boolean isAvailable() {
38         // proxy UI disabled until we have better app support
39         return false;
40     }
41 
42     @Override
displayPreference(PreferenceScreen screen)43     public void displayPreference(PreferenceScreen screen) {
44         super.displayPreference(screen);
45         // Enable Proxy selector settings if allowed.
46         final Preference pref = screen.findPreference(KEY_PROXY_SETTINGS);
47         if (pref != null) {
48             final DevicePolicyManager dpm = (DevicePolicyManager)
49                     mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
50             pref.setEnabled(dpm.getGlobalProxyAdmin() == null);
51         }
52     }
53 
54     @Override
getPreferenceKey()55     public String getPreferenceKey() {
56         return KEY_PROXY_SETTINGS;
57     }
58 }
59