Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Do not install requirements by default
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Oct 18, 2017
1 parent 1fc367d commit 8066792
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
*_vfsdata.go
atx-agent
*.tmp/
*.exe.old
*.exe.old
*.apk
49 changes: 12 additions & 37 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func getProperty(name string) string {
}

func installRequirements() error {
log.Println("install uiautomator apk")
if err := installUiautomatorAPK(); err != nil {
return err
}
return installMinicap()
}

Expand Down Expand Up @@ -206,10 +210,6 @@ func installMinicap() error {
if runtime.GOOS == "windows" {
return nil
}
log.Println("install uiautomator apk")
if err := installUiautomatorAPK(); err != nil {
return err
}
log.Println("install minicap")
if fileExists("/data/local/tmp/minicap") && fileExists("/data/local/tmp/minicap.so") {
if err := Screenshot("/dev/null"); err != nil {
Expand Down Expand Up @@ -270,35 +270,6 @@ func Screenshot(filename string) (err error) {
return nil
}

func safeRunUiautomator() {
if runtime.GOOS == "windows" {
return
}
retry := 5
for retry > 0 {
retry--
start := time.Now()
if err := runUiautomator(); err != nil {
log.Printf("uiautomator quit: %v", err)
}
if time.Since(start) > 3*time.Minute {
retry = 5
}
time.Sleep(2 * time.Second)
}
log.Println("uiautomator can not started")
}

func runUiautomator() error {
c := exec.Command("am", "instrument", "-w", "-r",
"-e", "debug", "false",
"-e", "class", "com.github.uiautomator.stub.Stub",
"com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner")
c.Stdout = os.Stdout
c.Stderr = os.Stderr
return c.Run()
}

type DownloadManager struct {
db map[string]*DownloadProxy
mu sync.Mutex
Expand Down Expand Up @@ -600,6 +571,7 @@ func main() {
fDaemon := flag.Bool("d", false, "run daemon")
flag.IntVar(&listenPort, "p", 7912, "listen port") // Create on 2017/09/12
fVersion := flag.Bool("v", false, "show version")
fRequirements := flag.Bool("r", false, "install minicap and uiautomator.apk")
fStop := flag.Bool("stop", false, "stop server")
fTunnelServer := flag.String("t", "", "tunnel server address")
flag.Parse()
Expand All @@ -621,10 +593,13 @@ func main() {
return
}

log.Println("check dependencies")
if err := installRequirements(); err != nil {
// panic(err)
log.Println("requirements not ready:", err)
if *fRequirements {
log.Println("check dependencies")
if err := installRequirements(); err != nil {
// panic(err)
log.Println("requirements not ready:", err)
return
}
}

if *fDaemon && os.Getenv("ATX_AGENT") == "" {
Expand Down
38 changes: 38 additions & 0 deletions uiautomator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"log"
"os"
"os/exec"
"runtime"
"time"
)

func safeRunUiautomator() {
if runtime.GOOS == "windows" {
return
}
retry := 5
for retry > 0 {
retry--
start := time.Now()
if err := runUiautomator(); err != nil {
log.Printf("uiautomator quit: %v", err)
}
if time.Since(start) > 1*time.Minute {
retry = 5
}
time.Sleep(2 * time.Second)
}
log.Println("uiautomator can not started")
}

func runUiautomator() error {
c := exec.Command("am", "instrument", "-w", "-r",
"-e", "debug", "false",
"-e", "class", "com.github.uiautomator.stub.Stub",
"com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner")
c.Stdout = os.Stdout
c.Stderr = os.Stderr
return c.Run()
}

0 comments on commit 8066792

Please sign in to comment.