Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d7f7a4a authored by Orion Hodson's avatar Orion Hodson Committed by Gerrit Code Review
Browse files

Merge "Remove dependency on libnativehelper/JniConstants.h"

parents a244ccd8 24b36058
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@
#include "android_media_AudioTrack.h"
#include "android_media_AudioTrack.h"


#include <nativehelper/JNIHelp.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/JniConstants.h>
#include "core_jni_helpers.h"
#include "core_jni_helpers.h"


#include <utils/Log.h>
#include <utils/Log.h>
+0 −1
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@


#include <utils/Log.h>
#include <utils/Log.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/JniConstants.h>
#include "core_jni_helpers.h"
#include "core_jni_helpers.h"
#include <media/AudioSystem.h>
#include <media/AudioSystem.h>


+21 −15
Original line number Original line Diff line number Diff line
@@ -20,8 +20,9 @@


#include <cutils/ashmem.h>
#include <cutils/ashmem.h>
#include <utils/Log.h>
#include <utils/Log.h>

#include <nativehelper/jni_macros.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/JniConstants.h>
#include <nativehelper/ScopedLocalRef.h>
#include <nativehelper/ScopedLocalRef.h>


#include <algorithm>
#include <algorithm>
@@ -31,10 +32,10 @@


namespace {
namespace {


static void throwErrnoException(JNIEnv* env, const char* functionName, int error) {
jclass errnoExceptionClass;
    static jmethodID ctor = env->GetMethodID(JniConstants::errnoExceptionClass,
jmethodID errnoExceptionCtor;  // MethodID for ErrnoException.<init>(String,I)
            "<init>", "(Ljava/lang/String;I)V");


void throwErrnoException(JNIEnv* env, const char* functionName, int error) {
    ScopedLocalRef<jstring> detailMessage(env, env->NewStringUTF(functionName));
    ScopedLocalRef<jstring> detailMessage(env, env->NewStringUTF(functionName));
    if (detailMessage.get() == NULL) {
    if (detailMessage.get() == NULL) {
        // Not really much we can do here. We're probably dead in the water,
        // 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();
        env->ExceptionClear();
    }
    }


    jobject exception = env->NewObject(JniConstants::errnoExceptionClass, ctor,
    jobject exception = env->NewObject(errnoExceptionClass,
            detailMessage.get(), error);
                                       errnoExceptionCtor,
                                       detailMessage.get(),
                                       error);
    env->Throw(reinterpret_cast<jthrowable>(exception));
    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
    // 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;
    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);
    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);
    int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
    if (!ashmem_valid(fd)) {
    if (!ashmem_valid(fd)) {
        return -1;
        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())));
    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 fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
    int err = 0;
    int err = 0;
    if (ashmem_set_prot_region(fd, prot)) {
    if (ashmem_set_prot_region(fd, prot)) {
@@ -87,18 +90,21 @@ static jint SharedMemory_setProt(JNIEnv* env, jobject, jobject fileDescriptor, j
    return err;
    return err;
}
}


static const JNINativeMethod methods[] = {
const JNINativeMethod methods[] = {
    {"nCreate", "(Ljava/lang/String;I)Ljava/io/FileDescriptor;", (void*)SharedMemory_create},
  NATIVE_METHOD(SharedMemory, nCreate, "(Ljava/lang/String;I)Ljava/io/FileDescriptor;"),
    {"nGetSize", "(Ljava/io/FileDescriptor;)I", (void*)SharedMemory_getSize},
  NATIVE_METHOD(SharedMemory, nGetSize, "(Ljava/io/FileDescriptor;)I"),
    {"nSetProt", "(Ljava/io/FileDescriptor;I)I", (void*)SharedMemory_setProt},
  NATIVE_METHOD(SharedMemory, nSetProt, "(Ljava/io/FileDescriptor;I)I")
};
};


} // anonymous namespace
} // anonymous namespace


namespace android {
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));
    return RegisterMethodsOrDie(env, "android/os/SharedMemory", methods, NELEM(methods));
}
}


+22 −19
Original line number Original line Diff line number Diff line
@@ -22,24 +22,26 @@


#include <log/log.h>
#include <log/log.h>


#include <nativehelper/jni_macros.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/JNIHelp.h>
#include <nativehelper/JniConstants.h>
#include <nativehelper/ScopedLocalRef.h>
#include <nativehelper/ScopedLocalRef.h>
#include <nativehelper/ScopedUtfChars.h>
#include <nativehelper/ScopedUtfChars.h>
#include "jni.h"

#include "core_jni_helpers.h"
#include "ziparchive/zip_archive.h"
#include "ziparchive/zip_archive.h"


namespace android {
namespace {


jclass zipEntryClass;
// The method ID for ZipEntry.<init>(String,String,JJJIII[BJJ)
// 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));
  jniThrowException(env, "java/io/IOException", ErrorCodeString(errorCode));
}
}


static jobject newZipEntry(JNIEnv* env, const ZipEntry& entry, jstring entryName) {
jobject newZipEntry(JNIEnv* env, const ZipEntry& entry, jstring entryName) {
  return env->NewObject(JniConstants::zipEntryClass,
  return env->NewObject(zipEntryClass,
                        zipEntryCtor,
                        zipEntryCtor,
                        entryName,
                        entryName,
                        NULL,  // comment
                        NULL,  // comment
@@ -52,7 +54,7 @@ static jobject newZipEntry(JNIEnv* env, const ZipEntry& entry, jstring entryName
                        static_cast<jlong>(entry.offset));
                        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.
  // Name argument is used for logging, and can be any string.
  ScopedUtfChars nameChars(env, name);
  ScopedUtfChars nameChars(env, name);
  if (nameChars.c_str() == NULL) {
  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) {
                                                jstring prefix) {
  ScopedUtfChars prefixChars(env, prefix);
  ScopedUtfChars prefixChars(env, prefix);
  if (prefixChars.c_str() == NULL) {
  if (prefixChars.c_str() == NULL) {
@@ -116,7 +118,7 @@ static jlong StrictJarFile_nativeStartIteration(JNIEnv* env, jobject, jlong nati
  return reinterpret_cast<jlong>(handle);
  return reinterpret_cast<jlong>(handle);
}
}


static jobject StrictJarFile_nativeNextEntry(JNIEnv* env, jobject, jlong iterationHandle) {
jobject StrictJarFile_nativeNextEntry(JNIEnv* env, jobject, jlong iterationHandle) {
  ZipEntry data;
  ZipEntry data;
  ZipString entryName;
  ZipString entryName;


@@ -135,7 +137,7 @@ static jobject StrictJarFile_nativeNextEntry(JNIEnv* env, jobject, jlong iterati
  return newZipEntry(env, data, entryNameString.get());
  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) {
                                             jstring entryName) {
  ScopedUtfChars entryNameChars(env, entryName);
  ScopedUtfChars entryNameChars(env, entryName);
  if (entryNameChars.c_str() == NULL) {
  if (entryNameChars.c_str() == NULL) {
@@ -152,11 +154,11 @@ static jobject StrictJarFile_nativeFindEntry(JNIEnv* env, jobject, jlong nativeH
  return newZipEntry(env, data, entryName);
  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));
  CloseArchive(reinterpret_cast<ZipArchiveHandle>(nativeHandle));
}
}


static JNINativeMethod gMethods[] = {
JNINativeMethod gMethods[] = {
  NATIVE_METHOD(StrictJarFile, nativeOpenJarFile, "(Ljava/lang/String;I)J"),
  NATIVE_METHOD(StrictJarFile, nativeOpenJarFile, "(Ljava/lang/String;I)J"),
  NATIVE_METHOD(StrictJarFile, nativeStartIteration, "(JLjava/lang/String;)J"),
  NATIVE_METHOD(StrictJarFile, nativeStartIteration, "(JLjava/lang/String;)J"),
  NATIVE_METHOD(StrictJarFile, nativeNextEntry, "(J)Ljava/util/zip/ZipEntry;"),
  NATIVE_METHOD(StrictJarFile, nativeNextEntry, "(J)Ljava/util/zip/ZipEntry;"),
@@ -164,14 +166,15 @@ static JNINativeMethod gMethods[] = {
  NATIVE_METHOD(StrictJarFile, nativeClose, "(J)V"),
  NATIVE_METHOD(StrictJarFile, nativeClose, "(J)V"),
};
};


int register_android_util_jar_StrictJarFile(JNIEnv* env) {
}  // namespace
  jniRegisterNativeMethods(env, "android/util/jar/StrictJarFile", gMethods, NELEM(gMethods));


  zipEntryCtor = env->GetMethodID(JniConstants::zipEntryClass, "<init>",
namespace android {
      "(Ljava/lang/String;Ljava/lang/String;JJJII[BJ)V");
  LOG_ALWAYS_FATAL_IF(zipEntryCtor == NULL, "Unable to find ZipEntry.<init>");


  return 0;
int register_android_util_jar_StrictJarFile(JNIEnv* env) {
  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
}; // namespace android