1 /*
2  * Copyright (C) 2023 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 <aidl/com/android/minidroid/testservice/ITestService.h>
18 #include <minidroid_sd.h>
19 
20 #include <stdio.h>
21 #include <unistd.h>
22 
23 #define LOG_TAG "client_minidroid"
24 #include <log/log.h>
25 
main(int argc,char ** argv)26 int main(int argc, char** argv) {
27   if (argc != 3) {
28     LOG_FATAL(
29         "Wrong usage of ITestService client. Please enter the CID and port of "
30         "the proxy process!");
31     return -1;
32   }
33 
34   int service_host_cid = atoi(argv[1]);
35   int service_port = atoi(argv[2]);
36 
37   ALOGI("Hello Minidroid client! Connecting to CID %d and port %d",
38         service_host_cid, service_port);
39 
40   ndk::SpAIBinder binder = bi::sd::getService(service_host_cid, service_port);
41 
42   if (nullptr == binder.get()) {
43     LOG_FATAL("Unable to find service!");
44     return -1;
45   }
46 
47   auto test_service =
48       aidl::com::android::minidroid::testservice::ITestService::fromBinder(
49           binder);
50 
51   test_service->sayHello();
52   test_service->printText("Hello from client!");
53   int32_t result = 0;
54   test_service->addInteger(4, 6, &result);
55 
56   ALOGI("Finished client. 4 + 6 is %d", result);
57 
58   return 0;
59 }
60