[Android] GUI: add an activity to show the application logcat when it crashes in native code

Adrien Maglo git at videolan.org
Thu May 8 11:50:58 CEST 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Thu May  8 11:46:13 2014 +0200| [3f0050659c813bd4d0af9306e1387be2cf09eb8d] | committer: Adrien Maglo

GUI: add an activity to show the application logcat when it crashes in native code

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

 vlc-android/AndroidManifest.xml                    |    5 ++
 vlc-android/res/layout/native_crash.xml            |   35 +++++++++++
 vlc-android/res/values/strings.xml                 |    3 +
 .../org/videolan/vlc/gui/NativeCrashActivity.java  |   63 ++++++++++++++++++++
 4 files changed, 106 insertions(+)

diff --git a/vlc-android/AndroidManifest.xml b/vlc-android/AndroidManifest.xml
index a1d9de7..0aa94a0 100644
--- a/vlc-android/AndroidManifest.xml
+++ b/vlc-android/AndroidManifest.xml
@@ -46,6 +46,11 @@
             android:theme="@style/Theme.VLC.NoTitleBar" />
         <activity android:name=".gui.DebugLogActivity" />
         <activity
+            android:name=".gui.NativeCrashActivity"
+            android:process=":NativeCrashActivity"
+            android:stateNotNeeded="true"
+            android:theme="@style/Theme.VLC" />
+        <activity
             android:name=".gui.video.VideoPlayerActivity"
             android:configChanges="orientation|screenSize"
             android:theme="@style/Theme.VLC.Fullscreen" >
diff --git a/vlc-android/res/layout/native_crash.xml b/vlc-android/res/layout/native_crash.xml
new file mode 100644
index 0000000..0d43267
--- /dev/null
+++ b/vlc-android/res/layout/native_crash.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:layout_marginTop="?attr/marginTopContent"
+    android:orientation="vertical" >
+
+    <TextView
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:gravity="center_horizontal"
+        android:text="@string/serious_crash"
+        android:textSize="24sp" />
+
+    <ScrollView
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        android:layout_margin="10dp"
+        android:scrollbars="vertical" >
+
+        <TextView
+            android:id="@+id/crash_log"
+            android:layout_width="fill_parent"
+            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>
\ No newline at end of file
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 8779fbe..9c63b90 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -263,6 +263,9 @@
     <string name="dump_logcat_success">Logcat successfully dumped to %1$s!</string>
     <string name="dump_logcat_failure">Failed to dump logcat.</string>
 
+    <string name="serious_crash">Sorry, a serious crash has occured…</string>
+    <string name="restart_vlc">Restart VLC</string>
+
     <string-array name="hardware_acceleration_list">
         <item>@string/automatic</item>
         <item>@string/hardware_acceleration_disabled</item>
diff --git a/vlc-android/src/org/videolan/vlc/gui/NativeCrashActivity.java b/vlc-android/src/org/videolan/vlc/gui/NativeCrashActivity.java
new file mode 100644
index 0000000..12815e8
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/NativeCrashActivity.java
@@ -0,0 +1,63 @@
+package org.videolan.vlc.gui;
+
+import java.io.IOException;
+
+import org.videolan.vlc.R;
+import org.videolan.vlc.Util;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.TextView;
+
+public class NativeCrashActivity extends Activity {
+
+    private TextView mCrashLog;
+    private Button mRestartButton;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.native_crash);
+
+        mCrashLog = (TextView) findViewById(R.id.crash_log);
+        mRestartButton = (Button) findViewById(R.id.restart_vlc);
+        mRestartButton.setEnabled(false);
+
+        mRestartButton.setOnClickListener(new Button.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                Intent i = new Intent(NativeCrashActivity.this, MainActivity.class);
+                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                startActivity(i);
+                finish();
+            }
+        });
+
+        new LogTask().execute();
+    }
+
+    class LogTask extends AsyncTask<Void, Void, String>
+    {
+        @Override
+        protected String doInBackground(Void... v) {
+            String log = null;
+            try {
+                log = Util.getLogcat();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            return log;
+        }
+
+        @Override
+        protected void onPostExecute(String log) {
+            mCrashLog.setText(log);
+            mRestartButton.setEnabled(true);
+        }
+    }
+
+}



More information about the Android mailing list