Bug 760107 - Add support for getting rotation of device to SUTAgent
authorWilliam Lachance <wlach@mozilla.com>
Thu, 31 May 2012 10:59:06 -0400
changeset 99458 7d6bfa12744db6b5ec4f57c6d8b9a257a48fdb58
parent 99457 7bcf7ead7392057b9631fa6ee8012a53a92c6880
child 99459 a6be10cfee3ff1ec96ad31fa188b8bff4a9a1742
push idunknown
push userunknown
push dateunknown
bugs760107
milestone15.0a1
Bug 760107 - Add support for getting rotation of device to SUTAgent
build/mobile/devicemanagerSUT.py
build/mobile/sutagent/android/DoCommand.java
--- a/build/mobile/devicemanagerSUT.py
+++ b/build/mobile/devicemanagerSUT.py
@@ -918,30 +918,31 @@ class DeviceManagerSUT(DeviceManager):
 
   # Returns information about the device:
   # Directive indicates the information you want to get, your choices are:
   # os - name of the os
   # id - unique id of the device
   # uptime - uptime of the device
   # systime - system time of the device
   # screen - screen resolution
+  # rotation - rotation of the device (in degrees)
   # memory - memory stats
   # process - list of running processes (same as ps)
   # disk - total, free, available bytes on disk
   # power - power status (charge, battery temp)
   # all - all of them - or call it with no parameters to get all the information
   # returns:
   #   success: dict of info strings by directive name
   #   failure: {}
   def getInfo(self, directive=None):
     data = None
     result = {}
     collapseSpaces = re.compile('  +')
 
-    directives = ['os', 'id','uptime','systime','screen','memory','process',
+    directives = ['os','id','uptime','systime','screen','rotation','memory','process',
                   'disk','power']
     if (directive in directives):
       directives = [directive]
 
     for d in directives:
       data = self.runCmds(['info ' + d])
       if (data is None):
         continue
--- a/build/mobile/sutagent/android/DoCommand.java
+++ b/build/mobile/sutagent/android/DoCommand.java
@@ -80,16 +80,17 @@ import android.database.Cursor;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Debug;
 import android.os.Environment;
 import android.os.StatFs;
 import android.os.SystemClock;
 import android.util.DisplayMetrics;
 import android.util.Log;
+import android.view.Surface;
 import android.view.WindowManager;
 
 public class DoCommand {
 
     String lineSep = System.getProperty("line.separator");
     Process    pProc;
     OutputStream sutIn;
     InputStream    sutErr;
@@ -116,16 +117,17 @@ public class DoCommand {
         PS ("ps"),
         DEVINFO ("info"),
         OS ("os"),
         ID ("id"),
         UPTIME ("uptime"),
         SETTIME ("settime"),
         SYSTIME ("systime"),
         SCREEN ("screen"),
+        ROTATION ("rotation"),
         MEMORY ("memory"),
         POWER ("power"),
         PROCESS ("process"),
         GETAPPROOT ("getapproot"),
         TESTROOT ("testroot"),
         ALRT ("alrt"),
         DISK ("disk"),
         CP ("cp"),
@@ -408,16 +410,18 @@ public class DoCommand {
                     strReturn += GetOSInfo();
                     strReturn += "\n";
                     strReturn += GetSystemTime();
                     strReturn += "\n";
                     strReturn += GetUptime();
                     strReturn += "\n";
                     strReturn += GetScreenInfo();
                     strReturn += "\n";
+                    strReturn += GetRotationInfo();
+                    strReturn += "\n";
                     strReturn += GetMemoryInfo();
                     strReturn += "\n";
                     strReturn += GetPowerInfo();
                     strReturn += "\n";
                     strReturn += GetProcessInfo();
                     }
                 else
                     {
@@ -427,16 +431,20 @@ public class DoCommand {
                         case ID:
                             strReturn = SUTAgentAndroid.sUniqueID;
                             break;
 
                         case SCREEN:
                             strReturn = GetScreenInfo();
                             break;
 
+                        case ROTATION:
+                            strReturn = GetRotationInfo();
+                            break;
+
                         case PROCESS:
                             strReturn = GetProcessInfo();
                             break;
 
                         case OS:
                             strReturn = GetOSInfo();
                             break;
 
@@ -2289,16 +2297,35 @@ private void CancelNotification()
             DisplayMetrics metrics = new DisplayMetrics();
             WindowManager wMgr = (WindowManager) contextWrapper.getSystemService(Context.WINDOW_SERVICE);
             wMgr.getDefaultDisplay().getMetrics(metrics);
             nRetXY[0] = metrics.widthPixels;
             nRetXY[1] = metrics.heightPixels;
             return(nRetXY);
         }
 
+    public String GetRotationInfo()
+        {
+            WindowManager wMgr = (WindowManager) contextWrapper.getSystemService(Context.WINDOW_SERVICE);
+            int nRotationDegrees = 0; // default
+            switch(wMgr.getDefaultDisplay().getRotation())
+                {
+                case Surface.ROTATION_90:
+                    nRotationDegrees = 90;
+                    break;
+                case Surface.ROTATION_180:
+                    nRotationDegrees = 180;
+                    break;
+                case Surface.ROTATION_270:
+                    nRotationDegrees = 270;
+                    break;
+                }
+            return "ROTATION:" + nRotationDegrees;
+        }
+
     public String SetADB(String sWhat) {
         String sRet = "";
         String sTmp = "";
         String sCmd;
 
         if (sWhat.contains("ip")) {
             sCmd = "setprop service.adb.tcp.port 5555";
         } else {