@@ -109,7 +109,7 @@ def Devices(cls):
109109 def GetState (self ):
110110 return self ._device_state
111111
112- def Install (self , apk_path , destination_dir = '' , replace_existing = True , timeout_ms = None ):
112+ def Install (self , apk_path , destination_dir = '' , timeout_ms = None , replace_existing = True , transfer_progress_callback = None ):
113113 """Install an apk to the device.
114114
115115 Doesn't support verifier file, instead allows destination directory to be
@@ -121,6 +121,7 @@ def Install(self, apk_path, destination_dir='', replace_existing=True, timeout_m
121121 persistent applications.
122122 replace_existing: whether to replace existing application
123123 timeout_ms: Expected timeout for pushing and installing.
124+ transfer_progress_callback: callback method that accepts filename, bytes_written and total_bytes of APK transfer
124125
125126 Returns:
126127 The pm install output.
@@ -129,15 +130,14 @@ def Install(self, apk_path, destination_dir='', replace_existing=True, timeout_m
129130 destination_dir = '/data/local/tmp/'
130131 basename = os .path .basename (apk_path )
131132 destination_path = destination_dir + basename
132- self .Push (apk_path , destination_path , timeout_ms = timeout_ms )
133-
133+ self .Push (apk_path , destination_path , timeout_ms = timeout_ms , progress_callback = transfer_progress_callback )
134+
134135 cmd = ['pm install' ]
135136 if replace_existing :
136137 cmd .append ('-r' )
137138 cmd .append ('"%s"' % destination_path )
138-
139139 return self .Shell (' ' .join (cmd ), timeout_ms = timeout_ms )
140-
140+
141141 def Uninstall (self , package_name , keep_data = False , timeout_ms = None ):
142142 """Removes a package from the device.
143143
@@ -155,7 +155,7 @@ def Uninstall(self, package_name, keep_data=False, timeout_ms=None):
155155 cmd .append ('"%s"' % package_name )
156156 return self .Shell (' ' .join (cmd ), timeout_ms = timeout_ms )
157157
158- def Push (self , source_file , device_filename , mtime = '0' , timeout_ms = None ):
158+ def Push (self , source_file , device_filename , mtime = '0' , timeout_ms = None , progress_callback = None ):
159159 """Push a file or directory to the device.
160160
161161 Args:
@@ -164,26 +164,28 @@ def Push(self, source_file, device_filename, mtime='0', timeout_ms=None):
164164 device_filename: Destination on the device to write to.
165165 mtime: Optional, modification time to set on the file.
166166 timeout_ms: Expected timeout for any part of the push.
167+ progress_callback: callback method that accepts filename, bytes_written and total_bytes,
168+ total_bytes will be -1 for file-like objects
167169 """
168170 should_close = False
169171 if isinstance (source_file , str ):
170172 if os .path .isdir (source_file ):
171173 self .Shell ("mkdir " + device_filename )
172174 for f in os .listdir (source_file ):
173- self .Push (os .path .join (source_file , f ), device_filename + '/' + f )
175+ self .Push (os .path .join (source_file , f ), device_filename + '/' + f , progress_callback = progress_callback )
174176 return
175177 source_file = open (source_file , "rb" )
176178 should_close = True
177179
178180 connection = self .protocol_handler .Open (
179181 self .handle , destination = b'sync:' , timeout_ms = timeout_ms )
180182 self .filesync_handler .Push (connection , source_file , device_filename ,
181- mtime = int (mtime ))
183+ mtime = int (mtime ), progress_callback = progress_callback )
182184 if should_close :
183185 source_file .close ()
184186 connection .Close ()
185187
186- def Pull (self , device_filename , dest_file = '' , timeout_ms = None ):
188+ def Pull (self , device_filename , dest_file = '' , progress_callback = None , timeout_ms = None ):
187189 """Pull a file from the device.
188190
189191 Args:
@@ -201,7 +203,7 @@ def Pull(self, device_filename, dest_file='', timeout_ms=None):
201203 connection = self .protocol_handler .Open (
202204 self .handle , destination = b'sync:' ,
203205 timeout_ms = timeout_ms )
204- self .filesync_handler .Pull (connection , device_filename , dest_file )
206+ self .filesync_handler .Pull (connection , device_filename , dest_file , progress_callback )
205207 connection .Close ()
206208 if isinstance (dest_file , io .BytesIO ):
207209 return dest_file .getvalue ()
0 commit comments