Bug 752690 - Various problems encountered with mozdevice when trying to get Google Chrome and Stock ICS working with Eideticker;r=jmaher
authorWilliam Lachance <wlachance@mozilla.com>
Tue, 08 May 2012 11:04:58 -0400
changeset 95770 a9d94e8f4073d02d55d1fbc232a9be77f99dfb00
parent 95769 81eed078269926791e7a77125771f14fc2754469
child 95771 f0b9f5c391a8e3e37afec10c9675b0072ea8ecaa
push id1439
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 20:19:22 +0000
treeherdermozilla-aurora@ea74834dccd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs752690
milestone15.0a1
Bug 752690 - Various problems encountered with mozdevice when trying to get Google Chrome and Stock ICS working with Eideticker;r=jmaher
build/mobile/devicemanagerADB.py
build/mobile/droid.py
--- a/build/mobile/devicemanagerADB.py
+++ b/build/mobile/devicemanagerADB.py
@@ -90,19 +90,26 @@ class DeviceManagerADB(DeviceManager):
     if self.host:
       self.disconnectRemoteADB()
 
   # external function: executes shell command on device
   # returns:
   # success: <return code>
   # failure: None
   def shell(self, cmd, outputfile, env=None, cwd=None):
-    # need to quote special characters here
+    # need to quote and escape special characters here
     for (index, arg) in enumerate(cmd):
-      if arg.find(" ") or arg.find("(") or arg.find(")") or arg.find("\""):
+      arg.replace('&', '\&')
+
+      needsQuoting = False
+      for char in [ ' ', '(', ')', '"', '&' ]:
+        if arg.find(char):
+          needsQuoting = True
+          break
+      if needsQuoting:
         cmd[index] = '\'%s\'' % arg
 
     # This is more complex than you'd think because adb doesn't actually
     # return the return code from a process, so we have to capture the output
     # to get it
     # FIXME: this function buffers all output of the command into memory,
     # always. :(
     cmdline = " ".join(cmd) + "; echo $?"
--- a/build/mobile/droid.py
+++ b/build/mobile/droid.py
@@ -4,53 +4,80 @@
 
 from devicemanagerADB import DeviceManagerADB
 from devicemanagerSUT import DeviceManagerSUT
 import StringIO
 
 class DroidMixin(object):
   """Mixin to extend DeviceManager with Android-specific functionality"""
 
-  def launchApplication(self, app, activity="App",
-                        intent="android.intent.action.VIEW", env=None,
-                        url=None, extra_args=None):
+  def launchApplication(self, appName, activityName, intent, url=None,
+                        extras=None):
     """
     Launches an Android application
     returns:
     success: True
     failure: False
     """
     # only one instance of an application may be running at once
-    if self.processExist(app):
+    if self.processExist(appName):
       return False
 
-    acmd = [ "am", "start", "-W", "-n", "%s/.%s" % (app, activity)]
+    acmd = [ "am", "start", "-W", "-n", "%s/%s" % (appName, activityName)]
 
     if intent:
       acmd.extend(["-a", intent])
 
-    if extra_args:
-      acmd.extend(["--es", "args", " ".join(extra_args)])
-
-    if env:
-      envCnt = 0
-      # env is expected to be a dict of environment variables
-      for envkey, envval in env.iteritems():
-        acmd.extend(["--es", "env" + str(envCnt), envkey + "=" + envval])
-        envCnt += 1
+    if extras:
+      for (key, val) in extras.iteritems():
+        if type(val) is int:
+          extraTypeParam = "--ei"
+        elif type(val) is bool:
+          extraTypeParam = "--ez"
+        else:
+          extraTypeParam = "--es"
+        acmd.extend([extraTypeParam, str(key), str(val)])
 
     if url:
-      acmd.extend(["-d", ''.join(["'", url, "'"])])
+      acmd.extend(["-d", url])
 
     # shell output not that interesting and debugging logs should already
     # show what's going on here... so just create an empty memory buffer
     # and ignore
     shellOutput = StringIO.StringIO()
     if self.shell(acmd, shellOutput) == 0:
       return True
 
     return False
 
+  def launchFennec(self, appName, intent="android.intent.action.VIEW",
+                   mozEnv=None, extraArgs=None, url=None):
+    """
+    Convenience method to launch Fennec on Android with various debugging
+    arguments
+    WARNING: FIXME: This would go better in mozrunner. Please do not
+    use this method if you are not comfortable with it going away sometime
+    in the near future
+    returns:
+    success: True
+    failure: False
+    """
+    extras = {}
+
+    if mozEnv:
+      # mozEnv is expected to be a dictionary of environment variables: Fennec
+      # itself will set them when launched
+      for (envCnt, (envkey, envval)) in enumerate(mozEnv.iteritems()):
+        extras["env" + str(envCnt)] = envkey + "=" + envval
+
+    # Additional command line arguments that fennec will read and use (e.g.
+    # with a custom profile)
+    if extraArgs:
+      extras['args'] = " ".join(extraArgs)
+
+    return self.launchApplication(appName, ".App", intent, url=url,
+                                  extras=extras)
+
 class DroidADB(DeviceManagerADB, DroidMixin):
   pass
 
 class DroidSUT(DeviceManagerSUT, DroidMixin):
   pass