Show Partition Info in Report Header

Bug 3400973

Show output of the 'df' command in the report header.
See the bug for a picture of what it looks like.

Change-Id: Ida450185ed8c0ead7c7d05e7326cc86346e05794
diff --git a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java
index 31168fd..8b00ddf 100644
--- a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java
+++ b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoInstrument.java
@@ -31,10 +31,12 @@
 import android.view.Display;
 import android.view.WindowManager;
 
+import java.io.IOException;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Scanner;
 import java.util.Set;
 
 public class DeviceInfoInstrument extends Instrumentation {
@@ -43,6 +45,7 @@
 
     // constants for device info attributes to be sent as instrumentation keys
     // these values should correspond to attributes defined in cts_result.xsd
+    private static final String PARTITIONS = "partitions";
     private static final String OPEN_GL_ES_VERSION = "openGlEsVersion";
     private static final String PROCESSES = "processes";
     private static final String FEATURES = "features";
@@ -158,6 +161,9 @@
         String openGlEsVersion = getOpenGlEsVersion();
         addResult(OPEN_GL_ES_VERSION, openGlEsVersion);
 
+        // partitions
+        String partitions = getPartitions();
+        addResult(PARTITIONS, partitions);
 
         finish(Activity.RESULT_OK, mResults);
     }
@@ -329,4 +335,22 @@
         }
         return "No feature for Open GL ES version.";
     }
+
+    private String getPartitions() {
+        try {
+            StringBuilder builder = new StringBuilder();
+            Process df = new ProcessBuilder("df").start();
+            Scanner scanner = new Scanner(df.getInputStream());
+            try {
+                while (scanner.hasNextLine()) {
+                    builder.append(scanner.nextLine()).append(';');
+                }
+                return builder.toString();
+            } finally {
+                scanner.close();
+            }
+        } catch (IOException e) {
+            return "Not able to run df for partition information.";
+        }
+    }
 }
diff --git a/tools/host/src/com/android/cts/TestDevice.java b/tools/host/src/com/android/cts/TestDevice.java
index 88bcd68..8460078 100644
--- a/tools/host/src/com/android/cts/TestDevice.java
+++ b/tools/host/src/com/android/cts/TestDevice.java
@@ -436,6 +436,7 @@
         public static final String FEATURES = "features";
         public static final String PROCESSES = "processes";
         public static final String OPEN_GL_ES_VERSION = "openGlEsVersion";
+        public static final String PARTITIONS = "partitions";
 
         private HashMap<String, String> mInfoMap;
 
@@ -861,6 +862,15 @@
         public String getOpenGlEsVersion() {
             return mInfoMap.get(OPEN_GL_ES_VERSION);
         }
+
+        /**
+         * Get partitions.
+         *
+         * @return partitions or error message.
+         */
+        public String getPartitions() {
+            return mInfoMap.get(PARTITIONS);
+        }
     }
 
     /**
diff --git a/tools/host/src/com/android/cts/TestSessionLog.java b/tools/host/src/com/android/cts/TestSessionLog.java
index cc59a3e..0b53076 100644
--- a/tools/host/src/com/android/cts/TestSessionLog.java
+++ b/tools/host/src/com/android/cts/TestSessionLog.java
@@ -46,7 +46,7 @@
     private static final String ATTRIBUTE_KNOWN_FAILURE = "KnownFailure";
 
     public static final String CTS_RESULT_FILE_NAME = "testResult.xml";
-    private static final String CTS_RESULT_FILE_VERSION = "1.10";
+    private static final String CTS_RESULT_FILE_VERSION = "1.11";
 
     static final String ATTRIBUTE_STARTTIME = "starttime";
     static final String ATTRIBUTE_ENDTIME = "endtime";
@@ -73,6 +73,7 @@
     static final String ATTRIBUTE_TYPE = "type";
     static final String ATTRIBUTE_UID = "uid";
     static final String ATTRIBUTE_OPEN_GL_ES_VERSION = "openGlEsVersion";
+    static final String ATTRIBUTE_PARTITIONS = "partitions";
 
     static final String ATTRIBUTE_PASS = "pass";
     static final String ATTRIBUTE_FAILED = "failed";
@@ -327,6 +328,8 @@
                 setAttribute(doc, devInfoNode, ATTRIBUTE_IMSI, bldInfo.getIMSI());
                 setAttribute(doc, devInfoNode, ATTRIBUTE_OPEN_GL_ES_VERSION,
                         bldInfo.getOpenGlEsVersion());
+                setAttribute(doc, devInfoNode, ATTRIBUTE_PARTITIONS,
+                        bldInfo.getPartitions());
 
                 setAttribute(doc, devInfoNode,
                         DeviceParameterCollector.BUILD_FINGERPRINT, bldInfo.getBuildFingerPrint());
diff --git a/tools/host/src/res/cts_result.xsd b/tools/host/src/res/cts_result.xsd
index 51bad35..ad8205c 100644
--- a/tools/host/src/res/cts_result.xsd
+++ b/tools/host/src/res/cts_result.xsd
@@ -74,6 +74,7 @@
         <xs:attribute name="network" type="xs:string"/>
         <xs:attribute name="touch" type="xs:string"/>
         <xs:attribute name="openGlEsVersion" type="xs:string"/>
+        <xs:attribute name="partitions" type="xs:string"/>
         <xs:attribute name="build_abi" type="xs:string"/>
         <xs:attribute name="build_abi2" type="xs:string"/>
       </xs:complexType>
diff --git a/tools/host/src/res/cts_result.xsl b/tools/host/src/res/cts_result.xsl
index 4317655..b6c9acc 100644
--- a/tools/host/src/res/cts_result.xsl
+++ b/tools/host/src/res/cts_result.xsl
@@ -252,6 +252,19 @@
                                                 </UL>
                                             </TD>
                                         </TR>
+                                        <TR>
+                                            <TD class="rowtitle">Partitions</TD>
+                                            <TD>
+                                                <UL>
+                                                    <pre>
+                                                        <xsl:call-template name="formatDelimitedString">
+                                                            <xsl:with-param name="string" select="TestResult/DeviceInfo/BuildInfo/@partitions" />
+                                                            <xsl:with-param name="numTokensPerRow" select="1" />
+                                                        </xsl:call-template>
+                                                    </pre>
+                                                </UL>
+                                            </TD>
+                                        </TR>
                                     </TABLE>
                                 </div>
                             </TD>