[Android] NativeCrashActivity: add a button to send the gziped context crash log to a remote server

Adrien Maglo git at videolan.org
Mon May 12 13:28:16 CEST 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Mon May 12 13:28:06 2014 +0200| [00c5a3f9796fbcc9663d9be87b61967ae85ff850] | committer: Adrien Maglo

NativeCrashActivity: add a button to send the gziped context crash log to a remote server

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=00c5a3f9796fbcc9663d9be87b61967ae85ff850
---

 vlc-android/res/layout/native_crash.xml            |   35 +++++++--
 vlc-android/res/values/strings.xml                 |    3 +
 .../org/videolan/vlc/gui/NativeCrashActivity.java  |   75 ++++++++++++++++++++
 3 files changed, 106 insertions(+), 7 deletions(-)

diff --git a/vlc-android/res/layout/native_crash.xml b/vlc-android/res/layout/native_crash.xml
index 0d43267..b8a8242 100644
--- a/vlc-android/res/layout/native_crash.xml
+++ b/vlc-android/res/layout/native_crash.xml
@@ -12,11 +12,18 @@
         android:text="@string/serious_crash"
         android:textSize="24sp" />
 
+    <TextView
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginLeft="10dp"
+        android:layout_marginRight="10dp"
+        android:text="@string/help_us_send_log" />
+
     <ScrollView
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
-        android:layout_weight="1"
         android:layout_margin="10dp"
+        android:layout_weight="1"
         android:scrollbars="vertical" >
 
         <TextView
@@ -25,11 +32,25 @@
             android:layout_height="wrap_content" />
     </ScrollView>
 
-    <Button
-        android:id="@+id/restart_vlc"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="center_horizontal"
-        android:text="@string/restart_vlc" />
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" >
+
+        <Button
+            android:id="@+id/send_log"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            android:layout_weight="1"
+            android:text="@string/send_log" />
+
+        <Button
+            android:id="@+id/restart_vlc"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal"
+            android:layout_weight="1"
+            android:text="@string/restart_vlc" />
+    </LinearLayout>
 
 </LinearLayout>
\ No newline at end of file
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 8d1bcb2..19b7c9a 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -264,7 +264,10 @@
     <string name="dump_logcat_failure">Failed to dump logcat.</string>
 
     <string name="serious_crash">Unfortunately, a serious error has occured and VLC had to close.</string>
+    <string name="help_us_send_log">Help us improving VLC by sending the following crash log:</string>
     <string name="restart_vlc">Restart VLC</string>
+    <string name="send_log">Send the log</string>
+    <string name="sending_log">Sending the log…</string>
 
     <string-array name="hardware_acceleration_list">
         <item>@string/automatic</item>
diff --git a/vlc-android/src/org/videolan/vlc/gui/NativeCrashActivity.java b/vlc-android/src/org/videolan/vlc/gui/NativeCrashActivity.java
index 12815e8..f8e653d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/NativeCrashActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/NativeCrashActivity.java
@@ -1,13 +1,23 @@
 package org.videolan.vlc.gui;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.util.zip.GZIPOutputStream;
 
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
 import org.videolan.vlc.R;
 import org.videolan.vlc.Util;
 
 import android.app.Activity;
+import android.app.ProgressDialog;
 import android.content.Intent;
 import android.os.AsyncTask;
+import android.os.Build;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;
@@ -17,6 +27,11 @@ public class NativeCrashActivity extends Activity {
 
     private TextView mCrashLog;
     private Button mRestartButton;
+    private Button mSendLog;
+
+    private ProgressDialog mProgressDialog;
+
+    private String mLog;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -26,6 +41,8 @@ public class NativeCrashActivity extends Activity {
         mCrashLog = (TextView) findViewById(R.id.crash_log);
         mRestartButton = (Button) findViewById(R.id.restart_vlc);
         mRestartButton.setEnabled(false);
+        mSendLog = (Button) findViewById(R.id.send_log);
+        mSendLog.setEnabled(false);
 
         mRestartButton.setOnClickListener(new Button.OnClickListener() {
             @Override
@@ -37,6 +54,14 @@ public class NativeCrashActivity extends Activity {
             }
         });
 
+        mSendLog.setOnClickListener(new Button.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                AsyncHttpRequest asyncHttpRequest = new AsyncHttpRequest();
+                asyncHttpRequest.execute(Build.MODEL, Build.DEVICE, mLog);
+            }
+        });
+
         new LogTask().execute();
     }
 
@@ -55,8 +80,58 @@ public class NativeCrashActivity extends Activity {
 
         @Override
         protected void onPostExecute(String log) {
+            mLog = log;
             mCrashLog.setText(log);
             mRestartButton.setEnabled(true);
+            mSendLog.setEnabled(true);
+        }
+    }
+
+    public class AsyncHttpRequest extends AsyncTask<String, String, Boolean> {
+
+        @Override
+        protected void onPreExecute() {
+            mProgressDialog = new ProgressDialog(NativeCrashActivity.this);
+            mProgressDialog.setMessage(NativeCrashActivity.this.getText(R.string.sending_log));
+            mProgressDialog.show();
+        }
+
+        @Override
+        protected Boolean doInBackground(String... params) {
+            if (params[0].length() == 0)
+                return false;
+            HttpClient httpClient = new DefaultHttpClient();
+            // FIXME: move this script to a Videolan server.
+            HttpPost httpPost = new HttpPost("http://magsoft.dinauz.org/videolan/vlc-android/upload_crash_log.php");
+
+            try {
+                httpPost.setEntity(new ByteArrayEntity(
+                        compress(params[0] + "\n" + params[1] + "\n" + params[2])));
+                httpClient.execute(httpPost);
+            } catch (ClientProtocolException e) {
+                e.printStackTrace();
+                return false;
+            } catch (IOException e) {
+                e.printStackTrace();
+                return false;
+            }
+            return true;
+        }
+
+        private byte[] compress(String string) throws IOException {
+            ByteArrayOutputStream os = new ByteArrayOutputStream(string.length());
+            GZIPOutputStream gos = new GZIPOutputStream(os);
+            gos.write(string.getBytes());
+            gos.close();
+            byte[] compressed = os.toByteArray();
+            os.close();
+            return compressed;
+        }
+
+        @Override
+        protected void onPostExecute(Boolean result) {
+            mProgressDialog.cancel();
+            mSendLog.setEnabled(false);
         }
     }
 



More information about the Android mailing list