feat: 支持安装前后ADB命令与安装后启动应用

按工程保存前后置命令和自动启动选项,全程绑定选中设备,区分安装与后续动作失败。通过实际APK及目标设备解析Launcher入口,兼容activity-alias;增加模拟进程回归测试及0.8.0三套服务部署记录。
This commit is contained in:
tongtong committed 2026-11-27 16:26:03 +08:00
1 parent 6f9cc7e7ea
commit b46ebd1070
18 files changed
+472 -35

No files matched your search

+36 -7
View File
@@ -109,14 +109,27 @@ func (s *Server) serveADB(w http.ResponseWriter, r *http.Request) {
return
}
var req struct {
BuildID string `json:"buildId"`
Artifact string `json:"artifact"`
Serial string `json:"serial"`
BuildID string `json:"buildId"`
Artifact string `json:"artifact"`
Serial string `json:"serial"`
BeforeCommands string `json:"beforeCommands"`
AfterCommands string `json:"afterCommands"`
LaunchAfter bool `json:"launchAfter"`
}
if e := decode(w, r, &req); e != nil {
http.Error(w, e.Error(), 400)
return
}
before, err := parseInstallCommands(req.BeforeCommands)
if err != nil {
http.Error(w, err.Error(), 400)
return
}
after, err := parseInstallCommands(req.AfterCommands)
if err != nil {
http.Error(w, err.Error(), 400)
return
}
if req.Serial == "" || strings.HasPrefix(req.Serial, "-") || strings.ContainsAny(req.Serial, " \t\r\n\x00") {
http.Error(w, "请选择服务端在线且已授权的设备", 400)
return
@@ -143,7 +156,7 @@ func (s *Server) serveADB(w http.ResponseWriter, r *http.Request) {
return
}
defer adbInstallLock.Unlock()
ctx, cancel := context.WithTimeout(r.Context(), 3*time.Minute)
ctx, cancel := context.WithTimeout(r.Context(), 12*time.Minute)
defer cancel()
out, e := s.adbCommand(ctx, "devices", "-l")
if e != nil {
@@ -166,14 +179,30 @@ func (s *Server) serveADB(w http.ResponseWriter, r *http.Request) {
http.Error(w, "服务端APK缺失或摘要校验失败,请重新构建", 409)
return
}
out, e = s.adbCommand(ctx, "-s", req.Serial, "install", "-r", path)
var log strings.Builder
if e = s.runInstallCommands(ctx, req.Serial, "安装前", before, &log); e != nil {
http.Error(w, log.String()+"\n"+e.Error(), 400)
return
}
log.WriteString("[安装APK] adb -s " + req.Serial + " install -r\n")
installCtx, installCancel := context.WithTimeout(ctx, 2*time.Minute)
out, e = s.adbCommand(installCtx, "-s", req.Serial, "install", "-r", path)
installCancel()
log.WriteString(out)
if e != nil {
http.Error(w, e.Error(), 400)
http.Error(w, log.String()+"\n"+e.Error(), 400)
return
}
if !strings.Contains(out, "Success") {
http.Error(w, "ADB未确认安装成功:"+out, 400)
return
}
jsonOut(w, map[string]any{"success": true, "serial": req.Serial, "output": out})
postError := s.runInstallCommands(ctx, req.Serial, "安装后", after, &log)
if postError == nil && req.LaunchAfter {
postError = s.launchInstalledAPK(ctx, req.Serial, path, &log)
}
if postError != nil {
log.WriteString("\n安装已成功,后续操作未完成:" + postError.Error())
}
jsonOut(w, map[string]any{"success": true, "serial": req.Serial, "output": log.String(), "postActionsSuccess": postError == nil})
}