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

This commit is contained in:
Treehugger Robot
2017-01-10 21:15:55 +00:00
committed by Gerrit Code Review

View File

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