diff options
author | Maxim Siniavine <siniavine@google.com> | 2014-07-02 18:09:59 -0700 |
---|---|---|
committer | Maxim Siniavine <siniavine@google.com> | 2014-07-09 19:36:19 -0700 |
commit | 6b1e88e5d09a88dd77e631918aa7122a95a7ff4b (patch) | |
tree | ba884efe0f012c736242e95c51e91c43bb038349 | |
parent | 85516d028b2dcc7ebc09f4a68085836aa26191d5 (diff) | |
download | frameworks_base-6b1e88e5d09a88dd77e631918aa7122a95a7ff4b.zip frameworks_base-6b1e88e5d09a88dd77e631918aa7122a95a7ff4b.tar.gz frameworks_base-6b1e88e5d09a88dd77e631918aa7122a95a7ff4b.tar.bz2 |
Add test apps for shared uid package manager test
Change-Id: I00c0db7a122774260d93d06212f4485210f86532
19 files changed, 894 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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 is an example of writing an application that bundles a + native code library. --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.framework.shareduid.bit32" android:sharedUserId="com.framework.shareduid"> + <application android:label="Main Activity (32 bit)"> + <activity android:name="MainActivity"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest> 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 <utils/Log.h> + +#include <stdio.h> + +#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 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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 is an example of writing an application that bundles a + native code library. --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.framework.shareduid.bit64" android:sharedUserId="com.framework.shareduid"> + <application android:label="Main Activity (64 bit)"> + <activity android:name="MainActivity"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest> 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 <utils/Log.h> + +#include <stdio.h> + +#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 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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 is an example of writing an application that bundles a + native code library. --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.framework.shareduid.dual" android:sharedUserId="com.framework.shareduid"> + <application android:label="Main Activity (dual)"> + <activity android:name="MainActivity"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest> 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 <utils/Log.h> + +#include <stdio.h> + +#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 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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 is an example of writing an application that bundles a + native code library. --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.framework.shareduid.java" android:sharedUserId="com.framework.shareduid"> + <application android:label="Main Activity (java only)"> + <activity android:name="MainActivity"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest> 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); + } +} |