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

Commit 98675a1

Browse files
committed
fix minitouch not working on HUAWEI and realme device error
1 parent a288b73 commit 98675a1

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ replace (
5757
github.com/qiniu/log v0.0.0-20140728010919-a304a74568d6 => github.com/gobuild/log v1.0.0
5858
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a => github.com/golang/net v0.0.0-20181114220301-adae6a3d119a
5959
)
60+
61+
go 1.13

httpserver.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -895,43 +895,43 @@ func (server *Server) initHTTPServer() {
895895
wsWrite(websocket.TextMessage, []byte("@minitouch service start failed: "+err.Error()))
896896
return
897897
}
898-
unixSocketName := "@minitouchagent"
899-
wsWrite(websocket.TextMessage, []byte("dial unix:"+unixSocketName))
898+
unixSocketPath := minitouchSocketPath
899+
wsWrite(websocket.TextMessage, []byte("dial unix:"+unixSocketPath))
900900
log.Printf("minitouch connection: %v", r.RemoteAddr)
901901
retries := 0
902902
quitC := make(chan bool, 2)
903903
operC := make(chan TouchRequest, 10)
904904
defer func() {
905-
wsWrite(websocket.TextMessage, []byte(unixSocketName+" websocket closed"))
905+
wsWrite(websocket.TextMessage, []byte(unixSocketPath+" websocket closed"))
906906
close(operC)
907907
}()
908908
go func() {
909909
for {
910910
if retries > 10 {
911-
log.Printf("unix %s connect failed", unixSocketName)
912-
wsWrite(websocket.TextMessage, []byte(unixSocketName+" listen timeout, possibly minitouch not installed"))
911+
log.Printf("unix %s connect failed", unixSocketPath)
912+
wsWrite(websocket.TextMessage, []byte(unixSocketPath+" listen timeout, possibly minitouch not installed"))
913913
ws.Close()
914914
break
915915
}
916-
conn, err := net.Dial("unix", unixSocketName)
916+
conn, err := net.Dial("unix", unixSocketPath)
917917
if err != nil {
918918
retries++
919-
log.Printf("dial %s error: %v, wait 0.5s", unixSocketName, err)
919+
log.Printf("dial %s error: %v, wait 0.5s", unixSocketPath, err)
920920
select {
921921
case <-quitC:
922922
return
923923
case <-time.After(500 * time.Millisecond):
924924
}
925925
continue
926926
}
927-
log.Printf("unix %s connected, accepting requests", unixSocketName)
927+
log.Printf("unix %s connected, accepting requests", unixSocketPath)
928928
retries = 0 // connected, reset retries
929929
err = drainTouchRequests(conn, operC)
930930
conn.Close()
931931
if err != nil {
932932
log.Println("drain touch requests err:", err)
933933
} else {
934-
log.Printf("unix %s disconnected", unixSocketName)
934+
log.Printf("unix %s disconnected", unixSocketPath)
935935
break // operC closed
936936
}
937937
}

main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,15 @@ func main() {
576576

577577
service.Add("minitouch", cmdctrl.CommandInfo{
578578
ArgsFunc: func() ([]string, error) {
579+
sdk, err := strconv.Atoi(getCachedProperty("ro.build.version.sdk"))
580+
if err != nil || sdk <= 28 { // Android P(sdk:28)
581+
minitouchSocketPath = "@minitouch"
582+
return []string{"/data/local/tmp/minitouch"}, nil
583+
}
584+
minitouchSocketPath = "@minitouchagent"
579585
pmPathOutput, err := Command{
580-
Args: []string{"pm", "path", "com.github.uiautomator"},
586+
Args: []string{"pm", "path", "com.github.uiautomator"},
587+
Shell: true,
581588
}.CombinedOutputString()
582589
if err != nil {
583590
return nil, err
@@ -587,7 +594,6 @@ func main() {
587594
}
588595
packagePath := strings.TrimSpace(pmPathOutput[len("package:"):])
589596
return []string{"CLASSPATH=" + packagePath, "exec", "app_process", "/system/bin", "com.github.uiautomator.MinitouchAgent"}, nil
590-
// return []string{"/data/local/tmp/minitouch"}, nil
591597
},
592598
Shell: true,
593599
})

minitouch.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/qiniu/log"
1212
)
1313

14+
var minitouchSocketPath = "@minitouch"
15+
1416
type toucher struct {
1517
width, height int
1618
rotation int

0 commit comments

Comments
 (0)