Merge "Some Wi-Fi Menus like WPS should be disabled when Wi-Fi is off" am: f952a87060

am: a9e9bf20e8

Change-Id: Ia45623e60a3a774b3b21dd58d350f3c408aaff20
This commit is contained in:
Yanhong Shen
2017-01-10 21:28:47 +00:00
committed by android-build-merger

View File

@@ -18,8 +18,11 @@ package com.android.settings.wifi;
import android.app.Dialog; import android.app.Dialog;
import android.app.DialogFragment; import android.app.DialogFragment;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
import android.net.wifi.WpsInfo; import android.net.wifi.WpsInfo;
import android.os.Bundle; import android.os.Bundle;
import android.os.UserManager; import android.os.UserManager;
@@ -43,6 +46,13 @@ public class AdvancedWifiSettings extends RestrictedSettingsFragment {
private boolean mUnavailable; private boolean mUnavailable;
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
initPreferences();
}
};
public AdvancedWifiSettings() { public AdvancedWifiSettings() {
super(UserManager.DISALLOW_CONFIG_WIFI); super(UserManager.DISALLOW_CONFIG_WIFI);
} }
@@ -73,13 +83,23 @@ public class AdvancedWifiSettings extends RestrictedSettingsFragment {
} }
@Override @Override
public void onResume() { public void onStart() {
super.onResume(); super.onStart();
if (!mUnavailable) { if (!mUnavailable) {
getActivity().registerReceiver(mReceiver,
new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
initPreferences(); initPreferences();
} }
} }
@Override
public void onStop() {
super.onStop();
if (!mUnavailable) {
getActivity().unregisterReceiver(mReceiver);
}
}
private void initPreferences() { private void initPreferences() {
final Context context = getActivity(); final Context context = getActivity();
Intent intent = new Intent(Credentials.INSTALL_AS_USER_ACTION); Intent intent = new Intent(Credentials.INSTALL_AS_USER_ACTION);
@@ -89,11 +109,13 @@ public class AdvancedWifiSettings extends RestrictedSettingsFragment {
Preference pref = findPreference(KEY_INSTALL_CREDENTIALS); Preference pref = findPreference(KEY_INSTALL_CREDENTIALS);
pref.setIntent(intent); pref.setIntent(intent);
final WifiManager wifiManager =
(WifiManager)getActivity().getSystemService(Context.WIFI_SERVICE);
Intent wifiDirectIntent = new Intent(context, Intent wifiDirectIntent = new Intent(context,
com.android.settings.Settings.WifiP2pSettingsActivity.class); com.android.settings.Settings.WifiP2pSettingsActivity.class);
Preference wifiDirectPref = findPreference(KEY_WIFI_DIRECT); Preference wifiDirectPref = findPreference(KEY_WIFI_DIRECT);
wifiDirectPref.setIntent(wifiDirectIntent); wifiDirectPref.setIntent(wifiDirectIntent);
wifiDirectPref.setEnabled(wifiManager.isWifiEnabled());
// WpsDialog: Create the dialog like WifiSettings does. // WpsDialog: Create the dialog like WifiSettings does.
Preference wpsPushPref = findPreference(KEY_WPS_PUSH); Preference wpsPushPref = findPreference(KEY_WPS_PUSH);
@@ -104,6 +126,7 @@ public class AdvancedWifiSettings extends RestrictedSettingsFragment {
return true; return true;
} }
}); });
wpsPushPref.setEnabled(wifiManager.isWifiEnabled());
// WpsDialog: Create the dialog like WifiSettings does. // WpsDialog: Create the dialog like WifiSettings does.
Preference wpsPinPref = findPreference(KEY_WPS_PIN); Preference wpsPinPref = findPreference(KEY_WPS_PIN);
@@ -114,6 +137,7 @@ public class AdvancedWifiSettings extends RestrictedSettingsFragment {
return true; return true;
} }
}); });
wpsPinPref.setEnabled(wifiManager.isWifiEnabled());
} }
/* Wrapper class for the WPS dialog to properly handle life cycle events like rotation. */ /* Wrapper class for the WPS dialog to properly handle life cycle events like rotation. */