Skip to content

Commit

Permalink
Delete ip_address from Device Property
Browse files Browse the repository at this point in the history
  • Loading branch information
teamwork523 committed Jan 22, 2013
1 parent 50282c3 commit 587128a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ array.

TCP Throughput parameters

(required) dir_up - Uplink or Downlink measurement (true/false)
(required) dir_up - Uplink or Downlink measurement (boolean)
(required) target - hostname for servers. Use m-lab for now. (string)
(optional) data_limit_mb_up - Uplink cellular network data
limit (double)
Expand Down
4 changes: 1 addition & 3 deletions android/src/com/mobiperf/Checkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ public List<MeasurementTask> checkin() throws IOException {
MeasurementTask task =
MeasurementJsonConvertor.makeMeasurementTaskFromJson(json, this.context);
Logger.i(MeasurementJsonConvertor.toJsonString(task.measurementDesc));
// TODO (Haokun): remove before release
if (!json.get("type").equals("traceroute"))
schedule.add(task);
schedule.add(task);
} catch (IllegalArgumentException e) {
Logger.w("Could not create task from JSON: " + e);
// Just skip it, and try the next one
Expand Down
8 changes: 4 additions & 4 deletions android/src/com/mobiperf/DeviceProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class DeviceProperty {
public String appVersion;
public long timestamp;
public String osVersion;
public String ipAddress;
// Exclude ip address due to NAT
// public String ipAddress;
public GeoLocation location;
public String locationType;
public String networkType;
Expand All @@ -38,15 +39,14 @@ public class DeviceProperty {
public int rssi;

public DeviceProperty(String deviceId, String appVersion, long timeStamp, String osVersion,
String ipAddress, double longtitude, double latitude, String locationType,
double longtitude, double latitude, String locationType,
String networkType, String carrier, int batteryLevel, boolean isCharging,
String cellInfo, int rssi) {
super();
this.deviceId = deviceId;
this.appVersion = appVersion;
this.timestamp = timeStamp;
this.osVersion = osVersion;
this.ipAddress = ipAddress;
this.osVersion = osVersion;
this.location = new GeoLocation(longtitude, latitude);
this.locationType = locationType;
this.networkType = networkType;
Expand Down
16 changes: 4 additions & 12 deletions android/src/com/mobiperf/measurements/TCPThroughputTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public class TCPThroughputTask extends MeasurementTask {

// Data related
private final int KBYTE = 1024;
private static final int DATA_LIMIT_MB_UP = 5;
private static final int DATA_LIMIT_MB_DOWN = 10;
private static final int DATA_LIMIT_MB_UP = 3;
private static final int DATA_LIMIT_MB_DOWN = 5;
private boolean DATA_LIMIT_ON = true;
private boolean DATA_LIMIT_EXCEEDED = false;
private static final String UPLINK_FINISH_MSG = "*";
Expand Down Expand Up @@ -136,7 +136,6 @@ protected void initializeParams(Map<String, String> params) {

try {
String readVal = null;
// TODO (Haokun): get limitation from configuration
if ((readVal = params.get("data_limit_mb_down")) != null && readVal.length() > 0
&& Integer.parseInt(readVal) > 0) {
this.data_limit_mb_down = Double.parseDouble(readVal);
Expand All @@ -145,7 +144,6 @@ protected void initializeParams(Map<String, String> params) {
}
}

// TODO (Haokun): get limitation from configuration
if ((readVal = params.get("data_limit_mb_up")) != null && readVal.length() > 0
&& Integer.parseInt(readVal) > 0) {
this.data_limit_mb_up = Double.parseDouble(readVal);
Expand Down Expand Up @@ -323,7 +321,7 @@ public MeasurementResult call() throws MeasurementError {
if (!acquireServerConfig()) {
throw new MeasurementError("Fail to acquire server configuration");
}
Logger.w("Server version is " + this.serverVersion);
Logger.i("Server version is " + this.serverVersion);
if (desc.dir_up == true) {
uplink();
Logger.i("Uplink measurement result is:");
Expand All @@ -350,17 +348,11 @@ public MeasurementResult call() throws MeasurementError {
System.currentTimeMillis() * 1000, isMeasurementSuccessful,
this.measurementDesc);
// TODO (Haokun): add more results if necessary
String resultList = MeasurementJsonConvertor.toJsonString(this.samplingResults);
String limitExceed = MeasurementJsonConvertor.toJsonString(this.DATA_LIMIT_EXCEEDED);
String taskDur = MeasurementJsonConvertor.toJsonString(this.taskDuration);
Logger.w("Result for this round is " + resultList);
Logger.w("Data limit exceed is " + limitExceed);
Logger.w("Total task duration is " + taskDur);
result.addResult("tcp_speed_results", this.samplingResults);
result.addResult("data_limit_exceeded", this.DATA_LIMIT_EXCEEDED);
result.addResult("duration", this.taskDuration);
result.addResult("server_version", this.serverVersion);
Logger.w(MeasurementJsonConvertor.toJsonString(result));
Logger.i(MeasurementJsonConvertor.toJsonString(result));
return result;
}

Expand Down
6 changes: 2 additions & 4 deletions android/src/com/mobiperf/measurements/TracerouteTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,13 @@ public MeasurementResult call() throws MeasurementError {


try {
InetAddress hostInetAddr = InetAddress.getByName(target);
hostIp = hostInetAddr.getHostAddress();
InetAddress hostInetAddr = InetAddress.getByName(target);
hostIp = hostInetAddr.getHostAddress();
// TODO(Wenjie): Add a exhaustive list of ping locations for different Android phones
// add support for ipv6
task.pingExe = (hostInetAddr.getAddress().length == 4)
? parent.getString(R.string.ping_executable)
: parent.getString(R.string.ping6_executable);
// TODO (Haokun): delete after testing
Logger.w("ping executable is " + task.pingExe);
} catch (UnknownHostException e) {
Logger.e("Cannont resolve host " + target);
throw new MeasurementError("target " + target + " cannot be resolved");
Expand Down
86 changes: 47 additions & 39 deletions android/src/com/mobiperf/util/PhoneUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ public boolean isTestingServer(String serverUrl) {
return serverUrl == getTestingServerUrl();
}

@Deprecated
private String getCellularIp() {
String ipAddress = null;

Expand Down Expand Up @@ -702,25 +703,29 @@ private String intToIp(int number) {
}
}

@Deprecated
/**
* Read the ip address from WifiInfo
* Use reflection to acquire the "InetAddress" field, which handles ipv6 internally
*/
private String getWifiIp() {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String resultIp = null;
// use reflection to acquire the "InetAddress" type, which handle ipv6 internally
try {
Field reflectIPField = wifiInfo.getClass().getDeclaredField("mIpAddress");
// enforce accessibility
reflectIPField.setAccessible(true);
InetAddress myIp = (InetAddress)reflectIPField.get(wifiInfo);
resultIp = myIp.getHostAddress();
Field reflectIPField = wifiInfo.getClass().getDeclaredField("mIpAddress");
// enforce accessibility
reflectIPField.setAccessible(true);
InetAddress myIp = (InetAddress)reflectIPField.get(wifiInfo);
resultIp = myIp.getHostAddress();
} catch (IllegalArgumentException e) {
Logger.e("Bad arguments");
Logger.e("Bad arguments when access WifiInfo");
} catch (IllegalAccessException e) {
Logger.e("Cannot access the field -- mIpAddress");
Logger.e("Cannot access the mIpAddress field in WifiInfo");
} catch (SecurityException e) {
e.printStackTrace();
Logger.e("Security Exception detected when access WifiInfo");
} catch (NoSuchFieldException e) {
Logger.e("Error during reflect: no mIpAddress field exists");
Logger.e("No mIpAddress field exists in WifiInfo");
}
return resultIp;
/*if (wifiInfo != null) {
Expand All @@ -730,42 +735,45 @@ private String getWifiIp() {
return null;
}*/
}


@Deprecated
/**
* Create temporary network to lookup for ip address
*/
private String getIpFromSocket() {
Socket tcpSocket = new Socket();
String localIP = null;
try {
// TODO (Haokun): store constant into config
SocketAddress remoteAddr = new InetSocketAddress("www.google.com", 80);
tcpSocket.setTcpNoDelay(true);
tcpSocket.connect(remoteAddr, 3000);
localIP = tcpSocket.getLocalAddress().getHostAddress();
} catch (IOException e) {
Logger.e("Error happen during local ip lookup: fail to set up socket.");
} finally {
try {
tcpSocket.close();
} catch (IOException e) {
Logger.e("Error happen during local ip lookup: fail to close socket.");
} finally {
return localIP;
Socket tcpSocket = new Socket();
String localIP = null;
try {
String hostname = "www.google.com";
int portNum = 80;
int tcpTimeout = 3000;
SocketAddress remoteAddr = new InetSocketAddress(hostname, portNum);
tcpSocket.setTcpNoDelay(true);
tcpSocket.connect(remoteAddr, tcpTimeout);
localIP = tcpSocket.getLocalAddress().getHostAddress();
} catch (IOException e) {
Logger.e("Error happen during local ip lookup: fail to set up socket.");
} finally {
try {
tcpSocket.close();
} catch (IOException e) {
Logger.e("Error happen during local ip lookup: fail to close socket.");
}
}
}
return localIP;
}

@Deprecated
/* Wifi and 3G can be both active. We first see if wifi is active and return the wifi IP using
* the WifiManager. Otherwise, we search an active network interface and return it as the 3G
* network IP*/
private String getIp() {
String wifiIp = getWifiIp();
Logger.w("Wifi IP is " + wifiIp);
// Handle ipv6 internally
String ipStr = getIpFromSocket();
Logger.w("Mobile IP is " + ipStr);
String ipStr = getWifiIp();
if (ipStr == null) {
ipStr = getIpFromSocket();
}
if (ipStr == null) {
ipStr = getCellularIp();
// TODO (Haokun): remove after testing
Logger.w("IP from interface is " + ipStr);
}
if (ipStr == null) {
return "";
Expand All @@ -786,15 +794,15 @@ public DeviceProperty getDeviceProperty() {

NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
String networkType = PhoneUtils.getPhoneUtils().getNetwork();
String activeIp = getIp();
if (activeNetwork != null && activeIp.compareTo("") == 0) {
// String activeIp = getIp();
if (activeNetwork != null) {
networkType = activeNetwork.getTypeName();
}
String versionName = PhoneUtils.getPhoneUtils().getAppVersionName();
PhoneUtils utils = PhoneUtils.getPhoneUtils();

return new DeviceProperty(getDeviceInfo().deviceId, versionName,
System.currentTimeMillis() * 1000, getVersionStr(), activeIp, location.getLongitude(),
System.currentTimeMillis() * 1000, getVersionStr(), location.getLongitude(),
location.getLatitude(), location.getProvider(), networkType, carrierName,
utils.getCurrentBatteryLevel(), utils.isCharging(), utils.getCellInfo(),
utils.getCurrentRssi());
Expand Down

0 comments on commit 587128a

Please sign in to comment.