Skip to content

Commit efdb28f

Browse files
committed
feat: add ability to change display density (dpi)
1 parent fa23bbf commit efdb28f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ adbe [options] battery saver (on | off)
216216
adbe [options] cat <file_path>
217217
adbe [options] clear-data <app_name>
218218
adbe [options] dark mode (on | off)
219+
adbe [options] debug-app (set [-w] [-p] <app_name> | clear)
219220
adbe [options] devices
221+
adbe [options] display size
222+
adbe [options] display size (ldpi | mdpi | hdpi | xhdpi | xxhdpi | xxxhdpi)
220223
adbe [options] (enable | disable) wireless debugging
221224
adbe [options] dont-keep-activities (on | off)
222225
adbe [options] doze (on | off)

adbe/adb_enhanced.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,3 +2102,16 @@ def print_display_size() -> None:
21022102
print_message("Display size is xxhdpi (480 dpi)")
21032103
else:
21042104
print_message("Display size is xxxhdpi (640 dpi)")
2105+
2106+
2107+
def set_display_size(size: int) -> None:
2108+
"""
2109+
Set the display size to the given value.
2110+
:param size: The display size in dpi.
2111+
"""
2112+
cmd = f"wm density {size:d}"
2113+
result = execute_adb_shell_command3(cmd)
2114+
if result.return_code != 0:
2115+
print_error_and_exit(f"Failed to set display size, stderr: {result.stderr}")
2116+
2117+
print_verbose(f"Display size set to {size:d} dpi")

adbe/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
adbe [options] debug-app (set [-w] [-p] <app_name> | clear)
4343
adbe [options] devices
4444
adbe [options] display size
45+
adbe [options] display size (ldpi | mdpi | hdpi | xhdpi | xxhdpi | xxxhdpi)
4546
adbe [options] (enable | disable) wireless debugging
4647
adbe [options] dont-keep-activities (on | off)
4748
adbe [options] doze (on | off)
@@ -196,6 +197,12 @@ def _get_actions(args: dict[str, typing.Any]) -> dict[tuple[str, str], typing.Ca
196197

197198
# Display size related
198199
# https://developer.android.com/training/multiscreen/screendensities
200+
("display", "size", "ldpi"): lambda: adb_enhanced.set_display_size(120),
201+
("display", "size", "mdpi"): lambda: adb_enhanced.set_display_size(160),
202+
("display", "size", "hdpi"): lambda: adb_enhanced.set_display_size(240),
203+
("display", "size", "xhdpi"): lambda: adb_enhanced.set_display_size(320),
204+
("display", "size", "xxhdpi"): lambda: adb_enhanced.set_display_size(480),
205+
("display", "size", "xxxhdpi"): lambda: adb_enhanced.set_display_size(640),
199206
("display", "size"): adb_enhanced.print_display_size,
200207

201208
# GFX

0 commit comments

Comments
 (0)