diff --git a/.eslintrc.json b/.eslintrc.json index 3883001..befe3fc 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -19,6 +19,7 @@ "indent": ["error", 2], "linebreak-style": ["error", "unix"], "quotes": ["error", "single"], - "semi": ["error", "always"] + "semi": ["error", "always"], + "@typescript-eslint/ban-types": "off" } } diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d7ff59b..45e914f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -64,8 +64,6 @@ jobs: - name: Setup Android SDK uses: amyu/setup-android@v3.1 - with: - cache-disabled: true - name: Run tests 👩🏽‍💻 run: npm run test diff --git a/spec/afterStart.test.ts b/spec/afterStart.test.ts index d4a1063..313748d 100644 --- a/spec/afterStart.test.ts +++ b/spec/afterStart.test.ts @@ -16,7 +16,14 @@ beforeAll(async () => { } else { avdName = avds[0].Name; } - const res = await android.start(avdName); + const res = await android.start({ + avd: avdName, + verbose: true, + noaudio: true, + noBootAnim: true, + noSnapshot: true, + noWindow: true + }); emulatorId = res.id; if (emulatorId) { await android.ensureReady(emulatorId); diff --git a/spec/start.test.ts b/spec/start.test.ts index 829cee4..9211f5f 100644 --- a/spec/start.test.ts +++ b/spec/start.test.ts @@ -5,7 +5,14 @@ describe('start', () => { test('start a non-existent AVD.', async () => { await expect(async () => { - await android.start(`${Math.random()}`); + await android.start({ + verbose: true, + avd: `${Math.random()}`, + noaudio: true, + noBootAnim: true, + noSnapshot: true, + noWindow: true + }); }).rejects.toThrow(/Android emulator version/); }); }); diff --git a/src/emulator.ts b/src/emulator.ts new file mode 100644 index 0000000..0f457e8 --- /dev/null +++ b/src/emulator.ts @@ -0,0 +1,299 @@ +export interface EmulatorOptions { + /** disable graphical window display */ + noWindow?: boolean; + /** perform a full boot and do not auto-save, but qemu vmload and vmsave operate on snapstorage */ + noSnapshot?: boolean; + /** do not mount a snapshot storage file (this disables all snapshot functionality) */ + noSnapstorage?: boolean; + /** do not try to correct snapshot time on restore */ + noSnapshotUpdateTime?: boolean; + /** do not auto-save to snapshot on exit: abandon changed state */ + noSnapshotSave?: boolean; + /** do not auto-start from snapshot: perform a full boot */ + noSnapshotLoad?: boolean; + /** set emulation mode for a camera facing back */ + cameraBack?: CameraBack; + /** set emulation mode for a camera facing front */ + cameraFront?: CameraFront; + /** set hardware OpenGLES emulation mode */ + gpu?: EmulatorGpu; + /** disable the cache partition */ + nocache?: boolean; + /** disable audio support */ + noaudio?: boolean; + /** disable animation for faster boot */ + noBootAnim?: boolean; + /** device is a low ram device */ + lowram?: boolean; + /** Allows restarting guest when it is stalled. */ + restartWhenStalled?: boolean; + /** Pause on launch and wait for a debugger process to attach before resuming */ + waitForDebugger?: boolean; + /** make TCP connections through a HTTP/HTTPS proxy */ + httpProxy?: string; + /** Set number of CPU cores to emulator */ + cores?: number; + /** reset the user data image (copy it from initdata) */ + wipeData?: boolean; + /** disable passive gps updates */ + noPassiveGps?: boolean; + /** use a specific android virtual device */ + avd?: string; + /** enable specific debug messages */ + verbose?: boolean; +} + +/** + * Use -camera-back to control emulation of a camera facing back. + * @value __emulated__ camera will be emulated using software ('fake') camera emulation + * @value __virtualscene__ If the feature is enabled, camera will render a virtual scene + * @value __videoplayback__ If the feature is enabled, camera will support playing back a video + * @value __none__ camera emulation will be disabled + * @value __webcam\__ camera will be emulated using a webcamera connected to the host + */ +export type CameraBack = 'emulated' | 'virtualscene' | 'videoplayback' | 'none' | (string & {}); + +/** + * Use -camera-front to control emulation of a camera facing front. + * @value __emulated__ camera will be emulated using software ('fake') camera emulation + * @value __webcam\__ camera will be emulated using a webcamera connected to the host + * @value __none__ camera emulation will be disabled + */ +export type CameraFront = 'emulated' | 'none' | (string & {}); + +/** + * Use -gpu to override the mode of hardware OpenGL ES emulation + * indicated by the AVD. + * + * Note that enabling GPU emulation if the system image does not support it + * will prevent the proper display of the emulated framebuffer. + * + * The 'auto' mode is the default. In this mode, the hw.gpu.enabled setting + * in the AVD's hardware-qemu.ini file will determine whether GPU emulation + * is enabled. + */ +export enum EmulatorGpu { + /** Auto-select the renderer. */ + AUTO = 'auto', + /** + * Auto-select the renderer when + * running headless. This will use the same + * gpu selection mechanism as running without + * the "-no-window" flag and the "-gpu auto" + * option. See auto for details on the behavior. + */ + AUTO_NO_WINDOW = 'auto-no-window', + /** Use the host system's OpenGL driver. */ + HOST = 'host', + /** + * Use SwiftShader software renderer on the + * host, which can be beneficial if you are + * experiencing issues with your GPU drivers + * or need to run on systems without GPUs. + */ + SWIFTSHADER_INDIRECT = 'swiftshader_indirect', + /** + * Use ANGLE, an OpenGL ES to D3D11 renderer + * (Windows 7 SP1 + Platform update, + * Windows 8.1+, or Windows 10 only). + */ + ANGLE_INDIRECT = 'angle_indirect', + /** + * Use guest-side software rendering. For + * advanced users only. Warning: slow! + * In API 28 and later, guest rendering + * is not supported, and will fall back + * automatically to swiftshader_indirect. + */ + GUEST = 'guest' +} + +/** + * Android Emulator usage: emulator [options] [-qemu args] + options: + -list-avds list available AVDs + -sysdir search for system disk images in + -system read initial system image from + -vendor read initial vendor image from + -writable-system make system & vendor image writable after 'adb remount' + -delay-adb delay adb communication till boot completes + -datadir write user data into + -kernel use specific emulated kernel + -ramdisk ramdisk image (default /ramdisk.img + -image obsolete, use -system instead + -initdata same as '-init-data ' + -data data image (default /userdata-qemu.img + -encryption-key read initial encryption key image from + -logcat-output output file of logcat(default none) + -partition-size system/data partition size in MBs + -cache cache partition image (default is temporary file) + -cache-size cache partition size in MBs + -no-cache disable the cache partition + -nocache same as -no-cache + -sdcard SD card image (default /sdcard.img + -quit-after-boot qeuit emulator after guest boots completely, or after timeout in seconds + -qemu-top-dir Use the emulator in the specified dir (relative or absolute path) + -monitor-adb monitor the adb messages between guest and host, default not + -snapstorage file that contains all state snapshots (default /snapshots.img) + -no-snapstorage do not mount a snapshot storage file (this disables all snapshot functionality) + -snapshot name of snapshot within storage file for auto-start and auto-save (default 'default-boot') + -no-snapshot perform a full boot and do not auto-save, but qemu vmload and vmsave operate on snapstorage + -no-snapshot-save do not auto-save to snapshot on exit: abandon changed state + -no-snapshot-load do not auto-start from snapshot: perform a full boot + -snapshot-list show a list of available snapshots + -no-snapshot-update-time do not try to correct snapshot time on restore + -wipe-data reset the user data image (copy it from initdata) + -avd use a specific android virtual device + -avd-arch use a specific target architecture + -skindir search skins in (default /skins) + -skin select a given skin + -no-skin deprecated: create an AVD with no skin instead + -noskin same as -no-skin + -memory physical RAM size in MBs + -ui-only run only the UI feature requested + -id assign an id to this virtual device (separate from the avd name) + -cores Set number of CPU cores to emulator + -accel Configure emulation acceleration + -no-accel Same as '-accel off' + -ranchu Use new emulator backend instead of the classic one + -engine Select engine. auto|classic|qemu2 + -netspeed maximum network download/upload speeds + -netdelay network latency emulation + -netfast disable network shaping + -code-profile enable code profiling + -show-kernel display kernel messages + -shell enable root shell on current terminal + -no-jni deprecated, see dalvik_vm_checkjni + -nojni deprecated, see dalvik_vm_checkjni + -dalvik-vm-checkjni Enable dalvik.vm.checkjni + -logcat enable logcat output with given tags + -log-nofilter Disable the duplicate log filter + -no-audio disable audio support + -noaudio same as -no-audio + -audio use specific audio backend + -radio redirect radio modem interface to character device + -port TCP port that will be used for the console + -ports , TCP ports used for the console and adb bridge + -modem-simulator-port TCP port that will be used for android modem simulator + -onion use overlay PNG image over screen + -onion-alpha <%age> specify onion-skin translucency + -onion-rotation 0|1|2|3 specify onion-skin rotation + -dpi-device specify device's resolution in dpi (default DEFAULT_DEVICE_DPI) + -scale scale emulator window (deprecated) + -wifi-client-port connect to other emulator for WiFi forwarding + -wifi-server-port listen to other emulator for WiFi forwarding + -http-proxy make TCP connections through a HTTP/HTTPS proxy + -timezone use this timezone instead of the host's default + -change-language use this language instead of the current one. Restarts the framework. + -change-country use this country instead of the current one. Restarts the framework. + -change-locale use this locale instead of the current one. Restarts the framework. + -dns-server use this DNS server(s) in the emulated system + -net-tap use this TAP interface for networking + -net-tap-script-up