@@ -184,8 +184,8 @@ def Devices(cls):
184184 def GetState (self ):
185185 return self ._device_state
186186
187- def Install (self , apk_path , destination_dir = '' , timeout_ms = None , replace_existing = True ,
188- transfer_progress_callback = None ):
187+ def Install (self , apk_path , destination_dir = '' , replace_existing = True ,
188+ grant_permissions = False , timeout_ms = None , transfer_progress_callback = None ):
189189 """Install an apk to the device.
190190
191191 Doesn't support verifier file, instead allows destination directory to be
@@ -196,6 +196,7 @@ def Install(self, apk_path, destination_dir='', timeout_ms=None, replace_existin
196196 destination_dir: Optional destination directory. Use /system/app/ for
197197 persistent applications.
198198 replace_existing: whether to replace existing application
199+ grant_permissions: If True, grant all permissions to the app specified in its manifest
199200 timeout_ms: Expected timeout for pushing and installing.
200201 transfer_progress_callback: callback method that accepts filename, bytes_written and total_bytes of APK transfer
201202
@@ -209,10 +210,19 @@ def Install(self, apk_path, destination_dir='', timeout_ms=None, replace_existin
209210 self .Push (apk_path , destination_path , timeout_ms = timeout_ms , progress_callback = transfer_progress_callback )
210211
211212 cmd = ['pm install' ]
213+ if grant_permissions :
214+ cmd .append ('-g' )
212215 if replace_existing :
213216 cmd .append ('-r' )
214217 cmd .append ('"{}"' .format (destination_path ))
215- return self .Shell (' ' .join (cmd ), timeout_ms = timeout_ms )
218+
219+ ret = self .Shell (' ' .join (cmd ), timeout_ms = timeout_ms )
220+
221+ # Remove the apk
222+ rm_cmd = ['rm' , destination_path ]
223+ rmret = self .Shell (' ' .join (rm_cmd ), timeout_ms = timeout_ms )
224+
225+ return ret
216226
217227 def Uninstall (self , package_name , keep_data = False , timeout_ms = None ):
218228 """Removes a package from the device.
@@ -229,6 +239,7 @@ def Uninstall(self, package_name, keep_data=False, timeout_ms=None):
229239 if keep_data :
230240 cmd .append ('-k' )
231241 cmd .append ('"%s"' % package_name )
242+
232243 return self .Shell (' ' .join (cmd ), timeout_ms = timeout_ms )
233244
234245 def Push (self , source_file , device_filename , mtime = '0' , timeout_ms = None , progress_callback = None ):
@@ -243,6 +254,7 @@ def Push(self, source_file, device_filename, mtime='0', timeout_ms=None, progres
243254 progress_callback: callback method that accepts filename, bytes_written and total_bytes,
244255 total_bytes will be -1 for file-like objects
245256 """
257+
246258 if isinstance (source_file , str ):
247259 if os .path .isdir (source_file ):
248260 self .Shell ("mkdir " + device_filename )
0 commit comments