xref: /aosp_15_r20/external/chromium-trace/catapult/devil/docs/device_utils.md (revision 1fa4b3da657c0e9ad43c0220bacf9731820715a5)
1# [devil.android.device_utils](https://chromium.googlesource.com/catapult.git/+/HEAD/devil/devil/android/device_utils.py)
2
3*This page was autogenerated. Run `devil/bin/generate_md_docs` to update*
4
5## DeviceUtils
6
7### DeviceUtils.BroadcastIntent
8
9Send a broadcast intent.
10```
11    Args:
12      intent: An Intent to broadcast.
13      timeout: timeout in seconds
14      retries: number of retries
15
16    Raises:
17      CommandTimeoutError on timeout.
18      DeviceUnreachableError on missing device.
19```
20
21
22### DeviceUtils.ChangeOwner
23
24Changes file system ownership for permissions.
25```
26    Args:
27      owner_group: New owner and group to assign. Note that this should be a
28        string in the form user[.group] where the group is option.
29      paths: Paths to change ownership of.
30
31      Note that the -R recursive option is not supported by all Android
32      versions.
33```
34
35
36### DeviceUtils.ChangeSecurityContext
37
38Changes the SELinux security context for files.
39```
40    Args:
41      security_context: The new security context as a string
42      paths: Paths to change the security context of.
43
44      Note that the -R recursive option is not supported by all Android
45      versions.
46```
47
48
49### DeviceUtils.ClearApplicationState
50
51Clear all state for the given package.
52```
53    Args:
54      package: A string containing the name of the package to stop.
55      permissions: List of permissions to set after clearing data.
56      timeout: timeout in seconds
57      retries: number of retries
58
59    Raises:
60      CommandTimeoutError on timeout.
61      DeviceUnreachableError on missing device.
62```
63
64
65### DeviceUtils.ClearCache
66
67Clears all caches.
68### DeviceUtils.DismissCrashDialogIfNeeded
69
70Dismiss the error/ANR dialog if present.
71```
72    Returns: Name of the crashed package if a dialog is focused,
73             None otherwise.
74```
75
76
77### DeviceUtils.DumpCacheData
78
79Dumps the current cache state to a string.
80```
81    Args:
82      timeout: timeout in seconds
83      retries: number of retries
84
85    Returns:
86      A serialized cache as a string.
87```
88
89
90### DeviceUtils.EnableRoot
91
92Restarts adbd with root privileges.
93```
94    Args:
95      timeout: timeout in seconds
96      retries: number of retries
97
98    Raises:
99      CommandFailedError if root could not be enabled.
100      CommandTimeoutError on timeout.
101```
102
103
104### DeviceUtils.FileExists
105
106Checks whether the given file exists on the device.
107```
108    Arguments are the same as PathExists.
109```
110
111
112### DeviceUtils.FileSize
113
114Get the size of a file on the device.
115```
116    Note: This is implemented by parsing the output of the 'ls' command on
117    the device. On some Android versions, when passing a directory or special
118    file, the size is *not* reported and this function will throw an exception.
119
120    Args:
121      device_path: A string containing the path of a file on the device.
122      as_root: A boolean indicating whether the to use root privileges to
123               access the file information.
124      timeout: timeout in seconds
125      retries: number of retries
126
127    Returns:
128      The size of the file in bytes.
129
130    Raises:
131      CommandFailedError if device_path cannot be found on the device, or
132        its size cannot be determited for some reason.
133      CommandTimeoutError on timeout.
134      DeviceUnreachableError on missing device.
135```
136
137
138### DeviceUtils.ForceStop
139
140Close the application.
141```
142    Args:
143      package: A string containing the name of the package to stop.
144      timeout: timeout in seconds
145      retries: number of retries
146
147    Raises:
148      CommandTimeoutError on timeout.
149      DeviceUnreachableError on missing device.
150```
151
152
153### DeviceUtils.GetABI
154
155Gets the device main ABI.
156```
157    Args:
158      timeout: timeout in seconds
159      retries: number of retries
160
161    Returns:
162      The device's main ABI name. For supported ABIs, the return value will be
163      one of the values defined in devil.android.ndk.abis.
164
165    Raises:
166      CommandTimeoutError on timeout.
167```
168
169
170### DeviceUtils.GetAppWritablePath
171
172Get a path that on the device's SD card that apps can write.
173```
174    Args:
175      timeout: timeout in seconds
176      retries: number of retries
177
178    Returns:
179      A app-writeable path on the device's SD card.
180
181    Raises:
182      CommandFailedError if the external storage path could not be determined.
183      CommandTimeoutError on timeout.
184      DeviceUnreachableError on missing device.
185```
186
187
188### DeviceUtils.GetApplicationDataDirectory
189
190Get the data directory on the device for the given package.
191```
192    Args:
193      package: Name of the package.
194
195    Returns:
196      The package's data directory.
197    Raises:
198      CommandFailedError if the package's data directory can't be found,
199        whether because it's not installed or otherwise.
200```
201
202
203### DeviceUtils.GetApplicationPaths
204
205Get the paths of the installed apks on the device for the given package.
206```
207    Args:
208      package: Name of the package.
209
210    Returns:
211      List of paths to the apks on the device for the given package.
212```
213
214
215### DeviceUtils.GetApplicationPids
216
217Returns the PID or PIDs of a given process name.
218```
219    Note that the |process_name|, often the package name, must match exactly.
220
221    Args:
222      process_name: A string containing the process name to get the PIDs for.
223      at_most_one: A boolean indicating that at most one PID is expected to
224                   be found.
225      timeout: timeout in seconds
226      retries: number of retries
227
228    Returns:
229      A list of the PIDs for the named process. If at_most_one=True returns
230      the single PID found or None otherwise.
231
232    Raises:
233      CommandFailedError if at_most_one=True and more than one PID is found
234          for the named process.
235      CommandTimeoutError on timeout.
236      DeviceUnreachableError on missing device.
237```
238
239
240### DeviceUtils.GetApplicationTargetSdk
241
242Get the targetSdkVersion of a package installed on the device.
243```
244    Args:
245      package: Name of the package.
246
247    Returns:
248      A string with the targetSdkVersion or None if the package is not found on
249      the device. Note: this cannot always be cast to an integer. If this
250      application targets a pre-release SDK, this returns the version codename
251      instead (ex. "R").
252```
253
254
255### DeviceUtils.GetApplicationVersion
256
257Get the version name of a package installed on the device.
258```
259    Args:
260      package: Name of the package.
261
262    Returns:
263      A string with the version name or None if the package is not found
264      on the device.
265```
266
267
268### DeviceUtils.GetClientCache
269
270Returns client cache.
271### DeviceUtils.GetCountry
272
273Returns the country setting on the device.
274```
275    DEPRECATED: Prefer GetLocale() instead.
276
277    Args:
278      cache: Whether to use cached properties when available.
279```
280
281
282### DeviceUtils.GetEnforce
283
284Get the current mode of SELinux.
285```
286    Args:
287      timeout: timeout in seconds
288      retries: number of retries
289
290    Returns:
291      True (enforcing), False (permissive), or None (disabled).
292
293    Raises:
294      CommandFailedError on failure.
295      CommandTimeoutError on timeout.
296      DeviceUnreachableError on missing device.
297```
298
299
300### DeviceUtils.GetExternalStoragePath
301
302Get the device's path to its SD card.
303```
304    Note: this path is read-only by apps in R+. Use GetAppWritablePath() to
305    obtain a path writable by apps.
306
307    Args:
308      timeout: timeout in seconds
309      retries: number of retries
310
311    Returns:
312      The device's path to its SD card.
313
314    Raises:
315      CommandFailedError if the external storage path could not be determined.
316      CommandTimeoutError on timeout.
317      DeviceUnreachableError on missing device.
318```
319
320
321### DeviceUtils.GetFeatures
322
323Returns the features supported on the device.
324### DeviceUtils.GetIMEI
325
326Get the device's IMEI.
327```
328    Args:
329      timeout: timeout in seconds
330      retries: number of retries
331
332    Returns:
333      The device's IMEI.
334
335    Raises:
336      AdbCommandFailedError on error
337```
338
339
340### DeviceUtils.GetLanguage
341
342Returns the language setting on the device.
343```
344    DEPRECATED: Prefer GetLocale() instead.
345
346    Args:
347      cache: Whether to use cached properties when available.
348```
349
350
351### DeviceUtils.GetLocale
352
353Returns the locale setting on the device.
354```
355    Args:
356      cache: Whether to use cached properties when available.
357    Returns:
358      A pair (language, country).
359```
360
361
362### DeviceUtils.GetLogcatMonitor
363
364Returns a new LogcatMonitor associated with this device.
365```
366    Parameters passed to this function are passed directly to
367    |logcat_monitor.LogcatMonitor| and are documented there.
368```
369
370
371### DeviceUtils.GetPackageArchitecture
372
373Get the architecture of a package installed on the device.
374```
375    Args:
376      package: Name of the package.
377
378    Returns:
379      A string with the architecture, or None if the package is missing.
380```
381
382
383### DeviceUtils.GetPids
384
385Returns the PIDs of processes containing the given name as substring.
386```
387    DEPRECATED
388
389    Note that the |process_name| is often the package name.
390
391    Args:
392      process_name: A string containing the process name to get the PIDs for.
393                    If missing returns PIDs for all processes.
394      timeout: timeout in seconds
395      retries: number of retries
396
397    Returns:
398      A dict mapping process name to a list of PIDs for each process that
399      contained the provided |process_name|.
400
401    Raises:
402      CommandTimeoutError on timeout.
403      DeviceUnreachableError on missing device.
404```
405
406
407### DeviceUtils.GetProp
408
409Gets a property from the device.
410```
411    Args:
412      property_name: A string containing the name of the property to get from
413                     the device.
414      cache: Whether to use cached properties when available.
415      timeout: timeout in seconds
416      retries: number of retries
417
418    Returns:
419      The value of the device's |property_name| property.
420
421    Raises:
422      CommandTimeoutError on timeout.
423```
424
425
426### DeviceUtils.GetSecurityContextForPackage
427
428Gets the SELinux security context for the given package.
429```
430    Args:
431      package: Name of the package.
432      encrypted: Whether to check in the encrypted data directory
433          (/data/user_de/0/) or the unencrypted data directory (/data/data/).
434
435    Returns:
436      The package's security context as a string, or None if not found.
437```
438
439
440### DeviceUtils.GetTracingPath
441
442Gets tracing path from the device.
443```
444    Args:
445      timeout: timeout in seconds
446      retries: number of retries
447
448    Returns:
449      /sys/kernel/debug/tracing for device with debugfs mount support;
450      /sys/kernel/tracing for device with tracefs support;
451      /sys/kernel/debug/tracing if support can't be determined.
452
453    Raises:
454      CommandTimeoutError on timeout.
455```
456
457
458### DeviceUtils.GetWebViewUpdateServiceDump
459
460Get the WebView update command sysdump on the device.
461```
462    Returns:
463      A dictionary with these possible entries:
464        FallbackLogicEnabled: True|False
465        CurrentWebViewPackage: "package name" or None
466        MinimumWebViewVersionCode: int
467        WebViewPackages: Dict of installed WebView providers, mapping "package
468            name" to "reason it's valid/invalid."
469
470    The returned dictionary may not include all of the above keys: this depends
471    on the support of the platform's underlying WebViewUpdateService. This may
472    return an empty dictionary on OS versions which do not support querying the
473    WebViewUpdateService.
474
475    Raises:
476      CommandTimeoutError on timeout.
477      DeviceUnreachableError on missing device.
478```
479
480
481### DeviceUtils.GoHome
482
483Return to the home screen and obtain launcher focus.
484```
485    This command launches the home screen and attempts to obtain
486    launcher focus until the timeout is reached.
487
488    Args:
489      timeout: timeout in seconds
490      retries: number of retries
491
492    Raises:
493      CommandTimeoutError on timeout.
494      DeviceUnreachableError on missing device.
495```
496
497
498### DeviceUtils.GrantPermissions
499
500### DeviceUtils.HasRoot
501
502Checks whether or not adbd has root privileges.
503```
504    A device is considered to have root if all commands are implicitly run
505    with elevated privileges, i.e. without having to use "su" to run them.
506
507    Note that some devices do not allow this implicit privilige elevation,
508    but _can_ run commands as root just fine when done explicitly with "su".
509    To check if your device can run commands with elevated privileges at all
510    use:
511
512      device.HasRoot() or device.NeedsSU()
513
514    Luckily, for the most part you don't need to worry about this and using
515    RunShellCommand(cmd, as_root=True) will figure out for you the right
516    command incantation to run with elevated privileges.
517
518    Args:
519      timeout: timeout in seconds
520      retries: number of retries
521
522    Returns:
523      True if adbd has root privileges, False otherwise.
524
525    Raises:
526      CommandTimeoutError on timeout.
527      DeviceUnreachableError on missing device.
528```
529
530
531### DeviceUtils.Install
532
533Install an APK or app bundle.
534```
535    Noop if an identical APK is already installed. If installing a bundle, the
536    bundletools helper script (bin/*_bundle) should be used rather than the .aab
537    file.
538
539    Args:
540      apk: An ApkHelper instance or string containing the path to the APK or
541        bundle.
542      allow_downgrade: A boolean indicating if we should allow downgrades.
543      reinstall: A boolean indicating if we should keep any existing app data.
544        Ignored if |apk| is a bundle.
545      permissions: Set of permissions to set. If not set, finds permissions with
546          apk helper. To set no permissions, pass [].
547      timeout: timeout in seconds
548      retries: number of retries
549      modules: An iterable containing specific bundle modules to install.
550          Error if set and |apk| points to an APK instead of a bundle.
551      fake_modules: An iterable containing specific bundle modules that should
552          have their apks copied to |MODULES_SRC_DIRECTORY_PATH| subdirectory
553          rather than installed. Thus the app can emulate SplitCompat while
554          running. This should not have any overlap with |modules|.
555      additional_locales: An iterable with additional locales to install for a
556        bundle.
557
558    Raises:
559      CommandFailedError if the installation fails.
560      CommandTimeoutError if the installation times out.
561      DeviceUnreachableError on missing device.
562```
563
564
565### DeviceUtils.InstallSplitApk
566
567Install a split APK.
568```
569    Noop if all of the APK splits are already installed.
570
571    Args:
572      base_apk: An ApkHelper instance or string containing the path to the base
573          APK.
574      split_apks: A list of strings of paths of all of the APK splits.
575      allow_downgrade: A boolean indicating if we should allow downgrades.
576      reinstall: A boolean indicating if we should keep any existing app data.
577      allow_cached_props: Whether to use cached values for device properties.
578      permissions: Set of permissions to set. If not set, finds permissions with
579          apk helper. To set no permissions, pass [].
580      timeout: timeout in seconds
581      retries: number of retries
582
583    Raises:
584      CommandFailedError if the installation fails.
585      CommandTimeoutError if the installation times out.
586      DeviceUnreachableError on missing device.
587      DeviceVersionError if device SDK is less than Android L.
588```
589
590
591### DeviceUtils.IsApplicationInstalled
592
593Determines whether a particular package is installed on the device.
594```
595    Args:
596      package: Name of the package.
597      version_code: The version of the package to check for as an int, if
598          applicable. Only used for static shared libraries, otherwise ignored.
599
600    Returns:
601      True if the application is installed, False otherwise.
602```
603
604
605### DeviceUtils.IsOnline
606
607Checks whether the device is online.
608```
609    Args:
610      timeout: timeout in seconds
611      retries: number of retries
612
613    Returns:
614      True if the device is online, False otherwise.
615
616    Raises:
617      CommandTimeoutError on timeout.
618```
619
620
621### DeviceUtils.IsScreenOn
622
623Determines if screen is on.
624```
625    Dumpsys input_method exposes screen on/off state. Below is an explination of
626    the states.
627
628    Pre-L:
629      On: mScreenOn=true
630      Off: mScreenOn=false
631    L+:
632      On: mInteractive=true
633      Off: mInteractive=false
634
635    Returns:
636      True if screen is on, false if it is off.
637
638    Raises:
639      device_errors.CommandFailedError: If screen state cannot be found.
640```
641
642
643### DeviceUtils.IsUserBuild
644
645Checks whether or not the device is running a user build.
646```
647    Args:
648      timeout: timeout in seconds
649      retries: number of retries
650
651    Returns:
652      True if the device is running a user build, False otherwise (i.e. if
653        it's running a userdebug build).
654
655    Raises:
656      CommandTimeoutError on timeout.
657      DeviceUnreachableError on missing device.
658```
659
660
661### DeviceUtils.KillAll
662
663Kill all processes with the given name on the device.
664```
665    Args:
666      process_name: A string containing the name of the process to kill.
667      exact: A boolean indicating whether to kill all processes matching
668             the string |process_name| exactly, or all of those which contain
669             |process_name| as a substring. Defaults to False.
670      signum: An integer containing the signal number to send to kill. Defaults
671              to SIGKILL (9).
672      as_root: A boolean indicating whether the kill should be executed with
673               root privileges.
674      blocking: A boolean indicating whether we should wait until all processes
675                with the given |process_name| are dead.
676      quiet: A boolean indicating whether to ignore the fact that no processes
677             to kill were found.
678      timeout: timeout in seconds
679      retries: number of retries
680
681    Returns:
682      The number of processes attempted to kill.
683
684    Raises:
685      CommandFailedError if no process was killed and |quiet| is False.
686      CommandTimeoutError on timeout.
687      DeviceUnreachableError on missing device.
688```
689
690
691### DeviceUtils.ListDirectory
692
693List all files on a device directory.
694```
695    Mirroring os.listdir (and most client expectations) the resulting list
696    does not include the special entries '.' and '..' even if they are present
697    in the directory.
698
699    Args:
700      device_path: A string containing the path of the directory on the device
701                   to list.
702      as_root: A boolean indicating whether the to use root privileges to list
703               the directory contents.
704      timeout: timeout in seconds
705      retries: number of retries
706
707    Returns:
708      A list of filenames for all entries contained in the directory.
709
710    Raises:
711      AdbCommandFailedError if |device_path| does not specify a valid and
712          accessible directory in the device.
713      CommandTimeoutError on timeout.
714      DeviceUnreachableError on missing device.
715```
716
717
718### DeviceUtils.ListProcesses
719
720Returns a list of tuples with info about processes on the device.
721```
722    This essentially parses the output of the |ps| command into convenient
723    ProcessInfo tuples.
724
725    Args:
726      process_name: A string used to filter the returned processes. If given,
727                    only processes whose name have this value as a substring
728                    will be returned.
729      timeout: timeout in seconds
730      retries: number of retries
731
732    Returns:
733      A list of ProcessInfo tuples with |name|, |pid|, and |ppid| fields.
734```
735
736
737### DeviceUtils.LoadCacheData
738
739Initializes the cache from data created using DumpCacheData.
740```
741    The cache is used only if its token matches the one found on the device.
742    This prevents a stale cache from being used (which can happen when sharing
743    devices).
744
745    Args:
746      data: A previously serialized cache (string).
747      timeout: timeout in seconds
748      retries: number of retries
749
750    Returns:
751      Whether the cache was loaded.
752```
753
754
755### DeviceUtils.NeedsSU
756
757Checks whether 'su' is needed to access protected resources.
758```
759    Args:
760      timeout: timeout in seconds
761      retries: number of retries
762
763    Returns:
764      True if 'su' is available on the device and is needed to to access
765        protected resources; False otherwise if either 'su' is not available
766        (e.g. because the device has a user build), or not needed (because adbd
767        already has root privileges).
768
769    Raises:
770      CommandTimeoutError on timeout.
771      DeviceUnreachableError on missing device.
772```
773
774
775### DeviceUtils.PathExists
776
777Checks whether the given path(s) exists on the device.
778```
779    Args:
780      device_path: A string containing the absolute path to the file on the
781                   device, or an iterable of paths to check.
782      as_root: Whether root permissions should be use to check for the existence
783               of the given path(s).
784      timeout: timeout in seconds
785      retries: number of retries
786
787    Returns:
788      True if the all given paths exist on the device, False otherwise.
789
790    Raises:
791      CommandTimeoutError on timeout.
792      DeviceUnreachableError on missing device.
793```
794
795
796### DeviceUtils.PullFile
797
798Pull a file from the device.
799```
800    Args:
801      device_path: A string containing the absolute path of the file to pull
802                   from the device.
803      host_path: A string containing the absolute path of the destination on
804                 the host.
805      as_root: Whether root permissions should be used to pull the file.
806      timeout: timeout in seconds
807      retries: number of retries
808
809    Raises:
810      CommandFailedError on failure.
811      CommandTimeoutError on timeout.
812```
813
814
815### DeviceUtils.PushChangedFiles
816
817Push files to the device, skipping files that don't need updating.
818```
819    When a directory is pushed, it is traversed recursively on the host and
820    all files in it are pushed to the device as needed.
821    Additionally, if delete_device_stale option is True,
822    files that exist on the device but don't exist on the host are deleted.
823
824    Args:
825      host_device_tuples: A list of (host_path, device_path) tuples, where
826        |host_path| is an absolute path of a file or directory on the host
827        that should be minimially pushed to the device, and |device_path| is
828        an absolute path of the destination on the device.
829      delete_device_stale: option to delete stale files on device
830      timeout: timeout in seconds
831      retries: number of retries
832
833    Raises:
834      CommandFailedError on failure.
835      CommandTimeoutError on timeout.
836      DeviceUnreachableError on missing device.
837```
838
839
840### DeviceUtils.ReadFile
841
842Reads the contents of a file from the device.
843```
844    Args:
845      device_path: A string containing the absolute path of the file to read
846                   from the device.
847      as_root: A boolean indicating whether the read should be executed with
848               root privileges.
849      force_pull: A boolean indicating whether to force the operation to be
850          performed by pulling a file from the device. The default is, when the
851          contents are short, to retrieve the contents using cat instead.
852      timeout: timeout in seconds
853      retries: number of retries
854
855    Returns:
856      The contents of |device_path| as a string. Contents are intepreted using
857      universal newlines, so the caller will see them encoded as '
858'. Also,
859      all lines will be terminated.
860
861    Raises:
862      AdbCommandFailedError if the file can't be read.
863      CommandTimeoutError on timeout.
864      DeviceUnreachableError on missing device.
865```
866
867
868### DeviceUtils.Reboot
869
870Reboot the device.
871```
872    Note if the device has the root privilege, it will likely lose it after the
873    reboot. When |block| is True, it will try to restore the root status if
874    applicable.
875
876    Args:
877      block: A boolean indicating if we should wait for the reboot to complete.
878      wifi: A boolean indicating if we should wait for wifi to be enabled after
879        the reboot.
880        The option has no effect unless |block| is also True.
881      decrypt: A boolean indicating if we should wait for full-disk decryption
882        to complete after the reboot.
883        The option has no effect unless |block| is also True.
884      timeout: timeout in seconds
885      retries: number of retries
886
887    Raises:
888      CommandTimeoutError on timeout.
889      DeviceUnreachableError on missing device.
890```
891
892
893### DeviceUtils.RemovePath
894
895Removes the given path(s) from the device.
896```
897    Args:
898      device_path: A string containing the absolute path to the file on the
899                   device, or an iterable of paths to check.
900      force: Whether to remove the path(s) with force (-f).
901      recursive: Whether to remove any directories in the path(s) recursively.
902      as_root: Whether root permissions should be use to remove the given
903               path(s).
904      rename: Whether to rename the path(s) before removing to help avoid
905            filesystem errors. See https://stackoverflow.com/questions/11539657
906      timeout: timeout in seconds
907      retries: number of retries
908```
909
910
911### DeviceUtils.RestartAdbd
912
913### DeviceUtils.RunShellCommand
914
915Run an ADB shell command.
916```
917    The command to run |cmd| should be a sequence of program arguments
918    (preferred) or a single string with a shell script to run.
919
920    When |cmd| is a sequence, it is assumed to contain the name of the command
921    to run followed by its arguments. In this case, arguments are passed to the
922    command exactly as given, preventing any further processing by the shell.
923    This allows callers to easily pass arguments with spaces or special
924    characters without having to worry about quoting rules. Whenever possible,
925    it is recomended to pass |cmd| as a sequence.
926
927    When |cmd| is passed as a single string, |shell| should be set to True.
928    The command will be interpreted and run by the shell on the device,
929    allowing the use of shell features such as pipes, wildcards, or variables.
930    Failing to set shell=True will issue a warning, but this will be changed
931    to a hard failure in the future (see: catapult:#3242).
932
933    This behaviour is consistent with that of command runners in cmd_helper as
934    well as Python's own subprocess.Popen.
935
936    TODO(crbug.com/1029769) Change the default of |check_return| to True when
937    callers have switched to the new behaviour.
938
939    Args:
940      cmd: A sequence containing the command to run and its arguments, or a
941        string with a shell script to run (should also set shell=True).
942      shell: A boolean indicating whether shell features may be used in |cmd|.
943      check_return: A boolean indicating whether or not the return code should
944        be checked.
945      cwd: The device directory in which the command should be run.
946      env: The environment variables with which the command should be run.
947      run_as: A string containing the package as which the command should be
948        run.
949      as_root: A boolean indicating whether the shell command should be run
950        with root privileges.
951      single_line: A boolean indicating if only a single line of output is
952        expected.
953      large_output: Uses a work-around for large shell command output. Without
954        this large output will be truncated.
955      raw_output: Whether to only return the raw output
956          (no splitting into lines).
957      timeout: timeout in seconds
958      retries: number of retries
959
960    Returns:
961      If single_line is False, the output of the command as a list of lines,
962      otherwise, a string with the unique line of output emmited by the command
963      (with the optional newline at the end stripped).
964
965    Raises:
966      AdbCommandFailedError if check_return is True and the exit code of
967        the command run on the device is non-zero.
968      CommandFailedError if single_line is True but the output contains two or
969        more lines.
970      CommandTimeoutError on timeout.
971      DeviceUnreachableError on missing device.
972```
973
974
975### DeviceUtils.SendKeyEvent
976
977Sends a keycode to the device.
978```
979    See the devil.android.sdk.keyevent module for suitable keycode values.
980
981    Args:
982      keycode: A integer keycode to send to the device.
983      timeout: timeout in seconds
984      retries: number of retries
985
986    Raises:
987      CommandTimeoutError on timeout.
988      DeviceUnreachableError on missing device.
989```
990
991
992### DeviceUtils.SetEnforce
993
994Modify the mode SELinux is running in.
995```
996    Args:
997      enabled: a boolean indicating whether to put SELinux in encorcing mode
998               (if True), or permissive mode (otherwise).
999      timeout: timeout in seconds
1000      retries: number of retries
1001
1002    Raises:
1003      CommandFailedError on failure.
1004      CommandTimeoutError on timeout.
1005      DeviceUnreachableError on missing device.
1006```
1007
1008
1009### DeviceUtils.SetJavaAsserts
1010
1011Enables or disables Java asserts.
1012```
1013    Args:
1014      enabled: A boolean indicating whether Java asserts should be enabled
1015               or disabled.
1016      timeout: timeout in seconds
1017      retries: number of retries
1018
1019    Returns:
1020      True if the device-side property changed and a restart is required as a
1021      result, False otherwise.
1022
1023    Raises:
1024      CommandTimeoutError on timeout.
1025```
1026
1027
1028### DeviceUtils.SetProp
1029
1030Sets a property on the device.
1031```
1032    Args:
1033      property_name: A string containing the name of the property to set on
1034                     the device.
1035      value: A string containing the value to set to the property on the
1036             device.
1037      check: A boolean indicating whether to check that the property was
1038             successfully set on the device.
1039      timeout: timeout in seconds
1040      retries: number of retries
1041
1042    Raises:
1043      CommandFailedError if check is true and the property was not correctly
1044        set on the device (e.g. because it is not rooted).
1045      CommandTimeoutError on timeout.
1046```
1047
1048
1049### DeviceUtils.SetScreen
1050
1051Turns screen on and off.
1052```
1053    Args:
1054      on: bool to decide state to switch to. True = on False = off.
1055```
1056
1057
1058### DeviceUtils.SetWebViewFallbackLogic
1059
1060Set whether WebViewUpdateService's "fallback logic" should be enabled.
1061```
1062    WebViewUpdateService has nonintuitive "fallback logic" for devices where
1063    Monochrome (Chrome Stable) is preinstalled as the WebView provider, with a
1064    "stub" (little-to-no code) implementation of standalone WebView.
1065
1066    "Fallback logic" (enabled by default) is designed, in the case where the
1067    user has disabled Chrome, to fall back to the stub standalone WebView by
1068    enabling the package. The implementation plumbs through the Chrome APK until
1069    Play Store installs an update with the full implementation.
1070
1071    A surprising side-effect of "fallback logic" is that, immediately after
1072    sideloading WebView, WebViewUpdateService re-disables the package and
1073    uninstalls the update. This can prevent successfully using standalone
1074    WebView for development, although "fallback logic" can be disabled on
1075    userdebug/eng devices.
1076
1077    Because this is only relevant for devices with the standalone WebView stub,
1078    this command is only relevant on N-P (inclusive).
1079
1080    You can determine if "fallback logic" is currently enabled by checking
1081    FallbackLogicEnabled in the dictionary returned by
1082    GetWebViewUpdateServiceDump.
1083
1084    Args:
1085      enabled: bool - True for enabled, False for disabled
1086      timeout: timeout in seconds
1087      retries: number of retries
1088
1089    Raises:
1090      CommandFailedError on failure.
1091      CommandTimeoutError on timeout.
1092      DeviceUnreachableError on missing device.
1093```
1094
1095
1096### DeviceUtils.SetWebViewImplementation
1097
1098Select the WebView implementation to the specified package.
1099```
1100    Args:
1101      package_name: The package name of a WebView implementation. The package
1102        must be already installed on the device.
1103      timeout: timeout in seconds
1104      retries: number of retries
1105
1106    Raises:
1107      CommandFailedError on failure.
1108      CommandTimeoutError on timeout.
1109      DeviceUnreachableError on missing device.
1110```
1111
1112
1113### DeviceUtils.StartActivity
1114
1115Start package's activity on the device.
1116```
1117    Args:
1118      intent_obj: An Intent object to send.
1119      blocking: A boolean indicating whether we should wait for the activity to
1120                finish launching.
1121      trace_file_name: If present, a string that both indicates that we want to
1122                       profile the activity and contains the path to which the
1123                       trace should be saved.
1124      force_stop: A boolean indicating whether we should stop the activity
1125                  before starting it.
1126      timeout: timeout in seconds
1127      retries: number of retries
1128
1129    Raises:
1130      CommandFailedError if the activity could not be started.
1131      CommandTimeoutError on timeout.
1132      DeviceUnreachableError on missing device.
1133```
1134
1135
1136### DeviceUtils.StartInstrumentation
1137
1138### DeviceUtils.StartService
1139
1140Start a service on the device.
1141```
1142    Args:
1143      intent_obj: An Intent object to send describing the service to start.
1144      user_id: A specific user to start the service as, defaults to current.
1145      timeout: Timeout in seconds.
1146      retries: Number of retries
1147
1148    Raises:
1149      CommandFailedError if the service could not be started.
1150      CommandTimeoutError on timeout.
1151      DeviceUnreachableError on missing device.
1152```
1153
1154
1155### DeviceUtils.StatDirectory
1156
1157List file and stat info for all entries on a device directory.
1158```
1159    Implementation notes: this is currently implemented by parsing the output
1160    of 'ls -a -l' on the device. Whether possible and convenient, we attempt to
1161    make parsing strict and return values mirroring those of the standard |os|
1162    and |stat| Python modules.
1163
1164    Mirroring os.listdir (and most client expectations) the resulting list
1165    does not include the special entries '.' and '..' even if they are present
1166    in the directory.
1167
1168    Args:
1169      device_path: A string containing the path of the directory on the device
1170                   to list.
1171      as_root: A boolean indicating whether the to use root privileges to list
1172               the directory contents.
1173      timeout: timeout in seconds
1174      retries: number of retries
1175
1176    Returns:
1177      A list of dictionaries, each containing the following keys:
1178        filename: A string with the file name.
1179        st_mode: File permissions, use the stat module to interpret these.
1180        st_nlink: Number of hard links (may be missing).
1181        st_owner: A string with the user name of the owner.
1182        st_group: A string with the group name of the owner.
1183        st_rdev_pair: Device type as (major, minior) (only if inode device).
1184        st_size: Size of file, in bytes (may be missing for non-regular files).
1185        st_mtime: Time of most recent modification, in seconds since epoch
1186          (although resolution is in minutes).
1187        symbolic_link_to: If entry is a symbolic link, path where it points to;
1188          missing otherwise.
1189
1190    Raises:
1191      AdbCommandFailedError if |device_path| does not specify a valid and
1192          accessible directory in the device.
1193      CommandTimeoutError on timeout.
1194      DeviceUnreachableError on missing device.
1195```
1196
1197
1198### DeviceUtils.StatPath
1199
1200Get the stat attributes of a file or directory on the device.
1201```
1202    Args:
1203      device_path: A string containing the path of a file or directory from
1204                   which to get attributes.
1205      as_root: A boolean indicating whether the to use root privileges to
1206               access the file information.
1207      timeout: timeout in seconds
1208      retries: number of retries
1209
1210    Returns:
1211      A dictionary with the stat info collected; see StatDirectory for details.
1212
1213    Raises:
1214      CommandFailedError if device_path cannot be found on the device.
1215      CommandTimeoutError on timeout.
1216      DeviceUnreachableError on missing device.
1217```
1218
1219
1220### DeviceUtils.TakeBugReport
1221
1222Takes a bug report and dumps it to the specified path.
1223```
1224    This doesn't use adb's bugreport option since its behavior is dependent on
1225    both adb version and device OS version. To make it simpler, this directly
1226    runs the bugreport command on the device itself and dumps the stdout to a
1227    file.
1228
1229    Args:
1230      path: Path on the host to drop the bug report.
1231      timeout: (optional) Timeout per try in seconds.
1232      retries: (optional) Number of retries to attempt.
1233```
1234
1235
1236### DeviceUtils.TakeScreenshot
1237
1238Takes a screenshot of the device.
1239```
1240    Args:
1241      host_path: A string containing the path on the host to save the
1242                 screenshot to. If None, a file name in the current
1243                 directory will be generated.
1244      timeout: timeout in seconds
1245      retries: number of retries
1246
1247    Returns:
1248      The name of the file on the host to which the screenshot was saved.
1249
1250    Raises:
1251      CommandFailedError on failure.
1252      CommandTimeoutError on timeout.
1253      DeviceUnreachableError on missing device.
1254```
1255
1256
1257### DeviceUtils.Uninstall
1258
1259Remove the app |package\_name| from the device.
1260```
1261    This is a no-op if the app is not already installed.
1262
1263    Args:
1264      package_name: The package to uninstall.
1265      keep_data: (optional) Whether to keep the data and cache directories.
1266      timeout: Timeout in seconds.
1267      retries: Number of retries.
1268
1269    Raises:
1270      CommandFailedError if the uninstallation fails.
1271      CommandTimeoutError if the uninstallation times out.
1272      DeviceUnreachableError on missing device.
1273```
1274
1275
1276### DeviceUtils.WaitUntilFullyBooted
1277
1278Wait for the device to fully boot.
1279```
1280    This means waiting for the device to boot, the package manager to be
1281    available, and the SD card to be ready.
1282    It can optionally wait the following:
1283     - Wait for wifi to come up.
1284     - Wait for full-disk decryption to complete.
1285
1286    Args:
1287      wifi: A boolean indicating if we should wait for wifi to come up or not.
1288      decrypt: A boolean indicating if we should wait for full-disk decryption
1289        to complete.
1290      timeout: timeout in seconds
1291      retries: number of retries
1292
1293    Raises:
1294      CommandFailedError on failure.
1295      CommandTimeoutError if one of the component waits times out.
1296      DeviceUnreachableError if the device becomes unresponsive.
1297```
1298
1299
1300### DeviceUtils.WriteFile
1301
1302Writes |contents| to a file on the device.
1303```
1304    Args:
1305      device_path: A string containing the absolute path to the file to write
1306          on the device.
1307      contents: A string containing the data to write to the device.
1308      as_root: A boolean indicating whether the write should be executed with
1309          root privileges (if available).
1310      force_push: A boolean indicating whether to force the operation to be
1311          performed by pushing a file to the device. The default is, when the
1312          contents are short, to pass the contents using a shell script instead.
1313      timeout: timeout in seconds
1314      retries: number of retries
1315
1316    Raises:
1317      CommandFailedError if the file could not be written on the device.
1318      CommandTimeoutError on timeout.
1319      DeviceUnreachableError on missing device.
1320```
1321
1322
1323### DeviceUtils.\_\_eq\_\_
1324
1325Checks whether |other| refers to the same device as |self|.
1326```
1327    Args:
1328      other: The object to compare to. This can be a basestring, an instance
1329        of adb_wrapper.AdbWrapper, or an instance of DeviceUtils.
1330    Returns:
1331      Whether |other| refers to the same device as |self|.
1332```
1333
1334
1335### DeviceUtils.\_\_init\_\_
1336
1337DeviceUtils constructor.
1338```
1339    Args:
1340      device: Either a device serial, an existing AdbWrapper instance, or an
1341        an existing AndroidCommands instance.
1342      enable_device_files_cache: For PushChangedFiles(), cache checksums of
1343        pushed files rather than recomputing them on a subsequent call.
1344      default_timeout: An integer containing the default number of seconds to
1345        wait for an operation to complete if no explicit value is provided.
1346      default_retries: An integer containing the default number or times an
1347        operation should be retried on failure if no explicit value is provided.
1348```
1349
1350
1351### DeviceUtils.\_\_lt\_\_
1352
1353Compares two instances of DeviceUtils.
1354```
1355    This merely compares their serial numbers.
1356
1357    Args:
1358      other: The instance of DeviceUtils to compare to.
1359    Returns:
1360      Whether |self| is less than |other|.
1361```
1362
1363
1364### DeviceUtils.\_\_str\_\_
1365
1366Returns the device serial.
1367## ProcessInfo
1368
1369ProcessInfo(name, pid, ppid)
1370### ProcessInfo.\_\_getnewargs\_\_
1371
1372Return self as a plain tuple.  Used by copy and pickle.
1373### ProcessInfo.\_\_getstate\_\_
1374
1375Exclude the OrderedDict from pickling
1376### ProcessInfo.\_\_repr\_\_
1377
1378Return a nicely formatted representation string
1379### GetAVDs
1380
1381Returns a list of Android Virtual Devices.
1382```
1383  Returns:
1384    A list containing the configured AVDs.
1385```
1386
1387
1388### RestartServer
1389
1390Restarts the adb server.
1391```
1392  Raises:
1393    CommandFailedError if we fail to kill or restart the server.
1394```
1395
1396
1397