Bug 933842 - Add ability to specify test root in SUTAgent.ini, r=jmaher.
authorBob Clary <bclary@bclary.com>
Mon, 02 Dec 2013 22:11:28 -0800
changeset 158448 8d562b33673102fe9cc785b61a5055911ad110ec
parent 158447 9d996ae7fc46ae0e7de42241b714b39b997f1828
child 158449 2eea9b6ba1d77a41f4a5d3e9bcce4cb55e8731dc
push id37002
push userbclary@mozilla.com
push dateTue, 03 Dec 2013 06:12:25 +0000
treeherdermozilla-inbound@2eea9b6ba1d7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs933842
milestone28.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 933842 - Add ability to specify test root in SUTAgent.ini, r=jmaher.
build/mobile/sutagent/android/DoCommand.java
build/mobile/sutagent/android/SUTAgentAndroid.java
--- a/build/mobile/sutagent/android/DoCommand.java
+++ b/build/mobile/sutagent/android/DoCommand.java
@@ -104,17 +104,17 @@ public class DoCommand {
     String    sErrorPrefix = "##AGENT-WARNING## ";
     boolean bTraceOn = false;
 
     String ffxProvider = "org.mozilla.ffxcp";
     String fenProvider = "org.mozilla.fencp";
 
     private static final int DEFAULT_STARTPRG_TIMEOUT_SECONDS = 300;
 
-    private final String prgVersion = "SUTAgentAndroid Version 1.19";
+    public final String prgVersion = "SUTAgentAndroid Version 1.20";
 
     public enum Command
         {
         RUN ("run"),
         EXEC ("exec"),
         EXECSU ("execsu"),
         EXECCWD ("execcwd"),
         EXECCWDSU ("execcwdsu"),
@@ -1428,39 +1428,58 @@ private void CancelNotification()
         }
         if (!tmpDir.exists() && !tmpDir.mkdirs()) {
             Log.e("SUTAgentAndroid", "Could not create directory /data/local/tmp");
         }
         chmodResult = ChmodDir("/data/local/tmp");
         Log.i("SUTAgentAndroid", "Changed permissions on /data/local/tmp to make it writable: " + chmodResult);
         }
 
+    private Boolean _SetTestRoot(String testroot)
+        {
+        String isWritable = IsDirWritable(testroot);
+        if (isWritable.contains(sErrorPrefix) || isWritable.contains("is not writable")) {
+            Log.w("SUTAgentAndroid", isWritable);
+            Log.w("SUTAgentAndroid", "Unable to set device root to " + testroot);
+            return false;
+        }
+
+        Log.i("SUTAgentAndroid", "Set device root to " + testroot);
+        SUTAgentAndroid.sTestRoot = testroot;
+        return true;
+        }
+
+    public void SetTestRoot(String testroot)
+        {
+        Boolean success = false;
+        if (!testroot.equals("")) {
+            // Device specified the required testroot.
+            success = _SetTestRoot(testroot);
+            if (!success) {
+                Log.e("SUTAgentAndroid", "Unable to set device root to " + testroot);
+            }
+        } else {
+            // Detect the testroot.
+            // Attempt external storage.
+            success = _SetTestRoot(Environment.getExternalStorageDirectory().getAbsolutePath());
+            if (!success) {
+                Log.e("SUTAgentAndroid", "Cannot access world writeable test root");
+            }
+        }
+        if (!success) {
+            SUTAgentAndroid.sTestRoot = sErrorPrefix + " unable to determine test root";
+        }
+        }
+
     public String GetTestRoot()
         {
-        String state = Environment.getExternalStorageState();
-        // Ensure sdcard is mounted and NOT read only
-        if (state.equalsIgnoreCase(Environment.MEDIA_MOUNTED) &&
-            (Environment.MEDIA_MOUNTED_READ_ONLY.compareTo(state) != 0))
-            {
-            return(Environment.getExternalStorageDirectory().getAbsolutePath());
-            }
-        File tmpFile = new java.io.File("/data/local/tmp/tests");
-        try{
-            tmpFile.createNewFile();
-        } catch (IOException e){
-            Log.i("SUTAgentAndroid", "Caught exception creating file in /data/local/tmp: " + e.getMessage());
+        if (SUTAgentAndroid.sTestRoot.equals("")) {
+            SetTestRoot("");
         }
-        if (tmpFile.exists())
-            {
-            tmpFile.delete();
-            return("/data/local");
-            }
-        Log.e("SUTAgentAndroid", "ERROR: Cannot access world writeable test root");
-
-        return sErrorPrefix + " unable to determine test root";
+        return SUTAgentAndroid.sTestRoot;
         }
 
     public String GetAppRoot(String AppName)
         {
         String sRet = sErrorPrefix + " internal error [no context]";
         Context ctx = contextWrapper.getApplicationContext();
 
         if (ctx != null)
--- a/build/mobile/sutagent/android/SUTAgentAndroid.java
+++ b/build/mobile/sutagent/android/SUTAgentAndroid.java
@@ -62,16 +62,17 @@ public class SUTAgentAndroid extends Act
 
     public static String sUniqueID = null;
     public static String sLocalIPAddr = null;
     public static String sACStatus = null;
     public static String sPowerStatus = null;
     public static int    nChargeLevel = 0;
     public static int    nBatteryTemp = 0;
     public static long   nCreateTimeMillis = System.currentTimeMillis();
+    public static String sTestRoot = "";
 
     String lineSep = System.getProperty("line.separator");
     public PrintWriter dataOut = null;
 
     private static boolean bNetworkingStarted = false;
     private static String RegSvrIPAddr = "";
     private static String RegSvrIPPort = "";
     private static String HardwareID = "";
@@ -157,34 +158,40 @@ public class SUTAgentAndroid extends Act
         super.onCreate(savedInstanceState);
 
         setContentView(R.layout.main);
 
         fixScreenOrientation();
 
         DoCommand dc = new DoCommand(getApplication());
 
+        Log.i("SUTAgentAndroid", dc.prgVersion);
         dc.FixDataLocalPermissions();
 
         // Get configuration settings from "ini" file
         File dir = getFilesDir();
         File iniFile = new File(dir, "SUTAgent.ini");
         String sIniFile = iniFile.getAbsolutePath();
 
         String lc = dc.GetIniData("General", "LogCommands", sIniFile);
         if (lc != "" && Integer.parseInt(lc) == 1) {
             SUTAgentAndroid.LogCommands = true;
         }
         SUTAgentAndroid.RegSvrIPAddr = dc.GetIniData("Registration Server", "IPAddr", sIniFile);
         SUTAgentAndroid.RegSvrIPPort = dc.GetIniData("Registration Server", "PORT", sIniFile);
         SUTAgentAndroid.HardwareID = dc.GetIniData("Registration Server", "HARDWARE", sIniFile);
         SUTAgentAndroid.Pool = dc.GetIniData("Registration Server", "POOL", sIniFile);
+        SUTAgentAndroid.sTestRoot = dc.GetIniData("Device", "TestRoot", sIniFile);
         SUTAgentAndroid.Abi = android.os.Build.CPU_ABI;
         log(dc, "onCreate");
 
+        dc.SetTestRoot(SUTAgentAndroid.sTestRoot);
+
+        Log.i("SUTAgentAndroid", "Test Root: " + SUTAgentAndroid.sTestRoot);
+
         tv = (TextView) this.findViewById(R.id.Textview01);
 
         if (getLocalIpAddress() == null)
             setUpNetwork(sIniFile);
 
         String macAddress = "Unknown";
         if (android.os.Build.VERSION.SDK_INT > 8) {
             try {
@@ -276,17 +283,19 @@ public class SUTAgentAndroid extends Act
                 }
             }
 
         String hwid = getHWID(this);
 
         sLocalIPAddr = getLocalIpAddress();
         Toast.makeText(getApplication().getApplicationContext(), "SUTAgent [" + sLocalIPAddr + "] ...", Toast.LENGTH_LONG).show();
 
-        String sConfig = "Unique ID: " + sUniqueID + lineSep;
+        String sConfig = dc.prgVersion + lineSep;
+        sConfig += "Test Root: " + sTestRoot + lineSep;
+        sConfig += "Unique ID: " + sUniqueID + lineSep;
         sConfig += "HWID: " + hwid + lineSep;
         sConfig += "ABI: " + Abi + lineSep;
         sConfig += "OS Info" + lineSep;
         sConfig += "\t" + dc.GetOSInfo() + lineSep;
         sConfig += "Screen Info" + lineSep;
         int [] xy = dc.GetScreenXY();
         sConfig += "\t Width: " + xy[0] + lineSep;
         sConfig += "\t Height: " + xy[1] + lineSep;