commands.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package adb
  2. import (
  3. "os/exec"
  4. "time"
  5. "notabug.org/Umnik/GoAndroidSDK/common"
  6. "notabug.org/Umnik/GoAndroidSDK/sdk/platformTools/adb/device"
  7. )
  8. //Device returns Device for adb connection
  9. //goland:noinspection GoUnnecessarilyExportedIdentifiers
  10. func (adb Adb) Device() device.Device {
  11. return adb.device
  12. }
  13. //Install installs apk
  14. //goland:noinspection GoUnnecessarilyExportedIdentifiers
  15. func (adb Adb) Install(apkFile string) ([]byte, error) {
  16. return adb.InstallWithFlags([]string{}, apkFile)
  17. }
  18. //InstallWithFlags installs apk with flags
  19. //goland:noinspection GoUnnecessarilyExportedIdentifiers
  20. func (adb Adb) InstallWithFlags(flags []string, apkFile string) ([]byte, error) {
  21. args := append([]string{"install"}, flags...)
  22. return common.ExecWithArgs(adb, append(args, apkFile))
  23. }
  24. //Uninstall uninstalls package
  25. //goland:noinspection GoUnnecessarilyExportedIdentifiers
  26. func (adb Adb) Uninstall(packageName string) ([]byte, error) {
  27. return common.ExecWithVarArgs(adb, "uninstall", packageName)
  28. }
  29. //Pull pulls file
  30. //goland:noinspection GoUnnecessarilyExportedIdentifiers
  31. func (adb Adb) Pull(source, target string) ([]byte, error) {
  32. return common.ExecWithVarArgs(adb, "pull", source, target)
  33. }
  34. //Push pushes or syncs file
  35. //goland:noinspection GoUnnecessarilyExportedIdentifiers
  36. func (adb Adb) Push(source, target string, sync bool) ([]byte, error) {
  37. sFlag := ""
  38. if sync {
  39. sFlag = "--sync"
  40. }
  41. return common.ExecWithVarArgs(adb, "push", sFlag, source, target)
  42. }
  43. //LogcatClear clears logcat buffer
  44. //goland:noinspection GoUnnecessarilyExportedIdentifiers
  45. func (adb Adb) LogcatClear() ([]byte, error) {
  46. return common.ExecWithVarArgs(adb, "logcat", "-c")
  47. }
  48. //LogcatDump dumps logcat buffer
  49. //goland:noinspection GoUnnecessarilyExportedIdentifiers
  50. func (adb Adb) LogcatDump() ([]byte, error) {
  51. return common.ExecWithVarArgs(adb, "logcat", "-d", "-v", "threadtime")
  52. }
  53. //LogcatStartToFileAsync starts saving logcat to filePath
  54. //goland:noinspection GoUnnecessarilyExportedIdentifiers
  55. func (adb Adb) LogcatStartToFileAsync(filePath string) (*exec.Cmd, error) {
  56. return common.StartProcessVarArgs(adb, "logcat", "-v", "threadtime", "-f", filePath)
  57. }
  58. //LogcatStop interrupts logcat process with timeSleep timeout in seconds
  59. //goland:noinspection GoUnnecessarilyExportedIdentifiers
  60. func (adb Adb) LogcatStop(timeSleep time.Duration, process *exec.Cmd) error {
  61. time.Sleep(timeSleep * time.Second)
  62. return common.StopProcess(adb, process)
  63. }