Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions adb/adb_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def Devices(cls):
def GetState(self):
return self._device_state

def Install(self, apk_path, destination_dir='', timeout_ms=None):
def Install(self, apk_path, destination_dir='', replace_existing=True, timeout_ms=None):
"""Install an apk to the device.

Doesn't support verifier file, instead allows destination directory to be
Expand All @@ -119,6 +119,7 @@ def Install(self, apk_path, destination_dir='', timeout_ms=None):
apk_path: Local path to apk to install.
destination_dir: Optional destination directory. Use /system/app/ for
persistent applications.
replace_existing: whether to replace existing application
timeout_ms: Expected timeout for pushing and installing.

Returns:
Expand All @@ -129,8 +130,30 @@ def Install(self, apk_path, destination_dir='', timeout_ms=None):
basename = os.path.basename(apk_path)
destination_path = destination_dir + basename
self.Push(apk_path, destination_path, timeout_ms=timeout_ms)
return self.Shell('pm install -r "%s"' % destination_path,
timeout_ms=timeout_ms)

cmd = ['pm install']
if replace_existing:
cmd.append('-r')
cmd.append('"%s"' % destination_path)

return self.Shell(' '.join(cmd), timeout_ms=timeout_ms)

def Uninstall(self, package_name, keep_data=False, timeout_ms=None):
"""Removes a package from the device.

Args:
package_name: Package name of target package.
keep_data: whether to keep the data and cache directories
timeout_ms: Expected timeout for pushing and installing.

Returns:
The pm uninstall output.
"""
cmd = ['pm uninstall']
if keep_data:
cmd.append('-k')
cmd.append('"%s"' % package_name)
return self.Shell(' '.join(cmd), timeout_ms=timeout_ms)

def Push(self, source_file, device_filename, mtime='0', timeout_ms=None):
"""Push a file or directory to the device.
Expand Down
1 change: 1 addition & 0 deletions adb/adb_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def main():

common_cli.MakeSubparser(
subparsers, parents, adb_commands.AdbCommands.Install)
common_cli.MakeSubparser(subparsers, parents, adb_commands.AdbCommands.Uninstall)
common_cli.MakeSubparser(subparsers, parents, List)
common_cli.MakeSubparser(subparsers, parents, Logcat)
common_cli.MakeSubparser(
Expand Down
9 changes: 9 additions & 0 deletions test/adb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ def testBigResponseShell(self):
self.assertEqual(b''.join(responses).decode('utf8'),
adb_commands.Shell(command))

def testUninstall(self):
package_name = "com.test.package"
response = 'Success'

usb = self._ExpectCommand(b'shell', ('pm uninstall "%s"' % package_name).encode('utf8'), response)

adb_commands = self._Connect(usb)
self.assertEquals(response, adb_commands.Uninstall(package_name))

def testStreamingResponseShell(self):
command = b'keepin it real big'
# expect multiple lines
Expand Down