1 /*
2 * Copyright (C) 2024 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 #include <dlfcn.h>
18 #include <jni.h>
19 #include <string.h>
20
21 extern "C" {
22
Java_android_nativeapi_cts_NonProductionReadyNativeApiCheck_checkNonProductionReadyNativeApis(JNIEnv * env,jobject obj,jobjectArray nonProductionReadyApis)23 JNIEXPORT jobjectArray JNICALL Java_android_nativeapi_cts_NonProductionReadyNativeApiCheck_checkNonProductionReadyNativeApis(
24 JNIEnv* env, jobject obj, jobjectArray nonProductionReadyApis)
25 {
26 int size = env->GetArrayLength(nonProductionReadyApis);
27 jobjectArray ret = (jobjectArray)env->NewObjectArray(
28 size,
29 env->FindClass("java/lang/String"),
30 env->NewStringUTF(""));
31
32 for (int i = 0; i < size; i++) {
33 jstring string = (jstring) env->GetObjectArrayElement(nonProductionReadyApis, i);
34 const char* api = env->GetStringUTFChars(string, 0);
35 if (dlsym(RTLD_DEFAULT, api) != nullptr) {
36 env->SetObjectArrayElement(
37 ret, i, env->NewStringUTF(api));
38 } else {
39 env->SetObjectArrayElement(
40 ret, i, env->NewStringUTF(""));
41 }
42 env->ReleaseStringUTFChars(string, api);
43 env->DeleteLocalRef(string);
44 }
45
46 return ret;
47 }
48
49 }
50