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