Add file permission tests for broadcom nfc drivers.

	modified:   tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java

(cherry picked from commit 5382de6c96ecf9a9f342da72a8598681bc79c8f0)

Change-Id: I6db82eaaad6df32b7384279abf55e8e98610950f
diff --git a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
index 3dd1652..4712257 100644
--- a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
@@ -166,11 +166,69 @@
         assertFalse(f.canWrite());
         assertFalse(f.canExecute());
 
+        assertFileOwnedBy(f, "nfc");
+        assertFileOwnedByGroup(f, "nfc");
+    }
+
+    @MediumTest
+    public void testBcm2079xSane() throws Exception {
+        File f = new File("/dev/bcm2079x");
+        assertFalse(f.canRead());
+        assertFalse(f.canWrite());
+        assertFalse(f.canExecute());
+
+        assertFileOwnedBy(f, "nfc");
+        assertFileOwnedByGroup(f, "nfc");
+    }
+
+    @MediumTest
+    public void testBcm2079xi2cSane() throws Exception {
+        File f = new File("/dev/bcm2079x-i2c");
+        assertFalse(f.canRead());
+        assertFalse(f.canWrite());
+        assertFalse(f.canExecute());
+
+        assertFileOwnedBy(f, "nfc");
+        assertFileOwnedByGroup(f, "nfc");
+    }
+
+    /**
+     * Assert that a file is owned by a specific owner. This is a noop if the
+     * file does not exist.
+     *
+     * @param file The file to check.
+     * @param expectedOwner The owner of the file.
+     */
+    private static void assertFileOwnedBy(File file, String expectedOwner) {
         FileUtils.FileStatus status = new FileUtils.FileStatus();
-        if (f.exists()
-                && FileUtils.getFileStatus(f.getAbsolutePath(), status, true)) {
-            assertEquals("nfc", FileUtils.getUserName(status.uid));
-            assertEquals("nfc", FileUtils.getGroupName(status.gid));
+        String path = file.getAbsolutePath();
+        if (file.exists() && FileUtils.getFileStatus(path, status, true)) {
+            String actualOwner = FileUtils.getUserName(status.uid);
+            if (!expectedOwner.equals(actualOwner)) {
+                String msg = String.format("Wrong owner. Expected '%s', but found '%s' for %s.",
+                        expectedOwner, actualOwner, path);
+                fail(msg);
+            }
+        }
+    }
+
+    /**
+     * Assert that a file is owned by a specific group. This is a noop if the
+     * file does not exist.
+     *
+     * @param file The file to check.
+     * @param expectedGroup The owner group of the file.
+     */
+    private static void assertFileOwnedByGroup(File file, String expectedGroup) {
+        FileUtils.FileStatus status = new FileUtils.FileStatus();
+        String path = file.getAbsolutePath();
+        if (file.exists() && FileUtils.getFileStatus(path, status, true)) {
+            String actualGroup = FileUtils.getGroupName(status.gid);
+            if (!expectedGroup.equals(actualGroup)) {
+                String msg = String.format("Wrong group. Expected '%s', but found '%s' for %s.",
+                        expectedGroup, actualGroup, path);
+                fail(msg);
+            }
         }
     }