1 /*
2  * Copyright (C) 2021 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 #include "AudioControl.h"
18 #include "vsockinfo.h"
19 
20 #include <android-base/logging.h>
21 #include <android/binder_manager.h>
22 #include <android/binder_process.h>
23 
24 using aidl::android::hardware::automotive::audiocontrol::AudioControl;
25 using android::hardware::automotive::utils::VsockConnectionInfo;
26 
main()27 int main() {
28     const auto si = VsockConnectionInfo::fromRoPropertyStore(
29             {
30                     "ro.boot.vendor.audiocontrol.server.cid",
31                     "ro.vendor.audiocontrol.server.cid",
32             },
33             {
34                     "ro.boot.vendor.audiocontrol.server.port",
35                     "ro.vendor.audiocontrol.server.port",
36             });
37 
38     if (!si) {
39         LOG(ERROR) << "failed to get server connection cid/port; audio control server disabled.";
40     } else {
41         LOG(INFO) << "Creating audio control server at " << si->str();
42     }
43 
44     ABinderProcess_setThreadPoolMaxThreadCount(0);
45 
46     // Create an instance of our service class
47     std::shared_ptr<AudioControl> audioControl = ndk::SharedRefBase::make<AudioControl>(si ? si->str() : "");
48 
49     audioControl->start();
50 
51     const std::string instance = std::string() + AudioControl::descriptor + "/default";
52     binder_status_t status =
53             AServiceManager_addService(audioControl->asBinder().get(), instance.c_str());
54     CHECK(status == STATUS_OK);
55 
56     ABinderProcess_joinThreadPool();
57     audioControl->join();
58     return EXIT_FAILURE;  // should not reach
59 }
60