1 /*
2 * Copyright (C) 2007 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 <jni.h>
18 #include <JNIHelp.h>
19
20 #include <hidl/HidlTransportSupport.h>
21
22 #include <schedulerservice/SchedulingPolicyService.h>
23 #include <sensorservice/SensorService.h>
24 #include <sensorservicehidl/SensorManager.h>
25
26 #include <cutils/properties.h>
27 #include <utils/Log.h>
28 #include <utils/misc.h>
29 #include <utils/AndroidThreads.h>
30
31 namespace android {
32
android_server_SystemServer_startSensorService(JNIEnv *,jobject)33 static void android_server_SystemServer_startSensorService(JNIEnv* /* env */, jobject /* clazz */) {
34 char propBuf[PROPERTY_VALUE_MAX];
35 property_get("system_init.startsensorservice", propBuf, "1");
36 if (strcmp(propBuf, "1") == 0) {
37 SensorService::instantiate();
38 }
39
40 }
41
android_server_SystemServer_startHidlServices(JNIEnv * env,jobject)42 static void android_server_SystemServer_startHidlServices(JNIEnv* env, jobject /* clazz */) {
43 using ::android::frameworks::schedulerservice::V1_0::ISchedulingPolicyService;
44 using ::android::frameworks::schedulerservice::V1_0::implementation::SchedulingPolicyService;
45 using ::android::frameworks::sensorservice::V1_0::ISensorManager;
46 using ::android::frameworks::sensorservice::V1_0::implementation::SensorManager;
47 using ::android::hardware::configureRpcThreadpool;
48
49 status_t err;
50
51 configureRpcThreadpool(5, false /* callerWillJoin */);
52
53 JavaVM *vm;
54 LOG_ALWAYS_FATAL_IF(env->GetJavaVM(&vm) != JNI_OK, "Cannot get Java VM");
55
56 sp<ISensorManager> sensorService = new SensorManager(vm);
57 err = sensorService->registerAsService();
58 ALOGE_IF(err != OK, "Cannot register %s: %d", ISensorManager::descriptor, err);
59
60 sp<ISchedulingPolicyService> schedulingService = new SchedulingPolicyService();
61 err = schedulingService->registerAsService();
62 ALOGE_IF(err != OK, "Cannot register %s: %d", ISchedulingPolicyService::descriptor, err);
63 }
64
65 /*
66 * JNI registration.
67 */
68 static const JNINativeMethod gMethods[] = {
69 /* name, signature, funcPtr */
70 { "startSensorService", "()V", (void*) android_server_SystemServer_startSensorService },
71 { "startHidlServices", "()V", (void*) android_server_SystemServer_startHidlServices },
72 };
73
register_android_server_SystemServer(JNIEnv * env)74 int register_android_server_SystemServer(JNIEnv* env)
75 {
76 return jniRegisterNativeMethods(env, "com/android/server/SystemServer",
77 gMethods, NELEM(gMethods));
78 }
79
80 }; // namespace android
81