aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-prod (mdb) <android-build-team-robot@google.com>2020-10-01 21:19:23 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-10-01 21:19:23 +0000
commite27770c4cebdfebab64ae4ad279911d8c6b1f5d4 (patch)
tree9715e081037c0b0608af2de790482e7e3b662cd7
parent53cc619c5cb6d73bf2a25fc92ff43d8e7bcdbe79 (diff)
parentd795f97dfce77fe6f201910553e270af4e0a80e4 (diff)
downloadplatform_libnativehelper-sdk-release.tar.gz
platform_libnativehelper-sdk-release.tar.bz2
platform_libnativehelper-sdk-release.zip
Merge "Snap for 6877830 from 80af3ff83c000561a7200846a49d5d5ba03d895f to sdk-release" into sdk-releasesdk-release
-rw-r--r--Android.bp4
-rw-r--r--JNIHelp.c12
-rw-r--r--header_only_include/nativehelper/scoped_bytes.h82
-rw-r--r--include/android/file_descriptor_jni.h2
-rw-r--r--include/nativehelper/JNIHelp.h18
-rw-r--r--include/nativehelper/ScopedBytes.h21
-rw-r--r--include/nativehelper/toStringArray.h5
-rw-r--r--libnativehelper.map.txt66
-rw-r--r--tests/Android.bp1
-rw-r--r--tests/scoped_bytes_test.cpp31
-rw-r--r--tests_mts/jni/jni_helper_jni.cpp14
-rw-r--r--tests_mts/src/android/libnativehelper/mts/JniHelpTest.java20
12 files changed, 35 insertions, 241 deletions
diff --git a/Android.bp b/Android.bp
index 4dc70c8..13882f5 100644
--- a/Android.bp
+++ b/Android.bp
@@ -112,7 +112,7 @@ cc_library_shared {
stl: "none",
stubs: {
symbol_file: "libnativehelper.map.txt",
- versions: ["31"],
+ versions: ["S"],
},
target: {
android: {
@@ -195,7 +195,7 @@ ndk_headers {
ndk_library {
name: "libnativehelper",
symbol_file: "libnativehelper.map.txt",
- first_version: "31",
+ first_version: "S",
}
//
diff --git a/JNIHelp.c b/JNIHelp.c
index fdc309e..159feb0 100644
--- a/JNIHelp.c
+++ b/JNIHelp.c
@@ -317,18 +317,6 @@ int jniThrowIOException(JNIEnv* env, int errnum) {
return jniThrowException(env, "java/io/IOException", message);
}
-jobject jniGetReferent(JNIEnv* env, jobject ref) {
- jmethodID get = FindMethod(env, "java/lang/ref/Reference", "get", "()Ljava/lang/Object;");
- return (*env)->CallObjectMethod(env, ref, get);
-}
-
jstring jniCreateString(JNIEnv* env, const jchar* unicodeChars, jsize len) {
return (*env)->NewString(env, unicodeChars, len);
}
-
-jobjectArray jniCreateStringArray(C_JNIEnv* env, size_t count) {
- jclass stringClass = (*env)->FindClass(env, "java/lang/String");
- jobjectArray result = (*env)->NewObjectArray(env, count, stringClass, NULL);
- (*env)->DeleteLocalRef(env, stringClass);
- return result;
-}
diff --git a/header_only_include/nativehelper/scoped_bytes.h b/header_only_include/nativehelper/scoped_bytes.h
deleted file mode 100644
index f58efa4..0000000
--- a/header_only_include/nativehelper/scoped_bytes.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <jni.h>
-
-#include "nativehelper_utils.h"
-
-/**
- * ScopedBytesRO and ScopedBytesRW attempt to paper over the differences between byte[]s and
- * ByteBuffers. This in turn helps paper over the differences between non-direct ByteBuffers backed
- * by byte[]s, direct ByteBuffers backed by bytes[]s, and direct ByteBuffers not backed by byte[]s.
- * (On Android, this last group only contains MappedByteBuffers.)
- */
-template<bool readOnly>
-class ScopedBytes {
-public:
- ScopedBytes(JNIEnv* env, jobject object)
- : mEnv(env), mObject(object), mByteArray(nullptr), mPtr(nullptr)
- {
- if (mObject == nullptr) {
- jniThrowNullPointerException(mEnv);
- } else {
- jclass byteArrayClass = env->FindClass("[B");
- if (mEnv->IsInstanceOf(mObject, byteArrayClass)) {
- mByteArray = reinterpret_cast<jbyteArray>(mObject);
- mPtr = mEnv->GetByteArrayElements(mByteArray, nullptr);
- } else {
- mPtr = reinterpret_cast<jbyte*>(mEnv->GetDirectBufferAddress(mObject));
- }
- mEnv->DeleteLocalRef(byteArrayClass);
- }
- }
-
- ~ScopedBytes() {
- if (mByteArray != nullptr) {
- mEnv->ReleaseByteArrayElements(mByteArray, mPtr, readOnly ? JNI_ABORT : 0);
- }
- }
-
-private:
- JNIEnv* const mEnv;
- const jobject mObject;
- jbyteArray mByteArray;
-
-protected:
- jbyte* mPtr;
-
-private:
- DISALLOW_COPY_AND_ASSIGN(ScopedBytes);
-};
-
-class ScopedBytesRO : public ScopedBytes<true> {
-public:
- ScopedBytesRO(JNIEnv* env, jobject object) : ScopedBytes<true>(env, object) {}
- const jbyte* get() const {
- return mPtr;
- }
-};
-
-class ScopedBytesRW : public ScopedBytes<false> {
-public:
- ScopedBytesRW(JNIEnv* env, jobject object) : ScopedBytes<false>(env, object) {}
- jbyte* get() {
- return mPtr;
- }
-};
-
diff --git a/include/android/file_descriptor_jni.h b/include/android/file_descriptor_jni.h
index a375be1..eeab09e 100644
--- a/include/android/file_descriptor_jni.h
+++ b/include/android/file_descriptor_jni.h
@@ -81,7 +81,7 @@ int AFileDescriptor_getFD(JNIEnv* env, jobject fileDescriptor) __INTRODUCED_IN(3
*/
void AFileDescriptor_setFD(JNIEnv* env, jobject fileDescriptor, int fd) __INTRODUCED_IN(31);
-#endif // __ANDROID_API__ >= 31
+#endif // __ANDROID_API__ >= __ANDROID_API_S__
__END_DECLS
diff --git a/include/nativehelper/JNIHelp.h b/include/nativehelper/JNIHelp.h
index ad6eb25..d95670c 100644
--- a/include/nativehelper/JNIHelp.h
+++ b/include/nativehelper/JNIHelp.h
@@ -93,26 +93,12 @@ int jniThrowRuntimeException(C_JNIEnv* env, const char* msg);
int jniThrowIOException(C_JNIEnv* env, int errnum);
/*
- * Returns the reference from a java.lang.ref.Reference.
- */
-jobject jniGetReferent(C_JNIEnv* env, jobject ref);
-
-/*
* Returns a Java String object created from UTF-16 data either from jchar or,
* if called from C++11, char16_t (a bitwise identical distinct type).
*/
jstring jniCreateString(C_JNIEnv* env, const jchar* unicodeChars, jsize len);
/*
- * Allocates a new array for java/lang/String instances with space for |count| elements. Elements
- * are initially null.
- *
- * Returns a new array on success or nullptr in case of failure. This method raises an
- * OutOfMemoryError exception if allocation fails.
- */
-jobjectArray jniCreateStringArray(C_JNIEnv* env, size_t count);
-
-/*
* Log a message and an exception.
* If exception is NULL, logs the current exception in the JNI environment.
*/
@@ -157,10 +143,6 @@ inline int jniThrowIOException(JNIEnv* env, int errnum) {
return jniThrowIOException(&env->functions, errnum);
}
-inline jobject jniGetReferent(JNIEnv* env, jobject ref) {
- return jniGetReferent(&env->functions, ref);
-}
-
inline jstring jniCreateString(JNIEnv* env, const jchar* unicodeChars, jsize len) {
return jniCreateString(&env->functions, unicodeChars, len);
}
diff --git a/include/nativehelper/ScopedBytes.h b/include/nativehelper/ScopedBytes.h
deleted file mode 100644
index 7c369b1..0000000
--- a/include/nativehelper/ScopedBytes.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include "JNIHelp.h"
-#include <nativehelper/scoped_bytes.h>
-
diff --git a/include/nativehelper/toStringArray.h b/include/nativehelper/toStringArray.h
index 4bdb297..e4eeaca 100644
--- a/include/nativehelper/toStringArray.h
+++ b/include/nativehelper/toStringArray.h
@@ -26,8 +26,9 @@
template <typename StringVisitor>
jobjectArray toStringArray(JNIEnv* env, size_t count, StringVisitor&& visitor) {
- C_JNIEnv* c_env = static_cast<C_JNIEnv*>(&env->functions);
- ScopedLocalRef<jobjectArray> result(env, jniCreateStringArray(c_env, count));
+ jclass stringClass = env->FindClass("java/lang/String");
+ ScopedLocalRef<jobjectArray> result(env, env->NewObjectArray(count, stringClass, NULL));
+ env->DeleteLocalRef(stringClass);
if (result == nullptr) {
return nullptr;
}
diff --git a/libnativehelper.map.txt b/libnativehelper.map.txt
index d1f5911..2664647 100644
--- a/libnativehelper.map.txt
+++ b/libnativehelper.map.txt
@@ -1,46 +1,38 @@
-# This library should only export C linkage definitions.
-#
-# VERSION string that follows is derived from <library_name>_<version>.
-LIBNATIVEHELPER_31 {
+LIBNATIVEHELPER_S { # introduced=S
global:
- JNI_GetDefaultJavaVMInitArgs;
+ # NDK API for libnativehelper.
+ AFileDescriptor_create;
+ AFileDescriptor_getFD;
+ AFileDescriptor_setFD;
+
+ # JNI Invocation methods available to platform and apps.
JNI_CreateJavaVM;
+ JNI_GetDefaultJavaVMInitArgs;
JNI_GetCreatedJavaVMs;
- jniRegisterNativeMethods;
- jniThrowException;
- jniThrowExceptionFmt;
- jniThrowNullPointerException;
- jniThrowRuntimeException;
- jniThrowIOException;
- jniCreateFileDescriptor;
- jniGetFDFromFileDescriptor;
- jniSetFileDescriptorOfFD;
- jniGetNioBufferBaseArray;
- jniGetNioBufferBaseArrayOffset;
- jniGetNioBufferPointer;
- jniGetNioBufferFields;
- jniGetReferent;
- jniCreateString;
- jniCreateStringArray;
- jniLogException;
- jniUninitializeConstants;
-
- JniInvocationCreate;
- JniInvocationDestroy;
- JniInvocationInit;
- JniInvocationGetLibrary;
+ # API for platform and modules only.
+ jniRegisterNativeMethods; # apex
+ jniThrowException; # apex
+ jniThrowExceptionFmt; # apex
+ jniThrowNullPointerException; # apex
+ jniThrowRuntimeException; # apex
+ jniThrowIOException; # apex
+ jniCreateFileDescriptor; # apex
+ jniGetFDFromFileDescriptor; # apex
+ jniSetFileDescriptorOfFD; # apex
+ jniGetNioBufferBaseArray; # apex
+ jniGetNioBufferBaseArrayOffset; # apex
+ jniGetNioBufferPointer; # apex
+ jniGetNioBufferFields; # apex
+ jniCreateString; # apex
+ jniLogException; # apex
+ jniUninitializeConstants; # apex
- local:
- *;
-};
+ JniInvocationCreate; # apex
+ JniInvocationDestroy; # apex
+ JniInvocationInit; # apex
+ JniInvocationGetLibrary; # apex
-# NDK API for libnativehelper.
-LIBNATIVEHELPER_S { # introduced=31
- global:
- AFileDescriptor_create;
- AFileDescriptor_getFD;
- AFileDescriptor_setFD;
local:
*;
};
diff --git a/tests/Android.bp b/tests/Android.bp
index ecf4c4a..9ac1260 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -5,7 +5,6 @@ cc_test {
test_suites: ["device-tests"],
host_supported: true,
srcs: [
- "scoped_bytes_test.cpp",
"scoped_local_frame_test.cpp",
"scoped_local_ref_test.cpp",
"scoped_primitive_array_test.cpp",
diff --git a/tests/scoped_bytes_test.cpp b/tests/scoped_bytes_test.cpp
deleted file mode 100644
index 17f0a5c..0000000
--- a/tests/scoped_bytes_test.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "nativehelper/scoped_bytes.h"
-
-// This is a test that scoped headers work independently.
-
-void TestCompilationScopedBytesRO(JNIEnv* env) {
- jobject o = nullptr;
- ScopedBytesRO sb(env, o);
- sb.get();
-}
-
-void TestCompilationScopedBytesRW(JNIEnv* env) {
- jobject o = nullptr;
- ScopedBytesRW sb(env, o);
- sb.get();
-}
diff --git a/tests_mts/jni/jni_helper_jni.cpp b/tests_mts/jni/jni_helper_jni.cpp
index 16f73cd..cfb28bd 100644
--- a/tests_mts/jni/jni_helper_jni.cpp
+++ b/tests_mts/jni/jni_helper_jni.cpp
@@ -177,19 +177,11 @@ static void assertBufferPointer(JNIEnv* env, jclass /*clazz*/, jobject jnb, jlon
}
}
-static jobject getReferent(JNIEnv* env, jclass /*clazz*/, jobject reference) {
- return jniGetReferent(env, reference);
-}
-
static jstring createString(JNIEnv* env, jclass /*clazz*/, jstring value) {
ScopedStringChars ssc(env, value);
return jniCreateString(env, ssc.get(), ssc.size());
}
-static jobjectArray createStringArray(JNIEnv* env, jclass /*clazz*/, jint length) {
- return jniCreateStringArray(&env->functions, length);
-}
-
} // namespace
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
@@ -253,15 +245,9 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
MAKE_JNI_NATIVE_METHOD("assertBufferPointer",
"(Ljava/nio/Buffer;J)V",
assertBufferPointer),
- MAKE_JNI_NATIVE_METHOD("getReferent",
- "(Ljava/lang/ref/Reference;)Ljava/lang/Object;",
- getReferent),
MAKE_JNI_NATIVE_METHOD("createString",
"(Ljava/lang/String;)Ljava/lang/String;",
createString),
- MAKE_JNI_NATIVE_METHOD("createStringArray",
- "(I)[Ljava/lang/String;",
- createStringArray)
};
int rc = jniRegisterNativeMethods(env,
"android/libnativehelper/mts/JniHelpTest",
diff --git a/tests_mts/src/android/libnativehelper/mts/JniHelpTest.java b/tests_mts/src/android/libnativehelper/mts/JniHelpTest.java
index ffcf3b1..e03a3d3 100644
--- a/tests_mts/src/android/libnativehelper/mts/JniHelpTest.java
+++ b/tests_mts/src/android/libnativehelper/mts/JniHelpTest.java
@@ -55,9 +55,7 @@ public class JniHelpTest extends AndroidTestCase {
private static native long getDirectBufferAddress(Buffer b);
private static native void assertBufferPointer(Buffer b, long address);
- private static native Object getReferent(Reference r);
private static native String createString(String input);
- private static native String[] createStringArray(int length);
static {
System.loadLibrary("nativehelper_mts_jni");
@@ -283,28 +281,10 @@ public class JniHelpTest extends AndroidTestCase {
checkNioXHeapBuffers(bb, 0);
}
- public void testGetReferent() {
- Object o = new Object();
- SoftReference r = new SoftReference<>(o);
- assertSame(getReferent(r), o);
- r.clear();
- assertSame(getReferent(r), null);
- }
-
public void testCreateString() {
String input = "The treacherous mountain path lay ahead.";
String output = createString(input);
assertEquals(input, output);
assertNotSame(input, output);
}
-
- public void testCreateStringArray() {
- for (int i = 0; i < 10; ++i) {
- String[] array = createStringArray(i);
- assertNotNull(array);
- for (int j = 0; j < i; ++j) {
- assertNull(array[j]);
- }
- }
- }
}