• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 "VrManagerService"
18 
19 #include <android_runtime/AndroidRuntime.h>
20 #include <jni.h>
21 #include <nativehelper/JNIHelp.h>
22 
23 #include <android/hardware/vr/1.0/IVr.h>
24 #include <utils/Errors.h>
25 #include <utils/Log.h>
26 
27 namespace android {
28 
29 using ::android::hardware::vr::V1_0::IVr;
30 
31 static sp<IVr> gVr;
32 
init_native(JNIEnv *,jclass)33 static void init_native(JNIEnv* /* env */, jclass /* clazz */) {
34     // TODO(b/31632518)
35     if (gVr != nullptr) {
36         // This call path should never be hit.
37         ALOGE("%s: May not initialize IVr interface module more than once!", __FUNCTION__);
38         return;
39     }
40 
41     gVr = IVr::getService();
42     if (gVr == nullptr) {
43         ALOGW("%s: Could not open IVr interface", __FUNCTION__);
44         return;
45     }
46 
47     gVr->init();
48 }
49 
setVrMode_native(JNIEnv *,jclass,jboolean enabled)50 static void setVrMode_native(JNIEnv* /* env */, jclass /* clazz */, jboolean enabled) {
51     if (gVr == nullptr) {
52         // There is no VR hardware module implemented, do nothing.
53         return;
54     }
55 
56     // Call set_vr_mode method, this must be implemented if the HAL exists.
57     gVr->setVrMode(static_cast<bool>(enabled));
58 }
59 
60 static const JNINativeMethod method_table[] = {
61     { "initializeNative", "()V", (void*)init_native },
62     { "setVrModeNative", "(Z)V", (void*)setVrMode_native },
63 };
64 
register_android_server_vr_VrManagerService(JNIEnv * env)65 int register_android_server_vr_VrManagerService(JNIEnv *env)
66 {
67     return jniRegisterNativeMethods(env, "com/android/server/vr/VrManagerService",
68             method_table, NELEM(method_table));
69 }
70 
71 }; // namespace android
72