Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt various pull requests #4

Merged
merged 23 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
753e331
Update __init__.py
r0xen Nov 12, 2021
d731fd2
call disable-user while uninstalling if app is device-admin
eybisi Feb 10, 2022
9675c44
mark pattern variables raw strings
mib1185 Apr 1, 2024
b85afe7
mark more pattern variables raw strings
mib1185 Apr 2, 2024
2710257
Fix SyntaxWarning
eamanu Dec 18, 2024
6693e67
fix openning quote
eamanu Dec 18, 2024
a13c5d9
Manually add https://github.com/Swind/pure-python-adb/pull/85
CloCkWeRX Feb 9, 2025
f0499b0
Merge remote-tracking branch 'eamanu/fix-syntax-warning'
CloCkWeRX Feb 9, 2025
26f9498
Merge remote-tracking branch 'mib1185/mark-regex-patterns-as-raw-stri…
CloCkWeRX Feb 9, 2025
67bde3a
Merge remote-tracking branch 'eybisi/uninstall-device-admin-app'
CloCkWeRX Feb 9, 2025
d87401f
Merge commit '753e331'
CloCkWeRX Feb 9, 2025
3a31315
Merge remote-tracking branch 'JeffLIrion/recursive-push-async'
CloCkWeRX Feb 9, 2025
643f48f
Merge branch 'master' of https://github.com/spm5065/pure-python-adb
CloCkWeRX Feb 9, 2025
b042d1b
Run black
CloCkWeRX Feb 9, 2025
e162469
Fix https://github.com/Swind/pure-python-adb/issues/94 ; Apply a vers…
CloCkWeRX Feb 9, 2025
5bbf54c
Add a workaround for https://github.com/Swind/pure-python-adb/issues/110
CloCkWeRX Feb 9, 2025
6aa757a
Add a workaround for https://github.com/Swind/pure-python-adb/issues/110
CloCkWeRX Feb 9, 2025
61022fa
Add history
CloCkWeRX Feb 9, 2025
0eee352
Add history
CloCkWeRX Feb 9, 2025
00be401
Add history
CloCkWeRX Feb 9, 2025
c7a225c
Improve metadata
CloCkWeRX Feb 9, 2025
88552d3
Update HISTORY.rst
CloCkWeRX Feb 9, 2025
d7d4a1b
Merge branch 'master' into master
CloCkWeRX Feb 17, 2025
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
17 changes: 17 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
0.3.0 (Unreleased)
--------------------

* Fixes #111: Invalid escape sequence via @eamanu and @mib1185
* Fixes #110: Add ability to pass extra arguments to `screencap` commands for waydroid via @CloCkWeRX
* Fixes #88: Missing return in ppadb.command.transport: Transport.shell() for custom handler via @roxen
* Fixes #60: Close socket if the connection fails via @JeffLIrion
* Fixes #64: ADB reverse command via @Hamz-a
* Fixes #92: incorrect timestamp type in asynchronous push via @slicen and @GeekDuanLian
* Adds #65: Added support to remove reverses via @Hamz-a
* Adds #67: asynchronous install and uninstall commands via @slicen
* Adds #85: Include LICENSE in pip package via @jan-janssen
* Adds #57: Recursive directory push for DeviceAsync class via @JeffLIrion
* Adds #89: Call disable-user if app is device-admin via @eybisi
* Change #94: Device#install and DeviceAsync#install changes param from `grand_all_permissions` to `grant_all_permissions`


0.2.1 (2019-10-14)
--------------------

Expand Down
2 changes: 1 addition & 1 deletion ppadb/command/host/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class Host(Command):
CONNECT_RESULT_PATTERN = "(connected to|already connected)"
CONNECT_RESULT_PATTERN = r"(connected to|already connected)"

OFFLINE = "offline"
DEVICE = "device"
Expand Down
2 changes: 1 addition & 1 deletion ppadb/command/host_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class HostAsync:
CONNECT_RESULT_PATTERN = "(connected to|already connected)"
CONNECT_RESULT_PATTERN = r"(connected to|already connected)"

OFFLINE = "offline"
DEVICE = "device"
Expand Down
14 changes: 8 additions & 6 deletions ppadb/command/transport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def shell(self, cmd, handler=None, timeout=None):
conn.send(cmd)

if handler:
handler(conn)
return handler(conn)
else:
result = conn.read_all()
conn.close()
Expand All @@ -37,11 +37,13 @@ def sync(self):

return conn

def screencap(self):
def screencap(self, optional_args=None):
conn = self.create_connection()

with conn:
cmd = "shell:/system/bin/screencap -p"
if optional_args is not None:
cmd = cmd + " " + optional_args
conn.send(cmd)
result = conn.read_all()

Expand All @@ -51,7 +53,7 @@ def screencap(self):
return result

def clear(self, package):
clear_result_pattern = "(Success|Failed)"
clear_result_pattern = r"(Success|Failed)"

result = self.shell("pm clear {}".format(package))
m = re.search(clear_result_pattern, result)
Expand All @@ -68,7 +70,7 @@ def framebuffer(self):
def list_features(self):
result = self.shell("pm list features 2>/dev/null")

result_pattern = "^feature:(.*?)(?:=(.*?))?\r?$"
result_pattern = r"^feature:(.*?)(?:=(.*?))?\r?$"
features = {}
for line in result.split("\n"):
m = re.match(result_pattern, line)
Expand All @@ -80,7 +82,7 @@ def list_features(self):

def list_packages(self):
result = self.shell("pm list packages 2>/dev/null")
result_pattern = "^package:(.*?)\r?$"
result_pattern = r"^package:(.*?)\r?$"

packages = []
for line in result.split("\n"):
Expand All @@ -92,7 +94,7 @@ def list_packages(self):

def get_properties(self):
result = self.shell("getprop")
result_pattern = "^\[([\s\S]*?)\]: \[([\s\S]*?)\]\r?$"
result_pattern = r"^\[([\s\S]*?)\]: \[([\s\S]*?)\]\r?$"

properties = {}
for line in result.split("\n"):
Expand Down
6 changes: 5 additions & 1 deletion ppadb/command/transport_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ async def sync(self):

return conn

async def screencap(self):
# Take a screenshot. Optionally, you can pass
# additional command line arguments, ie "2>/dev/null"
async def screencap(self, optional_args=None):
async with await self.create_connection() as conn:
cmd = "shell:/system/bin/screencap -p"
if optional_args is not None:
cmd = cmd + " " + optional_args
await conn.send(cmd)
result = await conn.read_all()

Expand Down
12 changes: 8 additions & 4 deletions ppadb/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@


class Device(Transport, Serial, Input, Utils, WM, Traffic, CPUStat, BatteryStats):
INSTALL_RESULT_PATTERN = "(Success|Failure|Error)\s?(.*)"
UNINSTALL_RESULT_PATTERN = "(Success|Failure.*|.*Unknown package:.*)"
INSTALL_RESULT_PATTERN = r"(Success|Failure|Error)\s?(.*)"
UNINSTALL_RESULT_PATTERN = r"(Success|Failure.*|.*Unknown package:.*)"

def __init__(self, client, serial):
self.client = client
Expand Down Expand Up @@ -90,7 +90,7 @@ def install(
shared_mass_storage=False, # -s
internal_system_memory=False, # -f
downgrade=False, # -d
grand_all_permissions=False, # -g
grant_all_permissions=False, # -g
):
dest = Sync.temp(path)
self.push(path, dest)
Expand All @@ -110,7 +110,7 @@ def install(
parameters.append("-f")
if downgrade:
parameters.append("-d")
if grand_all_permissions:
if grant_all_permissions:
parameters.append("-g")

try:
Expand Down Expand Up @@ -146,6 +146,10 @@ def uninstall(self, package):
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")
Expand Down
8 changes: 4 additions & 4 deletions ppadb/device_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@


class DeviceAsync(TransportAsync):
INSTALL_RESULT_PATTERN = "(Success|Failure|Error)\s?(.*)"
UNINSTALL_RESULT_PATTERN = "(Success|Failure.*|.*Unknown package:.*)"
INSTALL_RESULT_PATTERN = r"(Success|Failure|Error)\s?(.*)"
UNINSTALL_RESULT_PATTERN = r"(Success|Failure.*|.*Unknown package:.*)"

def __init__(self, client, serial):
self.client = client
Expand Down Expand Up @@ -75,7 +75,7 @@ async def install(
shared_mass_storage=False, # -s
internal_system_memory=False, # -f
downgrade=False, # -d
grand_all_permissions=False, # -g
grant_all_permissions=False, # -g
):
dest = SyncAsync.temp(path)

Expand All @@ -99,7 +99,7 @@ async def install(
parameters.append("-f")
if downgrade:
parameters.append("-d")
if grand_all_permissions:
if grant_all_permissions:
parameters.append("-g")

try:
Expand Down
2 changes: 1 addition & 1 deletion ppadb/plugins/device/cpustat.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def total(self):

class CPUStat(Plugin):
total_cpu_pattern = re.compile(
"cpu\s+([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s"
r"cpu\s+([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s"
)

def cpu_times(self):
Expand Down
2 changes: 1 addition & 1 deletion ppadb/plugins/device/traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_traffic(self, package_name):
cmd = "dumpsys package {} | grep userId".format(package_name)
result = self.shell(cmd).strip()

pattern = "userId=([\d]+)"
pattern = r"userId=([\d]+)"

if result:
match = re.search(pattern, result)
Expand Down
20 changes: 10 additions & 10 deletions ppadb/plugins/device/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_top_activity(self):
return None

def get_top_activities(self):
pattern = "ACTIVITY\s([\w\.]+)/([\w\.]+)\s[\w\d]+\spid=([\d]+)"
pattern = r"ACTIVITY\s([\w\.]+)/([\w\.]+)\s[\w\d]+\spid=([\d]+)"
cmd = "dumpsys activity top | grep ACTIVITY"
result = self.shell(cmd)

Expand All @@ -57,13 +57,13 @@ def get_top_activities(self):

def get_meminfo(self, package_name):
total_meminfo_re = re.compile(
"\s*TOTAL\s*(?P<pss>\d+)"
"\s*(?P<private_dirty>\d+)"
"\s*(?P<private_clean>\d+)"
"\s*(?P<swapped_dirty>\d+)"
"\s*(?P<heap_size>\d+)"
"\s*(?P<heap_alloc>\d+)"
"\s*(?P<heap_free>\d+)"
r"\s*TOTAL\s*(?P<pss>\d+)"
r"\s*(?P<private_dirty>\d+)"
r"\s*(?P<private_clean>\d+)"
r"\s*(?P<swapped_dirty>\d+)"
r"\s*(?P<heap_size>\d+)"
r"\s*(?P<heap_alloc>\d+)"
r"\s*(?P<heap_free>\d+)"
)

cmd = "dumpsys meminfo {}".format(package_name)
Expand Down Expand Up @@ -95,7 +95,7 @@ def get_uid(self, package_name):
cmd = "dumpsys package {} | grep userId".format(package_name)
result = self.shell(cmd).strip()

pattern = "userId=([\d]+)"
pattern = r"userId=([\d]+)"

if result:
match = re.search(pattern, result)
Expand All @@ -112,7 +112,7 @@ def get_package_version_name(self, package_name):
cmd = "dumpsys package {} | grep versionName".format(package_name)
result = self.shell(cmd).strip()

pattern = "versionName=([\d\.]+)"
pattern = r"versionName=([\d\.]+)"

if result:
match = re.search(pattern, result)
Expand Down
2 changes: 1 addition & 1 deletion ppadb/plugins/device/wm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class WM(Plugin):
SIZE_RE = "Physical size:\s([\d]+)x([\d]+)"
SIZE_RE = r"Physical size:\s([\d]+)x([\d]+)"

def wm_size(self):
result = self.shell("wm size")
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
setup(
name="pure-python-adb",
version="0.3.0-dev",
description="Pure python implementation of the adb client",
description="Pure python implementation of the adb client, forked and maintained",
long_description=readme + "\n\n" + history,
author="Swind Ou",
author_email="[email protected]",
url="https://github.com/Swind/pure-python-adb",
author="Sergio Martins",
author_email="",
url="https://github.com/spm5065/pure-python-adb",
license="MIT license",
packages=find_packages(exclude=["*.test", "*.test.*", "test.*", "test"]),
install_requires=[],
Expand Down