• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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 #include <stdlib.h>
18 
19 #include <iostream>
20 #include <string>
21 
22 #include <utils/RefBase.h>
23 #define LOG_TAG "VtsFuzzerBinderService"
24 #include <utils/Log.h>
25 
26 #include <binder/IBinder.h>
27 #include <binder/IInterface.h>
28 #include <binder/IPCThreadState.h>
29 #include <binder/IServiceManager.h>
30 #include <binder/ProcessState.h>
31 #include <binder/TextOutput.h>
32 
33 #include "binder/VtsFuzzerBinderService.h"
34 
35 using namespace std;
36 
37 namespace android {
38 namespace vts {
39 
40 IMPLEMENT_META_INTERFACE(VtsFuzzer, VTS_FUZZER_BINDER_SERVICE_NAME);
41 
Exit()42 void BpVtsFuzzer::Exit() {
43   Parcel data;
44   Parcel reply;
45   data.writeInterfaceToken(IVtsFuzzer::getInterfaceDescriptor());
46   data.writeString16(String16("Exit code"));
47   remote()->transact(EXIT, data, &reply, IBinder::FLAG_ONEWAY);
48 }
49 
LoadHal(const string & path,int target_class,int target_type,float target_version,const string & module_name)50 int32_t BpVtsFuzzer::LoadHal(const string& path, int target_class,
51                              int target_type, float target_version,
52                              const string& module_name) {
53   Parcel data;
54   Parcel reply;
55 
56   printf("agent->driver: LoadHal(%s, %d, %d, %f, %s)\n", path.c_str(),
57          target_class, target_type, target_version, module_name.c_str());
58   data.writeInterfaceToken(IVtsFuzzer::getInterfaceDescriptor());
59   data.writeCString(path.c_str());
60   data.writeInt32(target_class);
61   data.writeInt32(target_type);
62   data.writeFloat(target_version);
63   data.writeCString(module_name.c_str());
64 
65 #ifdef VTS_FUZZER_BINDER_DEBUG
66   alog << "BpVtsFuzzer::Status request parcel:\n"
67        << data
68        << endl;
69 #endif
70 
71   remote()->transact(LOAD_HAL, data, &reply);
72 
73 #ifdef VTS_FUZZER_BINDER_DEBUG
74   alog << "BpVtsFuzzer::Status response parcel:\n"
75        << reply
76        << endl;
77 #endif
78 
79   int32_t res;
80   status_t status = reply.readInt32(&res);
81 
82   printf("driver->agent: LoadHal returns %d\n", status);
83   return res;
84 }
85 
Status(int32_t type)86 int32_t BpVtsFuzzer::Status(int32_t type) {
87   Parcel data;
88   Parcel reply;
89 
90   data.writeInterfaceToken(IVtsFuzzer::getInterfaceDescriptor());
91   data.writeInt32(type);
92 
93 #ifdef VTS_FUZZER_BINDER_DEBUG
94   alog << "BpVtsFuzzer::Status request parcel:\n"
95        << data
96        << endl;
97 #endif
98 
99   remote()->transact(STATUS, data, &reply);
100 
101 #ifdef VTS_FUZZER_BINDER_DEBUG
102   alog << "BpVtsFuzzer::Status response parcel:\n"
103        << reply
104        << endl;
105 #endif
106 
107   int32_t res;
108   /* status_t */ reply.readInt32(&res);
109   return res;
110 }
111 
Call(const string & call_payload)112 const char* BpVtsFuzzer::Call(const string& call_payload) {
113   Parcel data, reply;
114   data.writeInterfaceToken(IVtsFuzzer::getInterfaceDescriptor());
115   data.writeCString(call_payload.c_str());
116 #ifdef VTS_FUZZER_BINDER_DEBUG
117   alog << data << endl;
118 #endif
119 
120   remote()->transact(CALL, data, &reply);
121 #ifdef VTS_FUZZER_BINDER_DEBUG
122   alog << reply << endl;
123 #endif
124 
125   const char* res = reply.readCString();
126   if (res == NULL) {
127     printf("reply == NULL\n");
128     return res;
129   }
130 
131   printf("len(reply) = %zu\n", strlen(res));
132   return res;
133 }
134 
GetFunctions()135 const char* BpVtsFuzzer::GetFunctions() {
136   Parcel data, reply;
137   data.writeInterfaceToken(IVtsFuzzer::getInterfaceDescriptor());
138 #ifdef VTS_FUZZER_BINDER_DEBUG
139   alog << data << endl;
140 #endif
141 
142   remote()->transact(GET_FUNCTIONS, data, &reply);
143 #ifdef VTS_FUZZER_BINDER_DEBUG
144   alog << reply << endl;
145 #endif
146 
147   const char* res = reply.readCString();
148   if (res == NULL) {
149     printf("reply == NULL\n");
150     return res;
151   }
152 
153   printf("len(reply) = %zu\n", strlen(res));
154   return res;
155 }
156 
157 }  // namespace vts
158 }  // namespace android
159