1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #include <jni.h>
19 
20 namespace {
21 
fakeMethod()22 bool fakeMethod() { return true; }
23 
com_android_tests_apex_app_nativeFakeMethod(JNIEnv *,jclass)24 jint com_android_tests_apex_app_nativeFakeMethod(JNIEnv * /*env*/,
25                                                  jclass /*clazz*/) {
26   return (jboolean)fakeMethod();
27 }
28 
29 static JNINativeMethod gMethods[] = {
30     {"nativeFakeMethod", "()Z",
31      (void *)com_android_tests_apex_app_nativeFakeMethod}};
32 
33 } // anonymous namespace
34 
register_android_native_code_test_data(JNIEnv * env)35 int register_android_native_code_test_data(JNIEnv *env) {
36   jclass clazz = env->FindClass("com/android/tests/apex/app/ApkInApexTests");
37   return env->RegisterNatives(clazz, gMethods,
38                               sizeof(gMethods) / sizeof(JNINativeMethod));
39 }
40 
JNI_OnLoad(JavaVM * vm,void *)41 jint JNI_OnLoad(JavaVM *vm, void * /*reserved*/) {
42   JNIEnv *env = nullptr;
43   if (vm->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK)
44     return JNI_ERR;
45   if (register_android_native_code_test_data(env))
46     return JNI_ERR;
47   return JNI_VERSION_1_6;
48 }
49