2222# -----------------------------------------------------------------------------
2323
2424'''
25- This module implements higher level Android queries and utilities, built on top
26- of the low level Android Debug Bridge wrapper .
25+ This module implements higher level Android filesystem utilities, built on top
26+ of the low level ADBConnect wrapper around Android Debug Bridge.
2727'''
2828
2929import os
3636class AndroidFilesystem :
3737 '''
3838 A library of utility methods for transferring files to/from a device.
39+
40+ Attributes:
41+ TEMP_DIR: The generally accessible device temp directory.
42+ DATA_PERM: The file permissions to use for data files.
43+ EXEC_PERM: The file permissions to use for executable files.
3944 '''
4045
4146 TEMP_DIR = '/data/local/tmp'
@@ -49,12 +54,12 @@ def push_file_to_tmp(
4954 '''
5055 Push a file to the device temp directory.
5156
52- File will be copied to: /data/local/tmp /<file>.
57+ File will be copied to: TEMP_DIR /<file>.
5358
5459 Args:
5560 conn: The adb connection.
5661 host_path: The path of the file on the host file system.
57- executable: True if the file should be configured as executable.
62+ executable: True if the file should have executable permissions .
5863
5964 Returns:
6065 True if the file was copied, False otherwise.
@@ -65,16 +70,17 @@ def push_file_to_tmp(
6570
6671 try :
6772 # Remove old file to prevent false success
68- conn .adb ( 'shell' , 'rm' , '-f' , device_path )
73+ conn .adb_run ( 'rm' , '-f' , device_path )
6974
7075 # Push new file
7176 conn .adb ('push' , host_path , device_path )
7277
7378 # Check it actually copied
74- conn .adb ( 'shell' , 'ls' , device_path )
79+ conn .adb_run ( 'ls' , device_path )
7580
7681 permission = cls .EXEC_PERM if executable else cls .DATA_PERM
77- conn .adb ('shell' , 'chmod' , permission , device_path )
82+ conn .adb_run ('chmod' , permission , device_path )
83+
7884 except sp .CalledProcessError :
7985 return False
8086
@@ -94,7 +100,7 @@ def pull_file_from_tmp(
94100 file_name: The name of the file in the tmp directory.
95101 host_path: The destination directory on the host file system.
96102 Host directory will be created if it doesn't exist.
97- delete: Delete the file on the device after copying it.
103+ delete: Should the file on the device be deleted after copying?
98104
99105 Returns:
100106 True if the file was copied, False otherwise.
@@ -121,7 +127,7 @@ def delete_file_from_tmp(
121127 '''
122128 Delete a file from the device temp directory.
123129
124- File will be deleted from: /data/local/tmp /<file>.
130+ File will be deleted from: TEMP_DIR /<file>.
125131
126132 Args:
127133 conn: The adb connection.
@@ -135,9 +141,9 @@ def delete_file_from_tmp(
135141
136142 try :
137143 if error_ok :
138- conn .adb ( 'shell' , 'rm' , '-f' , device_path )
144+ conn .adb_run ( 'rm' , '-f' , device_path )
139145 else :
140- conn .adb ( 'shell' , 'rm' , device_path )
146+ conn .adb_run ( 'rm' , device_path )
141147 except sp .CalledProcessError :
142148 return False
143149
@@ -155,7 +161,7 @@ def push_file_to_package(
155161 Args:
156162 conn: The adb connection.
157163 host_path: The path of the file on the host file system.
158- executable: True if the file should be configured as executable.
164+ executable: True if the file should have executable permissions .
159165
160166 Returns:
161167 True if the file was copied, False otherwise.
@@ -197,7 +203,7 @@ def pull_file_from_package(
197203 src_file: The name of the file in the tmp directory.
198204 host_path: The destination directory on the host file system.
199205 Host directory will be created if it doesn't exist.
200- delete: Delete the file on the device after copying it.
206+ delete: Should the file on the device be deleted after copying?
201207
202208 Returns:
203209 True if the file was copied, False otherwise.
@@ -218,6 +224,7 @@ def pull_file_from_package(
218224
219225 if delete :
220226 cls .delete_file_from_package (conn , src_file )
227+
221228 except sp .SubprocessError :
222229 return False
223230
@@ -227,13 +234,13 @@ def pull_file_from_package(
227234 def rename_file_in_package (
228235 cls , conn : ADBConnect , file_name : str , new_file_name : str ) -> bool :
229236 '''
230- Delete a file from the package directory.
237+ Rename a file in the package directory.
231238
232- File will be deleted from , e.g.: /data/user/0/<package>/<file >
239+ File will be renamed to , e.g.: /data/user/0/<package>/<new_file >
233240
234241 Args:
235242 conn: The adb connection.
236- file_name: The name of the file to rename.
243+ file_name: The name of the existing file to rename.
237244 new_file_name: The new file name to use.
238245
239246 Returns:
0 commit comments