Add open files to logcat, show percentage files open

refs #307
This commit is contained in:
M66B 2016-02-10 20:17:22 +01:00
parent d5911f8a51
commit 2e185d184a
3 changed files with 55 additions and 13 deletions

View File

@ -633,11 +633,30 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
else
remoteViews.setTextViewText(R.id.tvRx, getString(R.string.msg_mbsec, rxsec / 1000 / 1000));
// Show session/file count
if (filter && loglevel <= Log.WARN) {
int[] count = jni_get_session_count();
remoteViews.setTextViewText(R.id.tvSessions, count[0] + "/" + count[1] + "/" + count[2]);
} else
remoteViews.setTextViewText(R.id.tvSessions, "");
File proc = new File("/proc/sys/fs/file-nr");
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(proc));
String line = br.readLine();
String[] filenr = line.split("\\s+");
if (filenr.length == 3) {
int perc = Integer.parseInt(filenr[0]) * 100 / Integer.parseInt(filenr[2]);
remoteViews.setTextViewText(R.id.tvFiles, perc + "%");
}
} catch (Throwable ignored) {
} finally {
if (br != null)
try {
br.close();
} catch (IOException ignored) {
}
}
}
// Show notification
Intent main = new Intent(SinkholeService.this, ActivityMain.class);

View File

@ -757,7 +757,7 @@ public class Util {
// Build intent
Intent sendEmail = new Intent(Intent.ACTION_SEND);
sendEmail.setType("message/rfc822");
sendEmail.putExtra(Intent.EXTRA_EMAIL, new String[]{"marcel+netguard@faircode.eu"});
sendEmail.putExtra(Intent.EXTRA_EMAIL, new String[]{"marcel+netguard@faircode.eu" });
sendEmail.putExtra(Intent.EXTRA_SUBJECT, "NetGuard " + version + " logcat");
sendEmail.putExtra(Intent.EXTRA_TEXT, sb.toString());
sendEmail.putExtra(Intent.EXTRA_STREAM, uri);
@ -779,12 +779,13 @@ public class Util {
private static StringBuilder getLogcat() {
StringBuilder builder = new StringBuilder();
Process process = null;
Process process1 = null;
Process process2 = null;
BufferedReader br = null;
try {
String[] command = new String[]{"logcat", "-d", "-v", "threadtime"};
process = Runtime.getRuntime().exec(command);
br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String[] command1 = new String[]{"logcat", "-d", "-v", "threadtime" };
process1 = Runtime.getRuntime().exec(command1);
br = new BufferedReader(new InputStreamReader(process1.getInputStream()));
int count = 0;
String line;
while ((line = br.readLine()) != null) {
@ -792,6 +793,13 @@ public class Util {
builder.append(line).append("\r\n");
}
Log.i(TAG, "Logcat lines=" + count);
String[] command2 = new String[]{"ls", "-l", "/proc/" + android.os.Process.myPid() + "/fd" };
process2 = Runtime.getRuntime().exec(command2);
br = new BufferedReader(new InputStreamReader(process2.getInputStream()));
while ((line = br.readLine()) != null)
builder.append(line).append("\r\n");
} catch (IOException ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
} finally {
@ -800,9 +808,15 @@ public class Util {
br.close();
} catch (IOException ignored) {
}
if (process != null)
if (process2 != null)
try {
process.destroy();
process2.destroy();
} catch (Throwable ex) {
Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
if (process1 != null)
try {
process1.destroy();
} catch (Throwable ex) {
Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}

View File

@ -47,6 +47,16 @@
android:textColor="@color/colorReceive" />
</LinearLayout>
<TextView
android:id="@+id/tvSessions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Info"
android:textSize="10sp" />
<TextView
android:id="@+id/tvTop"
android:layout_width="wrap_content"
@ -59,13 +69,12 @@
android:textSize="10sp" />
<TextView
android:id="@+id/tvSessions"
android:id="@+id/tvFiles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:singleLine="false"
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Info"
android:textSize="10sp" />