Commits

Michael Knight committed c61c06f

Sum up bandwidth difference across all network devices.

  • Participants
  • Parent commits 7e08d4b

Comments (0)

Files changed (1)

src/com/miknight/bameter/BameterActivity.java

     	String downloadOutput = "";
     	String uploadOutput = "";
     	String debug = "";
+        long newDownloaded = 0;
+        long newUploaded = 0;
     	try {
     		p = Runtime.getRuntime().exec("cat /proc/net/dev");
     		BufferedReader istream = new BufferedReader(new InputStreamReader(p.getInputStream()));
     		String line;
     		while ((line = istream.readLine()) != null) {
     			debug += line + "\n";
-    			if (line.matches(".*" + device + ":.*") || line.matches(".*rmnet0.*")) {
+    			//if (line.matches(".*" + device + ":.*") || line.matches(".*rmnet0.*")) {
+    			// Collect I/O from all devices.
+    			// TODO: Exclude loopback.
+    			if (line.matches(".*[a-z0-9]+:.*")) {
     				downloadOutput = line.split("\\s+")[2];
     				uploadOutput = line.split("\\s+")[10];
+    				newDownloaded += Long.parseLong(downloadOutput);
+    				newUploaded += Long.parseLong(uploadOutput);
     			}
     		}
     	} catch (IOException e) {
     	if (downloadOutput.isEmpty() || uploadOutput.isEmpty()) {
     		output = debug;
     	} else {
-    		long newDownloaded = Long.parseLong(downloadOutput);
-    		long d_diff = (newDownloaded - downloaded);
-    		long newUploaded = Long.parseLong(uploadOutput);
-    		long u_diff = (newUploaded - uploaded);
+			long d_diff = (newDownloaded - downloaded);
+			long u_diff = (newUploaded - uploaded);
     		output = d_diff/1024 + " KB/s down,\n"
     				+ u_diff/1024 + " KB/s up.\n";
     		downloaded = newDownloaded;
     public void exitApplication(View view) {
     	NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
     	nm.cancelAll();
-        System.exit(0);
+        this.finish();
+
     }
 }