From 6b1e88e5d09a88dd77e631918aa7122a95a7ff4b Mon Sep 17 00:00:00 2001 From: Maxim Siniavine Date: Wed, 2 Jul 2014 18:09:59 -0700 Subject: Add test apps for shared uid package manager test Change-Id: I00c0db7a122774260d93d06212f4485210f86532 --- .../hosttests/test-apps/SharedUid/32/Android.mk | 43 ++++++++ .../test-apps/SharedUid/32/AndroidManifest.xml | 29 ++++++ .../test-apps/SharedUid/32/jni/Android.mk | 39 ++++++++ .../test-apps/SharedUid/32/jni/native.cpp | 109 +++++++++++++++++++++ .../framework/shareduid/bit32/MainActivity.java | 43 ++++++++ .../hosttests/test-apps/SharedUid/64/Android.mk | 43 ++++++++ .../test-apps/SharedUid/64/AndroidManifest.xml | 29 ++++++ .../test-apps/SharedUid/64/jni/Android.mk | 41 ++++++++ .../test-apps/SharedUid/64/jni/native.cpp | 109 +++++++++++++++++++++ .../framework/shareduid/bit64/MainActivity.java | 43 ++++++++ .../tests/hosttests/test-apps/SharedUid/Android.mk | 1 + .../hosttests/test-apps/SharedUid/dual/Android.mk | 43 ++++++++ .../test-apps/SharedUid/dual/AndroidManifest.xml | 29 ++++++ .../test-apps/SharedUid/dual/jni/Android.mk | 40 ++++++++ .../test-apps/SharedUid/dual/jni/native.cpp | 109 +++++++++++++++++++++ .../com/framework/shareduid/dual/MainActivity.java | 43 ++++++++ .../test-apps/SharedUid/java_only/Android.mk | 40 ++++++++ .../SharedUid/java_only/AndroidManifest.xml | 29 ++++++ .../com/framework/shareduid/java/MainActivity.java | 32 ++++++ 19 files changed, 894 insertions(+) create mode 100644 core/tests/hosttests/test-apps/SharedUid/32/Android.mk create mode 100644 core/tests/hosttests/test-apps/SharedUid/32/AndroidManifest.xml create mode 100644 core/tests/hosttests/test-apps/SharedUid/32/jni/Android.mk create mode 100644 core/tests/hosttests/test-apps/SharedUid/32/jni/native.cpp create mode 100644 core/tests/hosttests/test-apps/SharedUid/32/src/com/framework/shareduid/bit32/MainActivity.java create mode 100644 core/tests/hosttests/test-apps/SharedUid/64/Android.mk create mode 100644 core/tests/hosttests/test-apps/SharedUid/64/AndroidManifest.xml create mode 100644 core/tests/hosttests/test-apps/SharedUid/64/jni/Android.mk create mode 100644 core/tests/hosttests/test-apps/SharedUid/64/jni/native.cpp create mode 100644 core/tests/hosttests/test-apps/SharedUid/64/src/com/framework/shareduid/bit64/MainActivity.java create mode 100644 core/tests/hosttests/test-apps/SharedUid/Android.mk create mode 100644 core/tests/hosttests/test-apps/SharedUid/dual/Android.mk create mode 100644 core/tests/hosttests/test-apps/SharedUid/dual/AndroidManifest.xml create mode 100644 core/tests/hosttests/test-apps/SharedUid/dual/jni/Android.mk create mode 100644 core/tests/hosttests/test-apps/SharedUid/dual/jni/native.cpp create mode 100644 core/tests/hosttests/test-apps/SharedUid/dual/src/com/framework/shareduid/dual/MainActivity.java create mode 100644 core/tests/hosttests/test-apps/SharedUid/java_only/Android.mk create mode 100644 core/tests/hosttests/test-apps/SharedUid/java_only/AndroidManifest.xml create mode 100644 core/tests/hosttests/test-apps/SharedUid/java_only/src/com/framework/shareduid/java/MainActivity.java diff --git a/core/tests/hosttests/test-apps/SharedUid/32/Android.mk b/core/tests/hosttests/test-apps/SharedUid/32/Android.mk new file mode 100644 index 0000000..e141bbe --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/32/Android.mk @@ -0,0 +1,43 @@ +# +# Copyright (C) 2014 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. +# + +# This makefile shows how to build a shared library and an activity that +# bundles the shared library and calls it using JNI. + +TOP_LOCAL_PATH:= $(call my-dir) + +# Build activity + +LOCAL_PATH:= $(TOP_LOCAL_PATH) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_PACKAGE_NAME := PMTest_Java32 +LOCAL_MULTILIB := 32 +LOCAL_MODULE_TAGS := tests + +LOCAL_JNI_SHARED_LIBRARIES = libpmtest32 + +LOCAL_PROGUARD_ENABLED := disabled + +LOCAL_SDK_VERSION := current +include $(BUILD_PACKAGE) + +# ============================================================ + +# Also build all of the sub-targets under this one: the shared library. +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/core/tests/hosttests/test-apps/SharedUid/32/AndroidManifest.xml b/core/tests/hosttests/test-apps/SharedUid/32/AndroidManifest.xml new file mode 100644 index 0000000..8aaf5d6 --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/32/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + diff --git a/core/tests/hosttests/test-apps/SharedUid/32/jni/Android.mk b/core/tests/hosttests/test-apps/SharedUid/32/jni/Android.mk new file mode 100644 index 0000000..ff5a535 --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/32/jni/Android.mk @@ -0,0 +1,39 @@ +# +# Copyright (C) 2008 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. +# + +# This makefile supplies the rules for building a library of JNI code for +# use by our example of how to bundle a shared library with an APK. + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +# This is the target being built. +LOCAL_MODULE:= libpmtest32 +LOCAL_MULTILIB := 32 +LOCAL_MODULE_TAGS := tests + +# All of the source files that we will compile. +LOCAL_SRC_FILES:= \ + native.cpp + +# All of the shard libraries we link against. +LOCAL_SHARED_LIBRARIES := liblog + +# Also need the JNI headers. +LOCAL_C_INCLUDES += \ + $(JNI_H_INCLUDE) + +include $(BUILD_SHARED_LIBRARY) diff --git a/core/tests/hosttests/test-apps/SharedUid/32/jni/native.cpp b/core/tests/hosttests/test-apps/SharedUid/32/jni/native.cpp new file mode 100644 index 0000000..4c16154 --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/32/jni/native.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2008 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. + */ + +#define LOG_TAG "pmtest32 native.cpp" +#include + +#include + +#include "jni.h" + +static jint +add(JNIEnv *env, jobject thiz, jint a, jint b) { +int result = a + b; + ALOGI("%d + %d = %d", a, b, result); + return result; +} + +static const char *classPathName = "com/framework/shareduid/bit32/Native"; + +static JNINativeMethod methods[] = { + {"add", "(II)I", (void*)add }, +}; + +/* + * Register several native methods for one class. + */ +static int registerNativeMethods(JNIEnv* env, const char* className, + JNINativeMethod* gMethods, int numMethods) +{ + jclass clazz; + + clazz = env->FindClass(className); + if (clazz == NULL) { + ALOGE("Native registration unable to find class '%s'", className); + return JNI_FALSE; + } + if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) { + ALOGE("RegisterNatives failed for '%s'", className); + return JNI_FALSE; + } + + return JNI_TRUE; +} + +/* + * Register native methods for all classes we know about. + * + * returns JNI_TRUE on success. + */ +static int registerNatives(JNIEnv* env) +{ + if (!registerNativeMethods(env, classPathName, + methods, sizeof(methods) / sizeof(methods[0]))) { + return JNI_FALSE; + } + + return JNI_TRUE; +} + + +// ---------------------------------------------------------------------------- + +/* + * This is called by the VM when the shared library is first loaded. + */ + +typedef union { + JNIEnv* env; + void* venv; +} UnionJNIEnvToVoid; + +jint JNI_OnLoad(JavaVM* vm, void* reserved) +{ + UnionJNIEnvToVoid uenv; + uenv.venv = NULL; + jint result = -1; + JNIEnv* env = NULL; + + ALOGI("JNI_OnLoad"); + + if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) { + ALOGE("ERROR: GetEnv failed"); + goto bail; + } + env = uenv.env; + + if (registerNatives(env) != JNI_TRUE) { + ALOGE("ERROR: registerNatives failed"); + goto bail; + } + + result = JNI_VERSION_1_4; + +bail: + return result; +} diff --git a/core/tests/hosttests/test-apps/SharedUid/32/src/com/framework/shareduid/bit32/MainActivity.java b/core/tests/hosttests/test-apps/SharedUid/32/src/com/framework/shareduid/bit32/MainActivity.java new file mode 100644 index 0000000..5f6fc2a --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/32/src/com/framework/shareduid/bit32/MainActivity.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2014 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. + */ + +package com.framework.shareduid.bit32; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.TextView; + +class Native { + static { + // The runtime will add "lib" on the front and ".o" on the end of + // the name supplied to loadLibrary. + System.loadLibrary("pmtest32"); + } + + static native int add(int a, int b); +} + +public class MainActivity extends Activity { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + TextView tv = new TextView(this); + int sum = Native.add(2, 3); + tv.setText("[computed by 32 bit native code] 2 + 3 = " + String.valueOf(sum)); + setContentView(tv); + } +} diff --git a/core/tests/hosttests/test-apps/SharedUid/64/Android.mk b/core/tests/hosttests/test-apps/SharedUid/64/Android.mk new file mode 100644 index 0000000..4f24f33 --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/64/Android.mk @@ -0,0 +1,43 @@ +# +# Copyright (C) 2014 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. +# + +# This makefile shows how to build a shared library and an activity that +# bundles the shared library and calls it using JNI. + +TOP_LOCAL_PATH:= $(call my-dir) + +# Build activity + +LOCAL_PATH:= $(TOP_LOCAL_PATH) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_PACKAGE_NAME := PMTest_Java64 +LOCAL_MULTILIB := 64 +LOCAL_MODULE_TAGS := tests + +LOCAL_JNI_SHARED_LIBRARIES = libpmtest64 + +LOCAL_PROGUARD_ENABLED := disabled + +LOCAL_SDK_VERSION := current +include $(BUILD_PACKAGE) + +# ============================================================ + +# Also build all of the sub-targets under this one: the shared library. +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/core/tests/hosttests/test-apps/SharedUid/64/AndroidManifest.xml b/core/tests/hosttests/test-apps/SharedUid/64/AndroidManifest.xml new file mode 100644 index 0000000..c3d51ef --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/64/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + diff --git a/core/tests/hosttests/test-apps/SharedUid/64/jni/Android.mk b/core/tests/hosttests/test-apps/SharedUid/64/jni/Android.mk new file mode 100644 index 0000000..abb1d9f --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/64/jni/Android.mk @@ -0,0 +1,41 @@ +# +# Copyright (C) 2008 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. +# + +# This makefile supplies the rules for building a library of JNI code for +# use by our example of how to bundle a shared library with an APK. + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +# This is the target being built. +LOCAL_MODULE:= libpmtest64 +LOCAL_MULTILIB := 64 +LOCAL_MODULE_TAGS := tests + + +# All of the source files that we will compile. +LOCAL_SRC_FILES:= \ + native.cpp + +# All of the shared libraries we link against. +LOCAL_SHARED_LIBRARIES := \ + libutils liblog + +# Also need the JNI headers. +LOCAL_C_INCLUDES += \ + $(JNI_H_INCLUDE) + +include $(BUILD_SHARED_LIBRARY) diff --git a/core/tests/hosttests/test-apps/SharedUid/64/jni/native.cpp b/core/tests/hosttests/test-apps/SharedUid/64/jni/native.cpp new file mode 100644 index 0000000..c2f9f52 --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/64/jni/native.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2008 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. + */ + +#define LOG_TAG "pmtest64 native.cpp" +#include + +#include + +#include "jni.h" + +static jint +add(JNIEnv *env, jobject thiz, jint a, jint b) { +int result = a + b; + ALOGI("%d + %d = %d", a, b, result); + return result; +} + +static const char *classPathName = "com/framework/shareduid/bit64/Native"; + +static JNINativeMethod methods[] = { + {"add", "(II)I", (void*)add }, +}; + +/* + * Register several native methods for one class. + */ +static int registerNativeMethods(JNIEnv* env, const char* className, + JNINativeMethod* gMethods, int numMethods) +{ + jclass clazz; + + clazz = env->FindClass(className); + if (clazz == NULL) { + ALOGE("Native registration unable to find class '%s'", className); + return JNI_FALSE; + } + if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) { + ALOGE("RegisterNatives failed for '%s'", className); + return JNI_FALSE; + } + + return JNI_TRUE; +} + +/* + * Register native methods for all classes we know about. + * + * returns JNI_TRUE on success. + */ +static int registerNatives(JNIEnv* env) +{ + if (!registerNativeMethods(env, classPathName, + methods, sizeof(methods) / sizeof(methods[0]))) { + return JNI_FALSE; + } + + return JNI_TRUE; +} + + +// ---------------------------------------------------------------------------- + +/* + * This is called by the VM when the shared library is first loaded. + */ + +typedef union { + JNIEnv* env; + void* venv; +} UnionJNIEnvToVoid; + +jint JNI_OnLoad(JavaVM* vm, void* reserved) +{ + UnionJNIEnvToVoid uenv; + uenv.venv = NULL; + jint result = -1; + JNIEnv* env = NULL; + + ALOGI("JNI_OnLoad"); + + if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) { + ALOGE("ERROR: GetEnv failed"); + goto bail; + } + env = uenv.env; + + if (registerNatives(env) != JNI_TRUE) { + ALOGE("ERROR: registerNatives failed"); + goto bail; + } + + result = JNI_VERSION_1_4; + +bail: + return result; +} diff --git a/core/tests/hosttests/test-apps/SharedUid/64/src/com/framework/shareduid/bit64/MainActivity.java b/core/tests/hosttests/test-apps/SharedUid/64/src/com/framework/shareduid/bit64/MainActivity.java new file mode 100644 index 0000000..12082a0 --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/64/src/com/framework/shareduid/bit64/MainActivity.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2014 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. + */ + +package com.framework.shareduid.bit64; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.TextView; + +class Native { + static { + // The runtime will add "lib" on the front and ".o" on the end of + // the name supplied to loadLibrary. + System.loadLibrary("pmtest64"); + } + + static native int add(int a, int b); +} + +public class MainActivity extends Activity { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + TextView tv = new TextView(this); + int sum = Native.add(2, 3); + tv.setText("[computed by 64 bit native code] 2 + 3 = " + String.valueOf(sum)); + setContentView(tv); + } +} diff --git a/core/tests/hosttests/test-apps/SharedUid/Android.mk b/core/tests/hosttests/test-apps/SharedUid/Android.mk new file mode 100644 index 0000000..5053e7d --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/Android.mk @@ -0,0 +1 @@ +include $(call all-subdir-makefiles) diff --git a/core/tests/hosttests/test-apps/SharedUid/dual/Android.mk b/core/tests/hosttests/test-apps/SharedUid/dual/Android.mk new file mode 100644 index 0000000..a7dc1bd0 --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/dual/Android.mk @@ -0,0 +1,43 @@ +# +# Copyright (C) 2014 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. +# + +# This makefile shows how to build a shared library and an activity that +# bundles the shared library and calls it using JNI. + +TOP_LOCAL_PATH:= $(call my-dir) + +# Build activity + +LOCAL_PATH:= $(TOP_LOCAL_PATH) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_PACKAGE_NAME := PMTest_Java_dual +LOCAL_MULTILIB := both +LOCAL_MODULE_TAGS := tests + +LOCAL_JNI_SHARED_LIBRARIES = libpmtestdual + +LOCAL_PROGUARD_ENABLED := disabled + +LOCAL_SDK_VERSION := current +include $(BUILD_PACKAGE) + +# ============================================================ + +# Also build all of the sub-targets under this one: the shared library. +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/core/tests/hosttests/test-apps/SharedUid/dual/AndroidManifest.xml b/core/tests/hosttests/test-apps/SharedUid/dual/AndroidManifest.xml new file mode 100644 index 0000000..b7ff46a --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/dual/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + diff --git a/core/tests/hosttests/test-apps/SharedUid/dual/jni/Android.mk b/core/tests/hosttests/test-apps/SharedUid/dual/jni/Android.mk new file mode 100644 index 0000000..ae8e636 --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/dual/jni/Android.mk @@ -0,0 +1,40 @@ +# +# Copyright (C) 2008 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. +# + +# This makefile supplies the rules for building a library of JNI code for +# use by our example of how to bundle a shared library with an APK. + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +# This is the target being built. +LOCAL_MODULE:= libpmtestdual +LOCAL_MULTILIB := both +LOCAL_MODULE_TAGS := tests + +# All of the source files that we will compile. +LOCAL_SRC_FILES:= \ + native.cpp + +# All of the shard libraries we link against. +LOCAL_LDLIBS = -llog +LOCAL_SHARED_LIBRARIES := liblog + +# Also need the JNI headers. +LOCAL_C_INCLUDES += \ + $(JNI_H_INCLUDE) + +include $(BUILD_SHARED_LIBRARY) diff --git a/core/tests/hosttests/test-apps/SharedUid/dual/jni/native.cpp b/core/tests/hosttests/test-apps/SharedUid/dual/jni/native.cpp new file mode 100644 index 0000000..5d3ca06 --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/dual/jni/native.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2008 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. + */ + +#define LOG_TAG "pmtestdual native.cpp" +#include + +#include + +#include "jni.h" + +static jint +add(JNIEnv *env, jobject thiz, jint a, jint b) { +int result = a + b; + ALOGI("%d + %d = %d", a, b, result); + return result; +} + +static const char *classPathName = "com/framework/shareduid/dual/Native"; + +static JNINativeMethod methods[] = { + {"add", "(II)I", (void*)add }, +}; + +/* + * Register several native methods for one class. + */ +static int registerNativeMethods(JNIEnv* env, const char* className, + JNINativeMethod* gMethods, int numMethods) +{ + jclass clazz; + + clazz = env->FindClass(className); + if (clazz == NULL) { + ALOGE("Native registration unable to find class '%s'", className); + return JNI_FALSE; + } + if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) { + ALOGE("RegisterNatives failed for '%s'", className); + return JNI_FALSE; + } + + return JNI_TRUE; +} + +/* + * Register native methods for all classes we know about. + * + * returns JNI_TRUE on success. + */ +static int registerNatives(JNIEnv* env) +{ + if (!registerNativeMethods(env, classPathName, + methods, sizeof(methods) / sizeof(methods[0]))) { + return JNI_FALSE; + } + + return JNI_TRUE; +} + + +// ---------------------------------------------------------------------------- + +/* + * This is called by the VM when the shared library is first loaded. + */ + +typedef union { + JNIEnv* env; + void* venv; +} UnionJNIEnvToVoid; + +jint JNI_OnLoad(JavaVM* vm, void* reserved) +{ + UnionJNIEnvToVoid uenv; + uenv.venv = NULL; + jint result = -1; + JNIEnv* env = NULL; + + ALOGI("JNI_OnLoad"); + + if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) { + ALOGE("ERROR: GetEnv failed"); + goto bail; + } + env = uenv.env; + + if (registerNatives(env) != JNI_TRUE) { + ALOGE("ERROR: registerNatives failed"); + goto bail; + } + + result = JNI_VERSION_1_4; + +bail: + return result; +} diff --git a/core/tests/hosttests/test-apps/SharedUid/dual/src/com/framework/shareduid/dual/MainActivity.java b/core/tests/hosttests/test-apps/SharedUid/dual/src/com/framework/shareduid/dual/MainActivity.java new file mode 100644 index 0000000..788ede6 --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/dual/src/com/framework/shareduid/dual/MainActivity.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2014 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. + */ + +package com.framework.shareduid.dual; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.TextView; + +class Native { + static { + // The runtime will add "lib" on the front and ".o" on the end of + // the name supplied to loadLibrary. + System.loadLibrary("pmtestdual"); + } + + static native int add(int a, int b); +} + +public class MainActivity extends Activity { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + TextView tv = new TextView(this); + int sum = Native.add(2, 3); + tv.setText("[computed by 32 bit native code] 2 + 3 = " + String.valueOf(sum)); + setContentView(tv); + } +} diff --git a/core/tests/hosttests/test-apps/SharedUid/java_only/Android.mk b/core/tests/hosttests/test-apps/SharedUid/java_only/Android.mk new file mode 100644 index 0000000..b846756 --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/java_only/Android.mk @@ -0,0 +1,40 @@ +# +# Copyright (C) 2014 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. +# + +# This makefile shows how to build a shared library and an activity that +# bundles the shared library and calls it using JNI. + +TOP_LOCAL_PATH:= $(call my-dir) + +# Build activity + +LOCAL_PATH:= $(TOP_LOCAL_PATH) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_PACKAGE_NAME := PMTest_Java +LOCAL_MODULE_TAGS := tests + +LOCAL_PROGUARD_ENABLED := disabled + +LOCAL_SDK_VERSION := current +include $(BUILD_PACKAGE) + +# ============================================================ + +# Also build all of the sub-targets under this one: the shared library. +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/core/tests/hosttests/test-apps/SharedUid/java_only/AndroidManifest.xml b/core/tests/hosttests/test-apps/SharedUid/java_only/AndroidManifest.xml new file mode 100644 index 0000000..c52689a --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/java_only/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + diff --git a/core/tests/hosttests/test-apps/SharedUid/java_only/src/com/framework/shareduid/java/MainActivity.java b/core/tests/hosttests/test-apps/SharedUid/java_only/src/com/framework/shareduid/java/MainActivity.java new file mode 100644 index 0000000..4b658af --- /dev/null +++ b/core/tests/hosttests/test-apps/SharedUid/java_only/src/com/framework/shareduid/java/MainActivity.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2014 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. + */ + +package com.framework.shareduid.java; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.TextView; + +public class MainActivity extends Activity { + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + TextView tv = new TextView(this); + tv.setText("2 + 3 = 5 (computed in Java)"); + setContentView(tv); + } +} -- cgit v1.1