Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
CURRENT_APP_OUTPUT = "com.amazon.tv.launcher"
RUNNING_APPS_OUTPUT = """u0_a18 316 197 1189204 115000 ffffffff 00000000 S com.netflix.ninja
u0_a2 15121 197 998628 24628 ffffffff 00000000 S com.amazon.device.controllermanager"""
RUNNING_APPS_LIST = ['com.netflix.ninja', 'com.amazon.device.controllermanager']
GET_PROPERTIES_OUTPUT1 = ""
GET_PROPERTIES_DICT1 = {'screen_on': False,
'awake': False,
'wake_lock_size': -1,
'current_app': None,
'media_session_state': None,
'running_apps': None}
STATE1 = (constants.STATE_OFF, None, None)
GET_PROPERTIES_OUTPUT2 = "1"
GET_PROPERTIES_DICT2 = {'screen_on': True,
'awake': False,
'wake_lock_size': -1,
'current_app': None,
'media_session_state': None,
'running_apps': None}
STATE2 = (constants.STATE_STANDBY, None, None)
GET_PROPERTIES_OUTPUT3 = """11Wake Locks: size=2
com.amazon.tv.launcher
u0_a2 17243 197 998628 24932 ffffffff 00000000 S com.amazon.device.controllermanager
u0_a2 17374 197 995368 20764 ffffffff 00000000 S com.amazon.device.controllermanager:BluetoothReceiver"""
GET_PROPERTIES_DICT3 = {'screen_on': True,
RUNNING_APPS_LIST = ['com.netflix.ninja', 'com.amazon.device.controllermanager']
GET_PROPERTIES_OUTPUT1 = ""
GET_PROPERTIES_DICT1 = {'screen_on': False,
'awake': False,
'audio_state': None,
'wake_lock_size': -1,
'media_session_state': None,
'current_app': None,
'audio_output_device': None,
'is_volume_muted': None,
'volume': None,
'running_apps': None}
STATE1 = (constants.STATE_OFF, None, None, None, None, None)
GET_PROPERTIES_OUTPUT2 = "1"
GET_PROPERTIES_DICT2 = {'screen_on': True,
'awake': False,
'audio_state': None,
'wake_lock_size': -1,
'media_session_state': None,
'current_app': None,
'audio_output_device': None,
'is_volume_muted': None,
'volume': None,
'running_apps': None}
STATE2 = (constants.STATE_STANDBY, None, None, None, None, None)
GET_PROPERTIES_OUTPUT3 = """110Wake Locks: size=2
com.amazon.tv.launcher
patch_key = "server"
with patchers.patch_connect(True)[patch_key], patchers.patch_shell("")[patch_key]:
aftv = setup(
"HOST", 5555, adb_server_ip="ADB_SERVER_IP", device_class="androidtv"
)
self.aftv = AndroidTVDevice(aftv, "Fake Android TV", {}, True, None, None)
with patchers.patch_shell("")[patch_key]:
self.aftv.update()
assert self.aftv.state == STATE_OFF
with patch("androidtv.androidtv.androidtv_sync.AndroidTVSync.update", side_effect=LockNotAcquiredException):
with patchers.patch_shell("1")[patch_key]:
self.aftv.update()
assert self.aftv.state == STATE_OFF
with patchers.patch_shell("1")[patch_key]:
self.aftv.update()
assert self.aftv.state == STATE_STANDBY
with patchers.patch_shell(GET_PROPERTIES_OUTPUT1)[self.PATCH_KEY]:
state = self.atv.update()
self.assertTupleEqual(state, STATE1)
with patchers.patch_shell(GET_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
state = self.atv.update()
self.assertTupleEqual(state, STATE2)
with patchers.patch_shell(GET_PROPERTIES_OUTPUT3)[self.PATCH_KEY]:
state = self.atv.update()
self.assertTupleEqual(state, STATE3)
self.atv._state_detection_rules = STATE_DETECTION_RULES1
state = self.atv.update()
self.assertEqual(state[0], constants.STATE_OFF)
self.atv._state_detection_rules = STATE_DETECTION_RULES2
state = self.atv.update()
self.assertEqual(state[0], constants.STATE_OFF)
self.atv._state_detection_rules = STATE_DETECTION_RULES3
state = self.atv.update()
self.assertEqual(state[0], constants.STATE_IDLE)
self.atv._state_detection_rules = STATE_DETECTION_RULES4
state = self.atv.update()
self.assertEqual(state[0], constants.STATE_PAUSED)
self.atv._state_detection_rules = STATE_DETECTION_RULES5
state = self.atv.update()
self.assertEqual(state[0], constants.STATE_IDLE)
with patchers.patch_shell(GET_PROPERTIES_OUTPUT2)[self.PATCH_KEY]:
state = self.ftv.update()
self.assertTupleEqual(state, STATE2)
with patchers.patch_shell(GET_PROPERTIES_OUTPUT3)[self.PATCH_KEY]:
state = self.ftv.update()
self.assertTupleEqual(state, STATE3)
self.ftv._state_detection_rules = STATE_DETECTION_RULES1
state = self.ftv.update()
self.assertEqual(state[0], constants.STATE_OFF)
self.ftv._state_detection_rules = STATE_DETECTION_RULES2
state = self.ftv.update()
self.assertEqual(state[0], constants.STATE_OFF)
self.ftv._state_detection_rules = STATE_DETECTION_RULES3
state = self.ftv.update()
self.assertEqual(state[0], constants.STATE_STANDBY)
self.ftv._state_detection_rules = STATE_DETECTION_RULES4
state = self.ftv.update()
self.assertEqual(state[0], constants.STATE_PAUSED)
self.ftv._state_detection_rules = STATE_DETECTION_RULES5
state = self.ftv.update()
self.assertEqual(state[0], constants.STATE_IDLE)
is_volume_muted : bool
Whether or not the volume is muted
volume_level : float
The volume level (between 0 and 1)
"""
# Get the volume (between 0 and 1)
volume_level = self._volume_level(volume)
# Check if device is unavailable
if screen_on is None:
state = None
# Check if device is off
elif not screen_on or current_app == 'off':
state = constants.STATE_OFF
# Check if screen saver is on
elif not awake:
state = constants.STATE_STANDBY
else:
# Get the running apps
if not running_apps and current_app:
running_apps = [current_app]
# Determine the state using custom rules
state = self._custom_state_detection(current_app=current_app, media_session_state=media_session_state, wake_lock_size=wake_lock_size, audio_state=audio_state)
if state:
return state, current_app, running_apps, audio_output_device, is_volume_muted, volume_level
# ATV Launcher
The state of the device
current_app : str
The current running app
running_apps : list
A list of the running apps if ``get_running_apps`` is True, otherwise the list ``[current_app]``
"""
# Check if device is unavailable
if screen_on is None:
state = None
current_app = None
running_apps = None
# Check if device is off
elif not screen_on:
state = constants.STATE_OFF
current_app = None
running_apps = None
# Check if screen saver is on
elif not awake:
state = constants.STATE_STANDBY
current_app = None
running_apps = None
else:
# Get the running apps
if not running_apps and current_app:
running_apps = [current_app]
# Determine the state using custom rules
state = self._custom_state_detection(current_app=current_app, media_session_state=media_session_state, wake_lock_size=wake_lock_size)