Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 39 additions & 1 deletion androidtv/basetv/basetv.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ def _cmd_audio_state(self):
# Is this an Android 11 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
return constants.CMD_AUDIO_STATE11

# Is this an Android 12 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
return constants.CMD_AUDIO_STATE11
return constants.CMD_AUDIO_STATE

def _cmd_current_app(self):
Expand All @@ -156,6 +160,10 @@ def _cmd_current_app(self):
# Is this an Android 11 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
return constants.CMD_CURRENT_APP11

# Is this an Android 12 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
return constants.CMD_CURRENT_APP12

return constants.CMD_CURRENT_APP

Expand Down Expand Up @@ -183,6 +191,10 @@ def _cmd_current_app_media_session_state(self):
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
return constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE11

# Is this an Android 11 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
return constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE12

return constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE

def _cmd_hdmi_input(self):
Expand All @@ -200,9 +212,31 @@ def _cmd_hdmi_input(self):
# Is this an Android 11 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
return constants.CMD_HDMI_INPUT11


# Is this an Android 12 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
return constants.CMD_HDMI_INPUT11
return constants.CMD_HDMI_INPUT

def _cmd_volume_set(self):
"""Get the command used to set volume for this device.

Returns
-------
str
The device-specific ADB shell command used to set volume

"""
# Is this an Android 11 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
return constants.CMD_VOLUME_SET_COMMAND12

# Is this an Android 12 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
return constants.CMD_VOLUME_SET_COMMAND12

return constants.CMD_VOLUME_SET_COMMAND

def _cmd_launch_app(self, app):
"""Get the command to launch the specified app for this device.

Expand Down Expand Up @@ -235,6 +269,10 @@ def _cmd_launch_app(self, app):
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
return constants.CMD_LAUNCH_APP11.format(app)

# Is this an Android 12 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
return constants.CMD_LAUNCH_APP11.format(app)

return constants.CMD_LAUNCH_APP.format(app)

def _cmd_running_apps(self):
Expand Down
2 changes: 1 addition & 1 deletion androidtv/basetv/basetv_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ async def set_volume_level(self, volume_level):

new_volume = int(min(max(round(self.max_volume * volume_level), 0.0), self.max_volume))

await self._adb.shell("media volume --show --stream 3 --set {}".format(new_volume))
await self._adb.shell(self._cmd_volume_set().format(new_volume))

# return the new volume level
return new_volume / self.max_volume
Expand Down
22 changes: 22 additions & 0 deletions androidtv/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,21 @@ class DeviceEnum(IntEnum):
"CURRENT_APP=$(dumpsys window windows | grep 'mInputMethodTarget') && " + CMD_PARSE_CURRENT_APP11
)

#: Assign focused application identifier to ``CURRENT_APP`` variable for an Android 12 device
CMD_DEFINE_CURRENT_APP_VARIABLE12 = (
"CURRENT_APP=$(dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp|mObscuringWindow') && " + CMD_PARSE_CURRENT_APP11
)

#: Output identifier for current/focused application
CMD_CURRENT_APP = CMD_DEFINE_CURRENT_APP_VARIABLE + " && echo $CURRENT_APP"

#: Output identifier for current/focused application for an Android 11 device
CMD_CURRENT_APP11 = CMD_DEFINE_CURRENT_APP_VARIABLE11 + " && echo $CURRENT_APP"


#: Output identifier for current/focused application for an Android 12 device
CMD_CURRENT_APP12 = CMD_DEFINE_CURRENT_APP_VARIABLE12 + " && echo $CURRENT_APP"

#: Assign focused application identifier to ``CURRENT_APP`` variable (for a Google TV device)
CMD_DEFINE_CURRENT_APP_VARIABLE_GOOGLE_TV = (
"CURRENT_APP=$(dumpsys activity a . | grep mResumedActivity) && " + CMD_PARSE_CURRENT_APP
Expand All @@ -114,6 +122,17 @@ class DeviceEnum(IntEnum):
#: Output identifier for current/focused application (for a Google TV device)
CMD_CURRENT_APP_GOOGLE_TV = CMD_DEFINE_CURRENT_APP_VARIABLE_GOOGLE_TV + " && echo $CURRENT_APP"

#: set volume
CMD_VOLUME_SET_COMMAND = (
"media volume --show --stream 3 --set {}"
)

#: set volume for an Android 12 device
CMD_VOLUME_SET_COMMAND12 = (
"cmd media_session volume --show --stream 3 --set {}"
)


#: Get the HDMI input
CMD_HDMI_INPUT = (
"dumpsys activity starter | grep -E -o '(ExternalTv|HDMI)InputService/HW[0-9]' -m 1 | grep -o 'HW[0-9]'"
Expand Down Expand Up @@ -164,6 +183,9 @@ class DeviceEnum(IntEnum):
#: Determine the current app and get the state from ``dumpsys media_session`` for an Android 11 device
CMD_CURRENT_APP_MEDIA_SESSION_STATE11 = CMD_CURRENT_APP11 + " && " + CMD_MEDIA_SESSION_STATE

#: Determine the current app and get the state from ``dumpsys media_session`` for an Android 12 device
CMD_CURRENT_APP_MEDIA_SESSION_STATE12 = CMD_CURRENT_APP12 + " && " + CMD_MEDIA_SESSION_STATE

#: Determine the current app and get the state from ``dumpsys media_session`` for a Google TV device
CMD_CURRENT_APP_MEDIA_SESSION_STATE_GOOGLE_TV = CMD_CURRENT_APP_GOOGLE_TV + " && " + CMD_MEDIA_SESSION_STATE

Expand Down