OLD | NEW |
---|---|
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Provides a variety of device interactions based on adb. | 5 """Provides a variety of device interactions based on adb. |
6 | 6 |
7 Eventually, this will be based on adb_wrapper. | 7 Eventually, this will be based on adb_wrapper. |
8 """ | 8 """ |
9 # pylint: disable=W0613 | 9 # pylint: disable=W0613 |
10 | 10 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 if check_return: | 291 if check_return: |
292 code, output = self.old_interface.GetShellCommandStatusAndOutput( | 292 code, output = self.old_interface.GetShellCommandStatusAndOutput( |
293 cmd, timeout_time=timeout) | 293 cmd, timeout_time=timeout) |
294 if int(code) != 0: | 294 if int(code) != 0: |
295 raise device_errors.CommandFailedError( | 295 raise device_errors.CommandFailedError( |
296 cmd, 'Nonzero exit code (%d)' % code) | 296 cmd, 'Nonzero exit code (%d)' % code) |
297 else: | 297 else: |
298 output = self.old_interface.RunShellCommand(cmd, timeout_time=timeout) | 298 output = self.old_interface.RunShellCommand(cmd, timeout_time=timeout) |
299 return output | 299 return output |
300 | 300 |
301 @decorators.WithTimeoutAndRetriesFromInstance() | |
302 def KillAll(self, process_name, signum=9, root=False, blocking=False, | |
Sami
2014/06/17 20:39:11
ditto about signal.SIGKILL.
jbudorick
2014/06/17 21:09:27
Done.
| |
303 timeout=None, retries=None): | |
304 """Kill all processes with the given name on the device. | |
305 | |
306 Args: | |
307 process_name: A string containing the name of the process to kill. | |
308 signum: An integer containing the signal number to send to kill. Defaults | |
309 to 9 (SIGKILL). | |
310 root: A boolean indicating whether the kill should be executed with root | |
311 priveleges. | |
312 blocking: A boolean indicating whether we should wait until all processes | |
313 with the given |process_name| are dead. | |
314 timeout: Same as for |IsOnline|. | |
315 retries: Same as for |IsOnline|. | |
316 """ | |
317 if blocking: | |
318 self.old_interface.KillAllBlocking(process_name, signum=signum, | |
319 with_su=root, timeout_sec=timeout) | |
320 else: | |
321 self.old_interface.KillAll(process_name, signum=signum, with_su=root) | |
322 | |
323 @decorators.WithTimeoutAndRetriesFromInstance() | |
324 def StartActivity(self, intent, blocking=False, trace_file_name=None, | |
325 force_stop=False, timeout=None, retries=None): | |
326 """Start package's activity on the device. | |
327 | |
328 Args: | |
329 intent: An Intent to send. | |
330 blocking: A boolean indicating whether we should wait for the activity to | |
331 finish launching. | |
332 trace_file_name: If present, a string that both indicates that we want to | |
333 profile the activity and contains the path to which the | |
334 trace should be saved. | |
335 force_stop: A boolean indicating whether we should stop the activity | |
336 before starting it. | |
337 timeout: Same as for |IsOnline|. | |
338 retries: Same as for |IsOnline|. | |
339 """ | |
340 self.old_interface.StartActivity( | |
341 intent.package, intent.activity, wait_for_completion=blocking, | |
342 action=intent.action, category=intent.category, data=intent.data, | |
343 extras=intent.extras, trace_file_name=trace_file_name, | |
344 force_stop=force_stop, flags=intent.flags) | |
345 | |
346 @decorators.WithTimeoutAndRetriesFromInstance() | |
347 def StartActivityTimed(self, intent, blocking=False, trace_file_name=None, | |
348 force_stop=False, timeout=None, retries=None): | |
Victor Starodub
2014/06/17 18:43:42
Why do we need both this and previous method? Can'
jbudorick
2014/06/17 21:09:27
This is a good question, and one to which I don't
| |
349 """Start package's activity on the device and return the start time. | |
350 | |
351 Args: | |
352 intent: Same as for |StartActivity|. | |
353 blocking: Same as for |StartActivity|. | |
354 trace_file_name: Same as for |StartActivity|. | |
355 force_stop: Same as for |StartActivity|. | |
356 timeout: Same as for |IsOnline|. | |
357 retries: Same as for |IsOnline|. | |
358 Returns: | |
359 The start time of the activity. | |
frankf
2014/06/17 18:45:44
can you clarify whether this is device or host tim
jbudorick
2014/06/17 21:09:27
removing this function as noted above
| |
360 """ | |
361 return self.old_interface.StartActivityTimed( | |
362 intent.package, intent.activity, wait_for_completion=blocking, | |
363 action=intent.action, category=intent.category, data=intent.data, | |
364 extras=intent.extras, trace_file_name=trace_file_name, | |
365 force_stop=force_stop, flags=intent.flags) | |
366 | |
367 @decorators.WithTimeoutAndRetriesFromInstance() | |
368 def BroadcastIntent(self, intent, timeout=None, retries=None): | |
369 """Send a broadcast intent. | |
370 | |
371 Args: | |
372 intent: An Intent to broadcast. | |
373 timeout: Same as for |IsOnline|. | |
374 retries: Same as for |IsOnline|. | |
375 """ | |
376 package, old_intent = intent.action.rsplit('.', 1) | |
377 if intent.extras is None: | |
378 args = [] | |
379 else: | |
380 args = ['-e %s%s' % (k, ' "%s"' % v if v else '') | |
381 for k, v in intent.extras.items() if len(k) > 0] | |
382 self.old_interface.BroadcastIntent(package, old_intent, *args) | |
383 | |
301 def __str__(self): | 384 def __str__(self): |
302 """Returns the device serial.""" | 385 """Returns the device serial.""" |
303 return self.old_interface.GetDevice() | 386 return self.old_interface.GetDevice() |
304 | 387 |
305 @staticmethod | 388 @staticmethod |
306 def parallel(devices=None, async=False): | 389 def parallel(devices=None, async=False): |
307 """Creates a Parallelizer to operate over the provided list of devices. | 390 """Creates a Parallelizer to operate over the provided list of devices. |
308 | 391 |
309 If |devices| is either |None| or an empty list, the Parallelizer will | 392 If |devices| is either |None| or an empty list, the Parallelizer will |
310 operate over all attached devices. | 393 operate over all attached devices. |
311 | 394 |
312 Args: | 395 Args: |
313 devices: A list of either DeviceUtils instances or objects from | 396 devices: A list of either DeviceUtils instances or objects from |
314 from which DeviceUtils instances can be constructed. If None, | 397 from which DeviceUtils instances can be constructed. If None, |
315 all attached devices will be used. | 398 all attached devices will be used. |
316 async: If true, returns a Parallelizer that runs operations | 399 async: If true, returns a Parallelizer that runs operations |
317 asynchronously. | 400 asynchronously. |
318 Returns: | 401 Returns: |
319 A Parallelizer operating over |devices|. | 402 A Parallelizer operating over |devices|. |
320 """ | 403 """ |
321 if not devices or len(devices) == 0: | 404 if not devices or len(devices) == 0: |
322 devices = pylib.android_commands.GetAttachedDevices() | 405 devices = pylib.android_commands.GetAttachedDevices() |
323 parallelizer_type = (parallelizer.Parallelizer if async | 406 parallelizer_type = (parallelizer.Parallelizer if async |
324 else parallelizer.SyncParallelizer) | 407 else parallelizer.SyncParallelizer) |
325 return parallelizer_type([ | 408 return parallelizer_type([ |
326 d if isinstance(d, DeviceUtils) else DeviceUtils(d) | 409 d if isinstance(d, DeviceUtils) else DeviceUtils(d) |
327 for d in devices]) | 410 for d in devices]) |
328 | 411 |
OLD | NEW |