am 39a09e32: Merge "Add OpenGL compressed texture format list to the test result. - For device supporting ES 2.0, 2.0 API is used, but for 1.1 only device,       1.1 API is used. - re-organized XML parsing / writing in host side to re-use the same code. - update versi

* commit '39a09e325849ddd69416ddf91cf4f29760e1e4a1':
  Add OpenGL compressed texture format list to the test result. - For device supporting ES 2.0, 2.0 API is used, but for 1.1 only device,       1.1 API is used. - re-organized XML parsing / writing in host side to re-use the same code. - update version to 1.13
diff --git a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java
index bcba1cb..3614e22 100644
--- a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java
+++ b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java
@@ -17,31 +17,33 @@
 package android.tests.getinfo;
 
 import android.app.Activity;
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.pm.ConfigurationInfo;
 import android.content.res.Configuration;
 import android.os.Bundle;
-import android.widget.TextView;
 
 import java.util.Locale;
+import java.util.concurrent.CountDownLatch;
 
 
 /**
  * Collect device information on target device.
  */
 public class DeviceInfoActivity extends Activity {
-    private boolean isActivityFinished = false;
-    private Object sync = new Object();
+
+    // work done should be reported in GLES..View
+    private CountDownLatch mDone = new CountDownLatch(1);
+    private GLESSurfaceView mGLView;
 
     /**
      * Other classes can call this function to wait for this activity
      * to finish. */
     public void waitForAcitityToFinish() {
-        synchronized (sync) {
-            while (!isActivityFinished) {
-                try {
-                    sync.wait();
-                } catch (InterruptedException e) {
-                }
-            }
+        try {
+            mDone.await();
+        } catch (InterruptedException e) {
+            // just move on
         }
     }
 
@@ -49,9 +51,14 @@
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        TextView view = new TextView(this);
-        view.setText("hello");
-        setContentView(view);
+        ActivityManager am =
+                (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
+        ConfigurationInfo info = am.getDeviceConfigurationInfo();
+        boolean useGL20 = (info.reqGlEsVersion >= 0x20000);
+
+        mGLView = new GLESSurfaceView(this, useGL20, mDone);
+        setContentView(mGLView);
+
         Configuration con = getResources().getConfiguration();
         String touchScreen = null;
         if (con.touchscreen == Configuration.TOUCHSCREEN_UNDEFINED) {
@@ -112,10 +119,5 @@
         }
         DeviceInfoInstrument.addResult(DeviceInfoConstants.LOCALES,
                 localeList.toString());
-
-        synchronized (sync) {
-            sync.notify();
-            isActivityFinished = true;
-        }
     }
 }
diff --git a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoConstants.java b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoConstants.java
index 63cbce8..dd9681a 100644
--- a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoConstants.java
+++ b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoConstants.java
@@ -23,6 +23,8 @@
  */
 public interface DeviceInfoConstants {
 
+    public static final String OPEN_GL_COMPRESSED_TEXTURE_FORMATS =
+            "openGlCompressedTextureFormats";
     public static final String SYS_LIBRARIES = "systemlibraries";
     public static final String PARTITIONS = "partitions";
     public static final String OPEN_GL_ES_VERSION = "openGlEsVersion";
diff --git a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/GLESSurfaceView.java b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/GLESSurfaceView.java
new file mode 100644
index 0000000..0ec11b7
--- /dev/null
+++ b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/GLESSurfaceView.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.tests.getinfo;
+
+import android.content.Context;
+import android.opengl.GLES20;
+import android.opengl.GLSurfaceView;
+import android.util.Log;
+
+import java.util.Scanner;
+import java.util.concurrent.CountDownLatch;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+class GLESSurfaceView extends GLSurfaceView {
+    private static final String TAG = "GLESSurfaceView";
+
+    private boolean mUseGL20;
+    CountDownLatch mDone;
+
+    /**
+     *
+     * @param context
+     * @param useGL20 whether to use GLES2.0 API or not inside the view
+     * @param done to notify the completion of the task
+     */
+    public GLESSurfaceView(Context context, boolean useGL20, CountDownLatch done){
+        super(context);
+
+        mUseGL20 = useGL20;
+        mDone = done;
+        if (mUseGL20) {
+            setEGLContextClientVersion(2);
+        }
+        setRenderer(new OpenGLESRenderer());
+    }
+
+    public class OpenGLESRenderer implements GLSurfaceView.Renderer {
+
+        @Override
+        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+            String extensions;
+            if (mUseGL20) {
+                extensions = GLES20.glGetString(GLES20.GL_EXTENSIONS);
+            } else {
+                extensions = gl.glGetString(GL10.GL_EXTENSIONS);
+            }
+            Log.i(TAG, "extensions : " + extensions);
+            Scanner scanner = new Scanner(extensions);
+            scanner.useDelimiter(" ");
+            StringBuilder builder = new StringBuilder();
+            while (scanner.hasNext()) {
+                String ext = scanner.next();
+                if (ext.contains("texture")) {
+                    if (ext.contains("compression") || ext.contains("compressed")) {
+                        Log.i(TAG, "Compression supported: " + ext);
+                        builder.append(ext);
+                        builder.append(";");
+                    }
+                }
+            }
+
+            DeviceInfoInstrument.addResult(
+                    DeviceInfoConstants.OPEN_GL_COMPRESSED_TEXTURE_FORMATS,
+                    builder.toString());
+
+            mDone.countDown();
+        }
+
+        @Override
+        public void onSurfaceChanged(GL10 gl, int width, int height) {
+
+        }
+
+        @Override
+        public void onDrawFrame(GL10 gl) {
+
+        }
+
+    }
+}
\ No newline at end of file
diff --git a/tools/tradefed-host/res/report/cts_result.xsd b/tools/tradefed-host/res/report/cts_result.xsd
index 2a40943..5e471d5 100644
--- a/tools/tradefed-host/res/report/cts_result.xsd
+++ b/tools/tradefed-host/res/report/cts_result.xsd
@@ -16,8 +16,8 @@
  -->
 
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
-           targetNamespace="http://compatibility.android.com/cts_result/1.10"
-           xmlns="http://compatibility.android.com/cts_result/1.10"
+           targetNamespace="http://compatibility.android.com/cts_result/1.13"
+           xmlns="http://compatibility.android.com/cts_result/1.13"
            elementFormDefault="qualified">
 
 <xs:element name="TestResult">
@@ -82,6 +82,7 @@
     <xs:element name="FeatureInfo" type="featureInfoType"/>
     <xs:element name="ProcessInfo" type="processInfoType"/>
     <xs:element name="SystemLibrariesInfo" type="systemLibrariesInfoType"/>
+    <xs:element name="OpenGLCompressedTextureFormatsInfo" type="openGLCompressedTextureFormatsInfoType"/>
   </xs:sequence>
 </xs:complexType>
 
@@ -150,6 +151,16 @@
     </xs:sequence>
 </xs:complexType>
 
+<xs:complexType name="openGLCompressedTextureFormatsInfoType">
+    <xs:sequence>
+        <xs:element name="TextureFormat" minOccurs="0" maxOccurs="unbounded">
+            <xs:complexType>
+                <xs:attribute name="name" type="xs:string" />
+            </xs:complexType>
+        </xs:element>
+    </xs:sequence>
+</xs:complexType>
+
 <xs:complexType name="summaryType">
   <xs:attribute name="failed" type="xs:integer"/>
   <xs:attribute name="notExecuted" type="xs:integer"/>
diff --git a/tools/tradefed-host/res/report/cts_result.xsl b/tools/tradefed-host/res/report/cts_result.xsl
index ae6f450..6fe7cec 100644
--- a/tools/tradefed-host/res/report/cts_result.xsl
+++ b/tools/tradefed-host/res/report/cts_result.xsl
@@ -213,6 +213,16 @@
                                             </TD>
                                         </TR>
                                         <TR>
+                                            <TD class="rowtitle">Open GL Compressed Texture Formats</TD>
+                                            <TD>
+                                                <UL>
+                                                    <xsl:for-each select="TestResult/DeviceInfo/OpenGLCompressedTextureFormatsInfo/TextureFormat">
+                                                        <LI><xsl:value-of select="@name" /></LI>
+                                                    </xsl:for-each>
+                                                </UL>
+                                            </TD>
+                                        </TR>
+                                        <TR>
                                             <TD class="rowtitle">Features</TD>
                                             <TD>
                                                 <xsl:for-each select="TestResult/DeviceInfo/FeatureInfo/Feature[@type='sdk']">
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java b/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
index a5519e6..855c209 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
@@ -56,7 +56,7 @@
     private static final String LOG_TAG = "CtsXmlResultReporter";
 
     static final String TEST_RESULT_FILE_NAME = "testResult.xml";
-    private static final String CTS_RESULT_FILE_VERSION = "1.12";
+    private static final String CTS_RESULT_FILE_VERSION = "1.13";
     private static final String[] CTS_RESULT_RESOURCES = {"cts_result.xsl", "cts_result.css",
         "logo.gif", "newrule-green.png"};
 
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/result/DeviceInfoResult.java b/tools/tradefed-host/src/com/android/cts/tradefed/result/DeviceInfoResult.java
index 28f818a..d5f4530 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/result/DeviceInfoResult.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/result/DeviceInfoResult.java
@@ -46,6 +46,10 @@
     private static final String FEATURE_TAG = "Feature";
     private static final String FEATURE_ATTR_DELIM = ":";
     private static final String FEATURE_DELIM = ";";
+    private static final String OPENGL_TEXTURE_FORMATS_INFO_TAG =
+            "OpenGLCompressedTextureFormatsInfo";
+    private static final String OPENGL_TEXTURE_FORMAT_TAG = "TextureFormat";
+    private static final String OPENGL_TEXTURE_FORMAT_DELIM = ";";
     private static final String SYSLIB_INFO_TAG = "SystemLibrariesInfo";
     private static final String SYSLIB_TAG = "Library";
     private static final String SYSLIB_DELIM = ";";
@@ -87,6 +91,8 @@
             String featureData = getMetric(metricsCopy, DeviceInfoConstants.FEATURES);
             String processData = getMetric(metricsCopy, DeviceInfoConstants.PROCESSES);
             String sysLibData = getMetric(metricsCopy, DeviceInfoConstants.SYS_LIBRARIES);
+            String textureData = getMetric(metricsCopy,
+                    DeviceInfoConstants.OPEN_GL_COMPRESSED_TEXTURE_FORMATS);
 
             // dump the remaining metrics without translation
             serializer.startTag(ns, BUILD_TAG);
@@ -98,6 +104,7 @@
             serializeFeatureInfo(serializer, featureData);
             serializeProcessInfo(serializer, processData);
             serializeSystemLibrariesInfo(serializer, sysLibData);
+            serializeOpenGLCompressedTextureFormatsInfo(serializer, textureData);
         } else {
             // this might be expected, if device info collection was turned off
             CLog.d("Could not find device info");
@@ -188,6 +195,55 @@
         serializer.endTag(ns, PROCESS_INFO_TAG);
     }
 
+    /**
+     * Prints XML data in two level hierarchy.
+     * It parses a string from the root argument that is in the form of
+     * "element1-delimiter-element2-delimiter..." with a trailing delimiter
+     *
+     * <pre>
+     *   <infoTag>
+     *     <elementTag name="element1" />
+     *     ...
+     *   </infoTag>
+     * </pre>
+     */
+    private void serializeSimpleInfo(KXmlSerializer serializer, String root,
+            String infoTag, String elementTag, String delimiter)
+            throws IOException {
+        serializer.startTag(ns, infoTag);
+
+        if (root == null) {
+            root = "";
+        }
+
+        String[] elemNames = root.split(delimiter);
+        for (String elemName : elemNames) {
+            elemName = elemName.trim();
+            if (elemName.length() > 0) {
+                serializer.startTag(ns, elementTag);
+                serializer.attribute(ns, "name", elemName);
+                serializer.endTag(ns, elementTag);
+            }
+        }
+        serializer.endTag(ns, infoTag);
+    }
+
+    /**
+     * Prints XML data listing available OpenGL Compressed Texture Formats.
+     *
+     * <pre>
+     *   <OpenGLCompressedTextureFormatsInfo>
+     *     <TextureFormat name="abc" />
+     *     ...
+     *   </OpenGLCompressedTextureFormatsInfo>
+     * </pre>
+     */
+    private void serializeOpenGLCompressedTextureFormatsInfo(KXmlSerializer serializer,
+            String root) throws IOException {
+        serializeSimpleInfo(serializer, root, OPENGL_TEXTURE_FORMATS_INFO_TAG,
+                OPENGL_TEXTURE_FORMAT_TAG,
+                OPENGL_TEXTURE_FORMAT_DELIM);
+    }
 
     /**
      * Prints XML data listing available system libraries.
@@ -203,22 +259,7 @@
      */
     private void serializeSystemLibrariesInfo(KXmlSerializer serializer, String rootLibraries)
             throws IOException {
-        serializer.startTag(ns, SYSLIB_INFO_TAG);
-
-        if (rootLibraries == null) {
-            rootLibraries = "";
-        }
-
-        String[] libNames = rootLibraries.split(SYSLIB_DELIM);
-        for (String libName : libNames) {
-            libName = libName.trim();
-            if (libName.length() > 0) {
-                serializer.startTag(ns, SYSLIB_TAG);
-                serializer.attribute(ns, "name", libName);
-                serializer.endTag(ns, SYSLIB_TAG);
-            }
-        }
-        serializer.endTag(ns, SYSLIB_INFO_TAG);
+        serializeSimpleInfo(serializer, rootLibraries, SYSLIB_INFO_TAG, SYSLIB_TAG, SYSLIB_DELIM);
     }
 
     /**
@@ -252,6 +293,11 @@
                     // store system libs into metrics map, in the same format as when collected from
                     // device
                     mMetrics.put(DeviceInfoConstants.SYS_LIBRARIES, parseSystemLibraries(parser));
+                } else if (parser.getName().equals(OPENGL_TEXTURE_FORMATS_INFO_TAG)) {
+                    // store OpenGL texture formats into metrics map, in the same format as when
+                    // collected from device
+                    mMetrics.put(DeviceInfoConstants.OPEN_GL_COMPRESSED_TEXTURE_FORMATS,
+                            parseOpenGLCompressedTextureFormats(parser));
                 }
             } else if (eventType == XmlPullParser.END_TAG && parser.getName().equals(TAG)) {
                 return;
@@ -313,29 +359,46 @@
 
     }
 
+    /**
+     * Parse two-level hierarchy XML, and return its contents as a delimited String
+     */
+    private String parseSimpleInfo(XmlPullParser parser, String infoTag, String elementTag,
+            String delimiter) throws XmlPullParserException, IOException {
+        if (!parser.getName().equals(infoTag)) {
+            throw new XmlPullParserException(String.format(
+                    "invalid XML: Expected %s tag but received %s", infoTag,
+                    parser.getName()));
+        }
+        StringBuilder result = new StringBuilder();
+        int eventType = parser.getEventType();
+        while (eventType != XmlPullParser.END_DOCUMENT) {
+            if (eventType == XmlPullParser.START_TAG && parser.getName().equals(elementTag)) {
+                result.append(getAttribute(parser, "name"));
+                result.append(delimiter);
+            } else if (eventType == XmlPullParser.END_TAG && parser.getName().equals(
+                    infoTag)) {
+                return result.toString();
+            }
+            eventType = parser.next();
+        }
+        return result.toString();
+    }
 
     /**
      * Parse JavaLibrariesInfo XML, and return its contents as a delimited String
      */
-    private String parseSystemLibraries(XmlPullParser parser) throws XmlPullParserException, IOException {
-        if (!parser.getName().equals(SYSLIB_INFO_TAG)) {
-            throw new XmlPullParserException(String.format(
-                    "invalid XML: Expected %s tag but received %s", SYSLIB_INFO_TAG,
-                    parser.getName()));
-        }
-        StringBuilder libsString = new StringBuilder();
-        int eventType = parser.getEventType();
-        while (eventType != XmlPullParser.END_DOCUMENT) {
-            if (eventType == XmlPullParser.START_TAG && parser.getName().equals(SYSLIB_TAG)) {
-                libsString.append(getAttribute(parser, "name"));
-                libsString.append(SYSLIB_DELIM);
-            } else if (eventType == XmlPullParser.END_TAG && parser.getName().equals(
-                    SYSLIB_INFO_TAG)) {
-                return libsString.toString();
-            }
-            eventType = parser.next();
-        }
-        return libsString.toString();
+    private String parseOpenGLCompressedTextureFormats(XmlPullParser parser)
+            throws XmlPullParserException, IOException {
+        return parseSimpleInfo(parser, OPENGL_TEXTURE_FORMATS_INFO_TAG, OPENGL_TEXTURE_FORMAT_TAG,
+                OPENGL_TEXTURE_FORMAT_DELIM);
+    }
+
+    /**
+     * Parse JavaLibrariesInfo XML, and return its contents as a delimited String
+     */
+    private String parseSystemLibraries(XmlPullParser parser)
+            throws XmlPullParserException, IOException {
+        return parseSimpleInfo(parser, SYSLIB_INFO_TAG, SYSLIB_TAG, SYSLIB_DELIM);
     }
 
     /**
diff --git a/tools/tradefed-host/tests/src/com/android/cts/tradefed/result/CtsXmlResultReporterTest.java b/tools/tradefed-host/tests/src/com/android/cts/tradefed/result/CtsXmlResultReporterTest.java
index 4162c65..94b7344 100644
--- a/tools/tradefed-host/tests/src/com/android/cts/tradefed/result/CtsXmlResultReporterTest.java
+++ b/tools/tradefed-host/tests/src/com/android/cts/tradefed/result/CtsXmlResultReporterTest.java
@@ -83,7 +83,7 @@
         final String expectedHeaderOutput = "<?xml version='1.0' encoding='UTF-8' standalone='no' ?>" +
             "<?xml-stylesheet type=\"text/xsl\" href=\"cts_result.xsl\"?>";
         final String expectedTestOutput =
-            "<TestResult testPlan=\"NA\" starttime=\"ignore\" endtime=\"ignore\" version=\"1.12\"> ";
+            "<TestResult testPlan=\"NA\" starttime=\"ignore\" endtime=\"ignore\" version=\"1.13\"> ";
         final String expectedSummaryOutput =
             "<Summary failed=\"0\" notExecuted=\"0\" timeout=\"0\" pass=\"0\" />";
         final String expectedEndTag = "</TestResult>";