Repository navigation
开机可带应用包名,开完机自动打开这个应用 - #215
Merged
Merged
Conversation
modavd start <i> --launch <包名>[/<Activity>]、MCP start_instance 的 launch、
ModAVD.exe --start <i> [--launch <包名>] 三处入口,由 emu.Manager.Start 在开机和
开机后的设置做完以后打开应用,并等它到前台(最多 30 秒)。
- 包名、Activity 开机前严格校验(Java 标识符字符和点),不合格直接报
invalid_argument、不开机;客体命令里不做转义拼接,只带校验过的名字,
客体打印出来的启动入口也同样校验后才用。
- 没装、没有启动入口、am start 报错、没到前台都不算开机失败:实例照常开着,
结果里 app 写明 ok、code(app_not_installed 3、timeout 6、app_launch_failed 7)、
message、advice,命令行的退出码是这个错误的退出码,信封里的 ok 仍是 true。
- 管理器:POST /api/instances/{i}/start 加可选的 launch;ModAVD.exe --start
在这个根目录的管理器已经运行时,把请求转给它(和更新交接同一套本机地址、
cookie、不跟随重定向的办法),没运行就起服务后开机。参数错误照现有规矩输出。
Refs ModAVD/ModAVD#289
- am start 的错误只认诊断行(Error:、Error type、Exception occurred、
SecurityException、Permission Denial),Activity 名里带 Exception 也能成功。
- POST /api/instances/{i}/start 显式给 "launch":"" 是 400、不建任务(和命令行、
MCP 一致),不给或 null 照旧不打开应用。
- 前台轮询整体用同一个 30 秒截止的 context,每次 adb 探测都带它;截止或取消以后
拿到的成功不算,卡住的 adb 也随截止结束。
- ModAVD.exe --start 没被受理(更新交接中、任务未获准、包名不对)时,Run 返回
StartRefusedError,管理器不再空跑,ModAVD.exe 按启动错误输出并以 1 退出;
已受理但应用没打开仍只在任务结果的 app 里,和未受理分开。
Refs ModAVD/ModAVD#289
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs ModAVD/ModAVD#289
做了什么
开机时可以带一个应用包名,实例准备好以后自动把这个应用打开(桌面快捷方式、脚本里「开机并直接进游戏」)。
modavd start <i> [--window|--headless] --launch <包名>[/<Activity>]start_instance加可选参数launch,含义相同ModAVD.exe --start <i> [--launch <包名>[/<Activity>]]三处都走
emu.StartOptions.Launch,由emu.Manager.Start在「开机 + 开机后的设置」做完以后打开应用,所以行为一致;「准备好」就是Start返回的时刻,和正在改的开机遮罩 / 在线判定(ModAVD#259)互不依赖:应用在Start返回、遮罩撤掉以后才打开。打开应用(
internal/emu/launchapp.go).Main或完整类名),不支持带$的内部类。开机之前校验,不合格直接invalid_argument(退出码 2),不开机。pm path <包名>查装没装(精确匹配)。cmd package resolve-activity --brief -a android.intent.action.MAIN -c android.intent.category.LAUNCHER <包名>取最后一行;这行是客体打印的,同样校验、且必须属于这个包才用。给了 Activity 就不查。am start -n <包名/Activity>,看输出里有没有Error/Exception/Permission Denial或非 0 退出码。topResumedActivity探测),等它的包名等于目标,最多 30 秒;每 0.5 秒一次。失败不算开机失败
没装、没有启动入口、
am start报错、30 秒没到前台,实例都照常开着。start的结果里多一个app:{package, component, ok, seconds, code?, message?, advice?}(中英提示);--json的信封ok仍是true(和stop --all有失败时一样),退出码取这个错误的:app.codeapp_not_installedtimeoutapp_launch_failedam start报错cancelederrs里加了app_not_installed、app_launch_failed两个码(退出码并入 3、7)。MCP 里这不算工具错误,结果的app说明情况;管理器里不算任务失败,任务的警告里也写一条。已经开着的实例:照
start原来的接管办法(给了--window/--headless而方式不对仍报busy),做完每次开机都做的设置后打开应用。管理器(GUI)怎么转发
ModAVD.exe --start <i> [--launch ...]先在parseArgs里检查(编号 0–9 除 5、包名格式),不对就照现有--help/ 参数错误的规矩输出(重定向了写流,终端写终端,都没有才弹框),退出码 2,不碰根目录、不碰正在运行的管理器、不开机。--launch必须和--start一起。ui.Options.Start,服务监听以后立刻起和页面「开机」按钮同一个任务(带窗口),再按--no-window决定开不开管理器窗口。POST /api/instances/{i}/start {"launch":...}转给正在运行的那个,由它开机、打开应用;和更新交接共用同一个postManager(只认状态文件里的本机地址、带 cookie 和 Origin、不走代理、不跟随重定向,响应体最多 64 KiB)。管理器拒绝(比如这台实例上已有任务、无头运行中)把它的提示按启动错误输出,退出码 1。POST /api/instances/{i}/start加可选字段launch,格式不对 400invalid_argument、不建任务;API.md/API.en.md已同步。app里看(快捷方式没有退出码可看)。单测
internal/emu/launchapp_test.go:包名 / Activity 解析(带 Activity、非法字符、;&&|`$()引号换行、超长、非 ASCII、-n开头等);用假客体测解析启动入口、给定 Activity 不查入口、已在前台、没装(三种输出)、pm不通、没有启动入口(含错包 /$/;的客体输出被拒)、am start报错、30 秒没到前台(假时钟)、取消、客体命令里没有 shell 特殊字符;Start在开机之后才打开(刚开机 / 本来就开着两条路径)、没装不影响开机成功、坏名字开机前就拒绝且不开机、开机失败没有app。internal/cli/start_launch_test.go:--launch到Start(刚开机 / 已开着)、一批非法值开机前 usage 错误且不调Start、没装时--json信封ok:true+app+ 退出码 3 与人类可读输出、四个退出码、英文输出、帮助里有说明。internal/mcp/start_launch_test.go:入参 schema、app过输出 schema、非法值不开机。internal/ui/start_launch_test.go:接口的launch(含非法名 400、类型错、多余字段)、Options.Start。cmd/modavd-gui/start_test.go、start_reopen_test.go:参数解析和校验、--help列出新选项、forwardStart对假的管理器(路径、cookie、Origin、请求体、202、409/400/401 的提示、只认本机地址、不跟随重定向)、reopen把请求转给正在运行的管理器 / 被拒绝时按启动错误处理。E:\testbed。go vet ./...、go test ./...、gofmt -l .都通过,GOOS=darwin GOARCH=arm64、GOOS=linux GOARCH=amd64的go vet ./...通过;没改页面脚本,不跑 node 测试。实机测试
用这个分支编的
modavd.exe/ModAVD.exe(--root指向测试根,实例 4 GB、720p,已装明日方舟和 1999),全部用 CIM 脱离启动;管理器用临时端口和--no-window。命令行:
start 1 --window --launch com.hypergryph.arknights.../com.u8.sdk.U8UnityContext用 0.8 秒,退出码 0;45 秒后截图是明日方舟标题页start 1 --launch <1999 包名>launched:false,打开 1999 用 0.8 秒,退出码 0,前台确认是 1999ok:true、app.code=app_not_installed,实例仍online;不带--json也是 3app_launch_failed,message 里是am start的Error type 3--launch com.x;reboot管理器(
ModAVD.exe):--no-window --start 1 --launch <1999>done,app.ok,前台是 1999--no-window --start 1 --launch com.hypergryph.arknightslaunched:false、app.ok),前台变成明日方舟done,app.code=app_not_installed,任务警告里有说明--start 1 --launch com.x;reboot--help退出码 0测的时候还有一个
ModAVD.exe进程,是第一个管理器拉起模拟器用的__spawn辅助进程,不是第二个管理器。不做
start --launch对已开着的实例就是打开应用)。$的内部类 Activity 不支持:宿主不做 shell 转义,直接拒绝。