1 /*
2 * Copyright (C) 2023 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 <android/binder_ibinder_jni.h>
18 #include <android/binder_manager.h>
19 #include <jni.h>
20 #include "nativehelper/JNIHelp.h"
21 #include <nativehelper/ScopedUtfChars.h>
22 #include <private/android_filesystem_config.h>
23
24 namespace android {
com_android_server_ServiceManagerWrapper_waitForService(JNIEnv * env,jobject clazz,jstring serviceName)25 static jobject com_android_server_ServiceManagerWrapper_waitForService(
26 JNIEnv* env, jobject clazz, jstring serviceName) {
27 ScopedUtfChars name(env, serviceName);
28
29 // AServiceManager_waitForService is available on only 31+, but it's still safe for Thread
30 // service because it's enabled on only 34+
31 #pragma clang diagnostic push
32 #pragma clang diagnostic ignored "-Wunguarded-availability"
33 return AIBinder_toJavaBinder(env, AServiceManager_waitForService(name.c_str()));
34 #pragma clang diagnostic pop
35 }
36
37 /*
38 * JNI registration.
39 */
40
41 static const JNINativeMethod gMethods[] = {
42 /* name, signature, funcPtr */
43 {"nativeWaitForService",
44 "(Ljava/lang/String;)Landroid/os/IBinder;",
45 (void*)com_android_server_ServiceManagerWrapper_waitForService},
46 };
47
register_com_android_server_ServiceManagerWrapper(JNIEnv * env)48 int register_com_android_server_ServiceManagerWrapper(JNIEnv* env) {
49 return jniRegisterNativeMethods(env,
50 "android/net/connectivity/com/android/server/ServiceManagerWrapper",
51 gMethods, NELEM(gMethods));
52 }
53
54 }; // namespace android
55