Yu Shan | 7a5283f | 2022-10-25 18:01:05 -0700 | [diff] [blame] | 1 | /* |
| 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> |
| 23 | #include <grpcpp/create_channel.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <utils/Log.h> |
| 26 | |
| 27 | constexpr char SERVICE_NAME[] = "android.hardware.automotive.remoteaccess.IRemoteAccess/default"; |
| 28 | |
| 29 | int main(int /* argc */, char* /* argv */[]) { |
| 30 | ALOGI("Registering RemoteAccessService as service..."); |
| 31 | |
| 32 | #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); |
| 38 | auto service = ndk::SharedRefBase::make< |
| 39 | android::hardware::automotive::remoteaccess::RemoteAccessService>(clientStub.get()); |
| 40 | |
| 41 | binder_exception_t err = AServiceManager_addService(service->asBinder().get(), SERVICE_NAME); |
| 42 | if (err != EX_NONE) { |
| 43 | ALOGE("failed to register android.hardware.automotive.remote.IRemoteAccess service, " |
| 44 | "exception: %d", |
| 45 | err); |
| 46 | exit(1); |
| 47 | } |
| 48 | |
| 49 | if (!ABinderProcess_setThreadPoolMaxThreadCount(1)) { |
| 50 | ALOGE("%s", "failed to set thread pool max thread count"); |
| 51 | exit(1); |
| 52 | } |
| 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 | } |