Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1587)

Side by Side Diff: mojo/devtools/common/devtoolslib/android_shell.py

Issue 1414633004: Use file to pass arguments to the shell. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 import atexit 5 import atexit
6 import hashlib 6 import hashlib
7 import json 7 import json
8 import logging 8 import logging
9 import os 9 import os
10 import os.path 10 import os.path
11 import random 11 import random
12 import re 12 import re
13 import subprocess 13 import subprocess
14 import sys 14 import sys
15 import tempfile 15 import tempfile
16 import threading 16 import threading
17 import time 17 import time
18 import uuid
18 19
19 from devtoolslib.http_server import start_http_server 20 from devtoolslib.http_server import start_http_server
20 from devtoolslib.shell import Shell 21 from devtoolslib.shell import Shell
21 from devtoolslib.utils import overrides 22 from devtoolslib.utils import overrides
22 23
23 24
24 # Tags used by mojo shell Java logging. 25 # Tags used by mojo shell Java logging.
25 _LOGCAT_JAVA_TAGS = [ 26 _LOGCAT_JAVA_TAGS = [
26 'AndroidHandler', 27 'AndroidHandler',
27 'MojoFileHelper', 28 'MojoFileHelper',
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 ['shell', 'rm', '-f', STDOUT_PIPE])) 343 ['shell', 'rm', '-f', STDOUT_PIPE]))
343 344
344 parameters.append('--fifo-path=%s' % STDOUT_PIPE) 345 parameters.append('--fifo-path=%s' % STDOUT_PIPE)
345 self._read_fifo(STDOUT_PIPE, stdout, on_application_stop) 346 self._read_fifo(STDOUT_PIPE, stdout, on_application_stop)
346 else: 347 else:
347 _logger.warning("Running without root access, full stdout of the " 348 _logger.warning("Running without root access, full stdout of the "
348 "shell won't be available.") 349 "shell won't be available.")
349 parameters.extend(arguments) 350 parameters.extend(arguments)
350 351
351 if parameters: 352 if parameters:
352 encodedParameters = json.dumps(parameters) 353 device_filename = (
353 cmd += ['--es', 'encodedParameters', encodedParameters] 354 '/sdcard/%s/%s' % (_MOJO_SHELL_PACKAGE_NAME, str(uuid.uuid4())))
ppi 2015/10/29 16:27:40 Should we push this to some /cache/ folder so that
ppi 2015/10/29 16:27:40 can you append or prepend "mojo_shell_args" to the
qsr 2015/10/29 16:57:02 Not that I know of. Cache folder are in the app ow
qsr 2015/10/29 16:57:02 It is already in a folder with the shell package n
355 with tempfile.NamedTemporaryFile(delete=False) as temp:
356 try:
357 for parameter in parameters:
358 temp.write(parameter)
359 temp.write('\n')
360 temp.close()
361 subprocess.check_call(self._adb_command(
362 ['push', temp.name, device_filename]))
363 finally:
364 os.remove(temp.name)
365
366 cmd += ['--es', 'parametersFile', device_filename]
ppi 2015/10/29 16:27:40 Should we call it argsFile for consistency?
qsr 2015/10/29 16:57:02 Done.
354 367
355 subprocess.check_call(cmd, stdout=self.verbose_pipe) 368 subprocess.check_call(cmd, stdout=self.verbose_pipe)
356 369
357 def stop_shell(self): 370 def stop_shell(self):
358 """Stops the mojo shell.""" 371 """Stops the mojo shell."""
359 subprocess.check_call(self._adb_command(['shell', 372 subprocess.check_call(self._adb_command(['shell',
360 'am', 373 'am',
361 'force-stop', 374 'force-stop',
362 _MOJO_SHELL_PACKAGE_NAME])) 375 _MOJO_SHELL_PACKAGE_NAME]))
363 376
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 Results.output = rf.read() 471 Results.output = rf.read()
459 472
460 run_thread = threading.Thread(target=do_run) 473 run_thread = threading.Thread(target=do_run)
461 run_thread.start() 474 run_thread.start()
462 run_thread.join(timeout) 475 run_thread.join(timeout)
463 476
464 if run_thread.is_alive(): 477 if run_thread.is_alive():
465 self.stop_shell() 478 self.stop_shell()
466 return None, Results.output, True 479 return None, Results.output, True
467 return None, Results.output, False 480 return None, Results.output, False
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698