HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/beacons/__pycache__/adb.cpython-310.pyc
o

�N�gF�@sTdZddlZddlZddlZe�e�ZdZiZ	ddd�Z
dd�Zdd	�Zd
d�Z
dS)zY
Beacon to emit adb device state changes for Android devices

.. versionadded:: 2016.3.0
�N�adbF)�value�
no_devicescCs4tjj�d�}|durd}t�dt|�d|fStS)Nrzadb is missing.zUnable to load %s beacon: %sF)�salt�utils�path�which�log�error�__virtualname__)Zwhich_result�err_msg�r
�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/beacons/adb.py�__virtual__srcs�t|t�st�d�dStjj�|�}d|vrt�d�dSt|dt�s,t�d�dSgd��t�fdd�|dD��rPt�d	d
�	���dd�
d
�	���fSd
S)z+
    Validate the beacon configuration
    �,Configuration for adb beacon must be a list.)Fr�states�9Configuration for adb beacon must include a states array.)Fr)
ZofflineZ
bootloader�device�hostZrecoveryzno permissionsZsideloadZunauthorized�unknown�missingc3s�|]}|�vVqdS)Nr
)�.0�s�rr
r�	<genexpr>=s�zvalidate.<locals>.<genexpr>z*Need a one of the following adb states: %sz, Fz*Need a one of the following adb states: {})TzValid beacon configuration)�
isinstance�listr	�inforr�beacons�list_to_dict�any�join�format)�configr
rr�validates*




���r$c	Cs(t�d�g}tjj�|�}tdd|�dd�d�}|�d�dd�}t	t
���}g}|D]�}z�|�d	�\}}|�|�||vsNd
t
|vrct
|d
|krc||dvrc|�|||d��d
|it
|<d
|vr�t
�|i�}	d�
|�}
td|
|�dd�d��d�}|D]H}t|�}
d|
kr�dkr�nq�d|	vs�|
|	dkr�d|	vs�|	d|d
kr�|
|d
kr�|�||
d
d��|t
vr�it
|<t
|�d|
i�q�Wq-ty�Yq-w|D]}||vr�d|dvr�|�|ddd��t
|=q�d|v�r
|ddu�r
|�s
td�s
|�ddi�|td<|S)a�
    Emit the status of all devices returned by adb

    Specify the device states that should emit an event,
    there will be an event for each device with the
    event type and device specified.

    .. code-block:: yaml

        beacons:
          adb:
            - states:
                - offline
                - unauthorized
                - missing
            - no_devices_event: True
            - battery_low: 25

    zadb beacon startingzcmd.runzadb devices�userN)Zrunas�
��	�stater)rr)�tagZbattery_lowz6adb -s {} shell cat /sys/class/power_supply/*/capacityr�dZbattery)r�
battery_levelr*rZno_devices_eventTrr*)r	ZtracerrrrZ__salt__�get�splitr�
last_state�keys�appendr"�int�update�
ValueError�last_state_extra)r#�ret�out�linesZlast_state_devicesZ
found_devices�linerr)�val�cmdZbattery_levels�lr,r
r
r�beaconJsr

��������
r=)�__doc__�loggingZsalt.utils.beaconsrZsalt.utils.path�	getLogger�__name__r	rr/r5rr$r=r
r
r
r�<module>s


,