Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 28 | using android::hardware::configureRpcThreadpool; |
| 29 | using android::hardware::joinRpcThreadpool; |
| 30 | using android::sp; |
| 31 | using android::status_t; |
| 32 | using android::OK; |
| 33 | |
| 34 | using ::vendor::lineage::touch::V1_0::samsung::GloveMode; |
| 35 | using ::vendor::lineage::touch::V1_0::samsung::KeyDisabler; |
| 36 | using ::vendor::lineage::touch::V1_0::samsung::StylusMode; |
| 37 | using ::vendor::lineage::touch::V1_0::samsung::TouchscreenGesture; |
| 38 | |
| 39 | int 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 Altensen | 6f3af5a | 2019-07-20 01:00:46 +0200 | [diff] [blame] | 77 | LOG(ERROR) << "Could not register service for Touch HAL GloveMode Iface (" << status |
| 78 | << ")"; |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 79 | goto shutdown; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | if (keyDisabler->isSupported()) { |
| 84 | status = keyDisabler->registerAsService(); |
| 85 | if (status != OK) { |
Jan Altensen | 6f3af5a | 2019-07-20 01:00:46 +0200 | [diff] [blame] | 86 | LOG(ERROR) << "Could not register service for Touch HAL KeyDisabler Iface (" << status |
| 87 | << ")"; |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 88 | goto shutdown; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if (stylusMode->isSupported()) { |
| 93 | status = stylusMode->registerAsService(); |
| 94 | if (status != OK) { |
Jan Altensen | 6f3af5a | 2019-07-20 01:00:46 +0200 | [diff] [blame] | 95 | LOG(ERROR) << "Could not register service for Touch HAL StylusMode Iface (" << status |
| 96 | << ")"; |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 97 | goto shutdown; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | if (touchscreenGesture->isSupported()) { |
| 102 | status = touchscreenGesture->registerAsService(); |
| 103 | if (status != OK) { |
Jan Altensen | 6f3af5a | 2019-07-20 01:00:46 +0200 | [diff] [blame] | 104 | LOG(ERROR) << "Could not register service for Touch HAL TouchscreenGesture Iface (" |
| 105 | << status << ")"; |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 106 | goto shutdown; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | LOG(INFO) << "Touch HAL service is ready."; |
| 111 | joinRpcThreadpool(); |
Jan Altensen | 6f3af5a | 2019-07-20 01:00:46 +0200 | [diff] [blame] | 112 | // Should not pass this line |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 113 | |
| 114 | shutdown: |
| 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 | } |