diff --git a/androidtv/basetv/basetv.py b/androidtv/basetv/basetv.py index 0f895890..75edd4f2 100644 --- a/androidtv/basetv/basetv.py +++ b/androidtv/basetv/basetv.py @@ -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): @@ -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 @@ -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): @@ -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. @@ -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): diff --git a/androidtv/basetv/basetv_async.py b/androidtv/basetv/basetv_async.py index b9d5e288..c6224ad5 100644 --- a/androidtv/basetv/basetv_async.py +++ b/androidtv/basetv/basetv_async.py @@ -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 diff --git a/androidtv/constants.py b/androidtv/constants.py index 175e4d81..a0a837ba 100644 --- a/androidtv/constants.py +++ b/androidtv/constants.py @@ -99,6 +99,10 @@ 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" @@ -106,6 +110,10 @@ class DeviceEnum(IntEnum): #: 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 @@ -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]'" @@ -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