-
Notifications
You must be signed in to change notification settings - Fork 1
/
adb-serverette.go
100 lines (88 loc) · 3.98 KB
/
adb-serverette.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
© 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
ISC License
*/
package parl
import (
"context"
)
/*
Serverette is a generic representation of an adb server running on a host.
As of Android 12, Android Debug Bridge version 1.0.41 Version 32.0.0-8006631 has the following commands are supported:
devices connect disconnect pair forward ppp reverse mdns push pull sync shell emu
install install-multiple install-multiple-package uninstall bugreport jdwp logcat disable-verity enable-verity keygen
wait-for* get-state get-serialno get-devpath remount reboot sideload
root unroot usb tcpip start-server kill-server reconnect attach detach
*/
type Serverette interface {
// DeviceSerialList lists serials for the currently online Android devices
DeviceSerialList() (serials []AndroidSerial, err error)
// DeviceForSerial obtains AdbDevice for a serial.
// The device instance can execute additional device functions.
// Devicette can connect to the device similarly to how the server implementation
// connects to trhe adb Android Debug Bridge server
DeviceForSerial(serial AndroidSerial) (android SkeletonDevice, err error)
// TrackDevices emits serial numbers for devices that come online.
// serials are sent on the serials channel.
// if err is non-nil, set-up of failed.
// The errs channel closes when watching stops
// Watching is stopped by calling cancel function or when the server’s context terminates
TrackDevices() (tracker Trackerette, err error)
/*
NIMP 220405:
host:version host:kill host:devices-l host:emulator: host:transport-usb
host:transport-local host:transport-any host-serial: host-usb: host-local:
host: :get-product :get-serialno :get-devpath :get-state
:forward: :forward:norebind: :killforward: :killforward-all :list-forward
*/
}
// Trackerette represents a server connection emitting device serial numbers
type Trackerette interface {
// Serials emit serial number as online devices become available
Serials() (serials <-chan AndroidSerial)
// Errs is available once Serials close. It returns any errors
Errs() (err error)
// Cancel shuts down the Tracker
Cancel()
}
/*
SkeletonDevice respresents a minimal adb protocol level connection to an Android device
via an adb server.
A SkeletonDevice may also be an AddressProvider.
// An address and an AndroidSerial is all required to make an Adbette connection
*/
type SkeletonDevice interface {
// Serial returns the device serial number
Serial() (serial AndroidSerial)
}
// ServeretteFactory is a Server connection factory for Adbette implementations
type ServeretteFactory interface {
// Adb connects to an adb adb Android Debug Bridge server on a specified tcp socket.
// address is a string default "localhost:5037" and default port ":5037".
// adbetter is a factory for Adbette connections.
Adb(address string, adbetter Adbetter, ctx context.Context) (server Serverette)
}
// ServerFactory describes how AdbServer objects are obtained.
// Such servers may use duifferent protocol implementations from Adbette
type ServerFactory interface {
// Adb connects to an adb adb Android Debug Bridge server on a specified tcp socket
Adb(address string, ctx context.Context) (server Serverette)
// AdbLocalhost connects to an adb Android Debug Bridge server on the local computer
AdbLocalhost(ctx context.Context) (server Serverette)
}
// AndroidSerial uniquely identities an Anroid device.
// It is typically a string of a dozen or so 8-bit chanacters consisting of
// lower and upper case a-zA-Z0-9
type AndroidSerial string
// AndroidStatus indicates the current status of a device
// known to a Server or Serverette
// it is a short word of ANSII-set characters
type AndroidStatus string
// AndroidOnline is the Android device status
// that indicates an online device
const AndroidOnline AndroidStatus = "device"
// AdressProvider retrieves the address from an adb server or device so that
// custom devices can be created
type AdressProvider interface {
DialAddress() (address string)
}