This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 274
/
requirements.go
95 lines (89 loc) · 2.65 KB
/
requirements.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"os"
"regexp"
"runtime"
"strings"
)
func installRequirements() error {
log.Println("install uiautomator apk")
if err := installUiautomatorAPK(); err != nil {
return err
}
return installMinicap()
}
func installUiautomatorAPK() error {
if runtime.GOOS == "windows" {
return nil
}
if checkUiautomatorInstalled() {
return nil
}
baseURL := "https://github.com/openatx/android-uiautomator-server/releases/download/" + apkVersionName
if _, err := httpDownload("/data/local/tmp/app-debug.apk", baseURL+"/app-uiautomator.apk", 0644); err != nil {
return err
}
if _, err := httpDownload("/data/local/tmp/app-debug-test.apk", baseURL+"/app-uiautomator-test.apk", 0644); err != nil {
return err
}
if err := forceInstallAPK("/data/local/tmp/app-debug.apk"); err != nil {
return err
}
if err := forceInstallAPK("/data/local/tmp/app-debug-test.apk"); err != nil {
return err
}
return nil
}
func installMinicap() error {
if runtime.GOOS == "windows" {
return nil
}
log.Println("install minicap")
// if fileExists("/data/local/tmp/minicap") && fileExists("/data/local/tmp/minicap.so") {
// if err := Screenshot("/dev/null"); err != nil {
// log.Println("err:", err)
// } else {
// return nil
// }
// }
// remove first to prevent "text file busy"
os.Remove("/data/local/tmp/minicap")
os.Remove("/data/local/tmp/minicap.so")
minicapSource := "https://github.com/codeskyblue/stf-binaries/raw/master/node_modules/minicap-prebuilt/prebuilt"
propOutput, err := runShell("getprop")
if err != nil {
return err
}
re := regexp.MustCompile(`\[(.*?)\]:\s*\[(.*?)\]`)
matches := re.FindAllStringSubmatch(string(propOutput), -1)
props := make(map[string]string)
for _, m := range matches {
var key = m[1]
var val = m[2]
props[key] = val
}
abi := props["ro.product.cpu.abi"]
sdk := props["ro.build.version.sdk"]
pre := props["ro.build.version.preview_sdk"]
if pre != "" && pre != "0" {
sdk = sdk + pre
}
binURL := strings.Join([]string{minicapSource, abi, "bin", "minicap"}, "/")
_, err = httpDownload("/data/local/tmp/minicap", binURL, 0755)
if err != nil {
return err
}
libURL := strings.Join([]string{minicapSource, abi, "lib", "android-" + sdk, "minicap.so"}, "/")
_, err = httpDownload("/data/local/tmp/minicap.so", libURL, 0644)
if err != nil {
return err
}
return nil
}
func installMinitouch() error {
baseURL := "https://github.com/codeskyblue/stf-binaries/raw/master/node_modules/minitouch-prebuilt/prebuilt"
abi := getCachedProperty("ro.product.cpu.abi")
binURL := strings.Join([]string{baseURL, abi, "bin/minitouch"}, "/")
_, err := httpDownload("/data/local/tmp/minitouch", binURL, 0755)
return err
}