From b2c8e2c4fd73a7fe699bbb1fb20f09baea342a51 Mon Sep 17 00:00:00 2001 From: qiyinxi Date: Sat, 21 Nov 2026 19:10:34 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E4=BE=8B=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=8A=A0=20DPI=20=E5=92=8C=E6=A8=AA=E7=AB=96=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DPI:默认跟随分辨率(720p 240、1080p 280),可选 160 / 240 / 280 / 320 / 400 / 480, 记在 mas-avd.json 的 instances..dpi,每次开机前写进 hw.lcd.density,换分辨率时保留。 - 方向:横屏(默认)/ 竖屏。写 config.ini 的 hw.initialOrientation,画布仍是横的; 开机后 user_rotation 横屏 0、竖屏 3,和模拟器(ModAVD/ModAVD#225 的修复)一致。 - 管理器新建和设置、modavd create / set 的 --dpi / --orientation、HTTP API、MCP 都加上; 中英文案、API.md、README 同步。 Refs ModAVD/ModAVD#247 --- README.en.md | 8 +- README.md | 8 +- changelog.d/247-dpi-orientation.feat.md | 1 + internal/avd/avd.go | 174 +++++++++++++++++++++--- internal/avd/avd_test.go | 8 +- internal/avd/resolution_test.go | 86 +++++++++++- internal/cli/args_test.go | 15 ++ internal/cli/commands.go | 50 ++++++- internal/cli/format.go | 14 +- internal/emu/afterboot.go | 28 +++- internal/emu/crud.go | 22 ++- internal/emu/launch.go | 4 +- internal/emu/ops_root_test.go | 22 ++- internal/emu/status.go | 4 +- internal/emu/types.go | 13 +- internal/i18n/locales/en/avd.json | 2 + internal/i18n/locales/en/cli.json | 12 +- internal/i18n/locales/en/emu.json | 6 +- internal/i18n/locales/en/mcp.json | 2 +- internal/i18n/locales/en/ui.json | 2 +- internal/i18n/locales/en/web.json | 10 +- internal/mcp/mcp_test.go | 10 +- internal/mcp/tools.go | 34 ++++- internal/ui/API.en.md | 6 +- internal/ui/API.md | 6 +- internal/ui/handlers.go | 16 ++- internal/ui/http_test.go | 8 +- internal/ui/web/dev/mock.js | 17 ++- internal/ui/web/js/forms.js | 19 ++- scripts/test_resolution_guards.py | 8 +- 30 files changed, 523 insertions(+), 92 deletions(-) create mode 100644 changelog.d/247-dpi-orientation.feat.md diff --git a/README.en.md b/README.en.md index 982c250e..71348d3e 100644 --- a/README.en.md +++ b/README.en.md @@ -62,8 +62,8 @@ modavd [--root ] [--json] [--quiet] [--verbose] [args] | --- | --- | | `list` | All instances and their status | | `info ` / `status ` | 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] [--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 install`. `--resume N` redoes the initialization of an instance whose creation failed | -| `set [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080\|720] [--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..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. | +| `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 install`. `--resume N` redoes the initialization of an instance whose creation failed | +| `set [--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..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 [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 --yes` | Delete a stopped instance, together with its game data | | `clone [--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) | @@ -208,7 +208,9 @@ On Apple Silicon macOS, downloads and imports use Android 15 Google Play `arm64- - Honkai: Star Rail (official `com.miHoYo.hkrpg` and bilibili `com.miHoYo.hkrpg.bilibili`, not tested on the latter) gets its display mode set to Vulkan in advance (guest script `modavd-vkmode.sh`, Windows only). At its first start the game picks OpenGL ES on its own and closes on ModAVD about fifteen seconds later; in Vulkan mode (Normal Mode under Settings > Graphics > Display Settings in the game) it runs. - A watcher looks every 3 seconds: once the game is installed, before its first start, it writes `vulkancaps.bin` and `customvulkancaps.bin` in the game's `Android/data//files`. A game already stuck in OpenGL ES after such a crash is switched to Vulkan as well, at the next boot or once it has exited. - A display mode chosen in the game's settings (`customvulkancaps.bin` is there and not empty) is left alone; so is a running game; no folder is made for a game that is not installed. -Two display presets are available: 1080p is 1920×1080 / DPI 280; 720p is 1280×720 / DPI 240. New instances default to 1080p. 720p uses fewer resources. The manager forms, CLI `--resolution 1080|720` and MCP `resolution` share these presets. Existing landscape or portrait 1920×1080 instances stay at 1080p; other configurations, including missing dimensions, stay at 720p. Changing the preset updates width, height and DPI together, preserves orientation, and takes effect at the next cold boot. DPI is not a separate option. No runtime `wm size` or `wm density` is used. Update the resolution in your automation tool as well. +Two display presets are available: 1080p is 1920×1080 / DPI 280; 720p is 1280×720 / DPI 240. New instances default to 1080p. 720p uses fewer resources. The manager forms, CLI `--resolution 1080|720` and MCP `resolution` share these presets. Existing landscape or portrait 1920×1080 instances stay at 1080p; other configurations, including missing dimensions, stay at 720p. Changing the preset updates width, height and the default DPI together, preserves orientation, and takes effect at the next cold boot. No runtime `wm size` or `wm density` is used. Update the resolution in your automation tool as well. + +DPI follows the resolution by default; the manager settings, CLI `--dpi` and MCP `dpi` can set 160 / 240 / 280 / 320 / 400 / 480 instead (`--dpi auto` follows again), kept across resolution changes. The orientation is landscape by default and can be portrait (`--orientation portrait`): the canvas stays wide, config.ini's `hw.initialOrientation` is set to portrait and Android turns to portrait after boot. Both take effect at the next boot. Automation such as MAA needs landscape; portrait is for playing yourself. AUTO-MAS currently prefers the packaged CLI, which preserves the selected preset. Old roots without a usable CLI fall back to the Python launch path, which still forces 720p. Update the packaged CLI before using 1080p there. AUTO-MAS creation and display settings still need matching two-preset support; use the ModAVD manager to set the preset meanwhile. diff --git a/README.md b/README.md index b351eb34..1c50e4f4 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,8 @@ modavd [--root <目录>] [--json] [--quiet] [--verbose] <命令> [参数] | --- | --- | | `list` | 全部实例和状态 | | `info ` / `status ` | 一台实例的详细信息 / 状态 | -| `create [--index N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto\|N] [--fps 1-60] [--resolution 1080\|720] [--no-bridge] [--timeout 1200]`、`create --resume N` | 新建(数据盘默认自动扩盘,见下),并在后台无头开机一次把初始化做完再关机(见下)。默认带 arm64 执行桥;`--no-bridge` 记下这台不要桥,以后开机也不装。新建的实例不带 Google Play 商店,要的话建好后用 `playstore install`。`--resume N` 重做新建失败的那台的初始化 | -| `set [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080\|720] [--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..sound`。`--boss-key` 是这台的老板键(见「管理器 ModAVD.exe」一节),比如 `Ctrl+Alt+Shift+1`,`none` 是不要,只有 Windows。 | +| `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 install`。`--resume N` 重做新建失败的那台的初始化 | +| `set [--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..sound`。`--boss-key` 是这台的老板键(见「管理器 ModAVD.exe」一节),比如 `Ctrl+Alt+Shift+1`,`none` 是不要,只有 Windows。 | | `proxy [on\|off\|test] [--server URL\|auto] [--add 包名] [--remove 包名] [--apps 包名]` | 按应用走代理:名单里的应用走代理,其余直连(见下) | | `delete --yes` | 删除已关机的实例,连同游戏数据 | | `clone [--title T]` | 把已关机的实例整份复制成一台新实例(游戏、登录状态、设置都带上):新实例用最小的空闲编号和它的端口,其余设置照源实例;数据盘整份复制,两台互不影响,可用空间不够时报错(`precheck_failed`)、什么都不复制;失败或取消时复制到一半的会删掉。两台的安卓设备标识(Android ID、GSF ID)相同 | @@ -214,7 +214,9 @@ Apple Silicon macOS 的下载与导入使用 Android 15 Google Play `arm64-v8a` - 崩坏:星穹铁道(官服 `com.miHoYo.hkrpg`、B 服 `com.miHoYo.hkrpg.bilibili`,B 服没有实测)的显示模式预先设成 Vulkan(客体脚本 `modavd-vkmode.sh`,只在 Windows 上)。游戏第一次启动时自己选 OpenGL ES,在 ModAVD 上十几秒后闪退;在游戏设置里的显示设置(Display Settings)选 Vulkan 模式就正常。 - 守护每 3 秒看一次:游戏装上以后、第一次启动之前,在它的 `Android/data/<包名>/files` 里写好 `vulkancaps.bin`、`customvulkancaps.bin`。已经因为闪退停在 OpenGL ES 的,下次开机或游戏退出后也改成 Vulkan。 - 在游戏设置里选过显示模式的(`customvulkancaps.bin` 已经在、不是空文件)不动;游戏开着时不动;没装的游戏不建任何目录。 -分辨率只有两档:1080p 为 1920×1080 / DPI 280,720p 为 1280×720 / DPI 240。新建默认 1080p,720p 更省资源。管理器的新建和实例设置、CLI `--resolution 1080|720`、MCP `resolution` 使用同一套档位。已有实例按宽高识别:横屏或竖屏的 1920×1080 保持 1080p,其余配置及缺字段的旧配置保持 720p。换档联动宽、高、DPI,保留方向,下次冷启动生效;DPI 不单独设置,不使用运行时 `wm size` 或 `wm density`。自动化工具里的分辨率也要跟着改。 +分辨率只有两档:1080p 为 1920×1080 / DPI 280,720p 为 1280×720 / DPI 240。新建默认 1080p,720p 更省资源。管理器的新建和实例设置、CLI `--resolution 1080|720`、MCP `resolution` 使用同一套档位。已有实例按宽高识别:横屏或竖屏的 1920×1080 保持 1080p,其余配置及缺字段的旧配置保持 720p。换档联动宽、高和默认 DPI,保留方向,下次冷启动生效;不使用运行时 `wm size` 或 `wm density`。自动化工具里的分辨率也要跟着改。 + +DPI 默认跟随分辨率,也可以在管理器设置、CLI `--dpi`、MCP `dpi` 里选 160 / 240 / 280 / 320 / 400 / 480(`--dpi auto` 改回跟随),换分辨率时保留。方向默认横屏,可以改成竖屏(`--orientation portrait`):画布仍是横的,config.ini 的 `hw.initialOrientation` 设为 portrait,开机后安卓转到竖屏。两项都下次开机生效。MAA 等自动化任务要横屏,竖屏只适合自己玩。 AUTO-MAS 当前优先调用包内 CLI,这条启动路径保持所选档位。没有可用 CLI 的旧根目录会回退到固定 720p 的 Python 启动路径,使用 1080p 前须更新包内 CLI。AUTO-MAS 的旧新建和显示配置表单仍需配套支持两档;可先在 ModAVD 管理器里设置。 diff --git a/changelog.d/247-dpi-orientation.feat.md b/changelog.d/247-dpi-orientation.feat.md new file mode 100644 index 00000000..a379fb51 --- /dev/null +++ b/changelog.d/247-dpi-orientation.feat.md @@ -0,0 +1 @@ +实例设置可以单独设 DPI,也可以改成竖屏 diff --git a/internal/avd/avd.go b/internal/avd/avd.go index b4d3d7e9..11acfadc 100644 --- a/internal/avd/avd.go +++ b/internal/avd/avd.go @@ -28,6 +28,18 @@ var ( MemoryChoicesMB = []int{3072, 4096, 5120, 6144, 8192} CPUChoices = []int{2, 4, 6} ResolutionChoices = []int{1080, 720} + // DPIChoices are the densities an instance can be given instead of its resolution's (DPIKey; ModAVD/ModAVD#247). + DPIChoices = []int{160, 240, 280, 320, 400, 480} + // OrientationChoices: landscape (the default; what AUTO-MAS and MAA expect) or portrait (the same wide canvas, turned). + OrientationChoices = []string{OrientationLandscape, OrientationPortrait} +) + +const ( + OrientationLandscape = "landscape" + OrientationPortrait = "portrait" + // DPIKey is instances..dpi in mas-avd.json: one of DPIChoices, written as hw.lcd.density before every boot; + // absent (or anything else) = the resolution's own density (720p 240, 1080p 280), as before it existed. + DPIKey = "dpi" ) const ( @@ -353,13 +365,42 @@ func SoundConfig(on bool) [][2]string { return [][2]string{{"hw.audioInput", v}, {"hw.audioOutput", v}} } -// Display returns the size and density the instance will boot with (after DisplayChanges). -func (in *Instance) Display() (width, height, dpi int) { - ch := DisplayChanges(in.Config) +// DPIMeta is the density set for the instance with metadata meta (DPIKey), 0 when none is: the resolution's own. +func DPIMeta(meta *jsonord.Obj) int { + if n, ok := meta.Get(DPIKey).Int(); ok && slices.Contains(DPIChoices, int(n)) { + return int(n) + } + return 0 +} + +// Display returns the size and density the instance will boot with (after DisplayChanges) when its metadata sets +// density dpi (DPIMeta; 0 = the resolution's). +func (in *Instance) Display(dpi int) (width, height, density int) { + ch := DisplayChanges(in.Config, dpi) width, _ = strconv.Atoi(ch[0][1]) height, _ = strconv.Atoi(ch[1][1]) - dpi, _ = strconv.Atoi(ch[2][1]) - return width, height, dpi + density, _ = strconv.Atoi(ch[2][1]) + return width, height, density +} + +// Orientation is the instance's display orientation, config.ini's hw.initialOrientation (as the emulator reads it: +// portrait or landscape, case-insensitive). Without either (no key, "natural") the emulator takes the size's natural +// orientation: portrait when the height is larger. +func (in *Instance) Orientation() string { return orientationFor(in.Config) } + +func orientationFor(cfg *Ini) string { + v, _ := cfg.Get("hw.initialOrientation") + for _, o := range OrientationChoices { + if strings.EqualFold(strings.TrimSpace(v), o) { + return o + } + } + w, _ := intOrNone(cfg.Value("hw.lcd.width")) + h, _ := intOrNone(cfg.Value("hw.lcd.height")) + if h > w { + return OrientationPortrait + } + return OrientationLandscape } func IniPath(r *root.Root, i int) string { return filepath.Join(r.AvdHome(), root.AvdName(i)+".ini") } // \avd\mas_.ini @@ -588,6 +629,25 @@ func ValidateResolution(resolution *int) (int, error) { return value, nil } +// ValidateDPI takes 0 (the resolution's own density) or one of DPIChoices. +func ValidateDPI(dpi int) error { + if dpi != 0 && !slices.Contains(DPIChoices, dpi) { + return errs.Newf(errs.InvalidArgument, "DPI 只能选 %s,或 0(跟随分辨率)", joinInts(DPIChoices, "%d", 1)) + } + return nil +} + +// ValidateOrientation takes "landscape" or "portrait" ("" = landscape). +func ValidateOrientation(orientation string) (string, error) { + if orientation == "" { + return OrientationLandscape, nil + } + if !slices.Contains(OrientationChoices, orientation) { + return "", errs.New(errs.InvalidArgument, "方向只能选 landscape(横屏)或 portrait(竖屏)") + } + return orientation, nil +} + // isLineBreak is every character str.splitlines() splits at: a title holding one would break config.ini apart. func isLineBreak(r rune) bool { switch r { @@ -614,7 +674,9 @@ type CreateOptions struct { CPU int DataPartitionGB int FPS int - Resolution int // 0 = DefaultResolution + Resolution int // 0 = DefaultResolution + DPI int // 0 = the resolution's density; else one of DPIChoices (DPIKey) + Orientation string // "" = landscape; OrientationChoices // DataDiskManual: DataPartitionGB is a size the user chose (dataDiskMode manual); otherwise the data disk grows by // itself (dataDiskMode auto; the caller passes AutoDataPartitionGB). DataDiskManual bool @@ -655,7 +717,14 @@ func Create(r *root.Root, i int, opt CreateOptions) (*Instance, error) { if err != nil { return nil, err } - display := displayChanges(nil, resolution) + if err := ValidateDPI(opt.DPI); err != nil { + return nil, err + } + orientation, err := ValidateOrientation(opt.Orientation) + if err != nil { + return nil, err + } + display := displayChanges(nil, resolution, orientation, opt.DPI) if err := validateTitle(opt.Title); err != nil { return nil, err } @@ -680,6 +749,8 @@ func Create(r *root.Root, i int, opt CreateOptions) (*Instance, error) { cfg.Set("abi.type", p.GuestABI) cfg.Set("hw.cpu.arch", p.GuestArch) cfg.Set("target", p.TargetAPI) + // in the template's place (landscape there): the emulator turns its window when this and the size disagree + cfg.Set(display[4][0], display[4][1]) for _, kv := range [][2]string{ {"avd.id", name}, {"avd.name", name}, @@ -743,6 +814,9 @@ func Create(r *root.Root, i int, opt CreateOptions) (*Instance, error) { mode = DataDiskManual } meta.Set(DataDiskModeKey, jsonord.NewString(mode)) + if opt.DPI != 0 { + meta.Set(DPIKey, jsonord.NewInt(int64(opt.DPI))) + } if opt.Creating { meta.Set("creationState", jsonord.NewString("creating")) } @@ -865,6 +939,11 @@ type UpdateOptions struct { CPU *int FPS *int Resolution *int + // DPI sets the density (DPIKey; 0 = the resolution's own again); Orientation turns the display ("landscape" / + // "portrait": hw.initialOrientation on the wide canvas, see displayChanges). Both are written into config.ini with + // the resolution's size, and again before every boot (ApplyDisplay). + DPI *int + Orientation *string // DataPartitionGB raises disk.dataPartition.size (modavd only; AUTO-MAS cannot change it): within // MinDataPartitionGB..MaxDataPartitionGB and never below the current value. The emulator (sdk-mas36 on) grows the // disk image at the next boot without touching the data, and the boot's after-boot step grows the file system. @@ -881,7 +960,8 @@ type UpdateOptions struct { // Update writes the changed keys like AUTO-MAS write_instance_settings: hw.ramSize=M and hw.cpu.ncore always // (current values when not changed), hw.lcd.vsync only when FPS is given, avd.ini.displayname when Title is given, // disk.dataPartition.size when DataPartitionGB is given, hw.audioInput / hw.audioOutput and instances..sound when -// Sound is given, and instances..memoryMb always. Validates first (memory / cpu / fps steps). Returns the applied +// Sound is given, the display keys (displayChanges) and instances..dpi when Resolution, DPI or Orientation is +// given, and instances..memoryMb always. Validates first (memory / cpu / fps steps). Returns the applied // changes by option name ("title", "memory_mb", "cpu", "fps", "data_partition_gb", "sound"). Takes effect at the next // boot. // @@ -910,7 +990,7 @@ func Update(r *root.Root, i int, opt UpdateOptions) (map[string]any, error) { // Sound alone is not an AUTO-MAS hardware edit: like the diagnostics switch it neither validates nor rewrites the // unrelated values (an old out-of-range data disk, AUTO-MAS's automatic memory), only the sound keys. if opt.Sound != nil && opt.Title == nil && opt.MemoryMB == nil && opt.CPU == nil && opt.FPS == nil && - opt.Resolution == nil && opt.DataPartitionGB == nil && !opt.DataDiskAuto { + opt.Resolution == nil && opt.DPI == nil && opt.Orientation == nil && opt.DataPartitionGB == nil && !opt.DataDiskAuto { if _, err := r.ReadMetadata(); err != nil { return nil, err } @@ -939,6 +1019,17 @@ func Update(r *root.Root, i int, opt UpdateOptions) (map[string]any, error) { return nil, err } } + if opt.DPI != nil { + if err := ValidateDPI(*opt.DPI); err != nil { + return nil, err + } + } + var orientation string + if opt.Orientation != nil { + if orientation, err = ValidateOrientation(*opt.Orientation); err != nil { + return nil, err + } + } memoryArg := opt.MemoryMB if memoryArg == nil { current := MemoryFor(r, i) @@ -985,8 +1076,16 @@ func Update(r *root.Root, i int, opt UpdateOptions) (map[string]any, error) { if opt.FPS != nil { changes = append(changes, [2]string{"hw.lcd.vsync", strconv.Itoa(fps)}) } - if opt.Resolution != nil { - changes = append(changes, displayChanges(in.Config, resolution)...) + if opt.Resolution != nil || opt.DPI != nil || opt.Orientation != nil { + res := resolution + if opt.Resolution == nil { + res = resolutionFor(in.Config) + } + dpi := DPIMeta(r.InstanceMeta(i)) + if opt.DPI != nil { + dpi = *opt.DPI + } + changes = append(changes, displayChanges(in.Config, res, orientation, dpi)...) } if opt.DataPartitionGB != nil || opt.DataDiskAuto { changes = append(changes, [2]string{"disk.dataPartition.size", strconv.Itoa(data) + "G"}) @@ -1016,9 +1115,17 @@ func Update(r *root.Root, i int, opt UpdateOptions) (map[string]any, error) { if opt.Sound != nil { metaChanges[SoundKey] = jsonord.NewBool(*opt.Sound) } + if opt.DPI != nil && *opt.DPI != 0 { + metaChanges[DPIKey] = jsonord.NewInt(int64(*opt.DPI)) + } if err := r.UpdateInstanceMeta(i, metaChanges); err != nil { return nil, err } + if opt.DPI != nil && *opt.DPI == 0 { + if err := r.EditInstanceMeta(i, func(meta *jsonord.Obj) error { meta.Delete(DPIKey); return nil }); err != nil { + return nil, err + } + } applied := map[string]any{} if opt.Title != nil { applied["title"] = title @@ -1035,6 +1142,12 @@ func Update(r *root.Root, i int, opt UpdateOptions) (map[string]any, error) { if opt.Resolution != nil { applied["resolution"] = resolution } + if opt.DPI != nil { + applied["dpi"] = *opt.DPI + } + if opt.Orientation != nil { + applied["orientation"] = orientation + } if opt.DataPartitionGB != nil || opt.DataDiskAuto { applied["data_partition_gb"] = data applied["data_disk_mode"] = DataDiskManual @@ -1137,29 +1250,46 @@ func resolutionFor(cfg *Ini) int { return 720 } -// DisplayChanges normalizes the current preset's dimensions and DPI, preserving orientation. -func DisplayChanges(cfg *Ini) [][2]string { return displayChanges(cfg, resolutionFor(cfg)) } +// DisplayChanges normalizes the current preset's dimensions, preserving orientation, with density dpi (DPIMeta; 0 = +// the preset's). +func DisplayChanges(cfg *Ini, dpi int) [][2]string { + return displayChanges(cfg, resolutionFor(cfg), "", dpi) +} -func displayChanges(cfg *Ini, resolution int) [][2]string { - w, _ := intOrNone(cfg.Value("hw.lcd.width")) - h, _ := intOrNone(cfg.Value("hw.lcd.height")) +// displayChanges: dpi 0 is the resolution's own density. orientation "" leaves the orientation alone: the size keeps +// cfg's (an old instance whose height is larger stays that way) and hw.initialOrientation is not written. A given +// orientation writes the landscape canvas of the resolution and hw.initialOrientation: portrait is the same wide +// canvas turned (ModAVD/ModAVD#247), the emulator (from 0.43.0, ModAVD/ModAVD#225) sets the guest's user_rotation +// from hw.initialOrientation (landscape 0, portrait 3) and the boot sets the same (emu setupOrientation). +func displayChanges(cfg *Ini, resolution int, orientation string, dpi int) [][2]string { width, height, density := 1280, 720, 240 if resolution == 1080 { width, height, density = 1920, 1080, 280 } - if h > w { - width, height = height, width + if dpi != 0 { + density = dpi } - return [][2]string{ + if orientation == "" { + w, _ := intOrNone(cfg.Value("hw.lcd.width")) + h, _ := intOrNone(cfg.Value("hw.lcd.height")) + if h > w { + width, height = height, width + } + } + changes := [][2]string{ {"hw.lcd.width", strconv.Itoa(width)}, {"hw.lcd.height", strconv.Itoa(height)}, {"hw.lcd.density", strconv.Itoa(density)}, {"hw.mainKeys", "yes"}, } + if orientation != "" { + changes = append(changes, [2]string{"hw.initialOrientation", orientation}) + } + return changes } -// ApplyDisplay writes DisplayChanges into config.ini when any differs; returns whether it wrote. Only while stopped. -// Under the instance's root.LockInstanceConfig, like Update. +// ApplyDisplay writes DisplayChanges (with the density instances..dpi sets) into config.ini when any differs; +// returns whether it wrote. Only while stopped. Under the instance's root.LockInstanceConfig, like Update. func ApplyDisplay(r *root.Root, i int) (bool, error) { l, noDir, err := lockInstance(r, i) if err != nil { @@ -1174,7 +1304,7 @@ func ApplyDisplay(r *root.Root, i int) (bool, error) { if err != nil || cfg.Len() == 0 { return false, configUnreadable(i, err) } - changes := DisplayChanges(cfg) + changes := DisplayChanges(cfg, DPIMeta(r.InstanceMeta(i))) same := true for _, kv := range changes { if v, ok := cfg.Get(kv[0]); !ok || v != kv[1] { diff --git a/internal/avd/avd_test.go b/internal/avd/avd_test.go index a3186183..2e722a39 100644 --- a/internal/avd/avd_test.go +++ b/internal/avd/avd_test.go @@ -190,7 +190,7 @@ func describe(r *root.Root, list []*Instance) []map[string]any { } return n } - w, h, dpi := in.Display() + w, h, dpi := in.Display(0) keys := in.Config.Keys() if keys == nil { keys = []string{} @@ -694,7 +694,7 @@ func TestListAndGet(t *testing.T) { if d, ok := in.DataPartitionGB(); !ok || d != 64 { t.Errorf("DataPartitionGB %d", d) } - if w, h, dpi := in.Display(); in.FPS() != 60 || w != 1920 || h != 1080 || dpi != 280 { + if w, h, dpi := in.Display(0); in.FPS() != 60 || w != 1920 || h != 1080 || dpi != 280 { t.Errorf("FPS / Display %d %d %d %d", in.FPS(), w, h, dpi) } // An instance whose config.ini cannot be read (opened elsewhere without sharing) is listed with an empty config @@ -713,7 +713,7 @@ func TestListAndGet(t *testing.T) { if _, ok := empty.MemoryMB(); ok || empty.FPS() != DefaultFPS { t.Error("nil config") } - if w, h, _ := empty.Display(); w != 1280 || h != 720 { + if w, h, _ := empty.Display(0); w != 1280 || h != 720 { t.Error("nil config display") } } @@ -1230,7 +1230,7 @@ func TestApplyDisplay(t *testing.T) { "": "1280x720", "hw.lcd.height=720\n": "720x1280", } { - ch := DisplayChanges(parseIni([]byte(cfg))) + ch := DisplayChanges(parseIni([]byte(cfg)), 0) if got := ch[0][1] + "x" + ch[1][1]; got != want || ch[2][1] != "240" || ch[3] != [2]string{"hw.mainKeys", "yes"} || ch[0][0] != "hw.lcd.width" || ch[1][0] != "hw.lcd.height" || ch[2][0] != "hw.lcd.density" { t.Errorf("%q: %v", cfg, ch) diff --git a/internal/avd/resolution_test.go b/internal/avd/resolution_test.go index 8eccbbb1..dc292b4d 100644 --- a/internal/avd/resolution_test.go +++ b/internal/avd/resolution_test.go @@ -12,7 +12,7 @@ import ( func assertDisplay(t *testing.T, in *Instance, want [3]int) { t.Helper() - w, h, dpi := in.Display() + w, h, dpi := in.Display(0) if got := [3]int{w, h, dpi}; got != want { t.Fatalf("display = %v, want %v", got, want) } @@ -37,7 +37,7 @@ func TestResolutionCreateSwitchAndReboot(t *testing.T) { initial = 1080 } if portrait { - w, h, _ := in.Display() + w, h, _ := in.Display(0) in.Config.Set("hw.lcd.width", fmt.Sprint(h)) in.Config.Set("hw.lcd.height", fmt.Sprint(w)) if err := WriteIni(ConfigPath(r, 0), in.Config); err != nil { @@ -114,6 +114,88 @@ func TestResolutionLegacy(t *testing.T) { } } +// DPI (instances..dpi) and orientation (hw.initialOrientation on the wide canvas), ModAVD/ModAVD#247. +func TestDPIAndOrientation(t *testing.T) { + r := newRoot(t) + in, err := Create(r, 0, CreateOptions{MemoryMB: 6144, CPU: 6, DataPartitionGB: 64, FPS: 60, Resolution: 720, + DPI: 320, Orientation: OrientationPortrait}) + if err != nil { + t.Fatal(err) + } + if DPIMeta(r.InstanceMeta(0)) != 320 || in.Orientation() != OrientationPortrait || + in.Config.Value("hw.initialOrientation") != "portrait" { + t.Fatalf("create: %v %s", DPIMeta(r.InstanceMeta(0)), in.Orientation()) + } + w, h, dpi := in.Display(DPIMeta(r.InstanceMeta(0))) + if w != 1280 || h != 720 || dpi != 320 || in.Config.Value("hw.lcd.density") != "320" { + t.Fatalf("create display %d×%d %d", w, h, dpi) + } + // the density survives resolution changes and the pre-boot write; the orientation too + res := 1080 + if _, err := Update(r, 0, UpdateOptions{Resolution: &res}); err != nil { + t.Fatal(err) + } + for boot := 0; boot < 2; boot++ { + if _, err := ApplyDisplay(r, 0); err != nil { + t.Fatal(err) + } + } + in, _ = Get(r, 0) + if in.Orientation() != OrientationPortrait { + t.Fatal("orientation lost") + } + for key, want := range map[string]string{"hw.lcd.width": "1920", "hw.lcd.height": "1080", "hw.lcd.density": "320"} { + if in.Config.Value(key) != want { + t.Fatalf("%s = %q", key, in.Config.Value(key)) + } + } + // back to the resolution's density and landscape: the key goes + zero, land := 0, OrientationLandscape + applied, err := Update(r, 0, UpdateOptions{DPI: &zero, Orientation: &land}) + if err != nil || applied["dpi"] != 0 || applied["orientation"] != "landscape" { + t.Fatalf("%v %v", applied, err) + } + if r.InstanceMeta(0).Has(DPIKey) { + t.Fatal("dpi key kept") + } + in, _ = Get(r, 0) + if in.Orientation() != OrientationLandscape { + t.Fatal("still portrait") + } + assertDisplay(t, in, [3]int{1920, 1080, 280}) + // an old instance whose height is larger is turned to the wide canvas once an orientation is chosen + writeFile(t, ConfigPath(r, 0), []byte("hw.lcd.width=720\nhw.lcd.height=1280\nhw.initialOrientation=landscape\n")) + portrait := OrientationPortrait + if _, err := Update(r, 0, UpdateOptions{Orientation: &portrait}); err != nil { + t.Fatal(err) + } + in, _ = Get(r, 0) + if w, h, _ := in.Display(0); w != 1280 || h != 720 || in.Orientation() != OrientationPortrait { + t.Fatalf("%d×%d %s", w, h, in.Orientation()) + } + // bad values write nothing + before, _ := os.ReadFile(ConfigPath(r, 0)) + bad, badOrient := 300, "upside" + _, err = Update(r, 0, UpdateOptions{DPI: &bad}) + wantCode(t, err, errs.InvalidArgument) + _, err = Update(r, 0, UpdateOptions{Orientation: &badOrient}) + wantCode(t, err, errs.InvalidArgument) + _, err = Create(r, 1, CreateOptions{MemoryMB: 6144, CPU: 6, DataPartitionGB: 64, FPS: 60, DPI: 300}) + wantCode(t, err, errs.InvalidArgument) + if after, _ := os.ReadFile(ConfigPath(r, 0)); string(after) != string(before) { + t.Fatal("invalid update changed config") + } + // no usable key: the size's natural orientation, as the emulator takes it + for cfg, want := range map[string]string{"hw.lcd.width=720\nhw.lcd.height=1280\n": "portrait", + "hw.lcd.width=1280\nhw.lcd.height=720\n": "landscape", "hw.initialOrientation=Portrait\n": "portrait", + "hw.initialOrientation=natural\nhw.lcd.width=720\nhw.lcd.height=1280\n": "portrait", + "hw.initialOrientation=landscape\nhw.lcd.width=720\nhw.lcd.height=1280\n": "landscape"} { + if got := orientationFor(parseIni([]byte(cfg))); got != want { + t.Errorf("%q: %s", cfg, got) + } + } +} + func TestResolutionValidationBeforeWrite(t *testing.T) { if got, err := ValidateResolution(nil); err != nil || got != 1080 { t.Fatalf("default: %d %v", got, err) diff --git a/internal/cli/args_test.go b/internal/cli/args_test.go index 191acdd5..0a9c0857 100644 --- a/internal/cli/args_test.go +++ b/internal/cli/args_test.go @@ -267,6 +267,13 @@ func TestBuildCreateRequest(t *testing.T) { req.FPS == nil || *req.FPS != 30 || req.Resolution == nil || *req.Resolution != 720 { t.Errorf("all options: %+v", req) } + req, err = buildCreateRequest(mustParse(t, "create", "--dpi", "320", "--orientation", "Portrait")) + if err != nil || req.DPI == nil || *req.DPI != 320 || req.Orientation == nil || *req.Orientation != "portrait" { + t.Errorf("dpi/orientation: %+v %v", req, err) + } + if _, err := buildCreateRequest(mustParse(t, "create", "--dpi", "high")); errs.CodeOf(err) != errs.InvalidArgument { + t.Errorf("--dpi high: %v", err) + } // Zero is passed on (emu rejects it with the AUTO-MAS wording), not mistaken for "not given". req, _ = buildCreateRequest(mustParse(t, "create", "--cpu", "0")) if req.CPU == nil || *req.CPU != 0 { @@ -332,6 +339,14 @@ func TestBuildUpdateRequest(t *testing.T) { if err != nil || req.Resolution == nil || *req.Resolution != 1080 || req.MemoryMB != nil { t.Fatalf("resolution alone: %+v %v", req, err) } + req, err = buildUpdateRequest(mustParse(t, "set", "3", "--dpi", "auto")) + if err != nil || req.DPI == nil || *req.DPI != 0 || req.Orientation != nil || req.MemoryMB != nil { + t.Fatalf("dpi auto alone: %+v %v", req, err) + } + req, err = buildUpdateRequest(mustParse(t, "set", "3", "--orientation", "landscape")) + if err != nil || req.Orientation == nil || *req.Orientation != "landscape" || req.DPI != nil { + t.Fatalf("orientation alone: %+v %v", req, err) + } for _, v := range []string{"auto", "AUTO", " auto "} { req, err = buildUpdateRequest(mustParse(t, "set", "3", "--data-gb", v)) if err != nil || !req.DataDiskAuto || req.DataPartitionGB != nil || req.Diagnostics != nil { diff --git a/internal/cli/commands.go b/internal/cli/commands.go index a7edce6e..fd9c251d 100644 --- a/internal/cli/commands.go +++ b/internal/cli/commands.go @@ -90,6 +90,8 @@ var ( optCPU = flagSpec{"cpu", kindInt, "N", "核数:2 / 4 / 6"} optDataGB = flagSpec{"data-gb", kindString, "auto|N", "数据盘:auto 自动扩盘(默认),或指定大小 16–512 GB"} optResolution = flagSpec{"resolution", kindInt, "", "分辨率:1080 / 720,DPI 随档位切换;新建默认 1080"} + optDPI = flagSpec{"dpi", kindString, "auto|N", "DPI:auto 跟随分辨率(720p 240、1080p 280,默认),或 160 / 240 / 280 / 320 / 400 / 480"} + optOrientation = flagSpec{"orientation", kindString, "landscape|portrait", "方向:landscape 横屏(默认),portrait 竖屏(MAA 等自动化任务要横屏)"} optFPS = flagSpec{"fps", kindInt, "F", "帧率:1–60 的整数,默认 60"} 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 时区"} @@ -199,7 +201,7 @@ func init() { run: runStatus, human: humanOf(formatStatus), }, { - name: "create", args: "[--index N | --count N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto|N] [--fps 1-60] [--resolution 1080|720] [--language host|preserve|语言] [--timezone host|preserve|IANA] [--no-bridge] [--timeout 1200] | --resume N", + name: "create", args: "[--index N | --count N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto|N] [--fps 1-60] [--resolution 1080|720] [--dpi auto|N] [--orientation landscape|portrait] [--language host|preserve|语言] [--timezone host|preserve|IANA] [--no-bridge] [--timeout 1200] | --resume N", summary: "新建一台实例,后台开机做完初始化后关机", details: "不给的选项用默认值:内存 6 GB、6 核、数据盘自动扩盘、60 帧、1080p(1920×1080 / DPI 280)。内存和核数只能取列出的档位,不会自动凑整。" + dataDiskHelp + @@ -211,19 +213,19 @@ func init() { "--count N 一次建 N 台:先取 N 个空闲编号(不够就一台不建),再按编号一台一台建,其余选项每台一样," + "给了 --title 时名称后面加序号(「T 1」「T 2」…);每台开建前查实例所在盘的剩余空间,低于开机所需就停下,剩下的不建。" + "一台失败不影响后面的;结果分 results 和 failed,有失败时退出码是第一个失败的退出码。", - flags: []flagSpec{optIndex, optCount, optTitle, optMemory, optCPU, optDataGB, optFPS, optResolution, optLanguage, optTimeZone, optNoBridge, optCreateTimeout, optResume}, + flags: []flagSpec{optIndex, optCount, optTitle, optMemory, optCPU, optDataGB, optFPS, optResolution, optDPI, optOrientation, optLanguage, optTimeZone, optNoBridge, optCreateTimeout, optResume}, final: true, run: runCreate, human: humanCreate, exit: exitBatch, }, { - name: "set", args: " [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080|720] [--data-gb auto|N] [--language host|preserve|语言] [--timezone host|preserve|IANA] [--diagnostics on|off] [--sound on|off] [--boss-key 组合|none]", + name: "set", args: " [--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]", 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, optDataGB, optLanguage, optTimeZone, optDiagnostics, optSound, optBossKey}, + flags: []flagSpec{optTitle, optMemory, optCPU, optFPS, optResolution, optDPI, optOrientation, optDataGB, optLanguage, optTimeZone, optDiagnostics, optSound, optBossKey}, posNames: []string{"实例编号"}, minPos: 1, maxPos: 1, final: true, run: runSet, human: humanOf(formatUpdate), @@ -619,6 +621,10 @@ func buildCreateRequest(inv *invocation) (emu.CreateRequest, error) { req.DataPartitionGB = gb req.FPS = intPtrOpt(inv, "fps") req.Resolution = intPtrOpt(inv, "resolution") + if req.DPI, err = dpiOpt(inv); err != nil { + return req, err + } + req.Orientation = strPtrOpt(inv, "orientation") req.NoBridge = inv.boolOpt("no-bridge") if inv.isSet("timeout") { n := inv.intOpt("timeout") @@ -628,7 +634,7 @@ func buildCreateRequest(inv *invocation) (emu.CreateRequest, error) { req.Timeout = time.Duration(n) * time.Second } if inv.isSet("resume") { - for _, o := range []string{"index", "title", "memory", "cpu", "data-gb", "fps", "resolution", "language", "timezone", "no-bridge"} { + for _, o := range []string{"index", "title", "memory", "cpu", "data-gb", "fps", "resolution", "dpi", "orientation", "language", "timezone", "no-bridge"} { if inv.isSet(o) { return req, errs.Newf(errs.Usage, "--resume 只重做初始化,不能再给 --%s", o) } @@ -664,6 +670,10 @@ func buildUpdateRequest(inv *invocation) (emu.UpdateRequest, error) { req.CPU = intPtrOpt(inv, "cpu") req.FPS = intPtrOpt(inv, "fps") req.Resolution = intPtrOpt(inv, "resolution") + if req.DPI, err = dpiOpt(inv); err != nil { + return req, err + } + req.Orientation = strPtrOpt(inv, "orientation") gb, auto, err := dataGBOpt(inv) if err != nil { return req, err @@ -689,9 +699,9 @@ func buildUpdateRequest(inv *invocation) (emu.UpdateRequest, error) { 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.DataPartitionGB == nil && + 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、--data-gb、--language、--timezone、--diagnostics、--sound、--boss-key 中的一个"). + return req, errs.New(errs.Usage, "没有要改的内容:至少给 --title、--memory、--cpu、--fps、--resolution、--dpi、--orientation、--data-gb、--language、--timezone、--diagnostics、--sound、--boss-key 中的一个"). WithAdvice(findCommand("set").usageAdvice()) } return req, nil @@ -732,6 +742,32 @@ func buildStartOptions(inv *invocation) (emu.StartOptions, error) { return opt, nil } +func strPtrOpt(inv *invocation, name string) *string { + if !inv.isSet(name) { + return nil + } + v := strings.ToLower(strings.TrimSpace(inv.strOpt(name))) + return &v +} + +// dpiOpt is --dpi: auto (0, the resolution's own density) or a number; nil when not given. The choices are checked +// by avd.ValidateDPI. +func dpiOpt(inv *invocation) (*int, error) { + if !inv.isSet("dpi") { + return nil, nil + } + s := strings.ToLower(strings.TrimSpace(inv.strOpt("dpi"))) + if s == "auto" { + zero := 0 + return &zero, nil + } + n, err := strconv.Atoi(s) + if err != nil { + return nil, errs.Newf(errs.InvalidArgument, "--dpi 只能是 auto 或数字,收到 %q", inv.strOpt("dpi")) + } + return &n, nil +} + func intPtrOpt(inv *invocation, name string) *int { if !inv.isSet(name) { return nil diff --git a/internal/cli/format.go b/internal/cli/format.go index 6a23a143..84d93f64 100644 --- a/internal/cli/format.go +++ b/internal/cli/format.go @@ -378,7 +378,7 @@ func formatCreate(w io.Writer, in *emu.InstanceInfo) { } // appliedOrder is the order changes are listed in; unknown keys follow alphabetically. -var appliedOrder = []string{"title", "memory_mb", "cpu", "fps", "resolution", "data_partition_gb"} +var appliedOrder = []string{"title", "memory_mb", "cpu", "fps", "resolution", "dpi", "orientation", "data_partition_gb"} func appliedParts(applied map[string]any) []string { keys := make([]string, 0, len(applied)) @@ -418,6 +418,18 @@ func appliedParts(applied map[string]any) []string { parts = append(parts, fmt.Sprintf("帧率 %v", v)) case "resolution": parts = append(parts, fmt.Sprintf("分辨率 %vp", v)) + case "dpi": + if n, ok := asInt(v); ok && n == 0 { + parts = append(parts, "DPI 跟随分辨率") + } else { + parts = append(parts, fmt.Sprintf("DPI %v", v)) + } + case "orientation": + if v == avd.OrientationPortrait { + parts = append(parts, "方向 竖屏") + } else { + parts = append(parts, "方向 横屏") + } case "data_partition_gb": if applied["data_disk_mode"] == avd.DataDiskAuto { parts = append(parts, fmt.Sprintf("数据盘 自动扩盘(%v GB,下次开机生效)", v)) diff --git a/internal/emu/afterboot.go b/internal/emu/afterboot.go index a0d2ec84..59c19bfd 100644 --- a/internal/emu/afterboot.go +++ b/internal/emu/afterboot.go @@ -640,8 +640,11 @@ func parseStatusLines(out string) map[string]string { return lines } -// setupOrientation keeps the display at 0° (landscape): it follows neither the sensor nor apps' orientation -// requests, and landscape games are never flipped to 180°. A portrait page then sits letterboxed in the middle. +// setupOrientation fixes the display's rotation: it follows neither the sensor nor apps' orientation requests, and +// landscape games are never flipped to 180°. A page of the other orientation then sits letterboxed in the middle. +// The rotation is the instance's orientation (config.ini hw.initialOrientation, ModAVD/ModAVD#247): landscape 0, +// portrait 3 (the same wide canvas turned). The emulator (from 0.43.0, ModAVD/ModAVD#225) writes the same value as +// soon as the settings service is up and before a window close, so both must agree (userRotationFor). // The letterbox education dialog ("See and do more") is turned off first: that switch is not persistent, so every // boot; `wm fixed-to-user-rotation` is stored in display_settings.xml and survives reboots. func (m *Manager) setupOrientation(ctx context.Context, i int) { @@ -649,15 +652,32 @@ func (m *Manager) setupOrientation(ctx context.Context, i int) { if res := m.shell(ctx, i, "wm set-letterbox-style --isEducationEnabled false", 0); res.Code != 0 { failures = append(failures, "关信箱引导: "+tail(res.Out, 200)) } - if res := m.shell(ctx, i, "settings put system user_rotation 0 ; wm fixed-to-user-rotation enabled", 0); res.Code != 0 { + orientation := avd.OrientationLandscape + if in, err := avd.Get(m.Root, i); err == nil { + orientation = in.Orientation() + } + rot := userRotationFor(orientation) + if res := m.shell(ctx, i, fmt.Sprintf("settings put system user_rotation %d ; wm fixed-to-user-rotation enabled", rot), 0); res.Code != 0 { failures = append(failures, "固定方向: "+tail(res.Out, 200)) } rotation := m.shell(ctx, i, "dumpsys window displays | grep -m1 -oE mDisplayRotation=ROTATION_[0-9]+", 0) if len(failures) > 0 { m.Log.Warnf("实例 %d 方向没设好: %s", i, pyList(failures)) } else { - m.Log.Infof("实例 %d 方向: 固定 0°,当前 %s", i, parseRotation(rotation.Out)) + text := "横屏" + if orientation == avd.OrientationPortrait { + text = "竖屏" + } + m.Log.Infof("实例 %d 方向: %s,固定 user_rotation=%d,当前 %s", i, text, rot, parseRotation(rotation.Out)) + } +} + +// userRotationFor is the guest's user_rotation for an orientation, as the emulator sets it: landscape 0, portrait 3. +func userRotationFor(orientation string) int { + if orientation == avd.OrientationPortrait { + return 3 } + return 0 } // parseRotation takes the mDisplayRotation= line only: when grep -m1 exits early dumpsys adds a "Broken pipe" line. diff --git a/internal/emu/crud.go b/internal/emu/crud.go index fcf319e6..84b71515 100644 --- a/internal/emu/crud.go +++ b/internal/emu/crud.go @@ -57,6 +57,20 @@ func (m *Manager) Create(ctx context.Context, req CreateRequest) (_ *InstanceInf if err != nil { return nil, err } + dpi := 0 + if req.DPI != nil { + dpi = *req.DPI + } + if err := avd.ValidateDPI(dpi); err != nil { + return nil, err + } + orientation := "" + if req.Orientation != nil { + orientation = *req.Orientation + } + if orientation, err = avd.ValidateOrientation(orientation); err != nil { + return nil, err + } // A root used by modavd alone has no mas-avd.json yet (AUTO-MAS writes it when the root is added). if _, err := m.Root.EnsureMetadata(); err != nil { return nil, err @@ -106,6 +120,7 @@ func (m *Manager) Create(ctx context.Context, req CreateRequest) (_ *InstanceInf } in, err := avd.Create(m.Root, i, avd.CreateOptions{ Title: req.Title, MemoryMB: memory, CPU: cpu, DataPartitionGB: dataGB, DataDiskManual: manualDisk, FPS: fps, Resolution: resolution, + DPI: dpi, Orientation: orientation, Creating: !req.filesOnly, Regional: regionalSettings, }) @@ -277,10 +292,11 @@ func (m *Manager) Update(ctx context.Context, i int, req UpdateRequest) (*Update return nil, err } } - if req.Title != nil || req.MemoryMB != nil || req.CPU != nil || req.FPS != nil || req.Resolution != nil || req.DataPartitionGB != nil || - req.DataDiskAuto || req.Sound != nil { + 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.Sound != nil { applied, err = avd.Update(m.Root, i, avd.UpdateOptions{ - Title: req.Title, MemoryMB: req.MemoryMB, CPU: req.CPU, FPS: req.FPS, Resolution: req.Resolution, DataPartitionGB: req.DataPartitionGB, + Title: req.Title, MemoryMB: req.MemoryMB, CPU: req.CPU, FPS: req.FPS, Resolution: req.Resolution, + DPI: req.DPI, Orientation: req.Orientation, DataPartitionGB: req.DataPartitionGB, DataDiskAuto: req.DataDiskAuto, Sound: req.Sound, }) if err != nil { diff --git a/internal/emu/launch.go b/internal/emu/launch.go index caeede5f..bde0515d 100644 --- a/internal/emu/launch.go +++ b/internal/emu/launch.go @@ -193,7 +193,9 @@ func (m *Manager) launchPlanFor(ctx context.Context, inst *avd.Instance, memoryM return nil, errs.Wrap(errs.Internal, err, fmt.Sprintf("实例 %d 写显示设置(config.ini)失败: %v", i, err)) } if wrote { - m.Log.Infof("实例 %d 显示设为 %dp、不显示导航栏(已写入 config.ini)", i, inst.Resolution()) + // Display normalizes the config read before the write the same way ApplyDisplay did + w, h, dpi := inst.Display(avd.DPIMeta(m.Root.InstanceMeta(i))) + m.Log.Infof("实例 %d 显示设为 %d×%d、DPI %d、不显示导航栏(已写入 config.ini)", i, w, h, dpi) } headless := !window diff --git a/internal/emu/ops_root_test.go b/internal/emu/ops_root_test.go index 44e06e15..4c25a393 100644 --- a/internal/emu/ops_root_test.go +++ b/internal/emu/ops_root_test.go @@ -11,6 +11,7 @@ import ( "strings" "testing" + "modavd/internal/avd" "modavd/internal/errs" "modavd/internal/logx" "modavd/internal/root" @@ -61,7 +62,7 @@ func TestOpsInstanceLifecycle(t *testing.T) { if !root.ValidIndex(i) || created.Title != "测试实例" || created.Status != StatusOffline || created.Running || created.PID != 0 { t.Fatalf("created = %+v", created) } - want := InstanceConfig{MemoryMB: 6144, CPU: 6, FPS: 60, DataPartitionGB: 256, DataDiskMode: "auto", Resolution: 1080, Width: 1920, Height: 1080, DPI: 280} + want := InstanceConfig{MemoryMB: 6144, CPU: 6, FPS: 60, DataPartitionGB: 256, DataDiskMode: "auto", Resolution: 1080, Width: 1920, Height: 1080, DPI: 280, Orientation: "landscape"} if created.Config != want { t.Fatalf("config = %+v, want %+v", created.Config, want) } @@ -105,6 +106,25 @@ func TestOpsInstanceLifecycle(t *testing.T) { if len(up.Applied) == 0 { t.Fatalf("applied empty: %+v", up) } + // DPI and orientation (ModAVD/ModAVD#247): the setting is shown, the next boot's density follows it, and back + dpi, portrait := 320, "portrait" + up, err = m.Update(ctx, i, UpdateRequest{DPI: &dpi, Orientation: &portrait}) + if err != nil { + t.Fatal(err) + } + if c := up.Instance.Config; c.DPISetting != 320 || c.DPI != 320 || c.Orientation != "portrait" || + c.Width != 1280 || c.Height != 720 || up.Applied["dpi"] != 320 || up.Applied["orientation"] != "portrait" { + t.Fatalf("dpi/orientation = %+v", up) + } + auto, landscape := 0, "landscape" + up, err = m.Update(ctx, i, UpdateRequest{DPI: &auto, Orientation: &landscape}) + if err != nil { + t.Fatal(err) + } + if c := up.Instance.Config; c.DPISetting != 0 || c.DPI != 240 || c.Orientation != "landscape" || + m.Root.InstanceMeta(i).Has(avd.DPIKey) { + t.Fatalf("dpi/orientation back = %+v", up) + } // A start in progress (lock held, here by this process) shows as busy and blocks the delete. l, ok, err := win.TryLock(m.lockPath(i, "start")) diff --git a/internal/emu/status.go b/internal/emu/status.go index b311d370..65896ffc 100644 --- a/internal/emu/status.go +++ b/internal/emu/status.go @@ -217,8 +217,10 @@ func (m *Manager) instanceInfo(ctx context.Context, in *avd.Instance, p *host.Pr if n, ok := in.DataPartitionGB(); ok { cfg.DataPartitionGB = n } - cfg.Width, cfg.Height, cfg.DPI = in.Display() meta := m.Root.InstanceMeta(i) + cfg.DPISetting = avd.DPIMeta(meta) + cfg.Width, cfg.Height, cfg.DPI = in.Display(cfg.DPISetting) + cfg.Orientation = in.Orientation() info.Regional = regionalConfig(meta) cfg.DataDiskMode = avd.DataDiskManual if avd.DataDiskAutoMeta(meta) { diff --git a/internal/emu/types.go b/internal/emu/types.go index 1c703965..1e821a0a 100644 --- a/internal/emu/types.go +++ b/internal/emu/types.go @@ -43,7 +43,12 @@ type InstanceConfig struct { DataDiskMode string `json:"data_disk_mode"` Width int `json:"width"` Height int `json:"height"` - DPI int `json:"dpi"` + DPI int `json:"dpi"` // the density the next boot uses + // DPISetting is the density chosen for the instance (mas-avd.json instances..dpi), 0 when it follows the + // resolution (720p 240, 1080p 280). + DPISetting int `json:"dpi_setting"` + // Orientation: "landscape" or "portrait" (config.ini hw.initialOrientation; the same wide canvas turned). + Orientation string `json:"orientation"` // Sound: the next boot has host sound and a guest sound card (mas-avd.json instances..sound; off by default). Sound bool `json:"sound"` } @@ -157,6 +162,8 @@ type CreateRequest struct { DataPartitionGB *int FPS *int Resolution *int + DPI *int // nil / 0 = the resolution's density; else one of avd.DPIChoices + Orientation *string // nil = landscape; "landscape" / "portrait" // NoBridge: no execution bridge (bridge.go), recorded for good. By default a new instance gets the bridge's boot // marker and create's setup installs it. NoBridge bool @@ -182,6 +189,10 @@ type UpdateRequest struct { CPU *int FPS *int Resolution *int + // DPI (0 = follow the resolution) and Orientation ("landscape" / "portrait") from the next boot; see + // avd.UpdateOptions. + DPI *int + Orientation *string // DataPartitionGB raises the data partition (never lowers it) and makes it manual; see avd.UpdateOptions. DataPartitionGB *int // DataDiskAuto switches the data disk to 自动扩盘 (raised to avd.AutoDataPartitionGB at the next boot); not together diff --git a/internal/i18n/locales/en/avd.json b/internal/i18n/locales/en/avd.json index 7e265eff..4314e15a 100644 --- a/internal/i18n/locales/en/avd.json +++ b/internal/i18n/locales/en/avd.json @@ -1,5 +1,6 @@ { "%s 读不出:%s": "Cannot read %s: %s", + "DPI 只能选 %s,或 0(跟随分辨率)": "DPI must be one of %s, or 0 (follow the resolution)", "ModAVD 实例 %d 不存在": "ModAVD instance %d does not exist", "ModAVD 实例已满(端口段 %d–%d 最多 9 台)": "No free ModAVD instance slot (port range %d-%d holds at most 9)", "ModAVD 的 CPU 核数只能选 %v": "ModAVD CPU cores must be one of %v", @@ -24,6 +25,7 @@ "数据盘上限只能改大:实例 %d 现在是 %d GB,不能改成 %d GB": "The data disk limit can only be increased: instance %d is %d GB now and cannot be changed to %d GB", "数据盘只能二选一:自动扩盘,或者指定大小": "Choose one for the data disk: automatic size, or a fixed size", "文件不存在": "File does not exist", + "方向只能选 landscape(横屏)或 portrait(竖屏)": "Orientation must be landscape or portrait", "替换 %s 失败:%v": "Failed to replace %s: %v", "请手动删除这个链接和它指向的数据": "Delete this link and the data it points to by hand", "读不了实例目录 %s:%v": "Cannot read instance folder %s: %v" diff --git a/internal/i18n/locales/en/cli.json b/internal/i18n/locales/en/cli.json index 09651d35..90926740 100644 --- a/internal/i18n/locales/en/cli.json +++ b/internal/i18n/locales/en/cli.json @@ -28,6 +28,7 @@ "--count 要给 1–9 的整数,收到 %d": "--count must be a whole number from 1 to 9, got %d", "--data-gb 只能是 auto 或 %d–%d 的整数(GB),收到「%s」": "--data-gb must be auto or an integer from %d to %d (GB), got \"%s\"", "--diagnostics 只能是 on 或 off": "--diagnostics must be on or off", + "--dpi 只能是 auto 或数字,收到 %q": "--dpi must be auto or a number, got %q", "--handoff-id 要和 --reopen 一起用": "--handoff-id must be used with --reopen", "--package 和 --sha256 只用于 update prepare 或 install": "--package and --sha256 are only for update prepare or install", "--reopen 要给程序的完整路径,收到「%s」": "--reopen needs the full path of a program, got \"%s\"", @@ -41,11 +42,13 @@ "0.3.0 起没有重启:先 modavd stop ,再 modavd start (要窗口加 --window)": "There is no restart since 0.3.0: run modavd stop , then modavd start (add --window for a window)", " [--] ": " [--] ", " [--timeout 秒] <命令...>": " [--timeout SECONDS] ", - " [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080|720] [--data-gb auto|N] [--language host|preserve|语言] [--timezone host|preserve|IANA] [--diagnostics on|off] [--sound on|off] [--boss-key 组合|none]": " [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080|720] [--data-gb auto|N] [--language host|preserve|LANG] [--timezone host|preserve|IANA] [--diagnostics on|off] [--sound on|off] [--boss-key COMBO|none]", + " [--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]": " [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080|720] [--dpi auto|N] [--orientation landscape|portrait] [--data-gb auto|N] [--language host|preserve|language] [--timezone host|preserve|IANA] [--diagnostics on|off] [--sound on|off] [--boss-key combo|none]", " [on|off|test] [--server URL|auto] [--add 包名] [--remove 包名] [--apps 包名]": " [on|off|test] [--server URL|auto] [--add PACKAGE] [--remove PACKAGE] [--apps PACKAGE]", "APK 路径": "APK path", "ARM64 商店文件已准备;当前 macOS 版本尚未开放实例内安装与移除": "ARM64 Store files are ready; this macOS version does not yet support installing or removing them in an instance", "DNS:%s(经代理用 TCP 查)\n": "DNS: %s (resolved over TCP through the proxy)\n", + "DPI 跟随分辨率": "DPI follows the resolution", + "DPI:auto 跟随分辨率(720p 240、1080p 280,默认),或 160 / 240 / 280 / 320 / 400 / 480": "DPI: auto follows the resolution (720p 240, 1080p 280; the default), or 160 / 240 / 280 / 320 / 400 / 480", "Google Play 商店的五个文件已经齐全、校验无误,没有改动(给的文件也核对过了)": "The five Google Play Store files are complete and verified; nothing changed (the files you gave were checked too)", "Google Play 版镜像的压缩包": "Google Play system image archive", "HTTP 代理": "HTTP proxy", @@ -59,7 +62,7 @@ "UDP:失败(%v)": "UDP: failed (%v)", "Windows:host 按宿主界面语言设置一次,preserve 保持安卓语言,或指定 zh-CN、en-US 等语言": "Windows: host sets it once from the host UI language, preserve keeps the Android language, or give a language such as zh-CN or en-US", "Windows:host 每次冷启动跟随宿主,preserve 沿用原行为,或指定 Asia/Shanghai、Etc/UTC 等 IANA 时区": "Windows: host follows the host on every cold start, preserve keeps the previous behavior, or give an IANA time zone such as Asia/Shanghai or Etc/UTC", - "[--index N | --count N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto|N] [--fps 1-60] [--resolution 1080|720] [--language host|preserve|语言] [--timezone host|preserve|IANA] [--no-bridge] [--timeout 1200] | --resume N": "[--index N | --count N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto|N] [--fps 1-60] [--resolution 1080|720] [--language host|preserve|LANG] [--timezone host|preserve|IANA] [--no-bridge] [--timeout 1200] | --resume N", + "[--index N | --count N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto|N] [--fps 1-60] [--resolution 1080|720] [--dpi auto|N] [--orientation landscape|portrait] [--language host|preserve|语言] [--timezone host|preserve|IANA] [--no-bridge] [--timeout 1200] | --resume N": "[--index N | --count N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto|N] [--fps 1-60] [--resolution 1080|720] [--dpi auto|N] [--orientation landscape|portrait] [--language host|preserve|language] [--timezone host|preserve|IANA] [--no-bridge] [--timeout 1200] | --resume N", "[--out-dir 目录] [--stage-dir 目录] [--keep-stage] [--no-explorer]": "[--out-dir DIR] [--stage-dir DIR] [--keep-stage] [--no-explorer]", "[status] | source [auto|googledownloads_cn|tencent|google] | fetch [--accept-license] [--mirror ID] [--mirror-url URL] [--keep-downloads] [--play-store] | import-playstore <文件或文件夹>…": "[status] | source [auto|googledownloads_cn|tencent|google] | fetch [--accept-license] [--mirror ID] [--mirror-url URL] [--keep-downloads] [--play-store] | import-playstore ...", "[status|check|prepare|install|recover] [--source github|mirrorchyan] [--cdk-dpapi BASE64] [--automas-version V] [--package ZIP --sha256 HEX] [--after-pid PID --reopen 程序 [--reopen-arg 参数]... [--handoff-id ID]]": "[status|check|prepare|install|recover] [--source github|mirrorchyan] [--cdk-dpapi BASE64] [--automas-version V] [--package ZIP --sha256 HEX] [--after-pid PID --reopen PROGRAM [--reopen-arg ARG]... [--handoff-id ID]]", @@ -306,6 +309,9 @@ "新建了 %d 台,%d 台没建成\n": "Created %d, %d not created\n", "新建后的初始化最多做多少秒(默认 1200;到点先正常关机,记为新建失败)": "How many seconds the initial setup after creation may take at most (default 1200; at the deadline it shuts down normally first and is recorded as a creation failure)", "新建失败": "Creation failed", + "方向 横屏": "Orientation landscape", + "方向 竖屏": "Orientation portrait", + "方向:landscape 横屏(默认),portrait 竖屏(MAA 等自动化任务要横屏)": "Orientation: landscape (the default) or portrait (automation such as MAA needs landscape)", "无": "none", "无头开机(不带 --window 时本来就是无头);实例已经带窗口运行时报错,不接管": "Start headless (without --window it is headless anyway); reports an error if the instance is already running with a window, and does not take it over", "显示": "Display", @@ -351,7 +357,7 @@ "没找到根目录:%s(之后每次调用工具时再找)": "Root folder not found: %s (it will be looked for again on each tool call)", "没有": "None", "没有正在运行的实例": "No running instances", - "没有要改的内容:至少给 --title、--memory、--cpu、--fps、--resolution、--data-gb、--language、--timezone、--diagnostics、--sound、--boss-key 中的一个": "Nothing to change: give at least one of --title, --memory, --cpu, --fps, --resolution, --data-gb, --language, --timezone, --diagnostics, --sound, --boss-key", + "没有要改的内容:至少给 --title、--memory、--cpu、--fps、--resolution、--dpi、--orientation、--data-gb、--language、--timezone、--diagnostics、--sound、--boss-key 中的一个": "Nothing to change: give at least one of --title, --memory, --cpu, --fps, --resolution, --dpi, --orientation, --data-gb, --language, --timezone, --diagnostics, --sound, --boss-key", "没生效:%v": "Not in effect: %v", "没装": "Not installed", "注意:%v": "Note: %v", diff --git a/internal/i18n/locales/en/emu.json b/internal/i18n/locales/en/emu.json index c009bf0f..fdc9f733 100644 --- a/internal/i18n/locales/en/emu.json +++ b/internal/i18n/locales/en/emu.json @@ -382,12 +382,12 @@ "实例 %d 新建后的初始化:后台无头开机,做完%s后正常关机": "Instance %d initial setup after create: starting headless in the background, shutting down normally after %s", "实例 %d 新建完成": "Instance %d created", "实例 %d 新建完成,已关机;第一次开机不用再做初始化": "Instance %d created and shut down; the first start needs no initial setup", - "实例 %d 方向: 固定 0°,当前 %s": "Instance %d orientation: fixed at 0 degrees, currently %s", + "实例 %d 方向: %s,固定 user_rotation=%d,当前 %s": "Instance %d orientation: %s, user_rotation fixed at %d, now %s", "实例 %d 方向没设好: %s": "Instance %d: orientation not set: %s", "实例 %d 无法确认 SDK/adb 目标,本次不切换宿主采集: %v": "Instance %d: cannot determine the SDK/adb target; not switching host collection this time: %v", "实例 %d 无法确认 SDK/adb 目标,本次不改客体缓冲区: %v": "Instance %d: cannot determine the SDK/adb target; not changing the guest buffer this time: %v", "实例 %d 无法确认日志采集的 SDK/adb 目标,本次不新起采集: %v": "Instance %d: cannot determine the SDK/adb target for log collection; not starting a new collection this time: %v", - "实例 %d 显示设为 %dp、不显示导航栏(已写入 config.ini)": "Instance %d display set to %dp, no navigation bar (written to config.ini)", + "实例 %d 显示设为 %d×%d、DPI %d、不显示导航栏(已写入 config.ini)": "Instance %d display set to %d×%d, DPI %d, no navigation bar (written to config.ini)", "实例 %d 更新 arm64 执行桥": "Instance %d: updating the arm64 execution bridge", "实例 %d 更新执行桥后关机再开机失败: %v": "Instance %d: shutting down and starting again after updating the execution bridge failed: %v", "实例 %d 更新执行桥后冷启动,客体里的文件还是旧的;日志 %s": "Instance %d: after the cold start following the execution bridge update, the files in the guest are still old; log %s", @@ -660,6 +660,7 @@ "模拟器版本": "Emulator version", "模拟器目录路径里有中文等非英文字符(%s),模拟器在这类路径下不可靠": "The emulator folder path contains non-English characters such as Chinese (%s); the emulator is unreliable under such paths", "模拟器组件还没装好,装好后再检查": "The emulator components are not fully installed; check again after installing them", + "横屏": "Landscape", "正在关机": "shutting down", "正在关闭": "shutting down", "正在启动": "starting", @@ -707,6 +708,7 @@ "私有 adb server(端口 %d)%.0f 秒内没起来": "The private adb server (port %d) did not start within %.0f s", "私有 adb server(端口 %d)%.0f 秒内没起来,照常开机": "The private adb server (port %d) did not start within %.0f s; starting anyway", "稍后再开机;一直关不掉的话先 modavd stop %d": "Start later; if it will not shut down, run modavd stop %d first", + "竖屏": "Portrait", "端口段": "Port range", "等它做完;进度用 modavd status 查看": "Wait for it to finish; check progress with modavd status", "等安装完": "wait for the install to finish", diff --git a/internal/i18n/locales/en/mcp.json b/internal/i18n/locales/en/mcp.json index 822b0b1a..bd38f2c2 100644 --- a/internal/i18n/locales/en/mcp.json +++ b/internal/i18n/locales/en/mcp.json @@ -33,7 +33,7 @@ "已取消": "Canceled", "收到的消息不是合法 JSON,已回复解析错误: %s": "The received message is not valid JSON; replied with a parse error: %s", "新建中 %d%%:%s": "Creating %d%%: %s", - "没有要改的选项:title、memory_mb、cpu、fps、resolution、data_partition_gb、data_disk_auto、sound 至少给一项": "Nothing to change: give at least one of title, memory_mb, cpu, fps, resolution, data_partition_gb, data_disk_auto, sound", + "没有要改的选项:title、memory_mb、cpu、fps、resolution、dpi、orientation、data_partition_gb、data_disk_auto、sound 至少给一项": "No option to change: give at least one of title, memory_mb, cpu, fps, resolution, dpi, orientation, data_partition_gb, data_disk_auto, sound", "没有要改的:enabled、server、apps、add_apps、remove_apps 至少给一项": "Nothing to change: give at least one of enabled, server, apps, add_apps, remove_apps", "确认要删除时把 confirm 设为 true": "To confirm the deletion, set confirm to true", "等 %d 个正在写文件的请求做完再退出(最多 %.0f 秒)": "Waiting for %d requests that are writing files to finish before exiting (up to %.0f s)", diff --git a/internal/i18n/locales/en/ui.json b/internal/i18n/locales/en/ui.json index 098363ae..d3092685 100644 --- a/internal/i18n/locales/en/ui.json +++ b/internal/i18n/locales/en/ui.json @@ -231,7 +231,7 @@ "老板键:读不了实例: %v": "Boss key: cannot read instances: %v", "自定义组件下载源至少要有一个地址": "A custom component download source needs at least one address", "至少给出 enabled、server、apps 中的一项": "Give at least one of enabled, server, apps", - "至少给出 title、memory_mb、cpu、fps、resolution、data_partition_gb、data_disk_auto、language、time_zone、diagnostics、sound、boss_key 中的一项": "Give at least one of title, memory_mb, cpu, fps, resolution, data_partition_gb, data_disk_auto, language, time_zone, diagnostics, sound, boss_key", + "至少给出 title、memory_mb、cpu、fps、resolution、dpi、orientation、data_partition_gb、data_disk_auto、language、time_zone、diagnostics、sound、boss_key 中的一项": "Give at least one of title, memory_mb, cpu, fps, resolution, dpi, orientation, data_partition_gb, data_disk_auto, language, time_zone, diagnostics, sound, boss_key", "补全 Google Play 商店": "setting up Google Play Store", "补全组件": "fetching components", "补全组件必须明确同意许可协议": "Fetching components requires explicitly accepting the license agreement", diff --git a/internal/i18n/locales/en/web.json b/internal/i18n/locales/en/web.json index d527129a..03e4b693 100644 --- a/internal/i18n/locales/en/web.json +++ b/internal/i18n/locales/en/web.json @@ -13,6 +13,7 @@ "Google Play 商店服务已就绪({bits})": "Google Play Store service ready ({bits})", "Google Play 商店的文件已就绪": "Google Play Store files are ready", "HTTP 代理": "HTTP proxy", + "MAA 等自动化任务要横屏,竖屏只适合自己玩": "Automation such as MAA needs landscape; portrait is for playing yourself", "Mirror 酱": "MirrorChyan", "Mirror 酱 CDK": "MirrorChyan CDK", "ModAVD 整包:模拟器、组件、脚本和管理器": "Full ModAVD package: emulator, components, scripts and manager", @@ -88,8 +89,10 @@ "上次补全组件已取消。": "The last fetch of components was canceled.", "上次补全组件没有成功:{reason}": "The last fetch of components failed: {reason}", "上次设置为 {last_language},之后保留安卓里的修改。": "Last set to {last_language}; changes made inside Android are kept afterwards.", + "下次开机生效。MAA 等自动化任务要横屏,竖屏只适合自己玩": "Takes effect at the next start. Automation such as MAA needs landscape; portrait is for playing yourself", "下次开机生效,带窗口和无头都有声音。开了会多占一些 CPU。": "Takes effect at the next start; sound works with a window and headless. It uses some more CPU.", "下次开机生效,自动化工具里的分辨率也要跟着改": "Takes effect at the next start; change the resolution in your automation tool as well", + "下次开机生效;跟随分辨率时 720p 是 240,1080p 是 280": "Takes effect at the next start; following the resolution is 240 at 720p and 280 at 1080p", "下次开机重新设置一次": "Set again at the next start", "下载…": "Download…", "下载源": "Download source", @@ -247,7 +250,7 @@ "实例照原样关着": "the instance was left off", "实例现在报 GLES 3.2": "The instance now reports GLES 3.2", "实例的数据(avd 文件夹)和设置都不动。正在新建的实例要先等它建完;用 modavd mcp 的 AI 助手等程序也要先关掉。": "Instance data (the avd folder) and settings are left untouched. Wait for instances being created to finish, and close programs such as AI assistants that use modavd mcp.", - "实例运行中,内存、CPU、帧率、分辨率、数据盘和声音在下次开机生效。诊断设置立即生效。": "The instance is running. Memory, CPU, frame rate, resolution, data disk and sound take effect at the next start; the diagnostics setting takes effect at once.", + "实例运行中,内存、CPU、帧率、分辨率、DPI、方向、数据盘和声音在下次开机生效。诊断设置立即生效。": "The instance is running. Memory, CPU, frame rate, resolution, DPI, orientation, data disk and sound take effect at the next start; the diagnostics setting takes effect at once.", "实例运行中,语言、时区和硬件设置在下次开机生效。诊断设置立即生效。": "The instance is running. Language, time zone and hardware settings take effect at the next start; the diagnostics setting takes effect at once.", "实例里没有装别的应用": "No other apps are installed in the instance", "实例里的 Google 服务框架联网登记后才有:开着网等一两分钟,再试一次。": "It exists once Google Services Framework in the instance has registered online: stay online for a minute or two, then try again.", @@ -383,6 +386,7 @@ "新建第一台实例": "Create the first instance", "新版已下载并核对好,待安装": "The new version is downloaded and verified, waiting to be installed", "新版没有换上": "The new version was not installed", + "方向": "Orientation", "无": "none", "无头": "headless", "日志是空的": "The log is empty", @@ -439,6 +443,7 @@ "模拟器刚拉起、安卓还没开机,已直接关掉(不用保存数据)": "The emulator had just launched and Android had not booted; it was stopped directly (no data to save)", "模拟器可能卡住了,过一会儿会再试": "The emulator may be stuck; it will try again shortly", "模拟器本来就在运行,只重做了开机后的设置。": "The emulator was already running; only the after-boot settings were redone.", + "横屏": "Landscape", "正在从这个下载源取许可协议…": "Getting the license agreement from this source…", "正在依次新建 {n} 台实例": "Creating {n} instances one after another", "正在保存…": "Saving…", @@ -547,6 +552,7 @@ "移除商店中": "Removing store", "稍后再试一次": "Try again in a moment", "立即生效。历史日志上限 4 GiB、客体内存最多增加 48 MiB;日志可能包含账号信息,仅保存在本机。": "Takes effect at once. Log history is capped at 4 GiB and guest memory grows by at most 48 MiB; logs may contain account information and stay on this computer only.", + "竖屏": "Portrait", "端口": "port", "等一会儿让登记生效,把实例关机再开机,再去登录。": "Wait a while for the registration to take effect, shut the instance down and start it again, then sign in.", "等它做完再下载": "Wait for it to finish, then download", @@ -613,6 +619,7 @@ "读不到诊断日志清理范围,请稍后重试": "Could not read the diagnostics log cleanup range. Try again later", "读取失败": "Read failed", "调小内存": "Lower memory", + "跟随分辨率": "Follow resolution", "跟随宿主": "Follow the host", "跟随系统": "Follow system", "跟随系统({language})": "Follow system ({language})", @@ -670,5 +677,6 @@ "首次初始化已完成": "initial setup done", "首次开机会做初始化,约 1⁠–⁠2 分钟": "The first start runs initial setup, about 1⁠–⁠2 minutes", "首次开机后才知道": "known after the first start", + "默认跟随分辨率:720p 是 240,1080p 是 280": "Follows the resolution by default: 240 at 720p, 280 at 1080p", "(可选)": " (optional)" } diff --git a/internal/mcp/mcp_test.go b/internal/mcp/mcp_test.go index 9fc74994..6b96bfac 100644 --- a/internal/mcp/mcp_test.go +++ b/internal/mcp/mcp_test.go @@ -776,9 +776,9 @@ func TestToolCalls(t *testing.T) { {"check_host", map[string]any{"memory_mb": 4096}, "check 4096"}, {"check_host", map[string]any{}, "check 0"}, {"create_instance", map[string]any{"title": "星铁", "index": 3, "memory_mb": 4096, "cpu": 4, - "data_partition_gb": 128, "fps": 30, "resolution": 720}, "create"}, + "data_partition_gb": 128, "fps": 30, "resolution": 720, "dpi": 320, "orientation": "portrait"}, "create"}, {"create_instance", map[string]any{}, "create"}, - {"update_instance", map[string]any{"index": 1, "memory_mb": 5120.0, "resolution": 1080}, "update 1"}, + {"update_instance", map[string]any{"index": 1, "memory_mb": 5120.0, "resolution": 1080, "dpi": 0, "orientation": "landscape"}, "update 1"}, {"delete_instance", map[string]any{"index": 2, "confirm": true}, "delete 2"}, {"start_instance", map[string]any{"index": 1, "window": true, "timeout_s": 120}, "start 1"}, {"start_instance", map[string]any{"index": 1}, "start 1"}, @@ -827,14 +827,16 @@ func TestToolCalls(t *testing.T) { f := h.f full := f.creates[0] if full.Title != "星铁" || *full.Index != 3 || *full.MemoryMB != 4096 || *full.CPU != 4 || *full.DataPartitionGB != 128 || - *full.FPS != 30 || full.Resolution == nil || *full.Resolution != 720 { + *full.FPS != 30 || full.Resolution == nil || *full.Resolution != 720 || full.DPI == nil || *full.DPI != 320 || + full.Orientation == nil || *full.Orientation != "portrait" { t.Fatalf("create request %+v", full) } if empty := f.creates[1]; empty.Title != "" || empty.Index != nil || empty.MemoryMB != nil || empty.CPU != nil || empty.DataPartitionGB != nil || empty.FPS != nil || empty.Resolution != nil { t.Fatalf("defaults must stay nil: %+v", empty) } - if u := f.updates[0]; u.Resolution == nil || *u.Resolution != 1080 || *u.MemoryMB != 5120 || u.Title != nil || u.CPU != nil || u.FPS != nil { + if u := f.updates[0]; u.Resolution == nil || *u.Resolution != 1080 || *u.MemoryMB != 5120 || u.Title != nil || u.CPU != nil || u.FPS != nil || + u.DPI == nil || *u.DPI != 0 || u.Orientation == nil || *u.Orientation != "landscape" { t.Fatalf("update request %+v", u) } if s := f.starts[0]; !s.Window || s.Headless || s.Timeout != 120*time.Second || s.Progress != nil { diff --git a/internal/mcp/tools.go b/internal/mcp/tools.go index 89f4893b..98238f8f 100644 --- a/internal/mcp/tools.go +++ b/internal/mcp/tools.go @@ -98,6 +98,14 @@ func resolutionProp(desc string) prop { return prop{"resolution", false, map[string]any{"type": "integer", "enum": avd.ResolutionChoices, "description": desc}} } +func dpiProp(desc string) prop { + return prop{"dpi", false, map[string]any{"type": "integer", "enum": append([]int{0}, avd.DPIChoices...), "description": desc}} +} + +func orientationProp(desc string) prop { + return prop{"orientation", false, map[string]any{"type": "string", "enum": avd.OrientationChoices, "description": desc}} +} + func timeoutProp(def time.Duration, desc string) prop { return prop{"timeout_s", false, map[string]any{"type": "integer", "minimum": 1, "maximum": maxTimeoutS, "default": int(def / time.Second), "description": desc}} @@ -203,6 +211,8 @@ func toolDefs() []*toolDef { "pays for what is written).", avd.AutoDataPartitionGB)}}, fpsProp("Display refresh rate in Hz, 1-60."), resolutionProp("Display preset: 1080 = 1920×1080 / DPI 280 (default), 720 = 1280×720 / DPI 240."), + dpiProp("Display density; 0 (default) = the resolution's own (720p 240, 1080p 280)."), + orientationProp("landscape (default) or portrait. Automation such as MAA needs landscape."), }, func(ctx context.Context, b backend, a args, progress func(emu.Progress)) (any, error) { var req emu.CreateRequest @@ -231,6 +241,12 @@ func toolDefs() []*toolDef { if req.Resolution, err = a.optInt("resolution"); err != nil { return nil, err } + if req.DPI, err = a.optInt("dpi"); err != nil { + return nil, err + } + if req.Orientation, err = a.optString("orientation"); err != nil { + return nil, err + } if progress != nil { req.Progress = func(p emu.Progress) { if p.Step != "done" { @@ -243,7 +259,7 @@ func toolDefs() []*toolDef { })), finishing(newTool("update_instance", "Update instance", - "Change the title, memory, CPU cores, frame rate, resolution, data disk (a fixed size or automatic) or sound of an instance. The changes take "+ + "Change the title, memory, CPU cores, frame rate, resolution, DPI, orientation, data disk (a fixed size or automatic) or sound of an instance. The changes take "+ "effect at its next boot (applies_next_boot=true when it is running now).", mutating(true, true), reflect.TypeFor[emu.UpdateResult](), []prop{ indexProp(true), @@ -251,7 +267,9 @@ func toolDefs() []*toolDef { memoryProp("New guest memory in MB."), cpuProp("New CPU core count."), fpsProp("New display refresh rate in Hz, 1-60."), - resolutionProp("Display preset: 1080 = 1920×1080 / DPI 280, 720 = 1280×720 / DPI 240. Preserves orientation; next boot."), + resolutionProp("Display preset: 1080 = 1920×1080 / DPI 280, 720 = 1280×720 / DPI 240. Preserves orientation and DPI; next boot."), + dpiProp("New display density; 0 = the resolution's own again (720p 240, 1080p 280). Next boot."), + orientationProp("New orientation: landscape or portrait. Automation such as MAA needs landscape. Next boot."), {"data_partition_gb", false, map[string]any{"type": "integer", "minimum": avd.MinDataPartitionGB, "maximum": avd.MaxDataPartitionGB, "description": "New data partition size in GB; can only be " + "raised, and the data disk then keeps this size (manual). Game data is kept: the emulator grows the " + @@ -283,6 +301,12 @@ func toolDefs() []*toolDef { if req.Resolution, err = a.optInt("resolution"); err != nil { return nil, err } + if req.DPI, err = a.optInt("dpi"); err != nil { + return nil, err + } + if req.Orientation, err = a.optString("orientation"); err != nil { + return nil, err + } if req.DataPartitionGB, err = a.optInt("data_partition_gb"); err != nil { return nil, err } @@ -294,9 +318,9 @@ func toolDefs() []*toolDef { if req.Sound, err = a.optBool("sound"); err != nil { return nil, err } - if req.Title == nil && req.MemoryMB == nil && req.CPU == nil && req.FPS == nil && req.Resolution == nil && req.DataPartitionGB == nil && - !req.DataDiskAuto && req.Sound == nil { - return nil, errs.New(errs.Usage, "没有要改的选项:title、memory_mb、cpu、fps、resolution、data_partition_gb、data_disk_auto、sound 至少给一项") + 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.Sound == nil { + return nil, errs.New(errs.Usage, "没有要改的选项:title、memory_mb、cpu、fps、resolution、dpi、orientation、data_partition_gb、data_disk_auto、sound 至少给一项") } return b.Update(ctx, i, req) })), diff --git a/internal/ui/API.en.md b/internal/ui/API.en.md index 0156db17..313c68d3 100644 --- a/internal/ui/API.en.md +++ b/internal/ui/API.en.md @@ -42,8 +42,8 @@ HTTP 4xx / 5xx with the body `{"error":{"code":"…","message":"…","advice":" | GET | `/api/instances` | | `ListResult` | | GET | `/api/instances/{i}` | | `InstanceInfo` | | GET | `/api/instances/{i}/regional` | | `RegionalResult` | -| POST | `/api/instances` | `{title?, index?, count?, memory_mb?, cpu?, data_partition_gb?, fps?, resolution?, language?: string, time_zone?: string}` | 202 `Job` (`kind` is `create`: without `data_partition_gb` the data disk is automatic (256 GB), with it a fixed size; it boots in the background, finishes the initial setup and shuts down again, which takes a few minutes. When `index` is not given, the server picks the number first, and `Job.index` is the new instance's; the result is an `InstanceInfo`). A new instance comes without the Google Play store (there is no `play_store` field; sending one returns 400). If you want it, use `playstore-install` below after the instance is created. `count` creates several at once (1–9, 1 when not given, not together with `index`): above 1 the server takes that many free numbers first (409 `busy` and nothing created when there are fewer), starts a `create` job for each at once and answers 202 `{jobs: [Job…]}`; the jobs run one after another in number order (a waiting one has `progress.step` `queued` and can be cancelled on its own), each checks the free space of the instances' disk before it starts and fails (`precheck_failed`) when it is too low; `title` gets a number (`T 1`, `T 2` …); one failing or cancelled does not stop the others | -| PATCH | `/api/instances/{i}` | `{title?, memory_mb?, cpu?, fps?, resolution?, data_partition_gb?, data_disk_auto?: bool, diagnostics?: bool, sound?: bool, boss_key?: string, language?: string, time_zone?: string}` | `UpdateResult`; the diagnostics setting and the boss key take effect immediately, ordinary configuration (`sound` too) at the next boot. `data_partition_gb` gives the data disk a fixed size (only larger), `data_disk_auto: true` makes it automatic; not both. When `boss_key` is given, the result has one more field `boss_key_taken` (bool): the new key was tried at once, and `true` means another program holds it (see "Boss keys and the tray" below) | +| POST | `/api/instances` | `{title?, index?, count?, memory_mb?, cpu?, data_partition_gb?, fps?, resolution?, dpi?, orientation?: string, language?: string, time_zone?: string}` | 202 `Job` (`kind` is `create`: without `data_partition_gb` the data disk is automatic (256 GB), with it a fixed size; it boots in the background, finishes the initial setup and shuts down again, which takes a few minutes. When `index` is not given, the server picks the number first, and `Job.index` is the new instance's; the result is an `InstanceInfo`). A new instance comes without the Google Play store (there is no `play_store` field; sending one returns 400). If you want it, use `playstore-install` below after the instance is created. `count` creates several at once (1–9, 1 when not given, not together with `index`): above 1 the server takes that many free numbers first (409 `busy` and nothing created when there are fewer), starts a `create` job for each at once and answers 202 `{jobs: [Job…]}`; the jobs run one after another in number order (a waiting one has `progress.step` `queued` and can be cancelled on its own), each checks the free space of the instances' disk before it starts and fails (`precheck_failed`) when it is too low; `title` gets a number (`T 1`, `T 2` …); one failing or cancelled does not stop the others | +| PATCH | `/api/instances/{i}` | `{title?, memory_mb?, cpu?, fps?, resolution?, dpi?, orientation?: string, data_partition_gb?, data_disk_auto?: bool, diagnostics?: bool, sound?: bool, boss_key?: string, language?: string, time_zone?: string}` | `UpdateResult`; the diagnostics setting and the boss key take effect immediately, ordinary configuration (`sound` too) at the next boot. `data_partition_gb` gives the data disk a fixed size (only larger), `data_disk_auto: true` makes it automatic; not both. When `boss_key` is given, the result has one more field `boss_key_taken` (bool): the new key was tried at once, and `true` means another program holds it (see "Boss keys and the tray" below) | | GET | `/api/instances/{i}/diagnostics/preview` | | `{"index","files","bytes"}`: the number of files and bytes that would be cleaned up when diagnostics is turned off; it changes no configuration and deletes no files | | DELETE | `/api/instances/{i}?confirm=1` | without `confirm=1` the server returns 400 `usage` | `DeleteResult` | | POST | `/api/instances/{i}/start` | `{}` | 202 `Job`: always boots with a window (the manager never boots headless; headless boot is command line only). If the instance is already running headless, the job fails with code `busy` (no switching while running) | @@ -243,4 +243,6 @@ ModAVD/ModAVD#101, Windows only. `resolution` accepts only 1080 and 720. A new instance defaults to 1080; they correspond to 1920×1080 / DPI 280 and 1280×720 / DPI 240 respectively; a change keeps the orientation and takes effect at the next boot. `InstanceInfo.config.resolution` is the tier recognized from the current configured width and height; after a change while running, it means the setting for the next boot. +`dpi` is 0 (follow the resolution, the default) or one of 160, 240, 280, 320, 400, 480. It is kept in `mas-avd.json` as `instances..dpi`, written to config.ini's `hw.lcd.density` before every boot and kept when the resolution changes; `config.dpi` is the DPI of the next boot, `config.dpi_setting` the value set (0 = follow the resolution). `orientation` is `landscape` (the default) or `portrait`, written to config.ini's `hw.initialOrientation`; the canvas stays the wide 1280×720 / 1920×1080, and after boot Android's `user_rotation` is 0 for landscape and 3 for portrait (the emulator sets the same from 0.43.0). `config.orientation` is the current setting. Both take effect at the next boot. Automation such as MAA needs landscape; portrait is for playing yourself. + Tap coordinates on the screen are converted and validated against the size of the current screenshot. When the tier is changed while running, `config` means the setting for the next boot, and the current picture and tap coordinates keep the old size until the restart. diff --git a/internal/ui/API.md b/internal/ui/API.md index d5e51ac3..9cd7b675 100644 --- a/internal/ui/API.md +++ b/internal/ui/API.md @@ -42,8 +42,8 @@ HTTP 4xx / 5xx,体为 `{"error":{"code":"…","message":"…","advice":"…"," | GET | `/api/instances` | | `ListResult` | | GET | `/api/instances/{i}` | | `InstanceInfo` | | GET | `/api/instances/{i}/regional` | | `RegionalResult` | -| POST | `/api/instances` | `{title?, index?, count?, memory_mb?, cpu?, data_partition_gb?, fps?, resolution?, language?: string, time_zone?: string}` | 202 `Job`(`kind` 是 `create`:不给 `data_partition_gb` 是自动扩盘(256 GB),给了是指定大小;后台开机做完初始化再关机,要几分钟;没给 `index` 时服务端先选好编号,`Job.index` 就是新实例的;结果是 `InstanceInfo`)。新建的实例不带 Google Play 商店(没有 `play_store` 字段,给了回 400),要的话建好后用下面的 `playstore-install`。`count` 是一次建几台(1–9,不给是 1,不能和 `index` 一起给):大于 1 时服务端先取好这么多个空闲编号(不够就 409 `busy`,一台不建),每台当场开一个 `create` 任务,回 202 `{jobs: [Job…]}`;任务按编号一台做完再做下一台(排着的 `progress.step` 是 `queued`,可以单独取消),每台开建前查实例所在盘的剩余空间,不够那一台失败(`precheck_failed`);`title` 后面加序号(`T 1`、`T 2`…);一台失败或取消不影响别的 | -| PATCH | `/api/instances/{i}` | `{title?, memory_mb?, cpu?, fps?, resolution?, data_partition_gb?, data_disk_auto?: bool, diagnostics?: bool, sound?: bool, boss_key?: string, language?: string, time_zone?: string}` | `UpdateResult`;诊断和老板键立即生效,普通配置(声音 `sound` 也是)下次开机生效。`data_partition_gb` 把数据盘改成指定大小(只能改大),`data_disk_auto: true` 改成自动扩盘,两个不能同时给。给了 `boss_key` 时多一个 `boss_key_taken`(bool):新键当场试注册过,被别的程序占着是 `true`(见下「老板键和托盘」) | +| POST | `/api/instances` | `{title?, index?, count?, memory_mb?, cpu?, data_partition_gb?, fps?, resolution?, dpi?, orientation?: string, language?: string, time_zone?: string}` | 202 `Job`(`kind` 是 `create`:不给 `data_partition_gb` 是自动扩盘(256 GB),给了是指定大小;后台开机做完初始化再关机,要几分钟;没给 `index` 时服务端先选好编号,`Job.index` 就是新实例的;结果是 `InstanceInfo`)。新建的实例不带 Google Play 商店(没有 `play_store` 字段,给了回 400),要的话建好后用下面的 `playstore-install`。`count` 是一次建几台(1–9,不给是 1,不能和 `index` 一起给):大于 1 时服务端先取好这么多个空闲编号(不够就 409 `busy`,一台不建),每台当场开一个 `create` 任务,回 202 `{jobs: [Job…]}`;任务按编号一台做完再做下一台(排着的 `progress.step` 是 `queued`,可以单独取消),每台开建前查实例所在盘的剩余空间,不够那一台失败(`precheck_failed`);`title` 后面加序号(`T 1`、`T 2`…);一台失败或取消不影响别的 | +| PATCH | `/api/instances/{i}` | `{title?, memory_mb?, cpu?, fps?, resolution?, dpi?, orientation?: string, data_partition_gb?, data_disk_auto?: bool, diagnostics?: bool, sound?: bool, boss_key?: string, language?: string, time_zone?: string}` | `UpdateResult`;诊断和老板键立即生效,普通配置(声音 `sound` 也是)下次开机生效。`data_partition_gb` 把数据盘改成指定大小(只能改大),`data_disk_auto: true` 改成自动扩盘,两个不能同时给。给了 `boss_key` 时多一个 `boss_key_taken`(bool):新键当场试注册过,被别的程序占着是 `true`(见下「老板键和托盘」) | | GET | `/api/instances/{i}/diagnostics/preview` | | `{"index","files","bytes"}`:关闭诊断时预计清理的份数、字节,不改配置、不删文件 | | DELETE | `/api/instances/{i}?confirm=1` | 不带 `confirm=1` 回 400 `usage` | `DeleteResult` | | POST | `/api/instances/{i}/start` | `{}` | 202 `Job`:一律带窗口开机(管理器不开无头的,无头开机只走命令行);实例要先装执行桥时,装桥这几次准备用的开机都无头,装好后正常关机,最后一次带窗口开机(同 `modavd start --window`);实例已经以无头方式在运行时,任务失败,code 是 `busy`(运行中不切换) | @@ -243,4 +243,6 @@ ModAVD/ModAVD#101,只有 Windows。 `resolution` 只接受 1080 和 720。新建默认 1080,分别联动 1920×1080 / DPI 280 与 1280×720 / DPI 240;修改保留方向,下次开机生效。`InstanceInfo.config.resolution` 是按当前配置宽高识别的档位,运行中修改后表示下次开机的设置。 +`dpi` 是 0(跟随分辨率,默认)或 160、240、280、320、400、480 之一,记在 `mas-avd.json` 的 `instances..dpi`,每次开机前写进 config.ini 的 `hw.lcd.density`,换分辨率时保留;`config.dpi` 是下次开机用的 DPI,`config.dpi_setting` 是设的值(0 = 跟随分辨率)。`orientation` 是 `landscape`(横屏,默认)或 `portrait`(竖屏),写进 config.ini 的 `hw.initialOrientation`,画布仍是横的 1280×720 / 1920×1080,开机后安卓的 `user_rotation` 横屏是 0、竖屏是 3(模拟器 0.43.0 起也按这个值设);`config.orientation` 是当前设置。两项都下次开机生效。MAA 等自动化任务要横屏,竖屏只适合自己玩。 + 画面点击按当前截图的尺寸换算并校验。运行中改档时,`config` 表示下次开机设置,当前画面和点击坐标在重启前保持原尺寸。 diff --git a/internal/ui/handlers.go b/internal/ui/handlers.go index e73e5b24..72338c77 100644 --- a/internal/ui/handlers.go +++ b/internal/ui/handlers.go @@ -64,6 +64,8 @@ func (s *server) handleCreate(w http.ResponseWriter, r *http.Request) { DataPartitionGB *int `json:"data_partition_gb"` FPS *int `json:"fps"` Resolution *int `json:"resolution"` + DPI *int `json:"dpi"` + Orientation *string `json:"orientation"` Count *int `json:"count"` } if !decode(w, r, &body) { @@ -71,7 +73,8 @@ func (s *server) handleCreate(w http.ResponseWriter, r *http.Request) { } req := emu.CreateRequest{Index: body.Index, MemoryMB: body.MemoryMB, CPU: body.CPU, Language: body.Language, TimeZone: body.TimeZone, - DataPartitionGB: body.DataPartitionGB, FPS: body.FPS, Resolution: body.Resolution} + DataPartitionGB: body.DataPartitionGB, FPS: body.FPS, Resolution: body.Resolution, + DPI: body.DPI, Orientation: body.Orientation} if body.Title != nil { req.Title = *body.Title } @@ -202,6 +205,8 @@ func (s *server) handleUpdate(w http.ResponseWriter, r *http.Request) { CPU *int `json:"cpu"` FPS *int `json:"fps"` Resolution *int `json:"resolution"` + DPI *int `json:"dpi"` + Orientation *string `json:"orientation"` DataPartitionGB *int `json:"data_partition_gb"` DataDiskAuto bool `json:"data_disk_auto"` BossKey *string `json:"boss_key"` @@ -210,9 +215,9 @@ func (s *server) handleUpdate(w http.ResponseWriter, r *http.Request) { if !decode(w, r, &body) { return } - if body.Title == nil && body.MemoryMB == nil && body.CPU == nil && body.FPS == nil && body.Resolution == nil && body.DataPartitionGB == nil && - !body.DataDiskAuto && body.Diagnostics == nil && body.Sound == nil && body.BossKey == nil && body.Language == nil && body.TimeZone == nil { - writeError(w, errs.New(errs.Usage, "没有要改的设置").WithAdvice("至少给出 title、memory_mb、cpu、fps、resolution、data_partition_gb、data_disk_auto、language、time_zone、diagnostics、sound、boss_key 中的一项")) + if body.Title == nil && body.MemoryMB == nil && body.CPU == nil && body.FPS == nil && body.Resolution == nil && body.DPI == nil && body.Orientation == nil && + body.DataPartitionGB == nil && !body.DataDiskAuto && body.Diagnostics == nil && body.Sound == nil && body.BossKey == nil && body.Language == nil && body.TimeZone == nil { + writeError(w, errs.New(errs.Usage, "没有要改的设置").WithAdvice("至少给出 title、memory_mb、cpu、fps、resolution、dpi、orientation、data_partition_gb、data_disk_auto、language、time_zone、diagnostics、sound、boss_key 中的一项")) return } release, err := s.beginInstanceAction(kindSettings, i) @@ -223,7 +228,8 @@ func (s *server) handleUpdate(w http.ResponseWriter, r *http.Request) { defer release() res, err := s.mgr.Update(detached(r), i, emu.UpdateRequest{Title: body.Title, MemoryMB: body.MemoryMB, CPU: body.CPU, Language: body.Language, TimeZone: body.TimeZone, - FPS: body.FPS, Resolution: body.Resolution, DataPartitionGB: body.DataPartitionGB, DataDiskAuto: body.DataDiskAuto, + FPS: body.FPS, Resolution: body.Resolution, DPI: body.DPI, Orientation: body.Orientation, + DataPartitionGB: body.DataPartitionGB, DataDiskAuto: body.DataDiskAuto, Diagnostics: body.Diagnostics, BossKey: body.BossKey, Sound: body.Sound}) if err != nil { writeError(w, err) diff --git a/internal/ui/http_test.go b/internal/ui/http_test.go index 5c2dadbb..e9e7cd40 100644 --- a/internal/ui/http_test.go +++ b/internal/ui/http_test.go @@ -134,7 +134,7 @@ func TestCreateUpdateDelete(t *testing.T) { } return h.waitJob(v.ID, stateIs(stateDone)) } - j := create(map[string]any{"title": "测试机", "index": 2, "memory_mb": 4096, "cpu": 4, "data_partition_gb": 32, "fps": 30, "resolution": 720}) + j := create(map[string]any{"title": "测试机", "index": 2, "memory_mb": 4096, "cpu": 4, "data_partition_gb": 32, "fps": 30, "resolution": 720, "dpi": 320, "orientation": "portrait"}) if res, _ := j.Result.(map[string]any); j.Index != 2 || res["title"] != "测试机" { t.Fatalf("created %+v", j) } @@ -153,7 +153,7 @@ func TestCreateUpdateDelete(t *testing.T) { } r := c[0] if r.Title != "测试机" || *r.Index != 2 || *r.MemoryMB != 4096 || *r.CPU != 4 || *r.DataPartitionGB != 32 || *r.FPS != 30 || r.Resolution == nil || *r.Resolution != 720 || - r.Progress == nil || r.Resume { + r.DPI == nil || *r.DPI != 320 || r.Orientation == nil || *r.Orientation != "portrait" || r.Progress == nil || r.Resume { t.Fatalf("create request %+v", r) } if r := c[1]; r.Title != "" || r.Index == nil || *r.Index != auto1.Index || r.MemoryMB != nil || r.CPU != nil || r.DataPartitionGB != nil || r.FPS != nil || r.Resolution != nil { @@ -178,7 +178,7 @@ func TestCreateUpdateDelete(t *testing.T) { // update expectError(t, h.do("PATCH", "/api/instances/2", "{}"), 400, errs.Usage) var up emu.UpdateResult - expect(t, h.do("PATCH", "/api/instances/2", `{"fps":30,"resolution":1080}`), http.StatusOK, &up) + expect(t, h.do("PATCH", "/api/instances/2", `{"fps":30,"resolution":1080,"dpi":0,"orientation":"landscape"}`), http.StatusOK, &up) if up.Applied["fps"] != float64(30) { t.Fatalf("update result %+v", up) } @@ -189,7 +189,7 @@ func TestCreateUpdateDelete(t *testing.T) { u := h.f.updated h.f.mu.Unlock() if len(u) != 4 || u[0].Resolution == nil || *u[0].Resolution != 1080 || *u[0].FPS != 30 || u[0].Title != nil || u[0].MemoryMB != nil || u[0].CPU != nil || - u[0].DataPartitionGB != nil { + u[0].DataPartitionGB != nil || u[0].DPI == nil || *u[0].DPI != 0 || u[0].Orientation == nil || *u[0].Orientation != "landscape" { t.Fatalf("update requests %+v", u) } if *u[1].Title != "新名字" || *u[1].MemoryMB != 8192 || *u[1].CPU != 8 || u[1].FPS != nil { diff --git a/internal/ui/web/dev/mock.js b/internal/ui/web/dev/mock.js index 73e1c126..8bb6d524 100644 --- a/internal/ui/web/dev/mock.js +++ b/internal/ui/web/dev/mock.js @@ -50,7 +50,7 @@ function mk(i, title, o = {}) { ports: { console, adb: console + 1, grpc: console + 2 }, screencap: { shm: 'SHM_videmulator' + console, shm_ready: st === 'online' }, // o.disk: a size the user set (manual); without it 自动扩盘 (256 GB) - config: { memory_mb: o.mem || 6144, cpu: o.cpu || 6, fps: o.fps || 60, data_partition_gb: o.disk || 256, data_disk_mode: o.disk ? 'manual' : 'auto', resolution: o.resolution || 720, width: o.resolution === 1080 ? 1920 : 1280, height: o.resolution === 1080 ? 1080 : 720, dpi: o.resolution === 1080 ? 280 : 240, sound: !!o.sound }, + config: { memory_mb: o.mem || 6144, cpu: o.cpu || 6, fps: o.fps || 60, data_partition_gb: o.disk || 256, data_disk_mode: o.disk ? 'manual' : 'auto', resolution: o.resolution || 720, width: o.resolution === 1080 ? 1920 : 1280, height: o.resolution === 1080 ? 1080 : 720, dpi: o.dpi || (o.resolution === 1080 ? 280 : 240), dpi_setting: o.dpi || 0, orientation: o.orientation || 'landscape', sound: !!o.sound }, initialized, launcher: initialized ? 'µLauncher' : '', renderer: initialized ? (o.sw ? SWIFT : GPU) : '', software_renderer: !!o.sw, path: `${ROOT}\\avd\\mas_${i}.avd`, @@ -856,6 +856,8 @@ function validate(b, create) { if (b.memory_mb != null && !MEM.includes(b.memory_mb)) return ['invalid_argument', `内存只能选 3、4、5、6、8 GB(收到 ${b.memory_mb} MB)`, '']; if (b.cpu != null && ![2, 4, 6].includes(b.cpu)) return ['invalid_argument', `CPU 核数只能是 2、4 或 6(收到 ${b.cpu})`, '']; if (b.resolution != null && ![1080, 720].includes(b.resolution)) return ['invalid_argument', '分辨率只能是 1080 或 720', '']; + if (b.dpi != null && ![0, 160, 240, 280, 320, 400, 480].includes(b.dpi)) return ['invalid_argument', 'DPI 只能选 160 / 240 / 280 / 320 / 400 / 480,或 0(跟随分辨率)', '']; + if (b.orientation != null && !['landscape', 'portrait'].includes(b.orientation)) return ['invalid_argument', '方向只能选 landscape(横屏)或 portrait(竖屏)', '']; if (b.fps != null && !(Number.isInteger(b.fps) && b.fps >= 1 && b.fps <= 60)) return ['invalid_argument', '帧率只能在 1–60 之间', '']; if (create && b.data_partition_gb != null && (!Number.isInteger(b.data_partition_gb) || b.data_partition_gb < 16 || b.data_partition_gb > 512)) { return ['invalid_argument', `数据盘上限只能是 16–512 GB 的整数(收到 ${b.data_partition_gb})`, '']; @@ -890,7 +892,7 @@ async function handle(url, init) { if (!INDEXES.includes(i)) return errResp('invalid_argument', `实例编号 ${i} 不可用(只能是 0–9,5 除外)`); if (db.insts.has(i)) return errResp('already_exists', `实例 mas_${i} 已存在`); await sleep(500); - const inst = mk(i, body.title, { mem: body.memory_mb, cpu: body.cpu, fps: body.fps, resolution: body.resolution || 1080, disk: body.data_partition_gb, initialized: false, scene: i }); + const inst = mk(i, body.title, { mem: body.memory_mb, cpu: body.cpu, fps: body.fps, resolution: body.resolution || 1080, dpi: body.dpi, orientation: body.orientation, disk: body.data_partition_gb, initialized: false, scene: i }); log('info', `已新建 ModAVD 实例 ${i}(内存 ${inst.config.memory_mb} MB / ${inst.config.cpu} 核 / 数据盘 ${body.data_partition_gb ? inst.config.data_partition_gb + ' GB' : '自动扩盘'} / 帧率 ${inst.config.fps})`); emit('instances', list()); return json(pub(inst), 201); @@ -999,9 +1001,18 @@ async function handle(url, init) { if (body.resolution != null) { const portrait = inst.config.height > inst.config.width; const w = body.resolution === 1080 ? 1920 : 1280, h = body.resolution; - Object.assign(inst.config, { resolution: body.resolution, width: portrait ? h : w, height: portrait ? w : h, dpi: body.resolution === 1080 ? 280 : 240 }); + Object.assign(inst.config, { resolution: body.resolution, width: portrait ? h : w, height: portrait ? w : h, dpi: inst.config.dpi_setting || (body.resolution === 1080 ? 280 : 240) }); applied.resolution = body.resolution; } + if (body.dpi != null) { + Object.assign(inst.config, { dpi_setting: body.dpi, dpi: body.dpi || (inst.config.resolution === 1080 ? 280 : 240) }); + applied.dpi = body.dpi; + } + if (body.orientation != null) { + const w = inst.config.resolution === 1080 ? 1920 : 1280; + Object.assign(inst.config, { orientation: body.orientation, width: w, height: inst.config.resolution }); + applied.orientation = body.orientation; + } for (const k of ['memory_mb', 'cpu', 'fps', 'sound']) if (body[k] != null) { inst.config[k] = body[k]; applied[k] = body[k]; } // the data disk: 自动扩盘, or a size that can only grow if (body.data_disk_auto && body.data_partition_gb != null) return errResp('invalid_argument', '数据盘只能二选一:自动扩盘,或者指定大小'); diff --git a/internal/ui/web/js/forms.js b/internal/ui/web/js/forms.js index a3d7149a..a434fa86 100644 --- a/internal/ui/web/js/forms.js +++ b/internal/ui/web/js/forms.js @@ -14,6 +14,10 @@ const CPU = [[2, t('2 核')], [4, t('4 核')], [6, t('6 核')]]; const FPS_MIN = 1; const FPS_MAX = 60; const RESOLUTION = [[1080, '1080p'], [720, '720p']]; +// DPI (ModAVD#247): 0 follows the resolution (720p 240, 1080p 280) +const DPI = [[0, t('跟随分辨率')], [160, '160'], [240, '240'], [280, '280'], [320, '320'], [400, '400'], [480, '480']]; +const ORIENTATION = [['landscape', t('横屏')], ['portrait', t('竖屏')]]; +const ORIENTATION_HINT = t('MAA 等自动化任务要横屏,竖屏只适合自己玩'); const INDEXES = [0, 1, 2, 3, 4, 6, 7, 8, 9]; const MIN12 = t('约 1⁠–⁠2 分钟'); const CREATE_TIME = t('一般要几分钟'); @@ -182,6 +186,8 @@ export function openCreate() { segRow('CPU', 'cpu', CPU, 6), fps.rows, segRow(t('分辨率'), 'resolution', RESOLUTION, 1080, hint(t('720p 更省资源'))), + segRow('DPI', 'dpi', DPI, 0, hint(t('默认跟随分辨率:720p 是 240,1080p 是 280'))), + segRow(t('方向'), 'orientation', ORIENTATION, 'landscape', hint(ORIENTATION_HINT)), disk.rows, regional && regional.rows), box), actions: { ok }, onSubmit() { @@ -203,7 +209,8 @@ export function openCreate() { ...(regional ? regional.values() : {}), title: title.value.trim() || undefined, memory_mb: Number(f.memory.value), cpu: Number(f.cpu.value), // no size: 自动扩盘 - fps: fpsValue, resolution: Number(f.resolution.value), data_partition_gb: d.auto ? undefined : d.gb, + fps: fpsValue, resolution: Number(f.resolution.value), dpi: Number(f.dpi.value) || undefined, + orientation: f.orientation.value === 'portrait' ? 'portrait' : undefined, data_partition_gb: d.auto ? undefined : d.gb, count: n > 1 ? n : undefined, }); // several: a job each, run one after another by the server (the later ones wait in 活动) @@ -231,7 +238,7 @@ export function openSettings(i, field) { const initSound = cfg.sound === true; const sound = h('input', { type: 'checkbox', id: 's-sound', checked: initSound, 'aria-describedby': 's-sound-h' }); const boss = bossKeyField(inst0.boss_key || '', () => dirty()); - const runNote = h('div', { class: 'note-box tone-warn', role: 'status' }, icon('info'), h('span', { text: t('实例运行中,内存、CPU、帧率、分辨率、数据盘和声音在下次开机生效。诊断设置立即生效。') })); + const runNote = h('div', { class: 'note-box tone-warn', role: 'status' }, icon('info'), h('span', { text: t('实例运行中,内存、CPU、帧率、分辨率、DPI、方向、数据盘和声音在下次开机生效。诊断设置立即生效。') })); const kv = h('dl', { class: 'kv' }); const fps = fpsField('s', cfg.fps); const diskAuto0 = cfg.data_disk_mode !== 'manual'; @@ -255,6 +262,8 @@ export function openSettings(i, field) { segRow('CPU', 'cpu', CPU, cfg.cpu), fps.rows, segRow(t('分辨率'), 'resolution', RESOLUTION, cfg.resolution, hint(t('下次开机生效,自动化工具里的分辨率也要跟着改'))), + segRow('DPI', 'dpi', DPI, cfg.dpi_setting || 0, hint(t('下次开机生效;跟随分辨率时 720p 是 240,1080p 是 280'))), + segRow(t('方向'), 'orientation', ORIENTATION, cfg.orientation || 'landscape', hint(t('下次开机生效。MAA 等自动化任务要横屏,竖屏只适合自己玩'))), disk.rows, inputRow(t('声音'), h('span', { class: 'checkbox p-switch' }, sound), hint(t('下次开机生效,带窗口和无头都有声音。开了会多占一些 CPU。'), 's-sound-h')), @@ -278,10 +287,12 @@ export function openSettings(i, field) { if (sound.checked !== initSound) out.sound = sound.checked; if (boss.changed()) out.boss_key = boss.value(); if (regional) Object.assign(out, regional.changes()); - for (const [k, key] of [['memory', 'memory_mb'], ['cpu', 'cpu'], ['fps', 'fps'], ['resolution', 'resolution']]) { + for (const [k, key] of [['memory', 'memory_mb'], ['cpu', 'cpu'], ['fps', 'fps'], ['resolution', 'resolution'], ['dpi', 'dpi_setting']]) { const v = f[k].value === '' ? null : Number(f[k].value); - if (v != null && v !== cfg[key]) out[key] = v; + const cur = key === 'dpi_setting' ? (cfg.dpi_setting || 0) : cfg[key]; + if (v != null && v !== cur) out[key === 'dpi_setting' ? 'dpi' : key] = v; } + if (f.orientation.value && f.orientation.value !== (cfg.orientation || 'landscape')) out.orientation = f.orientation.value; // 自动扩盘 or a size; an invalid size is no change yet (saving shows the error) const d = disk.value(true); if (d && d.auto && !diskAuto0) out.data_disk_auto = true; diff --git a/scripts/test_resolution_guards.py b/scripts/test_resolution_guards.py index a980869d..910fe27b 100644 --- a/scripts/test_resolution_guards.py +++ b/scripts/test_resolution_guards.py @@ -22,9 +22,13 @@ ("orientation", "internal/avd/avd.go", "avd", "TestResolutionCreateSwitchAndReboot", "if h > w {", "if false && h > w {"), ("update persistence", "internal/avd/avd.go", "avd", "TestResolutionCreateSwitchAndReboot", - "changes = append(changes, displayChanges(in.Config, resolution)...)", "_ = resolution"), + "changes = append(changes, displayChanges(in.Config, res, orientation, dpi)...)", "_, _, _ = res, orientation, dpi"), ("pre-boot preset", "internal/avd/avd.go", "avd", "TestResolutionCreateSwitchAndReboot", - "displayChanges(cfg, resolutionFor(cfg))", "displayChanges(cfg, 720)"), + "displayChanges(cfg, resolutionFor(cfg), \"\", dpi)", "displayChanges(cfg, 720, \"\", dpi)"), + ("pre-boot dpi", "internal/avd/avd.go", "avd", "TestDPIAndOrientation", + "changes := DisplayChanges(cfg, DPIMeta(r.InstanceMeta(i)))", "changes := DisplayChanges(cfg, 0)"), + ("orientation key", "internal/avd/avd.go", "avd", "TestDPIAndOrientation", + "changes = append(changes, [2]string{\"hw.initialOrientation\", orientation})", "_ = orientation"), ("CLI create wiring", "internal/cli/commands.go", "cli", "TestBuildCreateRequest", 'req.Resolution = intPtrOpt(inv, "resolution")', "req.Resolution = nil"), ("CLI update wiring", "internal/cli/commands.go", "cli", "TestBuildUpdateRequest",