Move jni stuff to NativeInterface.

Makes it more generic and extensible for the future.
This commit is contained in:
Themaister 2013-10-14 23:26:16 +02:00
parent b5c733f692
commit 773295cb28
7 changed files with 37 additions and 46 deletions

View File

@ -2,7 +2,7 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_MODULE := apk-extract
LOCAL_MODULE := retroarch-jni
RARCH_DIR := $(LOCAL_PATH)/../../..
LOCAL_CFLAGS += -std=gnu99 -Wall -DHAVE_LOGGER -DRARCH_DUMMY_LOG -DHAVE_ZLIB -DHAVE_MMAP -I$(RARCH_DIR)
LOCAL_LDLIBS := -llog -lz

View File

@ -2,7 +2,7 @@
#include "file.h"
#include <stdio.h>
#include "org_retroarch_browser_AssetExtractor.h"
#include "../native/org_retroarch_browser_NativeInterface.h"
struct userdata
{
@ -60,7 +60,7 @@ static bool zlib_cb(const char *name, const uint8_t *cdata, unsigned cmode, uint
return true;
}
JNIEXPORT jboolean JNICALL Java_org_retroarch_browser_AssetExtractor_extractArchiveTo(
JNIEXPORT jboolean JNICALL Java_org_retroarch_browser_NativeInterface_extractArchiveTo(
JNIEnv *env, jclass cls, jstring archive, jstring subdir, jstring dest)
{
const char *archive_c = (*env)->GetStringUTFChars(env, archive, NULL);

View File

@ -1,21 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_retroarch_browser_AssetExtractor */
#ifndef _Included_org_retroarch_browser_AssetExtractor
#define _Included_org_retroarch_browser_AssetExtractor
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_retroarch_browser_AssetExtractor
* Method: extractArchiveTo
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_org_retroarch_browser_AssetExtractor_extractArchiveTo
(JNIEnv *, jclass, jstring, jstring, jstring);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,21 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_retroarch_browser_NativeInterface */
#ifndef _Included_org_retroarch_browser_NativeInterface
#define _Included_org_retroarch_browser_NativeInterface
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_retroarch_browser_NativeInterface
* Method: extractArchiveTo
* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z
*/
JNIEXPORT jboolean JNICALL Java_org_retroarch_browser_NativeInterface_extractArchiveTo
(JNIEnv *, jclass, jstring, jstring, jstring);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,20 +0,0 @@
package org.retroarch.browser;
public final class AssetExtractor {
final private String archive;
public AssetExtractor(String archive) {
this.archive = archive;
}
static {
System.loadLibrary("apk-extract");
}
public boolean extractTo(String subDirectory, String destinationFolder) {
return extractArchiveTo(archive, subDirectory, destinationFolder);
}
private static native boolean extractArchiveTo(String archive,
String subDirectory, String destinationFolder);
}

View File

@ -124,8 +124,7 @@ public final class MainMenuActivity extends PreferenceActivity {
String apk = getApplicationInfo().sourceDir;
Log.i(TAG, "Extracting RetroArch assets from: " + apk + " ...");
AssetExtractor asset = new AssetExtractor(apk);
boolean success = asset.extractTo("assets", dataDir);
boolean success = NativeInterface.extractArchiveTo(apk, "assets", dataDir);
if (!success) {
throw new IOException("Failed to extract assets ...");
}

View File

@ -0,0 +1,12 @@
package org.retroarch.browser;
// Helper class which calls into JNI for various tasks.
public final class NativeInterface {
static {
System.loadLibrary("retroarch-jni");
}
public static native boolean extractArchiveTo(String archive,
String subDirectory, String destinationFolder);
}