com_android_server_SystemServer.cpp revision eb4b2d056cd905b4b6ca0c985131c102f2254a45
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
31namespace android {
32
33static 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
42static 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    sp<ISensorManager> sensorService = new SensorManager();
54    err = sensorService->registerAsService();
55    ALOGE_IF(err != OK, "Cannot register %s: %d", ISensorManager::descriptor, err);
56
57    sp<ISchedulingPolicyService> schedulingService = new SchedulingPolicyService();
58    err = schedulingService->registerAsService();
59    ALOGE_IF(err != OK, "Cannot register %s: %d", ISchedulingPolicyService::descriptor, err);
60}
61
62/*
63 * JNI registration.
64 */
65static const JNINativeMethod gMethods[] = {
66    /* name, signature, funcPtr */
67    { "startSensorService", "()V", (void*) android_server_SystemServer_startSensorService },
68    { "startHidlServices", "()V", (void*) android_server_SystemServer_startHidlServices },
69};
70
71int register_android_server_SystemServer(JNIEnv* env)
72{
73    return jniRegisterNativeMethods(env, "com/android/server/SystemServer",
74            gMethods, NELEM(gMethods));
75}
76
77}; // namespace android
78