androidtv.constants module¶
Constants used throughout the code.
Links
-
androidtv.constants.
CMD_AUDIO_STATE
= "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
-
androidtv.constants.
CMD_AWAKE
= 'dumpsys power | grep mWakefulness | grep -q Awake'¶ Determine whether the device is awake
-
androidtv.constants.
CMD_CURRENT_APP
= "CURRENT_APP=$(dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp') && CURRENT_APP=${CURRENT_APP#*ActivityRecord{* * } && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP%\\}*} && echo $CURRENT_APP"¶ Output identifier for current/focused application
-
androidtv.constants.
CMD_CURRENT_APP_GOOGLE_TV
= 'CURRENT_APP=$(dumpsys activity a . | grep mResumedActivity) && CURRENT_APP=${CURRENT_APP#*ActivityRecord{* * } && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP%\\}*} && echo $CURRENT_APP'¶ Output identifier for current/focused application (for a Google TV device)
-
androidtv.constants.
CMD_CURRENT_APP_MEDIA_SESSION_STATE
= "CURRENT_APP=$(dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp') && CURRENT_APP=${CURRENT_APP#*ActivityRecord{* * } && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP%\\}*} && echo $CURRENT_APP && dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {'"¶ Determine the current app and get the state from
dumpsys media_session
-
androidtv.constants.
CMD_CURRENT_APP_MEDIA_SESSION_STATE_GOOGLE_TV
= "CURRENT_APP=$(dumpsys activity a . | grep mResumedActivity) && CURRENT_APP=${CURRENT_APP#*ActivityRecord{* * } && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP%\\}*} && echo $CURRENT_APP && dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {'"¶ Determine the current app and get the state from
dumpsys media_session
for a Google TV device
-
androidtv.constants.
CMD_DEFINE_CURRENT_APP_VARIABLE
= "CURRENT_APP=$(dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp') && CURRENT_APP=${CURRENT_APP#*ActivityRecord{* * } && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP%\\}*}"¶ Assign focused application identifier to
CURRENT_APP
variable
-
androidtv.constants.
CMD_DEFINE_CURRENT_APP_VARIABLE_GOOGLE_TV
= 'CURRENT_APP=$(dumpsys activity a . | grep mResumedActivity) && CURRENT_APP=${CURRENT_APP#*ActivityRecord{* * } && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP%\\}*}'¶ Assign focused application identifier to
CURRENT_APP
variable (for a Google TV device)
-
androidtv.constants.
CMD_DEVICE_PROPERTIES
= 'getprop ro.product.manufacturer && getprop ro.product.model && getprop ro.serialno && getprop ro.build.version.release'¶ The command used for getting the device properties
-
androidtv.constants.
CMD_HDMI_INPUT
= "dumpsys activity starter | grep -E -o '(ExternalTv|HDMI)InputService/HW[0-9]' -m 1 | grep -o 'HW[0-9]'"¶ Get the HDMI input
-
androidtv.constants.
CMD_INSTALLED_APPS
= 'pm list packages'¶ Get installed apps
-
androidtv.constants.
CMD_LAUNCH_APP
= "CURRENT_APP=$(dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp') && CURRENT_APP=${{CURRENT_APP#*ActivityRecord{{* * }} && CURRENT_APP=${{CURRENT_APP#*{{* * }} && CURRENT_APP=${{CURRENT_APP%%/*}} && CURRENT_APP=${{CURRENT_APP%\\}}*}} && if [ $CURRENT_APP != '{0}' ]; then monkey -p {0} -c android.intent.category.LEANBACK_LAUNCHER --pct-syskeys 0 1; fi"¶ Launch an app if it is not already the current app
-
androidtv.constants.
CMD_LAUNCH_APP_CONDITION
= "if [ $CURRENT_APP != '{0}' ]; then monkey -p {0} -c android.intent.category.LEANBACK_LAUNCHER --pct-syskeys 0 1; fi"¶ Launch an app if it is not already the current app (assumes the variable
CURRENT_APP
has already been set)
-
androidtv.constants.
CMD_LAUNCH_APP_CONDITION_FIRETV
= "if [ $CURRENT_APP != '{0}' ]; then monkey -p {0} -c android.intent.category.LAUNCHER --pct-syskeys 0 1; fi"¶ Launch an app if it is not already the current app (assumes the variable
CURRENT_APP
has already been set) on a Fire TV
-
androidtv.constants.
CMD_LAUNCH_APP_FIRETV
= "CURRENT_APP=$(dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp') && CURRENT_APP=${{CURRENT_APP#*ActivityRecord{{* * }} && CURRENT_APP=${{CURRENT_APP#*{{* * }} && CURRENT_APP=${{CURRENT_APP%%/*}} && CURRENT_APP=${{CURRENT_APP%\\}}*}} && if [ $CURRENT_APP != '{0}' ]; then monkey -p {0} -c android.intent.category.LAUNCHER --pct-syskeys 0 1; fi"¶ Launch an app on a Fire TV device
-
androidtv.constants.
CMD_LAUNCH_APP_GOOGLE_TV
= "CURRENT_APP=$(dumpsys activity a . | grep mResumedActivity) && CURRENT_APP=${{CURRENT_APP#*ActivityRecord{{* * }} && CURRENT_APP=${{CURRENT_APP#*{{* * }} && CURRENT_APP=${{CURRENT_APP%%/*}} && CURRENT_APP=${{CURRENT_APP%\\}}*}} && if [ $CURRENT_APP != '{0}' ]; then monkey -p {0} -c android.intent.category.LEANBACK_LAUNCHER --pct-syskeys 0 1; fi"¶ Launch an app on a Google TV device
-
androidtv.constants.
CMD_MEDIA_SESSION_STATE
= "dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {'"¶ Get the state from
dumpsys media_session
; this assumes that the variableCURRENT_APP
has been defined
-
androidtv.constants.
CMD_PARSE_CURRENT_APP
= 'CURRENT_APP=${CURRENT_APP#*ActivityRecord{* * } && CURRENT_APP=${CURRENT_APP#*{* * } && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP%\\}*}'¶ Parse current application identifier from dumpsys output and assign it to
CURRENT_APP
variable (assumes dumpsys output is momentarily set toCURRENT_APP
variable)
-
androidtv.constants.
CMD_RUNNING_APPS_ANDROIDTV
= 'ps -A | grep u0_a'¶ Get the running apps for an Android TV device
-
androidtv.constants.
CMD_RUNNING_APPS_FIRETV
= 'ps | grep u0_a'¶ Get the running apps for a Fire TV device
-
androidtv.constants.
CMD_SCREEN_ON
= "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true')"¶ Determine if the device is on
-
androidtv.constants.
CMD_SCREEN_ON_AWAKE_WAKE_LOCK_SIZE
= "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') && echo -e '1\\c' || echo -e '0\\c' && dumpsys power | grep mWakefulness | grep -q Awake && echo -e '1\\c' || echo -e '0\\c' && dumpsys power | grep Locks | grep 'size='"¶ Determine if the device is on, the screen is on, and get the wake lock size
-
androidtv.constants.
CMD_STREAM_MUSIC
= "dumpsys audio | grep '\\- STREAM_MUSIC:' -A 11"¶ Get the “STREAM_MUSIC” block from
dumpsys audio
-
androidtv.constants.
CMD_TURN_OFF_ANDROIDTV
= "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') && input keyevent 26"¶ KEY_POWER = 26 is defined below)
- Type
Turn off an Android TV device (note
-
androidtv.constants.
CMD_TURN_OFF_FIRETV
= "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') && input keyevent 223"¶ KEY_SLEEP = 223 is defined below)
- Type
Turn off a Fire TV device (note
-
androidtv.constants.
CMD_TURN_ON_ANDROIDTV
= "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') || input keyevent 26"¶ KEY_POWER = 26 is defined below)
- Type
Turn on an Android TV device (note
-
androidtv.constants.
CMD_TURN_ON_FIRETV
= "(dumpsys power | grep 'Display Power' | grep -q 'state=ON' || dumpsys power | grep -q 'mScreenOn=true') || (input keyevent 26 && input keyevent 3)"¶ KEY_POWER = 26 and KEY_HOME = 3 are defined below)
- Type
Turn on a Fire TV device (note
-
androidtv.constants.
CMD_WAKE_LOCK_SIZE
= "dumpsys power | grep Locks | grep 'size='"¶ Get the wake lock size
-
androidtv.constants.
DEFAULT_ADB_TIMEOUT_S
= 9.0¶ Default timeout (in s) for
adb_shell.handle.tcp_handle.TcpHandle
andadb_shell.handle.tcp_handle_async.TcpHandleAsync
-
androidtv.constants.
DEFAULT_AUTH_TIMEOUT_S
= 10.0¶ Default authentication timeout (in s) for
adb_shell.handle.tcp_handle.TcpHandle.connect()
andadb_shell.handle.tcp_handle_async.TcpHandleAsync.connect()
-
androidtv.constants.
DEFAULT_LOCK_TIMEOUT_S
= 3.0¶ Default timeout for acquiring the lock that protects ADB commands
-
androidtv.constants.
DEFAULT_TRANSPORT_TIMEOUT_S
= 1.0¶ Default transport timeout (in s) for
adb_shell.handle.tcp_handle.TcpHandle.connect()
andadb_shell.handle.tcp_handle_async.TcpHandleAsync.connect()
-
class
androidtv.constants.
DeviceEnum
[source]¶ Bases:
enum.IntEnum
An enum for the various device types.
-
ANDROIDTV
= 1¶
-
BASETV
= 0¶
-
FIRETV
= 2¶
-
-
androidtv.constants.
HA_CUSTOMIZABLE_COMMANDS
= ('audio_state', 'current_app_media_session_state', 'hdmi_input', 'launch_app', 'running_apps', 'turn_off', 'turn_on')¶ The subset of CUSTOMIZABLE_COMMANDS that is potentially used in the
update()
method
-
androidtv.constants.
MEDIA_SESSION_STATES
= {0: None, 1: 'stopped', 2: 'paused', 3: 'playing'}¶ States for the
media_session_state
property
-
androidtv.constants.
VALID_PROPERTIES
= ('audio_state', 'media_session_state', 'wake_lock_size')¶ Properties that can be checked for custom state detection (used by
state_detection_rules_validator()
)
-
androidtv.constants.
VALID_PROPERTIES_TYPES
= {'audio_state': <class 'str'>, 'media_session_state': <class 'int'>, 'wake_lock_size': <class 'int'>}¶ The required type for each entry in
VALID_PROPERTIES
(used bystate_detection_rules_validator()
)
-
androidtv.constants.
VALID_STATES
= ('idle', 'off', 'playing', 'paused', 'standby')¶ States that are valid (used by
state_detection_rules_validator()
)
-
androidtv.constants.
VALID_STATE_PROPERTIES
= ('audio_state', 'media_session_state')¶ Properties that can be used to determine the current state (used by
state_detection_rules_validator()
)