blob: e12326c3725fb66d08ef02a1fe57f822e625b694 [file] [log] [blame]
Paul Keith2b27b272019-01-09 00:11:40 +01001/*
2 * Copyright (C) 2019 The LineageOS 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 "vendor.lineage.touch@1.0-service.samsung"
18
19#include <android-base/logging.h>
20#include <binder/ProcessState.h>
21#include <hidl/HidlTransportSupport.h>
22
23#include "GloveMode.h"
24#include "KeyDisabler.h"
25#include "StylusMode.h"
26#include "TouchscreenGesture.h"
27
28using android::hardware::configureRpcThreadpool;
29using android::hardware::joinRpcThreadpool;
30using android::sp;
31using android::status_t;
32using android::OK;
33
34using ::vendor::lineage::touch::V1_0::samsung::GloveMode;
35using ::vendor::lineage::touch::V1_0::samsung::KeyDisabler;
36using ::vendor::lineage::touch::V1_0::samsung::StylusMode;
37using ::vendor::lineage::touch::V1_0::samsung::TouchscreenGesture;
38
39int main() {
40 sp<GloveMode> gloveMode;
41 sp<KeyDisabler> keyDisabler;
42 sp<StylusMode> stylusMode;
43 sp<TouchscreenGesture> touchscreenGesture;
44 status_t status;
45
46 LOG(INFO) << "Touch HAL service is starting.";
47
48 gloveMode = new GloveMode();
49 if (gloveMode == nullptr) {
50 LOG(ERROR) << "Can not create an instance of Touch HAL GloveMode Iface, exiting.";
51 goto shutdown;
52 }
53
54 keyDisabler = new KeyDisabler();
55 if (keyDisabler == nullptr) {
56 LOG(ERROR) << "Can not create an instance of Touch HAL KeyDisabler Iface, exiting.";
57 goto shutdown;
58 }
59
60 stylusMode = new StylusMode();
61 if (stylusMode == nullptr) {
62 LOG(ERROR) << "Can not create an instance of Touch HAL StylusMode Iface, exiting.";
63 goto shutdown;
64 }
65
66 touchscreenGesture = new TouchscreenGesture();
67 if (touchscreenGesture == nullptr) {
68 LOG(ERROR) << "Can not create an instance of Touch HAL TouchscreenGesture Iface, exiting.";
69 goto shutdown;
70 }
71
72 configureRpcThreadpool(1, true /*callerWillJoin*/);
73
74 if (gloveMode->isSupported()) {
75 status = gloveMode->registerAsService();
76 if (status != OK) {
Jan Altensen6f3af5a2019-07-20 01:00:46 +020077 LOG(ERROR) << "Could not register service for Touch HAL GloveMode Iface (" << status
78 << ")";
Paul Keith2b27b272019-01-09 00:11:40 +010079 goto shutdown;
80 }
81 }
82
83 if (keyDisabler->isSupported()) {
84 status = keyDisabler->registerAsService();
85 if (status != OK) {
Jan Altensen6f3af5a2019-07-20 01:00:46 +020086 LOG(ERROR) << "Could not register service for Touch HAL KeyDisabler Iface (" << status
87 << ")";
Paul Keith2b27b272019-01-09 00:11:40 +010088 goto shutdown;
89 }
90 }
91
92 if (stylusMode->isSupported()) {
93 status = stylusMode->registerAsService();
94 if (status != OK) {
Jan Altensen6f3af5a2019-07-20 01:00:46 +020095 LOG(ERROR) << "Could not register service for Touch HAL StylusMode Iface (" << status
96 << ")";
Paul Keith2b27b272019-01-09 00:11:40 +010097 goto shutdown;
98 }
99 }
100
101 if (touchscreenGesture->isSupported()) {
102 status = touchscreenGesture->registerAsService();
103 if (status != OK) {
Jan Altensen6f3af5a2019-07-20 01:00:46 +0200104 LOG(ERROR) << "Could not register service for Touch HAL TouchscreenGesture Iface ("
105 << status << ")";
Paul Keith2b27b272019-01-09 00:11:40 +0100106 goto shutdown;
107 }
108 }
109
110 LOG(INFO) << "Touch HAL service is ready.";
111 joinRpcThreadpool();
Jan Altensen6f3af5a2019-07-20 01:00:46 +0200112// Should not pass this line
Paul Keith2b27b272019-01-09 00:11:40 +0100113
114shutdown:
115 // In normal operation, we don't expect the thread pool to shutdown
116 LOG(ERROR) << "Touch HAL service is shutting down.";
117 return 1;
118}