diff --git a/docker-compose.yaml b/docker-compose.yaml index 46b89f2..37e5705 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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 diff --git a/ppadb/device.py b/ppadb/device.py index a7d7dd4..eda1a93 100644 --- a/ppadb/device.py +++ b/ppadb/device.py @@ -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 diff --git a/ppadb/device_async.py b/ppadb/device_async.py index 26c23de..992557e 100644 --- a/ppadb/device_async.py +++ b/ppadb/device_async.py @@ -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 diff --git a/requirements.txt b/requirements.txt index 274fbc7..0e59c78 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pytest Exscript +aiofiles >= 0.4.0