summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
46c0a5b)
(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
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
-import android.os.SystemProperties;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
-import android.provider.Settings;
-import android.util.Log;
import android.webkit.WebView;
import java.io.InputStream;
import android.webkit.WebView;
import java.io.InputStream;
private BroadcastReceiver mTetherChangeReceiver;
private String[] mUsbRegexs;
private BroadcastReceiver mTetherChangeReceiver;
private String[] mUsbRegexs;
- private ArrayList mUsbIfaces;
private String[] mWifiRegexs;
private String[] mWifiRegexs;
ConnectivityManager.EXTRA_ACTIVE_TETHER);
ArrayList<String> errored = intent.getStringArrayListExtra(
ConnectivityManager.EXTRA_ERRORED_TETHER);
ConnectivityManager.EXTRA_ACTIVE_TETHER);
ArrayList<String> errored = intent.getStringArrayListExtra(
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) ||
intent.getAction().equals(Intent.ACTION_MEDIA_UNSHARED)) {
updateState();
} else if (intent.getAction().equals(Intent.ACTION_MEDIA_SHARED) ||
intent.getAction().equals(Intent.ACTION_MEDIA_UNSHARED)) {
updateState();
updateState(available, tethered, errored);
}
updateState(available, tethered, errored);
}
- private void updateState(Object[] available, Object[] tethered,
- Object[] errored) {
+ private void updateState(String[] available, String[] tethered,
+ String[] errored) {
ConnectivityManager cm =
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
boolean usbTethered = false;
ConnectivityManager cm =
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
boolean usbTethered = false;
boolean usbErrored = false;
boolean massStorageActive =
Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
boolean usbErrored = false;
boolean massStorageActive =
Environment.MEDIA_SHARED.equals(Environment.getExternalStorageState());
- for (Object o : available) {
- String s = (String)o;
+ for (String s : available) {
for (String regex : mUsbRegexs) {
if (s.matches(regex)) {
usbAvailable = true;
for (String regex : mUsbRegexs) {
if (s.matches(regex)) {
usbAvailable = true;
- for (Object o : tethered) {
- String s = (String)o;
+ for (String s : tethered) {
for (String regex : mUsbRegexs) {
if (s.matches(regex)) usbTethered = true;
}
}
for (String regex : mUsbRegexs) {
if (s.matches(regex)) usbTethered = true;
}
}
- for (Object o: errored) {
- String s = (String)o;
+ for (String s: errored) {
for (String regex : mUsbRegexs) {
if (s.matches(regex)) usbErrored = true;
}
for (String regex : mUsbRegexs) {
if (s.matches(regex)) usbErrored = true;
}