Merge "Save WifiAp config changes when hotspot is enabled" into nyc-dev

am: da9957780b

* commit 'da9957780b71a17b81e25213053f45be73564f03':
  Save WifiAp config changes when hotspot is enabled
This commit is contained in:
Rebecca Silberstein
2016-03-07 23:37:07 +00:00
committed by android-build-merger

View File

@@ -42,6 +42,7 @@ import android.os.UserManager;
import android.support.v14.preference.SwitchPreference; import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import com.android.internal.logging.MetricsProto.MetricsEvent; import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settings.wifi.WifiApDialog; import com.android.settings.wifi.WifiApDialog;
@@ -65,6 +66,8 @@ public class TetherSettings extends RestrictedSettingsFragment
private static final int DIALOG_AP_SETTINGS = 1; private static final int DIALOG_AP_SETTINGS = 1;
private static final String TAG = "TetheringSettings";
private SwitchPreference mUsbTether; private SwitchPreference mUsbTether;
private WifiApEnabler mWifiApEnabler; private WifiApEnabler mWifiApEnabler;
@@ -95,6 +98,8 @@ public class TetherSettings extends RestrictedSettingsFragment
private WifiConfiguration mWifiConfig = null; private WifiConfiguration mWifiConfig = null;
private ConnectivityManager mCm; private ConnectivityManager mCm;
private boolean mRestartWifiApAfterConfigChange;
private boolean mUsbConnected; private boolean mUsbConnected;
private boolean mMassStorageActive; private boolean mMassStorageActive;
@@ -141,7 +146,7 @@ public class TetherSettings extends RestrictedSettingsFragment
mUsbTether = (SwitchPreference) findPreference(USB_TETHER_SETTINGS); mUsbTether = (SwitchPreference) findPreference(USB_TETHER_SETTINGS);
mBluetoothTether = (SwitchPreference) findPreference(ENABLE_BLUETOOTH_TETHERING); mBluetoothTether = (SwitchPreference) findPreference(ENABLE_BLUETOOTH_TETHERING);
mCm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
mUsbRegexs = mCm.getTetherableUsbRegexs(); mUsbRegexs = mCm.getTetherableUsbRegexs();
mWifiRegexs = mCm.getTetherableWifiRegexs(); mWifiRegexs = mCm.getTetherableWifiRegexs();
@@ -183,6 +188,8 @@ public class TetherSettings extends RestrictedSettingsFragment
mCreateNetwork = findPreference(WIFI_AP_SSID_AND_SECURITY); mCreateNetwork = findPreference(WIFI_AP_SSID_AND_SECURITY);
mRestartWifiApAfterConfigChange = false;
if (mWifiConfig == null) { if (mWifiConfig == null) {
final String s = activity.getString( final String s = activity.getString(
com.android.internal.R.string.wifi_tether_configure_ssid_default); com.android.internal.R.string.wifi_tether_configure_ssid_default);
@@ -222,6 +229,12 @@ public class TetherSettings extends RestrictedSettingsFragment
updateState(available.toArray(new String[available.size()]), updateState(available.toArray(new String[available.size()]),
active.toArray(new String[active.size()]), active.toArray(new String[active.size()]),
errored.toArray(new String[errored.size()])); errored.toArray(new String[errored.size()]));
if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_DISABLED
&& mRestartWifiApAfterConfigChange) {
mRestartWifiApAfterConfigChange = false;
Log.d(TAG, "Restarting WifiAp due to prior config change.");
startTethering(TETHERING_WIFI);
}
} else if (action.equals(Intent.ACTION_MEDIA_SHARED)) { } else if (action.equals(Intent.ACTION_MEDIA_SHARED)) {
mMassStorageActive = true; mMassStorageActive = true;
updateState(); updateState();
@@ -391,8 +404,9 @@ public class TetherSettings extends RestrictedSettingsFragment
} }
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter == null) if (adapter == null) {
return; return;
}
int btState = adapter.getState(); int btState = adapter.getState();
if (btState == BluetoothAdapter.STATE_TURNING_OFF) { if (btState == BluetoothAdapter.STATE_TURNING_OFF) {
mBluetoothTether.setEnabled(false); mBluetoothTether.setEnabled(false);
@@ -402,8 +416,8 @@ public class TetherSettings extends RestrictedSettingsFragment
mBluetoothTether.setSummary(R.string.bluetooth_turning_on); mBluetoothTether.setSummary(R.string.bluetooth_turning_on);
} else { } else {
BluetoothPan bluetoothPan = mBluetoothPan.get(); BluetoothPan bluetoothPan = mBluetoothPan.get();
if (btState == BluetoothAdapter.STATE_ON && bluetoothPan != null && if (btState == BluetoothAdapter.STATE_ON && bluetoothPan != null
bluetoothPan.isTetheringOn()) { && bluetoothPan.isTetheringOn()) {
mBluetoothTether.setChecked(true); mBluetoothTether.setChecked(true);
mBluetoothTether.setEnabled(true); mBluetoothTether.setEnabled(true);
int bluetoothTethered = bluetoothPan.getConnectedDevices().size(); int bluetoothTethered = bluetoothPan.getConnectedDevices().size();
@@ -506,11 +520,12 @@ public class TetherSettings extends RestrictedSettingsFragment
* TODO: update config on a running access point when framework support is added * TODO: update config on a running access point when framework support is added
*/ */
if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED) { if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED) {
mWifiManager.setWifiApEnabled(null, false); Log.d("TetheringSettings",
mWifiManager.setWifiApEnabled(mWifiConfig, true); "Wifi AP config changed while enabled, stop and restart");
} else { mRestartWifiApAfterConfigChange = true;
mWifiManager.setWifiApConfiguration(mWifiConfig); mCm.stopTethering(TETHERING_WIFI);
} }
mWifiManager.setWifiApConfiguration(mWifiConfig);
int index = WifiApDialog.getSecurityTypeIndex(mWifiConfig); int index = WifiApDialog.getSecurityTypeIndex(mWifiConfig);
mCreateNetwork.setSummary(String.format(getActivity().getString(CONFIG_SUBTEXT), mCreateNetwork.setSummary(String.format(getActivity().getString(CONFIG_SUBTEXT),
mWifiConfig.SSID, mWifiConfig.SSID,