12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package adb
- import (
- "os/exec"
- "time"
- "notabug.org/Umnik/GoAndroidSDK/common"
- "notabug.org/Umnik/GoAndroidSDK/sdk/platformTools/adb/device"
- )
- //Device returns Device for adb connection
- //goland:noinspection GoUnnecessarilyExportedIdentifiers
- func (adb Adb) Device() device.Device {
- return adb.device
- }
- //Install installs apk
- //goland:noinspection GoUnnecessarilyExportedIdentifiers
- func (adb Adb) Install(apkFile string) ([]byte, error) {
- return adb.InstallWithFlags([]string{}, apkFile)
- }
- //InstallWithFlags installs apk with flags
- //goland:noinspection GoUnnecessarilyExportedIdentifiers
- func (adb Adb) InstallWithFlags(flags []string, apkFile string) ([]byte, error) {
- args := append([]string{"install"}, flags...)
- return common.ExecWithArgs(adb, append(args, apkFile))
- }
- //Uninstall uninstalls package
- //goland:noinspection GoUnnecessarilyExportedIdentifiers
- func (adb Adb) Uninstall(packageName string) ([]byte, error) {
- return common.ExecWithVarArgs(adb, "uninstall", packageName)
- }
- //Pull pulls file
- //goland:noinspection GoUnnecessarilyExportedIdentifiers
- func (adb Adb) Pull(source, target string) ([]byte, error) {
- return common.ExecWithVarArgs(adb, "pull", source, target)
- }
- //Push pushes or syncs file
- //goland:noinspection GoUnnecessarilyExportedIdentifiers
- func (adb Adb) Push(source, target string, sync bool) ([]byte, error) {
- sFlag := ""
- if sync {
- sFlag = "--sync"
- }
- return common.ExecWithVarArgs(adb, "push", sFlag, source, target)
- }
- //LogcatClear clears logcat buffer
- //goland:noinspection GoUnnecessarilyExportedIdentifiers
- func (adb Adb) LogcatClear() ([]byte, error) {
- return common.ExecWithVarArgs(adb, "logcat", "-c")
- }
- //LogcatDump dumps logcat buffer
- //goland:noinspection GoUnnecessarilyExportedIdentifiers
- func (adb Adb) LogcatDump() ([]byte, error) {
- return common.ExecWithVarArgs(adb, "logcat", "-d", "-v", "threadtime")
- }
- //LogcatStartToFileAsync starts saving logcat to filePath
- //goland:noinspection GoUnnecessarilyExportedIdentifiers
- func (adb Adb) LogcatStartToFileAsync(filePath string) (*exec.Cmd, error) {
- return common.StartProcessVarArgs(adb, "logcat", "-v", "threadtime", "-f", filePath)
- }
- //LogcatStop interrupts logcat process with timeSleep timeout in seconds
- //goland:noinspection GoUnnecessarilyExportedIdentifiers
- func (adb Adb) LogcatStop(timeSleep time.Duration, process *exec.Cmd) error {
- time.Sleep(timeSleep * time.Second)
- return common.StopProcess(adb, process)
- }
|