Bug 838844 - Add info option to get sutagent user info;r=gbrown
authorWilliam Lachance <wlachance@mozilla.com>
Fri, 08 Feb 2013 15:46:57 -0500
changeset 131251 69e3d0de1e0134fbff59c7e07b48b237ddf861df
parent 131250 8d3212955deb14b63d07650eba8c7e380720b0b8
child 131252 3634c136a68b886b2b6e4a74521cd3f9de338193
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs838844
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 838844 - Add info option to get sutagent user info;r=gbrown
build/mobile/sutagent/android/DoCommand.java
--- a/build/mobile/sutagent/android/DoCommand.java
+++ b/build/mobile/sutagent/android/DoCommand.java
@@ -126,16 +126,17 @@ public class DoCommand {
         UPTIMEMILLIS ("uptimemillis"),
         SETTIME ("settime"),
         SYSTIME ("systime"),
         SCREEN ("screen"),
         ROTATION ("rotation"),
         MEMORY ("memory"),
         POWER ("power"),
         PROCESS ("process"),
+        SUTUSERINFO ("sutuserinfo"),
         GETAPPROOT ("getapproot"),
         TESTROOT ("testroot"),
         ALRT ("alrt"),
         DISK ("disk"),
         CP ("cp"),
         TIME ("time"),
         HASH ("hash"),
         CD ("cd"),
@@ -430,16 +431,18 @@ public class DoCommand {
                     strReturn += "\n";
                     strReturn += GetRotationInfo();
                     strReturn += "\n";
                     strReturn += GetMemoryInfo();
                     strReturn += "\n";
                     strReturn += GetPowerInfo();
                     strReturn += "\n";
                     strReturn += GetProcessInfo();
+                    strReturn += "\n";
+                    strReturn += GetSutUserInfo();
                     }
                 else
                     {
                     cSubCmd = Command.getCmd(Argv[1]);
                     switch(cSubCmd)
                         {
                         case ID:
                             strReturn = SUTAgentAndroid.sUniqueID;
@@ -476,16 +479,20 @@ public class DoCommand {
                         case MEMORY:
                             strReturn = GetMemoryInfo();
                             break;
 
                         case POWER:
                             strReturn += GetPowerInfo();
                             break;
 
+                        case SUTUSERINFO:
+                            strReturn += GetSutUserInfo();
+                            break;
+
                         default:
                             break;
                         }
                     }
                 break;
 
             case STAT:
                 if (Argc == 2)
@@ -2602,16 +2609,38 @@ private void CancelNotification()
 
         sRet = "Power status:\n  AC power " + SUTAgentAndroid.sACStatus + "\n";
         sRet += "  Battery charge " + SUTAgentAndroid.sPowerStatus + "\n";
         sRet += "  Remaining charge:      " + SUTAgentAndroid.nChargeLevel + "%\n";
         sRet += "  Battery Temperature:   " + (((float)(SUTAgentAndroid.nBatteryTemp))/10) + " (c)\n";
         return (sRet);
         }
 
+    public String GetSutUserInfo()
+        {
+        String sRet = "";
+        try {
+            // based on patch in https://bugzilla.mozilla.org/show_bug.cgi?id=811763
+            Context context = contextWrapper.getApplicationContext();
+            Object userManager = context.getSystemService("user");
+            if (userManager != null) {
+                // if userManager is non-null that means we're running on 4.2+ and so the rest of this
+                // should just work
+                Object userHandle = android.os.Process.class.getMethod("myUserHandle", (Class[])null).invoke(null);
+                Object userSerial = userManager.getClass().getMethod("getSerialNumberForUser", userHandle.getClass()).invoke(userManager, userHandle);
+                sRet += "User Serial:" + userSerial.toString();
+            }
+        } catch (Exception e) {
+            // Guard against any unexpected failures
+            e.printStackTrace();
+        }
+
+        return sRet;
+        }
+
     // todo
     public String GetDiskInfo(String sPath)
         {
         String sRet = "";
         StatFs statFS = new StatFs(sPath);
 
         int nBlockCount = statFS.getBlockCount();
         int nBlockSize = statFS.getBlockSize();