blob: 1bdc66fc3dc32418350c5b59a949e63b3ae5d0e8 [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) {
77 LOG(ERROR)
78 << "Could not register service for Touch HAL GloveMode Iface ("
79 << status << ")";
80 goto shutdown;
81 }
82 }
83
84 if (keyDisabler->isSupported()) {
85 status = keyDisabler->registerAsService();
86 if (status != OK) {
87 LOG(ERROR)
88 << "Could not register service for Touch HAL KeyDisabler Iface ("
89 << status << ")";
90 goto shutdown;
91 }
92 }
93
94 if (stylusMode->isSupported()) {
95 status = stylusMode->registerAsService();
96 if (status != OK) {
97 LOG(ERROR)
98 << "Could not register service for Touch HAL StylusMode Iface ("
99 << status << ")";
100 goto shutdown;
101 }
102 }
103
104 if (touchscreenGesture->isSupported()) {
105 status = touchscreenGesture->registerAsService();
106 if (status != OK) {
107 LOG(ERROR)
108 << "Could not register service for Touch HAL TouchscreenGesture Iface ("
109 << status << ")";
110 goto shutdown;
111 }
112 }
113
114 LOG(INFO) << "Touch HAL service is ready.";
115 joinRpcThreadpool();
116 // Should not pass this line
117
118shutdown:
119 // In normal operation, we don't expect the thread pool to shutdown
120 LOG(ERROR) << "Touch HAL service is shutting down.";
121 return 1;
122}