Update Tethering UI
Finalizing some strings and changing the error handling.
This commit is contained in:
@@ -1374,9 +1374,9 @@
|
|||||||
<string name="call_settings_summary">Set up voicemail, call forwarding, call waiting, caller ID</string>
|
<string name="call_settings_summary">Set up voicemail, call forwarding, call waiting, caller ID</string>
|
||||||
|
|
||||||
<!-- Tethering controls, item title to go into the tethering settings -->
|
<!-- Tethering controls, item title to go into the tethering settings -->
|
||||||
<string name="tether_settings_title">Tethering settings</string>
|
<string name="tether_settings_title">Tethering</string>
|
||||||
<!-- Tethering controls, the item summary for the user to go into the tethering settings -->
|
<!-- Tethering controls, the item summary for the user to go into the tethering settings -->
|
||||||
<string name="tether_settings_summary">Set up and manage tethering</string>
|
<string name="tether_settings_summary">Set up & manage tethering</string>
|
||||||
|
|
||||||
<!-- Title of the screen for adjusting tethering settings -->
|
<!-- Title of the screen for adjusting tethering settings -->
|
||||||
<string name="tether_screen_title">Tethering settings</string>
|
<string name="tether_screen_title">Tethering settings</string>
|
||||||
@@ -1385,15 +1385,23 @@
|
|||||||
<string name="usb_title">USB</string>
|
<string name="usb_title">USB</string>
|
||||||
<string name="usb_tethering_button_text">USB tethering</string>
|
<string name="usb_tethering_button_text">USB tethering</string>
|
||||||
<!-- USB available subtext - shown when USB is connected but not currently being tethered -->
|
<!-- USB available subtext - shown when USB is connected but not currently being tethered -->
|
||||||
<string name="usb_tethering_available_subtext">USB connected, select to tether</string>
|
<string name="usb_tethering_available_subtext">USB connected, check to tether</string>
|
||||||
<!-- USB tethered subtext - shown when USB is connected and being tethered -->
|
<!-- USB tethered subtext - shown when USB is connected and being tethered -->
|
||||||
<string name="usb_tethering_active_subtext">Connected, select to disconnect</string>
|
<string name="usb_tethering_active_subtext">Tethered</string>
|
||||||
<!-- USB storage subtext - shown when tethering is disabled because USB storage is active -->
|
<!-- USB storage subtext - shown when tethering is disabled because USB storage is active -->
|
||||||
<string name="usb_tethering_storage_active_subtext">Tethering disabled (USB storage is in use)</string>
|
<string name="usb_tethering_storage_active_subtext">Can\'t tether when USB storage in use</string>
|
||||||
<!-- USB unavailable subtext - shown when USB is not connected -->
|
<!-- USB unavailable subtext - shown when USB is not connected -->
|
||||||
<string name="usb_tethering_unavailable_subtext">USB not connected</string>
|
<string name="usb_tethering_unavailable_subtext">USB not connected</string>
|
||||||
<!-- USB errored subtext - shown when USB is broken for some reason -->
|
<!-- USB errored subtext - shown when USB is broken for some reason -->
|
||||||
<string name="usb_tethering_errored_subtext">USB tethering has had a problem.</string>
|
<string name="usb_tethering_errored_subtext">USB tethering error</string>
|
||||||
|
|
||||||
|
<!-- Thethering help button - calls up a web view with general tethering info -->
|
||||||
|
<string name="tethering_help_button_text">Tethering help</string>
|
||||||
|
|
||||||
|
<!-- Tethered notification text - shown in the notification bar when tethering is active -->
|
||||||
|
<string name="tethered_notifcation_title">Tethering active</string>
|
||||||
|
<!-- Tethered notification message - shown under the notification title -->
|
||||||
|
<string name="tethered_notification_message">Touch to configure</string>
|
||||||
|
|
||||||
<!-- Wireless controls, item title to go into the network settings -->
|
<!-- Wireless controls, item title to go into the network settings -->
|
||||||
<string name="network_settings_title">Mobile networks</string>
|
<string name="network_settings_title">Mobile networks</string>
|
||||||
|
@@ -17,21 +17,10 @@
|
|||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:title="@string/tether_screen_title">
|
android:title="@string/tether_screen_title">
|
||||||
|
|
||||||
<PreferenceCategory
|
<CheckBoxPreference
|
||||||
android:key="usb_category"
|
android:key="usb_tether_settings"
|
||||||
android:title="@string/usb_title">
|
android:title="@string/usb_tethering_button_text"
|
||||||
|
android:persistent="false" />
|
||||||
<PreferenceScreen
|
|
||||||
android:key="usb_tether_settings"
|
|
||||||
android:title="@string/usb_tethering_button_text"
|
|
||||||
android:widgetLayout="@*android:layout/preference_dialog" >
|
|
||||||
<intent
|
|
||||||
android:action="android.intent.action.MAIN"
|
|
||||||
android:targetPackage="android"
|
|
||||||
android:targetClass="com.android.internal.app.TetherActivity" />
|
|
||||||
</PreferenceScreen>
|
|
||||||
|
|
||||||
</PreferenceCategory>
|
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="wifi_category"
|
android:key="wifi_category"
|
||||||
|
@@ -26,10 +26,10 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.preference.CheckBoxPreference;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ public class TetherSettings extends PreferenceActivity {
|
|||||||
private static final String ENABLE_WIFI_AP = "enable_wifi_ap";
|
private static final String ENABLE_WIFI_AP = "enable_wifi_ap";
|
||||||
private static final String WIFI_AP_SETTINGS = "wifi_ap_settings";
|
private static final String WIFI_AP_SETTINGS = "wifi_ap_settings";
|
||||||
|
|
||||||
private PreferenceScreen mUsbTether;
|
private CheckBoxPreference mUsbTether;
|
||||||
|
|
||||||
private CheckBoxPreference mEnableWifiAp;
|
private CheckBoxPreference mEnableWifiAp;
|
||||||
private PreferenceScreen mWifiApSettings;
|
private PreferenceScreen mWifiApSettings;
|
||||||
@@ -63,9 +63,9 @@ public class TetherSettings extends PreferenceActivity {
|
|||||||
|
|
||||||
addPreferencesFromResource(R.xml.tether_prefs);
|
addPreferencesFromResource(R.xml.tether_prefs);
|
||||||
|
|
||||||
mUsbTether = (PreferenceScreen) findPreference(USB_TETHER_SETTINGS);
|
|
||||||
mEnableWifiAp = (CheckBoxPreference) findPreference(ENABLE_WIFI_AP);
|
mEnableWifiAp = (CheckBoxPreference) findPreference(ENABLE_WIFI_AP);
|
||||||
mWifiApSettings = (PreferenceScreen) findPreference(WIFI_AP_SETTINGS);
|
mWifiApSettings = (PreferenceScreen) findPreference(WIFI_AP_SETTINGS);
|
||||||
|
mUsbTether = (CheckBoxPreference) findPreference(USB_TETHER_SETTINGS);
|
||||||
|
|
||||||
ConnectivityManager cm =
|
ConnectivityManager cm =
|
||||||
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
@@ -93,7 +93,7 @@ public class TetherSettings extends PreferenceActivity {
|
|||||||
ArrayList<String> errored = intent.getStringArrayListExtra(
|
ArrayList<String> errored = intent.getStringArrayListExtra(
|
||||||
ConnectivityManager.EXTRA_ERRORED_TETHER);
|
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();
|
mWifiApEnabler.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateState(ArrayList<String> available, ArrayList<String> tethered,
|
private void updateState() {
|
||||||
ArrayList<String> errored) {
|
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 usbTethered = false;
|
||||||
boolean usbAvailable = false;
|
boolean usbAvailable = false;
|
||||||
|
int usbError = ConnectivityManager.TETHER_ERROR_NO_ERROR;
|
||||||
boolean usbErrored = false;
|
boolean usbErrored = false;
|
||||||
boolean wifiTethered = false;
|
boolean wifiTethered = false;
|
||||||
boolean wifiAvailable = 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;
|
boolean wifiErrored = false;
|
||||||
|
|
||||||
for (String s : available) {
|
for (Object o : available) {
|
||||||
|
String s = (String)o;
|
||||||
for (String regex : mUsbRegexs) {
|
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) {
|
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) {
|
for (String regex : mUsbRegexs) {
|
||||||
if (s.matches(regex)) usbTethered = true;
|
if (s.matches(regex)) usbTethered = true;
|
||||||
}
|
}
|
||||||
@@ -146,7 +172,8 @@ public class TetherSettings extends PreferenceActivity {
|
|||||||
if (s.matches(regex)) wifiTethered = true;
|
if (s.matches(regex)) wifiTethered = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String s: errored) {
|
for (Object o: errored) {
|
||||||
|
String s = (String)o;
|
||||||
for (String regex : mUsbRegexs) {
|
for (String regex : mUsbRegexs) {
|
||||||
if (s.matches(regex)) usbErrored = true;
|
if (s.matches(regex)) usbErrored = true;
|
||||||
}
|
}
|
||||||
@@ -155,6 +182,9 @@ public class TetherSettings extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (usbTethered || wifiTethered) {
|
||||||
|
// showTetheredNotification();
|
||||||
|
}
|
||||||
if (usbTethered) {
|
if (usbTethered) {
|
||||||
mUsbTether.setSummary(R.string.usb_tethering_active_subtext);
|
mUsbTether.setSummary(R.string.usb_tethering_active_subtext);
|
||||||
mUsbTether.setEnabled(true);
|
mUsbTether.setEnabled(true);
|
||||||
@@ -162,7 +192,11 @@ public class TetherSettings extends PreferenceActivity {
|
|||||||
mUsbTether.setSummary(R.string.usb_tethering_storage_active_subtext);
|
mUsbTether.setSummary(R.string.usb_tethering_storage_active_subtext);
|
||||||
mUsbTether.setEnabled(false);
|
mUsbTether.setEnabled(false);
|
||||||
} else if (usbAvailable) {
|
} 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);
|
mUsbTether.setEnabled(true);
|
||||||
} else if (usbErrored) {
|
} else if (usbErrored) {
|
||||||
mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
|
mUsbTether.setSummary(R.string.usb_tethering_errored_subtext);
|
||||||
@@ -172,4 +206,93 @@ public class TetherSettings extends PreferenceActivity {
|
|||||||
mUsbTether.setEnabled(false);
|
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);
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user