code clean up
This commit is contained in:
parent
111c5b6116
commit
99d73ad3ea
|
|
@ -7,23 +7,25 @@ import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by yanzi on 7/10/15.
|
* Created by yanzi on 7/10/15.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class Connectivity {
|
|
||||||
|
class Connectivity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the network info
|
* Get the network info
|
||||||
* @param context
|
* @param context:
|
||||||
* @return
|
* @return NetworkInfo
|
||||||
*/
|
*/
|
||||||
public static NetworkInfo getNetworkInfo(Context context){
|
private static NetworkInfo getNetworkInfo(Context context){
|
||||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
return cm.getActiveNetworkInfo();
|
return cm.getActiveNetworkInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if there is any connectivity
|
* Check if there is any connectivity
|
||||||
* @param context
|
* @param context:
|
||||||
* @return
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static boolean isConnected(Context context){
|
public static boolean isConnected(Context context){
|
||||||
NetworkInfo info = Connectivity.getNetworkInfo(context);
|
NetworkInfo info = Connectivity.getNetworkInfo(context);
|
||||||
|
|
@ -32,8 +34,8 @@ public class Connectivity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if there is any connectivity to a Wifi network
|
* Check if there is any connectivity to a Wifi network
|
||||||
* @param context
|
* @param context:
|
||||||
* @return
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static boolean isConnectedWifi(Context context){
|
public static boolean isConnectedWifi(Context context){
|
||||||
NetworkInfo info = Connectivity.getNetworkInfo(context);
|
NetworkInfo info = Connectivity.getNetworkInfo(context);
|
||||||
|
|
@ -42,8 +44,8 @@ public class Connectivity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if there is any connectivity to a mobile network
|
* Check if there is any connectivity to a mobile network
|
||||||
* @param context
|
* @param context:
|
||||||
* @return
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static boolean isConnectedMobile(Context context){
|
public static boolean isConnectedMobile(Context context){
|
||||||
NetworkInfo info = Connectivity.getNetworkInfo(context);
|
NetworkInfo info = Connectivity.getNetworkInfo(context);
|
||||||
|
|
@ -52,8 +54,8 @@ public class Connectivity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if there is any connectivity to a mobile network
|
* Check if there is any connectivity to a mobile network
|
||||||
* @param context
|
* @param context:
|
||||||
* @return
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static boolean isConnectedLTE(Context context){
|
public static boolean isConnectedLTE(Context context){
|
||||||
NetworkInfo info = Connectivity.getNetworkInfo(context);
|
NetworkInfo info = Connectivity.getNetworkInfo(context);
|
||||||
|
|
@ -63,8 +65,8 @@ public class Connectivity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if there is fast connectivity
|
* Check if there is fast connectivity
|
||||||
* @param context
|
* @param context:
|
||||||
* @return
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static boolean isConnectedFast(Context context){
|
public static boolean isConnectedFast(Context context){
|
||||||
NetworkInfo info = Connectivity.getNetworkInfo(context);
|
NetworkInfo info = Connectivity.getNetworkInfo(context);
|
||||||
|
|
@ -73,11 +75,11 @@ public class Connectivity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the connection is fast
|
* Check if the connection is fast
|
||||||
* @param type
|
* @param type:
|
||||||
* @param subType
|
* @param subType:
|
||||||
* @return
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static boolean isConnectionFast(int type, int subType){
|
private static boolean isConnectionFast(int type, int subType){
|
||||||
if(type== ConnectivityManager.TYPE_WIFI){
|
if(type== ConnectivityManager.TYPE_WIFI){
|
||||||
return true;
|
return true;
|
||||||
}else if(type== ConnectivityManager.TYPE_MOBILE){
|
}else if(type== ConnectivityManager.TYPE_MOBILE){
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ public class MainActivity extends Activity {
|
||||||
protected static boolean isRunning_RX_RawNormal = false;
|
protected static boolean isRunning_RX_RawNormal = false;
|
||||||
/**
|
/**
|
||||||
* Check whether a service is running
|
* Check whether a service is running
|
||||||
* @param serviceClass
|
* @param serviceClass:
|
||||||
* @return true/false
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
protected boolean isServiceRunning(Class<?> serviceClass) {
|
protected boolean isServiceRunning(Class<?> serviceClass) {
|
||||||
|
|
@ -171,19 +171,17 @@ public class MainActivity extends Activity {
|
||||||
+ binaryFolderPath + "bigfile"
|
+ binaryFolderPath + "bigfile"
|
||||||
+ " count=1 bs=1 seek=$((2 * 1024 * 1024 * 1024 - 1)) "
|
+ " count=1 bs=1 seek=$((2 * 1024 * 1024 * 1024 - 1)) "
|
||||||
+ "&& chmod 755 " + binaryFolderPath + "bigfile").waitFor();
|
+ "&& chmod 755 " + binaryFolderPath + "bigfile").waitFor();
|
||||||
} catch (IOException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
Toast.makeText(this, "Created a 2Gbits big file", Toast.LENGTH_LONG).show();
|
Toast.makeText(this, "Created a 2Gbits big file", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
if (!missingFiles.equals("")) {
|
if (!missingFiles.equals("")) {
|
||||||
final String mFiles = missingFiles;
|
final String mFiles = "Failed to find following files:\n" + missingFiles;
|
||||||
myHandler.post(new Runnable() {
|
myHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
txt_results.setText("Failed to find following files:\n" + mFiles);
|
txt_results.setText(mFiles);
|
||||||
btn_startTransmit.setEnabled(false);
|
btn_startTransmit.setEnabled(false);
|
||||||
btn_startReceive.setEnabled(false);
|
btn_startReceive.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
@ -508,9 +506,7 @@ public class MainActivity extends Activity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException | IOException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -523,9 +519,7 @@ public class MainActivity extends Activity {
|
||||||
Runtime.getRuntime().exec(
|
Runtime.getRuntime().exec(
|
||||||
"su -c echo 1 > /sys/class/lcd/panel/lcd_power")
|
"su -c echo 1 > /sys/class/lcd/panel/lcd_power")
|
||||||
.waitFor();
|
.waitFor();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException | IOException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
// msg indicating all done
|
// msg indicating all done
|
||||||
|
|
@ -585,7 +579,7 @@ public class MainActivity extends Activity {
|
||||||
intentSSLogger = new Intent(this, SSLogger.class);
|
intentSSLogger = new Intent(this, SSLogger.class);
|
||||||
// grab WiFi service and check if wifi is enabled
|
// grab WiFi service and check if wifi is enabled
|
||||||
wm = (WifiManager) this.getSystemService(WIFI_SERVICE);
|
wm = (WifiManager) this.getSystemService(WIFI_SERVICE);
|
||||||
isUsingWifi = (wm.isWifiEnabled()) ? true : false;
|
isUsingWifi = wm.isWifiEnabled();
|
||||||
Utilities.getSelfIdentity(tcpdumpInterface, true);
|
Utilities.getSelfIdentity(tcpdumpInterface, true);
|
||||||
// predefined selections
|
// predefined selections
|
||||||
existedItems = new CharSequence[] {
|
existedItems = new CharSequence[] {
|
||||||
|
|
@ -741,9 +735,7 @@ public class MainActivity extends Activity {
|
||||||
out.add(line);
|
out.add(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
final CharSequence mTmp[] = out.toArray(new CharSequence[out.size()]);
|
final CharSequence mTmp[] = out.toArray(new CharSequence[out.size()]);
|
||||||
|
|
@ -823,8 +815,7 @@ public class MainActivity extends Activity {
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// TODO: wifi driver for android build not working, only for
|
// TODO: wifi driver for Nexus build not working
|
||||||
// Samsung? Need to check.
|
|
||||||
wifiDriverPID = isChecked ?
|
wifiDriverPID = isChecked ?
|
||||||
Utilities.getMyPID("dhd_dpc", true) : -1;
|
Utilities.getMyPID("dhd_dpc", true) : -1;
|
||||||
Toast.makeText(MainActivity.this,
|
Toast.makeText(MainActivity.this,
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import java.io.InputStreamReader;
|
||||||
* Updated on 01/27/17
|
* Updated on 01/27/17
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Thread_TX_CNormal implements Runnable {
|
class Thread_TX_CNormal implements Runnable {
|
||||||
private double sentBytes = 0.0;
|
private double sentBytes = 0.0;
|
||||||
private double duration = 0.0;
|
private double duration = 0.0;
|
||||||
private double throughput = 0.0;
|
private double throughput = 0.0;
|
||||||
|
|
|
||||||
|
|
@ -9,22 +9,26 @@ import java.io.InputStreamReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by yanzi on 9/18/15.
|
* Created by yanzi on 9/18/15.
|
||||||
* Updated on 01/25/17
|
* Updated on 01/27/17
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Thread_TX_CNormalUDP implements Runnable {
|
class Thread_TX_CNormalUDP implements Runnable {
|
||||||
private double sentBytes = 0.0;
|
private double sentBytes = 0.0;
|
||||||
private double duration = 0.0;
|
private double duration = 0.0;
|
||||||
private double throughput = 0.0;
|
private double throughput = 0.0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
|
// prevent multiple runs
|
||||||
if (MainActivity.isRunning_TX_NormalUDP)
|
if (MainActivity.isRunning_TX_NormalUDP)
|
||||||
return;
|
return;
|
||||||
if (MainActivity.isVerbose)
|
|
||||||
Log.d("TX_NormalUDP", "Start TX Normal UDP");
|
|
||||||
MainActivity.isRunning_TX_NormalUDP = true;
|
MainActivity.isRunning_TX_NormalUDP = true;
|
||||||
|
|
||||||
|
// variables
|
||||||
Process proc;
|
Process proc;
|
||||||
|
String stdout;
|
||||||
|
BufferedReader stdout_buf, error_buf;
|
||||||
String[] commd = new String[3];
|
String[] commd = new String[3];
|
||||||
|
|
||||||
// get the right command
|
// get the right command
|
||||||
|
|
@ -40,6 +44,8 @@ public class Thread_TX_CNormalUDP implements Runnable {
|
||||||
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
|
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
|
||||||
MainActivity.currentBandwidth));
|
MainActivity.currentBandwidth));
|
||||||
|
|
||||||
|
Log.d("TX_NormalUDP", "Start TX Normal UDP");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// run process
|
// run process
|
||||||
proc = Runtime.getRuntime().exec(commd);
|
proc = Runtime.getRuntime().exec(commd);
|
||||||
|
|
@ -52,14 +58,13 @@ public class Thread_TX_CNormalUDP implements Runnable {
|
||||||
|
|
||||||
|
|
||||||
// read error
|
// read error
|
||||||
BufferedReader error_buf = new BufferedReader(new InputStreamReader(
|
error_buf = new BufferedReader(new InputStreamReader(
|
||||||
proc.getErrorStream()));
|
proc.getErrorStream()));
|
||||||
final String error = error_buf.readLine(); // only one line error
|
final String error = error_buf.readLine(); // only one line error
|
||||||
|
|
||||||
// read std out
|
// read std out
|
||||||
BufferedReader stdout_buf = new BufferedReader(new InputStreamReader(
|
stdout_buf = new BufferedReader(new InputStreamReader(
|
||||||
proc.getInputStream()));
|
proc.getInputStream()));
|
||||||
String stdout;
|
|
||||||
|
|
||||||
// get sent bytes
|
// get sent bytes
|
||||||
stdout = stdout_buf.readLine();
|
stdout = stdout_buf.readLine();
|
||||||
|
|
@ -92,44 +97,13 @@ public class Thread_TX_CNormalUDP implements Runnable {
|
||||||
stdout = stdout_buf.readLine();
|
stdout = stdout_buf.readLine();
|
||||||
throughput = Utilities.parseBinOutput(stdout);
|
throughput = Utilities.parseBinOutput(stdout);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// InputStream stdout = proc.getInputStream();
|
} catch (IOException | InterruptedException e) {
|
||||||
// byte[] buffer = new byte[20];
|
|
||||||
// int read;
|
|
||||||
// StringBuilder out = new StringBuilder();
|
|
||||||
// while(true){
|
|
||||||
// read = stdout.read(buffer);
|
|
||||||
// if(read<0){
|
|
||||||
// MainActivity.myHandler.post(new Runnable() {
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// MainActivity.txt_results.append("Failed in TX_NormalUDP\n");
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// out.append(new String(buffer, 0, read));
|
|
||||||
// if(read<20){
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// final String mOut = out.toString().trim();
|
|
||||||
// MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
|
||||||
// if (MainActivity.isVerbose) {
|
|
||||||
// MainActivity.myHandler.post(new Runnable() {
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (MainActivity.isVerbose)
|
|
||||||
Log.d("TX_NormalUDP", "Stop TX Normal UDP");
|
Log.d("TX_NormalUDP", "Stop TX Normal UDP");
|
||||||
|
|
||||||
MainActivity.isRunning_TX_NormalUDP = false;
|
MainActivity.isRunning_TX_NormalUDP = false;
|
||||||
MainActivity.perProcPID = -1;
|
MainActivity.perProcPID = -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,21 +9,25 @@ import java.io.InputStreamReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by yanzi on 9/19/15.
|
* Created by yanzi on 9/19/15.
|
||||||
|
* Updated on 01/27/17
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Thread_TX_CRawNormal implements Runnable {
|
class Thread_TX_CRawNormal implements Runnable {
|
||||||
private double sentBytes = 0.0;
|
private double sentBytes = 0.0;
|
||||||
private double duration = 0.0;
|
private double duration = 0.0;
|
||||||
private double throughput = 0.0;
|
private double throughput = 0.0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
// prevent multiple runs
|
||||||
if (MainActivity.isRunning_TX_RawNormal)
|
if (MainActivity.isRunning_TX_RawNormal)
|
||||||
return;
|
return;
|
||||||
if (MainActivity.isVerbose)
|
|
||||||
Log.d("TX_RawNormal", "Start TX RawNormal");
|
|
||||||
MainActivity.isRunning_TX_RawNormal = true;
|
MainActivity.isRunning_TX_RawNormal = true;
|
||||||
|
|
||||||
|
// variables
|
||||||
Process proc;
|
Process proc;
|
||||||
|
String stdout;
|
||||||
|
BufferedReader stdout_buf, error_buf;
|
||||||
String[] commd = new String[3];
|
String[] commd = new String[3];
|
||||||
|
|
||||||
// get the right command
|
// get the right command
|
||||||
|
|
@ -38,6 +42,7 @@ public class Thread_TX_CRawNormal implements Runnable {
|
||||||
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
|
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
|
||||||
MainActivity.currentBandwidth));
|
MainActivity.currentBandwidth));
|
||||||
|
|
||||||
|
Log.d("TX_RawNormal", "Start TX RawNormal");
|
||||||
try {
|
try {
|
||||||
// run process
|
// run process
|
||||||
proc = Runtime.getRuntime().exec(commd);
|
proc = Runtime.getRuntime().exec(commd);
|
||||||
|
|
@ -49,14 +54,13 @@ public class Thread_TX_CRawNormal implements Runnable {
|
||||||
proc.waitFor();
|
proc.waitFor();
|
||||||
|
|
||||||
// read error
|
// read error
|
||||||
BufferedReader error_buf = new BufferedReader(new InputStreamReader(
|
error_buf = new BufferedReader(new InputStreamReader(
|
||||||
proc.getErrorStream()));
|
proc.getErrorStream()));
|
||||||
final String error = error_buf.readLine(); // only one line error
|
final String error = error_buf.readLine(); // only one line error
|
||||||
|
|
||||||
// read std out
|
// read std out
|
||||||
BufferedReader stdout_buf = new BufferedReader(new InputStreamReader(
|
stdout_buf = new BufferedReader(new InputStreamReader(
|
||||||
proc.getInputStream()));
|
proc.getInputStream()));
|
||||||
String stdout;
|
|
||||||
|
|
||||||
// get sent bytes
|
// get sent bytes
|
||||||
stdout = stdout_buf.readLine();
|
stdout = stdout_buf.readLine();
|
||||||
|
|
@ -90,43 +94,12 @@ public class Thread_TX_CRawNormal implements Runnable {
|
||||||
throughput = Utilities.parseBinOutput(stdout);
|
throughput = Utilities.parseBinOutput(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// InputStream stdout = proc.getInputStream();
|
} catch (IOException | InterruptedException e) {
|
||||||
// byte[] buffer = new byte[20];
|
|
||||||
// int read;
|
|
||||||
// StringBuilder out = new StringBuilder();
|
|
||||||
// while(true){
|
|
||||||
// read = stdout.read(buffer);
|
|
||||||
// if(read<0){
|
|
||||||
// MainActivity.myHandler.post(new Runnable() {
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// MainActivity.txt_results.append("Failed in TX_RawNormal\n");
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// out.append(new String(buffer, 0, read));
|
|
||||||
// if(read<20){
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// final String mOut = out.toString().trim();
|
|
||||||
// MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
|
||||||
// if (MainActivity.isVerbose) {
|
|
||||||
// MainActivity.myHandler.post(new Runnable() {
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (MainActivity.isVerbose)
|
|
||||||
Log.d("TX_RawNormal", "Stop TX RawNormal");
|
Log.d("TX_RawNormal", "Stop TX RawNormal");
|
||||||
|
|
||||||
MainActivity.isRunning_TX_RawNormal = false;
|
MainActivity.isRunning_TX_RawNormal = false;
|
||||||
MainActivity.perProcPID = -1;
|
MainActivity.perProcPID = -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ import java.io.InputStreamReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by yanzi on 9/18/15.
|
* Created by yanzi on 9/18/15.
|
||||||
* Updated on 01/25/17
|
* Updated on 01/27/17
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Thread_TX_CRawSplice implements Runnable {
|
class Thread_TX_CRawSplice implements Runnable {
|
||||||
private double sentBytes = 0.0;
|
private double sentBytes = 0.0;
|
||||||
private double duration = 0.0;
|
private double duration = 0.0;
|
||||||
private double throughput = 0.0;
|
private double throughput = 0.0;
|
||||||
|
|
@ -92,48 +92,12 @@ public class Thread_TX_CRawSplice implements Runnable {
|
||||||
throughput = Utilities.parseBinOutput(stdout);
|
throughput = Utilities.parseBinOutput(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// proc = Runtime.getRuntime().exec(commd);
|
} catch (IOException | InterruptedException e) {
|
||||||
// while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
|
|
||||||
// MainActivity.perProcPID = Utilities.getMyPID(MainActivity.binary_TX_RawSplice, false);
|
|
||||||
// }
|
|
||||||
// proc.waitFor();
|
|
||||||
// InputStream stdout = proc.getInputStream();
|
|
||||||
// byte[] buffer = new byte[20];
|
|
||||||
// int read;
|
|
||||||
// StringBuilder out = new StringBuilder();
|
|
||||||
// while(true){
|
|
||||||
// read = stdout.read(buffer);
|
|
||||||
// if(read<0){
|
|
||||||
// MainActivity.myHandler.post(new Runnable() {
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// MainActivity.txt_results.append("Failed in TX_RawSplice\n");
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// out.append(new String(buffer, 0, read));
|
|
||||||
// if(read<20){
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// final String mOut = out.toString().trim();
|
|
||||||
// MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
|
||||||
// if (MainActivity.isVerbose) {
|
|
||||||
// MainActivity.myHandler.post(new Runnable() {
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (MainActivity.isVerbose)
|
|
||||||
Log.d("TX_RawSplice", "Stop TX RawSplice");
|
Log.d("TX_RawSplice", "Stop TX RawSplice");
|
||||||
|
|
||||||
MainActivity.isRunning_TX_RawSplice = false;
|
MainActivity.isRunning_TX_RawSplice = false;
|
||||||
MainActivity.perProcPID = -1;
|
MainActivity.perProcPID = -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,21 +9,25 @@ import java.io.InputStreamReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by yanzi on 9/19/15.
|
* Created by yanzi on 9/19/15.
|
||||||
* Updated on 01/25/17
|
* Updated on 01/27/17
|
||||||
*/
|
*/
|
||||||
public class Thread_TX_CSendfile implements Runnable {
|
|
||||||
|
class Thread_TX_CSendfile implements Runnable {
|
||||||
private double sentBytes = 0.0;
|
private double sentBytes = 0.0;
|
||||||
private double duration = 0.0;
|
private double duration = 0.0;
|
||||||
private double throughput = 0.0;
|
private double throughput = 0.0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
// prevent multiple runs
|
||||||
if (MainActivity.isRunning_TX_Sendfile)
|
if (MainActivity.isRunning_TX_Sendfile)
|
||||||
return;
|
return;
|
||||||
if (MainActivity.isVerbose)
|
|
||||||
Log.d("TX_Sendfile", "Start TX Sendfile");
|
|
||||||
MainActivity.isRunning_TX_Sendfile = true;
|
MainActivity.isRunning_TX_Sendfile = true;
|
||||||
|
|
||||||
|
// variables
|
||||||
Process proc;
|
Process proc;
|
||||||
|
String stdout;
|
||||||
|
BufferedReader stdout_buf, error_buf;
|
||||||
String[] commd = new String[3];
|
String[] commd = new String[3];
|
||||||
|
|
||||||
// get the right command
|
// get the right command
|
||||||
|
|
@ -39,6 +43,7 @@ public class Thread_TX_CSendfile implements Runnable {
|
||||||
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
|
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
|
||||||
MainActivity.currentBandwidth));
|
MainActivity.currentBandwidth));
|
||||||
|
|
||||||
|
Log.d("TX_Sendfile", "Start TX Sendfile");
|
||||||
try {
|
try {
|
||||||
// run process
|
// run process
|
||||||
proc = Runtime.getRuntime().exec(commd);
|
proc = Runtime.getRuntime().exec(commd);
|
||||||
|
|
@ -51,14 +56,13 @@ public class Thread_TX_CSendfile implements Runnable {
|
||||||
proc.waitFor();
|
proc.waitFor();
|
||||||
|
|
||||||
// read error
|
// read error
|
||||||
BufferedReader error_buf = new BufferedReader(new InputStreamReader(
|
error_buf = new BufferedReader(new InputStreamReader(
|
||||||
proc.getErrorStream()));
|
proc.getErrorStream()));
|
||||||
final String error = error_buf.readLine(); // only one line error
|
final String error = error_buf.readLine(); // only one line error
|
||||||
|
|
||||||
// read std out
|
// read std out
|
||||||
BufferedReader stdout_buf = new BufferedReader(new InputStreamReader(
|
stdout_buf = new BufferedReader(new InputStreamReader(
|
||||||
proc.getInputStream()));
|
proc.getInputStream()));
|
||||||
String stdout;
|
|
||||||
|
|
||||||
// get sent bytes
|
// get sent bytes
|
||||||
stdout = stdout_buf.readLine();
|
stdout = stdout_buf.readLine();
|
||||||
|
|
@ -92,54 +96,12 @@ public class Thread_TX_CSendfile implements Runnable {
|
||||||
throughput = Utilities.parseBinOutput(stdout);
|
throughput = Utilities.parseBinOutput(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// commd[0] = "su";
|
} catch (IOException | InterruptedException e) {
|
||||||
// commd[1] = "-c";
|
|
||||||
// commd[2] = (MainActivity.isForcingCPU0?"taskset 1 ":"")
|
|
||||||
// + MainActivity.binaryFolderPath + MainActivity.binary_TX_Sendfile + " "
|
|
||||||
// + MainActivity.bytes2send + " " + String.valueOf(MainActivity.currentBandwidth);
|
|
||||||
// try {
|
|
||||||
// proc = Runtime.getRuntime().exec(commd);
|
|
||||||
// while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
|
|
||||||
// MainActivity.perProcPID = Utilities.getMyPID(MainActivity.binary_TX_Sendfile, false);
|
|
||||||
// }
|
|
||||||
// proc.waitFor();
|
|
||||||
// InputStream stdout = proc.getInputStream();
|
|
||||||
// byte[] buffer = new byte[20];
|
|
||||||
// int read;
|
|
||||||
// StringBuilder out = new StringBuilder();
|
|
||||||
// while(true){
|
|
||||||
// read = stdout.read(buffer);
|
|
||||||
// if(read<0){
|
|
||||||
// MainActivity.myHandler.post(new Runnable() {
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// MainActivity.txt_results.append("Failed in TX_Sendfile\n");
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// out.append(new String(buffer, 0, read));
|
|
||||||
// if(read<20){
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// final String mOut = out.toString().trim();
|
|
||||||
// MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
|
||||||
// if (MainActivity.isVerbose) {
|
|
||||||
// MainActivity.myHandler.post(new Runnable() {
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (MainActivity.isVerbose)
|
|
||||||
Log.d("TX_Sendfile", "Stop TX Sendfile");
|
Log.d("TX_Sendfile", "Stop TX Sendfile");
|
||||||
|
|
||||||
MainActivity.isRunning_TX_Sendfile = false;
|
MainActivity.isRunning_TX_Sendfile = false;
|
||||||
MainActivity.perProcPID = -1;
|
MainActivity.perProcPID = -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,23 +9,29 @@ import java.io.InputStreamReader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by yanzi on 9/18/15.
|
* Created by yanzi on 9/18/15.
|
||||||
* Updated on 01/25/17
|
* Updated on 01/27/17
|
||||||
*/
|
*/
|
||||||
public class Thread_TX_CSplice implements Runnable {
|
|
||||||
|
class Thread_TX_CSplice implements Runnable {
|
||||||
private double sentBytes = 0.0;
|
private double sentBytes = 0.0;
|
||||||
private double duration = 0.0;
|
private double duration = 0.0;
|
||||||
private double throughput = 0.0;
|
private double throughput = 0.0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
// prevent multiple runs
|
||||||
if (MainActivity.isRunning_TX_Splice)
|
if (MainActivity.isRunning_TX_Splice)
|
||||||
return;
|
return;
|
||||||
if (MainActivity.isVerbose)
|
|
||||||
Log.d("TX_Splice", "Start TX Splice");
|
|
||||||
MainActivity.isRunning_TX_Splice = true;
|
MainActivity.isRunning_TX_Splice = true;
|
||||||
|
|
||||||
|
// variables
|
||||||
Process proc;
|
Process proc;
|
||||||
|
String stdout;
|
||||||
|
BufferedReader stdout_buf, error_buf;
|
||||||
String[] commd = new String[3];
|
String[] commd = new String[3];
|
||||||
|
|
||||||
|
MainActivity.isRunning_TX_Splice = true;
|
||||||
|
|
||||||
// get the right command
|
// get the right command
|
||||||
commd[0] = "su";
|
commd[0] = "su";
|
||||||
commd[1] = "-c";
|
commd[1] = "-c";
|
||||||
|
|
@ -39,6 +45,7 @@ public class Thread_TX_CSplice implements Runnable {
|
||||||
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
|
+ ((MainActivity.currentBandwidth < 0) ? "" : String.valueOf(
|
||||||
MainActivity.currentBandwidth));
|
MainActivity.currentBandwidth));
|
||||||
|
|
||||||
|
Log.d("TX_Splice", "Start TX Splice");
|
||||||
try {
|
try {
|
||||||
// run process
|
// run process
|
||||||
proc = Runtime.getRuntime().exec(commd);
|
proc = Runtime.getRuntime().exec(commd);
|
||||||
|
|
@ -50,14 +57,13 @@ public class Thread_TX_CSplice implements Runnable {
|
||||||
proc.waitFor();
|
proc.waitFor();
|
||||||
|
|
||||||
// read error
|
// read error
|
||||||
BufferedReader error_buf = new BufferedReader(new InputStreamReader(
|
error_buf = new BufferedReader(new InputStreamReader(
|
||||||
proc.getErrorStream()));
|
proc.getErrorStream()));
|
||||||
final String error = error_buf.readLine(); // only one line error
|
final String error = error_buf.readLine(); // only one line error
|
||||||
|
|
||||||
// read std out
|
// read std out
|
||||||
BufferedReader stdout_buf = new BufferedReader(new InputStreamReader(
|
stdout_buf = new BufferedReader(new InputStreamReader(
|
||||||
proc.getInputStream()));
|
proc.getInputStream()));
|
||||||
String stdout;
|
|
||||||
|
|
||||||
// get sent bytes
|
// get sent bytes
|
||||||
stdout = stdout_buf.readLine();
|
stdout = stdout_buf.readLine();
|
||||||
|
|
@ -91,54 +97,12 @@ public class Thread_TX_CSplice implements Runnable {
|
||||||
throughput = Utilities.parseBinOutput(stdout);
|
throughput = Utilities.parseBinOutput(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// commd[0] = "su";
|
} catch (IOException | InterruptedException e) {
|
||||||
// commd[1] = "-c";
|
|
||||||
// commd[2] = (MainActivity.isForcingCPU0?"taskset 1 ":"")
|
|
||||||
// + MainActivity.binaryFolderPath + MainActivity.binary_TX_Splice + " "
|
|
||||||
// + MainActivity.bytes2send + " " + String.valueOf(MainActivity.currentBandwidth);
|
|
||||||
// try {
|
|
||||||
// proc = Runtime.getRuntime().exec(commd);
|
|
||||||
// while (MainActivity.isLoggingPerProcPID && MainActivity.perProcPID == -1) {
|
|
||||||
// MainActivity.perProcPID = Utilities.getMyPID(MainActivity.binary_TX_Splice, false);
|
|
||||||
// }
|
|
||||||
// proc.waitFor();
|
|
||||||
// InputStream stdout = proc.getInputStream();
|
|
||||||
// byte[] buffer = new byte[20];
|
|
||||||
// int read;
|
|
||||||
// StringBuilder out = new StringBuilder();
|
|
||||||
// while(true){
|
|
||||||
// read = stdout.read(buffer);
|
|
||||||
// if(read<0){
|
|
||||||
// MainActivity.myHandler.post(new Runnable() {
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// MainActivity.txt_results.append("Failed in TX_Splice\n");
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// out.append(new String(buffer, 0, read));
|
|
||||||
// if(read<20){
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// final String mOut = out.toString().trim();
|
|
||||||
// MainActivity.reportedFinishTime = Double.parseDouble(mOut);
|
|
||||||
// if (MainActivity.isVerbose) {
|
|
||||||
// MainActivity.myHandler.post(new Runnable() {
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
// MainActivity.txt_results.append("Time: " + mOut + "ms\n");
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (MainActivity.isVerbose)
|
|
||||||
Log.d("TX_Splice", "Stop TX Splice");
|
Log.d("TX_Splice", "Stop TX Splice");
|
||||||
|
|
||||||
MainActivity.isRunning_TX_Splice = false;
|
MainActivity.isRunning_TX_Splice = false;
|
||||||
MainActivity.perProcPID = -1;
|
MainActivity.perProcPID = -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,18 +12,14 @@ import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -75,10 +71,7 @@ public class Utilities {
|
||||||
*/
|
*/
|
||||||
static boolean canWriteOnExternalStorage() {
|
static boolean canWriteOnExternalStorage() {
|
||||||
String state = Environment.getExternalStorageState();
|
String state = Environment.getExternalStorageState();
|
||||||
if (Environment.MEDIA_MOUNTED.equals(state)) {
|
return Environment.MEDIA_MOUNTED.equals(state);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -258,9 +251,7 @@ public class Utilities {
|
||||||
*/
|
*/
|
||||||
static boolean fileExist(String myFile) {
|
static boolean fileExist(String myFile) {
|
||||||
File file = new File(myFile);
|
File file = new File(myFile);
|
||||||
if (file.exists() && file.isFile())
|
return file.exists() && file.isFile();
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -271,17 +262,7 @@ public class Utilities {
|
||||||
*/
|
*/
|
||||||
static boolean dirExist(String myDirectory, boolean createIfNot) {
|
static boolean dirExist(String myDirectory, boolean createIfNot) {
|
||||||
File file = new File(myDirectory);
|
File file = new File(myDirectory);
|
||||||
if (file.exists() && file.isDirectory())
|
return (file.exists() && file.isDirectory()) || (createIfNot && file.mkdirs());
|
||||||
return true;
|
|
||||||
if (createIfNot) {
|
|
||||||
try{
|
|
||||||
file.mkdirs();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -417,7 +398,7 @@ public class Utilities {
|
||||||
* @param tmp: cpu usage
|
* @param tmp: cpu usage
|
||||||
* @return long: used cpu usage
|
* @return long: used cpu usage
|
||||||
*/
|
*/
|
||||||
static Long parseUsedCPU(String[] tmp, int offset) {
|
private static Long parseUsedCPU(String[] tmp, int offset) {
|
||||||
return (Long.parseLong(tmp[1 + offset])
|
return (Long.parseLong(tmp[1 + offset])
|
||||||
+ Long.parseLong(tmp[2 + offset])
|
+ Long.parseLong(tmp[2 + offset])
|
||||||
+ Long.parseLong(tmp[3 + offset])
|
+ Long.parseLong(tmp[3 + offset])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue