11import { type AndroidAppLaunchOptions } from '@react-native-harness/platforms' ;
22import { spawn , SubprocessError } from '@react-native-harness/tools' ;
3- import { withAndroidProcessEnv } from './environment.js' ;
43
54const wait = async ( ms : number ) : Promise < void > => {
65 await new Promise ( ( resolve ) => {
@@ -66,11 +65,15 @@ export const isAppInstalled = async (
6665 adbId : string ,
6766 bundleId : string
6867) : Promise < boolean > => {
69- const { stdout } = await spawn (
70- 'adb' ,
71- [ '-s' , adbId , 'shell' , 'pm' , 'list' , 'packages' , bundleId ] ,
72- withAndroidProcessEnv ( )
73- ) ;
68+ const { stdout } = await spawn ( 'adb' , [
69+ '-s' ,
70+ adbId ,
71+ 'shell' ,
72+ 'pm' ,
73+ 'list' ,
74+ 'packages' ,
75+ bundleId ,
76+ ] ) ;
7477 return stdout . trim ( ) !== '' ;
7578} ;
7679
@@ -79,22 +82,20 @@ export const reversePort = async (
7982 port : number ,
8083 hostPort : number = port
8184) : Promise < void > => {
82- await spawn (
83- 'adb' ,
84- [ '-s' , adbId , 'reverse' , `tcp:${ port } ` , `tcp:${ hostPort } ` ] ,
85- withAndroidProcessEnv ( )
86- ) ;
85+ await spawn ( 'adb' , [
86+ '-s' ,
87+ adbId ,
88+ 'reverse' ,
89+ `tcp:${ port } ` ,
90+ `tcp:${ hostPort } ` ,
91+ ] ) ;
8792} ;
8893
8994export const stopApp = async (
9095 adbId : string ,
9196 bundleId : string
9297) : Promise < void > => {
93- await spawn (
94- 'adb' ,
95- [ '-s' , adbId , 'shell' , 'am' , 'force-stop' , bundleId ] ,
96- withAndroidProcessEnv ( )
97- ) ;
98+ await spawn ( 'adb' , [ '-s' , adbId , 'shell' , 'am' , 'force-stop' , bundleId ] ) ;
9899} ;
99100
100101export const startApp = async (
@@ -103,15 +104,15 @@ export const startApp = async (
103104 activityName : string ,
104105 options ?: AndroidAppLaunchOptions
105106) : Promise < void > => {
106- await spawn (
107- 'adb ' ,
108- [ '-s' , adbId , ... getStartAppArgs ( bundleId , activityName , options ) ] ,
109- withAndroidProcessEnv ( )
110- ) ;
107+ await spawn ( 'adb' , [
108+ '-s ' ,
109+ adbId ,
110+ ... getStartAppArgs ( bundleId , activityName , options ) ,
111+ ] ) ;
111112} ;
112113
113114export const getDeviceIds = async ( ) : Promise < string [ ] > => {
114- const { stdout } = await spawn ( 'adb' , [ 'devices' ] , withAndroidProcessEnv ( ) ) ;
115+ const { stdout } = await spawn ( 'adb' , [ 'devices' ] ) ;
115116 return stdout
116117 . split ( '\n' )
117118 . slice ( 1 ) // Skip header
@@ -122,23 +123,21 @@ export const getDeviceIds = async (): Promise<string[]> => {
122123export const getEmulatorName = async (
123124 adbId : string
124125) : Promise < string | null > => {
125- const { stdout } = await spawn (
126- 'adb' ,
127- [ '-s' , adbId , 'emu' , 'avd' , 'name' ] ,
128- withAndroidProcessEnv ( )
129- ) ;
126+ const { stdout } = await spawn ( 'adb' , [ '-s' , adbId , 'emu' , 'avd' , 'name' ] ) ;
130127 return stdout . split ( '\n' ) [ 0 ] . trim ( ) || null ;
131128} ;
132129
133130export const getShellProperty = async (
134131 adbId : string ,
135132 property : string
136133) : Promise < string | null > => {
137- const { stdout } = await spawn (
138- 'adb' ,
139- [ '-s' , adbId , 'shell' , 'getprop' , property ] ,
140- withAndroidProcessEnv ( )
141- ) ;
134+ const { stdout } = await spawn ( 'adb' , [
135+ '-s' ,
136+ adbId ,
137+ 'shell' ,
138+ 'getprop' ,
139+ property ,
140+ ] ) ;
142141 return stdout . trim ( ) || null ;
143142} ;
144143
@@ -161,7 +160,7 @@ export const isBootCompleted = async (adbId: string): Promise<boolean> => {
161160} ;
162161
163162export const stopEmulator = async ( adbId : string ) : Promise < void > => {
164- await spawn ( 'adb' , [ '-s' , adbId , 'emu' , 'kill' ] , withAndroidProcessEnv ( ) ) ;
163+ await spawn ( 'adb' , [ '-s' , adbId , 'emu' , 'kill' ] ) ;
165164} ;
166165
167166export const installApp = async (
@@ -267,11 +266,13 @@ export const isAppRunning = async (
267266 bundleId : string
268267) : Promise < boolean > => {
269268 try {
270- const { stdout } = await spawn (
271- 'adb' ,
272- [ '-s' , adbId , 'shell' , 'pidof' , bundleId ] ,
273- withAndroidProcessEnv ( )
274- ) ;
269+ const { stdout } = await spawn ( 'adb' , [
270+ '-s' ,
271+ adbId ,
272+ 'shell' ,
273+ 'pidof' ,
274+ bundleId ,
275+ ] ) ;
275276 return stdout . trim ( ) !== '' ;
276277 } catch ( error ) {
277278 if ( error instanceof SubprocessError && error . exitCode === 1 ) {
@@ -286,11 +287,15 @@ export const getAppUid = async (
286287 adbId : string ,
287288 bundleId : string
288289) : Promise < number > => {
289- const { stdout } = await spawn (
290- 'adb' ,
291- [ '-s' , adbId , 'shell' , 'pm' , 'list' , 'packages' , '-U' ] ,
292- withAndroidProcessEnv ( )
293- ) ;
290+ const { stdout } = await spawn ( 'adb' , [
291+ '-s' ,
292+ adbId ,
293+ 'shell' ,
294+ 'pm' ,
295+ 'list' ,
296+ 'packages' ,
297+ '-U' ,
298+ ] ) ;
294299 const line = stdout
295300 . split ( '\n' )
296301 . find ( ( entry ) => entry . includes ( `package:${ bundleId } ` ) ) ;
@@ -307,39 +312,33 @@ export const setHideErrorDialogs = async (
307312 adbId : string ,
308313 hide : boolean
309314) : Promise < void > => {
310- await spawn (
311- 'adb' ,
312- [
313- '-s' ,
314- adbId ,
315- 'shell' ,
316- 'settings' ,
317- 'put' ,
318- 'global' ,
319- 'hide_error_dialogs' ,
320- hide ? '1' : '0' ,
321- ] ,
322- withAndroidProcessEnv ( )
323- ) ;
315+ await spawn ( 'adb' , [
316+ '-s' ,
317+ adbId ,
318+ 'shell' ,
319+ 'settings' ,
320+ 'put' ,
321+ 'global' ,
322+ 'hide_error_dialogs' ,
323+ hide ? '1' : '0' ,
324+ ] ) ;
324325} ;
325326
326327export const getLogcatTimestamp = async ( adbId : string ) : Promise < string > => {
327- const { stdout } = await spawn (
328- 'adb' ,
329- [ '-s' , adbId , 'shell' , 'date' , "+'%m-%d %H:%M:%S.000'" ] ,
330- withAndroidProcessEnv ( )
331- ) ;
328+ const { stdout } = await spawn ( 'adb' , [
329+ '-s' ,
330+ adbId ,
331+ 'shell' ,
332+ 'date' ,
333+ "+'%m-%d %H:%M:%S.000'" ,
334+ ] ) ;
332335
333336 return stdout . trim ( ) . replace ( / ^ ' + | ' + $ / g, '' ) ;
334337} ;
335338
336339export const getAvds = async ( ) : Promise < string [ ] > => {
337340 try {
338- const { stdout } = await spawn (
339- 'emulator' ,
340- [ '-list-avds' ] ,
341- withAndroidProcessEnv ( )
342- ) ;
341+ const { stdout } = await spawn ( 'emulator' , [ '-list-avds' ] ) ;
343342 return stdout
344343 . split ( '\n' )
345344 . map ( ( line ) => line . trim ( ) )
@@ -356,11 +355,7 @@ export type AdbDevice = {
356355} ;
357356
358357export const getConnectedDevices = async ( ) : Promise < AdbDevice [ ] > => {
359- const { stdout } = await spawn (
360- 'adb' ,
361- [ 'devices' , '-l' ] ,
362- withAndroidProcessEnv ( )
363- ) ;
358+ const { stdout } = await spawn ( 'adb' , [ 'devices' , '-l' ] ) ;
364359 const lines = stdout . split ( '\n' ) . slice ( 1 ) ;
365360 const devices : AdbDevice [ ] = [ ] ;
366361
0 commit comments