dsh-apk-vm 0.12.0 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/android.js CHANGED
@@ -71,6 +71,8 @@ export const DEFAULT_OPTIONS = Object.freeze({
71
71
  avdName: null, // AVD name — required to enable spawning
72
72
  spawnEmulator: true, // spawn only when emulatorPath+avdName are configured
73
73
  emulatorArgs: [], // extra argv appended to the emulator command line
74
+ extraEmulatorArgs: [], // additional argv appended after emulatorArgs (virtual camera/mic flags)
75
+ enableAudio: false, // when true omit -no-audio so host/remote audio INPUT reaches the guest
74
76
 
75
77
  // device selection
76
78
  serial: null, // authoritative adb serial (e.g. '127.0.0.1:5555', 'emulator-5558')
@@ -774,6 +776,13 @@ export class AndroidVm {
774
776
  : resolveEmulatorPath({ sdkRoot: this.sdkRoot });
775
777
  this.avdName = opts.avdName ? String(opts.avdName) : null;
776
778
  this.emulatorArgs = Array.isArray(opts.emulatorArgs) ? opts.emulatorArgs.map(String) : [];
779
+ // Media/camera/mic flags (see lib/media.js) appended after emulatorArgs.
780
+ // Kept mutable on purpose so a running panel can enable a virtual camera or
781
+ // microphone before the next emulator start without rebuilding the VM.
782
+ this.extraEmulatorArgs = Array.isArray(opts.extraEmulatorArgs)
783
+ ? opts.extraEmulatorArgs.map(String).filter((arg) => arg.trim().length > 0)
784
+ : [];
785
+ this.enableAudio = opts.enableAudio === true;
777
786
  this.spawnEmulatorEnabled = opts.spawnEmulator !== false;
778
787
 
779
788
  this.serial = opts.serial ? String(opts.serial) : null;
@@ -4381,7 +4390,9 @@ export class AndroidVm {
4381
4390
  return { args: [], bootKind: 'cold', accelAvailable, snapshotAvailable, fatal: message };
4382
4391
  }
4383
4392
  const bootKind = snapshotAvailable ? 'snapshot' : 'cold';
4384
- const args = ['-avd', this.avdName, '-no-window', '-no-audio', '-no-boot-anim', '-no-metrics'];
4393
+ const args = ['-avd', this.avdName, '-no-window'];
4394
+ if (!this.enableAudio) args.push('-no-audio');
4395
+ args.push('-no-boot-anim', '-no-metrics');
4385
4396
  if (snapshotAvailable) {
4386
4397
  args.push('-snapshot', this.snapshotName);
4387
4398
  } else if (!this.quickBoot) {
@@ -4397,9 +4408,45 @@ export class AndroidVm {
4397
4408
  if (this.dnsServers.length) args.push('-dns-server', this.dnsServers.join(','));
4398
4409
  if (this.tcpdumpPath) args.push('-tcpdump', this.tcpdumpPath);
4399
4410
  args.push(...this.emulatorArgs);
4411
+ this._appendExtraEmulatorArgs(args);
4400
4412
  return { args, bootKind, accelAvailable, snapshotAvailable };
4401
4413
  }
4402
4414
 
4415
+ /**
4416
+ * Append `this.extraEmulatorArgs` to a composed emulator argv.
4417
+ *
4418
+ * The extra args are the virtual-camera/microphone flags produced by
4419
+ * lib/media.js (mediaLaunchOptions().extraEmulatorArgs). They are appended
4420
+ * after the built-in `emulatorArgs` so the media flags win where the emulator
4421
+ * honours last-wins. A switch already present in the built-out argv (for
4422
+ * example a `-camera-back` passed through `emulatorArgs`) is skipped together
4423
+ * with its value token, which keeps the argv valid instead of emitting two
4424
+ * different settings for one switch. Repeated switches *within* the extra
4425
+ * list are preserved because some flags legitimately repeat
4426
+ * (`-virtualscene-poster`).
4427
+ */
4428
+ _appendExtraEmulatorArgs(args) {
4429
+ const extra = Array.isArray(this.extraEmulatorArgs) ? this.extraEmulatorArgs : [];
4430
+ if (!extra.length) return args;
4431
+ // Snapshot the switches already composed; do not grow it while appending,
4432
+ // so repeated flags inside `extra` are all emitted.
4433
+ const existing = new Set(
4434
+ args.filter((arg) => typeof arg === 'string' && arg.startsWith('-')),
4435
+ );
4436
+ for (let index = 0; index < extra.length; index += 1) {
4437
+ const arg = extra[index];
4438
+ if (typeof arg !== 'string' || !arg) continue;
4439
+ const isSwitch = arg.startsWith('-');
4440
+ if (isSwitch && existing.has(arg)) {
4441
+ const next = extra[index + 1];
4442
+ if (typeof next === 'string' && !next.startsWith('-')) index += 1;
4443
+ continue;
4444
+ }
4445
+ args.push(arg);
4446
+ }
4447
+ return args;
4448
+ }
4449
+
4403
4450
  /** Save a quick-boot snapshot of the running device (deduplicated). */
4404
4451
  async saveSnapshot(name) {
4405
4452
  const serial = this._serialActive || this.serial;