author Gregory Szorc <>
Wed, 28 Jan 2015 13:37:00 -0800
changeset 243304 de801bc4b960fcd6787cb12a0c38d8b5153e5630
parent 97557 a9d94e8f4073d02d55d1fbc232a9be77f99dfb00
permissions -rw-r--r--
Close old release branch GECKO160_2012091123_RELBRANCH

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at

from devicemanagerADB import DeviceManagerADB
from devicemanagerSUT import DeviceManagerSUT
import StringIO

class DroidMixin(object):
  """Mixin to extend DeviceManager with Android-specific functionality"""

  def launchApplication(self, appName, activityName, intent, url=None,
    Launches an Android application
    success: True
    failure: False
    # only one instance of an application may be running at once
    if self.processExist(appName):
      return False

    acmd = [ "am", "start", "-W", "-n", "%s/%s" % (appName, activityName)]

    if intent:
      acmd.extend(["-a", intent])

    if extras:
      for (key, val) in extras.iteritems():
        if type(val) is int:
          extraTypeParam = "--ei"
        elif type(val) is bool:
          extraTypeParam = "--ez"
          extraTypeParam = "--es"
        acmd.extend([extraTypeParam, str(key), str(val)])

    if 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, 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
    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
    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,

class DroidADB(DeviceManagerADB, DroidMixin):

class DroidSUT(DeviceManagerSUT, DroidMixin):