Android-cuttlefish cvd tool
adb_client.h
Go to the documentation of this file.
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 <functional>
20#include <optional>
21#include <string>
22
23#include "adb.h"
24#include "adb_unique_fd.h"
25#include "sysdeps.h"
26#include "transport.h"
27
28// Explicitly check the adb server version.
29// All of the commands below do this implicitly.
30// Only the first invocation of this function will check the server version.
31bool adb_check_server_version(std::string* _Nonnull error);
32
33// Connect to adb, connect to the named service, and return a valid fd for
34// interacting with that service upon success or a negative number on failure.
35int adb_connect(std::string_view service, std::string* _Nonnull error);
36
37// Same as above, except returning the TransportId for the service that we've connected to.
38// force_switch_device forces the function to attempt to select a device, even if the service
39// string appears to be a host: service (for use with host services that are device specific, like
40// forward).
41int adb_connect(TransportId* _Nullable id, std::string_view service, std::string* _Nonnull error,
42 bool force_switch_device = false);
43
44// Kill the currently running adb server, if it exists.
45bool adb_kill_server();
46
47// Connect to adb, connect to the named service, returns true if the connection
48// succeeded AND the service returned OKAY. Outputs any returned error otherwise.
49bool adb_command(const std::string& service);
50
51// Connects to the named adb service and fills 'result' with the response.
52// Returns true on success; returns false and fills 'error' on failure.
53bool adb_query(const std::string& service, std::string* _Nonnull result,
54 std::string* _Nonnull error, bool force_switch_device = false);
55
56// Set the preferred transport to connect to.
57void adb_set_transport(TransportType type, const char* _Nullable serial, TransportId transport_id);
58void adb_get_transport(TransportType* _Nullable type, const char* _Nullable* _Nullable serial,
59 TransportId* _Nullable transport_id);
60
61// Set the server's "one device" id. This is either null, or a pointer to a serial number
62// or a pointer to a usb device path, the argument must live to the end of the process.
63void adb_set_one_device(const char* _Nullable one_device);
64
65// Set the socket specification for the adb server.
66// This function can only be called once, and the argument must live to the end of the process.
67void adb_set_socket_spec(const char* _Nonnull socket_spec);
68
69// Send commands to the current emulator instance. Will fail if there is not
70// exactly one emulator connected (or if you use -s <serial> with a <serial>
71// that does not designate an emulator).
72int adb_send_emulator_command(int argc, const char* _Nonnull* _Nonnull argv,
73 const char* _Nullable serial);
74
75// Reads a standard adb status response (OKAY|FAIL) and returns true in the
76// event of OKAY, false in the event of FAIL or protocol error.
77bool adb_status(borrowed_fd fd, std::string* _Nonnull error);
78
79// Create a host command corresponding to selected transport type/serial.
80std::string format_host_command(const char* _Nonnull command);
81
82// Get the feature set of the current preferred transport.
83const std::optional<FeatureSet>& adb_get_feature_set(std::string* _Nullable error);
84
85#if defined(__linux__)
86// Get the path of a file containing the path to the server executable, if the socket spec set via
87// adb_set_socket_spec is a local one.
88std::optional<std::string> adb_get_server_executable_path();
89#endif
90
91[[noreturn]] void error_exit(const char* _Nonnull fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
92[[noreturn]] void perror_exit(const char* _Nonnull fmt, ...) __attribute__((__format__(__printf__, 1, 2)));
93
94// Globally acccesible argv/envp, for the purpose of re-execing adb.
95extern const char* _Nullable * _Nullable __adb_argv;
96extern const char* _Nullable * _Nullable __adb_envp;
TransportType
Definition: adb.h:96
uint64_t TransportId
Definition: adb.h:73
std::string format_host_command(const char *_Nonnull command)
bool adb_kill_server()
Definition: adb_client.cpp:198
int adb_send_emulator_command(int argc, const char *_Nonnull *_Nonnull argv, const char *_Nullable serial)
void adb_set_socket_spec(const char *_Nonnull socket_spec)
void adb_get_transport(TransportType *_Nullable type, const char *_Nullable *_Nullable serial, TransportId *_Nullable transport_id)
bool adb_command(const std::string &service)
Definition: adb_client.cpp:381
void adb_set_one_device(const char *_Nullable one_device)
const std::optional< FeatureSet > & adb_get_feature_set(std::string *_Nullable error)
void void perror_exit(const char *_Nonnull fmt,...) __attribute__((__format__(__printf__
void void const char *_Nullable *_Nullable __adb_argv
Definition: main.cpp:48
bool adb_check_server_version(std::string *_Nonnull error)
bool adb_query(const std::string &service, std::string *_Nonnull result, std::string *_Nonnull error, bool force_switch_device=false)
void adb_set_transport(TransportType type, const char *_Nullable serial, TransportId transport_id)
bool adb_status(borrowed_fd fd, std::string *_Nonnull error)
int adb_connect(std::string_view service, std::string *_Nonnull error)
void error_exit(const char *_Nonnull fmt,...) __attribute__((__format__(__printf__
const char *_Nullable *_Nullable __adb_envp
Definition: main.cpp:49
static const char * serial
Definition: fastboot.cpp:96
#define error(format, args...)
Definition: fec_private.h:201
Definition: result.h:31
class incremental::File __attribute__
uint8_t type
Definition: pairing_connection.h:0
Definition: unique_fd.h:292