Refactor to remove multiple in-loop Object[]->String[] castings

(This replaces Iaa0f3b25eaadb094a4c3fb4cecbd09e0322aae33)

This change removes the need to convert Object[]->String[] for each iteration
of each of available,tethered,errored states in updateStatus()
by converting these as soon as possible.

This fix (and the code before) is strange because each of available,tethered,
errored are defined as type ArrayList<String> but
intent.getStringArrayListExtra() returns type Object[] dispite its name.
Because other calls to updateState() use String[] it seems best to do the
conversion outside this method in the Object[] case and thus avoid the
per-iteration casting in the Object[] case and the downright wasteful
per-iteration String[]->Object[]->String[] casting in the String[] input cases.

I've also removed some unused imports and an unused variable.

Change-Id: I805ef19aa9ceff7e4fc491623cdcb413ce170798
This commit is contained in:
Ben Clark
2010-07-27 16:20:59 +01:00
parent 46c0a5b129
commit 0008d219a2

View File

@@ -21,7 +21,6 @@ import com.android.settings.wifi.WifiApEnabler;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemProperties;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -33,8 +32,6 @@ 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.provider.Settings;
import android.util.Log;
import android.webkit.WebView; import android.webkit.WebView;
import java.io.InputStream; import java.io.InputStream;
@@ -67,7 +64,6 @@ public class TetherSettings extends PreferenceActivity {
private BroadcastReceiver mTetherChangeReceiver; private BroadcastReceiver mTetherChangeReceiver;
private String[] mUsbRegexs; private String[] mUsbRegexs;
private ArrayList mUsbIfaces;
private String[] mWifiRegexs; private String[] mWifiRegexs;
@@ -161,7 +157,8 @@ public class TetherSettings extends PreferenceActivity {
ConnectivityManager.EXTRA_ACTIVE_TETHER); ConnectivityManager.EXTRA_ACTIVE_TETHER);
ArrayList<String> errored = intent.getStringArrayListExtra( ArrayList<String> errored = intent.getStringArrayListExtra(
ConnectivityManager.EXTRA_ERRORED_TETHER); ConnectivityManager.EXTRA_ERRORED_TETHER);
updateState(available.toArray(), active.toArray(), errored.toArray()); updateState((String[]) available.toArray(), (String[]) active.toArray(),
(String[]) errored.toArray());
} else if (intent.getAction().equals(Intent.ACTION_MEDIA_SHARED) || } else if (intent.getAction().equals(Intent.ACTION_MEDIA_SHARED) ||
intent.getAction().equals(Intent.ACTION_MEDIA_UNSHARED)) { intent.getAction().equals(Intent.ACTION_MEDIA_UNSHARED)) {
updateState(); updateState();
@@ -205,8 +202,8 @@ public class TetherSettings extends PreferenceActivity {
updateState(available, tethered, errored); updateState(available, tethered, errored);
} }
private void updateState(Object[] available, Object[] tethered, private void updateState(String[] available, String[] tethered,
Object[] errored) { String[] errored) {
ConnectivityManager cm = ConnectivityManager cm =
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
boolean usbTethered = false; boolean usbTethered = false;
@@ -215,8 +212,7 @@ public class TetherSettings extends PreferenceActivity {
boolean usbErrored = false; boolean usbErrored = false;
boolean massStorageActive = boolean massStorageActive =
Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState()); Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
for (Object o : available) { for (String s : available) {
String s = (String)o;
for (String regex : mUsbRegexs) { for (String regex : mUsbRegexs) {
if (s.matches(regex)) { if (s.matches(regex)) {
usbAvailable = true; usbAvailable = true;
@@ -226,14 +222,12 @@ public class TetherSettings extends PreferenceActivity {
} }
} }
} }
for (Object o : tethered) { for (String s : 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;
} }
} }
for (Object o: errored) { for (String s: 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;
} }