Snap for 5058806 from ad0af835dac738ff86ac4a1f5fee0d1991f4343d to qt-release
Change-Id: Iea1e75e60d1db0c1a31325194dc37c02b1c4a608
diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java
index 355de8c..9a67379 100644
--- a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/AccessPermissionWithDiffSigTest.java
@@ -40,6 +40,7 @@
import android.provider.CalendarContract;
import android.provider.ContactsContract;
import android.test.AndroidTestCase;
+import android.support.test.InstrumentationRegistry;
import android.util.Log;
import com.android.cts.permissiondeclareapp.UtilsProvider;
@@ -1620,10 +1621,19 @@
assertReadingClipNotAllowed(clip);
assertWritingClipNotAllowed(clip);
- // But if someone puts it on the clipboard, we can read it
- setPrimaryClip(clip);
- final ClipData clipFromClipboard = getContext().getSystemService(ClipboardManager.class)
- .getPrimaryClip();
+ // Use shell's permissions to ensure we can access the clipboard
+ InstrumentationRegistry.getInstrumentation().getUiAutomation()
+ .adoptShellPermissionIdentity();
+ ClipData clipFromClipboard;
+ try {
+ // But if someone puts it on the clipboard, we can read it
+ setPrimaryClip(clip);
+ clipFromClipboard = getContext()
+ .getSystemService(ClipboardManager.class).getPrimaryClip();
+ } finally {
+ InstrumentationRegistry.getInstrumentation().getUiAutomation()
+ .dropShellPermissionIdentity();
+ }
assertClipDataEquals(clip, clipFromClipboard);
assertReadingClipAllowed(clipFromClipboard);
assertWritingClipNotAllowed(clipFromClipboard);
diff --git a/hostsidetests/jvmti/base/jni/redefine.cpp b/hostsidetests/jvmti/base/jni/redefine.cpp
index 003b909..7656fb3 100644
--- a/hostsidetests/jvmti/base/jni/redefine.cpp
+++ b/hostsidetests/jvmti/base/jni/redefine.cpp
@@ -196,7 +196,7 @@
void register_android_jvmti_cts_JvmtiRedefineClassesTest(jvmtiEnv* jenv, JNIEnv* env) {
ScopedLocalRef<jclass> klass(env, FindClass(jenv, env,
"android/jvmti/cts/JvmtiRedefineClassesTest", nullptr));
- if (env->ExceptionCheck()) {
+ if (klass.get() == nullptr) {
env->ExceptionClear();
return;
}
diff --git a/hostsidetests/jvmti/base/jni/tagging.cpp b/hostsidetests/jvmti/base/jni/tagging.cpp
index d2208f3..8ab4a10 100644
--- a/hostsidetests/jvmti/base/jni/tagging.cpp
+++ b/hostsidetests/jvmti/base/jni/tagging.cpp
@@ -138,7 +138,7 @@
void register_art_Main(jvmtiEnv* jenv, JNIEnv* env) {
ScopedLocalRef<jclass> klass(env, FindClass(jenv, env, "art/Main", nullptr));
- if (env->ExceptionCheck()) {
+ if (klass.get() == nullptr) {
env->ExceptionClear();
return;
}
@@ -159,7 +159,7 @@
void register_android_jvmti_cts_JvmtiTaggingTest(jvmtiEnv* jenv, JNIEnv* env) {
ScopedLocalRef<jclass> klass(env, FindClass(jenv, env,
"android/jvmti/cts/JvmtiTaggingTest", nullptr));
- if (env->ExceptionCheck()) {
+ if (klass.get() == nullptr) {
env->ExceptionClear();
return;
}
diff --git a/hostsidetests/jvmti/base/jni/tracking.cpp b/hostsidetests/jvmti/base/jni/tracking.cpp
index 25c9060..7576ed5 100644
--- a/hostsidetests/jvmti/base/jni/tracking.cpp
+++ b/hostsidetests/jvmti/base/jni/tracking.cpp
@@ -119,7 +119,7 @@
void register_android_jvmti_cts_JvmtiTrackingTest(jvmtiEnv* jenv, JNIEnv* env) {
ScopedLocalRef<jclass> klass(env, FindClass(jenv, env,
"android/jvmti/cts/JvmtiTrackingTest", nullptr));
- if (env->ExceptionCheck()) {
+ if (klass.get() == nullptr) {
env->ExceptionClear();
return;
}
diff --git a/tests/signature/dex-checker/dex-checker.cpp b/tests/signature/dex-checker/dex-checker.cpp
index 4a80e02..61d9e32 100644
--- a/tests/signature/dex-checker/dex-checker.cpp
+++ b/tests/signature/dex-checker/dex-checker.cpp
@@ -49,7 +49,8 @@
ScopedUtfChars utf_type(env, type);
jfieldID fid = env->GetFieldID(klass, utf_name.c_str(), utf_type.c_str());
if (env->ExceptionCheck()) {
- env->ExceptionClear();
+ // GetFieldID could have thrown either NoSuchFieldError or ExceptionInInitializerError.
+ // Do not clear the exception, let Java code handle it.
return nullptr;
}
return env->ToReflectedField(klass, fid, /* static */ false);
@@ -62,7 +63,8 @@
ScopedUtfChars utf_type(env, type);
jfieldID fid = env->GetStaticFieldID(klass, utf_name.c_str(), utf_type.c_str());
if (env->ExceptionCheck()) {
- env->ExceptionClear();
+ // GetStaticFieldID could have thrown either NoSuchFieldError or ExceptionInInitializerError.
+ // Do not clear the exception, let Java code handle it.
return nullptr;
}
return env->ToReflectedField(klass, fid, /* static */ true);
@@ -75,7 +77,8 @@
ScopedUtfChars utf_signature(env, signature);
jmethodID mid = env->GetMethodID(klass, utf_name.c_str(), utf_signature.c_str());
if (env->ExceptionCheck()) {
- env->ExceptionClear();
+ // GetMethodID could have thrown either NoSuchMethodError or ExceptionInInitializerError.
+ // Do not clear the exception, let Java code handle it.
return nullptr;
}
return env->ToReflectedMethod(klass, mid, /* static */ false);
@@ -88,7 +91,8 @@
ScopedUtfChars utf_signature(env, signature);
jmethodID mid = env->GetStaticMethodID(klass, utf_name.c_str(), utf_signature.c_str());
if (env->ExceptionCheck()) {
- env->ExceptionClear();
+ // GetStaticMethodID could have thrown either NoSuchMethodError or ExceptionInInitializerError.
+ // Do not clear the exception, let Java code handle it.
return nullptr;
}
return env->ToReflectedMethod(klass, mid, /* static */ true);
diff --git a/tests/signature/src/android/signature/cts/DexMemberChecker.java b/tests/signature/src/android/signature/cts/DexMemberChecker.java
index 528e868..1efdbad 100644
--- a/tests/signature/src/android/signature/cts/DexMemberChecker.java
+++ b/tests/signature/src/android/signature/cts/DexMemberChecker.java
@@ -16,6 +16,7 @@
package android.signature.cts;
+import android.util.Log;
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Field;
@@ -24,6 +25,7 @@
import java.util.List;
public class DexMemberChecker {
+ public static final String TAG = "DexMemberChecker";
public interface Observer {
void classAccessible(boolean accessible, DexMember member);
@@ -85,17 +87,39 @@
observer.fieldAccessibleViaReflection(
hasMatchingField_Reflection(klass, field),
field);
- observer.fieldAccessibleViaJni(
- hasMatchingField_JNI(klass, field),
- field);
+ try {
+ observer.fieldAccessibleViaJni(
+ hasMatchingField_JNI(klass, field),
+ field);
+ } catch (ExceptionInInitializerError | UnsatisfiedLinkError | NoClassDefFoundError e) {
+ if ((e instanceof NoClassDefFoundError)
+ && !(e.getCause() instanceof ExceptionInInitializerError)
+ && !(e.getCause() instanceof UnsatisfiedLinkError)) {
+ throw e;
+ }
+
+ // Could not initialize the class. Skip JNI test.
+ Log.w(TAG, "JNI failed for " + dexMember.toString(), e);
+ }
} else if (dexMember instanceof DexMethod) {
DexMethod method = (DexMethod) dexMember;
observer.methodAccessibleViaReflection(
hasMatchingMethod_Reflection(klass, method),
method);
- observer.methodAccessibleViaJni(
- hasMatchingMethod_JNI(klass, method),
- method);
+ try {
+ observer.methodAccessibleViaJni(
+ hasMatchingMethod_JNI(klass, method),
+ method);
+ } catch (ExceptionInInitializerError | UnsatisfiedLinkError | NoClassDefFoundError e) {
+ if ((e instanceof NoClassDefFoundError)
+ && !(e.getCause() instanceof ExceptionInInitializerError)
+ && !(e.getCause() instanceof UnsatisfiedLinkError)) {
+ throw e;
+ }
+
+ // Could not initialize the class. Skip JNI test.
+ Log.w(TAG, "JNI failed for " + dexMember.toString(), e);
+ }
} else {
throw new IllegalStateException("Unexpected type of dex member");
}
@@ -134,10 +158,25 @@
}
private static boolean hasMatchingField_JNI(Class<?> klass, DexField dexField) {
- Field ifield = getField_JNI(klass, dexField.getName(), dexField.getDexType());
- Field sfield = getStaticField_JNI(klass, dexField.getName(), dexField.getDexType());
- return (ifield != null && ifield.getDeclaringClass() == klass) ||
- (sfield != null && sfield.getDeclaringClass() == klass);
+ try {
+ Field ifield = getField_JNI(klass, dexField.getName(), dexField.getDexType());
+ if (ifield.getDeclaringClass() == klass) {
+ return true;
+ }
+ } catch (NoSuchFieldError e) {
+ // Not found.
+ }
+
+ try {
+ Field sfield = getStaticField_JNI(klass, dexField.getName(), dexField.getDexType());
+ if (sfield.getDeclaringClass() == klass) {
+ return true;
+ }
+ } catch (NoSuchFieldError e) {
+ // Not found.
+ }
+
+ return false;
}
private static boolean hasMatchingMethod_Reflection(Class<?> klass, DexMethod dexMethod) {
@@ -163,11 +202,29 @@
}
private static boolean hasMatchingMethod_JNI(Class<?> klass, DexMethod dexMethod) {
- Executable imethod = getMethod_JNI(klass, dexMethod.getName(), dexMethod.getDexSignature());
- Executable smethod = dexMethod.isConstructor() ? null :
- getStaticMethod_JNI(klass, dexMethod.getName(), dexMethod.getDexSignature());
- return (imethod != null && imethod.getDeclaringClass() == klass) ||
- (smethod != null && smethod.getDeclaringClass() == klass);
+ try {
+ Executable imethod = getMethod_JNI(
+ klass, dexMethod.getName(), dexMethod.getDexSignature());
+ if (imethod.getDeclaringClass() == klass) {
+ return true;
+ }
+ } catch (NoSuchMethodError e) {
+ // Not found.
+ }
+
+ if (!dexMethod.isConstructor()) {
+ try {
+ Executable smethod =
+ getStaticMethod_JNI(klass, dexMethod.getName(), dexMethod.getDexSignature());
+ if (smethod.getDeclaringClass() == klass) {
+ return true;
+ }
+ } catch (NoSuchMethodError e) {
+ // Not found.
+ }
+ }
+
+ return false;
}
private static native Field getField_JNI(Class<?> klass, String name, String type);
diff --git a/tests/tests/binder_ndk/libbinder_ndk_test/android_binder_cts_NativeService.cpp b/tests/tests/binder_ndk/libbinder_ndk_test/android_binder_cts_NativeService.cpp
index 11fe8e7..ecc04c3 100644
--- a/tests/tests/binder_ndk/libbinder_ndk_test/android_binder_cts_NativeService.cpp
+++ b/tests/tests/binder_ndk/libbinder_ndk_test/android_binder_cts_NativeService.cpp
@@ -20,12 +20,13 @@
#include "itest_impl.h"
using ::aidl::test_package::ITest;
-using ::android::AutoAIBinder;
+using ::ndk::SharedRefBase;
+using ::ndk::SpAIBinder;
extern "C" JNIEXPORT jobject JNICALL
Java_android_binder_cts_NativeService_getBinder_1native(JNIEnv* env) {
// The ref owns the MyTest, and the binder owns the ref.
- AutoAIBinder binder = (new MyTest)->ref<MyTest>()->asBinder();
+ SpAIBinder binder = SharedRefBase::make<MyTest>()->asBinder();
// And the Java object owns the binder
return AIBinder_toJavaBinder(env, binder.get());
diff --git a/tests/tests/binder_ndk/libbinder_ndk_test/itest_impl.h b/tests/tests/binder_ndk/libbinder_ndk_test/itest_impl.h
index 5c25d18..b81e25e 100644
--- a/tests/tests/binder_ndk/libbinder_ndk_test/itest_impl.h
+++ b/tests/tests/binder_ndk/libbinder_ndk_test/itest_impl.h
@@ -24,68 +24,72 @@
class MyTest : public ::aidl::test_package::BnTest,
public ThisShouldBeDestroyed {
public:
- ::android::AutoAStatus TestVoidReturn() override {
- return ::android::AutoAStatus(AStatus_newOk());
+ ::ndk::ScopedAStatus TestVoidReturn() override {
+ return ::ndk::ScopedAStatus(AStatus_newOk());
}
- ::android::AutoAStatus TestOneway() override {
+ ::ndk::ScopedAStatus TestOneway() override {
// This return code should be ignored since it is oneway.
- return ::android::AutoAStatus(AStatus_fromStatus(STATUS_UNKNOWN_ERROR));
+ return ::ndk::ScopedAStatus(AStatus_fromStatus(STATUS_UNKNOWN_ERROR));
}
- ::android::AutoAStatus RepeatInt(int32_t in_value,
- int32_t* _aidl_return) override {
+ ::ndk::ScopedAStatus RepeatInt(int32_t in_value,
+ int32_t* _aidl_return) override {
*_aidl_return = in_value;
- return ::android::AutoAStatus(AStatus_newOk());
+ return ::ndk::ScopedAStatus(AStatus_newOk());
}
- ::android::AutoAStatus RepeatLong(int64_t in_value,
- int64_t* _aidl_return) override {
+ ::ndk::ScopedAStatus RepeatLong(int64_t in_value,
+ int64_t* _aidl_return) override {
*_aidl_return = in_value;
- return ::android::AutoAStatus(AStatus_newOk());
+ return ::ndk::ScopedAStatus(AStatus_newOk());
}
- ::android::AutoAStatus RepeatFloat(float in_value,
- float* _aidl_return) override {
+ ::ndk::ScopedAStatus RepeatFloat(float in_value,
+ float* _aidl_return) override {
*_aidl_return = in_value;
- return ::android::AutoAStatus(AStatus_newOk());
+ return ::ndk::ScopedAStatus(AStatus_newOk());
}
- ::android::AutoAStatus RepeatDouble(double in_value,
- double* _aidl_return) override {
+ ::ndk::ScopedAStatus RepeatDouble(double in_value,
+ double* _aidl_return) override {
*_aidl_return = in_value;
- return ::android::AutoAStatus(AStatus_newOk());
+ return ::ndk::ScopedAStatus(AStatus_newOk());
}
- ::android::AutoAStatus RepeatBoolean(bool in_value,
- bool* _aidl_return) override {
+ ::ndk::ScopedAStatus RepeatBoolean(bool in_value,
+ bool* _aidl_return) override {
*_aidl_return = in_value;
- return ::android::AutoAStatus(AStatus_newOk());
+ return ::ndk::ScopedAStatus(AStatus_newOk());
}
- ::android::AutoAStatus RepeatChar(char16_t in_value,
- char16_t* _aidl_return) override {
+ ::ndk::ScopedAStatus RepeatChar(char16_t in_value,
+ char16_t* _aidl_return) override {
*_aidl_return = in_value;
- return ::android::AutoAStatus(AStatus_newOk());
+ return ::ndk::ScopedAStatus(AStatus_newOk());
}
- ::android::AutoAStatus RepeatByte(int8_t in_value,
- int8_t* _aidl_return) override {
+ ::ndk::ScopedAStatus RepeatByte(int8_t in_value,
+ int8_t* _aidl_return) override {
*_aidl_return = in_value;
- return ::android::AutoAStatus(AStatus_newOk());
+ return ::ndk::ScopedAStatus(AStatus_newOk());
}
- ::android::AutoAStatus RepeatBinder(
- const ::android::AutoAIBinder& in_value,
- ::android::AutoAIBinder* _aidl_return) override {
+ ::ndk::ScopedAStatus RepeatBinder(const ::ndk::SpAIBinder& in_value,
+ ::ndk::SpAIBinder* _aidl_return) override {
*_aidl_return = in_value;
- return ::android::AutoAStatus(AStatus_newOk());
+ return ::ndk::ScopedAStatus(AStatus_newOk());
}
- ::android::AutoAStatus RepeatInterface(
+ ::ndk::ScopedAStatus RepeatInterface(
const std::shared_ptr<IEmpty>& in_value,
std::shared_ptr<IEmpty>* _aidl_return) override {
*_aidl_return = in_value;
- return ::android::AutoAStatus(AStatus_newOk());
+ return ::ndk::ScopedAStatus(AStatus_newOk());
}
- ::android::AutoAStatus RepeatString(const std::string& in_value,
- std::string* _aidl_return) override {
+ ::ndk::ScopedAStatus RepeatString(const std::string& in_value,
+ std::string* _aidl_return) override {
*_aidl_return = in_value;
- return ::android::AutoAStatus(AStatus_newOk());
+ return ::ndk::ScopedAStatus(AStatus_newOk());
}
- ::android::AutoAStatus RepeatPolygon(const RegularPolygon& in_value,
- RegularPolygon* _aidl_return) override {
+ ::ndk::ScopedAStatus RepeatPolygon(const RegularPolygon& in_value,
+ RegularPolygon* _aidl_return) override {
*_aidl_return = in_value;
- return ::android::AutoAStatus(AStatus_newOk());
+ return ::ndk::ScopedAStatus(AStatus_newOk());
+ }
+ ::ndk::ScopedAStatus RenamePolygon(RegularPolygon* value,
+ const std::string& newName) override {
+ value->name = newName;
+ return ::ndk::ScopedAStatus(AStatus_newOk());
}
};
\ No newline at end of file
diff --git a/tests/tests/binder_ndk/libbinder_ndk_test/test_native_aidl_client.cpp b/tests/tests/binder_ndk/libbinder_ndk_test/test_native_aidl_client.cpp
index f655a90..576c624 100644
--- a/tests/tests/binder_ndk/libbinder_ndk_test/test_native_aidl_client.cpp
+++ b/tests/tests/binder_ndk/libbinder_ndk_test/test_native_aidl_client.cpp
@@ -27,22 +27,35 @@
using ::aidl::test_package::BpTest;
using ::aidl::test_package::ITest;
using ::aidl::test_package::RegularPolygon;
-using ::android::AutoAIBinder;
-using ::android::AutoAStatus;
+using ::ndk::ScopedAStatus;
+using ::ndk::SharedRefBase;
+using ::ndk::SpAIBinder;
-class NdkBinderTest_Aidl
- : public NdkBinderTest,
- public ::testing::WithParamInterface<std::shared_ptr<ITest>> {};
+struct Params {
+ std::shared_ptr<ITest> iface;
+ bool shouldBeRemote;
+};
-#define iface GetParam()
+#define iface GetParam().iface
+#define shouldBeRemote GetParam().shouldBeRemote
+
+class NdkBinderTest_Aidl : public NdkBinderTest,
+ public ::testing::WithParamInterface<Params> {};
TEST_P(NdkBinderTest_Aidl, GotTest) { ASSERT_NE(nullptr, iface); }
+TEST_P(NdkBinderTest_Aidl, Remoteness) {
+ ASSERT_EQ(shouldBeRemote, iface->isRemote());
+}
+
TEST_P(NdkBinderTest_Aidl, UseBinder) {
ASSERT_EQ(STATUS_OK, AIBinder_ping(iface->asBinder().get()));
}
-TEST_P(NdkBinderTest_Aidl, Oneway) { ASSERT_OK(iface->TestOneway()); }
+TEST_P(NdkBinderTest_Aidl, Trivial) {
+ ASSERT_OK(iface->TestVoidReturn());
+ ASSERT_OK(iface->TestOneway());
+}
TEST_P(NdkBinderTest_Aidl, Constants) {
ASSERT_EQ(0, ITest::kZero);
@@ -97,8 +110,8 @@
}
TEST_P(NdkBinderTest_Aidl, RepeatBinder) {
- AutoAIBinder binder = iface->asBinder();
- AutoAIBinder ret;
+ SpAIBinder binder = iface->asBinder();
+ SpAIBinder ret;
ASSERT_OK(iface->RepeatBinder(binder, &ret));
EXPECT_EQ(binder.get(), ret.get());
@@ -110,7 +123,7 @@
TEST_P(NdkBinderTest_Aidl, RepeatInterface) {
class MyEmpty : public ::aidl::test_package::BnEmpty {};
- std::shared_ptr<IEmpty> empty = (new MyEmpty)->ref<IEmpty>();
+ std::shared_ptr<IEmpty> empty = SharedRefBase::make<MyEmpty>();
std::shared_ptr<IEmpty> ret;
ASSERT_OK(iface->RepeatInterface(empty, &ret));
@@ -150,9 +163,15 @@
EXPECT_EQ(defaultPolygon.sideLength, outputPolygon.sideLength);
}
+TEST_P(NdkBinderTest_Aidl, InsAndOuts) {
+ RegularPolygon defaultPolygon;
+ ASSERT_OK(iface->RenamePolygon(&defaultPolygon, "Jerry"));
+ EXPECT_EQ("Jerry", defaultPolygon.name);
+}
+
std::shared_ptr<ITest> getLocalService() {
// BpTest -> AIBinder -> test
- std::shared_ptr<MyTest> test = (new MyTest)->ref<MyTest>();
+ std::shared_ptr<MyTest> test = SharedRefBase::make<MyTest>();
return BpTest::associate(test->asBinder());
}
@@ -182,16 +201,19 @@
return nullptr;
}
- AutoAIBinder binder = AutoAIBinder(AIBinder_fromJavaBinder(env, object));
+ SpAIBinder binder = SpAIBinder(AIBinder_fromJavaBinder(env, object));
return BpTest::associate(binder);
}
INSTANTIATE_TEST_CASE_P(Local, NdkBinderTest_Aidl,
- ::testing::Values(getLocalService()));
-INSTANTIATE_TEST_CASE_P(
- RemoteNative, NdkBinderTest_Aidl,
- ::testing::Values(getNdkBinderTestJavaService("getRemoteNativeService")));
-INSTANTIATE_TEST_CASE_P(
- RemoteJava, NdkBinderTest_Aidl,
- ::testing::Values(getNdkBinderTestJavaService("getRemoteJavaService")));
+ ::testing::Values(Params{getLocalService(),
+ false /*shouldBeRemote*/}));
+INSTANTIATE_TEST_CASE_P(RemoteNative, NdkBinderTest_Aidl,
+ ::testing::Values(Params{getNdkBinderTestJavaService(
+ "getRemoteNativeService"),
+ true /*shouldBeRemote*/}));
+INSTANTIATE_TEST_CASE_P(RemoteJava, NdkBinderTest_Aidl,
+ ::testing::Values(Params{
+ getNdkBinderTestJavaService("getRemoteJavaService"),
+ true /*shouldBeRemote*/}));
diff --git a/tests/tests/binder_ndk/libbinder_ndk_test/test_package/ITest.aidl b/tests/tests/binder_ndk/libbinder_ndk_test/test_package/ITest.aidl
index 9126cda..34f899b 100644
--- a/tests/tests/binder_ndk/libbinder_ndk_test/test_package/ITest.aidl
+++ b/tests/tests/binder_ndk/libbinder_ndk_test/test_package/ITest.aidl
@@ -48,4 +48,7 @@
String RepeatString(String value);
RegularPolygon RepeatPolygon(in RegularPolygon value);
+
+ // Testing inout
+ void RenamePolygon(inout RegularPolygon value, String newName);
}
diff --git a/tests/tests/binder_ndk/libbinder_ndk_test/utilities.h b/tests/tests/binder_ndk/libbinder_ndk_test/utilities.h
index 0067855..d254a45 100644
--- a/tests/tests/binder_ndk/libbinder_ndk_test/utilities.h
+++ b/tests/tests/binder_ndk/libbinder_ndk_test/utilities.h
@@ -29,7 +29,7 @@
static inline ::testing::AssertionResult isOk(T) = delete;
template <>
-inline ::testing::AssertionResult isOk(::android::AutoAStatus t) {
+inline ::testing::AssertionResult isOk(::ndk::ScopedAStatus t) {
if (AStatus_isOk(t.get())) {
return ::testing::AssertionSuccess();
} else {
diff --git a/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java b/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java
index 76b6f6a..5dc25b057 100644
--- a/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java
+++ b/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java
@@ -68,6 +68,12 @@
}
@Test
+ public void testTrivial() throws RemoteException {
+ mInterface.TestVoidReturn();
+ mInterface.TestOneway();
+ }
+
+ @Test
public void testRepeatPrimitives() throws RemoteException {
assertEquals(1, mInterface.RepeatInt(1));
assertEquals(2, mInterface.RepeatLong(2));
@@ -120,4 +126,11 @@
assertEquals(polygon.numSides, result.numSides);
assertEquals(polygon.sideLength, result.sideLength, 0.0f);
}
+
+ @Test
+ public void testInsAndOuts() throws RemoteException {
+ RegularPolygon polygon = new RegularPolygon();
+ mInterface.RenamePolygon(polygon, "Jerry");
+ assertEquals("Jerry", polygon.name);
+ }
}
diff --git a/tests/tests/binder_ndk/src/android/binder/cts/TestImpl.java b/tests/tests/binder_ndk/src/android/binder/cts/TestImpl.java
index 1acffec..1aa1c10 100644
--- a/tests/tests/binder_ndk/src/android/binder/cts/TestImpl.java
+++ b/tests/tests/binder_ndk/src/android/binder/cts/TestImpl.java
@@ -83,4 +83,9 @@
public RegularPolygon RepeatPolygon(RegularPolygon in_value) {
return in_value;
}
+
+ @Override
+ public void RenamePolygon(RegularPolygon value, String name) {
+ value.name = name;
+ }
}
diff --git a/tests/tests/graphics/jni/android_graphics_cts_BitmapTest.cpp b/tests/tests/graphics/jni/android_graphics_cts_BitmapTest.cpp
index 2e3bf06..b08f384 100644
--- a/tests/tests/graphics/jni/android_graphics_cts_BitmapTest.cpp
+++ b/tests/tests/graphics/jni/android_graphics_cts_BitmapTest.cpp
@@ -19,6 +19,8 @@
#include <jni.h>
#include <android/bitmap.h>
+#include <android/hardware_buffer.h>
+#include <android/hardware_buffer_jni.h>
#include "NativeTestHelpers.h"
@@ -41,11 +43,37 @@
ASSERT_EQ(err, ANDROID_BITMAP_RESULT_JNI_EXCEPTION);
}
+static void fillRgbaHardwareBuffer(JNIEnv* env, jclass, jobject hwBuffer) {
+ AHardwareBuffer* hardware_buffer = AHardwareBuffer_fromHardwareBuffer(env, hwBuffer);
+ AHardwareBuffer_Desc description;
+ AHardwareBuffer_describe(hardware_buffer, &description);
+ ASSERT_EQ(AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM, description.format);
+
+ uint8_t* rgbaBytes;
+ AHardwareBuffer_lock(hardware_buffer,
+ AHARDWAREBUFFER_USAGE_CPU_WRITE_RARELY,
+ -1,
+ nullptr,
+ reinterpret_cast<void**>(&rgbaBytes));
+ int c = 0;
+ for (int y = 0; y < description.width; ++y) {
+ for (int x = 0; x < description.height; ++x) {
+ rgbaBytes[c++] = static_cast<uint8_t>(x % 255);
+ rgbaBytes[c++] = static_cast<uint8_t>(y % 255);
+ rgbaBytes[c++] = 42;
+ rgbaBytes[c++] = 255;
+ }
+ }
+ AHardwareBuffer_unlock(hardware_buffer, nullptr);
+}
+
static JNINativeMethod gMethods[] = {
{ "nValidateBitmapInfo", "(Landroid/graphics/Bitmap;IIZ)V",
(void*) validateBitmapInfo },
{ "nValidateNdkAccessAfterRecycle", "(Landroid/graphics/Bitmap;)V",
(void*) validateNdkAccessAfterRecycle },
+ { "nFillRgbaHwBuffer", "(Landroid/hardware/HardwareBuffer;)V",
+ (void*) fillRgbaHardwareBuffer },
};
int register_android_graphics_cts_BitmapTest(JNIEnv* env) {
diff --git a/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java b/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java
index 5289726..69bb828 100644
--- a/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/BitmapTest.java
@@ -34,6 +34,7 @@
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Picture;
+import android.hardware.HardwareBuffer;
import android.os.Debug;
import android.os.Parcel;
import android.os.StrictMode;
@@ -522,6 +523,31 @@
}
@Test
+ public void testWrapHardwareBufferSucceeds() {
+ try (HardwareBuffer hwBuffer = createTestBuffer(128, 128, false)) {
+ Bitmap bitmap = Bitmap.wrapHardwareBuffer(hwBuffer, ColorSpace.get(Named.SRGB));
+ assertNotNull(bitmap);
+ bitmap.recycle();
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testWrapHardwareBufferWithInvalidUsageFails() {
+ try (HardwareBuffer hwBuffer = HardwareBuffer.create(512, 512, HardwareBuffer.RGBA_8888, 1,
+ HardwareBuffer.USAGE_CPU_WRITE_RARELY)) {
+ Bitmap bitmap = Bitmap.wrapHardwareBuffer(hwBuffer, ColorSpace.get(Named.SRGB));
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testWrapHardwareBufferWithRgbBufferButNonRgbColorSpaceFails() {
+ try (HardwareBuffer hwBuffer = HardwareBuffer.create(512, 512, HardwareBuffer.RGBA_8888, 1,
+ HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE)) {
+ Bitmap bitmap = Bitmap.wrapHardwareBuffer(hwBuffer, ColorSpace.get(Named.CIE_LAB));
+ }
+ }
+
+ @Test
public void testGenerationId() {
Bitmap bitmap = Bitmap.createBitmap(10, 10, Config.ARGB_8888);
int genId = bitmap.getGenerationId();
@@ -1380,6 +1406,30 @@
assertFalse(bitmap1.sameAs(bitmap4));
}
+ @Test
+ public void testSameAs_wrappedHardwareBuffer() {
+ try (HardwareBuffer hwBufferA = createTestBuffer(512, 512, true);
+ HardwareBuffer hwBufferB = createTestBuffer(512, 512, true);
+ HardwareBuffer hwBufferC = createTestBuffer(512, 512, true);) {
+ // Fill buffer C with generated data
+ nFillRgbaHwBuffer(hwBufferC);
+
+ // Create the test bitmaps
+ Bitmap bitmap1 = Bitmap.wrapHardwareBuffer(hwBufferA, ColorSpace.get(Named.SRGB));
+ Bitmap bitmap2 = Bitmap.wrapHardwareBuffer(hwBufferA, ColorSpace.get(Named.SRGB));
+ Bitmap bitmap3 = BitmapFactory.decodeResource(mRes, R.drawable.robot);
+ Bitmap bitmap4 = Bitmap.wrapHardwareBuffer(hwBufferB, ColorSpace.get(Named.SRGB));
+ Bitmap bitmap5 = Bitmap.wrapHardwareBuffer(hwBufferC, ColorSpace.get(Named.SRGB));
+
+ // Run the compare-a-thon
+ assertTrue(bitmap1.sameAs(bitmap2)); // SAME UNDERLYING BUFFER
+ assertTrue(bitmap2.sameAs(bitmap1)); // SAME UNDERLYING BUFFER
+ assertFalse(bitmap1.sameAs(bitmap3)); // HW vs. NON-HW
+ assertTrue(bitmap1.sameAs(bitmap4)); // DIFFERENT BUFFERS, SAME CONTENT
+ assertFalse(bitmap1.sameAs(bitmap5)); // DIFFERENT BUFFERS, DIFFERENT CONTENT
+ }
+ }
+
@Test(expected=IllegalStateException.class)
public void testHardwareGetPixel() {
Bitmap bitmap = BitmapFactory.decodeResource(mRes, R.drawable.robot, HARDWARE_OPTIONS);
@@ -1620,6 +1670,41 @@
@Test
@LargeTest
+ public void testWrappedHardwareBufferBitmapNotLeaking() {
+ Debug.MemoryInfo meminfoStart = new Debug.MemoryInfo();
+ Debug.MemoryInfo meminfoEnd = new Debug.MemoryInfo();
+ BitmapFactory.Options opts = new BitmapFactory.Options();
+ opts.inPreferredConfig = Config.HARDWARE;
+ opts.inScaled = false;
+
+ final ColorSpace colorSpace = ColorSpace.get(Named.SRGB);
+ try (HardwareBuffer hwBuffer = createTestBuffer(128, 128, false)) {
+ for (int i = 0; i < 2000; i++) {
+ if (i == 2) {
+ // Not really the "start" but by having done a couple
+ // we've fully initialized any state that may be required,
+ // so memory usage should be stable now
+ runGcAndFinalizersSync();
+ Debug.getMemoryInfo(meminfoStart);
+ }
+ if (i % 100 == 5) {
+ assertNotLeaking(i, meminfoStart, meminfoEnd);
+ }
+ Bitmap bitmap = Bitmap.wrapHardwareBuffer(hwBuffer, colorSpace);
+ assertNotNull(bitmap);
+ // Make sure nothing messed with the bitmap
+ assertEquals(128, bitmap.getWidth());
+ assertEquals(128, bitmap.getHeight());
+ assertEquals(Config.HARDWARE, bitmap.getConfig());
+ bitmap.recycle();
+ }
+ }
+
+ assertNotLeaking(2000, meminfoStart, meminfoEnd);
+ }
+
+ @Test
+ @LargeTest
public void testDrawingHardwareBitmapNotLeaking() {
Debug.MemoryInfo meminfoStart = new Debug.MemoryInfo();
Debug.MemoryInfo meminfoEnd = new Debug.MemoryInfo();
@@ -1656,6 +1741,64 @@
assertNotLeaking(2000, meminfoStart, meminfoEnd);
}
+ @Test
+ public void testWrapHardwareBufferHoldsReference() {
+ RenderTarget renderTarget = RenderTarget.create();
+ renderTarget.setDefaultSize(128, 128);
+ final Surface surface = renderTarget.getSurface();
+ Bitmap bitmap = null;
+
+ // Create hardware-buffer and wrap it in a Bitmap
+ try (HardwareBuffer hwBuffer = createTestBuffer(128, 128, false)) {
+ // Fill buffer with colors (x, y, 42, 255)
+ nFillRgbaHwBuffer(hwBuffer);
+ bitmap = Bitmap.wrapHardwareBuffer(hwBuffer, ColorSpace.get(Named.SRGB));
+ }
+
+ // Buffer is closed at this point. Ensure bitmap still works by drawing it
+ assertEquals(128, bitmap.getWidth());
+ assertEquals(128, bitmap.getHeight());
+ assertEquals(Config.HARDWARE, bitmap.getConfig());
+
+ // Copy bitmap to target bitmap we can read from
+ Bitmap dstBitmap = bitmap.copy(Config.ARGB_8888, false);
+ bitmap.recycle();
+
+ // Ensure that the bitmap has valid contents
+ int pixel = dstBitmap.getPixel(0, 0);
+ assertEquals(255 << 24 | 42, pixel);
+ dstBitmap.recycle();
+ }
+
+ @Test
+ public void testWrapHardwareBufferPreservesColors() {
+ try (HardwareBuffer hwBuffer = createTestBuffer(128, 128, true)) {
+ // Fill buffer with colors (x, y, 42, 255)
+ nFillRgbaHwBuffer(hwBuffer);
+
+ // Create HW bitmap from this buffer
+ Bitmap srcBitmap = Bitmap.wrapHardwareBuffer(hwBuffer, ColorSpace.get(Named.SRGB));
+ assertNotNull(srcBitmap);
+
+ // Copy it to target non-HW bitmap
+ Bitmap dstBitmap = srcBitmap.copy(Config.ARGB_8888, false);
+ srcBitmap.recycle();
+
+ // Ensure all colors are as expected (matches the nFillRgbaHwBuffer call used above).
+ for (int y = 0; y < 128; ++y) {
+ for (int x = 0; x < 128; ++x) {
+ int pixel = dstBitmap.getPixel(x, y);
+ short a = 255;
+ short r = (short) (x % 255);
+ short g = (short) (y % 255);
+ short b = 42;
+ assertEquals(a << 24 | r << 16 | g << 8 | b, pixel);
+ }
+ }
+ dstBitmap.recycle();
+ }
+ }
+
private void strictModeTest(Runnable runnable) {
StrictMode.ThreadPolicy originalPolicy = StrictMode.getThreadPolicy();
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
@@ -1674,6 +1817,19 @@
boolean is565);
private static native void nValidateNdkAccessAfterRecycle(Bitmap bitmap);
+ private static native void nFillRgbaHwBuffer(HardwareBuffer hwBuffer);
+
+ private static HardwareBuffer createTestBuffer(int width, int height, boolean cpuAccess) {
+ long usage = HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE;
+ if (cpuAccess) {
+ usage |= HardwareBuffer.USAGE_CPU_WRITE_RARELY;
+ }
+ // We can assume that RGBA_8888 format is supported for every platform.
+ HardwareBuffer hwBuffer = HardwareBuffer.create(width, height, HardwareBuffer.RGBA_8888,
+ 1, usage);
+ return hwBuffer;
+ }
+
private static int scaleFromDensity(int size, int sdensity, int tdensity) {
if (sdensity == Bitmap.DENSITY_NONE || sdensity == tdensity) {
return size;
diff --git a/tools/release-parser/tests/classyshark.properties b/tools/release-parser/tests/classyshark.properties
deleted file mode 100644
index 19bb30a..0000000
--- a/tools/release-parser/tests/classyshark.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-#CURRENT_FOLDERwrote
-#Fri Oct 05 13:39:27 PDT 2018
-CURRENT_FOLDER=/mnt/secondary/master/cts/tools/release-parser/tests/resources
diff --git a/tools/release-parser/tests/classyshark_recents.properties b/tools/release-parser/tests/classyshark_recents.properties
deleted file mode 100644
index 2e9cd81..0000000
--- a/tools/release-parser/tests/classyshark_recents.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-#CURRENT_FOLDERwrote
-#Fri Oct 05 13:39:27 PDT 2018
-HelloActivity.apk=/mnt/secondary/master/cts/tools/release-parser/tests/resources
diff --git a/tools/release-parser/tests/classyshark_ui.properties b/tools/release-parser/tests/classyshark_ui.properties
deleted file mode 100644
index e69de29..0000000
--- a/tools/release-parser/tests/classyshark_ui.properties
+++ /dev/null