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 #ifndef __VTS_AGENT_REQUEST_HANDLER_H__ 18 #define __VTS_AGENT_REQUEST_HANDLER_H__ 19 20 #include <string> 21 22 #include "SocketClientToDriver.h" 23 #include "test/vts/proto/AndroidSystemControlMessage.pb.h" 24 #include "test/vts/proto/VtsDriverControlMessage.pb.h" 25 26 namespace android { 27 namespace vts { 28 29 // Class which contains actual methods to handle the runner requests. 30 class AgentRequestHandler : public VtsDriverCommUtil { 31 public: AgentRequestHandler(const char * spec_dir_path,const char * hal_path32,const char * hal_path64,const char * shell_path32,const char * shell_path64)32 AgentRequestHandler(const char* spec_dir_path, const char* hal_path32, 33 const char* hal_path64, const char* shell_path32, 34 const char* shell_path64) 35 : VtsDriverCommUtil(), 36 service_name_(), 37 driver_client_(NULL), 38 driver_hal_spec_dir_path_(spec_dir_path), 39 driver_hal_binary32_(hal_path32), 40 driver_hal_binary64_(hal_path64), 41 driver_shell_binary32_(shell_path32), 42 driver_shell_binary64_(shell_path64) {} 43 44 45 // handles a new session. 46 bool ProcessOneCommand(); 47 48 protected: 49 // for the LIST_HAL command 50 bool ListHals(const ::google::protobuf::RepeatedPtrField<string>& base_paths); 51 52 // for the SET_HOST_INFO command. 53 bool SetHostInfo(const int callback_port); 54 55 // for the CHECK_DRIVER_SERVICE command 56 bool CheckDriverService(const string& service_name, bool* live); 57 58 // for the LAUNCH_DRIVER_SERVICE command 59 bool LaunchDriverService( 60 const AndroidSystemControlCommandMessage& command_msg); 61 62 // for the VTS_AGENT_COMMAND_READ_SPECIFICATION` 63 bool ReadSpecification( 64 const AndroidSystemControlCommandMessage& command_message); 65 66 // for the LIST_APIS command 67 bool ListApis(); 68 69 // for the CALL_API command 70 bool CallApi(const string& call_payload, const string& uid); 71 72 // for the VTS_AGENT_COMMAND_GET_ATTRIBUTE 73 bool GetAttribute(const string& payload); 74 75 // for the EXECUTE_SHELL command 76 bool ExecuteShellCommand( 77 const AndroidSystemControlCommandMessage& command_message); 78 79 // Returns a default response message. 80 bool DefaultResponse(); 81 82 // Send SUCCESS response with given result and/or spec if it is not empty, 83 // otherwise send FAIL. 84 bool SendApiResult(const string& func_name, const string& result, 85 const string& spec = ""); 86 87 // for processing commands for FMQ. 88 bool ProcessFmqCommand( 89 const AndroidSystemControlCommandMessage& command_message); 90 91 // for processing commands for hidl_memory. 92 bool ProcessHidlMemoryCommand( 93 const AndroidSystemControlCommandMessage& command_message); 94 95 // for processing commands for hidl_handle. 96 bool ProcessHidlHandleCommand( 97 const AndroidSystemControlCommandMessage& command_message); 98 99 protected: 100 // the currently opened, connected service name. 101 string service_name_; 102 // the port number of a host-side callback server. 103 int callback_port_; 104 // the socket client of a launched or connected driver. 105 VtsDriverSocketClient* driver_client_; 106 107 void CreateSystemControlResponseFromDriverControlResponse( 108 const VtsDriverControlResponseMessage& driver_control_response_message, 109 AndroidSystemControlResponseMessage* system_control_response_message); 110 111 const string driver_hal_spec_dir_path_; 112 const string driver_hal_binary32_; 113 const string driver_hal_binary64_; 114 const string driver_shell_binary32_; 115 const string driver_shell_binary64_; 116 }; 117 118 } // namespace vts 119 } // namespace android 120 121 #endif 122