Merge "CTS: Fixes for android.hardware.cts.CameraTest#testPreviewFpsRangeByCamera" into gingerbread
diff --git a/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java b/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
index cb420a6..624f35a 100644
--- a/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
+++ b/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
@@ -43,9 +43,11 @@
         double density = 160.0d * metrics.density;
         assertTrue("Screen density must be at least 100 dpi: " + density, density >= 100.0d);
 
-        double aspectRatio = (double) Math.max(metrics.widthPixels, metrics.heightPixels)
-                / (double) Math.min(metrics.widthPixels, metrics.heightPixels);
-        assertTrue("Aspect ratio must be between 1.333 (4:3) and 1.779 (16:9): " + aspectRatio,
-                aspectRatio >= 1.333d && aspectRatio <= 1.779d);
+        int max = Math.max(metrics.widthPixels, metrics.heightPixels);
+        int min = Math.min(metrics.widthPixels, metrics.heightPixels);
+        boolean format16x9 = Math.floor(max * 9.0d / 16.0d) <= min;
+        boolean format4x3 = Math.ceil(max * 3.0d / 4.0d) >= min;
+        assertTrue("Aspect ratio must be between 4:3 and 16:9. It was " + max + ":" + min,
+                format4x3 && format16x9);
     }
 }
diff --git a/tests/tests/permission/src/android/permission/cts/NoExecutePermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoExecutePermissionTest.java
new file mode 100644
index 0000000..5c0a4c3
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/NoExecutePermissionTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.permission.cts;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.Scanner;
+
+import junit.framework.TestCase;
+
+/**
+ * {@link TestCase} that checks that the NX (No Execute) feature is enabled. This feature makes it
+ * harder to perform attacks against Android by marking certain data blocks as non-executable.
+ */
+public class NoExecutePermissionTest extends TestCase {
+
+    public void testNoExecutePermission() throws FileNotFoundException {
+        String heapPermissions = null;
+        String stackPermissions = null;
+
+        Scanner scanner = null;
+        try {
+            scanner = new Scanner(new File("/proc/self/maps"));
+            while (scanner.hasNextLine()) {
+                String line = scanner.nextLine().trim();
+                String[] fields = line.split("\\s+");
+
+                // Sample line:
+                // 0001d000-00024000 rw-p 00000000 00:00 0          [heap]
+                if (fields != null && fields.length >= 1) {
+                    String permissions = fields[1];
+                    if (fields.length >= 6) {
+                        String tag = fields[5];
+                        if ("[heap]".equals(tag)) {
+                            heapPermissions = permissions;
+                        } else if ("[stack]".equals(tag)) {
+                            stackPermissions = permissions;
+                        }
+                    }
+                }
+            }
+        } finally {
+            if (scanner != null) {
+                scanner.close();
+            }
+        }
+
+        assertEquals("NX (No Execute) not enabled for heap", "rw-p", heapPermissions);
+        assertEquals("NX (No Execute) not enabled for stack", "rw-p", stackPermissions);
+    }
+}
diff --git a/tests/tests/provider/src/android/provider/cts/Settings_SecureTest.java b/tests/tests/provider/src/android/provider/cts/Settings_SecureTest.java
index 6ce4157..c325abf 100644
--- a/tests/tests/provider/src/android/provider/cts/Settings_SecureTest.java
+++ b/tests/tests/provider/src/android/provider/cts/Settings_SecureTest.java
@@ -23,6 +23,7 @@
 
 import android.content.ContentResolver;
 import android.net.Uri;
+import android.provider.Settings;
 import android.provider.Settings.Secure;
 import android.provider.Settings.SettingNotFoundException;
 import android.test.AndroidTestCase;
@@ -178,4 +179,9 @@
         assertNotNull(uri);
         assertEquals(Uri.withAppendedPath(Secure.CONTENT_URI, name), uri);
     }
+
+    public void testUnknownSourcesOffByDefault() throws SettingNotFoundException {
+        assertEquals("Device should not ship with 'Unknown Sources' enabled by default.",
+                0, Secure.getInt(cr, Settings.Secure.INSTALL_NON_MARKET_APPS));
+    }
 }
diff --git a/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java b/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java
old mode 100644
new mode 100755
index 1f8cd23..172d8a9
--- a/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java
+++ b/tests/tests/widget/src/android/widget/cts/FrameLayoutTest.java
@@ -379,8 +379,8 @@
         int topDelta = rect.top - container.getTop();
         int bottomDelta = container.getBottom() - rect.bottom;
 
-        assertTrue(Math.abs(leftDelta - rightDelta) < 1);
-        assertTrue(Math.abs(topDelta - bottomDelta) < 1);
+        assertTrue(Math.abs(leftDelta - rightDelta) <= 1);
+        assertTrue(Math.abs(topDelta - bottomDelta) <= 1);
     }
 
     private AttributeSet getAttributeSet() throws XmlPullParserException, IOException {
diff --git a/tests/tests/widget/src/android/widget/cts/ScrollViewTest.java b/tests/tests/widget/src/android/widget/cts/ScrollViewTest.java
index b852e5b..cff8142 100644
--- a/tests/tests/widget/src/android/widget/cts/ScrollViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ScrollViewTest.java
@@ -78,10 +78,10 @@
 
         // calculate pixel positions from dpi constants.
         final float density = getActivity().getResources().getDisplayMetrics().density;
-        mItemWidth = (int) (ITEM_WIDTH_DPI * density);
-        mItemHeight = (int) (ITEM_HEIGHT_DPI * density);
-        mPageWidth = (int) (PAGE_WIDTH_DPI * density);
-        mPageHeight = (int) (PAGE_HEIGHT_DPI * density);
+        mItemWidth = (int) (ITEM_WIDTH_DPI * density + 0.5f);
+        mItemHeight = (int) (ITEM_HEIGHT_DPI * density + 0.5f);
+        mPageWidth = (int) (PAGE_WIDTH_DPI * density + 0.5f);
+        mPageHeight = (int) (PAGE_HEIGHT_DPI * density + 0.5f);
 
         mScrollBottom = mItemHeight * ITEM_COUNT - mPageHeight;
         mScrollRight = mItemWidth - mPageWidth;
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>