Home | History | Annotate | Download | only in docs
      1 # [devil.android.device_utils](https://github.com/catapult-project/catapult/blob/master/devil/devil/android/device_utils.py)
      2 
      3 *This page was autogenerated by `devil/utils/markdown.py --module-link https://github.com/catapult-project/catapult/blob/master/devil/devil/android/device_utils.py`*
      4 
      5 ## DeviceUtils
      6 
      7 ### DeviceUtils.\_\_init\_\_
      8 
      9 DeviceUtils constructor.
     10 ```
     11     Args:
     12       device: Either a device serial, an existing AdbWrapper instance, or an
     13         an existing AndroidCommands instance.
     14       enable_device_files_cache: For PushChangedFiles(), cache checksums of
     15         pushed files rather than recomputing them on a subsequent call.
     16       default_timeout: An integer containing the default number of seconds to
     17         wait for an operation to complete if no explicit value is provided.
     18       default_retries: An integer containing the default number or times an
     19         operation should be retried on failure if no explicit value is provided.
     20 ```
     21 
     22 
     23 ### DeviceUtils.\_\_eq\_\_
     24 
     25 Checks whether |other| refers to the same device as |self|.
     26 ```
     27     Args:
     28       other: The object to compare to. This can be a basestring, an instance
     29         of adb_wrapper.AdbWrapper, or an instance of DeviceUtils.
     30     Returns:
     31       Whether |other| refers to the same device as |self|.
     32 ```
     33 
     34 
     35 ### DeviceUtils.\_\_lt\_\_
     36 
     37 Compares two instances of DeviceUtils.
     38 ```
     39     This merely compares their serial numbers.
     40 
     41     Args:
     42       other: The instance of DeviceUtils to compare to.
     43     Returns:
     44       Whether |self| is less than |other|.
     45 ```
     46 
     47 
     48 ### DeviceUtils.\_\_str\_\_
     49 
     50 Returns the device serial.
     51 ### DeviceUtils.NeedsSU
     52 
     53 Checks whether 'su' is needed to access protected resources.
     54 ```
     55     Args:
     56       timeout: timeout in seconds
     57       retries: number of retries
     58 
     59     Returns:
     60       True if 'su' is available on the device and is needed to to access
     61         protected resources; False otherwise if either 'su' is not available
     62         (e.g. because the device has a user build), or not needed (because adbd
     63         already has root privileges).
     64 
     65     Raises:
     66       CommandTimeoutError on timeout.
     67       DeviceUnreachableError on missing device.
     68 ```
     69 
     70 
     71 ### DeviceUtils.IsOnline
     72 
     73 Checks whether the device is online.
     74 ```
     75     Args:
     76       timeout: timeout in seconds
     77       retries: number of retries
     78 
     79     Returns:
     80       True if the device is online, False otherwise.
     81 
     82     Raises:
     83       CommandTimeoutError on timeout.
     84 ```
     85 
     86 
     87 ### DeviceUtils.HasRoot
     88 
     89 Checks whether or not adbd has root privileges.
     90 ```
     91     Args:
     92       timeout: timeout in seconds
     93       retries: number of retries
     94 
     95     Returns:
     96       True if adbd has root privileges, False otherwise.
     97 
     98     Raises:
     99       CommandTimeoutError on timeout.
    100       DeviceUnreachableError on missing device.
    101 ```
    102 
    103 
    104 ### DeviceUtils.EnableRoot
    105 
    106 Restarts adbd with root privileges.
    107 ```
    108     Args:
    109       timeout: timeout in seconds
    110       retries: number of retries
    111 
    112     Raises:
    113       CommandFailedError if root could not be enabled.
    114       CommandTimeoutError on timeout.
    115 ```
    116 
    117 
    118 ### DeviceUtils.IsUserBuild
    119 
    120 Checks whether or not the device is running a user build.
    121 ```
    122     Args:
    123       timeout: timeout in seconds
    124       retries: number of retries
    125 
    126     Returns:
    127       True if the device is running a user build, False otherwise (i.e. if
    128         it's running a userdebug build).
    129 
    130     Raises:
    131       CommandTimeoutError on timeout.
    132       DeviceUnreachableError on missing device.
    133 ```
    134 
    135 
    136 ### DeviceUtils.GetExternalStoragePath
    137 
    138 Get the device's path to its SD card.
    139 ```
    140     Args:
    141       timeout: timeout in seconds
    142       retries: number of retries
    143 
    144     Returns:
    145       The device's path to its SD card.
    146 
    147     Raises:
    148       CommandFailedError if the external storage path could not be determined.
    149       CommandTimeoutError on timeout.
    150       DeviceUnreachableError on missing device.
    151 ```
    152 
    153 
    154 ### DeviceUtils.GetApplicationPaths
    155 
    156 Get the paths of the installed apks on the device for the given package.
    157 ```
    158     Args:
    159       package: Name of the package.
    160 
    161     Returns:
    162       List of paths to the apks on the device for the given package.
    163 ```
    164 
    165 
    166 ### DeviceUtils.GetApplicationVersion
    167 
    168 Get the version name of a package installed on the device.
    169 ```
    170     Args:
    171       package: Name of the package.
    172 
    173     Returns:
    174       A string with the version name or None if the package is not found
    175       on the device.
    176 ```
    177 
    178 
    179 ### DeviceUtils.GetApplicationDataDirectory
    180 
    181 Get the data directory on the device for the given package.
    182 ```
    183     Args:
    184       package: Name of the package.
    185 
    186     Returns:
    187       The package's data directory.
    188     Raises:
    189       CommandFailedError if the package's data directory can't be found,
    190         whether because it's not installed or otherwise.
    191 ```
    192 
    193 
    194 ### DeviceUtils.WaitUntilFullyBooted
    195 
    196 Wait for the device to fully boot.
    197 ```
    198     This means waiting for the device to boot, the package manager to be
    199     available, and the SD card to be ready. It can optionally mean waiting
    200     for wifi to come up, too.
    201 
    202     Args:
    203       wifi: A boolean indicating if we should wait for wifi to come up or not.
    204       timeout: timeout in seconds
    205       retries: number of retries
    206 
    207     Raises:
    208       CommandFailedError on failure.
    209       CommandTimeoutError if one of the component waits times out.
    210       DeviceUnreachableError if the device becomes unresponsive.
    211 ```
    212 
    213 
    214 ### DeviceUtils.Reboot
    215 
    216 Reboot the device.
    217 ```
    218     Args:
    219       block: A boolean indicating if we should wait for the reboot to complete.
    220       wifi: A boolean indicating if we should wait for wifi to be enabled after
    221         the reboot. The option has no effect unless |block| is also True.
    222       timeout: timeout in seconds
    223       retries: number of retries
    224 
    225     Raises:
    226       CommandTimeoutError on timeout.
    227       DeviceUnreachableError on missing device.
    228 ```
    229 
    230 
    231 ### DeviceUtils.Install
    232 
    233 Install an APK.
    234 ```
    235     Noop if an identical APK is already installed.
    236 
    237     Args:
    238       apk: An ApkHelper instance or string containing the path to the APK.
    239       allow_downgrade: A boolean indicating if we should allow downgrades.
    240       reinstall: A boolean indicating if we should keep any existing app data.
    241       permissions: Set of permissions to set. If not set, finds permissions with
    242           apk helper. To set no permissions, pass [].
    243       timeout: timeout in seconds
    244       retries: number of retries
    245 
    246     Raises:
    247       CommandFailedError if the installation fails.
    248       CommandTimeoutError if the installation times out.
    249       DeviceUnreachableError on missing device.
    250 ```
    251 
    252 
    253 ### DeviceUtils.InstallSplitApk
    254 
    255 Install a split APK.
    256 ```
    257     Noop if all of the APK splits are already installed.
    258 
    259     Args:
    260       base_apk: An ApkHelper instance or string containing the path to the base
    261           APK.
    262       split_apks: A list of strings of paths of all of the APK splits.
    263       allow_downgrade: A boolean indicating if we should allow downgrades.
    264       reinstall: A boolean indicating if we should keep any existing app data.
    265       allow_cached_props: Whether to use cached values for device properties.
    266       permissions: Set of permissions to set. If not set, finds permissions with
    267           apk helper. To set no permissions, pass [].
    268       timeout: timeout in seconds
    269       retries: number of retries
    270 
    271     Raises:
    272       CommandFailedError if the installation fails.
    273       CommandTimeoutError if the installation times out.
    274       DeviceUnreachableError on missing device.
    275       DeviceVersionError if device SDK is less than Android L.
    276 ```
    277 
    278 
    279 ### DeviceUtils.Uninstall
    280 
    281 Remove the app |package\_name| from the device.
    282 ```
    283     This is a no-op if the app is not already installed.
    284 
    285     Args:
    286       package_name: The package to uninstall.
    287       keep_data: (optional) Whether to keep the data and cache directories.
    288       timeout: Timeout in seconds.
    289       retries: Number of retries.
    290 
    291     Raises:
    292       CommandFailedError if the uninstallation fails.
    293       CommandTimeoutError if the uninstallation times out.
    294       DeviceUnreachableError on missing device.
    295 ```
    296 
    297 
    298 ### DeviceUtils.RunShellCommand
    299 
    300 Run an ADB shell command.
    301 ```
    302     The command to run |cmd| should be a sequence of program arguments or else
    303     a single string.
    304 
    305     When |cmd| is a sequence, it is assumed to contain the name of the command
    306     to run followed by its arguments. In this case, arguments are passed to the
    307     command exactly as given, without any further processing by the shell. This
    308     allows to easily pass arguments containing spaces or special characters
    309     without having to worry about getting quoting right. Whenever possible, it
    310     is recomended to pass |cmd| as a sequence.
    311 
    312     When |cmd| is given as a string, it will be interpreted and run by the
    313     shell on the device.
    314 
    315     This behaviour is consistent with that of command runners in cmd_helper as
    316     well as Python's own subprocess.Popen.
    317 
    318     TODO(perezju) Change the default of |check_return| to True when callers
    319       have switched to the new behaviour.
    320 
    321     Args:
    322       cmd: A string with the full command to run on the device, or a sequence
    323         containing the command and its arguments.
    324       check_return: A boolean indicating whether or not the return code should
    325         be checked.
    326       cwd: The device directory in which the command should be run.
    327       env: The environment variables with which the command should be run.
    328       run_as: A string containing the package as which the command should be
    329         run.
    330       as_root: A boolean indicating whether the shell command should be run
    331         with root privileges.
    332       single_line: A boolean indicating if only a single line of output is
    333         expected.
    334       large_output: Uses a work-around for large shell command output. Without
    335         this large output will be truncated.
    336       raw_output: Whether to only return the raw output
    337           (no splitting into lines).
    338       timeout: timeout in seconds
    339       retries: number of retries
    340 
    341     Returns:
    342       If single_line is False, the output of the command as a list of lines,
    343       otherwise, a string with the unique line of output emmited by the command
    344       (with the optional newline at the end stripped).
    345 
    346     Raises:
    347       AdbCommandFailedError if check_return is True and the exit code of
    348         the command run on the device is non-zero.
    349       CommandFailedError if single_line is True but the output contains two or
    350         more lines.
    351       CommandTimeoutError on timeout.
    352       DeviceUnreachableError on missing device.
    353 ```
    354 
    355 
    356 ### DeviceUtils.KillAll
    357 
    358 Kill all processes with the given name on the device.
    359 ```
    360     Args:
    361       process_name: A string containing the name of the process to kill.
    362       exact: A boolean indicating whether to kill all processes matching
    363              the string |process_name| exactly, or all of those which contain
    364              |process_name| as a substring. Defaults to False.
    365       signum: An integer containing the signal number to send to kill. Defaults
    366               to SIGKILL (9).
    367       as_root: A boolean indicating whether the kill should be executed with
    368                root privileges.
    369       blocking: A boolean indicating whether we should wait until all processes
    370                 with the given |process_name| are dead.
    371       quiet: A boolean indicating whether to ignore the fact that no processes
    372              to kill were found.
    373       timeout: timeout in seconds
    374       retries: number of retries
    375 
    376     Returns:
    377       The number of processes attempted to kill.
    378 
    379     Raises:
    380       CommandFailedError if no process was killed and |quiet| is False.
    381       CommandTimeoutError on timeout.
    382       DeviceUnreachableError on missing device.
    383 ```
    384 
    385 
    386 ### DeviceUtils.StartActivity
    387 
    388 Start package's activity on the device.
    389 ```
    390     Args:
    391       intent_obj: An Intent object to send.
    392       blocking: A boolean indicating whether we should wait for the activity to
    393                 finish launching.
    394       trace_file_name: If present, a string that both indicates that we want to
    395                        profile the activity and contains the path to which the
    396                        trace should be saved.
    397       force_stop: A boolean indicating whether we should stop the activity
    398                   before starting it.
    399       timeout: timeout in seconds
    400       retries: number of retries
    401 
    402     Raises:
    403       CommandFailedError if the activity could not be started.
    404       CommandTimeoutError on timeout.
    405       DeviceUnreachableError on missing device.
    406 ```
    407 
    408 
    409 ### DeviceUtils.StartInstrumentation
    410 
    411 ### DeviceUtils.BroadcastIntent
    412 
    413 Send a broadcast intent.
    414 ```
    415     Args:
    416       intent: An Intent to broadcast.
    417       timeout: timeout in seconds
    418       retries: number of retries
    419 
    420     Raises:
    421       CommandTimeoutError on timeout.
    422       DeviceUnreachableError on missing device.
    423 ```
    424 
    425 
    426 ### DeviceUtils.GoHome
    427 
    428 Return to the home screen and obtain launcher focus.
    429 ```
    430     This command launches the home screen and attempts to obtain
    431     launcher focus until the timeout is reached.
    432 
    433     Args:
    434       timeout: timeout in seconds
    435       retries: number of retries
    436 
    437     Raises:
    438       CommandTimeoutError on timeout.
    439       DeviceUnreachableError on missing device.
    440 ```
    441 
    442 
    443 ### DeviceUtils.ForceStop
    444 
    445 Close the application.
    446 ```
    447     Args:
    448       package: A string containing the name of the package to stop.
    449       timeout: timeout in seconds
    450       retries: number of retries
    451 
    452     Raises:
    453       CommandTimeoutError on timeout.
    454       DeviceUnreachableError on missing device.
    455 ```
    456 
    457 
    458 ### DeviceUtils.ClearApplicationState
    459 
    460 Clear all state for the given package.
    461 ```
    462     Args:
    463       package: A string containing the name of the package to stop.
    464       permissions: List of permissions to set after clearing data.
    465       timeout: timeout in seconds
    466       retries: number of retries
    467 
    468     Raises:
    469       CommandTimeoutError on timeout.
    470       DeviceUnreachableError on missing device.
    471 ```
    472 
    473 
    474 ### DeviceUtils.SendKeyEvent
    475 
    476 Sends a keycode to the device.
    477 ```
    478     See the devil.android.sdk.keyevent module for suitable keycode values.
    479 
    480     Args:
    481       keycode: A integer keycode to send to the device.
    482       timeout: timeout in seconds
    483       retries: number of retries
    484 
    485     Raises:
    486       CommandTimeoutError on timeout.
    487       DeviceUnreachableError on missing device.
    488 ```
    489 
    490 
    491 ### DeviceUtils.PushChangedFiles
    492 
    493 Push files to the device, skipping files that don't need updating.
    494 ```
    495     When a directory is pushed, it is traversed recursively on the host and
    496     all files in it are pushed to the device as needed.
    497     Additionally, if delete_device_stale option is True,
    498     files that exist on the device but don't exist on the host are deleted.
    499 
    500     Args:
    501       host_device_tuples: A list of (host_path, device_path) tuples, where
    502         |host_path| is an absolute path of a file or directory on the host
    503         that should be minimially pushed to the device, and |device_path| is
    504         an absolute path of the destination on the device.
    505       timeout: timeout in seconds
    506       retries: number of retries
    507       delete_device_stale: option to delete stale files on device
    508 
    509     Raises:
    510       CommandFailedError on failure.
    511       CommandTimeoutError on timeout.
    512       DeviceUnreachableError on missing device.
    513 ```
    514 
    515 
    516 ### DeviceUtils.FileExists
    517 
    518 Checks whether the given file exists on the device.
    519 ```
    520     Arguments are the same as PathExists.
    521 ```
    522 
    523 
    524 ### DeviceUtils.PathExists
    525 
    526 Checks whether the given path(s) exists on the device.
    527 ```
    528     Args:
    529       device_path: A string containing the absolute path to the file on the
    530                    device, or an iterable of paths to check.
    531       as_root: Whether root permissions should be use to check for the existence
    532                of the given path(s).
    533       timeout: timeout in seconds
    534       retries: number of retries
    535 
    536     Returns:
    537       True if the all given paths exist on the device, False otherwise.
    538 
    539     Raises:
    540       CommandTimeoutError on timeout.
    541       DeviceUnreachableError on missing device.
    542 ```
    543 
    544 
    545 ### DeviceUtils.RemovePath
    546 
    547 Removes the given path(s) from the device.
    548 ```
    549     Args:
    550       device_path: A string containing the absolute path to the file on the
    551                    device, or an iterable of paths to check.
    552       force: Whether to remove the path(s) with force (-f).
    553       recursive: Whether to remove any directories in the path(s) recursively.
    554       as_root: Whether root permissions should be use to remove the given
    555                path(s).
    556       timeout: timeout in seconds
    557       retries: number of retries
    558 ```
    559 
    560 
    561 ### DeviceUtils.PullFile
    562 
    563 Pull a file from the device.
    564 ```
    565     Args:
    566       device_path: A string containing the absolute path of the file to pull
    567                    from the device.
    568       host_path: A string containing the absolute path of the destination on
    569                  the host.
    570       timeout: timeout in seconds
    571       retries: number of retries
    572 
    573     Raises:
    574       CommandFailedError on failure.
    575       CommandTimeoutError on timeout.
    576 ```
    577 
    578 
    579 ### DeviceUtils.ReadFile
    580 
    581 Reads the contents of a file from the device.
    582 ```
    583     Args:
    584       device_path: A string containing the absolute path of the file to read
    585                    from the device.
    586       as_root: A boolean indicating whether the read should be executed with
    587                root privileges.
    588       force_pull: A boolean indicating whether to force the operation to be
    589           performed by pulling a file from the device. The default is, when the
    590           contents are short, to retrieve the contents using cat instead.
    591       timeout: timeout in seconds
    592       retries: number of retries
    593 
    594     Returns:
    595       The contents of |device_path| as a string. Contents are intepreted using
    596       universal newlines, so the caller will see them encoded as '
    597 '. Also,
    598       all lines will be terminated.
    599 
    600     Raises:
    601       AdbCommandFailedError if the file can't be read.
    602       CommandTimeoutError on timeout.
    603       DeviceUnreachableError on missing device.
    604 ```
    605 
    606 
    607 ### DeviceUtils.WriteFile
    608 
    609 Writes |contents| to a file on the device.
    610 ```
    611     Args:
    612       device_path: A string containing the absolute path to the file to write
    613           on the device.
    614       contents: A string containing the data to write to the device.
    615       as_root: A boolean indicating whether the write should be executed with
    616           root privileges (if available).
    617       force_push: A boolean indicating whether to force the operation to be
    618           performed by pushing a file to the device. The default is, when the
    619           contents are short, to pass the contents using a shell script instead.
    620       timeout: timeout in seconds
    621       retries: number of retries
    622 
    623     Raises:
    624       CommandFailedError if the file could not be written on the device.
    625       CommandTimeoutError on timeout.
    626       DeviceUnreachableError on missing device.
    627 ```
    628 
    629 
    630 ### DeviceUtils.ListDirectory
    631 
    632 List all files on a device directory.
    633 ```
    634     Mirroring os.listdir (and most client expectations) the resulting list
    635     does not include the special entries '.' and '..' even if they are present
    636     in the directory.
    637 
    638     Args:
    639       device_path: A string containing the path of the directory on the device
    640                    to list.
    641       as_root: A boolean indicating whether the to use root privileges to list
    642                the directory contents.
    643       timeout: timeout in seconds
    644       retries: number of retries
    645 
    646     Returns:
    647       A list of filenames for all entries contained in the directory.
    648 
    649     Raises:
    650       AdbCommandFailedError if |device_path| does not specify a valid and
    651           accessible directory in the device.
    652       CommandTimeoutError on timeout.
    653       DeviceUnreachableError on missing device.
    654 ```
    655 
    656 
    657 ### DeviceUtils.StatDirectory
    658 
    659 List file and stat info for all entries on a device directory.
    660 ```
    661     Implementation notes: this is currently implemented by parsing the output
    662     of 'ls -a -l' on the device. Whether possible and convenient, we attempt to
    663     make parsing strict and return values mirroring those of the standard |os|
    664     and |stat| Python modules.
    665 
    666     Mirroring os.listdir (and most client expectations) the resulting list
    667     does not include the special entries '.' and '..' even if they are present
    668     in the directory.
    669 
    670     Args:
    671       device_path: A string containing the path of the directory on the device
    672                    to list.
    673       as_root: A boolean indicating whether the to use root privileges to list
    674                the directory contents.
    675       timeout: timeout in seconds
    676       retries: number of retries
    677 
    678     Returns:
    679       A list of dictionaries, each containing the following keys:
    680         filename: A string with the file name.
    681         st_mode: File permissions, use the stat module to interpret these.
    682         st_nlink: Number of hard links (may be missing).
    683         st_owner: A string with the user name of the owner.
    684         st_group: A string with the group name of the owner.
    685         st_rdev_pair: Device type as (major, minior) (only if inode device).
    686         st_size: Size of file, in bytes (may be missing for non-regular files).
    687         st_mtime: Time of most recent modification, in seconds since epoch
    688           (although resolution is in minutes).
    689         symbolic_link_to: If entry is a symbolic link, path where it points to;
    690           missing otherwise.
    691 
    692     Raises:
    693       AdbCommandFailedError if |device_path| does not specify a valid and
    694           accessible directory in the device.
    695       CommandTimeoutError on timeout.
    696       DeviceUnreachableError on missing device.
    697 ```
    698 
    699 
    700 ### DeviceUtils.StatPath
    701 
    702 Get the stat attributes of a file or directory on the device.
    703 ```
    704     Args:
    705       device_path: A string containing the path of a file or directory from
    706                    which to get attributes.
    707       as_root: A boolean indicating whether the to use root privileges to
    708                access the file information.
    709       timeout: timeout in seconds
    710       retries: number of retries
    711 
    712     Returns:
    713       A dictionary with the stat info collected; see StatDirectory for details.
    714 
    715     Raises:
    716       CommandFailedError if device_path cannot be found on the device.
    717       CommandTimeoutError on timeout.
    718       DeviceUnreachableError on missing device.
    719 ```
    720 
    721 
    722 ### DeviceUtils.FileSize
    723 
    724 Get the size of a file on the device.
    725 ```
    726     Note: This is implemented by parsing the output of the 'ls' command on
    727     the device. On some Android versions, when passing a directory or special
    728     file, the size is *not* reported and this function will throw an exception.
    729 
    730     Args:
    731       device_path: A string containing the path of a file on the device.
    732       as_root: A boolean indicating whether the to use root privileges to
    733                access the file information.
    734       timeout: timeout in seconds
    735       retries: number of retries
    736 
    737     Returns:
    738       The size of the file in bytes.
    739 
    740     Raises:
    741       CommandFailedError if device_path cannot be found on the device, or
    742         its size cannot be determited for some reason.
    743       CommandTimeoutError on timeout.
    744       DeviceUnreachableError on missing device.
    745 ```
    746 
    747 
    748 ### DeviceUtils.GetLanguage
    749 
    750 Returns the language setting on the device.
    751 ```
    752     Args:
    753       cache: Whether to use cached properties when available.
    754 ```
    755 
    756 
    757 ### DeviceUtils.SetJavaAsserts
    758 
    759 Enables or disables Java asserts.
    760 ```
    761     Args:
    762       enabled: A boolean indicating whether Java asserts should be enabled
    763                or disabled.
    764       timeout: timeout in seconds
    765       retries: number of retries
    766 
    767     Returns:
    768       True if the device-side property changed and a restart is required as a
    769       result, False otherwise.
    770 
    771     Raises:
    772       CommandTimeoutError on timeout.
    773 ```
    774 
    775 
    776 ### DeviceUtils.GetCountry
    777 
    778 Returns the country setting on the device.
    779 ```
    780     Args:
    781       cache: Whether to use cached properties when available.
    782 ```
    783 
    784 
    785 ### DeviceUtils.GetProp
    786 
    787 Gets a property from the device.
    788 ```
    789     Args:
    790       property_name: A string containing the name of the property to get from
    791                      the device.
    792       cache: Whether to use cached properties when available.
    793       timeout: timeout in seconds
    794       retries: number of retries
    795 
    796     Returns:
    797       The value of the device's |property_name| property.
    798 
    799     Raises:
    800       CommandTimeoutError on timeout.
    801 ```
    802 
    803 
    804 ### DeviceUtils.SetProp
    805 
    806 Sets a property on the device.
    807 ```
    808     Args:
    809       property_name: A string containing the name of the property to set on
    810                      the device.
    811       value: A string containing the value to set to the property on the
    812              device.
    813       check: A boolean indicating whether to check that the property was
    814              successfully set on the device.
    815       timeout: timeout in seconds
    816       retries: number of retries
    817 
    818     Raises:
    819       CommandFailedError if check is true and the property was not correctly
    820         set on the device (e.g. because it is not rooted).
    821       CommandTimeoutError on timeout.
    822 ```
    823 
    824 
    825 ### DeviceUtils.GetABI
    826 
    827 Gets the device main ABI.
    828 ```
    829     Args:
    830       timeout: timeout in seconds
    831       retries: number of retries
    832 
    833     Returns:
    834       The device's main ABI name.
    835 
    836     Raises:
    837       CommandTimeoutError on timeout.
    838 ```
    839 
    840 
    841 ### DeviceUtils.GetPids
    842 
    843 Returns the PIDs of processes with the given name.
    844 ```
    845     Note that the |process_name| is often the package name.
    846 
    847     Args:
    848       process_name: A string containing the process name to get the PIDs for.
    849       timeout: timeout in seconds
    850       retries: number of retries
    851 
    852     Returns:
    853       A dict mapping process name to a list of PIDs for each process that
    854       contained the provided |process_name|.
    855 
    856     Raises:
    857       CommandTimeoutError on timeout.
    858       DeviceUnreachableError on missing device.
    859 ```
    860 
    861 
    862 ### DeviceUtils.GetEnforce
    863 
    864 Get the current mode of SELinux.
    865 ```
    866     Args:
    867       timeout: timeout in seconds
    868       retries: number of retries
    869 
    870     Returns:
    871       True (enforcing), False (permissive), or None (disabled).
    872 
    873     Raises:
    874       CommandFailedError on failure.
    875       CommandTimeoutError on timeout.
    876       DeviceUnreachableError on missing device.
    877 ```
    878 
    879 
    880 ### DeviceUtils.SetEnforce
    881 
    882 Modify the mode SELinux is running in.
    883 ```
    884     Args:
    885       enabled: a boolean indicating whether to put SELinux in encorcing mode
    886                (if True), or permissive mode (otherwise).
    887       timeout: timeout in seconds
    888       retries: number of retries
    889 
    890     Raises:
    891       CommandFailedError on failure.
    892       CommandTimeoutError on timeout.
    893       DeviceUnreachableError on missing device.
    894 ```
    895 
    896 
    897 ### DeviceUtils.TakeScreenshot
    898 
    899 Takes a screenshot of the device.
    900 ```
    901     Args:
    902       host_path: A string containing the path on the host to save the
    903                  screenshot to. If None, a file name in the current
    904                  directory will be generated.
    905       timeout: timeout in seconds
    906       retries: number of retries
    907 
    908     Returns:
    909       The name of the file on the host to which the screenshot was saved.
    910 
    911     Raises:
    912       CommandFailedError on failure.
    913       CommandTimeoutError on timeout.
    914       DeviceUnreachableError on missing device.
    915 ```
    916 
    917 
    918 ### DeviceUtils.GetMemoryUsageForPid
    919 
    920 Gets the memory usage for the given PID.
    921 ```
    922     Args:
    923       pid: PID of the process.
    924       timeout: timeout in seconds
    925       retries: number of retries
    926 
    927     Returns:
    928       A dict containing memory usage statistics for the PID. May include:
    929         Size, Rss, Pss, Shared_Clean, Shared_Dirty, Private_Clean,
    930         Private_Dirty, VmHWM
    931 
    932     Raises:
    933       CommandTimeoutError on timeout.
    934 ```
    935 
    936 
    937 ### DeviceUtils.DismissCrashDialogIfNeeded
    938 
    939 Dismiss the error/ANR dialog if present.
    940 ```
    941     Returns: Name of the crashed package if a dialog is focused,
    942              None otherwise.
    943 ```
    944 
    945 
    946 ### DeviceUtils.GetLogcatMonitor
    947 
    948 Returns a new LogcatMonitor associated with this device.
    949 ```
    950     Parameters passed to this function are passed directly to
    951     |logcat_monitor.LogcatMonitor| and are documented there.
    952 ```
    953 
    954 
    955 ### DeviceUtils.GetClientCache
    956 
    957 Returns client cache.
    958 ### DeviceUtils.LoadCacheData
    959 
    960 Initializes the cache from data created using DumpCacheData.
    961 ```
    962     The cache is used only if its token matches the one found on the device.
    963     This prevents a stale cache from being used (which can happen when sharing
    964     devices).
    965 
    966     Args:
    967       data: A previously serialized cache (string).
    968       timeout: timeout in seconds
    969       retries: number of retries
    970 
    971     Returns:
    972       Whether the cache was loaded.
    973 ```
    974 
    975 
    976 ### DeviceUtils.DumpCacheData
    977 
    978 Dumps the current cache state to a string.
    979 ```
    980     Args:
    981       timeout: timeout in seconds
    982       retries: number of retries
    983 
    984     Returns:
    985       A serialized cache as a string.
    986 ```
    987 
    988 
    989 ### DeviceUtils.RestartAdbd
    990 
    991 ### DeviceUtils.GrantPermissions
    992 
    993 ### DeviceUtils.IsScreenOn
    994 
    995 Determines if screen is on.
    996 ```
    997     Dumpsys input_method exposes screen on/off state. Below is an explination of
    998     the states.
    999 
   1000     Pre-L:
   1001       On: mScreenOn=true
   1002       Off: mScreenOn=false
   1003     L+:
   1004       On: mInteractive=true
   1005       Off: mInteractive=false
   1006 
   1007     Returns:
   1008       True if screen is on, false if it is off.
   1009 
   1010     Raises:
   1011       device_errors.CommandFailedError: If screen state cannot be found.
   1012 ```
   1013 
   1014 
   1015 ### DeviceUtils.SetScreen
   1016 
   1017 Turns screen on and off.
   1018 ```
   1019     Args:
   1020       on: bool to decide state to switch to. True = on False = off.
   1021 ```
   1022 
   1023 
   1024 ### GetAVDs
   1025 
   1026 Returns a list of Android Virtual Devices.
   1027 ```
   1028   Returns:
   1029     A list containing the configured AVDs.
   1030 ```
   1031 
   1032 
   1033 ### RestartServer
   1034 
   1035 Restarts the adb server.
   1036 ```
   1037   Raises:
   1038     CommandFailedError if we fail to kill or restart the server.
   1039 ```
   1040 
   1041 
   1042