blob: 8720c2f5c631482c8c826476cf055be26386976c [file] [log] [blame]
Yu Shan562c0f82022-08-04 17:10:38 -07001/*
2 * Copyright (C) 2022 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 "RemoteAccessImpl"
18
19#include "RemoteAccessService.h"
20
21#include <android/binder_manager.h>
22#include <android/binder_process.h>
Yu Shana725df42022-09-12 14:56:32 -070023#include <grpcpp/create_channel.h>
24#include <stdlib.h>
Yu Shan562c0f82022-08-04 17:10:38 -070025#include <utils/Log.h>
26
Yu Shana725df42022-09-12 14:56:32 -070027constexpr char SERVICE_NAME[] = "android.hardware.automotive.remoteaccess.IRemoteAccess/default";
28
Yu Shan562c0f82022-08-04 17:10:38 -070029int main(int /* argc */, char* /* argv */[]) {
30 ALOGI("Registering RemoteAccessService as service...");
31
Yu Shana725df42022-09-12 14:56:32 -070032#ifndef GRPC_SERVICE_ADDRESS
33 ALOGE("GRPC_SERVICE_ADDRESS is not defined, exiting");
34 exit(1);
35#endif
36 auto channel = grpc::CreateChannel(GRPC_SERVICE_ADDRESS, grpc::InsecureChannelCredentials());
37 auto clientStub = android::hardware::automotive::remoteaccess::WakeupClient::NewStub(channel);
Yu Shan562c0f82022-08-04 17:10:38 -070038 auto service = ndk::SharedRefBase::make<
Yu Shana725df42022-09-12 14:56:32 -070039 android::hardware::automotive::remoteaccess::RemoteAccessService>(clientStub.get());
Yu Shan562c0f82022-08-04 17:10:38 -070040
Yu Shana725df42022-09-12 14:56:32 -070041 binder_exception_t err = AServiceManager_addService(service->asBinder().get(), SERVICE_NAME);
Yu Shan562c0f82022-08-04 17:10:38 -070042 if (err != EX_NONE) {
43 ALOGE("failed to register android.hardware.automotive.remote.IRemoteAccess service, "
44 "exception: %d",
45 err);
Yu Shana725df42022-09-12 14:56:32 -070046 exit(1);
Yu Shan562c0f82022-08-04 17:10:38 -070047 }
48
49 if (!ABinderProcess_setThreadPoolMaxThreadCount(1)) {
50 ALOGE("%s", "failed to set thread pool max thread count");
Yu Shana725df42022-09-12 14:56:32 -070051 exit(1);
Yu Shan562c0f82022-08-04 17:10:38 -070052 }
53 ABinderProcess_startThreadPool();
54
55 ALOGI("RemoteAccess service Ready");
56
57 ABinderProcess_joinThreadPool();
58
59 ALOGW("Should not reach here");
60
61 return 0;
62}