The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | */ |
Jeff Brown | ef69117 | 2013-07-15 13:22:04 -0700 | [diff] [blame] | 16 | |
| 17 | #include <jni.h> |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 18 | #include <nativehelper/JNIHelp.h> |
Jeff Brown | ef69117 | 2013-07-15 13:22:04 -0700 | [diff] [blame] | 19 | |
Yifan Hong | 26b421f | 2017-03-10 13:41:11 -0800 | [diff] [blame] | 20 | #include <hidl/HidlTransportSupport.h> |
| 21 | |
Steven Moreland | 3d8166f | 2017-04-07 10:47:06 -0700 | [diff] [blame] | 22 | #include <schedulerservice/SchedulingPolicyService.h> |
Jeff Brown | ef69117 | 2013-07-15 13:22:04 -0700 | [diff] [blame] | 23 | #include <sensorservice/SensorService.h> |
Yifan Hong | 26b421f | 2017-03-10 13:41:11 -0800 | [diff] [blame] | 24 | #include <sensorservicehidl/SensorManager.h> |
Jeff Brown | ef69117 | 2013-07-15 13:22:04 -0700 | [diff] [blame] | 25 | |
| 26 | #include <cutils/properties.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | #include <utils/Log.h> |
| 28 | #include <utils/misc.h> |
Wei Wang | f94016d | 2016-11-29 11:53:53 -0800 | [diff] [blame] | 29 | #include <utils/AndroidThreads.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | namespace android { |
| 32 | |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 33 | static void android_server_SystemServer_startSensorService(JNIEnv* /* env */, jobject /* clazz */) { |
Jeff Brown | ef69117 | 2013-07-15 13:22:04 -0700 | [diff] [blame] | 34 | char propBuf[PROPERTY_VALUE_MAX]; |
| 35 | property_get("system_init.startsensorservice", propBuf, "1"); |
| 36 | if (strcmp(propBuf, "1") == 0) { |
Keun-young Park | 9b73a54 | 2017-02-01 12:09:58 -0800 | [diff] [blame] | 37 | SensorService::instantiate(); |
Jeff Brown | ef69117 | 2013-07-15 13:22:04 -0700 | [diff] [blame] | 38 | } |
Yifan Hong | 26b421f | 2017-03-10 13:41:11 -0800 | [diff] [blame] | 39 | |
| 40 | } |
| 41 | |
Yifan Hong | bef3988 | 2017-06-13 18:20:09 -0700 | [diff] [blame] | 42 | static void android_server_SystemServer_startHidlServices(JNIEnv* env, jobject /* clazz */) { |
Steven Moreland | 3d8166f | 2017-04-07 10:47:06 -0700 | [diff] [blame] | 43 | using ::android::frameworks::schedulerservice::V1_0::ISchedulingPolicyService; |
| 44 | using ::android::frameworks::schedulerservice::V1_0::implementation::SchedulingPolicyService; |
Yifan Hong | 26b421f | 2017-03-10 13:41:11 -0800 | [diff] [blame] | 45 | using ::android::frameworks::sensorservice::V1_0::ISensorManager; |
| 46 | using ::android::frameworks::sensorservice::V1_0::implementation::SensorManager; |
| 47 | using ::android::hardware::configureRpcThreadpool; |
| 48 | |
Steven Moreland | 3d8166f | 2017-04-07 10:47:06 -0700 | [diff] [blame] | 49 | status_t err; |
| 50 | |
Yifan Hong | 6f7a9e1 | 2017-11-02 20:23:08 +0000 | [diff] [blame] | 51 | configureRpcThreadpool(5, false /* callerWillJoin */); |
| 52 | |
Yifan Hong | bef3988 | 2017-06-13 18:20:09 -0700 | [diff] [blame] | 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); |
Steven Moreland | 3d8166f | 2017-04-07 10:47:06 -0700 | [diff] [blame] | 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); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /* |
| 66 | * JNI registration. |
| 67 | */ |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 68 | static const JNINativeMethod gMethods[] = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | /* name, signature, funcPtr */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 70 | { "startSensorService", "()V", (void*) android_server_SystemServer_startSensorService }, |
Yifan Hong | 26b421f | 2017-03-10 13:41:11 -0800 | [diff] [blame] | 71 | { "startHidlServices", "()V", (void*) android_server_SystemServer_startHidlServices }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | }; |
| 73 | |
| 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 |