Skip to content

Commit

Permalink
feat(shell): Add times for volume_up and volume_down
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaojun0822 authored and codeskyblue committed Apr 16, 2024
1 parent cfa9d09 commit 7c03a72
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
24 changes: 19 additions & 5 deletions adbutils/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


import abc
import datetime
import time, datetime
import json
import re
from typing import List, Optional, Union
Expand Down Expand Up @@ -46,11 +46,25 @@ def keyevent(self, key_code: Union[int, str]):
"""adb shell input keyevent KEY_CODE"""
self.shell(["input", "keyevent", str(key_code)])

def volume_up(self):
self.shell("input keyevent VOLUME_UP")
def volume_up(self, times: int = 1):
"""
Increase the volume by times step
:param times: times to increase volume,default is 1(Wake up volume bar).
:return:
"""
for i in range(times):
self.shell("input keyevent VOLUME_UP")
time.sleep(0.5)

def volume_down(self):
self.shell("input keyevent VOLUME_DOWN")
def volume_down(self, times: int = 1):
"""
Decrease the volume by times step
:param times: times to decrease volume,default is 1(Wake up volume bar).
:return:
"""
for i in range(times):
self.shell("input keyevent VOLUME_DOWN")
time.sleep(0.5)

def volume_mute(self):
self.shell("input keyevent VOLUME_MUTE")
Expand Down
4 changes: 2 additions & 2 deletions test_real_device/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def test_get_xxx(device: AdbDevice):
def test_keyevent(device: AdbDevice):
# make sure no error raised
device.keyevent(4)
device.volume_up()
device.volume_down()
device.volume_up(2)
device.volume_down(3)
device.volume_mute()


Expand Down

0 comments on commit 7c03a72

Please sign in to comment.