Skip to content

Commit

Permalink
Add Android 14 support
Browse files Browse the repository at this point in the history
Only tested on the Google TV Streamer for now, so the HDMI input stuff
may need further tweaking once this actually rolls out to things with
HDMI inputs.
  • Loading branch information
K900 committed Oct 30, 2024
1 parent ac4b909 commit 0d82f27
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 41 deletions.
47 changes: 12 additions & 35 deletions androidtv/basetv/basetv.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,10 @@ 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", "") == ["11", "12", "13", "14"]:
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 +168,8 @@ 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 All @@ -201,7 +194,7 @@ def _cmd_current_app_media_session_state(self):
):
return constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE_GOOGLE_TV

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

Expand All @@ -210,7 +203,7 @@ def _cmd_current_app_media_session_state(self):
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":
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 +220,8 @@ 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 +240,8 @@ 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 +282,8 @@ 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):(paused|started).*$/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

0 comments on commit 0d82f27

Please # to comment.