Move status update to WifiApEnabler
Bug: 2528202 Change-Id: I093699ac171279af9df5f3b3b4ae359aab79088b
This commit is contained in:
@@ -26,8 +26,6 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.net.wifi.WifiConfiguration;
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
@@ -56,7 +54,6 @@ public class TetherSettings extends PreferenceActivity {
|
|||||||
private PreferenceScreen mWifiApSettings;
|
private PreferenceScreen mWifiApSettings;
|
||||||
private WifiApEnabler mWifiApEnabler;
|
private WifiApEnabler mWifiApEnabler;
|
||||||
private PreferenceScreen mTetherHelp;
|
private PreferenceScreen mTetherHelp;
|
||||||
private WifiManager mWifiManager;
|
|
||||||
|
|
||||||
private BroadcastReceiver mTetherChangeReceiver;
|
private BroadcastReceiver mTetherChangeReceiver;
|
||||||
|
|
||||||
@@ -64,7 +61,6 @@ public class TetherSettings extends PreferenceActivity {
|
|||||||
private ArrayList mUsbIfaces;
|
private ArrayList mUsbIfaces;
|
||||||
|
|
||||||
private String[] mWifiRegexs;
|
private String[] mWifiRegexs;
|
||||||
private ArrayList mWifiIfaces;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle icicle) {
|
protected void onCreate(Bundle icicle) {
|
||||||
@@ -79,7 +75,6 @@ public class TetherSettings extends PreferenceActivity {
|
|||||||
|
|
||||||
ConnectivityManager cm =
|
ConnectivityManager cm =
|
||||||
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
mWifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
|
|
||||||
|
|
||||||
mUsbRegexs = cm.getTetherableUsbRegexs();
|
mUsbRegexs = cm.getTetherableUsbRegexs();
|
||||||
if (mUsbRegexs.length == 0) {
|
if (mUsbRegexs.length == 0) {
|
||||||
@@ -157,12 +152,8 @@ public class TetherSettings extends PreferenceActivity {
|
|||||||
boolean usbAvailable = false;
|
boolean usbAvailable = false;
|
||||||
int usbError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
int usbError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
||||||
boolean usbErrored = false;
|
boolean usbErrored = false;
|
||||||
boolean wifiTethered = false;
|
|
||||||
boolean wifiAvailable = false;
|
|
||||||
int wifiError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
|
||||||
boolean massStorageActive =
|
boolean massStorageActive =
|
||||||
Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
|
Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
|
||||||
boolean wifiErrored = false;
|
|
||||||
for (Object o : available) {
|
for (Object o : available) {
|
||||||
String s = (String)o;
|
String s = (String)o;
|
||||||
for (String regex : mUsbRegexs) {
|
for (String regex : mUsbRegexs) {
|
||||||
@@ -173,32 +164,18 @@ public class TetherSettings extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String regex : mWifiRegexs) {
|
|
||||||
if (s.matches(regex)) {
|
|
||||||
wifiAvailable = true;
|
|
||||||
if (wifiError == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
|
|
||||||
wifiError = cm.getLastTetherError(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (Object o : tethered) {
|
for (Object o : tethered) {
|
||||||
String s = (String)o;
|
String s = (String)o;
|
||||||
for (String regex : mUsbRegexs) {
|
for (String regex : mUsbRegexs) {
|
||||||
if (s.matches(regex)) usbTethered = true;
|
if (s.matches(regex)) usbTethered = true;
|
||||||
}
|
}
|
||||||
for (String regex : mWifiRegexs) {
|
|
||||||
if (s.matches(regex)) wifiTethered = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (Object o: errored) {
|
for (Object o: errored) {
|
||||||
String s = (String)o;
|
String s = (String)o;
|
||||||
for (String regex : mUsbRegexs) {
|
for (String regex : mUsbRegexs) {
|
||||||
if (s.matches(regex)) usbErrored = true;
|
if (s.matches(regex)) usbErrored = true;
|
||||||
}
|
}
|
||||||
for (String regex : mWifiRegexs) {
|
|
||||||
if (s.matches(regex)) wifiErrored = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (usbTethered) {
|
if (usbTethered) {
|
||||||
@@ -226,17 +203,6 @@ public class TetherSettings extends PreferenceActivity {
|
|||||||
mUsbTether.setEnabled(false);
|
mUsbTether.setEnabled(false);
|
||||||
mUsbTether.setChecked(false);
|
mUsbTether.setChecked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wifiTethered) {
|
|
||||||
WifiConfiguration mWifiConfig = mWifiManager.getWifiApConfiguration();
|
|
||||||
String s = getString(com.android.internal.R.string.wifi_tether_configure_ssid_default);
|
|
||||||
mEnableWifiAp.setSummary(String.format(getString(R.string.wifi_tether_enabled_subtext),
|
|
||||||
(mWifiConfig == null) ? s : mWifiConfig.SSID));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wifiErrored) {
|
|
||||||
mEnableWifiAp.setSummary(R.string.wifi_error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -19,13 +19,17 @@ package com.android.settings.wifi;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.WirelessSettings;
|
import com.android.settings.WirelessSettings;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.BroadcastReceiver;
|
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.content.IntentFilter;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.wifi.SupplicantState;
|
import android.net.wifi.SupplicantState;
|
||||||
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
@@ -43,6 +47,9 @@ public class WifiApEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
private WifiManager mWifiManager;
|
private WifiManager mWifiManager;
|
||||||
private final IntentFilter mIntentFilter;
|
private final IntentFilter mIntentFilter;
|
||||||
|
|
||||||
|
ConnectivityManager mCm;
|
||||||
|
private String[] mWifiRegexs;
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@@ -50,7 +57,16 @@ public class WifiApEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
if (WifiManager.WIFI_AP_STATE_CHANGED_ACTION.equals(action)) {
|
if (WifiManager.WIFI_AP_STATE_CHANGED_ACTION.equals(action)) {
|
||||||
handleWifiApStateChanged(intent.getIntExtra(
|
handleWifiApStateChanged(intent.getIntExtra(
|
||||||
WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_FAILED));
|
WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_FAILED));
|
||||||
|
} 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,7 +77,12 @@ public class WifiApEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
checkBox.setPersistent(false);
|
checkBox.setPersistent(false);
|
||||||
|
|
||||||
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
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 = new IntentFilter(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
||||||
|
mIntentFilter.addAction(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resume() {
|
public void resume() {
|
||||||
@@ -86,6 +107,34 @@ public class WifiApEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 mWifiConfig = mWifiManager.getWifiApConfiguration();
|
||||||
|
String s = mContext.getString(
|
||||||
|
com.android.internal.R.string.wifi_tether_configure_ssid_default);
|
||||||
|
mCheckBox.setSummary(String.format(
|
||||||
|
mContext.getString(R.string.wifi_tether_enabled_subtext),
|
||||||
|
(mWifiConfig == null) ? s : mWifiConfig.SSID));
|
||||||
|
} else if (wifiErrored) {
|
||||||
|
mCheckBox.setSummary(R.string.wifi_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void handleWifiApStateChanged(int state) {
|
private void handleWifiApStateChanged(int state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
Reference in New Issue
Block a user