Commit ffbbb880 authored by Thomas Guillem's avatar Thomas Guillem

remove native crash handler

This not working since android 5.0, this prevent us to have useful native
traces (that can be used with ndk-stack) and this mess up native crash report
on the Google Play Developer Console.
parent fdb66fbf
......@@ -28,7 +28,7 @@ LOCAL_SRC_FILES += libvlcjni-mediaplayer.c
LOCAL_SRC_FILES += libvlcjni-vlcobject.c
LOCAL_SRC_FILES += libvlcjni-media.c libvlcjni-medialist.c libvlcjni-mediadiscoverer.c
LOCAL_SRC_FILES += libvlcjni-dialog.c
LOCAL_SRC_FILES += native_crash_handler.c thumbnailer.c
LOCAL_SRC_FILES += thumbnailer.c
LOCAL_SRC_FILES += std_logger.c
LOCAL_LDLIBS := -llog
......
......@@ -36,7 +36,6 @@
#include "libvlcjni-vlcobject.h"
#include "utils.h"
#include "native_crash_handler.h"
#include "std_logger.h"
struct fields fields;
......@@ -161,8 +160,6 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
fields.FileDescriptor.descriptorID,
fields.FileDescriptor.clazz,
"descriptor", "I");
GET_CLASS(fields.LibVLC.clazz,
"org/videolan/libvlc/LibVLC", true);
GET_CLASS(fields.VLCObject.clazz,
"org/videolan/libvlc/VLCObject", true);
GET_CLASS(fields.Media.clazz,
......@@ -188,11 +185,6 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
GET_CLASS(fields.Dialog.clazz,
"org/videolan/libvlc/Dialog", true);
GET_ID(GetStaticMethodID,
fields.LibVLC.onNativeCrashID,
fields.LibVLC.clazz,
"onNativeCrash", "()V");
GET_ID(GetFieldID,
fields.VLCObject.mInstanceID,
fields.VLCObject.clazz,
......@@ -335,8 +327,6 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
#undef GET_CLASS
#undef GET_ID
init_native_crash_handler();
LOGD("JNI interface loaded.");
return VLC_JNI_VERSION;
}
......@@ -345,8 +335,6 @@ void JNI_OnUnload(JavaVM* vm, void* reserved)
{
JNIEnv* env = NULL;
destroy_native_crash_handler();
if ((*vm)->GetEnv(vm, (void**) &env, VLC_JNI_VERSION) != JNI_OK)
return;
......
/*****************************************************************************
* native_crash_handler.c
*****************************************************************************
* Copyright © 2010-2014 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <stdbool.h>
#include <signal.h>
#include "native_crash_handler.h"
#include "utils.h"
static struct sigaction old_actions[NSIG];
#define THREAD_NAME "native_crash_handler"
extern JNIEnv *jni_get_env(const char *name);
// Monitored signals.
static const int monitored_signals[] = {
SIGILL,
SIGABRT,
SIGBUS,
SIGFPE,
SIGSEGV,
#ifndef _MIPS_ARCH
SIGSTKFLT,
#else
SIGEMT,
#endif
SIGPIPE
};
/**
* Callback called when a monitored signal is triggered.
*/
void sigaction_callback(int signal, siginfo_t *info, void *reserved)
{
JNIEnv *env;
if (!(env = jni_get_env(THREAD_NAME)))
return;
// Call the Java LibVLC method that handle the crash.
(*env)->CallStaticVoidMethod(env, fields.LibVLC.clazz,
fields.LibVLC.onNativeCrashID);
// Call the old signal handler.
old_actions[signal].sa_handler(signal);
}
void init_native_crash_handler()
{
struct sigaction handler;
memset(&handler, 0, sizeof(struct sigaction));
handler.sa_sigaction = sigaction_callback;
handler.sa_flags = SA_RESETHAND;
// Install the signal handlers and save their old actions.
for (unsigned i = 0; i < sizeof(monitored_signals) / sizeof(int); ++i)
{
const int s = monitored_signals[i];
sigaction(s, &handler, &old_actions[s]);
}
}
void destroy_native_crash_handler()
{
// Uninstall the signal handlers and restore their old actions.
for (unsigned i = 0; i < sizeof(monitored_signals) / sizeof(int); ++i)
{
const int s = monitored_signals[i];
sigaction(s, &old_actions[s], NULL);
}
}
/*****************************************************************************
* native_crash_handler.h
*****************************************************************************
* Copyright © 2010-2013 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef LIBVLCJNI_NATIVE_CRASH_HANDLER_H
#define LIBVLCJNI_NATIVE_CRASH_HANDLER_H
#include <jni.h>
void init_native_crash_handler();
void destroy_native_crash_handler();
#endif // LIBVLCJNI_NATIVE_CRASH_HANDLER_H
......@@ -40,10 +40,6 @@ struct fields {
jclass clazz;
jfieldID descriptorID;
} FileDescriptor;
struct {
jclass clazz;
jmethodID onNativeCrashID;
} LibVLC;
struct {
jclass clazz;
jfieldID mInstanceID;
......
......@@ -38,9 +38,6 @@ public class LibVLC extends VLCObject<LibVLC.Event> {
}
}
/** Native crash handler */
private static OnNativeCrashListener sOnNativeCrashListener;
/**
* Create a LibVLC withs options
*
......@@ -117,19 +114,6 @@ public class LibVLC extends VLCObject<LibVLC.Event> {
nativeRelease();
}
public interface OnNativeCrashListener {
void onNativeCrash();
}
public static void setOnNativeCrashListener(OnNativeCrashListener l) {
sOnNativeCrashListener = l;
}
private static void onNativeCrash() {
if (sOnNativeCrashListener != null)
sOnNativeCrashListener.onNativeCrash();
}
/**
* Sets the application name. LibVLC passes this as the user agent string
* when a protocol requires it.
......
package org.videolan.vlc.gui;
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;
import android.widget.TextView;
import org.videolan.vlc.R;
import org.videolan.vlc.StartActivity;
import org.videolan.vlc.util.Logcat;
import org.videolan.vlc.util.Util;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.zip.GZIPOutputStream;
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) {
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);
mSendLog = (Button) findViewById(R.id.send_log);
mSendLog.setEnabled(false);
mRestartButton.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
android.os.Process.killProcess(android.os.Process.myPid());
Intent i = new Intent(NativeCrashActivity.this, StartActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
finish();
}
});
mSendLog.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
String buildDate = "Build date: " + getString(R.string.build_time);
String builder = "Builder: " + getString(R.string.build_host);
String revision = "Revision: " + getString(R.string.build_revision);
AsyncHttpRequest asyncHttpRequest = new AsyncHttpRequest();
asyncHttpRequest.execute(Build.BRAND, Build.MANUFACTURER, Build.PRODUCT, Build.MODEL,
Build.DEVICE, Build.VERSION.RELEASE,
buildDate, builder, revision, mLog);
}
});
new LogTask().execute();
}
class LogTask extends AsyncTask<Void, Void, String>
{
@Override
protected String doInBackground(Void... v) {
String log = null;
try {
log = Logcat.getLogcat();
} catch (IOException e) {
e.printStackTrace();
}
return log;
}
@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;
HttpURLConnection urlConnection = null;
try {
URL url = new URL("http://people.videolan.org/~magsoft/vlc-android_crashes/upload_crash_log.php");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setRequestMethod("POST");
urlConnection.setDoInput(true);
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
StringBuilder msgBuilder = new StringBuilder();
for (int i = 0; i < params.length; ++i) {
msgBuilder.append(params[i]);
msgBuilder.append("\n");
}
byte[] body = compress(msgBuilder.toString());
urlConnection.setFixedLengthStreamingMode(body.length);
out.write(body);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (urlConnection != null)
urlConnection.disconnect();
}
return true;
}
private byte[] compress(String string) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream(string.length());
GZIPOutputStream gos = new GZIPOutputStream(os);
gos.write(string.getBytes());
Util.close(gos);
byte[] compressed = os.toByteArray();
Util.close(os);
return compressed;
}
@Override
protected void onPostExecute(Boolean result) {
mProgressDialog.cancel();
mSendLog.setEnabled(false);
}
}
}
......@@ -31,7 +31,6 @@ import org.videolan.libvlc.util.VLCUtil;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.VLCCrashHandler;
import org.videolan.vlc.gui.CompatErrorActivity;
import org.videolan.vlc.gui.NativeCrashActivity;
public class VLCInstance {
public final static String TAG = "VLC/UiTools/VLCInstance";
......@@ -60,15 +59,6 @@ public class VLCInstance {
}
sLibVLC = new LibVLC(context, VLCOptions.getLibOptions());
LibVLC.setOnNativeCrashListener(new LibVLC.OnNativeCrashListener() {
@Override
public void onNativeCrash() {
Intent i = new Intent(context, NativeCrashActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
});
VLCApplication.runBackground(sCopyLua);
}
return sLibVLC;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment