github.com/haraldrudell/parl@v0.4.176/if-adb-serverette.go (about)

     1  /*
     2  © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package parl
     7  
     8  import (
     9  	"context"
    10  )
    11  
    12  /*
    13  Serverette is a generic representation of an adb server running on a host.
    14  
    15  command-line adb:
    16  As of Android 12, Android Debug Bridge version 1.0.41 Version 32.0.0-8006631 has the following commands are supported:
    17  devices connect disconnect pair forward ppp reverse mdns push pull sync shell emu
    18  install install-multiple install-multiple-package uninstall bugreport jdwp logcat disable-verity enable-verity keygen
    19  wait-for* get-state get-serialno get-devpath remount reboot sideload
    20  root unroot usb tcpip start-server kill-server reconnect attach detach
    21  */
    22  type Serverette interface {
    23  	AdbAdressProvider // AdbSocketAddress()
    24  	// DeviceSerialList lists serials for the currently online Android devices
    25  	DeviceSerialList() (serials []AndroidSerial, err error)
    26  	// DeviceStati lists all serials currently known to the server along with
    27  	// their current status.
    28  	// The two slices correspond and are of the same length
    29  	DeviceStati() (serials []AndroidSerial, stati []AndroidStatus, err error)
    30  	// TrackDevices emits serial numbers for devices that come online.
    31  	// serials are sent on the serials channel.
    32  	// if err is non-nil, set-up of failed.
    33  	// The errs channel closes when watching stops
    34  	// Watching is stopped by calling cancel function or when the server’s context terminates
    35  	TrackDevices() (tracker Trackerette, err error)
    36  	/*
    37  		NIMP 220405:
    38  		host:version host:kill host:devices-l host:emulator: host:transport-usb
    39  		host:transport-local host:transport-any host-serial: host-usb: host-local:
    40  		host: :get-product :get-serialno :get-devpath :get-state
    41  		:forward: :forward:norebind: :killforward: :killforward-all :list-forward
    42  	*/
    43  }
    44  
    45  // Trackerette represents a server connection emitting device serial numbers
    46  type Trackerette interface {
    47  	// Serials emit serial number as online devices become available
    48  	Serials() (serials <-chan AndroidSerial)
    49  	// Errs is available once Serials close. It returns any errors
    50  	Errs() (err error)
    51  	// Cancel shuts down the Tracker
    52  	Cancel()
    53  }
    54  
    55  // ServeretteFactory is a Server connection factory for Adbette implementations
    56  type ServeretteFactory interface {
    57  	// Adb connects to an adb adb Android Debug Bridge server on a specified tcp socket.
    58  	// address is a string default "localhost:5037" and default port ":5037".
    59  	// adbetter is a factory for Adbette connections.
    60  	NewServerette(address AdbSocketAddress, adbetter Adbetter, ctx context.Context) (server Serverette)
    61  }
    62  
    63  // ServerFactory describes how AdbServer objects are obtained.
    64  // Such servers may use duifferent protocol implementations from Adbette
    65  type ServerFactory interface {
    66  	// Adb connects to an adb adb Android Debug Bridge server on a specified tcp socket
    67  	Adb(address AdbSocketAddress, ctx context.Context) (server Serverette)
    68  	// AdbLocalhost connects to an adb Android Debug Bridge server on the local computer
    69  	AdbLocalhost(ctx context.Context) (server Serverette)
    70  }
    71  
    72  // AndroidStatus indicates the current status of a device
    73  // known to a Server or Serverette
    74  //   - AndroidStatus is a single word of ANSII-set characters
    75  type AndroidStatus string
    76  
    77  // AndroidOnline is the Android device status
    78  // that indicates an online device
    79  //   - can be checked using method [AndroidSerial.IsOnline]
    80  const AndroidOnline AndroidStatus = "device"