blob: 44960fb13dec1f91d84b32583af507375a40edfb [file] [log] [blame]
Kathan Shuklab6261cb2019-11-25 22:52:12 -08001/*
2 * Copyright (C) 2016 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#define LOG_TAG "android.hardware.automotive.occupant_awareness@1.0-service"
18
19#include <unistd.h>
20
21#include <android-base/logging.h>
22#include <android/binder_manager.h>
23#include <android/binder_process.h>
24
25#include "OccupantAwareness.h"
26
27using ::aidl::android::hardware::automotive::occupant_awareness::IOccupantAwareness;
28using ::android::hardware::automotive::occupant_awareness::V1_0::implementation::OccupantAwareness;
29using ::ndk::ScopedAStatus;
30using ::ndk::SharedRefBase;
31
32const static char kOccupantAwarenessServiceName[] = "default";
33
34int main() {
35 ABinderProcess_setThreadPoolMaxThreadCount(0);
36 LOG(INFO) << "Occupant Awareness service is starting";
37 std::shared_ptr<OccupantAwareness> occupantAwareness = SharedRefBase::make<OccupantAwareness>();
38
39 const std::string instance =
40 std::string() + IOccupantAwareness::descriptor + "/" + kOccupantAwarenessServiceName;
41
42 binder_status_t status =
43 AServiceManager_addService(occupantAwareness->asBinder().get(), instance.c_str());
44 if (status == STATUS_OK) {
45 LOG(INFO) << "Service " << kOccupantAwarenessServiceName << " is ready";
46 ABinderProcess_joinThreadPool();
47 } else {
48 LOG(ERROR) << "Could not register service " << kOccupantAwarenessServiceName
49 << ", status: " << status;
50 }
51
52 // In normal operation, we don't expect the thread pool to exit.
53 LOG(ERROR) << "Occupant Awareness service is shutting down";
54 return 1;
55}