Skip to content

Commit 99e7967

Browse files
authored
Add Android 14 support (#355)
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.
1 parent 6f04990 commit 99e7967

File tree

3 files changed

+43
-42
lines changed

3 files changed

+43
-42
lines changed

androidtv/basetv/basetv.py

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,15 @@ def _cmd_audio_state(self):
134134
if constants.CUSTOM_AUDIO_STATE in self._custom_commands:
135135
return self._custom_commands[constants.CUSTOM_AUDIO_STATE]
136136

137-
# Is this an Android 11 device?
138-
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
139-
return constants.CMD_AUDIO_STATE11
140-
141-
# Is this an Android 12 device?
142-
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
137+
# Is this an Android 11-14 device?
138+
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") in [
139+
"11",
140+
"12",
141+
"13",
142+
"14",
143+
]:
143144
return constants.CMD_AUDIO_STATE11
144145

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

150148
def _cmd_current_app(self):
@@ -183,8 +181,11 @@ def _cmd_current_app(self):
183181
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
184182
return constants.CMD_CURRENT_APP12
185183

186-
# Is this an Android 13 device?
187-
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "13":
184+
# Is this an Android 13/14 device?
185+
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") in [
186+
"13",
187+
"14",
188+
]:
188189
return constants.CMD_CURRENT_APP13
189190

190191
return constants.CMD_CURRENT_APP
@@ -225,8 +226,11 @@ def _cmd_current_app_media_session_state(self):
225226
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
226227
return constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE12
227228

228-
# Is this an Android 13 device?
229-
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "13":
229+
# Is this an Android 13/14 device?
230+
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") in [
231+
"13",
232+
"14",
233+
]:
230234
return constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE13
231235

232236
return constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE
@@ -243,16 +247,13 @@ def _cmd_hdmi_input(self):
243247
if constants.CUSTOM_HDMI_INPUT in self._custom_commands:
244248
return self._custom_commands[constants.CUSTOM_HDMI_INPUT]
245249

246-
# Is this an Android 11 device?
247-
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
248-
return constants.CMD_HDMI_INPUT11
249-
250-
# Is this an Android 12 device?
251-
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
252-
return constants.CMD_HDMI_INPUT11
253-
254-
# Is this an Android 13 device?
255-
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "13":
250+
# Is this an Android 11-14 device?
251+
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") in [
252+
"11",
253+
"12",
254+
"13",
255+
"14",
256+
]:
256257
return constants.CMD_HDMI_INPUT11
257258

258259
return constants.CMD_HDMI_INPUT
@@ -271,16 +272,13 @@ def _cmd_volume_set(self, new_volume):
271272
The device-specific ADB shell command used to set volume
272273
273274
"""
274-
# Is this an Android 11 device?
275-
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
276-
return constants.CMD_VOLUME_SET_COMMAND11.format(new_volume)
277-
278-
# Is this an Android 12 device?
279-
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
280-
return constants.CMD_VOLUME_SET_COMMAND11.format(new_volume)
281-
282-
# Is this an Android 13 device?
283-
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "13":
275+
# Is this an Android 11-14 device?
276+
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") in [
277+
"11",
278+
"12",
279+
"13",
280+
"14",
281+
]:
284282
return constants.CMD_VOLUME_SET_COMMAND11.format(new_volume)
285283

286284
return constants.CMD_VOLUME_SET_COMMAND.format(new_volume)
@@ -321,8 +319,11 @@ def _cmd_launch_app(self, app):
321319
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "12":
322320
return constants.CMD_LAUNCH_APP12.format(app)
323321

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

328329
return constants.CMD_LAUNCH_APP.format(app)

androidtv/constants.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ class DeviceEnum(IntEnum):
7474
#: Get the audio state
7575
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')"
7676

77-
#: Get the audio state for an Android 11 device
77+
#: Get the audio state for an Android 11+ device
7878
CMD_AUDIO_STATE11 = (
79-
"CURRENT_AUDIO_STATE=$(dumpsys audio | sed -r -n '/[0-9]{2}-[0-9]{2}.*player piid:.*state:.*$/h; ${x;p;}') && "
79+
"CURRENT_AUDIO_STATE=$(dumpsys audio | sed -r -n '/[0-9]{2}-[0-9]{2}.*player piid:.*(state|event):(started|paused|stopped).*$/h; ${x;p;}') && "
8080
+ 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' ; }"
8181
)
8282

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

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

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

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

124124

@@ -144,7 +144,7 @@ class DeviceEnum(IntEnum):
144144
#: set volume
145145
CMD_VOLUME_SET_COMMAND = "media volume --show --stream 3 --set {}"
146146

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

150150
#: Get the HDMI input

tests/test_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_constants(self):
7171
# CMD_AUDIO_STATE11
7272
self.assertCommand(
7373
constants.CMD_AUDIO_STATE11,
74-
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' ; }",
74+
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' ; }",
7575
)
7676

7777
# CMD_AWAKE

0 commit comments

Comments
 (0)