Remove code for old wifi tether feature
Change-Id: If92798ddf075801e66cd97ecacff2f8df1e41985 Fix: 64032458 Test: rerun robotests
This commit is contained in:
@@ -1,154 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2010 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="300sp"
|
||||
android:layout_height="wrap_content"
|
||||
android:fadeScrollbars="false">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:descendantFocusability="beforeDescendants"
|
||||
android:focusableInTouchMode="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout android:id="@+id/info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_section" />
|
||||
|
||||
<LinearLayout android:id="@+id/type"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_section"
|
||||
android:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_label"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/wifi_ssid" />
|
||||
|
||||
<EditText android:id="@+id/ssid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_edit_content"
|
||||
android:singleLine="true"
|
||||
android:hint="@string/wifi_ssid_hint"
|
||||
android:inputType="textNoSuggestions"
|
||||
android:maxLength="32" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_label"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/wifi_security" />
|
||||
|
||||
<Spinner android:id="@+id/security"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_content"
|
||||
android:prompt="@string/wifi_security"
|
||||
android:entries="@array/wifi_ap_security" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/fields"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_section"
|
||||
android:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_label"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/wifi_password" />
|
||||
|
||||
<EditText android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_edit_content"
|
||||
android:singleLine="true"
|
||||
android:password="true"
|
||||
android:maxLength="63"
|
||||
android:imeOptions="flagForceAscii" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item">
|
||||
<TextView android:id="@+id/hint"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_label"
|
||||
android:text="@string/credentials_password_too_short"
|
||||
android:layout_marginTop="8dip"
|
||||
android:layout_marginBottom="10sp"/>
|
||||
|
||||
<CheckBox android:id="@+id/show_password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_content"
|
||||
android:text="@string/wifi_show_password" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/fields"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_section" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_label"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/wifi_ap_band_config" />
|
||||
|
||||
<Spinner android:id="@+id/choose_channel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_content"
|
||||
android:prompt="@string/wifi_ap_band_config" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
@@ -235,13 +235,6 @@
|
||||
<item>@string/wifi_security_psk_generic</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Wi-Fi AP settings. The type of security a Wi-Fi AP supports. -->
|
||||
<!-- Note that adding/removing/moving the items will need wifi settings code change. -->
|
||||
<string-array name="wifi_ap_security">
|
||||
<item>@string/wifi_security_none</item>
|
||||
<item>@string/wifi_security_wpa2</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Match this with the constants in WifiDialog. --> <skip />
|
||||
<!-- Wi-Fi settings. The type of EAP method a Wi-Fi network has. -->
|
||||
<string-array name="wifi_eap_method">
|
||||
|
@@ -2088,8 +2088,6 @@
|
||||
<string name="wifi_hotspot_configure_ap_text">Wi\u2011Fi hotspot setup</string>
|
||||
<!-- Summary Used to open the ssid and security dialog for Wifi Access Point. [CHAR LIMIT=60] -->
|
||||
<string name="wifi_hotspot_configure_ap_text_summary">AndroidAP WPA2 PSK hotspot</string>
|
||||
<!-- Subtext on configuration preference to indicate SSID and security chosen -->
|
||||
<string name="wifi_tether_configure_subtext"><xliff:g id="network_ssid">%1$s</xliff:g> <xliff:g id="network_security">%2$s</xliff:g> hotspot</string>
|
||||
<!-- Default access point SSID used for tethering -->
|
||||
<string name="wifi_tether_configure_ssid_default">AndroidHotspot</string>
|
||||
|
||||
@@ -5177,7 +5175,6 @@
|
||||
<string name="credentials_old_password">Current password:</string>
|
||||
<!-- Description of dialog to reset credential storage [CHAR LIMIT=NONE] -->
|
||||
<string name="credentials_reset_hint">Remove all the contents?</string>
|
||||
<string name="credentials_password_too_short">The password must have at least 8 characters.</string>
|
||||
<!-- Error message [CHAR LIMIT=NONE] -->
|
||||
<string name="credentials_wrong_password">Incorrect password.</string>
|
||||
<!-- Error message [CHAR LIMIT=NONE] -->
|
||||
|
@@ -28,16 +28,6 @@
|
||||
android:title="@string/usb_tethering_button_text"
|
||||
android:summary="@string/usb_tethering_subtext" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="enable_wifi_ap"
|
||||
android:title="@string/wifi_hotspot_checkbox_text"
|
||||
android:summary="@string/summary_two_lines_placeholder" />
|
||||
|
||||
<Preference
|
||||
android:key="wifi_ap_ssid_and_security"
|
||||
android:title="@string/wifi_tether_configure_ap_text"
|
||||
android:persistent="false" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="enable_bluetooth_tethering"
|
||||
android:title="@string/bluetooth_tether_checkbox_text"
|
||||
|
@@ -16,95 +16,64 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import static android.net.ConnectivityManager.TETHERING_BLUETOOTH;
|
||||
import static android.net.ConnectivityManager.TETHERING_USB;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothPan;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.UserManager;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.datausage.DataSaverBackend;
|
||||
import com.android.settings.wifi.WifiApDialog;
|
||||
import com.android.settings.wifi.WifiApEnabler;
|
||||
import com.android.settings.wifi.tether.WifiTetherPreferenceController;
|
||||
import com.android.settings.wifi.tether.WifiTetherSettings;
|
||||
import com.android.settingslib.TetherUtil;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static android.net.ConnectivityManager.TETHERING_BLUETOOTH;
|
||||
import static android.net.ConnectivityManager.TETHERING_USB;
|
||||
import static android.net.ConnectivityManager.TETHERING_WIFI;
|
||||
|
||||
/*
|
||||
* Displays preferences for Tethering.
|
||||
*/
|
||||
public class TetherSettings extends RestrictedSettingsFragment
|
||||
implements DialogInterface.OnClickListener, Preference.OnPreferenceChangeListener,
|
||||
DataSaverBackend.Listener {
|
||||
implements DataSaverBackend.Listener {
|
||||
|
||||
private static final String USB_TETHER_SETTINGS = "usb_tether_settings";
|
||||
private static final String ENABLE_WIFI_AP = "enable_wifi_ap";
|
||||
private static final String ENABLE_BLUETOOTH_TETHERING = "enable_bluetooth_tethering";
|
||||
private static final String DATA_SAVER_FOOTER = "disabled_on_data_saver";
|
||||
|
||||
private static final int DIALOG_AP_SETTINGS = 1;
|
||||
|
||||
private static final String TAG = "TetheringSettings";
|
||||
|
||||
private SwitchPreference mUsbTether;
|
||||
|
||||
private WifiApEnabler mWifiApEnabler;
|
||||
private SwitchPreference mEnableWifiAp;
|
||||
|
||||
private SwitchPreference mBluetoothTether;
|
||||
|
||||
private BroadcastReceiver mTetherChangeReceiver;
|
||||
|
||||
private String[] mUsbRegexs;
|
||||
|
||||
private String[] mWifiRegexs;
|
||||
|
||||
private String[] mBluetoothRegexs;
|
||||
private AtomicReference<BluetoothPan> mBluetoothPan = new AtomicReference<BluetoothPan>();
|
||||
private AtomicReference<BluetoothPan> mBluetoothPan = new AtomicReference<>();
|
||||
|
||||
private Handler mHandler = new Handler();
|
||||
private OnStartTetheringCallback mStartTetheringCallback;
|
||||
|
||||
private static final String WIFI_AP_SSID_AND_SECURITY = "wifi_ap_ssid_and_security";
|
||||
private static final int CONFIG_SUBTEXT = R.string.wifi_tether_configure_subtext;
|
||||
|
||||
private String[] mSecurityType;
|
||||
private Preference mCreateNetwork;
|
||||
|
||||
private WifiApDialog mDialog;
|
||||
private WifiManager mWifiManager;
|
||||
private WifiConfiguration mWifiConfig = null;
|
||||
private ConnectivityManager mCm;
|
||||
|
||||
private WifiTetherPreferenceController mWifiTetherPreferenceController;
|
||||
|
||||
private boolean mRestartWifiApAfterConfigChange;
|
||||
|
||||
private boolean mUsbConnected;
|
||||
private boolean mMassStorageActive;
|
||||
|
||||
@@ -157,24 +126,17 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
BluetoothProfile.PAN);
|
||||
}
|
||||
|
||||
mEnableWifiAp =
|
||||
(SwitchPreference) findPreference(ENABLE_WIFI_AP);
|
||||
|
||||
Preference wifiApSettings = findPreference(WIFI_AP_SSID_AND_SECURITY);
|
||||
mUsbTether = (SwitchPreference) findPreference(USB_TETHER_SETTINGS);
|
||||
mBluetoothTether = (SwitchPreference) findPreference(ENABLE_BLUETOOTH_TETHERING);
|
||||
|
||||
mDataSaverBackend.addListener(this);
|
||||
|
||||
mCm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
|
||||
mUsbRegexs = mCm.getTetherableUsbRegexs();
|
||||
mWifiRegexs = mCm.getTetherableWifiRegexs();
|
||||
mBluetoothRegexs = mCm.getTetherableBluetoothRegexs();
|
||||
|
||||
final boolean usbAvailable = mUsbRegexs.length != 0;
|
||||
final boolean wifiAvailable = mWifiRegexs.length != 0;
|
||||
final boolean bluetoothAvailable = mBluetoothRegexs.length != 0;
|
||||
|
||||
if (!usbAvailable || Utils.isMonkeyRunning()) {
|
||||
@@ -182,18 +144,6 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
|
||||
mWifiTetherPreferenceController.displayPreference(getPreferenceScreen());
|
||||
if (WifiTetherSettings.isTetherSettingPageEnabled()) {
|
||||
removePreference(ENABLE_WIFI_AP);
|
||||
removePreference(WIFI_AP_SSID_AND_SECURITY);
|
||||
} else {
|
||||
if (wifiAvailable && !Utils.isMonkeyRunning()) {
|
||||
mWifiApEnabler = new WifiApEnabler(activity, mDataSaverBackend, mEnableWifiAp);
|
||||
initWifiTethering();
|
||||
} else {
|
||||
getPreferenceScreen().removePreference(mEnableWifiAp);
|
||||
getPreferenceScreen().removePreference(wifiApSettings);
|
||||
}
|
||||
}
|
||||
|
||||
if (!bluetoothAvailable) {
|
||||
getPreferenceScreen().removePreference(mBluetoothTether);
|
||||
@@ -225,7 +175,6 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
@Override
|
||||
public void onDataSaverChanged(boolean isDataSaving) {
|
||||
mDataSaverEnabled = isDataSaving;
|
||||
mEnableWifiAp.setEnabled(!mDataSaverEnabled);
|
||||
mUsbTether.setEnabled(!mDataSaverEnabled);
|
||||
mBluetoothTether.setEnabled(!mDataSaverEnabled);
|
||||
mDataSaverFooter.setVisible(mDataSaverEnabled);
|
||||
@@ -239,47 +188,6 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
public void onBlacklistStatusChanged(int uid, boolean isBlacklisted) {
|
||||
}
|
||||
|
||||
private void initWifiTethering() {
|
||||
final Activity activity = getActivity();
|
||||
mWifiConfig = mWifiManager.getWifiApConfiguration();
|
||||
mSecurityType = getResources().getStringArray(R.array.wifi_ap_security);
|
||||
|
||||
mCreateNetwork = findPreference(WIFI_AP_SSID_AND_SECURITY);
|
||||
|
||||
mRestartWifiApAfterConfigChange = false;
|
||||
|
||||
if (mWifiConfig == null) {
|
||||
final String s = activity.getString(
|
||||
com.android.internal.R.string.wifi_tether_configure_ssid_default);
|
||||
mCreateNetwork.setSummary(String.format(activity.getString(CONFIG_SUBTEXT),
|
||||
s, mSecurityType[WifiApDialog.OPEN_INDEX]));
|
||||
} else {
|
||||
int index = WifiApDialog.getSecurityTypeIndex(mWifiConfig);
|
||||
mCreateNetwork.setSummary(String.format(activity.getString(CONFIG_SUBTEXT),
|
||||
mWifiConfig.SSID,
|
||||
mSecurityType[index]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(int id) {
|
||||
if (id == DIALOG_AP_SETTINGS) {
|
||||
final Activity activity = getActivity();
|
||||
mDialog = new WifiApDialog(activity, this, mWifiConfig);
|
||||
return mDialog;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDialogMetricsCategory(int dialogId) {
|
||||
if (dialogId == DIALOG_AP_SETTINGS) {
|
||||
return MetricsEvent.DIALOG_AP_SETTINGS;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private class TetherChangeReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context content, Intent intent) {
|
||||
@@ -295,20 +203,6 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
updateState(available.toArray(new String[available.size()]),
|
||||
active.toArray(new String[active.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(WifiManager.WIFI_AP_STATE_CHANGED_ACTION)) {
|
||||
int state = intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_STATE, 0);
|
||||
if (state == 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)) {
|
||||
mMassStorageActive = true;
|
||||
updateState();
|
||||
@@ -360,7 +254,6 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
mMassStorageActive = Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
|
||||
mTetherChangeReceiver = new TetherChangeReceiver();
|
||||
IntentFilter filter = new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
|
||||
filter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
||||
Intent intent = activity.registerReceiver(mTetherChangeReceiver, filter);
|
||||
|
||||
filter = new IntentFilter();
|
||||
@@ -378,10 +271,6 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
activity.registerReceiver(mTetherChangeReceiver, filter);
|
||||
|
||||
if (intent != null) mTetherChangeReceiver.onReceive(activity, intent);
|
||||
if (mWifiApEnabler != null) {
|
||||
mEnableWifiAp.setOnPreferenceChangeListener(this);
|
||||
mWifiApEnabler.resume();
|
||||
}
|
||||
|
||||
updateState();
|
||||
}
|
||||
@@ -396,10 +285,6 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
getActivity().unregisterReceiver(mTetherChangeReceiver);
|
||||
mTetherChangeReceiver = null;
|
||||
mStartTetheringCallback = null;
|
||||
if (mWifiApEnabler != null) {
|
||||
mEnableWifiAp.setOnPreferenceChangeListener(null);
|
||||
mWifiApEnabler.pause();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
@@ -415,7 +300,6 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
updateBluetoothState();
|
||||
}
|
||||
|
||||
|
||||
private void updateUsbState(String[] available, String[] tethered,
|
||||
String[] errored) {
|
||||
boolean usbAvailable = mUsbConnected && !mMassStorageActive;
|
||||
@@ -477,18 +361,6 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object value) {
|
||||
boolean enable = (Boolean) value;
|
||||
|
||||
if (enable) {
|
||||
startTethering(TETHERING_WIFI);
|
||||
} else {
|
||||
mCm.stopTethering(TETHERING_WIFI);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isProvisioningNeededButUnavailable(Context context) {
|
||||
return (TetherUtil.isProvisioningNeeded(context)
|
||||
&& !isIntentAvailable(context));
|
||||
@@ -541,37 +413,11 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
// connected. Need to update state manually.
|
||||
updateState();
|
||||
}
|
||||
} else if (preference == mCreateNetwork) {
|
||||
showDialog(DIALOG_AP_SETTINGS);
|
||||
}
|
||||
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
public void onClick(DialogInterface dialogInterface, int button) {
|
||||
if (button == DialogInterface.BUTTON_POSITIVE) {
|
||||
mWifiConfig = mDialog.getConfig();
|
||||
if (mWifiConfig != null) {
|
||||
/**
|
||||
* if soft AP is stopped, bring up
|
||||
* else restart with new config
|
||||
* TODO: update config on a running access point when framework support is added
|
||||
*/
|
||||
if (mWifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_ENABLED) {
|
||||
Log.d("TetheringSettings",
|
||||
"Wifi AP config changed while enabled, stop and restart");
|
||||
mRestartWifiApAfterConfigChange = true;
|
||||
mCm.stopTethering(TETHERING_WIFI);
|
||||
}
|
||||
mWifiManager.setWifiApConfiguration(mWifiConfig);
|
||||
int index = WifiApDialog.getSecurityTypeIndex(mWifiConfig);
|
||||
mCreateNetwork.setSummary(String.format(getActivity().getString(CONFIG_SUBTEXT),
|
||||
mWifiConfig.SSID,
|
||||
mSecurityType[index]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHelpResource() {
|
||||
return R.string.help_url_tether;
|
||||
@@ -592,7 +438,7 @@ public class TetherSettings extends RestrictedSettingsFragment
|
||||
final WeakReference<TetherSettings> mTetherSettings;
|
||||
|
||||
OnStartTetheringCallback(TetherSettings settings) {
|
||||
mTetherSettings = new WeakReference<TetherSettings>(settings);
|
||||
mTetherSettings = new WeakReference<>(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,263 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
|
||||
import android.net.wifi.WifiConfiguration.KeyMgmt;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* Dialog to configure the SSID and security settings
|
||||
* for Access Point operation
|
||||
*/
|
||||
public class WifiApDialog extends AlertDialog implements View.OnClickListener,
|
||||
TextWatcher, AdapterView.OnItemSelectedListener {
|
||||
|
||||
static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;
|
||||
|
||||
private final DialogInterface.OnClickListener mListener;
|
||||
|
||||
public static final int OPEN_INDEX = 0;
|
||||
public static final int WPA2_INDEX = 1;
|
||||
|
||||
private View mView;
|
||||
private TextView mSsid;
|
||||
private int mSecurityTypeIndex = OPEN_INDEX;
|
||||
private EditText mPassword;
|
||||
private int mBandIndex = OPEN_INDEX;
|
||||
|
||||
WifiConfiguration mWifiConfig;
|
||||
WifiManager mWifiManager;
|
||||
private Context mContext;
|
||||
|
||||
private static final String TAG = "WifiApDialog";
|
||||
|
||||
public WifiApDialog(Context context, DialogInterface.OnClickListener listener,
|
||||
WifiConfiguration wifiConfig) {
|
||||
super(context);
|
||||
mListener = listener;
|
||||
mWifiConfig = wifiConfig;
|
||||
if (wifiConfig != null) {
|
||||
mSecurityTypeIndex = getSecurityTypeIndex(wifiConfig);
|
||||
}
|
||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public static int getSecurityTypeIndex(WifiConfiguration wifiConfig) {
|
||||
if (wifiConfig.allowedKeyManagement.get(KeyMgmt.WPA2_PSK)) {
|
||||
return WPA2_INDEX;
|
||||
}
|
||||
return OPEN_INDEX;
|
||||
}
|
||||
|
||||
public WifiConfiguration getConfig() {
|
||||
|
||||
WifiConfiguration config = new WifiConfiguration();
|
||||
|
||||
/**
|
||||
* TODO: SSID in WifiConfiguration for soft ap
|
||||
* is being stored as a raw string without quotes.
|
||||
* This is not the case on the client side. We need to
|
||||
* make things consistent and clean it up
|
||||
*/
|
||||
config.SSID = mSsid.getText().toString();
|
||||
|
||||
config.apBand = mBandIndex;
|
||||
|
||||
switch (mSecurityTypeIndex) {
|
||||
case OPEN_INDEX:
|
||||
config.allowedKeyManagement.set(KeyMgmt.NONE);
|
||||
return config;
|
||||
|
||||
case WPA2_INDEX:
|
||||
config.allowedKeyManagement.set(KeyMgmt.WPA2_PSK);
|
||||
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
|
||||
if (mPassword.length() != 0) {
|
||||
String password = mPassword.getText().toString();
|
||||
config.preSharedKey = password;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
boolean mInit = true;
|
||||
mView = getLayoutInflater().inflate(R.layout.wifi_ap_dialog, null);
|
||||
Spinner mSecurity = ((Spinner) mView.findViewById(R.id.security));
|
||||
final Spinner mChannel = (Spinner) mView.findViewById(R.id.choose_channel);
|
||||
|
||||
setView(mView);
|
||||
setInverseBackgroundForced(true);
|
||||
|
||||
Context context = getContext();
|
||||
|
||||
setTitle(R.string.wifi_tether_configure_ap_text);
|
||||
mView.findViewById(R.id.type).setVisibility(View.VISIBLE);
|
||||
mSsid = (TextView) mView.findViewById(R.id.ssid);
|
||||
mPassword = (EditText) mView.findViewById(R.id.password);
|
||||
|
||||
ArrayAdapter <CharSequence> channelAdapter;
|
||||
String countryCode = mWifiManager.getCountryCode();
|
||||
if (!mWifiManager.isDualBandSupported() || countryCode == null) {
|
||||
//If no country code, 5GHz AP is forbidden
|
||||
Log.i(TAG,(!mWifiManager.isDualBandSupported() ? "Device do not support 5GHz " :"")
|
||||
+ (countryCode == null ? " NO country code" :"") + " forbid 5GHz");
|
||||
channelAdapter = ArrayAdapter.createFromResource(mContext,
|
||||
R.array.wifi_ap_band_config_2G_only, android.R.layout.simple_spinner_item);
|
||||
mWifiConfig.apBand = 0;
|
||||
} else {
|
||||
channelAdapter = ArrayAdapter.createFromResource(mContext,
|
||||
R.array.wifi_ap_band_config_full, android.R.layout.simple_spinner_item);
|
||||
}
|
||||
|
||||
channelAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
|
||||
setButton(BUTTON_SUBMIT, context.getString(R.string.wifi_save), mListener);
|
||||
setButton(DialogInterface.BUTTON_NEGATIVE,
|
||||
context.getString(R.string.wifi_cancel), mListener);
|
||||
|
||||
if (mWifiConfig != null) {
|
||||
mSsid.setText(mWifiConfig.SSID);
|
||||
if (mWifiConfig.apBand == 0) {
|
||||
mBandIndex = 0;
|
||||
} else {
|
||||
mBandIndex = 1;
|
||||
}
|
||||
|
||||
mSecurity.setSelection(mSecurityTypeIndex);
|
||||
if (mSecurityTypeIndex == WPA2_INDEX) {
|
||||
mPassword.setText(mWifiConfig.preSharedKey);
|
||||
}
|
||||
}
|
||||
|
||||
mChannel.setAdapter(channelAdapter);
|
||||
mChannel.setOnItemSelectedListener(
|
||||
new AdapterView.OnItemSelectedListener() {
|
||||
boolean mInit = true;
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int position,
|
||||
long id) {
|
||||
if (!mInit) {
|
||||
mBandIndex = position;
|
||||
mWifiConfig.apBand = mBandIndex;
|
||||
Log.i(TAG, "config on channelIndex : " + mBandIndex + " Band: " +
|
||||
mWifiConfig.apBand);
|
||||
} else {
|
||||
mInit = false;
|
||||
mChannel.setSelection(mBandIndex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> adapterView) {
|
||||
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
mSsid.addTextChangedListener(this);
|
||||
mPassword.addTextChangedListener(this);
|
||||
((CheckBox) mView.findViewById(R.id.show_password)).setOnClickListener(this);
|
||||
mSecurity.setOnItemSelectedListener(this);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
showSecurityFields();
|
||||
validate();
|
||||
}
|
||||
|
||||
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
mPassword.setInputType(
|
||||
InputType.TYPE_CLASS_TEXT |
|
||||
(((CheckBox) mView.findViewById(R.id.show_password)).isChecked() ?
|
||||
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD :
|
||||
InputType.TYPE_TEXT_VARIATION_PASSWORD));
|
||||
}
|
||||
|
||||
private void validate() {
|
||||
String mSsidString = mSsid.getText().toString();
|
||||
if ((mSsid != null && mSsid.length() == 0)
|
||||
|| ((mSecurityTypeIndex == WPA2_INDEX) && mPassword.length() < 8)
|
||||
|| (mSsid != null &&
|
||||
Charset.forName("UTF-8").encode(mSsidString).limit() > 32)) {
|
||||
getButton(BUTTON_SUBMIT).setEnabled(false);
|
||||
} else {
|
||||
getButton(BUTTON_SUBMIT).setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
mPassword.setInputType(
|
||||
InputType.TYPE_CLASS_TEXT | (((CheckBox) view).isChecked() ?
|
||||
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD :
|
||||
InputType.TYPE_TEXT_VARIATION_PASSWORD));
|
||||
}
|
||||
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
public void afterTextChanged(Editable editable) {
|
||||
validate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
mSecurityTypeIndex = position;
|
||||
showSecurityFields();
|
||||
validate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
|
||||
private void showSecurityFields() {
|
||||
if (mSecurityTypeIndex == OPEN_INDEX) {
|
||||
mView.findViewById(R.id.fields).setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
mView.findViewById(R.id.fields).setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
@@ -1,188 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.text.BidiFormatter;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.datausage.DataSaverBackend;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @deprecated in favor of WifiTetherPreferenceController and WifiTetherSettings
|
||||
*/
|
||||
@Deprecated
|
||||
public class WifiApEnabler {
|
||||
private final Context mContext;
|
||||
private final SwitchPreference mSwitch;
|
||||
private final CharSequence mOriginalSummary;
|
||||
private final DataSaverBackend mDataSaverBackend;
|
||||
|
||||
private WifiManager mWifiManager;
|
||||
private final IntentFilter mIntentFilter;
|
||||
|
||||
ConnectivityManager mCm;
|
||||
private String[] mWifiRegexs;
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (WifiManager.WIFI_AP_STATE_CHANGED_ACTION.equals(action)) {
|
||||
int state = intent.getIntExtra(
|
||||
WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_FAILED);
|
||||
if (state == WifiManager.WIFI_AP_STATE_FAILED) {
|
||||
int reason = intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_FAILURE_REASON,
|
||||
WifiManager.SAP_START_FAILURE_GENERAL);
|
||||
handleWifiApStateChanged(state, reason);
|
||||
} else {
|
||||
handleWifiApStateChanged(state, WifiManager.SAP_START_FAILURE_GENERAL);
|
||||
}
|
||||
} else if (ConnectivityManager.ACTION_TETHER_STATE_CHANGED.equals(action)) {
|
||||
ArrayList<String> available = intent.getStringArrayListExtra(
|
||||
ConnectivityManager.EXTRA_AVAILABLE_TETHER);
|
||||
ArrayList<String> active = intent.getStringArrayListExtra(
|
||||
ConnectivityManager.EXTRA_ACTIVE_TETHER);
|
||||
ArrayList<String> errored = intent.getStringArrayListExtra(
|
||||
ConnectivityManager.EXTRA_ERRORED_TETHER);
|
||||
updateTetherState(available.toArray(), active.toArray(), errored.toArray());
|
||||
} else if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(action)) {
|
||||
enableWifiSwitch();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public WifiApEnabler(Context context, DataSaverBackend dataSaverBackend,
|
||||
SwitchPreference switchPreference) {
|
||||
mContext = context;
|
||||
mDataSaverBackend = dataSaverBackend;
|
||||
mSwitch = switchPreference;
|
||||
mOriginalSummary = switchPreference.getSummary();
|
||||
switchPreference.setPersistent(false);
|
||||
|
||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
mCm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
mWifiRegexs = mCm.getTetherableWifiRegexs();
|
||||
|
||||
mIntentFilter = new IntentFilter(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
||||
mIntentFilter.addAction(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
|
||||
mIntentFilter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
|
||||
}
|
||||
|
||||
public void resume() {
|
||||
mContext.registerReceiver(mReceiver, mIntentFilter);
|
||||
enableWifiSwitch();
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
mContext.unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
private void enableWifiSwitch() {
|
||||
boolean isAirplaneMode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
|
||||
if(!isAirplaneMode) {
|
||||
mSwitch.setEnabled(!mDataSaverBackend.isDataSaverEnabled());
|
||||
} else {
|
||||
mSwitch.setSummary(mOriginalSummary);
|
||||
mSwitch.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConfigSummary(WifiConfiguration wifiConfig) {
|
||||
String s = mContext.getString(
|
||||
com.android.internal.R.string.wifi_tether_configure_ssid_default);
|
||||
|
||||
mSwitch.setSummary(mContext.getString(R.string.wifi_tether_enabled_subtext,
|
||||
BidiFormatter.getInstance().unicodeWrap(
|
||||
(wifiConfig == null) ? s : wifiConfig.SSID)));
|
||||
}
|
||||
|
||||
private void updateTetherState(Object[] available, Object[] tethered, Object[] errored) {
|
||||
boolean wifiTethered = false;
|
||||
boolean wifiErrored = false;
|
||||
|
||||
for (Object o : tethered) {
|
||||
String s = (String)o;
|
||||
for (String regex : mWifiRegexs) {
|
||||
if (s.matches(regex)) wifiTethered = true;
|
||||
}
|
||||
}
|
||||
for (Object o: errored) {
|
||||
String s = (String)o;
|
||||
for (String regex : mWifiRegexs) {
|
||||
if (s.matches(regex)) wifiErrored = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (wifiTethered) {
|
||||
WifiConfiguration wifiConfig = mWifiManager.getWifiApConfiguration();
|
||||
updateConfigSummary(wifiConfig);
|
||||
} else if (wifiErrored) {
|
||||
mSwitch.setSummary(R.string.wifi_error);
|
||||
} else {
|
||||
mSwitch.setSummary(R.string.wifi_hotspot_off_subtext);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleWifiApStateChanged(int state, int reason) {
|
||||
switch (state) {
|
||||
case WifiManager.WIFI_AP_STATE_ENABLING:
|
||||
mSwitch.setSummary(R.string.wifi_tether_starting);
|
||||
mSwitch.setEnabled(false);
|
||||
break;
|
||||
case WifiManager.WIFI_AP_STATE_ENABLED:
|
||||
/**
|
||||
* Summary on enable is handled by tether
|
||||
* broadcast notice
|
||||
*/
|
||||
mSwitch.setChecked(true);
|
||||
/* Doesnt need the airplane check */
|
||||
mSwitch.setEnabled(!mDataSaverBackend.isDataSaverEnabled());
|
||||
break;
|
||||
case WifiManager.WIFI_AP_STATE_DISABLING:
|
||||
mSwitch.setSummary(R.string.wifi_tether_stopping);
|
||||
mSwitch.setChecked(false);
|
||||
mSwitch.setEnabled(false);
|
||||
break;
|
||||
case WifiManager.WIFI_AP_STATE_DISABLED:
|
||||
mSwitch.setChecked(false);
|
||||
mSwitch.setSummary(mOriginalSummary);
|
||||
enableWifiSwitch();
|
||||
break;
|
||||
default:
|
||||
mSwitch.setChecked(false);
|
||||
if (reason == WifiManager.SAP_START_FAILURE_NO_CHANNEL) {
|
||||
mSwitch.setSummary(R.string.wifi_sap_no_channel_error);
|
||||
} else {
|
||||
mSwitch.setSummary(R.string.wifi_error);
|
||||
}
|
||||
enableWifiSwitch();
|
||||
}
|
||||
}
|
||||
}
|
@@ -73,7 +73,6 @@ public class WifiTetherPreferenceController extends AbstractPreferenceController
|
||||
public boolean isAvailable() {
|
||||
return mWifiRegexs != null
|
||||
&& mWifiRegexs.length != 0
|
||||
&& WifiTetherSettings.isTetherSettingPageEnabled()
|
||||
&& !Utils.isMonkeyRunning();
|
||||
}
|
||||
|
||||
|
@@ -26,7 +26,6 @@ import android.content.IntentFilter;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemProperties;
|
||||
import android.os.UserManager;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.Log;
|
||||
@@ -44,10 +43,6 @@ import java.util.List;
|
||||
public class WifiTetherSettings extends RestrictedDashboardFragment
|
||||
implements WifiTetherBasePreferenceController.OnTetherConfigUpdateListener {
|
||||
|
||||
public static boolean isTetherSettingPageEnabled() {
|
||||
return SystemProperties.getBoolean("settings.ui.wifi.tether.enabled", true);
|
||||
}
|
||||
|
||||
private static final IntentFilter TETHER_STATE_CHANGE_FILTER;
|
||||
|
||||
private WifiTetherSwitchBarController mSwitchBarController;
|
||||
|
Reference in New Issue
Block a user