Skip to content

Commit 8d2cecf

Browse files
committed
feat: add "display size" command to print display size
1 parent 65d2784 commit 8d2cecf

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

adbe/adb_enhanced.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,3 +2086,27 @@ def print_state_change_info(state_name: str, old_state: str | int | bool, new_st
20862086
print_message(f'"{state_name}" state changed from "{old_state}" -> "{new_state}"')
20872087
else:
20882088
print_message(f'"{state_name}" state unchanged ({old_state})')
2089+
2090+
2091+
def print_display_size() -> None:
2092+
# Ref: https://developer.android.com/training/multiscreen/screendensities
2093+
cmd = "shell wm density"
2094+
return_code, stdout, stderr = execute_adb_command2(cmd)
2095+
assert return_code == 0, f"Failed to get display size, stderr: {stderr}"
2096+
display_size = re.search(r"Physical density: (\d+)", stdout)
2097+
if display_size is None:
2098+
print_error_and_exit("Failed to get display size")
2099+
2100+
display_size = int(display_size.group(1))
2101+
if display_size < 120:
2102+
print_message("Display size is ldpi (120 dpi)")
2103+
elif display_size < 160:
2104+
print_message("Display size is mdpi (160 dpi)")
2105+
elif display_size < 240:
2106+
print_message("Display size is hdpi (240 dpi)")
2107+
elif display_size < 320:
2108+
print_message("Display size is xhdpi (320 dpi)")
2109+
elif display_size < 480:
2110+
print_message("Display size is xxhdpi (480 dpi)")
2111+
else:
2112+
print_message("Display size is xxxhdpi (640 dpi)")

adbe/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
adbe [options] dark mode (on | off)
4242
adbe [options] debug-app (set [-w] [-p] <app_name> | clear)
4343
adbe [options] devices
44+
adbe [options] display size
4445
adbe [options] (enable | disable) wireless debugging
4546
adbe [options] dont-keep-activities (on | off)
4647
adbe [options] doze (on | off)
@@ -193,6 +194,10 @@ def _get_actions(args: dict[str, typing.Any]) -> dict[tuple[str, str], typing.Ca
193194
# List devices
194195
("devices",): adb_enhanced.handle_list_devices,
195196

197+
# Display size related
198+
# https://developer.android.com/training/multiscreen/screendensities
199+
("display", "size"): adb_enhanced.print_display_size,
200+
196201
# GFX
197202
("gfx", "on"): lambda: adb_enhanced.handle_gfx("on"),
198203
("gfx", "off"): lambda: adb_enhanced.handle_gfx("off"),

0 commit comments

Comments
 (0)