[RESTRICT AUTOMERGE] CTS test for Android Security b/65540999

Bug: 65540999
Bug: 68653380
Test: Ran the new testcase on android-8.0.0_r2 (version without patch) and
      on android-8.0.0_r30 (version with patch)

Merged-in: Ia89daca5737f23768f96be9af5dd50d53cf20379
Change-Id: Ia89daca5737f23768f96be9af5dd50d53cf20379
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
index 9321116..f85bb38 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/TestMedia.java
@@ -24,7 +24,9 @@
 import org.junit.runner.RunWith;
 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
 
+import org.junit.Assert;
 import static org.junit.Assert.*;
+import java.util.regex.Pattern;
 
 @RunWith(DeviceJUnit4ClassRunner.class)
 public class TestMedia extends SecurityTestCase {
@@ -49,6 +51,30 @@
      ******************************************************************************/
 
     /**
+     * b/65540999
+     * Vulnerability Behaviour: Assert failure
+     **/
+    @SecurityTest(minPatchLevel = "2017-11")
+    public void testPocCVE_2017_0847() throws Exception {
+        String cmdOut = AdbUtils.runCommandLine("ps -eo cmd,gid | grep mediametrics", getDevice());
+        if (cmdOut.length() > 0) {
+            String[] segment = cmdOut.split("\\s+");
+            if (segment.length > 1) {
+                int gid = -1;
+                if ((segment[1]).length() < Integer.toString(Integer.MAX_VALUE).length()) {
+                    try {
+                        gid = Integer.parseInt(segment[1]);
+                    } catch (NumberFormatException e) {
+                    }
+                }
+                if (gid == 0) {
+                    Assert.fail("mediametrics has root group id");
+                }
+            }
+        }
+    }
+
+    /**
      * b/32096780
      * Vulnerability Behaviour: SIGSEGV in self
      **/