Use file to pass arguments to the shell.

Passing parameters directly through the intent have the following
issues:
- It limits the size of the parameters to 1024 bytes.
- It is regularly broken by new versions of adb.

R=ppi@chromium.org
BUG=Fixes https://github.com/domokit/mojo/issues/488

Review URL: https://codereview.chromium.org/1414633004 .

Cr-Mirrored-From: https://github.com/domokit/mojo
Cr-Mirrored-Commit: 69df74a38358c7c3611babeeaa5b8258dce05619
diff --git a/devtoolslib/android_shell.py b/devtoolslib/android_shell.py
index 611732e..ab03bb2 100644
--- a/devtoolslib/android_shell.py
+++ b/devtoolslib/android_shell.py
@@ -15,6 +15,7 @@
 import tempfile
 import threading
 import time
+import uuid
 
 from devtoolslib.http_server import start_http_server
 from devtoolslib.shell import Shell
@@ -349,8 +350,20 @@
     parameters.extend(arguments)
 
     if parameters:
-      encodedParameters = json.dumps(parameters)
-      cmd += ['--es', 'encodedParameters', encodedParameters]
+      device_filename = (
+          '/sdcard/%s/args_%s' % (_MOJO_SHELL_PACKAGE_NAME, str(uuid.uuid4())))
+      with tempfile.NamedTemporaryFile(delete=False) as temp:
+        try:
+          for parameter in parameters:
+            temp.write(parameter)
+            temp.write('\n')
+          temp.close()
+          subprocess.check_call(self._adb_command(
+              ['push', temp.name, device_filename]))
+        finally:
+          os.remove(temp.name)
+
+      cmd += ['--es', 'argsFile', device_filename]
 
     subprocess.check_call(cmd, stdout=self.verbose_pipe)