From 11db518fe9cc6556b056a7b2b859f93f7effcdaa Mon Sep 17 00:00:00 2001 From: Balint Kovacs Date: Tue, 3 May 2011 17:06:04 +0200 Subject: [PATCH] Polished log view to a usable stage Signed-off-by: Balint Kovacs --- AndroidManifest.xml | 4 +- default.properties | 2 +- res/layout/read_logs.xml | 8 ++- src/hu/blint/ssldroid/SSLDroidGui.java | 10 ++- src/hu/blint/ssldroid/SSLDroidReadLogs.java | 72 +++++++++++++++++---- 5 files changed, 79 insertions(+), 17 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 3dd3142..b457a73 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2,7 +2,6 @@ - @@ -12,6 +11,8 @@ + @@ -28,4 +29,5 @@ + \ No newline at end of file diff --git a/default.properties b/default.properties index 46769a7..e2e8061 100644 --- a/default.properties +++ b/default.properties @@ -8,4 +8,4 @@ # project structure. # Project target. -target=android-7 +target=android-8 diff --git a/res/layout/read_logs.xml b/res/layout/read_logs.xml index e389973..59e7f4b 100644 --- a/res/layout/read_logs.xml +++ b/res/layout/read_logs.xml @@ -2,6 +2,10 @@ - + android:layout_height="fill_parent" android:isScrollContainer="true"> + + + + + diff --git a/src/hu/blint/ssldroid/SSLDroidGui.java b/src/hu/blint/ssldroid/SSLDroidGui.java index 849d506..808a7a5 100644 --- a/src/hu/blint/ssldroid/SSLDroidGui.java +++ b/src/hu/blint/ssldroid/SSLDroidGui.java @@ -59,7 +59,7 @@ public class SSLDroidGui extends ListActivity { startService(new Intent(this, SSLDroid.class)); return true; case R.id.readlogs: - startService(new Intent(this, SSLDroid.class)); + readLogs(); return true; } return super.onMenuItemSelected(featureId, item); @@ -79,6 +79,9 @@ public class SSLDroidGui extends ListActivity { Log.d("SSLDroid", "Starting service"); startService(new Intent(this, SSLDroid.class)); return true; + case R.id.readlogs: + readLogs(); + return true; } return super.onOptionsItemSelected(item); } @@ -101,6 +104,11 @@ public class SSLDroidGui extends ListActivity { startActivityForResult(i, ACTIVITY_CREATE); } + private void readLogs() { + Intent i = new Intent(this, SSLDroidReadLogs.class); + startActivity(i); + } + // ListView and view (row) on which was clicked, position and @Override protected void onListItemClick(ListView l, View v, int position, long id) { diff --git a/src/hu/blint/ssldroid/SSLDroidReadLogs.java b/src/hu/blint/ssldroid/SSLDroidReadLogs.java index 32d1fc1..45f2a5a 100644 --- a/src/hu/blint/ssldroid/SSLDroidReadLogs.java +++ b/src/hu/blint/ssldroid/SSLDroidReadLogs.java @@ -6,6 +6,7 @@ import java.io.InputStreamReader; import android.app.Activity; import android.os.Bundle; +import android.util.Log; import android.widget.TextView; public class SSLDroidReadLogs extends Activity{ @@ -14,19 +15,66 @@ public class SSLDroidReadLogs extends Activity{ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.read_logs); - try { - Process process = Runtime.getRuntime().exec("logcat -d"); - BufferedReader bufferedReader = new BufferedReader( - new InputStreamReader(process.getInputStream())); + TextView logcontainer = (TextView) findViewById(R.id.logTextView); +/* try { + int[] tags = new int[1]; + tags[0] = 0; + Collection output = new HashSet(); + EventLog eventlog = new EventLog(); + eventlog.readEvents(tags, output); + //Log.i("test",Integer.toString(desc.mTag)); + logcontainer.setText("wtf"); + Iterator logs = output.iterator(); + while (logs.hasNext()){ + Log.d("SSLDroid", "Entry"); + EventLog.Event entry = logs.next(); + logcontainer.append(entry.getData().toString()); + } + } catch (IOException e) { + e.printStackTrace(); + } */ + + Process mLogcatProc = null; + BufferedReader reader = null; + try + { + mLogcatProc = Runtime.getRuntime().exec(new String[] + {"logcat", "-d", "SSLDroid:D SSLDroidGui:D *:S" }); - StringBuilder log=new StringBuilder(); - String line; - while ((line = bufferedReader.readLine()) != null) { - log.append(line); - } - TextView tv = (TextView)findViewById(R.id.logTextView); - tv.setText(log.toString()); - } catch (IOException e) { + reader = new BufferedReader(new InputStreamReader(mLogcatProc.getInputStream())); + + String line; + final StringBuilder log = new StringBuilder(); + String separator = System.getProperty("line.separator"); + + while ((line = reader.readLine()) != null) + { + log.append(line); + log.append(separator); + } + + logcontainer.setText(log); } + + catch (IOException e) + { + Log.d("SSLDroid", "Logcat problem: "+e.toString()); + } + + finally + { + if (reader != null) + try + { + reader.close(); + } + catch (IOException e) + { + Log.d("SSLDroid", "Logcat problem: "+e.toString()); + } + + } + } + }