#include <jni.h>
#include <string.h>
#include <stdlib.h>
#include <android/log.h>
#include "android_breakpad.h"

#define TAG "crash.c"

// globals

JNIEnv *stored_env;
char crash_dir[255];

// Java native calls

JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *jvm, void *reserved) {
    __android_log_print(ANDROID_LOG_DEBUG, TAG, "OnLoad()");
    return JNI_VERSION_1_6;
}

JNIEXPORT void JNICALL
Java_com_avg_zaap_crashlibrary_CrashLib_initializeNativeLibrary(JNIEnv *env, jclass clazz,
                                                                jstring crashDir_) {
    __android_log_write(ANDROID_LOG_DEBUG, TAG, "initializeNativeLibrary() called");

    // parameter conversion
    const char *param_internal_files_dir = (*env)->GetStringUTFChars(env, crashDir_, 0);
    strcpy(crash_dir, param_internal_files_dir);
    (*env)->ReleaseStringUTFChars(env, crashDir_, param_internal_files_dir);

    // method body
    initializeBreakpad(crash_dir);
}
