1919import com .google .common .collect .ImmutableMap ;
2020
2121import java .nio .charset .StandardCharsets ;
22+ import java .util .AbstractMap ;
2223import java .util .Base64 ;
2324
2425import static com .google .common .base .Preconditions .checkNotNull ;
26+ import static io .appium .java_client .MobileCommand .PULL_FILE ;
27+ import static io .appium .java_client .MobileCommand .PULL_FOLDER ;
2528
26- public interface PullsFiles extends ExecutesMethod {
29+ public interface PullsFiles extends ExecutesMethod , CanRememberExtensionPresence {
2730
2831 /**
2932 * Pull a file from the remote system.
@@ -38,11 +41,22 @@ public interface PullsFiles extends ExecutesMethod {
3841 * @return A byte array of Base64 encoded data.
3942 */
4043 default byte [] pullFile (String remotePath ) {
41- String base64String = checkNotNull (
42- CommandExecutionHelper .executeScript (this , "mobile: pullFile" , ImmutableMap .of (
43- "remotePath" , remotePath
44- ))
45- );
44+ final String extName = "mobile: pullFile" ;
45+ String base64String ;
46+ try {
47+ base64String = checkNotNull (
48+ CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName ,
49+ ImmutableMap .of ("remotePath" , remotePath )
50+ )
51+ );
52+ } catch (UnsupportedOperationException e ) {
53+ // TODO: Remove the fallback
54+ base64String = checkNotNull (
55+ CommandExecutionHelper .execute (markExtensionAbsence (extName ),
56+ new AbstractMap .SimpleEntry <>(PULL_FILE , ImmutableMap .of ("path" , remotePath ))
57+ )
58+ );
59+ }
4660 return Base64 .getDecoder ().decode (base64String .getBytes (StandardCharsets .UTF_8 ));
4761 }
4862
@@ -59,11 +73,22 @@ default byte[] pullFile(String remotePath) {
5973 * @return A byte array of Base64 encoded zip archive data.
6074 */
6175 default byte [] pullFolder (String remotePath ) {
62- String base64String = checkNotNull (
63- CommandExecutionHelper .executeScript (this , "mobile: pullFolder" , ImmutableMap .of (
64- "remotePath" , remotePath
65- ))
66- );
76+ final String extName = "mobile: pullFolder" ;
77+ String base64String ;
78+ try {
79+ base64String = checkNotNull (
80+ CommandExecutionHelper .executeScript (assertExtensionExists (extName ), extName ,
81+ ImmutableMap .of ("remotePath" , remotePath )
82+ )
83+ );
84+ } catch (UnsupportedOperationException e ) {
85+ // TODO: Remove the fallback
86+ base64String = checkNotNull (
87+ CommandExecutionHelper .execute (markExtensionAbsence (extName ),
88+ new AbstractMap .SimpleEntry <>(PULL_FOLDER , ImmutableMap .of ("path" , remotePath ))
89+ )
90+ );
91+ }
6792 return Base64 .getDecoder ().decode (base64String .getBytes (StandardCharsets .UTF_8 ));
6893 }
6994
0 commit comments