@@ -120,27 +120,28 @@ export async function swipeGestureAndroid(
120120 device : DeviceInfo ,
121121 options : AndroidSwipeGestureOptions ,
122122) : Promise < Record < string , unknown > | void > {
123- const providerTouch = resolveAndroidTouchInjector ( device ) ;
124- if ( providerTouch ) {
125- return {
126- backend : 'provider-native-touch' ,
127- ...( ( await providerTouch ( { kind : 'swipe' , ...options } ) ) ?? { } ) ,
128- } ;
129- }
130-
131- try {
132- return await runAndroidMultiTouchGesture ( device , { kind : 'swipe' , ...options } ) ;
133- } catch ( error ) {
134- emitDiagnostic ( {
135- level : 'warn' ,
136- phase : 'android_swipe_helper_fallback' ,
137- data : {
138- error : normalizeError ( error ) . message ,
139- } ,
140- } ) ;
141- await swipeAndroid ( device , options . x1 , options . y1 , options . x2 , options . y2 , options . durationMs ) ;
142- return { backend : 'adb-input-swipe-fallback' } ;
143- }
123+ return await performAndroidTouchGestureWithFallback (
124+ device ,
125+ { kind : 'swipe' , ...options } ,
126+ async ( error ) => {
127+ emitDiagnostic ( {
128+ level : 'warn' ,
129+ phase : 'android_swipe_helper_fallback' ,
130+ data : {
131+ error : normalizeError ( error ) . message ,
132+ } ,
133+ } ) ;
134+ await swipeAndroid (
135+ device ,
136+ options . x1 ,
137+ options . y1 ,
138+ options . x2 ,
139+ options . y2 ,
140+ options . durationMs ,
141+ ) ;
142+ return { backend : 'adb-input-swipe-fallback' } ;
143+ } ,
144+ ) ;
144145}
145146
146147export async function pinchAndroid (
@@ -151,7 +152,7 @@ export async function pinchAndroid(
151152 throw new AppError ( 'INVALID_ARGS' , 'gesture pinch requires scale > 0' ) ;
152153 }
153154 const center = await resolveGestureCenter ( device , options . x , options . y ) ;
154- return await runAndroidMultiTouchGesture ( device , {
155+ return await performAndroidTouchGesture ( device , {
155156 kind : 'pinch' ,
156157 x : center . x ,
157158 y : center . y ,
@@ -175,7 +176,7 @@ export async function rotateGestureAndroid(
175176 }
176177 const center = await resolveGestureCenter ( device , options . x , options . y ) ;
177178 const degrees = options . degrees ;
178- return await runAndroidMultiTouchGesture ( device , {
179+ return await performAndroidTouchGesture ( device , {
179180 kind : 'rotate' ,
180181 x : center . x ,
181182 y : center . y ,
@@ -197,7 +198,7 @@ export async function transformGestureAndroid(
197198 if ( ! [ options . x , options . y , options . dx , options . dy ] . every ( Number . isFinite ) ) {
198199 throw new AppError ( 'INVALID_ARGS' , 'gesture transform requires finite x y dx dy' ) ;
199200 }
200- return await runAndroidMultiTouchGesture ( device , {
201+ return await performAndroidTouchGesture ( device , {
201202 kind : 'transform' ,
202203 x : options . x ,
203204 y : options . y ,
@@ -219,7 +220,19 @@ async function resolveGestureCenter(
219220 return { x : Math . round ( size . width / 2 ) , y : Math . round ( size . height / 2 ) } ;
220221}
221222
222- async function runAndroidMultiTouchGesture (
223+ async function performAndroidTouchGestureWithFallback (
224+ device : DeviceInfo ,
225+ request : AndroidTouchGestureRequest ,
226+ fallback : ( error : unknown ) => Promise < Record < string , unknown > | void > ,
227+ ) : Promise < Record < string , unknown > | void > {
228+ try {
229+ return await performAndroidTouchGesture ( device , request ) ;
230+ } catch ( error ) {
231+ return await fallback ( error ) ;
232+ }
233+ }
234+
235+ async function performAndroidTouchGesture (
223236 device : DeviceInfo ,
224237 request : AndroidTouchGestureRequest ,
225238) : Promise < Record < string , unknown > > {
@@ -229,6 +242,13 @@ async function runAndroidMultiTouchGesture(
229242 return { backend : 'provider-native-touch' , ...result } ;
230243 }
231244
245+ return await runAndroidMultiTouchHelperGestureForDevice ( device , request ) ;
246+ }
247+
248+ async function runAndroidMultiTouchHelperGestureForDevice (
249+ device : DeviceInfo ,
250+ request : AndroidTouchGestureRequest ,
251+ ) : Promise < Record < string , unknown > > {
232252 const adb = resolveAndroidAdbExecutor ( device ) ;
233253 const artifact = await resolveAndroidMultiTouchHelperArtifact ( ) ;
234254 const adbProvider = resolveAndroidAdbProvider ( device ) ;
0 commit comments