@@ -18,6 +18,8 @@ async function ensureAndroidEmulatorBoot(params: {
1818 avdName : string ;
1919 serial ?: string ;
2020 headless ?: boolean ;
21+ cameraFront ?: string ;
22+ cameraBack ?: string ;
2123} ) : Promise < DeviceInfo > {
2224 const { ensureAndroidEmulatorBooted } = await import ( '../../platforms/android/devices.ts' ) ;
2325 return await ensureAndroidEmulatorBooted ( params ) ;
@@ -148,12 +150,19 @@ export async function handleSessionStateCommands(params: {
148150 normalizePlatformSelector ( flags . platform ) ?? session ?. device . platform ;
149151 const targetsAndroid = normalizedPlatform === 'android' ;
150152 const wantsAndroidHeadless = flags . headless === true ;
153+ const wantsAndroidCamera = Boolean ( flags . cameraFront || flags . cameraBack ) ;
151154 if ( wantsAndroidHeadless && ! targetsAndroid ) {
152155 return errorResponse (
153156 'INVALID_ARGS' ,
154157 'boot --headless is supported only for Android emulators.' ,
155158 ) ;
156159 }
160+ if ( wantsAndroidCamera && ! targetsAndroid ) {
161+ return errorResponse (
162+ 'INVALID_ARGS' ,
163+ 'boot --camera-front/--camera-back is supported only for Android emulators.' ,
164+ ) ;
165+ }
157166
158167 const fallbackAvdName = resolveAndroidEmulatorAvdName ( {
159168 flags,
@@ -173,13 +182,13 @@ export async function handleSessionStateCommands(params: {
173182 const appErr = asAppError ( error ) ;
174183 if (
175184 targetsAndroid &&
176- wantsAndroidHeadless &&
185+ ( wantsAndroidHeadless || wantsAndroidCamera ) &&
177186 ! fallbackAvdName &&
178187 appErr . code === 'DEVICE_NOT_FOUND'
179188 ) {
180189 return errorResponse (
181190 'INVALID_ARGS' ,
182- 'boot --headless requires --device <avd-name> (or an Android emulator session target).' ,
191+ androidBootOptionsRequireDeviceMessage ( wantsAndroidCamera ) ,
183192 ) ;
184193 }
185194 if (
@@ -193,6 +202,8 @@ export async function handleSessionStateCommands(params: {
193202 avdName : fallbackAvdName ,
194203 serial : flags . serial ,
195204 headless : wantsAndroidHeadless ,
205+ cameraFront : typeof flags . cameraFront === 'string' ? flags . cameraFront : undefined ,
206+ cameraBack : typeof flags . cameraBack === 'string' ? flags . cameraBack : undefined ,
196207 } ) ;
197208 launchedAndroidEmulator = true ;
198209 }
@@ -204,11 +215,13 @@ export async function handleSessionStateCommands(params: {
204215 ) ;
205216 }
206217
207- if ( targetsAndroid && wantsAndroidHeadless ) {
218+ if ( targetsAndroid && ( wantsAndroidHeadless || wantsAndroidCamera ) ) {
208219 if ( device . platform !== 'android' || device . kind !== 'emulator' ) {
209220 return errorResponse (
210221 'INVALID_ARGS' ,
211- 'boot --headless is supported only for Android emulators.' ,
222+ wantsAndroidCamera
223+ ? 'boot --camera-front/--camera-back is supported only for Android emulators.'
224+ : 'boot --headless is supported only for Android emulators.' ,
212225 ) ;
213226 }
214227 if ( ! launchedAndroidEmulator ) {
@@ -220,13 +233,15 @@ export async function handleSessionStateCommands(params: {
220233 if ( ! avdName ) {
221234 return errorResponse (
222235 'INVALID_ARGS' ,
223- 'boot --headless requires --device <avd-name> (or an Android emulator session target).' ,
236+ androidBootOptionsRequireDeviceMessage ( wantsAndroidCamera ) ,
224237 ) ;
225238 }
226239 device = await ensureAndroidEmulatorBoot ( {
227240 avdName,
228241 serial : flags . serial ,
229- headless : true ,
242+ headless : wantsAndroidHeadless ,
243+ cameraFront : typeof flags . cameraFront === 'string' ? flags . cameraFront : undefined ,
244+ cameraBack : typeof flags . cameraBack === 'string' ? flags . cameraBack : undefined ,
230245 } ) ;
231246 }
232247 await ensureDeviceReady ( device ) ;
@@ -332,6 +347,12 @@ export async function handleSessionStateCommands(params: {
332347 return null ;
333348}
334349
350+ function androidBootOptionsRequireDeviceMessage ( wantsAndroidCamera : boolean ) : string {
351+ return wantsAndroidCamera
352+ ? 'boot --camera-front/--camera-back requires --device <avd-name> (or an Android emulator session target).'
353+ : 'boot --headless requires --device <avd-name> (or an Android emulator session target).' ;
354+ }
355+
335356function shutdownFailureMessage (
336357 shutdown : Awaited < ReturnType < typeof shutdownDeviceTarget > > ,
337358) : string {
0 commit comments