#ifndef LIBADB_H
#define LIBADB_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct adb_connection adb_connection_t;
typedef uint64_t adb_channel_id_t;
typedef enum {
ADB_OK = 0,
ADB_ERR_INVALID_ARG = 1,
ADB_ERR_INVALID_URI = 2,
ADB_ERR_CONNECT = 3,
ADB_ERR_IO = 4,
ADB_ERR_AUTH = 5,
ADB_ERR_PROTOCOL = 6,
ADB_ERR_CHANNEL_CLOSED = 7,
ADB_ERR_NO_FREE_CHANNELS = 8,
ADB_ERR_DESYNCHRONIZED = 9,
ADB_ERR_REVERSE = 10,
ADB_ERR_TLS_REQUIRED = 11,
ADB_ERR_PAIRING = 12,
ADB_ERR_DISCONNECTED = 13,
ADB_ERR_INTERNAL = 255
} adb_status_t;
adb_status_t adb_connect(
const char *uri,
const char *priv_key_pem,
const char *pub_key,
const char *banner,
adb_connection_t **out);
typedef adb_status_t (*adb_sign_fn)(
void *user_data,
const uint8_t *token,
size_t token_len,
uint8_t *out_signature,
size_t out_capacity,
size_t *out_length);
typedef struct {
const uint8_t *public_key;
size_t public_key_len;
adb_sign_fn sign;
void *user_data;
} adb_authenticator_t;
adb_status_t adb_connect_with_authenticator(
const char *uri,
const adb_authenticator_t *authenticator,
const char *banner,
adb_connection_t **out);
void adb_connection_free(adb_connection_t *conn);
typedef struct adb_key adb_key_t;
adb_status_t adb_key_load_or_generate(
const char *android_dir,
const char *name,
adb_key_t **out);
const char *adb_key_private_key_pem(const adb_key_t *key);
const char *adb_key_public_key(const adb_key_t *key);
void adb_key_free(adb_key_t *key);
adb_status_t adb_pair(
const char *uri,
const char *priv_key_pem,
const char *pub_key,
const char *code,
uint8_t *guid,
size_t guid_cap,
size_t *out_guid_len);
adb_status_t adb_connection_set_io_timeout_ms(
adb_connection_t *conn,
uint32_t read_ms,
uint32_t write_ms);
uint32_t adb_connection_max_payload(const adb_connection_t *conn);
bool adb_connection_delayed_ack(const adb_connection_t *conn);
adb_status_t adb_connection_device_banner(
const adb_connection_t *conn,
uint8_t *buf,
size_t buf_len,
size_t *out_len);
typedef uint32_t adb_feature_t;
#define ADB_FEATURE_ABB 0
#define ADB_FEATURE_ABB_EXEC 1
#define ADB_FEATURE_APEX 2
#define ADB_FEATURE_APP_INFO 3
#define ADB_FEATURE_CMD 4
#define ADB_FEATURE_DELAYED_ACK 5
#define ADB_FEATURE_DEVICETRACKER_PROTO_FORMAT 6
#define ADB_FEATURE_DEVRAW 7
#define ADB_FEATURE_FIXED_PUSH_MKDIR 8
#define ADB_FEATURE_FIXED_PUSH_SYMLINK_TIMESTAMP 9
#define ADB_FEATURE_LS_V2 10
#define ADB_FEATURE_OPENSCREEN_MDNS 11
#define ADB_FEATURE_REMOUNT_SHELL 12
#define ADB_FEATURE_SENDRECV_V2 13
#define ADB_FEATURE_SENDRECV_V2_BROTLI 14
#define ADB_FEATURE_SENDRECV_V2_DRY_RUN_SEND 15
#define ADB_FEATURE_SENDRECV_V2_LZ4 16
#define ADB_FEATURE_SENDRECV_V2_ZSTD 17
#define ADB_FEATURE_SHELL_V2 18
#define ADB_FEATURE_STAT_V2 19
#define ADB_FEATURE_TRACK_APP 20
bool adb_connection_has_feature(
const adb_connection_t *conn,
adb_feature_t feature);
const char *adb_feature_name(adb_feature_t feature);
adb_status_t adb_connection_features(
const adb_connection_t *conn,
adb_feature_t *buf,
size_t buf_cap,
size_t *out_len);
adb_status_t adb_open_channel(
adb_connection_t *conn,
const uint8_t *destination,
size_t destination_len,
adb_channel_id_t *out_id);
adb_status_t adb_read_channel(
adb_connection_t *conn,
adb_channel_id_t id,
uint8_t *buf,
size_t buf_len,
size_t *out_read);
adb_status_t adb_write_channel(
adb_connection_t *conn,
adb_channel_id_t id,
const uint8_t *buf,
size_t buf_len);
adb_status_t adb_close_channel(
adb_connection_t *conn,
adb_channel_id_t id);
adb_status_t adb_reverse_forward(
adb_connection_t *conn,
const char *device_spec,
const char *host_spec,
uint8_t *data,
size_t data_cap,
size_t *out_data_len);
adb_status_t adb_reverse_remove(
adb_connection_t *conn,
const char *device_spec);
adb_status_t adb_reverse_remove_all(adb_connection_t *conn);
adb_status_t adb_reverse_list(
adb_connection_t *conn,
uint8_t *buf,
size_t buf_len,
size_t *out_len);
adb_status_t adb_accept_channel(
adb_connection_t *conn,
uint8_t *dest,
size_t dest_cap,
size_t *out_dest_len);
adb_status_t adb_incoming_accept(
adb_connection_t *conn,
adb_channel_id_t *out_id);
adb_status_t adb_incoming_reject(adb_connection_t *conn);
const char *adb_last_error(void);
#define ADB_SHELL_V2_STDIN 0
#define ADB_SHELL_V2_STDOUT 1
#define ADB_SHELL_V2_STDERR 2
#define ADB_SHELL_V2_EXIT 3
#define ADB_SHELL_V2_CLOSE_STDIN 4
#define ADB_SHELL_V2_WINDOW_SIZE_CHANGE 5
typedef struct adb_shell adb_shell_t;
adb_status_t adb_shell_open(
adb_connection_t *conn,
const uint8_t *command,
size_t command_len,
bool pty,
const char *term,
uint16_t rows,
uint16_t cols,
adb_shell_t **out_sh);
void adb_shell_free(adb_shell_t *sh);
adb_status_t adb_shell_read_frame(
adb_shell_t *sh,
uint8_t *out_id,
uint8_t *buf,
size_t buf_cap,
size_t *out_len);
adb_status_t adb_shell_write_stdin(
adb_shell_t *sh,
const uint8_t *data,
size_t len);
adb_status_t adb_shell_close_stdin(adb_shell_t *sh);
adb_status_t adb_shell_set_window_size(
adb_shell_t *sh,
uint16_t rows,
uint16_t cols);
adb_status_t adb_shell_close(adb_shell_t *sh);
#ifdef __cplusplus
}
#endif
#endif