pkg.go.dev Open in urlscan Pro
2600:1901:0:f535::  Public Scan

URL: https://pkg.go.dev/github.com/matt-e/go-adb
Submission: On December 16 via api from US — Scanned from DE

Form analysis 3 forms found in the DOM

/search

<form class="go-InputGroup go-ShortcutKey go-SearchForm-form" action="/search" data-shortcut="/" data-shortcut-alt="search" data-gtmc="search form" aria-label="Search for a package" role="search">
  <input name="q" class="go-Input js-searchFocus" aria-label="Search for a package" type="search" autocapitalize="off" autocomplete="off" autocorrect="off" spellcheck="false" placeholder="Search packages or symbols" value="">
  <input name="m" value="" hidden="">
  <button class="go-Button go-Button--inverted" aria-label="Submit search">
    <img class="go-Icon" height="24" width="24" src="/static/shared/icon/search_gm_grey_24dp.svg" alt="">
  </button>
</form>

DIALOG

<form method="dialog" data-gmtc="jump to form" aria-label="Jump to Identifier">
  <div class="Dialog-title go-Modal-header">
    <h2>Jump to</h2>
    <button class="go-Button go-Button--inline" type="button" data-modal-close="" data-gtmc="modal button" aria-label="Close">
      <img class="go-Icon" height="24" width="24" src="/static/shared/icon/close_gm_grey_24dp.svg" alt="">
    </button>
  </div>
  <div class="JumpDialog-filter">
    <input class="JumpDialog-input go-Input" autocomplete="off" type="text">
  </div>
  <div class="JumpDialog-body go-Modal-body">
    <div class="JumpDialog-list"></div>
  </div>
  <div class="go-Modal-actions">
    <button class="go-Button" data-test-id="close-dialog">Close</button>
  </div>
</form>

DIALOG

<form method="dialog">
  <div class="go-Modal-header">
    <h2>Keyboard shortcuts</h2>
    <button class="go-Button go-Button--inline" type="button" data-modal-close="" data-gtmc="modal button" aria-label="Close">
      <img class="go-Icon" height="24" width="24" src="/static/shared/icon/close_gm_grey_24dp.svg" alt="">
    </button>
  </div>
  <div class="go-Modal-body">
    <table>
      <tbody>
        <tr>
          <td class="ShortcutsDialog-key">
            <strong>?</strong>
          </td>
          <td> : This menu</td>
        </tr>
        <tr>
          <td class="ShortcutsDialog-key">
            <strong>/</strong>
          </td>
          <td> : Search site</td>
        </tr>
        <tr>
          <td class="ShortcutsDialog-key">
            <strong>f</strong> or <strong>F</strong>
          </td>
          <td> : Jump to</td>
        </tr>
        <tr>
          <td class="ShortcutsDialog-key"><strong>y</strong> or <strong>Y</strong></td>
          <td> : Canonical URL</td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class="go-Modal-actions">
    <button class="go-Button" data-test-id="close-dialog">Close</button>
  </div>
</form>

Text Content

Skip to Main Content
 * Why Go
   * Case Studies
     
     Common problems companies solve with Go
   
   * Use Cases
     
     Stories about how and why companies use Go
   
   * Security Policy
     
     How Go can help keep you secure by default
 * Learn
 * Docs
   * Effective Go
     
     Tips for writing clear, performant, and idiomatic Go code
   
   * Go User Manual
     
     A complete introduction to building software with Go
   
   * Standard library
     
     Reference documentation for Go's standard library
   
   * Release Notes
     
     Learn what's new in each Go release
 * Packages
 * Community
   * Recorded Talks
     
     Videos from prior events
   
   * Meetups
     
     Meet other local Go developers
   
   * Conferences
     
     Learn and network with Go developers from around the world
   
   * Go blog
     
     The Go project's official blog.
   
   * Go project
     
     Get help and stay informed from Go
   
   * Get connected
     
     
     
     

 * Why Go
   Why Go
    * Case Studies
    * Use Cases
    * Security Policy

 * Learn
 * Docs
   Docs
    * Effective Go
    * Go User Manual
    * Standard library
    * Release Notes

 * Packages
 * Community
   Community
    * Recorded Talks
    * Meetups
    * Conferences
    * Go blog
    * Go project
    * Get connected
      


 1. Discover Packages
 2. github.com/matt-e/go-adb


ADB

package module
Version: v0.0.0-...-82a4324
Opens a new window with list of versions in this module.
Latest Latest

This package is not in the latest version of its module.

Go to latest Published: Mar 11, 2024 License: Apache-2.0
Opens a new window with license information.
Imports: 23
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
Main Versions Licenses Imports Imported By


DETAILS

 * Valid go.mod file
   
   The Go module system was introduced in Go 1.11 and is the official dependency
   management solution for Go.

 * Redistributable license
   
   Redistributable licenses place minimal restrictions on how software can be
   used, modified, and redistributed.

 * Tagged version
   
   Modules with tagged versions give importers more predictable builds.

 * Stable version
   
   When a project reaches major version v1 it is considered stable.

 * Learn more about best practices


REPOSITORY

github.com/matt-e/go-adb


LINKS

 * Open Source Insights

Jump to ...
 * README
 * Documentation
   * Overview
   * Index
     * Examples
   * Constants
   * Variables
   * Functions
     * ErrorWithCauseChain(err)
     * HasErrCode(err, code)
   * Types
     * type Adb
       * New()
       * NewWithConfig(config)
       * (c) Device(descriptor)
       * (c) Dial()
       * (c) KillServer()
       * (c) ListDeviceSerials()
       * (c) ListDevices()
       * (c) NewDeviceWatcher()
       * (c) ServerVersion()
       * (c) StartServer()
     * type AsyncWriter
       * (a) BytesCompleted()
       * (a) Cancel()
       * (a) Err()
       * (a) Progress()
       * (a) Wait()
     * type Device
       * (c) DeviceInfo()
       * (c) DevicePath()
       * (c) DoSyncFile(path, rd, size, perms)
       * (c) DoSyncHTTPFile(dst, srcUrl, perms)
       * (c) DoSyncLocalFile(dst, src, perms)
       * (c) Forward(local, remote)
       * (c) ForwardList()
       * (c) ForwardRemove(local)
       * (c) ForwardRemoveAll()
       * (c) ForwardToFreePort(remote)
       * (c) KillProcessByName(name, sig)
       * (c) ListDirEntries(path)
       * (c) ListProcesses()
       * (c) OpenCommand(cmd, args)
       * (c) OpenRead(path)
       * (c) OpenWrite(path, perms, mtime)
       * (c) Properties()
       * (c) Reboot()
       * (c) Remount()
       * (c) RunCommand(cmd, args)
       * (c) RunCommandWithExitCode(cmd, args)
       * (c) Serial()
       * (c) Stat(path)
       * (c) StatPackage(packageName)
       * (c) State()
       * (c) String()
       * (c) WriteHttpToFile(path, urlStr, perms)
       * (c) WriteToFile(path, rd, perms)
     * type DeviceDescriptor
       * AnyDevice()
       * AnyLocalDevice()
       * AnyUsbDevice()
       * DeviceWithSerial(serial)
       * (d) String()
     * type DeviceInfo
       * (d) IsUsb()
     * type DeviceState
       * (i) String()
     * type DeviceStateChangedEvent
       * (s) CameOnline()
       * (s) WentOffline()
     * type DeviceWatcher
       * (w) C()
       * (w) Err()
       * (w) Shutdown()
     * type Dialer
     * type DirEntries
       * (entries) Close()
       * (entries) Entry()
       * (entries) Err()
       * (entries) Next()
       * (entries) ReadAll()
     * type DirEntry
     * type ErrCode
     * type ForwardPair
     * type ForwardSpec
       * (f) Port()
       * (f) String()
     * type PackageInfo
     * type Process
     * type ServerConfig
     * type ShellExitError
       * (s) Error()
 * Source Files
 * Directories

READMEDocumentationSource
FilesDirectoriesOverviewIndexConstantsVariablesFunctionsTypesExamplesErrorWithCauseChain(err)HasErrCode(err,
code)type Adbtype AsyncWritertype Devicetype DeviceDescriptortype DeviceInfotype
DeviceStatetype DeviceStateChangedEventtype DeviceWatchertype Dialertype
DirEntriestype DirEntrytype ErrCodetype ForwardPairtype ForwardSpectype
PackageInfotype Processtype ServerConfigtype
ShellExitErrorNew()NewWithConfig(config)(c) Device(descriptor)(c) Dial()(c)
KillServer()(c) ListDeviceSerials()(c) ListDevices()(c) NewDeviceWatcher()(c)
ServerVersion()(c) StartServer()(a) BytesCompleted()(a) Cancel()(a) Err()(a)
Progress()(a) Wait()(c) DeviceInfo()(c) DevicePath()(c) DoSyncFile(path, rd,
size, perms)(c) DoSyncHTTPFile(dst, srcUrl, perms)(c) DoSyncLocalFile(dst, src,
perms)(c) Forward(local, remote)(c) ForwardList()(c) ForwardRemove(local)(c)
ForwardRemoveAll()(c) ForwardToFreePort(remote)(c) KillProcessByName(name,
sig)(c) ListDirEntries(path)(c) ListProcesses()(c) OpenCommand(cmd, args)(c)
OpenRead(path)(c) OpenWrite(path, perms, mtime)(c) Properties()(c) Reboot()(c)
Remount()(c) RunCommand(cmd, args)(c) RunCommandWithExitCode(cmd, args)(c)
Serial()(c) Stat(path)(c) StatPackage(packageName)(c) State()(c) String()(c)
WriteHttpToFile(path, urlStr, perms)(c) WriteToFile(path, rd,
perms)AnyDevice()AnyLocalDevice()AnyUsbDevice()DeviceWithSerial(serial)(d)
String()(d) IsUsb()(i) String()(s) CameOnline()(s) WentOffline()(w) C()(w)
Err()(w) Shutdown()(entries) Close()(entries) Entry()(entries) Err()(entries)
Next()(entries) ReadAll()(f) Port()(f) String()(s) Error()


README ¶

#goadb



A Golang library for interacting with the Android Debug Bridge (adb).

See demo.go for usage.

For this project, a tool called stringer is used to modify some files during go
generate step. Codes will be generated in the following files:

devicedescriptortype_string.go
devicestate_string.go
internal/errors/errcode_string.go


Please make sure your environment variable GOBIN is correctly set, so that
stringer can be successfully installed.

There is a Makefile at repo root. Just need to run:

> make

It will download all dependencies, install stringer locally, generate code, and
run the tests.

Expand ▾ Collapse ▴


DOCUMENTATION ¶

Rendered for linux/amd64 windows/amd64 darwin/amd64 js/wasm


OVERVIEW ¶

package adb is a Go interface to the Android Debug Bridge (adb).

See cmd/demo/demo.go for an example of how to use this library.

The client/server spec is defined at
https://android.googlesource.com/platform/system/core/+/master/adb/OVERVIEW.TXT.

WARNING This library is under heavy development, and its API is likely to change
without notice.


INDEX ¶

 * Constants
 * Variables
 * func ErrorWithCauseChain(err error) string
 * func HasErrCode(err error, code ErrCode) bool
 * type Adb
 * * func New() (*Adb, error)
   * func NewWithConfig(config ServerConfig) (*Adb, error)
 * * func (c *Adb) Device(descriptor DeviceDescriptor) *Device
   * func (c *Adb) Dial() (*wire.Conn, error)
   * func (c *Adb) KillServer() error
   * func (c *Adb) ListDeviceSerials() ([]string, error)
   * func (c *Adb) ListDevices() ([]*DeviceInfo, error)
   * func (c *Adb) NewDeviceWatcher() *DeviceWatcher
   * func (c *Adb) ServerVersion() (int, error)
   * func (c *Adb) StartServer() error
 * type AsyncWriter
 * * func (a *AsyncWriter) BytesCompleted() int64
   * func (a *AsyncWriter) Cancel() error
   * func (a *AsyncWriter) Err() error
   * func (a *AsyncWriter) Progress() float64
   * func (a *AsyncWriter) Wait()
 * type Device
 * * func (c *Device) DeviceInfo() (*DeviceInfo, error)
   * func (c *Device) DevicePath() (string, error)
   * func (c *Device) DoSyncFile(path string, rd io.ReadCloser, size int64,
     perms os.FileMode) (aw *AsyncWriter, err error)
   * func (c *Device) DoSyncHTTPFile(dst string, srcUrl string, perms
     os.FileMode) (aw *AsyncWriter, err error)
   * func (c *Device) DoSyncLocalFile(dst string, src string, perms os.FileMode)
     (aw *AsyncWriter, err error)
   * func (c *Device) Forward(local, remote ForwardSpec) error
   * func (c *Device) ForwardList() (fs []ForwardPair, err error)
   * func (c *Device) ForwardRemove(local ForwardSpec) error
   * func (c *Device) ForwardRemoveAll() error
   * func (c *Device) ForwardToFreePort(remote ForwardSpec) (port int, err
     error)
   * func (c *Device) KillProcessByName(name string, sig syscall.Signal) error
   * func (c *Device) ListDirEntries(path string) (*DirEntries, error)
   * func (c *Device) ListProcesses() (ps []Process, err error)
   * func (c *Device) OpenCommand(cmd string, args ...string) (conn *wire.Conn,
     err error)
   * func (c *Device) OpenRead(path string) (io.ReadCloser, error)
   * func (c *Device) OpenWrite(path string, perms os.FileMode, mtime time.Time)
     (io.WriteCloser, error)
   * func (c *Device) Properties() (props map[string]string, err error)
   * func (c *Device) Reboot() error
   * func (c *Device) Remount() (string, error)
   * func (c *Device) RunCommand(cmd string, args ...string) (string, error)
   * func (c *Device) RunCommandWithExitCode(cmd string, args ...string)
     (string, int, error)
   * func (c *Device) Serial() (string, error)
   * func (c *Device) Stat(path string) (*DirEntry, error)
   * func (c *Device) StatPackage(packageName string) (pi PackageInfo, err
     error)
   * func (c *Device) State() (DeviceState, error)
   * func (c *Device) String() string
   * func (c *Device) WriteHttpToFile(path string, urlStr string, perms
     os.FileMode) (written int64, err error)
   * func (c *Device) WriteToFile(path string, rd io.Reader, perms os.FileMode)
     (written int64, err error)
 * type DeviceDescriptor
 * * func AnyDevice() DeviceDescriptor
   * func AnyLocalDevice() DeviceDescriptor
   * func AnyUsbDevice() DeviceDescriptor
   * func DeviceWithSerial(serial string) DeviceDescriptor
 * * func (d DeviceDescriptor) String() string
 * type DeviceInfo
 * * func (d *DeviceInfo) IsUsb() bool
 * type DeviceState
 * * func (i DeviceState) String() string
 * type DeviceStateChangedEvent
 * * func (s DeviceStateChangedEvent) CameOnline() bool
   * func (s DeviceStateChangedEvent) WentOffline() bool
 * type DeviceWatcher
 * * func (w *DeviceWatcher) C() <-chan DeviceStateChangedEvent
   * func (w *DeviceWatcher) Err() error
   * func (w *DeviceWatcher) Shutdown()
 * type Dialer
 * type DirEntries
 * * func (entries *DirEntries) Close() error
   * func (entries *DirEntries) Entry() *DirEntry
   * func (entries *DirEntries) Err() error
   * func (entries *DirEntries) Next() bool
   * func (entries *DirEntries) ReadAll() (result []*DirEntry, err error)
 * type DirEntry
 * type ErrCode
 * type ForwardPair
 * type ForwardSpec
 * * func (f ForwardSpec) Port() (int, error)
   * func (f ForwardSpec) String() string
 * type PackageInfo
 * type Process
 * type ServerConfig
 * type ShellExitError
 * * func (s ShellExitError) Error() string

EXAMPLES ¶

 * Device.DoSyncLocalFile


CONSTANTS ¶

View Source

const (
	// host:transport-any and host:<request>
	DeviceAny deviceDescriptorType = iota
	// host:transport:<serial> and host-serial:<serial>:<request>
	DeviceSerial
	// host:transport-usb and host-usb:<request>
	DeviceUsb
	// host:transport-local and host-local:<request>
	DeviceLocal
)

View Source

const (
	AssertionError = ErrCode(errors.AssertionError)
	ParseError     = ErrCode(errors.ParseError)
	// The server was not available on the requested port.
	ServerNotAvailable = ErrCode(errors.ServerNotAvailable)
	// General network error communicating with the server.
	NetworkError = ErrCode(errors.NetworkError)
	// The connection to the server was reset in the middle of an operation. Server probably died.
	ConnectionResetError = ErrCode(errors.ConnectionResetError)
	// The server returned an error message, but we couldn't parse it.
	AdbError = ErrCode(errors.AdbError)
	// The server returned a "device not found" error.
	DeviceNotFound = ErrCode(errors.DeviceNotFound)
	// Tried to perform an operation on a path that doesn't exist on the device.
	FileNoExistError = ErrCode(errors.FileNoExistError)
)

View Source

const (
	AdbExecutableName = "adb"

	// Default port the adb server listens on.
	AdbPort = 5037
)


VARIABLES ¶

View Source

var (
	FProtocolTcp        = "tcp"
	FProtocolAbstract   = "localabstract"
	FProtocolReserved   = "localreserved"
	FProtocolFilesystem = "localfilesystem"
)

View Source

var ErrPackageNotExist = sysErrors.New("package not exist")

View Source

var MtimeOfClose = time.Time{}

MtimeOfClose should be passed to OpenWrite to set the file modification time to
the time the Close method is called.


FUNCTIONS ¶

FUNC ERRORWITHCAUSECHAIN ¶

func ErrorWithCauseChain(err error) string

ErrorWithCauseChain formats err and all its causes if it's an *errors.Err, else
returns err.Error().

FUNC HASERRCODE ¶

func HasErrCode(err error, code ErrCode) bool

HasErrCode returns true if err is an *errors.Err and err.Code == code.


TYPES ¶

TYPE ADB ¶

type Adb struct {
	// contains filtered or unexported fields
}

Adb communicates with host services on the adb server.

Eg.

client := adb.New()
client.ListDevices()


See list of services at
https://android.googlesource.com/platform/system/core/+/master/adb/SERVICES.TXT.

TODO(z): Finish implementing host services.

FUNC NEW ¶

func New() (*Adb, error)

New creates a new Adb client that uses the default ServerConfig.

FUNC NEWWITHCONFIG ¶

func NewWithConfig(config ServerConfig) (*Adb, error)

FUNC (*ADB) DEVICE ¶

func (c *Adb) Device(descriptor DeviceDescriptor) *Device

FUNC (*ADB) DIAL ¶

func (c *Adb) Dial() (*wire.Conn, error)

Dial establishes a connection with the adb server.

FUNC (*ADB) KILLSERVER ¶

func (c *Adb) KillServer() error

KillServer tells the server to quit immediately.

Corresponds to the command:

adb kill-server


FUNC (*ADB) LISTDEVICESERIALS ¶

func (c *Adb) ListDeviceSerials() ([]string, error)

ListDeviceSerials returns the serial numbers of all attached devices.

Corresponds to the command:

adb devices


FUNC (*ADB) LISTDEVICES ¶

func (c *Adb) ListDevices() ([]*DeviceInfo, error)

ListDevices returns the list of connected devices.

Corresponds to the command:

adb devices -l


FUNC (*ADB) NEWDEVICEWATCHER ¶

func (c *Adb) NewDeviceWatcher() *DeviceWatcher

FUNC (*ADB) SERVERVERSION ¶

func (c *Adb) ServerVersion() (int, error)

ServerVersion asks the ADB server for its internal version number.

FUNC (*ADB) STARTSERVER ¶

func (c *Adb) StartServer() error

Starts the adb server if it’s not running.

TYPE ASYNCWRITER ¶

type AsyncWriter struct {
	Done     chan bool
	DoneCopy chan bool // for debug
	C        chan bool

	TotalSize int64
	// contains filtered or unexported fields
}

FUNC (*ASYNCWRITER) BYTESCOMPLETED ¶

func (a *AsyncWriter) BytesCompleted() int64

BytesCompleted returns the total number of bytes which have been copied to the
destination

FUNC (*ASYNCWRITER) CANCEL ¶

func (a *AsyncWriter) Cancel() error

FUNC (*ASYNCWRITER) ERR ¶

func (a *AsyncWriter) Err() error

Err return error immediately

FUNC (*ASYNCWRITER) PROGRESS ¶

func (a *AsyncWriter) Progress() float64

FUNC (*ASYNCWRITER) WAIT ¶

func (a *AsyncWriter) Wait()

Wait blocks until sync is completed

TYPE DEVICE ¶

type Device struct {
	// contains filtered or unexported fields
}

Device communicates with a specific Android device. To get an instance, call
Device() on an Adb.

FUNC (*DEVICE) DEVICEINFO ¶

func (c *Device) DeviceInfo() (*DeviceInfo, error)

FUNC (*DEVICE) DEVICEPATH ¶

func (c *Device) DevicePath() (string, error)

FUNC (*DEVICE) DOSYNCFILE ¶

func (c *Device) DoSyncFile(path string, rd io.ReadCloser, size int64, perms os.FileMode) (aw *AsyncWriter, err error)

DoWriteFile return an object, use this object can Cancel write and get Process

FUNC (*DEVICE) DOSYNCHTTPFILE ¶

func (c *Device) DoSyncHTTPFile(dst string, srcUrl string, perms os.FileMode) (aw *AsyncWriter, err error)

FUNC (*DEVICE) DOSYNCLOCALFILE ¶

func (c *Device) DoSyncLocalFile(dst string, src string, perms os.FileMode) (aw *AsyncWriter, err error)

Example ¶

Output:





Share Format Run

FUNC (*DEVICE) FORWARD ¶

func (c *Device) Forward(local, remote ForwardSpec) error

Forward remote connection to local

FUNC (*DEVICE) FORWARDLIST ¶

func (c *Device) ForwardList() (fs []ForwardPair, err error)

ForwardList returns list with struct ForwardPair If no device serial specified
all devices's forward list will returned

FUNC (*DEVICE) FORWARDREMOVE ¶

func (c *Device) ForwardRemove(local ForwardSpec) error

ForwardRemove specified forward

FUNC (*DEVICE) FORWARDREMOVEALL ¶

func (c *Device) ForwardRemoveAll() error

ForwardRemoveAll cancel all exists forwards

FUNC (*DEVICE) FORWARDTOFREEPORT ¶

func (c *Device) ForwardToFreePort(remote ForwardSpec) (port int, err error)

ForwardToFreePort return random generated port If forward already exists, just
return current forworded port

FUNC (*DEVICE) KILLPROCESSBYNAME ¶

func (c *Device) KillProcessByName(name string, sig syscall.Signal) error

KillProcessByName return if killed success

FUNC (*DEVICE) LISTDIRENTRIES ¶

func (c *Device) ListDirEntries(path string) (*DirEntries, error)

FUNC (*DEVICE) LISTPROCESSES ¶

func (c *Device) ListProcesses() (ps []Process, err error)

ListProcesses return list of Process

FUNC (*DEVICE) OPENCOMMAND ¶

func (c *Device) OpenCommand(cmd string, args ...string) (conn *wire.Conn, err error)

FUNC (*DEVICE) OPENREAD ¶

func (c *Device) OpenRead(path string) (io.ReadCloser, error)

FUNC (*DEVICE) OPENWRITE ¶

func (c *Device) OpenWrite(path string, perms os.FileMode, mtime time.Time) (io.WriteCloser, error)

OpenWrite opens the file at path on the device, creating it with the permissions
specified by perms if necessary, and returns a writer that writes to the file.
The files modification time will be set to mtime when the WriterCloser is
closed. The zero value is TimeOfClose, which will use the time the Close method
is called as the modification time.

FUNC (*DEVICE) PROPERTIES ¶

func (c *Device) Properties() (props map[string]string, err error)

Properties extract info from $ adb shell getprop

FUNC (*DEVICE) REBOOT ¶

func (c *Device) Reboot() error

FUNC (*DEVICE) REMOUNT ¶

func (c *Device) Remount() (string, error)

Remount, from the official adb command’s docs:

Ask adbd to remount the device's filesystem in read-write mode,
instead of read-only. This is usually necessary before performing
an "adb sync" or "adb push" request.
This request may not succeed on certain builds which do not allow
that.


Source:
https://android.googlesource.com/platform/system/core/+/master/adb/SERVICES.TXT

FUNC (*DEVICE) RUNCOMMAND ¶

func (c *Device) RunCommand(cmd string, args ...string) (string, error)

RunCommand runs the specified commands on a shell on the device.

From the Android docs:

Run 'command arg1 arg2 ...' in a shell on the device, and return
its output and error streams. Note that arguments must be separated
by spaces. If an argument contains a space, it must be quoted with
double-quotes. Arguments cannot contain double quotes or things
will go very wrong.

Note that this is the non-interactive version of "adb shell"


Source:
https://android.googlesource.com/platform/system/core/+/master/adb/SERVICES.TXT

This method quotes the arguments for you, and will return an error if any of
them contain double quotes.

Because the adb shell converts all "\n" into "\r\n", so here we convert it back
(maybe not good for binary output)

FUNC (*DEVICE) RUNCOMMANDWITHEXITCODE ¶

func (c *Device) RunCommandWithExitCode(cmd string, args ...string) (string, int, error)

RunCommandWithExitCode use a little tricky to get exit code

The tricky is append "; echo :$?" to the command, and parse out the exit code
from output

FUNC (*DEVICE) SERIAL ¶

func (c *Device) Serial() (string, error)

FUNC (*DEVICE) STAT ¶

func (c *Device) Stat(path string) (*DirEntry, error)

FUNC (*DEVICE) STATPACKAGE ¶

func (c *Device) StatPackage(packageName string) (pi PackageInfo, err error)

StatPackage returns PackageInfo If package not found, err will be
ErrPackageNotExist

FUNC (*DEVICE) STATE ¶

func (c *Device) State() (DeviceState, error)

FUNC (*DEVICE) STRING ¶

func (c *Device) String() string

FUNC (*DEVICE) WRITEHTTPTOFILE ¶

func (c *Device) WriteHttpToFile(path string, urlStr string, perms os.FileMode) (written int64, err error)

WriteHttpToFile download http resource to device

FUNC (*DEVICE) WRITETOFILE ¶

func (c *Device) WriteToFile(path string, rd io.Reader, perms os.FileMode) (written int64, err error)

WriteToFile write a reader stream to device

TYPE DEVICEDESCRIPTOR ¶

type DeviceDescriptor struct {
	// contains filtered or unexported fields
}

FUNC ANYDEVICE ¶

func AnyDevice() DeviceDescriptor

FUNC ANYLOCALDEVICE ¶

func AnyLocalDevice() DeviceDescriptor

FUNC ANYUSBDEVICE ¶

func AnyUsbDevice() DeviceDescriptor

FUNC DEVICEWITHSERIAL ¶

func DeviceWithSerial(serial string) DeviceDescriptor

FUNC (DEVICEDESCRIPTOR) STRING ¶

func (d DeviceDescriptor) String() string

TYPE DEVICEINFO ¶

type DeviceInfo struct {
	// Always set.
	Serial string
	State  DeviceState

	// Product, device, and model are not set in the short form.
	Product    string
	Model      string
	DeviceInfo string

	// Only set for devices connected via USB.
	Usb string

	// Set to 'device' usually, but have observed 'unauthorized' or 'offline'
	Flag string
}

FUNC (*DEVICEINFO) ISUSB ¶

func (d *DeviceInfo) IsUsb() bool

IsUsb returns true if the device is connected via USB.

TYPE DEVICESTATE ¶

type DeviceState int8

DeviceState represents one of the 3 possible states adb will report devices. A
device can be communicated with when it's in StateOnline. A USB device will make
the following state transitions:

Plugged in: StateDisconnected->StateOffline->StateOnline
Unplugged:  StateOnline->StateDisconnected


const (
	StateInvalid DeviceState = iota
	StateUnauthorized
	StateDisconnected
	StateOffline
	StateOnline
)

FUNC (DEVICESTATE) STRING ¶

func (i DeviceState) String() string

TYPE DEVICESTATECHANGEDEVENT ¶

type DeviceStateChangedEvent struct {
	Serial   string
	OldState DeviceState
	NewState DeviceState
}

DeviceStateChangedEvent represents a device state transition. Contains the
device’s old and new states, but also provides methods to query the type of
state transition.

FUNC (DEVICESTATECHANGEDEVENT) CAMEONLINE ¶

func (s DeviceStateChangedEvent) CameOnline() bool

CameOnline returns true if this event represents a device coming online.

FUNC (DEVICESTATECHANGEDEVENT) WENTOFFLINE ¶

func (s DeviceStateChangedEvent) WentOffline() bool

WentOffline returns true if this event represents a device going offline.

TYPE DEVICEWATCHER ¶

type DeviceWatcher struct {
	// contains filtered or unexported fields
}

DeviceWatcher publishes device status change events. If the server dies while
listening for events, it restarts the server.

FUNC (*DEVICEWATCHER) C ¶

func (w *DeviceWatcher) C() <-chan DeviceStateChangedEvent

C returns a channel than can be received on to get events. If an unrecoverable
error occurs, or Shutdown is called, the channel will be closed.

FUNC (*DEVICEWATCHER) ERR ¶

func (w *DeviceWatcher) Err() error

Err returns the error that caused the channel returned by C to be closed, if C
is closed. If C is not closed, its return value is undefined.

FUNC (*DEVICEWATCHER) SHUTDOWN ¶

func (w *DeviceWatcher) Shutdown()

Shutdown stops the watcher from listening for events and closes the channel
returned from C.

TYPE DIALER ¶

type Dialer interface {
	Dial(address string) (*wire.Conn, error)
}

Dialer knows how to create connections to an adb server.

TYPE DIRENTRIES ¶

type DirEntries struct {
	// contains filtered or unexported fields
}

DirEntries iterates over directory entries.

FUNC (*DIRENTRIES) CLOSE ¶

func (entries *DirEntries) Close() error

Close closes the connection to the adb. Next() will call Close() before
returning false.

FUNC (*DIRENTRIES) ENTRY ¶

func (entries *DirEntries) Entry() *DirEntry

FUNC (*DIRENTRIES) ERR ¶

func (entries *DirEntries) Err() error

FUNC (*DIRENTRIES) NEXT ¶

func (entries *DirEntries) Next() bool

FUNC (*DIRENTRIES) READALL ¶

func (entries *DirEntries) ReadAll() (result []*DirEntry, err error)

ReadAllDirEntries reads all the remaining directory entries into a slice, closes
self, and returns any error. If err is non-nil, result will contain any entries
read until the error occurred.

TYPE DIRENTRY ¶

type DirEntry struct {
	Name       string
	Mode       os.FileMode
	Size       int32
	ModifiedAt time.Time
}

DirEntry holds information about a directory entry on a device.

TYPE ERRCODE ¶

type ErrCode errors.ErrCode

TYPE FORWARDPAIR ¶

type ForwardPair struct {
	Serial string
	Local  ForwardSpec
	Remote ForwardSpec
}

TYPE FORWARDSPEC ¶

type ForwardSpec struct {
	Protocol   string
	PortOrName string
}

FUNC (FORWARDSPEC) PORT ¶

func (f ForwardSpec) Port() (int, error)

FUNC (FORWARDSPEC) STRING ¶

func (f ForwardSpec) String() string

TYPE PACKAGEINFO ¶

type PackageInfo struct {
	Name    string
	Path    string
	Version struct {
		Code int
		Name string
	}
}

TYPE PROCESS ¶

type Process struct {
	User string
	Pid  int
	Name string
}

TYPE SERVERCONFIG ¶

type ServerConfig struct {
	// Path to the adb executable. If empty, the PATH environment variable will be searched.
	PathToAdb string

	// Host and port the adb server is listening on.
	// If not specified, will use the default port on localhost.
	Host string
	Port int

	// Dialer used to connect to the adb server.
	Dialer
	// contains filtered or unexported fields
}

TYPE SHELLEXITERROR ¶

type ShellExitError struct {
	Command  string
	ExitCode int
}

FUNC (SHELLEXITERROR) ERROR ¶

func (s ShellExitError) Error() string


SOURCE FILES ¶

View all Source files
 * adb.go
 * asyncwriter.go
 * device.go
 * device_descriptor.go
 * device_extra.go
 * device_info.go
 * device_state.go
 * device_watcher.go
 * devicedescriptortype_string.go
 * devicestate_string.go
 * dialer.go
 * dir_entries.go
 * doc.go
 * error.go
 * executable.go
 * executable_unix.go
 * server.go
 * sync_client.go
 * sync_file_reader.go
 * sync_file_writer.go
 * util.go


DIRECTORIES ¶

Show internal Expand all

Path Synopsis
cmd
adb

demo
An app demonstrating most of the library's features.
An app demonstrating most of the library's features.
raw-adb
A simple tool for sending raw messages to an adb server.
A simple tool for sending raw messages to an adb server.
internal
errors

wire
Package wire implements the low-level part of the client/server wire protocol.
Package wire implements the low-level part of the client/server wire protocol.

Click to show internal directories.
Click to hide internal directories.

Why Go Use Cases Case Studies
Get Started Playground Tour Stack Overflow Help
Packages Standard Library Sub-repositories About Go Packages
About Download Blog Issue Tracker Release Notes Brand Guidelines Code of Conduct
Connect Twitter GitHub Slack r/golang Meetup Golang Weekly
 * Copyright
 * Terms of Service
 * Privacy Policy
 * Report an Issue

 * Theme Toggle

 * Shortcuts Modal


JUMP TO



Close


KEYBOARD SHORTCUTS

? : This menu / : Search site f or F : Jump to y or Y : Canonical URL

Close
go.dev uses cookies from Google to deliver and enhance the quality of its
services and to analyze traffic. Learn more.
Okay