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