1 /* 2 * Copyright (C) 2015 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 #pragma once 18 19 #include "adb.h" 20 #include "sysdeps.h" 21 #include "transport.h" 22 23 #include <optional> 24 #include <string> 25 26 // Explicitly check the adb server version. 27 // All of the commands below do this implicitly. 28 // Only the first invocation of this function will check the server version. 29 bool adb_check_server_version(std::string* _Nonnull error); 30 31 // Connect to adb, connect to the named service, and return a valid fd for 32 // interacting with that service upon success or a negative number on failure. 33 int adb_connect(std::string_view service, std::string* _Nonnull error); 34 35 // Same as above, except returning the TransportId for the service that we've connected to. 36 int adb_connect(TransportId* _Nullable id, std::string_view service, std::string* _Nonnull error); 37 38 // Kill the currently running adb server, if it exists. 39 bool adb_kill_server(); 40 41 // Connect to adb, connect to the named service, returns true if the connection 42 // succeeded AND the service returned OKAY. Outputs any returned error otherwise. 43 bool adb_command(const std::string& service); 44 45 // Connects to the named adb service and fills 'result' with the response. 46 // Returns true on success; returns false and fills 'error' on failure. 47 bool adb_query(const std::string& service, std::string* _Nonnull result, 48 std::string* _Nonnull error); 49 50 // Set the preferred transport to connect to. 51 void adb_set_transport(TransportType type, const char* _Nullable serial, TransportId transport_id); 52 void adb_get_transport(TransportType* _Nullable type, const char* _Nullable* _Nullable serial, 53 TransportId* _Nullable transport_id); 54 55 // Set the socket specification for the adb server. 56 // This function can only be called once, and the argument must live to the end of the process. 57 void adb_set_socket_spec(const char* _Nonnull socket_spec); 58 59 // Send commands to the current emulator instance. Will fail if there is not 60 // exactly one emulator connected (or if you use -s <serial> with a <serial> 61 // that does not designate an emulator). 62 int adb_send_emulator_command(int argc, const char* _Nonnull* _Nonnull argv, 63 const char* _Nullable serial); 64 65 // Reads a standard adb status response (OKAY|FAIL) and returns true in the 66 // event of OKAY, false in the event of FAIL or protocol error. 67 bool adb_status(int fd, std::string* _Nonnull error); 68 69 // Create a host command corresponding to selected transport type/serial. 70 std::string format_host_command(const char* _Nonnull command); 71 72 // Get the feature set of the current preferred transport. 73 bool adb_get_feature_set(FeatureSet* _Nonnull feature_set, std::string* _Nonnull error); 74 75 #if defined(__linux__) 76 // Get the path of a file containing the path to the server executable, if the socket spec set via 77 // adb_set_socket_spec is a local one. 78 std::optional<std::string> adb_get_server_executable_path(); 79 #endif 80 81 // Globally acccesible argv/envp, for the purpose of re-execing adb. 82 extern const char* _Nullable * _Nullable __adb_argv; 83 extern const char* _Nullable * _Nullable __adb_envp; 84