struct.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package connection
  2. import (
  3. "os/exec"
  4. "notabug.org/Umnik/GoAndroidSDK/v2/components/sdk/platformTools/adb"
  5. )
  6. type Connection struct {
  7. adb adb.Adb
  8. device adb.Device
  9. }
  10. func (c Connection) Adb() adb.Adb {
  11. return c.adb
  12. }
  13. func (c Connection) Device() adb.Device {
  14. return c.device
  15. }
  16. // Install installs apk
  17. func (c Connection) Install(apkFile string, flags ...string) ([]byte, error) {
  18. fc := append(flags, apkFile)
  19. return c.RunSync("install", fc...)
  20. }
  21. // Uninstall uninstalls package
  22. func (c Connection) Uninstall(packageName string) ([]byte, error) {
  23. return c.RunSync("uninstall", packageName)
  24. }
  25. // Pull pulls files from device to host
  26. func (c Connection) Pull(onDevice, onHost string) ([]byte, error) {
  27. return c.RunSync("pull", onDevice, onHost)
  28. }
  29. // Push pushes or syncs file
  30. func (c Connection) Push(onDevice, onHost string, sync bool) ([]byte, error) {
  31. sFlag := ""
  32. if sync {
  33. sFlag = "--sync"
  34. }
  35. return c.RunSync("push", sFlag, onHost, onDevice)
  36. }
  37. // LogcatClear clears logcat buffer
  38. func (c Connection) LogcatClear() ([]byte, error) {
  39. return c.RunSync("logcat", "-c")
  40. }
  41. // LogcatDump dumps logcat buffer
  42. func (c Connection) LogcatDump() ([]byte, error) {
  43. return c.RunSync("logcat", "-d", "-v", "threadtime")
  44. }
  45. // LogcatStartToFileAsync starts saving logcat to filePath
  46. func (c Connection) LogcatStartToFileAsync(filePath string) (*exec.Cmd, error) {
  47. return c.StartAsync("logcat", "-v", "threadtime", "-f", filePath)
  48. }
  49. // LogcatStop interrupts logcat process with timeSleep timeout in seconds
  50. func (c Connection) LogcatStop(process *exec.Cmd) error {
  51. return c.StopAsync(process)
  52. }