github.com/haraldrudell/parl@v0.4.176/if-adb-devicette.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  	"io"
    11  	"io/fs"
    12  	"time"
    13  )
    14  
    15  // Devicette is a generic implementation of the capabilities
    16  // of a device implementing the adb Android debug bridge protocol
    17  type Devicette interface {
    18  	// Serial returns the serial number for this device
    19  	Serial() (serial AndroidSerial)
    20  	// Shell executes a shell command on the device.
    21  	//	- the response is a byte sequence
    22  	//	- note: interning large strings may lead to memory leaks
    23  	Shell(command string) (out []byte, err error)
    24  	// ShellStream executes a shell command on the device returning a readable socket
    25  	ShellStream(command string) (conn io.ReadWriteCloser, err error)
    26  	/*
    27  		Pull copies a remote file or directory on the Android device to a local file system location.
    28  		the local file must not exist.
    29  		Pull refuses certain files like product apks. shell cat works
    30  	*/
    31  	Pull(remotePath, nearPath string) (err error)
    32  	/*
    33  		List has some peculiarities:
    34  		If remoteDir is not an existing directory, an empty list is returned.
    35  		Entries with insufficient permisions are ignored.
    36  		Update: . and .. are removed, adb LIST ortherwise do return those.
    37  		File mode: the only present type bits beyond 9-bit Unix permissions are
    38  		symlink, regular file and directory.
    39  		File size is limited to 4 GiB-1.
    40  		Modification time resolution is second and range is confined to a 32-bit Unix timestamp.
    41  	*/
    42  	List(remoteDir string) (dFileInfo []Dent, err error)
    43  	/*
    44  		NIMP 220405:
    45  		remount: dev: tcp: local:localreserved: localabstract: localfilesystem:
    46  		framebuffer: jdwp: track-jdwp reverse:
    47  		sync STAT SEND
    48  	*/
    49  }
    50  
    51  // Dent is the information returned by adb ls or LIST
    52  type Dent interface {
    53  	// Name is utf-8 base path in device file system.
    54  	// Name is base name, ie. file name and extension.
    55  	Name() (name string)
    56  	// Modified time, the time file contents was changed, second precision, continuous time
    57  	Modified() (modified time.Time)
    58  	// IsDir indicates directory.
    59  	// LIST only support symbolic link, directory and regular file types
    60  	IsDir() (isDir bool)
    61  	// IsRegular indicates regular file, ie. not a directory or symbolic link.
    62  	// LIST only support symbolic link, directory and regular file types
    63  	IsRegular() (isRegular bool) // ie.not directory or symlink
    64  	// Perm returns os.FileMode data.
    65  	// 9-bit Unix permissions per os.FilePerm.
    66  	// LIST also supports directory and symlink bits
    67  	Perm() (perm fs.FileMode)
    68  	// Size is limited to 4 GiB-1
    69  	Size() (size uint32)
    70  }
    71  
    72  // DevicetteFactory describes how Devicette objects are obtained.
    73  type DevicetteFactory interface {
    74  	// NewDevicette creates a Devicette interacting with remote adb Android Debug Bridge
    75  	// devices via an adb server available at the socket address address
    76  	NewDevicette(address AdbSocketAddress, serial AndroidSerial, ctx context.Context) (devicette Devicette)
    77  }