blob: 9dad30349ce658e5acbbbe686282a362ef21c750 [file] [log] [blame]
Joeyc6e0e422019-01-09 14:05:01 +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.trust@1.0-service"
18
19#include <android-base/logging.h>
20#include <binder/ProcessState.h>
21#include <hidl/HidlTransportSupport.h>
22
23#include "UsbRestrict.h"
24
25using android::sp;
26using android::status_t;
27using android::OK;
28
29// libhwbinder:
30using android::hardware::configureRpcThreadpool;
31using android::hardware::joinRpcThreadpool;
32
33using ::vendor::lineage::trust::V1_0::IUsbRestrict;
34using ::vendor::lineage::trust::V1_0::implementation::UsbRestrict;
35
36int main() {
37 sp<IUsbRestrict> usbRestrict;
38 status_t status;
39
40 LOG(INFO) << "Trust HAL service is starting.";
41
42 usbRestrict = new UsbRestrict();
43 if (usbRestrict == nullptr) {
44 LOG(ERROR) << "Can not create an instance of Trust HAL UsbRestricted Iface, exiting.";
45 goto shutdown;
46 }
47
48 configureRpcThreadpool(1, true /*callerWillJoin*/);
49
50 status = usbRestrict->registerAsService();
51 if (status != OK) {
52 LOG(ERROR) << "Could not register service for Trust HAL UsbRestricted Iface ("
53 << status << ").";
54 }
55
56 LOG(INFO) << "Trust HAL service is ready.";
57 joinRpcThreadpool();
58 // Should not pass this line
59
60shutdown:
61 // In normal operation, we don't expect the thread pool to shutdown
62 LOG(ERROR) << "Trust HAL service is shutting down.";
63 return 1;
64}