• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.wifi;
18 
19 import android.app.Dialog;
20 import android.app.DialogFragment;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.net.wifi.WpsInfo;
24 import android.os.Bundle;
25 import android.os.UserManager;
26 import android.security.Credentials;
27 import android.support.v7.preference.Preference;
28 import android.support.v7.preference.Preference.OnPreferenceClickListener;
29 import android.support.v7.preference.PreferenceScreen;
30 
31 import com.android.internal.logging.MetricsProto.MetricsEvent;
32 import com.android.settings.R;
33 import com.android.settings.RestrictedSettingsFragment;
34 import com.android.settingslib.RestrictedLockUtils;
35 
36 public class AdvancedWifiSettings extends RestrictedSettingsFragment {
37     private static final String TAG = "AdvancedWifiSettings";
38 
39     private static final String KEY_INSTALL_CREDENTIALS = "install_credentials";
40     private static final String KEY_WIFI_DIRECT = "wifi_direct";
41     private static final String KEY_WPS_PUSH = "wps_push_button";
42     private static final String KEY_WPS_PIN = "wps_pin_entry";
43 
44     private boolean mUnavailable;
45 
AdvancedWifiSettings()46     public AdvancedWifiSettings() {
47         super(UserManager.DISALLOW_CONFIG_WIFI);
48     }
49 
50     @Override
getMetricsCategory()51     protected int getMetricsCategory() {
52         return MetricsEvent.WIFI_ADVANCED;
53     }
54 
55     @Override
onCreate(Bundle savedInstanceState)56     public void onCreate(Bundle savedInstanceState) {
57         super.onCreate(savedInstanceState);
58         if (isUiRestricted()) {
59             mUnavailable = true;
60             setPreferenceScreen(new PreferenceScreen(getPrefContext(), null));
61         } else {
62             addPreferencesFromResource(R.xml.wifi_advanced_settings);
63         }
64     }
65 
66     @Override
onActivityCreated(Bundle savedInstanceState)67     public void onActivityCreated(Bundle savedInstanceState) {
68         super.onActivityCreated(savedInstanceState);
69         getEmptyTextView().setText(R.string.wifi_advanced_not_available);
70         if (mUnavailable) {
71             getPreferenceScreen().removeAll();
72         }
73     }
74 
75     @Override
onResume()76     public void onResume() {
77         super.onResume();
78         if (!mUnavailable) {
79             initPreferences();
80         }
81     }
82 
initPreferences()83     private void initPreferences() {
84         final Context context = getActivity();
85         Intent intent = new Intent(Credentials.INSTALL_AS_USER_ACTION);
86         intent.setClassName("com.android.certinstaller",
87                 "com.android.certinstaller.CertInstallerMain");
88         intent.putExtra(Credentials.EXTRA_INSTALL_AS_UID, android.os.Process.WIFI_UID);
89         Preference pref = findPreference(KEY_INSTALL_CREDENTIALS);
90         pref.setIntent(intent);
91 
92 
93         Intent wifiDirectIntent = new Intent(context,
94                 com.android.settings.Settings.WifiP2pSettingsActivity.class);
95         Preference wifiDirectPref = findPreference(KEY_WIFI_DIRECT);
96         wifiDirectPref.setIntent(wifiDirectIntent);
97 
98         // WpsDialog: Create the dialog like WifiSettings does.
99         Preference wpsPushPref = findPreference(KEY_WPS_PUSH);
100         wpsPushPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
101                 public boolean onPreferenceClick(Preference arg0) {
102                     WpsFragment wpsFragment = new WpsFragment(WpsInfo.PBC);
103                     wpsFragment.show(getFragmentManager(), KEY_WPS_PUSH);
104                     return true;
105                 }
106         });
107 
108         // WpsDialog: Create the dialog like WifiSettings does.
109         Preference wpsPinPref = findPreference(KEY_WPS_PIN);
110         wpsPinPref.setOnPreferenceClickListener(new OnPreferenceClickListener(){
111                 public boolean onPreferenceClick(Preference arg0) {
112                     WpsFragment wpsFragment = new WpsFragment(WpsInfo.DISPLAY);
113                     wpsFragment.show(getFragmentManager(), KEY_WPS_PIN);
114                     return true;
115                 }
116         });
117     }
118 
119     /* Wrapper class for the WPS dialog to properly handle life cycle events like rotation. */
120     public static class WpsFragment extends DialogFragment {
121         private static int mWpsSetup;
122 
123         // Public default constructor is required for rotation.
WpsFragment()124         public WpsFragment() {
125             super();
126         }
127 
WpsFragment(int wpsSetup)128         public WpsFragment(int wpsSetup) {
129             super();
130             mWpsSetup = wpsSetup;
131         }
132 
133         @Override
onCreateDialog(Bundle savedInstanceState)134         public Dialog onCreateDialog(Bundle savedInstanceState) {
135             return new WpsDialog(getActivity(), mWpsSetup);
136         }
137     }
138 
139 }
140