Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ modavd [--root <dir>] [--json] [--quiet] [--verbose] <command> [args]
| `list` | All instances and their status |
| `info <i>` / `status <i>` | Details of one instance / its status |
| `create [--index N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto\|N] [--fps 1-60] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--no-bridge] [--timeout 1200]`, `create --resume N` | Create an instance (automatic data disk by default, see below), then start it once in the background, headless, to finish initialization, and shut it down (see below). The arm64 execution bridge is included by default; `--no-bridge` records that this instance does not want the bridge, so it is not installed on later starts either. New instances never get the Google Play Store; add it afterwards with `playstore <i> install`. `--resume N` redoes the initialization of an instance whose creation failed |
| `set <i> [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--data-gb auto\|N] [--diagnostics on\|off] [--sound on\|off] [--boss-key combination\|none]` | Change settings. Diagnostics and the boss key apply immediately; other settings take effect at the next start. `--data-gb auto` makes the data disk automatic, `--data-gb N` gives it a fixed size (see below); the size can only be increased, and game data is untouched: the emulator (from 0.36) grows the disk image at start and grows the file system online after boot. A disk created before 0.36 at 16 GB or smaller can only be grown to just below the next backup group (a 16 GB disk to about 30 GB). `--sound on` gives this instance sound from its next start (windowed and headless, at some extra CPU); the default `off` boots without a sound card; stored as `instances.<i>.sound` in `mas-avd.json`. `--boss-key` is this instance's boss key (see the ModAVD.exe manager section), for example `Ctrl+Alt+Shift+1`; `none` means no boss key; Windows only. |
| `set <i> [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--data-gb auto\|N] [--diagnostics on\|off] [--sound on\|off] [--app-keepalive on\|off] [--boss-key combination\|none]` | Change settings. Diagnostics and the boss key apply immediately; other settings take effect at the next start. `--data-gb auto` makes the data disk automatic, `--data-gb N` gives it a fixed size (see below); the size can only be increased, and game data is untouched: the emulator (from 0.36) grows the disk image at start and grows the file system online after boot. A disk created before 0.36 at 16 GB or smaller can only be grown to just below the next backup group (a 16 GB disk to about 30 GB). `--sound on` gives this instance sound from its next start (windowed and headless, at some extra CPU); the default `off` boots without a sound card; stored as `instances.<i>.sound` in `mas-avd.json`. `--boss-key` is this instance's boss key (see the ModAVD.exe manager section), for example `Ctrl+Alt+Shift+1`; `none` means no boss key; Windows only. |
| `proxy <i> [on\|off\|test] [--server URL\|auto] [--add PKG] [--remove PKG] [--apps PKG]` | Per-app proxy: the listed apps go through a proxy, the others direct (see below) |
| `delete <i> --yes` | Delete a stopped instance, together with its game data |
| `clone <i> [--title T]` | Copy a stopped instance whole into a new one (games, logins and settings included): the new one takes the smallest free index and its ports, everything else follows the source. The data disk is copied whole, so the two do not affect each other; without enough free space the command fails (`precheck_failed`) and copies nothing, and a failed or canceled copy is deleted. Both have the same Android device IDs (Android ID, GSF ID) |
Expand All @@ -81,6 +81,8 @@ modavd [--root <dir>] [--json] [--quiet] [--verbose] <command> [args]
| `update [status\|check\|prepare\|install\|recover] [--source github\|mirrorchyan] [--cdk-dpapi BASE64] [--automas-version V]` | Update the whole ModAVD package in the root folder, using the update source from "Settings", or the source and CDK the caller passes for this run (see "Updating ModAVD") |
| `servers`, `version`, `mcp`, `help [command]` | |

The instance setting **Keep background apps** takes effect at the next boot. With the default `--app-keepalive off`, ModAVD force-stops a third-party app after 60 continuous seconds away from the foreground. Returning to the app cancels its timer. Home apps, the active keyboard, system apps and Google services are exempt. Set `--app-keepalive on` to leave background apps running. The setting is stored as `instances.<i>.appKeepalive` in `mas-avd.json`. Older instances without the key use `off`. The MCP tool `update_instance` takes the boolean `app_keepalive`.

Apple Silicon macOS supports `report-config` and `collect-info`, including hardware, macOS, HVF, Metal and component versions. Game lists are queried only through an existing private ADB server and running instances with verified ownership; no service is started. The package contains an allowlist of local instance settings and at most eight emulator logs, capped at 2 MiB each and 20 MiB of text in total. Common credential fields, paths and device identifiers are filtered. macOS does not collect screenshots, system dumps or other applications' logs. Review the package before sharing it. Clipboard copying and Finder reveal can be disabled with `--no-clipboard` and `--no-explorer`.

- Write `<i>` as `3` or `mas_3` (0-9, except 5). Memory is written as `6144`, `6144M` or `6G`, with only five tiers: 3 / 4 / 5 / 6 / 8 GB. Cores are 2 / 4 / 6, and the frame rate is any whole number from 1 to 60 (default 60).
Expand Down Expand Up @@ -401,6 +403,8 @@ Tests run on Windows only. Optional environment variables:

The native regional check is `python scripts/test_regional_guest.py --root <this-checkout/out/fresh-test-root> --legacy-cli <old-cli> --lock <shared-acceptance-lock>`. Copy an independent SDK into the test root and explicitly set `portBase: 34100`, `adbServerPort: 34198`, `scriptAdbServerPort: 34199`, and `shareDefaultAdbServer: false`. The runner validates these conditions. The test holds an exclusive handle through normal shutdown and cleanup. English-host inputs and host time-zone changes are injected; they do not replace acceptance on two real Windows display-language environments.

To check background app timers, push `scripts/test_app_keepalive_guest.sh` to an Android 14 test instance. In its shell, run `sh test_app_keepalive_guest.sh /data/local/tmp/modavd-app-keepalive.sh` from the directory containing the test script. The check takes about 70 seconds and simulates app switches and a failed foreground query to verify retry and cancellation.

The 4 KiB guest helper in `internal/guest/regional/Regional.java` includes its compiled DEX. Normal builds need neither Java nor an Android SDK. After changing the helper, rebuild and compare its bytes using a local JDK and the pinned D8: `python internal/guest/regional/generate.py --r8 <r8-8.3.37.jar> --check`. The script records the download URL and SHA-256. Regenerate the CLDR table with `python internal/regional/generate.py <windowsZones.xml>` using the pinned input.

## Standalone download and hashes
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ modavd [--root <目录>] [--json] [--quiet] [--verbose] <命令> [参数]
| `list` | 全部实例和状态 |
| `info <i>` / `status <i>` | 一台实例的详细信息 / 状态 |
| `create [--index N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto\|N] [--fps 1-60] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--no-bridge] [--timeout 1200]`、`create --resume N` | 新建(数据盘默认自动扩盘,见下),并在后台无头开机一次把初始化做完再关机(见下)。默认带 arm64 执行桥;`--no-bridge` 记下这台不要桥,以后开机也不装。新建的实例不带 Google Play 商店,要的话建好后用 `playstore <i> install`。`--resume N` 重做新建失败的那台的初始化 |
| `set <i> [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--data-gb auto\|N] [--diagnostics on\|off] [--sound on\|off] [--boss-key 组合\|none]` | 修改;诊断模式和老板键立即生效,其余设置下次开机生效。`--data-gb auto` 改成自动扩盘,`--data-gb N` 改成指定大小(见下);大小只能改大,游戏数据不动:模拟器(0.36 起)开机时扩磁盘镜像,开机后在线扩文件系统。0.36 之前按 16 GB 及以下建的盘只能扩到下一个备份组之前(16 GB 约到 30 GB)。`--sound on` 让这台下次开机起有声音(带窗口和无头都是,会多占一些 CPU),默认 `off` 不带声卡;记在 `mas-avd.json` 的 `instances.<i>.sound`。`--boss-key` 是这台的老板键(见「管理器 ModAVD.exe」一节),比如 `Ctrl+Alt+Shift+1`,`none` 是不要,只有 Windows。 |
| `set <i> [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--data-gb auto\|N] [--diagnostics on\|off] [--sound on\|off] [--app-keepalive on\|off] [--boss-key 组合\|none]` | 修改;诊断模式和老板键立即生效,其余设置下次开机生效。`--data-gb auto` 改成自动扩盘,`--data-gb N` 改成指定大小(见下);大小只能改大,游戏数据不动:模拟器(0.36 起)开机时扩磁盘镜像,开机后在线扩文件系统。0.36 之前按 16 GB 及以下建的盘只能扩到下一个备份组之前(16 GB 约到 30 GB)。`--sound on` 让这台下次开机起有声音(带窗口和无头都是,会多占一些 CPU),默认 `off` 不带声卡;记在 `mas-avd.json` 的 `instances.<i>.sound`。`--boss-key` 是这台的老板键(见「管理器 ModAVD.exe」一节),比如 `Ctrl+Alt+Shift+1`,`none` 是不要,只有 Windows。 |
| `proxy <i> [on\|off\|test] [--server URL\|auto] [--add 包名] [--remove 包名] [--apps 包名]` | 按应用走代理:名单里的应用走代理,其余直连(见下) |
| `delete <i> --yes` | 删除已关机的实例,连同游戏数据 |
| `clone <i> [--title T]` | 把已关机的实例整份复制成一台新实例(游戏、登录状态、设置都带上):新实例用最小的空闲编号和它的端口,其余设置照源实例;数据盘整份复制,两台互不影响,可用空间不够时报错(`precheck_failed`)、什么都不复制;失败或取消时复制到一半的会删掉。两台的安卓设备标识(Android ID、GSF ID)相同 |
Expand All @@ -83,6 +83,8 @@ modavd [--root <目录>] [--json] [--quiet] [--verbose] <命令> [参数]
| `update [status\|check\|prepare\|install\|recover] [--source github\|mirrorchyan] [--cdk-dpapi BASE64] [--automas-version V]` | 更新根目录里的整个 ModAVD 包,按「设置」里的更新源,或调用方这次传的更新源和 CDK(见「更新 ModAVD」) |
| `servers`、`version`、`mcp`、`help [命令]` | |

实例设置里的「应用保活」下次开机生效。默认 `--app-keepalive off`,第三方应用连续离开前台满 60 秒后由 ModAVD 结束,中途切回就取消计时。桌面、当前输入法、系统包和谷歌服务豁免。`--app-keepalive on` 保留后台应用。设置记在 `mas-avd.json` 的 `instances.<i>.appKeepalive`,旧实例没有这个字段时按关闭处理。MCP 的 `update_instance` 接受布尔参数 `app_keepalive`。

Apple Silicon macOS 支持 `report-config` 和 `collect-info`:读取硬件、macOS、HVF、Metal 和组件版本;游戏列表只向归属已确认的运行实例与现有私有 ADB 查询,不启动服务。问题包只收本目录的实例配置白名单和最多 8 份模拟器日志,每份最多 2 MiB、总文本最多 20 MiB,过滤常见凭据字段、路径和设备标识。macOS 不收截图、系统转储或其他应用日志;分享前请检查问题包。默认复制配置到剪贴板、用 Finder 显示问题包,自动化可用 `--no-clipboard` / `--no-explorer`。

- `<i>` 写成 `3` 或 `mas_3`(0–9,5 除外);内存写成 `6144`、`6144M` 或 `6G`,只有 3 / 4 / 5 / 6 / 8 GB 五档,核数 2 / 4 / 6,帧率 1–60 的整数(默认 60)。
Expand Down Expand Up @@ -404,6 +406,8 @@ go test ./...

语言/时区的真实客体验收用 `python scripts/test_regional_guest.py --root <本工作树/out/全新测试根> --legacy-cli <旧版命令行> --lock <共享验收锁文件>`。测试根须复制独立 SDK,并明确设置 `portBase: 34100`、`adbServerPort: 34198`、`scriptAdbServerPort: 34199`、`shareDefaultAdbServer: false`。脚本验证这些条件;测试持有独占句柄直到正常关机和清理完成。英文宿主及宿主时区变化采用注入输入,不代替两种真实 Windows 的验收。

在 Android 14 测试实例的 shell 里运行 `sh test_app_keepalive_guest.sh /data/local/tmp/modavd-app-keepalive.sh` 可复测后台应用计时。先将 `scripts/test_app_keepalive_guest.sh` 推到测试实例。脚本用模拟的应用切换和前台查询失败事件验证超时重试、切回取消,约需 70 秒。

`internal/guest/regional/Regional.java` 的 4 KiB 客体助手随源码附带 DEX。普通构建不用 Java 或 Android SDK;修改助手后,用本地 JDK 和指定 D8 重建,并核对字节:`python internal/guest/regional/generate.py --r8 <r8-8.3.37.jar> --check`。脚本记录下载地址和 SHA-256。CLDR 表用 `python internal/regional/generate.py <windowsZones.xml>` 从固定版本重建。

## 单独下载与哈希
Expand Down
17 changes: 13 additions & 4 deletions internal/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var (
optLanguage = flagSpec{"language", kindString, "host|preserve|语言", "Windows:host 按宿主界面语言设置一次,preserve 保持安卓语言,或指定 zh-CN、en-US 等语言"}
optTimeZone = flagSpec{"timezone", kindString, "host|preserve|IANA", "Windows:host 每次冷启动跟随宿主,preserve 沿用原行为,或指定 Asia/Shanghai、Etc/UTC 等 IANA 时区"}
optDiagnostics = flagSpec{"diagnostics", kindString, "on|off", "诊断模式:即时增加日志保留;off 立即删回平常规则"}
optAppKeepalive = flagSpec{"app-keepalive", kindString, "on|off", "应用保活:默认 off,第三方应用连续在后台满 60 秒后结束;on 保留后台应用。下次开机生效。"}
optSound = flagSpec{"sound", kindString, "on|off", "声音:on 下次开机起带声卡、电脑出声(会多占一些 CPU),off 照旧不带(默认)"}
optBossKey = flagSpec{"boss-key", kindString, "组合", "老板键,比如 Ctrl+Alt+Shift+1(Ctrl、Alt、Shift 至少带一个,不收 Win);none 是不要(只有 Windows)"}
optYes = flagSpec{"yes", kindBool, "", "确认删除(连同游戏数据)"}
Expand Down Expand Up @@ -218,14 +219,14 @@ func init() {
run: runCreate, human: humanCreate, exit: exitBatch,
},
{
name: "set", args: "<i> [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080|720] [--dpi auto|N] [--orientation landscape|portrait] [--data-gb auto|N] [--language host|preserve|语言] [--timezone host|preserve|IANA] [--diagnostics on|off] [--sound on|off] [--boss-key 组合|none]",
name: "set", args: "<i> [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080|720] [--dpi auto|N] [--orientation landscape|portrait] [--data-gb auto|N] [--language host|preserve|语言] [--timezone host|preserve|IANA] [--diagnostics on|off] [--sound on|off] [--app-keepalive on|off] [--boss-key 组合|none]",
summary: "修改实例设置、诊断模式和老板键",
details: "至少给一个选项。诊断模式和老板键立即生效;其它改动下次开机生效。诊断模式最多多用约 4 GiB 磁盘和 48 MiB 客体内存,日志可能含账号信息,只存本机;关闭立即删回平常保留规则。" +
dataDiskHelp + "数据盘只能改大,游戏数据不动:下次开机时模拟器(0.36 起)扩大磁盘镜像,开机后再在线扩大文件系统。" +
"--sound on 让这台下次开机起有声音(带窗口和无头都是),会多占一些 CPU;默认 off。" +
"--boss-key 是这台的老板键:管理器开着时(窗口关了、留在托盘也算),按一下藏起这台带窗口运行的模拟器窗口,再按一下叫回来;" +
"几台设成同一个键就一起藏、一起显示。没设过时编号 0–9 默认 Ctrl+Alt+Shift+编号,超过 9 没有;none 是不要。立即生效,只有 Windows。",
flags: []flagSpec{optTitle, optMemory, optCPU, optFPS, optResolution, optDPI, optOrientation, optDataGB, optLanguage, optTimeZone, optDiagnostics, optSound, optBossKey},
flags: []flagSpec{optTitle, optMemory, optCPU, optFPS, optResolution, optDPI, optOrientation, optDataGB, optLanguage, optTimeZone, optDiagnostics, optSound, optAppKeepalive, optBossKey},
posNames: []string{"实例编号"}, minPos: 1, maxPos: 1,
final: true,
run: runSet, human: humanOf(formatUpdate),
Expand Down Expand Up @@ -695,13 +696,21 @@ func buildUpdateRequest(inv *invocation) (emu.UpdateRequest, error) {
on := value == "on"
req.Sound = &on
}
if inv.isSet("app-keepalive") {
value := strings.ToLower(inv.strOpt("app-keepalive"))
if value != "on" && value != "off" {
return req, errs.New(errs.InvalidArgument, "--app-keepalive 只能是 on 或 off")
}
on := value == "on"
req.AppKeepalive = &on
}
if inv.isSet("boss-key") {
k := inv.strOpt("boss-key")
req.BossKey = &k
}
if req.Title == nil && req.MemoryMB == nil && req.CPU == nil && req.FPS == nil && req.Resolution == nil && req.DPI == nil && req.Orientation == nil && req.DataPartitionGB == nil &&
!req.DataDiskAuto && req.Diagnostics == nil && req.Sound == nil && req.BossKey == nil && req.Language == nil && req.TimeZone == nil {
return req, errs.New(errs.Usage, "没有要改的内容:至少给 --title、--memory、--cpu、--fps、--resolution、--dpi、--orientation、--data-gb、--language、--timezone、--diagnostics、--sound、--boss-key 中的一个").
!req.DataDiskAuto && req.Diagnostics == nil && req.Sound == nil && req.AppKeepalive == nil && req.BossKey == nil && req.Language == nil && req.TimeZone == nil {
return req, errs.New(errs.Usage, "没有要改的内容:至少给 --title、--memory、--cpu、--fps、--resolution、--dpi、--orientation、--data-gb、--language、--timezone、--diagnostics、--sound、--app-keepalive、--boss-key 中的一个").
WithAdvice(findCommand("set").usageAdvice())
}
return req, nil
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func formatInfo(w io.Writer, in *emu.InstanceInfo) {
kv("核数", intOrDash(cfg.CPU))
kv("帧率", intOrDash(cfg.FPS))
kv("声音", onOff(cfg.Sound))
kv("应用保活", onOff(cfg.AppKeepalive))
kv("数据盘", dataDiskText(cfg)+","+dataSpaceSummary(in.DataSpace))
if in.DataSpace.Message != "" {
kv("数据盘提示", dataSpaceNote(in.DataSpace))
Expand Down Expand Up @@ -444,6 +445,9 @@ func appliedParts(applied map[string]any) []string {
} else {
parts = append(parts, "诊断模式 关")
}
case "app_keepalive":
on, _ := v.(bool)
parts = append(parts, "应用保活 "+onOff(on))
case "sound":
on, _ := v.(bool)
parts = append(parts, "声音 "+onOff(on))
Expand Down
7 changes: 7 additions & 0 deletions internal/emu/afterboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ func (m *Manager) afterBoot(ctx context.Context, inst *avd.Instance, mode bootSe
m.ensurePixelLauncherRemoved(ctx, i)
}
},
func() {
// Changing the switch while running takes effect after reboot. Adopting an
// already configured boot must keep the current watcher and its timers.
if mode != setupAdopted {
m.setupAppKeepalive(ctx, i)
}
},
// 10) orientation: the display stays landscape (persistent; set every boot so old instances get it)
func() { m.setupOrientation(ctx, i) },
// 10b) hand the clusters the guest freed back to the host, at most once a day (best effort, see autotrim.go)
Expand Down
Loading
Loading