#include "AdbClient.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileUtilities.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/PosixApi.h"
#include "lldb/Utility/DataBuffer.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/DataEncoder.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/Timeout.h"
#include <climits>
#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <sstream>
#ifdef SendMessage
#undef SendMessage
#endif
usingnamespacelldb;
usingnamespacelldb_private;
usingnamespacelldb_private::platform_android;
usingnamespacestd::chrono;
static const seconds kReadTimeout(20);
static const char *kOKAY = …;
static const char *kFAIL = …;
static const char *kDATA = …;
static const char *kDONE = …;
static const char *kSEND = …;
static const char *kRECV = …;
static const char *kSTAT = …;
static const size_t kSyncPacketLen = …;
static const size_t kMaxPushData = …;
static const uint32_t kDefaultMode = …;
static const char *kSocketNamespaceAbstract = …;
static const char *kSocketNamespaceFileSystem = …;
static Status ReadAllBytes(Connection &conn, void *buffer, size_t size) { … }
Status AdbClient::CreateByDeviceID(const std::string &device_id,
AdbClient &adb) { … }
AdbClient::AdbClient() = default;
AdbClient::AdbClient(const std::string &device_id) : … { … }
AdbClient::~AdbClient() = default;
void AdbClient::SetDeviceID(const std::string &device_id) { … }
const std::string &AdbClient::GetDeviceID() const { … }
Status AdbClient::Connect() { … }
Status AdbClient::GetDevices(DeviceIDList &device_list) { … }
Status AdbClient::SetPortForwarding(const uint16_t local_port,
const uint16_t remote_port) { … }
Status
AdbClient::SetPortForwarding(const uint16_t local_port,
llvm::StringRef remote_socket_name,
const UnixSocketNamespace socket_namespace) { … }
Status AdbClient::DeletePortForwarding(const uint16_t local_port) { … }
Status AdbClient::SendMessage(const std::string &packet, const bool reconnect) { … }
Status AdbClient::SendDeviceMessage(const std::string &packet) { … }
Status AdbClient::ReadMessage(std::vector<char> &message) { … }
Status AdbClient::ReadMessageStream(std::vector<char> &message,
milliseconds timeout) { … }
Status AdbClient::ReadResponseStatus() { … }
Status AdbClient::GetResponseError(const char *response_id) { … }
Status AdbClient::SwitchDeviceTransport() { … }
Status AdbClient::StartSync() { … }
Status AdbClient::Sync() { … }
Status AdbClient::ReadAllBytes(void *buffer, size_t size) { … }
Status AdbClient::internalShell(const char *command, milliseconds timeout,
std::vector<char> &output_buf) { … }
Status AdbClient::Shell(const char *command, milliseconds timeout,
std::string *output) { … }
Status AdbClient::ShellToFile(const char *command, milliseconds timeout,
const FileSpec &output_file_spec) { … }
std::unique_ptr<AdbClient::SyncService>
AdbClient::GetSyncService(Status &error) { … }
Status AdbClient::SyncService::internalPullFile(const FileSpec &remote_file,
const FileSpec &local_file) { … }
Status AdbClient::SyncService::internalPushFile(const FileSpec &local_file,
const FileSpec &remote_file) { … }
Status AdbClient::SyncService::internalStat(const FileSpec &remote_file,
uint32_t &mode, uint32_t &size,
uint32_t &mtime) { … }
Status AdbClient::SyncService::PullFile(const FileSpec &remote_file,
const FileSpec &local_file) { … }
Status AdbClient::SyncService::PushFile(const FileSpec &local_file,
const FileSpec &remote_file) { … }
Status AdbClient::SyncService::Stat(const FileSpec &remote_file, uint32_t &mode,
uint32_t &size, uint32_t &mtime) { … }
bool AdbClient::SyncService::IsConnected() const { … }
AdbClient::SyncService::SyncService(std::unique_ptr<Connection> &&conn)
: … { … }
Status
AdbClient::SyncService::executeCommand(const std::function<Status()> &cmd) { … }
AdbClient::SyncService::~SyncService() = default;
Status AdbClient::SyncService::SendSyncRequest(const char *request_id,
const uint32_t data_len,
const void *data) { … }
Status AdbClient::SyncService::ReadSyncHeader(std::string &response_id,
uint32_t &data_len) { … }
Status AdbClient::SyncService::PullFileChunk(std::vector<char> &buffer,
bool &eof) { … }
Status AdbClient::SyncService::ReadAllBytes(void *buffer, size_t size) { … }