blob: 3901cebcc787404e1d0ac00c30f8de4e1b82d929 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 */
Jeff Brownef691172013-07-15 13:22:04 -070016
17#include <jni.h>
Steven Moreland2279b252017-07-19 09:50:45 -070018#include <nativehelper/JNIHelp.h>
Jeff Brownef691172013-07-15 13:22:04 -070019
Yifan Hong26b421f2017-03-10 13:41:11 -080020#include <hidl/HidlTransportSupport.h>
21
Steven Moreland3d8166f2017-04-07 10:47:06 -070022#include <schedulerservice/SchedulingPolicyService.h>
Jeff Brownef691172013-07-15 13:22:04 -070023#include <sensorservice/SensorService.h>
Yifan Hong26b421f2017-03-10 13:41:11 -080024#include <sensorservicehidl/SensorManager.h>
Jeff Brownef691172013-07-15 13:22:04 -070025
26#include <cutils/properties.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <utils/Log.h>
28#include <utils/misc.h>
Wei Wangf94016d2016-11-29 11:53:53 -080029#include <utils/AndroidThreads.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031namespace android {
32
Svet Ganovb9d71a62015-04-30 10:38:13 -070033static void android_server_SystemServer_startSensorService(JNIEnv* /* env */, jobject /* clazz */) {
Jeff Brownef691172013-07-15 13:22:04 -070034 char propBuf[PROPERTY_VALUE_MAX];
35 property_get("system_init.startsensorservice", propBuf, "1");
36 if (strcmp(propBuf, "1") == 0) {
Keun-young Park9b73a542017-02-01 12:09:58 -080037 SensorService::instantiate();
Jeff Brownef691172013-07-15 13:22:04 -070038 }
Yifan Hong26b421f2017-03-10 13:41:11 -080039
40}
41
Yifan Hongbef39882017-06-13 18:20:09 -070042static void android_server_SystemServer_startHidlServices(JNIEnv* env, jobject /* clazz */) {
Steven Moreland3d8166f2017-04-07 10:47:06 -070043 using ::android::frameworks::schedulerservice::V1_0::ISchedulingPolicyService;
44 using ::android::frameworks::schedulerservice::V1_0::implementation::SchedulingPolicyService;
Yifan Hong26b421f2017-03-10 13:41:11 -080045 using ::android::frameworks::sensorservice::V1_0::ISensorManager;
46 using ::android::frameworks::sensorservice::V1_0::implementation::SensorManager;
47 using ::android::hardware::configureRpcThreadpool;
48
Steven Moreland3d8166f2017-04-07 10:47:06 -070049 status_t err;
50
Yifan Hong6f7a9e12017-11-02 20:23:08 +000051 configureRpcThreadpool(5, false /* callerWillJoin */);
52
Yifan Hongbef39882017-06-13 18:20:09 -070053 JavaVM *vm;
54 LOG_ALWAYS_FATAL_IF(env->GetJavaVM(&vm) != JNI_OK, "Cannot get Java VM");
55
56 sp<ISensorManager> sensorService = new SensorManager(vm);
Steven Moreland3d8166f2017-04-07 10:47:06 -070057 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);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063}
64
65/*
66 * JNI registration.
67 */
Daniel Micay76f6a862015-09-19 17:31:01 -040068static const JNINativeMethod gMethods[] = {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 /* name, signature, funcPtr */
Svet Ganovb9d71a62015-04-30 10:38:13 -070070 { "startSensorService", "()V", (void*) android_server_SystemServer_startSensorService },
Yifan Hong26b421f2017-03-10 13:41:11 -080071 { "startHidlServices", "()V", (void*) android_server_SystemServer_startHidlServices },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072};
73
74int register_android_server_SystemServer(JNIEnv* env)
75{
76 return jniRegisterNativeMethods(env, "com/android/server/SystemServer",
77 gMethods, NELEM(gMethods));
78}
79
80}; // namespace android