diff --git a/res/values/strings.xml b/res/values/strings.xml
index b6cb2fad694..646c038d00d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1374,9 +1374,9 @@
Set up voicemail, call forwarding, call waiting, caller ID
- Tethering settings
+ Tethering
- Set up and manage tethering
+ Set up & manage tethering
Tethering settings
@@ -1385,15 +1385,23 @@
USB
USB tethering
- USB connected, select to tether
+ USB connected, check to tether
- Connected, select to disconnect
+ Tethered
- Tethering disabled (USB storage is in use)
+ Can\'t tether when USB storage in use
USB not connected
- USB tethering has had a problem.
+ USB tethering error
+
+
+ Tethering help
+
+
+ Tethering active
+
+ Touch to configure
Mobile networks
diff --git a/res/xml/tether_prefs.xml b/res/xml/tether_prefs.xml
index aefe6d36e0a..bdf693f075a 100644
--- a/res/xml/tether_prefs.xml
+++ b/res/xml/tether_prefs.xml
@@ -17,21 +17,10 @@
-
-
-
-
-
-
-
+
errored = intent.getStringArrayListExtra(
ConnectivityManager.EXTRA_ERRORED_TETHER);
- updateState(available, active, errored);
+ updateState(available.toArray(), active.toArray(), errored.toArray());
}
}
@@ -119,26 +119,52 @@ public class TetherSettings extends PreferenceActivity {
mWifiApEnabler.pause();
}
- private void updateState(ArrayList available, ArrayList tethered,
- ArrayList errored) {
+ private void updateState() {
+ ConnectivityManager cm =
+ (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
+
+ String[] available = cm.getTetherableIfaces();
+ String[] tethered = cm.getTetheredIfaces();
+ String[] errored = cm.getTetheringErroredIfaces();
+ updateState(available, tethered, errored);
+ }
+
+ private void updateState(Object[] available, Object[] tethered,
+ Object[] errored) {
+ ConnectivityManager cm =
+ (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
boolean usbTethered = false;
boolean usbAvailable = false;
+ int usbError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
boolean usbErrored = false;
boolean wifiTethered = false;
boolean wifiAvailable = false;
+ int wifiError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
boolean massStorageActive =
Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
boolean wifiErrored = false;
- for (String s : available) {
+ for (Object o : available) {
+ String s = (String)o;
for (String regex : mUsbRegexs) {
- if (s.matches(regex)) usbAvailable = true;
+ if (s.matches(regex)) {
+ usbAvailable = true;
+ if (usbError == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
+ usbError = cm.getLastTetherError(s);
+ }
+ }
}
for (String regex : mWifiRegexs) {
- if (s.matches(regex)) wifiAvailable = true;
+ if (s.matches(regex)) {
+ wifiAvailable = true;
+ if (wifiError == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
+ wifiError = cm.getLastTetherError(s);
+ }
+ }
}
}
- for (String s : tethered) {
+ for (Object o : tethered) {
+ String s = (String)o;
for (String regex : mUsbRegexs) {
if (s.matches(regex)) usbTethered = true;
}
@@ -146,7 +172,8 @@ public class TetherSettings extends PreferenceActivity {
if (s.matches(regex)) wifiTethered = true;
}
}
- for (String s: errored) {
+ for (Object o: errored) {
+ String s = (String)o;
for (String regex : mUsbRegexs) {
if (s.matches(regex)) usbErrored = true;
}
@@ -155,6 +182,9 @@ public class TetherSettings extends PreferenceActivity {
}
}
+ if (usbTethered || wifiTethered) {
+// showTetheredNotification();
+ }
if (usbTethered) {
mUsbTether.setSummary(R.string.usb_tethering_active_subtext);
mUsbTether.setEnabled(true);
@@ -162,7 +192,11 @@ public class TetherSettings extends PreferenceActivity {
mUsbTether.setSummary(R.string.usb_tethering_storage_active_subtext);
mUsbTether.setEnabled(false);
} else if (usbAvailable) {
- mUsbTether.setSummary(R.string.usb_tethering_available_subtext);
+ if (usbError == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
+ mUsbTether.setSummary(R.string.usb_tethering_available_subtext);
+ } else {
+ mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
+ }
mUsbTether.setEnabled(true);
} else if (usbErrored) {
mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
@@ -172,4 +206,93 @@ public class TetherSettings extends PreferenceActivity {
mUsbTether.setEnabled(false);
}
}
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+ if (preference == mUsbTether) {
+ boolean newState = mUsbTether.isChecked();
+
+ ConnectivityManager cm =
+ (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
+
+ if (newState) {
+ String[] available = cm.getTetherableIfaces();
+
+ String usbIface = findIface(available, mUsbRegexs);
+ if (usbIface == null) {
+ updateState();
+ return true;
+ }
+ if (cm.tether(usbIface) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
+ mUsbTether.setChecked(false);
+ mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
+ return true;
+ }
+ mUsbTether.setSummary("");
+ } else {
+ String [] tethered = cm.getTetheredIfaces();
+
+ String usbIface = findIface(tethered, mUsbRegexs);
+ if (usbIface == null) {
+ updateState();
+ return true;
+ }
+ if (cm.untether(usbIface) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
+ mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
+ return true;
+ }
+ mUsbTether.setSummary("");
+ }
+ }
+ return false;
+ }
+
+ private String findIface(String[] ifaces, String[] regexes) {
+ for (String iface : ifaces) {
+ for (String regex : regexes) {
+ if (iface.matches(regex)) {
+ return iface;
+ }
+ }
+ }
+ return null;
+ }
+
+// private showTetheredNotification() {
+// NotificationManager notificationManager = (NotificationManager)mContext.
+// getSystemService(Context.NOTIFICATION_SERVICE);
+// if (notificationManager == null) {
+// return;
+// }
+//
+// Intent intent = new Intent();
+//
+// PendingIntent pi = PendingIntent.getActivity(mContext, 0, intent, 0);
+//
+// Resources r = Resources.getSystem();
+// CharSequence title = r.getText(com.android.internal.R.string.
+// tether_stop_notification_title);
+// CharSequence message = r.getText(com.android.internal.R.string.
+// tether_stop_notification_message);
+//
+// if(mTetheringNotification == null) {
+// mTetheringNotification = new Notification();
+// mTetheringNotification.when = 0;
+// }
+// mTetheringNotification.icon = com.android.internal.R.drawable.stat_sys_tether_usb;
+//
+// boolean playSounds = false;
+// //playSounds = SystemProperties.get("persist.service.mount.playsnd", "1").equals("1");
+// if (playSounds) {
+// mTetheringNotification.defaults |= Notification.DEFAULT_SOUND;
+// } else {
+// mTetheringNotification.defaults &= ~Notification.DEFAULT_SOUND;
+// }
+// mTetheringNotification.flags = Notification.FLAG_ONGOING_EVENT;
+// mTetheringNotification.tickerText = title;
+// mTetheringNotification.setLatestEventInfo(mContext, title, message, pi);
+//
+// notificationManager.notify(mTetheringNotification.icon, mTetheringNotification);
+// }
+
}