@@ -12,11 +12,13 @@ import Utilities from './Utilities';
1212import { ACCOUNT_ACTIVITY_WS } from '../websocket/constants.ts' ;
1313// eslint-disable-next-line import-x/no-nodejs-modules
1414import { execSync } from 'child_process' ;
15- import { CurrentDeviceDetails } from './fixture' ;
15+ import type { CurrentDeviceDetails } from './fixture' ;
1616
1717// eslint-disable-next-line @typescript-eslint/no-var-requires, import-x/no-commonjs, @typescript-eslint/no-require-imports
1818const deviceMatrix : DeviceMatrix = require ( '../performance/device-matrix.json' ) ;
1919
20+ type AndroidIntentExtra = [ 's' , string , string ] ;
21+
2022/**
2123 * Get the driver instance.
2224 * @returns The driver instance.
@@ -270,29 +272,28 @@ class PlaywrightUtilities {
270272 }
271273
272274 /**
273- * Builds `optionalIntentArguments` for Android `am start` from {@link LaunchArgs}.
274- * Each defined string value is passed as a string extra (`--es`) using the same keys
275- * as Detox `launchArgs` / `react-native-launch-arguments`.
275+ * Builds Android string intent extras from {@link LaunchArgs}.
276+ * Each defined string value is passed as a string extra (`--es`) using the
277+ * same keys as Detox `launchArgs` / `react-native-launch-arguments`.
276278 */
277- private static buildAndroidOptionalIntentArguments (
279+ private static buildAndroidIntentExtras (
278280 { launchArgs } : { launchArgs ?: Partial < LaunchArgs > } = {
279281 launchArgs : { } as Partial < LaunchArgs > ,
280282 } ,
281- ) : string | undefined {
283+ ) : AndroidIntentExtra [ ] {
282284 const resolved = PlaywrightUtilities . buildResolvedLaunchArgs ( {
283285 launchArgs,
284286 } ) ;
285287
286- const segments : string [ ] = [ ] ;
288+ const extras : AndroidIntentExtra [ ] = [ ] ;
287289 for ( const [ key , value ] of Object . entries ( resolved ) ) {
288290 if ( value === undefined || value === '' ) {
289291 continue ;
290292 }
291- const escaped = String ( value ) . replace ( / \\ / g, '\\\\' ) . replace ( / " / g, '\\"' ) ;
292- segments . push ( `--es ${ key } "${ escaped } "` ) ;
293+ extras . push ( [ 's' , key , String ( value ) ] ) ;
293294 }
294295
295- return segments . length > 0 ? segments . join ( ' ' ) : undefined ;
296+ return extras ;
296297 }
297298
298299 /**
@@ -340,16 +341,17 @@ class PlaywrightUtilities {
340341 ) ;
341342 }
342343
343- const optionalIntentArguments =
344- PlaywrightUtilities . buildAndroidOptionalIntentArguments ( {
345- launchArgs ,
346- } ) ;
344+ const extras = PlaywrightUtilities . buildAndroidIntentExtras ( {
345+ launchArgs ,
346+ } ) ;
347+
347348 await drv . execute ( 'mobile: startActivity' , {
348- appPackage : pkg ,
349- appActivity : activity ,
350- ...( optionalIntentArguments !== undefined
351- ? { optionalIntentArguments }
352- : { } ) ,
349+ component : `${ pkg } /${ activity } ` ,
350+ action : 'android.intent.action.MAIN' ,
351+ categories : [ 'android.intent.category.LAUNCHER' ] ,
352+ stop : true ,
353+ wait : true ,
354+ ...( extras . length > 0 ? { extras } : { } ) ,
353355 } ) ;
354356 }
355357
@@ -402,6 +404,7 @@ class PlaywrightUtilities {
402404 if ( ! currentDeviceDetails ?. packageName && ! currentDeviceDetails ?. appId ) {
403405 throw new Error ( 'Package name or app id is not available' ) ;
404406 }
407+
405408 if ( currentDeviceDetails . platform === 'android' ) {
406409 await this . launchAppAndroid ( currentDeviceDetails , {
407410 launchArgs,
0 commit comments