Merge "Remove dependency on libnativehelper/JniConstants.h" am: 8d7f7a4ada
am: 107a8e7582
Change-Id: Ia6dae72a882e4f5298df3b9895a396ef4dcb0093
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
#include "android_media_AudioTrack.h"
|
||||
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <nativehelper/JniConstants.h>
|
||||
#include "core_jni_helpers.h"
|
||||
|
||||
#include <utils/Log.h>
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
|
||||
#include <utils/Log.h>
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <nativehelper/JniConstants.h>
|
||||
#include "core_jni_helpers.h"
|
||||
#include <media/AudioSystem.h>
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@
|
||||
|
||||
#include <cutils/ashmem.h>
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include <nativehelper/jni_macros.h>
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <nativehelper/JniConstants.h>
|
||||
#include <nativehelper/ScopedLocalRef.h>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -31,10 +32,10 @@
|
||||
|
||||
namespace {
|
||||
|
||||
static void throwErrnoException(JNIEnv* env, const char* functionName, int error) {
|
||||
static jmethodID ctor = env->GetMethodID(JniConstants::errnoExceptionClass,
|
||||
"<init>", "(Ljava/lang/String;I)V");
|
||||
jclass errnoExceptionClass;
|
||||
jmethodID errnoExceptionCtor; // MethodID for ErrnoException.<init>(String,I)
|
||||
|
||||
void throwErrnoException(JNIEnv* env, const char* functionName, int error) {
|
||||
ScopedLocalRef<jstring> detailMessage(env, env->NewStringUTF(functionName));
|
||||
if (detailMessage.get() == NULL) {
|
||||
// Not really much we can do here. We're probably dead in the water,
|
||||
@@ -42,12 +43,14 @@ static void throwErrnoException(JNIEnv* env, const char* functionName, int error
|
||||
env->ExceptionClear();
|
||||
}
|
||||
|
||||
jobject exception = env->NewObject(JniConstants::errnoExceptionClass, ctor,
|
||||
detailMessage.get(), error);
|
||||
jobject exception = env->NewObject(errnoExceptionClass,
|
||||
errnoExceptionCtor,
|
||||
detailMessage.get(),
|
||||
error);
|
||||
env->Throw(reinterpret_cast<jthrowable>(exception));
|
||||
}
|
||||
|
||||
static jobject SharedMemory_create(JNIEnv* env, jobject, jstring jname, jint size) {
|
||||
jobject SharedMemory_nCreate(JNIEnv* env, jobject, jstring jname, jint size) {
|
||||
|
||||
// Name is optional so we can't use ScopedUtfChars for this as it throws NPE on null
|
||||
const char* name = jname ? env->GetStringUTFChars(jname, nullptr) : nullptr;
|
||||
@@ -69,7 +72,7 @@ static jobject SharedMemory_create(JNIEnv* env, jobject, jstring jname, jint siz
|
||||
return jniCreateFileDescriptor(env, fd);
|
||||
}
|
||||
|
||||
static jint SharedMemory_getSize(JNIEnv* env, jobject, jobject fileDescriptor) {
|
||||
jint SharedMemory_nGetSize(JNIEnv* env, jobject, jobject fileDescriptor) {
|
||||
int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
|
||||
if (!ashmem_valid(fd)) {
|
||||
return -1;
|
||||
@@ -78,7 +81,7 @@ static jint SharedMemory_getSize(JNIEnv* env, jobject, jobject fileDescriptor) {
|
||||
return static_cast<jint>(std::min(size, static_cast<size_t>(std::numeric_limits<jint>::max())));
|
||||
}
|
||||
|
||||
static jint SharedMemory_setProt(JNIEnv* env, jobject, jobject fileDescriptor, jint prot) {
|
||||
jint SharedMemory_nSetProt(JNIEnv* env, jobject, jobject fileDescriptor, jint prot) {
|
||||
int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
|
||||
int err = 0;
|
||||
if (ashmem_set_prot_region(fd, prot)) {
|
||||
@@ -87,18 +90,21 @@ static jint SharedMemory_setProt(JNIEnv* env, jobject, jobject fileDescriptor, j
|
||||
return err;
|
||||
}
|
||||
|
||||
static const JNINativeMethod methods[] = {
|
||||
{"nCreate", "(Ljava/lang/String;I)Ljava/io/FileDescriptor;", (void*)SharedMemory_create},
|
||||
{"nGetSize", "(Ljava/io/FileDescriptor;)I", (void*)SharedMemory_getSize},
|
||||
{"nSetProt", "(Ljava/io/FileDescriptor;I)I", (void*)SharedMemory_setProt},
|
||||
const JNINativeMethod methods[] = {
|
||||
NATIVE_METHOD(SharedMemory, nCreate, "(Ljava/lang/String;I)Ljava/io/FileDescriptor;"),
|
||||
NATIVE_METHOD(SharedMemory, nGetSize, "(Ljava/io/FileDescriptor;)I"),
|
||||
NATIVE_METHOD(SharedMemory, nSetProt, "(Ljava/io/FileDescriptor;I)I")
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace android {
|
||||
|
||||
int register_android_os_SharedMemory(JNIEnv* env)
|
||||
{
|
||||
int register_android_os_SharedMemory(JNIEnv* env) {
|
||||
errnoExceptionClass =
|
||||
MakeGlobalRefOrDie(env, FindClassOrDie(env, "android/system/ErrnoException"));
|
||||
errnoExceptionCtor =
|
||||
GetMethodIDOrDie(env, errnoExceptionClass, "<init>", "(Ljava/lang/String;I)V");
|
||||
return RegisterMethodsOrDie(env, "android/os/SharedMemory", methods, NELEM(methods));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,24 +22,26 @@
|
||||
|
||||
#include <log/log.h>
|
||||
|
||||
#include <nativehelper/jni_macros.h>
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
#include <nativehelper/JniConstants.h>
|
||||
#include <nativehelper/ScopedLocalRef.h>
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
#include "jni.h"
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
#include "ziparchive/zip_archive.h"
|
||||
|
||||
namespace android {
|
||||
namespace {
|
||||
|
||||
jclass zipEntryClass;
|
||||
// The method ID for ZipEntry.<init>(String,String,JJJIII[BJJ)
|
||||
static jmethodID zipEntryCtor;
|
||||
jmethodID zipEntryCtor;
|
||||
|
||||
static void throwIoException(JNIEnv* env, const int32_t errorCode) {
|
||||
void throwIoException(JNIEnv* env, const int32_t errorCode) {
|
||||
jniThrowException(env, "java/io/IOException", ErrorCodeString(errorCode));
|
||||
}
|
||||
|
||||
static jobject newZipEntry(JNIEnv* env, const ZipEntry& entry, jstring entryName) {
|
||||
return env->NewObject(JniConstants::zipEntryClass,
|
||||
jobject newZipEntry(JNIEnv* env, const ZipEntry& entry, jstring entryName) {
|
||||
return env->NewObject(zipEntryClass,
|
||||
zipEntryCtor,
|
||||
entryName,
|
||||
NULL, // comment
|
||||
@@ -52,7 +54,7 @@ static jobject newZipEntry(JNIEnv* env, const ZipEntry& entry, jstring entryName
|
||||
static_cast<jlong>(entry.offset));
|
||||
}
|
||||
|
||||
static jlong StrictJarFile_nativeOpenJarFile(JNIEnv* env, jobject, jstring name, jint fd) {
|
||||
jlong StrictJarFile_nativeOpenJarFile(JNIEnv* env, jobject, jstring name, jint fd) {
|
||||
// Name argument is used for logging, and can be any string.
|
||||
ScopedUtfChars nameChars(env, name);
|
||||
if (nameChars.c_str() == NULL) {
|
||||
@@ -90,7 +92,7 @@ class IterationHandle {
|
||||
};
|
||||
|
||||
|
||||
static jlong StrictJarFile_nativeStartIteration(JNIEnv* env, jobject, jlong nativeHandle,
|
||||
jlong StrictJarFile_nativeStartIteration(JNIEnv* env, jobject, jlong nativeHandle,
|
||||
jstring prefix) {
|
||||
ScopedUtfChars prefixChars(env, prefix);
|
||||
if (prefixChars.c_str() == NULL) {
|
||||
@@ -116,7 +118,7 @@ static jlong StrictJarFile_nativeStartIteration(JNIEnv* env, jobject, jlong nati
|
||||
return reinterpret_cast<jlong>(handle);
|
||||
}
|
||||
|
||||
static jobject StrictJarFile_nativeNextEntry(JNIEnv* env, jobject, jlong iterationHandle) {
|
||||
jobject StrictJarFile_nativeNextEntry(JNIEnv* env, jobject, jlong iterationHandle) {
|
||||
ZipEntry data;
|
||||
ZipString entryName;
|
||||
|
||||
@@ -135,7 +137,7 @@ static jobject StrictJarFile_nativeNextEntry(JNIEnv* env, jobject, jlong iterati
|
||||
return newZipEntry(env, data, entryNameString.get());
|
||||
}
|
||||
|
||||
static jobject StrictJarFile_nativeFindEntry(JNIEnv* env, jobject, jlong nativeHandle,
|
||||
jobject StrictJarFile_nativeFindEntry(JNIEnv* env, jobject, jlong nativeHandle,
|
||||
jstring entryName) {
|
||||
ScopedUtfChars entryNameChars(env, entryName);
|
||||
if (entryNameChars.c_str() == NULL) {
|
||||
@@ -152,11 +154,11 @@ static jobject StrictJarFile_nativeFindEntry(JNIEnv* env, jobject, jlong nativeH
|
||||
return newZipEntry(env, data, entryName);
|
||||
}
|
||||
|
||||
static void StrictJarFile_nativeClose(JNIEnv*, jobject, jlong nativeHandle) {
|
||||
void StrictJarFile_nativeClose(JNIEnv*, jobject, jlong nativeHandle) {
|
||||
CloseArchive(reinterpret_cast<ZipArchiveHandle>(nativeHandle));
|
||||
}
|
||||
|
||||
static JNINativeMethod gMethods[] = {
|
||||
JNINativeMethod gMethods[] = {
|
||||
NATIVE_METHOD(StrictJarFile, nativeOpenJarFile, "(Ljava/lang/String;I)J"),
|
||||
NATIVE_METHOD(StrictJarFile, nativeStartIteration, "(JLjava/lang/String;)J"),
|
||||
NATIVE_METHOD(StrictJarFile, nativeNextEntry, "(J)Ljava/util/zip/ZipEntry;"),
|
||||
@@ -164,14 +166,15 @@ static JNINativeMethod gMethods[] = {
|
||||
NATIVE_METHOD(StrictJarFile, nativeClose, "(J)V"),
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace android {
|
||||
|
||||
int register_android_util_jar_StrictJarFile(JNIEnv* env) {
|
||||
jniRegisterNativeMethods(env, "android/util/jar/StrictJarFile", gMethods, NELEM(gMethods));
|
||||
|
||||
zipEntryCtor = env->GetMethodID(JniConstants::zipEntryClass, "<init>",
|
||||
"(Ljava/lang/String;Ljava/lang/String;JJJII[BJ)V");
|
||||
LOG_ALWAYS_FATAL_IF(zipEntryCtor == NULL, "Unable to find ZipEntry.<init>");
|
||||
|
||||
return 0;
|
||||
zipEntryClass = MakeGlobalRefOrDie(env, FindClassOrDie(env, "java/util/zip/ZipEntry"));
|
||||
zipEntryCtor = GetMethodIDOrDie(env, zipEntryClass, "<init>",
|
||||
"(Ljava/lang/String;Ljava/lang/String;JJJII[BJ)V");
|
||||
return jniRegisterNativeMethods(env, "android/util/jar/StrictJarFile", gMethods, NELEM(gMethods));
|
||||
}
|
||||
|
||||
}; // namespace android
|
||||
|
||||
Reference in New Issue
Block a user