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

Add Android 14 support #355

Merged
merged 1 commit into from
Nov 10, 2024
Merged
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
71 changes: 36 additions & 35 deletions androidtv/basetv/basetv.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,15 @@ def _cmd_audio_state(self):
if constants.CUSTOM_AUDIO_STATE in self._custom_commands:
return self._custom_commands[constants.CUSTOM_AUDIO_STATE]

# 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":
# Is this an Android 11-14 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") in [
"11",
"12",
"13",
"14",
]:
JeffLIrion marked this conversation as resolved.
Show resolved Hide resolved
return constants.CMD_AUDIO_STATE11

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

def _cmd_current_app(self):
Expand Down Expand Up @@ -175,8 +173,11 @@ def _cmd_current_app(self):
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
return constants.CMD_CURRENT_APP12

# Is this an Android 13 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "13":
# Is this an Android 13/14 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") in [
"13",
"14",
]:
return constants.CMD_CURRENT_APP13

return constants.CMD_CURRENT_APP
Expand Down Expand Up @@ -209,8 +210,11 @@ def _cmd_current_app_media_session_state(self):
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
return constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE12

# Is this an Android 13 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "13":
# Is this an Android 13/14 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") in [
"13",
"14",
]:
return constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE13

return constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE
Expand All @@ -227,16 +231,13 @@ def _cmd_hdmi_input(self):
if constants.CUSTOM_HDMI_INPUT in self._custom_commands:
return self._custom_commands[constants.CUSTOM_HDMI_INPUT]

# 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

# Is this an Android 13 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "13":
# Is this an Android 11-14 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") in [
"11",
"12",
"13",
"14",
]:
return constants.CMD_HDMI_INPUT11

return constants.CMD_HDMI_INPUT
Expand All @@ -255,16 +256,13 @@ def _cmd_volume_set(self, new_volume):
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_COMMAND11.format(new_volume)

# 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_COMMAND11.format(new_volume)

# Is this an Android 13 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "13":
# Is this an Android 11-14 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") in [
"11",
"12",
"13",
"14",
]:
return constants.CMD_VOLUME_SET_COMMAND11.format(new_volume)

return constants.CMD_VOLUME_SET_COMMAND.format(new_volume)
Expand Down Expand Up @@ -305,8 +303,11 @@ def _cmd_launch_app(self, app):
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
return constants.CMD_LAUNCH_APP12.format(app)

# Is this an Android 13 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "13":
# Is this an Android 13-14 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") in [
"13",
"14",
]:
return constants.CMD_LAUNCH_APP13.format(app)

return constants.CMD_LAUNCH_APP.format(app)
Expand Down
12 changes: 6 additions & 6 deletions androidtv/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class DeviceEnum(IntEnum):
#: Get the audio state
CMD_AUDIO_STATE = r"dumpsys audio | grep paused | grep -qv 'Buffer Queue' && echo -e '1\c' || (dumpsys audio | grep started | grep -qv 'Buffer Queue' && echo '2\c' || echo '0\c')"

#: Get the audio state for an Android 11 device
#: Get the audio state for an Android 11+ device
CMD_AUDIO_STATE11 = (
"CURRENT_AUDIO_STATE=$(dumpsys audio | sed -r -n '/[0-9]{2}-[0-9]{2}.*player piid:.*state:.*$/h; ${x;p;}') && "
"CURRENT_AUDIO_STATE=$(dumpsys audio | sed -r -n '/[0-9]{2}-[0-9]{2}.*player piid:.*(state|event):(started|paused|stopped).*$/h; ${x;p;}') && "
+ r"echo $CURRENT_AUDIO_STATE | grep -q paused && echo -e '1\c' || { echo $CURRENT_AUDIO_STATE | grep -q started && echo '2\c' || echo '0\c' ; }"
)

Expand All @@ -86,7 +86,7 @@ class DeviceEnum(IntEnum):
#: Parse current application identifier from dumpsys output and assign it to ``CURRENT_APP`` variable (assumes dumpsys output is momentarily set to ``CURRENT_APP`` variable)
CMD_PARSE_CURRENT_APP = "CURRENT_APP=${CURRENT_APP#*ActivityRecord{* * } && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP%\\}*}"

#: Parse current application for an Android 11 device
#: Parse current application for an Android 11+ device
CMD_PARSE_CURRENT_APP11 = "CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP##* }"
#: Assign focused application identifier to ``CURRENT_APP`` variable
CMD_DEFINE_CURRENT_APP_VARIABLE = (
Expand All @@ -103,7 +103,7 @@ class DeviceEnum(IntEnum):
+ CMD_PARSE_CURRENT_APP11
)

#: Assign focused application identifier to ``CURRENT_APP`` variable for an Android 13 device
#: Assign focused application identifier to ``CURRENT_APP`` variable for an Android 13+ device
CMD_DEFINE_CURRENT_APP_VARIABLE13 = (
"CURRENT_APP=$(dumpsys window windows | grep -E -m 1 'imeLayeringTarget|imeInputTarget|imeControlTarget') && "
+ CMD_PARSE_CURRENT_APP11
Expand All @@ -118,7 +118,7 @@ class DeviceEnum(IntEnum):
#: Output identifier for current/focused application for an Android 12 device
CMD_CURRENT_APP12 = CMD_DEFINE_CURRENT_APP_VARIABLE12 + " && echo $CURRENT_APP"

#: Output identifier for current/focused application for an Android 13 device
#: Output identifier for current/focused application for an Android 13+ device
CMD_CURRENT_APP13 = CMD_DEFINE_CURRENT_APP_VARIABLE13 + " && echo $CURRENT_APP"

#: Assign focused application identifier to ``CURRENT_APP`` variable (for a Google TV device)
Expand All @@ -132,7 +132,7 @@ class DeviceEnum(IntEnum):
#: set volume
CMD_VOLUME_SET_COMMAND = "media volume --show --stream 3 --set {}"

#: set volume for an Android 11 & 12 & 13 device
#: set volume for an Android 11+ device
CMD_VOLUME_SET_COMMAND11 = "cmd media_session volume --show --stream 3 --set {}"

#: Get the HDMI input
Expand Down
2 changes: 1 addition & 1 deletion tests/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_constants(self):
# CMD_AUDIO_STATE11
self.assertCommand(
constants.CMD_AUDIO_STATE11,
r"CURRENT_AUDIO_STATE=$(dumpsys audio | sed -r -n '/[0-9]{2}-[0-9]{2}.*player piid:.*state:.*$/h; ${x;p;}') && echo $CURRENT_AUDIO_STATE | grep -q paused && echo -e '1\c' || { echo $CURRENT_AUDIO_STATE | grep -q started && echo '2\c' || echo '0\c' ; }",
r"CURRENT_AUDIO_STATE=$(dumpsys audio | sed -r -n '/[0-9]{2}-[0-9]{2}.*player piid:.*(state|event):(started|paused|stopped).*$/h; ${x;p;}') && echo $CURRENT_AUDIO_STATE | grep -q paused && echo -e '1\c' || { echo $CURRENT_AUDIO_STATE | grep -q started && echo '2\c' || echo '0\c' ; }",
)

# CMD_AWAKE
Expand Down
Loading