Bug 634691 - update devicemanager to adjust screen resolution and fix unit tests. r=mcote, a=NPOTB
authorJoel Maher <jmaher@mozilla.com>
Wed, 23 Feb 2011 14:38:55 -0500
changeset 63016 c84daebe92d2f0bee48f7c4e6599f184bb80a782
parent 63015 865a1e5b97a1eec4f72a8f3862296a590fa47375
child 63017 8d295a60c458ce81f76b0187fef1f9474f164e3b
push idunknown
push userunknown
push dateunknown
reviewersmcote, NPOTB
bugs634691
milestone2.0b13pre
Bug 634691 - update devicemanager to adjust screen resolution and fix unit tests. r=mcote, a=NPOTB
build/mobile/devicemanager.py
--- a/build/mobile/devicemanager.py
+++ b/build/mobile/devicemanager.py
@@ -482,18 +482,22 @@ class DeviceManager:
           files += [[pidproc[1], pidproc[2], pidproc[0]]]     
     return files
 
   # external function
   # returns:
   #  success: pid
   #  failure: None
   def fireProcess(self, appname):
+    if (not appname):
+      if (self.debug >= 1): print "WARNING: fireProcess called with no command to run"
+      return None
+
     if (self.debug >= 2): print "FIRE PROC: '" + appname + "'"
-    
+
     if (self.processExist(appname) != None):
       print "WARNING: process %s appears to be running already\n" % appname
     
     try:
       data = self.verifySendCMD(['exec ' + appname])
     except(DMError):
       return None
 
@@ -509,16 +513,20 @@ class DeviceManager:
     if (self.debug >= 4): print "got pid: %s for process: %s" % (process, appname)
     return process
 
   # external function
   # returns:
   #  success: output filename
   #  failure: None
   def launchProcess(self, cmd, outputFile = "process.txt", cwd = '', env = ''):
+    if not cmd:
+      if (self.debug >= 1): print "WARNING: launchProcess called without command to run"
+      return None
+
     cmdline = subprocess.list2cmdline(cmd)
     if (outputFile == "process.txt" or outputFile == None):
       outputFile = self.getDeviceRoot();
       if outputFile is None:
         return None
       outputFile += "/process.txt"
       cmdline += " > " + outputFile
     
@@ -1149,33 +1157,33 @@ class DeviceManager:
       # Then we pass '' for processName
       cmd += "'' " + appBundlePath
     else:
       cmd += processName + ' ' + appBundlePath
 
     if (destPath):
       cmd += " " + destPath
 
-    if (self.debug > 3): print "INFO: updateApp using command: " + str(cmd)
-
     if (ipAddr is not None):
       ip, port = self.getCallbackIpAndPort(ipAddr, port)
       cmd += " %s %s" % (ip, port)
       # Set up our callback server
       callbacksvr = callbackServer(ip, port, self.debug)
 
+    if (self.debug >= 3): print "INFO: updateApp using command: " + str(cmd)
+
     try:
       status = self.verifySendCMD([cmd])
     except(DMError):
       return None
 
     if ipAddr is not None:
       status = callbacksvr.disconnect()
 
-    if (self.debug > 3): print "INFO: updateApp: got status back: " + str(status)
+    if (self.debug >= 3): print "INFO: updateApp: got status back: " + str(status)
 
     return status
 
   """
     return the current time on the device
   """
   # external function
   # returns:
@@ -1204,54 +1212,107 @@ class DeviceManager:
     else:
       port = nettools.findOpenPort(ip, 30000)
     return ip, port
 
   """
     Returns a properly formatted env string for the agent.
     Input - env, which is either None, '', or a dict
     Output - a quoted string of the form: '"envvar1=val1,envvar2=val2..."'
-    If env is None or '' return '""' (empty quoted string)
+    If env is None or '' return '' (empty quoted string)
   """
   def formatEnvString(self, env):
     if (env == None or env == ''):
-      return '""'
+      return ''
+
+    retVal = '"%s"' % ','.join(map(lambda x: '%s=%s' % (x[0], x[1]), env.iteritems()))
+    print "got retval: '%s'" % retVal
+    if (retVal == '""'):
+      return ''
+
+    return retVal
+
+  """
+    adjust the screen resolution on the device, REBOOT REQUIRED
+    NOTE: this only works on a tegra ATM
+    success: True
+    failure: False
+
+    supported resolutions: 640x480, 800x600, 1024x768, 1152x864, 1200x1024, 1440x900, 1680x1050, 1920x1080
+  """
+  def adjustResolution(self, width=1680, height=1050, type='hdmi'):
+    if self.getInfo('os')['os'][0].split()[0] != 'harmony-eng':
+      if (self.debug >= 2): print "WARNING: unable to adjust screen resolution on non Tegra device"
+      return False
+
+    results = self.getInfo('screen')
+    parts = results['screen'][0].split(':')
+    if (self.debug >= 3): print "INFO: we have a current resolution of %s, %s" % (parts[1].split()[0], parts[2].split()[0])
 
-    return '"%s"' % ','.join(map(lambda x: '%s=%s' % (x[0], x[1]), env.iteritems()))
+    #verify screen type is valid, and set it to the proper value (https://bugzilla.mozilla.org/show_bug.cgi?id=632895#c4)
+    screentype = -1
+    if (type == 'hdmi'):
+      screentype = 5
+    elif (type == 'vga' or type == 'crt'):
+      screentype = 3
+    else:
+      return False
+
+    #verify we have numbers
+    if not (isinstance(width, int) and isinstance(height, int)):
+      return False
+
+    if (width < 100 or width > 9999):
+      return False
+
+    if (height < 100 or height > 9999):
+      return False
+
+    if (self.debug >= 3): print "INFO: adjusting screen resolution to %s, %s and rebooting" % (width, height)
+    try:
+      self.verifySendCMD(["exec setprop persist.tegra.dpy%s.mode.width %s" % (screentype, width)])
+      self.verifySendCMD(["exec setprop persist.tegra.dpy%s.mode.height %s" % (screentype, height)])
+    except(DMError):
+      return False
+
+    if (self.reboot(True) == None):
+      return False
+
+    return True
 
 gCallbackData = ''
 
 class myServer(SocketServer.TCPServer):
   allow_reuse_address = True
 
 class callbackServer():
   def __init__(self, ip, port, debuglevel):
     self.ip = ip
     self.port = port
     self.connected = False
     self.debug = debuglevel
-    if (self.debug > 3) : print "Creating server with " + str(ip) + ":" + str(port)
+    if (self.debug >= 3) : print "Creating server with " + str(ip) + ":" + str(port)
     self.server = myServer((ip, port), self.myhandler)
     self.server_thread = Thread(target=self.server.serve_forever) 
     self.server_thread.setDaemon(True)
     self.server_thread.start()
 
   def disconnect(self, step = 60, timeout = 600):
     t = 0
-    if (self.debug > 3): print "Calling disconnect on callback server"
+    if (self.debug >= 3): print "Calling disconnect on callback server"
     while t < timeout:
       if (gCallbackData):
         # Got the data back
-        if (self.debug > 3): print "Got data back from agent: " + str(gCallbackData)
+        if (self.debug >= 3): print "Got data back from agent: " + str(gCallbackData)
         break
       time.sleep(step)
       t += step
 
     try:
-      if (self.debug > 3): print "Shutting down server now"
+      if (self.debug >= 3): print "Shutting down server now"
       self.server.shutdown()
     except:
       print "Unable to shutdown callback server - check for a connection on port: " + str(self.port)
     return gCallbackData
 
   class myhandler(SocketServer.BaseRequestHandler):
     def handle(self):
       global gCallbackData