1 /*
2 * Copyright (C) 2020 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 #define LOG_TAG "GpuService-JNI"
18
19 #include <binder/IServiceManager.h>
20 #include <graphicsenv/IGpuService.h>
21 #include <nativehelper/JNIHelp.h>
22 #include <nativehelper/scoped_utf_chars.h>
23
24 namespace {
25
getGpuService()26 static android::sp<android::IGpuService> getGpuService() {
27 static const android::sp<android::IBinder> binder =
28 android::defaultServiceManager()->checkService(android::String16("gpu"));
29 if (!binder) {
30 ALOGE("Failed to get gpu service");
31 return nullptr;
32 }
33
34 return interface_cast<android::IGpuService>(binder);
35 }
36
setUpdatableDriverPath_native(JNIEnv * env,jobject clazz,jstring jDriverPath)37 void setUpdatableDriverPath_native(JNIEnv* env, jobject clazz, jstring jDriverPath) {
38 if (jDriverPath == nullptr) {
39 return;
40 }
41 const android::sp<android::IGpuService> gpuService = getGpuService();
42 if (!gpuService) {
43 return;
44 }
45 ScopedUtfChars driverPath(env, jDriverPath);
46 gpuService->setUpdatableDriverPath(driverPath.c_str());
47 }
48
49 static const JNINativeMethod gGpuServiceMethods[] = {
50 /* name, signature, funcPtr */
51 {"nSetUpdatableDriverPath", "(Ljava/lang/String;)V",
52 reinterpret_cast<void*>(setUpdatableDriverPath_native)},
53 };
54
55 const char* const kGpuServiceName = "com/android/server/gpu/GpuService";
56
57 } // anonymous namespace
58
59 namespace android {
60
register_android_server_GpuService(JNIEnv * env)61 int register_android_server_GpuService(JNIEnv* env) {
62 return jniRegisterNativeMethods(env, kGpuServiceName, gGpuServiceMethods,
63 NELEM(gGpuServiceMethods));
64 }
65
66 } /* namespace android */
67