Skip to content
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
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
environment:
- PYTHONPATH=/code
- PYTHONUNBUFFERED=0
command: sh -c "pip install -r requirements.txt;pip install 'Exscript';py.test test -s -v --junit-xml test_result.xml;pip install 'aiofiles>=0.4.0';py.test test_async -s -v --junit-xml test_result_async.xml;"
command: sh -c "pip install -r requirements.txt;py.test test -s -v --junit-xml test_result.xml;py.test test_async -s -v --junit-xml test_result_async.xml;"

emulator:
image: swind/android-emulator:android_28
Expand Down
37 changes: 23 additions & 14 deletions ppadb/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,28 @@ def is_installed(self, package):
return False

def uninstall(self, package):
result = self.shell("pm uninstall {}".format(package))
attempts_remaining = 2
while attempts_remaining > 0:
attempts_remaining -= 1

m = re.search(self.UNINSTALL_RESULT_PATTERN, result)
result = self.shell("pm uninstall {}".format(package))
m = re.search(self.UNINSTALL_RESULT_PATTERN, result)

if m and m.group(1) == "Success":
return True
elif m:
logger.error(m.group(1))
if "DELETE_FAILED_DEVICE_POLICY_MANAGER" in m.group(1):
logger.info("App is device-admin, calling disable-user")
self.shell("pm disable-user {}".format(package))
return self.uninstall(package)
return False
else:
logger.error("There is no message after uninstalling")
return False
if m and m.group(1) == "Success":
return True
elif m:
if (
"DELETE_FAILED_DEVICE_POLICY_MANAGER" in m.group(1)
and attempts_remaining > 0
):
logger.warn(m.group(1))
logger.info("App is device-admin, calling disable-user")
self.shell("pm disable-user {}".format(package))
else:
logger.error(m.group(1))
return False
else:
logger.error("There is no message after uninstalling")
return False

return False
33 changes: 23 additions & 10 deletions ppadb/device_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,28 @@ async def install(
await self.shell("rm -f {}".format(dest))

async def uninstall(self, package):
result = await self.shell("pm uninstall {}".format(package))
attempts_remaining = 2
while attempts_remaining > 0:
attempts_remaining -= 1

m = re.search(self.UNINSTALL_RESULT_PATTERN, result)
result = await self.shell("pm uninstall {}".format(package))
m = re.search(self.UNINSTALL_RESULT_PATTERN, result)

if m and m.group(1) == "Success":
return True
elif m:
logger.error(m.group(1))
return False
else:
logger.error("There is no message after uninstalling")
return False
if m and m.group(1) == "Success":
return True
elif m:
if (
"DELETE_FAILED_DEVICE_POLICY_MANAGER" in m.group(1)
and attempts_remaining > 0
):
logger.warn(m.group(1))
logger.info("App is device-admin, calling disable-user")
await self.shell("pm disable-user {}".format(package))
else:
logger.error(m.group(1))
return False
else:
logger.error("There is no message after uninstalling")
return False

return False
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest
Exscript
aiofiles >= 0.4.0