diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 389e2352..db6476b9 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -9,7 +9,7 @@
android:targetSdkVersion="19" />
-
+
ifaceList = NetworkInterface.getNetworkInterfaces();
-
- while (ifaceList.hasMoreElements()) {
+ Enumeration ifaceList;
+ NetworkInterface selectedIface = null;
+
+ // First look for a WLAN interface (since those generally aren't removable)
+ ifaceList = NetworkInterface.getNetworkInterfaces();
+ while (selectedIface == null && ifaceList.hasMoreElements()) {
NetworkInterface iface = ifaceList.nextElement();
-
- /* Look for the first non-loopback interface to use as the MAC address.
- * We don't require the interface to be up to avoid having to repair when
- * connecting over different interfaces */
- if (!iface.isLoopback()) {
- byte[] macAddress = iface.getHardwareAddress();
- if (macAddress != null && macAddress.length == 6) {
- StringBuilder addrStr = new StringBuilder();
- for (int i = 0; i < macAddress.length; i++) {
- addrStr.append(String.format("%02x", macAddress[i]));
- if (i != macAddress.length - 1) {
- addrStr.append(':');
- }
- }
- return addrStr.toString();
+
+ if (iface.getName().startsWith("wlan")) {
+ selectedIface = iface;
+ }
+ }
+
+ // If we didn't find that, look for an Ethernet interface
+ ifaceList = NetworkInterface.getNetworkInterfaces();
+ while (selectedIface == null && ifaceList.hasMoreElements()) {
+ NetworkInterface iface = ifaceList.nextElement();
+
+ if (iface.getName().startsWith("eth")) {
+ selectedIface = iface;
+ }
+ }
+
+ // Now just find something
+ ifaceList = NetworkInterface.getNetworkInterfaces();
+ if (ifaceList.hasMoreElements()) {
+ selectedIface = ifaceList.nextElement();
+ }
+
+ if (selectedIface == null) {
+ return null;
+ }
+
+ byte[] macAddress = selectedIface.getHardwareAddress();
+ if (macAddress != null && macAddress.length == 6) {
+ StringBuilder addrStr = new StringBuilder();
+ for (int i = 0; i < macAddress.length; i++) {
+ addrStr.append(String.format("%02x", macAddress[i]));
+ if (i != macAddress.length - 1) {
+ addrStr.append(':');
}
}
+ return addrStr.toString();
}
return null;
@@ -93,6 +117,8 @@ public class NvConnection {
new Thread(new Runnable() {
@Override
public void run() {
+ checkDataConnection();
+
try {
host = InetAddress.getByName(host).getHostAddress();
} catch (UnknownHostException e) {
@@ -122,6 +148,14 @@ public class NvConnection {
}).start();
}
+ private void checkDataConnection()
+ {
+ ConnectivityManager mgr = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (mgr.isActiveNetworkMetered()) {
+ displayToast("Warning: Your active network connection is metered!");
+ }
+ }
+
public void sendMouseMove(final short deltaX, final short deltaY)
{
if (inputStream == null)
diff --git a/src/com/limelight/nvstream/NvControl.java b/src/com/limelight/nvstream/NvControl.java
index f9cb81f5..3cfaf47d 100644
--- a/src/com/limelight/nvstream/NvControl.java
+++ b/src/com/limelight/nvstream/NvControl.java
@@ -327,9 +327,17 @@ public class NvControl {
int offset = 0;
do
{
- offset = in.read(header, offset, header.length - offset);
+ int bytesRead = in.read(header, offset, header.length - offset);
+ if (bytesRead < 0) {
+ break;
+ }
+ offset += bytesRead;
} while (offset != header.length);
+ if (offset != header.length) {
+ throw new IOException("Socket closed prematurely");
+ }
+
ByteBuffer bb = ByteBuffer.wrap(header).order(ByteOrder.LITTLE_ENDIAN);
type = bb.getShort();
@@ -342,8 +350,16 @@ public class NvControl {
offset = 0;
do
{
- offset = in.read(payload, offset, payload.length - offset);
+ int bytesRead = in.read(payload, offset, payload.length - offset);
+ if (bytesRead < 0) {
+ break;
+ }
+ offset += bytesRead;
} while (offset != payload.length);
+
+ if (offset != payload.length) {
+ throw new IOException("Socket closed prematurely");
+ }
}
}