Merge "Snap for 5918762 from 1111e06ee795b78c4edc79051a52a34aa97b1cd6 to oreo-mr1-cts-release" into oreo-mr1-cts-release
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 9d06f6e..a06db9e 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -18,7 +18,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.android.cts.verifier"
       android:versionCode="5"
-      android:versionName="8.1_r16">
+      android:versionName="8.1_r17">
 
     <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27"/>
 
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/RingerModeActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/RingerModeActivity.java
index 7c807c2..b4bfa01 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/RingerModeActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/RingerModeActivity.java
@@ -136,7 +136,8 @@
 
     private boolean supportsConditionProviders() {
         ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
-        return !am.isLowRamDevice();
+        return !am.isLowRamDevice()
+                || mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);
     }
 
     private int getVolumeDelta(int volume) {
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/CrashReporter.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/CrashReporter.java
index c564067..f17498d 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/CrashReporter.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/CrashReporter.java
@@ -120,15 +120,16 @@
 
         private void processLogLine(String line) {
             mLogcatChunk.append(line);
+            mLogcatChunk.append('\n');
             Matcher m;
-            if ((m = CrashUtils.sNewTestPattern.matcher(line)).matches()) {
+            if ((m = CrashUtils.sNewTestPattern.matcher(line)).find()) {
                 mTestName = m.group(1);
                 mCrashes = new JSONArray();
                 mLogcatChunk.setLength(0);
-            } else if (CrashUtils.sEndofCrashPattern.matcher(line).matches()) {
+            } else if (CrashUtils.sEndofCrashPattern.matcher(line).find()) {
                 CrashUtils.addAllCrashes(mLogcatChunk.toString(), mCrashes);
                 mLogcatChunk.setLength(0);
-            } else if (CrashUtils.sUploadRequestPattern.matcher(line).matches()) {
+            } else if (CrashUtils.sUploadRequestPattern.matcher(line).find()) {
                 upload(mDevice, mTestName, mCrashes);
             }
         }
diff --git a/common/util/src/com/android/compatibility/common/util/CrashUtils.java b/common/util/src/com/android/compatibility/common/util/CrashUtils.java
index e058df4..2b0531c 100644
--- a/common/util/src/com/android/compatibility/common/util/CrashUtils.java
+++ b/common/util/src/com/android/compatibility/common/util/CrashUtils.java
@@ -16,89 +16,133 @@
 
 package com.android.compatibility.common.util;
 
+import java.io.File;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
+import java.math.BigInteger;
 
 /** Contains helper functions and shared constants for crash parsing. */
 public class CrashUtils {
+    // used to only detect actual addresses instead of nullptr and other unlikely values
+    public static final BigInteger MIN_CRASH_ADDR = new BigInteger("8000", 16);
 
-    public static final long MIN_CRASH_ADDR = 32768;
     // Matches the end of a crash
     public static final Pattern sEndofCrashPattern =
-            Pattern.compile(".*DEBUG\\s+:\\s+backtrace:.*");
+            Pattern.compile("DEBUG\\s+?:\\s+?backtrace:");
     public static final String DEVICE_PATH = "/data/local/tmp/CrashParserResults/";
     public static final String LOCK_FILENAME = "lockFile.loc";
     public static final String UPLOAD_REQUEST = "Please upload a result file to stagefright";
     public static final Pattern sUploadRequestPattern =
-            Pattern.compile(".*" + UPLOAD_REQUEST + ".*");
+            Pattern.compile(UPLOAD_REQUEST);
     public static final String NEW_TEST_ALERT = "New test starting with name: ";
     public static final Pattern sNewTestPattern =
-            Pattern.compile(".*" + NEW_TEST_ALERT + "(\\w+)\\(.*\\).*");
-    public static final String SIGNAL = "signal",
-            NAME = "name",
-            PID = "pid",
-            TID = "tid",
-            FAULT_ADDRESS = "faultaddress";
+            Pattern.compile(NEW_TEST_ALERT + "(\\w+?)\\(.*?\\)");
+    public static final String SIGNAL = "signal";
+    public static final String NAME = "name";
+    public static final String PROCESS = "process";
+    public static final String PID = "pid";
+    public static final String TID = "tid";
+    public static final String FAULT_ADDRESS = "faultaddress";
     // Matches the smallest blob that has the appropriate header and footer
     private static final Pattern sCrashBlobPattern =
-            Pattern.compile("DEBUG\\s+:( [*]{3})+.*?DEBUG\\s+:\\s+backtrace:", Pattern.DOTALL);
+            Pattern.compile("DEBUG\\s+?:( [*]{3})+?.*?DEBUG\\s+?:\\s+?backtrace:", Pattern.DOTALL);
     // Matches process id and name line and captures them
     private static final Pattern sPidtidNamePattern =
-            Pattern.compile("pid: (\\d+), tid: (\\d+), name: ([^\\s]+\\s+)*>>> (.*) <<<");
+            Pattern.compile("pid: (\\d+?), tid: (\\d+?), name: ([^\\s]+?\\s+?)*?>>> (.*?) <<<");
     // Matches fault address and signal type line
     private static final Pattern sFaultLinePattern =
             Pattern.compile(
-                    "\\w+ \\d+ \\((.*)\\), code -*\\d+ \\(.*\\), fault addr "
+                    "\\w+? \\d+? \\((.*?)\\), code -*?\\d+? \\(.*?\\), fault addr "
                             + "(?:0x(\\p{XDigit}+)|-+)");
     // Matches the abort message line if it contains CHECK_
     private static Pattern sAbortMessageCheckPattern =
-            Pattern.compile("(?i)Abort message.*CHECK_.*");
+            Pattern.compile("(?i)Abort message.*?CHECK_");
+
+    /**
+     * returns true if the signal is a segmentation fault or bus error.
+     */
+    public static boolean isSecuritySignal(JSONObject crash) throws JSONException {
+        return crash.getString(SIGNAL).toLowerCase().matches("sig(segv|bus)");
+    }
+
+    /**
+     * returns the filename of the process.
+     * e.g. "/system/bin/mediaserver" returns "mediaserver"
+     */
+    public static String getProcessFileName(JSONObject crash) throws JSONException {
+        return new File(crash.getString(PROCESS)).getName();
+    }
 
     /**
      * Determines if the given input has a {@link com.android.compatibility.common.util.Crash} that
      * should fail an sts test
      *
-     * @param processNames list of applicable process names
+     * @param processPatterns list of patterns that match applicable process names
      * @param checkMinAddr if the minimum fault address should be respected
      * @param crashes list of crashes to check
      * @return if a crash is serious enough to fail an sts test
      */
-    public static boolean detectCrash(
-            String[] processNames, boolean checkMinAddr, JSONArray crashes) {
+    public static boolean securityCrashDetected(
+            JSONArray crashes, boolean checkMinAddr, Pattern... processPatterns) {
+        return matchSecurityCrashes(crashes, checkMinAddr, processPatterns).length() > 0;
+    }
+
+    public static BigInteger getBigInteger(JSONObject source, String name) throws JSONException {
+        if (source.isNull(name)) {
+            return null;
+        }
+        String intString = source.getString(name);
+        BigInteger value = null;
+        try {
+            value = new BigInteger(intString, 16);
+        } catch (NumberFormatException e) {}
+        return value;
+    }
+
+    /**
+     * Determines which given inputs have a {@link com.android.compatibility.common.util.Crash} that
+     * should fail an sts test
+     *
+     * @param processPatterns list of patterns that match applicable process names
+     * @param checkMinAddr if the minimum fault address should be respected
+     * @param crashes list of crashes to check
+     * @return the list of crashes serious enough to fail an sts test
+     */
+    public static JSONArray matchSecurityCrashes(
+            JSONArray crashes, boolean checkMinAddr, Pattern... processPatterns) {
+        JSONArray securityCrashes = new JSONArray();
         for (int i = 0; i < crashes.length(); i++) {
             try {
                 JSONObject crash = crashes.getJSONObject(i);
-                if (!crash.getString(SIGNAL).toLowerCase().matches("sig(segv|bus)")) {
+                if (!matchesAny(getProcessFileName(crash), processPatterns)) {
                     continue;
                 }
-
-                if (checkMinAddr && !crash.isNull(FAULT_ADDRESS)) {
-                    if (crash.getLong(FAULT_ADDRESS) < MIN_CRASH_ADDR) {
-                        continue;
-                    }
-                }
-
-                boolean foundProcess = false;
-                String name = crash.getString(NAME);
-                for (String process : processNames) {
-                    if (name.equals(process)) {
-                        foundProcess = true;
-                        break;
-                    }
-                }
-
-                if (!foundProcess) {
+                if (!isSecuritySignal(crash)) {
                     continue;
                 }
+                BigInteger faultAddress = getBigInteger(crash, FAULT_ADDRESS);
+                if (checkMinAddr && faultAddress != null
+                        && faultAddress.compareTo(MIN_CRASH_ADDR) < 0) {
+                    continue;
+                }
+                securityCrashes.put(crash);
+            } catch (JSONException | NullPointerException e) {}
+        }
+        return securityCrashes;
+    }
 
-                return true; // crash detected
-            } catch (JSONException | NullPointerException e) {
+    /**
+     * returns true if the input matches any of the patterns.
+     */
+    private static boolean matchesAny(String input, Pattern... patterns) {
+        for (Pattern p : patterns) {
+            if (p.matcher(input).matches()) {
+                return true;
             }
         }
-
         return false;
     }
 
@@ -107,21 +151,23 @@
         Matcher crashBlobFinder = sCrashBlobPattern.matcher(input);
         while (crashBlobFinder.find()) {
             String crashStr = crashBlobFinder.group(0);
-            int tid = 0, pid = 0;
-            Long faultAddress = null;
-            String name = null, signal = null;
+            int tid = 0;
+            int pid = 0;
+            BigInteger faultAddress = null;
+            String name = null;
+            String process = null;
+            String signal = null;
 
             Matcher pidtidNameMatcher = sPidtidNamePattern.matcher(crashStr);
             if (pidtidNameMatcher.find()) {
                 try {
                     pid = Integer.parseInt(pidtidNameMatcher.group(1));
-                } catch (NumberFormatException e) {
-                }
+                } catch (NumberFormatException e) {}
                 try {
                     tid = Integer.parseInt(pidtidNameMatcher.group(2));
-                } catch (NumberFormatException e) {
-                }
+                } catch (NumberFormatException e) {}
                 name = pidtidNameMatcher.group(3).trim();
+                process = pidtidNameMatcher.group(4).trim();
             }
 
             Matcher faultLineMatcher = sFaultLinePattern.matcher(crashStr);
@@ -130,9 +176,8 @@
                 String faultAddrMatch = faultLineMatcher.group(2);
                 if (faultAddrMatch != null) {
                     try {
-                        faultAddress = Long.parseLong(faultAddrMatch, 16);
-                    } catch (NumberFormatException e) {
-                    }
+                        faultAddress = new BigInteger(faultAddrMatch, 16);
+                    } catch (NumberFormatException e) {}
                 }
             }
             if (!sAbortMessageCheckPattern.matcher(crashStr).find()) {
@@ -141,12 +186,12 @@
                     crash.put(PID, pid);
                     crash.put(TID, tid);
                     crash.put(NAME, name);
-                    crash.put(FAULT_ADDRESS, faultAddress);
+                    crash.put(PROCESS, process);
+                    crash.put(FAULT_ADDRESS,
+                            faultAddress == null ? null : faultAddress.toString(16));
                     crash.put(SIGNAL, signal);
                     crashes.put(crash);
-                } catch (JSONException e) {
-
-                }
+                } catch (JSONException e) {}
             }
         }
         return crashes;
diff --git a/common/util/tests/res/logcat.txt b/common/util/tests/res/logcat.txt
index ad778c7..b9d10d0 100644
--- a/common/util/tests/res/logcat.txt
+++ b/common/util/tests/res/logcat.txt
@@ -271,4 +271,66 @@
 11-25 19:47:35.597   940   940 F DEBUG   :     #24 pc 0003fa3b  /system/lib/libc.so (_ZL15__pthread_startPv+30)
 11-25 19:47:35.597   940   940 F DEBUG   :     #25 pc 0001a085  /system/lib/libc.so (__start_thread+6)
 11-25 19:47:35.837   940   940 F DEBUG   :
-11-25 19:47:35.837   940   940 F DEBUG   : Tombstone written to: /data/tombstones/tombstone_01
\ No newline at end of file
+11-25 19:47:35.837   940   940 F DEBUG   : Tombstone written to: /data/tombstones/tombstone_01
+--------- beginning of crash
+09-03 17:48:05.627 11071 11189 F libc    : Fatal signal 11 (SIGSEGV), code 1, fault addr 0xe9380000 in tid 11189 (synthetic_thread)
+09-03 17:48:05.707   359   359 W         : debuggerd: handling request: pid=11071 uid=1041 gid=1005 tid=11189
+09-03 17:48:05.796  7072  7072 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
+09-03 17:48:05.796  7072  7072 F DEBUG   : Build fingerprint: 'google/angler/angler:7.1.1/N4F26T/3687331:userdebug/dev-keys'
+09-03 17:48:05.796  7072  7072 F DEBUG   : Revision: '0'
+09-03 17:48:05.796  7072  7072 F DEBUG   : ABI: 'arm'
+09-03 17:48:05.796  7072  7072 F DEBUG   : pid: 11071, tid: 11189, name: synthetic_thread  >>> synthetic_process_0 <<<
+09-03 17:48:05.797  7072  7072 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xe9380000
+09-03 17:48:05.797  7072  7072 F DEBUG   :     r0 e9e7a240  r1 e9380000  r2 00000170  r3 00000000
+09-03 17:48:05.797  7072  7072 F DEBUG   :     r4 00000002  r5 00000000  r6 ec1e1f25  r7 eb6f8000
+09-03 17:48:05.797  7072  7072 F DEBUG   :     r8 00000000  r9 eb105204  sl 00000000  fp 000003c0
+09-03 17:48:05.797  7072  7072 F DEBUG   :     ip ebd3df18  sp eaf80688  lr ec1e1f41  pc ebd38dd6  cpsr 20000030
+09-03 17:48:05.805  7072  7072 F DEBUG   :
+09-03 17:48:05.805  7072  7072 F DEBUG   : backtrace:
+09-03 17:48:05.806  7072  7072 F DEBUG   :     #00 pc 00002dd6  /system/lib/libaudioutils.so (memcpy_to_float_from_i16+5)
+09-03 17:48:05.806  7072  7072 F DEBUG   :     #01 pc 00040f3d  /system/lib/libaudioflinger.so
+09-03 17:48:05.806  7072  7072 F DEBUG   :     #02 pc 00040799  /system/lib/libaudioflinger.so
+09-03 17:48:05.806  7072  7072 F DEBUG   :     #03 pc 00011178  /system/lib/libaudioflinger.so
+09-03 17:48:05.806  7072  7072 F DEBUG   :     #04 pc 0003180b  /system/lib/libaudioflinger.so
+09-03 17:48:05.806  7072  7072 F DEBUG   :     #05 pc 0002fe57  /system/lib/libaudioflinger.so
+09-03 17:48:05.806  7072  7072 F DEBUG   :     #06 pc 0000e345  /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+140)
+09-03 17:48:05.806  7072  7072 F DEBUG   :     #07 pc 000470b3  /system/lib/libc.so (_ZL15__pthread_startPv+22)
+09-03 17:48:05.806  7072  7072 F DEBUG   :     #08 pc 00019e3d  /system/lib/libc.so (__start_thread+6)
+09-03 17:48:05.967 11272 11568 W NativeCrashListener: Couldn't find ProcessRecord for pid 11071
+09-03 17:48:05.969   359   359 W         : debuggerd: resuming target 11071
+09-03 17:48:05.981 11272 11307 I BootReceiver: Copying /data/tombstones/tombstone_01 to DropBox (SYSTEM_TOMBSTONE)
+09-03 17:48:06.067   394   394 I ServiceManager: service 'media.sound_trigger_hw' died
+06-15 19:57:33.607 12736 12761 D PermissionCache: checking android.permission.MODIFY_AUDIO_SETTINGS for uid=10197 => granted (698 us)
+--------- beginning of crash
+06-15 19:57:33.607 12736 12761 F libc    : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 12761 (synthetic_thread)
+06-15 19:57:33.608   379   379 W         : debuggerd: handling request: pid=12736 uid=1041 gid=1005 tid=12761
+06-15 19:57:33.670 26192 26192 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
+06-15 19:57:33.670 26192 26192 F DEBUG   : Build fingerprint: 'google/bullhead/bullhead:7.1.2/N2G48C/4104010:userdebug/dev-keys'
+06-15 19:57:33.670 26192 26192 F DEBUG   : Revision: 'rev_1.0'
+06-15 19:57:33.670 26192 26192 F DEBUG   : ABI: 'arm'
+06-15 19:57:33.670 26192 26192 F DEBUG   : pid: 12736, tid: 12761, name: synthetic_thread  >>> synthetic_process_1 <<<
+06-15 19:57:33.670 26192 26192 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
+06-15 19:57:33.670 26192 26192 F DEBUG   :     r0 00000000  r1 00000000  r2 0000005f  r3 00000000
+06-15 19:57:33.670 26192 26192 F DEBUG   :     r4 ffffffff  r5 00000000  r6 f14f9000  r7 00000001
+06-15 19:57:33.670 26192 26192 F DEBUG   :     r8 00000004  r9 f3353114  sl f3313900  fp 00000000
+06-15 19:57:33.670 26192 26192 F DEBUG   :     ip f3bd4d88  sp f127d9c8  lr f3b9cbc5  pc f3b65af4  cpsr 60000030
+06-15 19:57:33.676 26192 26192 F DEBUG   :
+06-15 19:57:33.676 26192 26192 F DEBUG   : backtrace:
+06-15 19:57:33.677 26192 26192 F DEBUG   :     #00 pc 00018af4  /system/lib/libc.so (strlen+71)
+06-15 19:57:33.677 26192 26192 F DEBUG   :     #01 pc 0004fbc1  /system/lib/libc.so (__strlen_chk+4)
+06-15 19:57:33.677 26192 26192 F DEBUG   :     #02 pc 0000c599  /system/lib/libutils.so (_ZN7android7String8C2EPKc+12)
+06-15 19:57:33.677 26192 26192 F DEBUG   :     #03 pc 0002fdbf  /system/lib/libaudiopolicymanagerdefault.so (_ZNK7android18HwModuleCollection19getDeviceDescriptorEjPKcS2_b+458)
+06-15 19:57:33.677 26192 26192 F DEBUG   :     #04 pc 0001de47  /system/lib/libaudiopolicymanagerdefault.so (_ZN7android18AudioPolicyManager27setDeviceConnectionStateIntEj24audio_policy_dev_state_tPKcS3_+178)
+06-15 19:57:33.677 26192 26192 F DEBUG   :     #05 pc 0000a009  /system/lib/libaudiopolicyservice.so
+06-15 19:57:33.677 26192 26192 F DEBUG   :     #06 pc 000a01a5  /system/lib/libmedia.so (_ZN7android20BnAudioPolicyService10onTransactEjRKNS_6ParcelEPS1_j+1256)
+06-15 19:57:33.677 26192 26192 F DEBUG   :     #07 pc 000359c3  /system/lib/libbinder.so (_ZN7android7BBinder8transactEjRKNS_6ParcelEPS1_j+70)
+06-15 19:57:33.677 26192 26192 F DEBUG   :     #08 pc 0003d1bb  /system/lib/libbinder.so (_ZN7android14IPCThreadState14executeCommandEi+702)
+06-15 19:57:33.677 26192 26192 F DEBUG   :     #09 pc 0003ce07  /system/lib/libbinder.so (_ZN7android14IPCThreadState20getAndExecuteCommandEv+114)
+06-15 19:57:33.677 26192 26192 F DEBUG   :     #10 pc 0003d31b  /system/lib/libbinder.so (_ZN7android14IPCThreadState14joinThreadPoolEb+46)
+06-15 19:57:33.678 26192 26192 F DEBUG   :     #11 pc 0004f8c5  /system/lib/libbinder.so
+06-15 19:57:33.678 26192 26192 F DEBUG   :     #12 pc 0000e345  /system/lib/libutils.so (_ZN7android6Thread11_threadLoopEPv+140)
+06-15 19:57:33.678 26192 26192 F DEBUG   :     #13 pc 000470b3  /system/lib/libc.so (_ZL15__pthread_startPv+22)
+06-15 19:57:33.678 26192 26192 F DEBUG   :     #14 pc 00019e3d  /system/lib/libc.so (__start_thread+6)
+06-15 19:57:33.839   934  2991 W NativeCrashListener: Couldn't find ProcessRecord for pid 12736
+06-15 19:57:33.846   934   952 I BootReceiver: Copying /data/tombstones/tombstone_01 to DropBox (SYSTEM_TOMBSTONE)
+
diff --git a/common/util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java b/common/util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java
index 94f472e..2138b7b 100644
--- a/common/util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java
+++ b/common/util/tests/src/com/android/compatibility/common/util/CrashUtilsTest.java
@@ -27,6 +27,7 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
+import java.util.regex.Pattern;
 
 /** Unit tests for {@link CrashUtils}. */
 @RunWith(JUnit4.class)
@@ -52,67 +53,89 @@
     @Test
     public void testGetAllCrashes() throws Exception {
         JSONArray expectedResults = new JSONArray();
-        expectedResults.put(createCrashJson(11071, 11189, "AudioOut_D", 3912761344L, "SIGSEGV"));
-        expectedResults.put(createCrashJson(12736, 12761, "Binder:12736_2", 0L, "SIGSEGV"));
-        expectedResults.put(createCrashJson(26201, 26227, "Binder:26201_3", 0L, "SIGSEGV"));
-        expectedResults.put(createCrashJson(26246, 26282, "Binder:26246_5", 0L, "SIGSEGV"));
-        expectedResults.put(createCrashJson(245, 245, "installd", null, "SIGABRT"));
-        expectedResults.put(createCrashJson(6371, 8072, "media.codec", 3976200192L, "SIGSEGV"));
-        expectedResults.put(createCrashJson(8373, 8414, "loo", null, "SIGABRT"));
+        expectedResults.put(createCrashJson(
+                11071, 11189, "AudioOut_D", "/system/bin/audioserver", "e9380000", "SIGSEGV"));
+        expectedResults.put(createCrashJson(
+                12736, 12761, "Binder:12736_2", "/system/bin/audioserver", "0", "SIGSEGV"));
+        expectedResults.put(createCrashJson(
+                26201, 26227, "Binder:26201_3", "/system/bin/audioserver", "0", "SIGSEGV"));
+        expectedResults.put(createCrashJson(
+                26246, 26282, "Binder:26246_5", "/system/bin/audioserver", "0", "SIGSEGV"));
+        expectedResults.put(createCrashJson(
+                245, 245, "installd", "/system/bin/installd", null, "SIGABRT"));
+        expectedResults.put(createCrashJson(
+                6371, 8072, "media.codec", "omx@1.0-service", "ed000000", "SIGSEGV"));
+        expectedResults.put(createCrashJson(
+                8373, 8414, "loo", "com.android.bluetooth", null, "SIGABRT"));
+        expectedResults.put(createCrashJson(
+                11071, 11189, "synthetic_thread", "synthetic_process_0", "e9380000", "SIGSEGV"));
+        expectedResults.put(createCrashJson(
+                12736, 12761, "synthetic_thread", "synthetic_process_1", "0", "SIGSEGV"));
 
         Assert.assertEquals(mCrashes.toString(), expectedResults.toString());
     }
 
     public JSONObject createCrashJson(
-            int pid, int tid, String name, Long faultaddress, String signal) {
+            int pid, int tid, String name, String process, String faultaddress, String signal) {
         JSONObject json = new JSONObject();
         try {
             json.put(CrashUtils.PID, pid);
             json.put(CrashUtils.TID, tid);
             json.put(CrashUtils.NAME, name);
+            json.put(CrashUtils.PROCESS, process);
             json.put(CrashUtils.FAULT_ADDRESS, faultaddress);
             json.put(CrashUtils.SIGNAL, signal);
-        } catch (JSONException e) {
-
-        }
+        } catch (JSONException e) {}
         return json;
     }
 
     @Test
     public void testValidCrash() throws Exception {
-        Assert.assertTrue(CrashUtils.detectCrash(new String[] {"AudioOut_D"}, true, mCrashes));
+        Assert.assertTrue(CrashUtils.securityCrashDetected(mCrashes, true,
+                Pattern.compile("synthetic_process_0")));
     }
 
     @Test
     public void testMissingName() throws Exception {
-        Assert.assertFalse(CrashUtils.detectCrash(new String[] {""}, true, mCrashes));
+        Assert.assertFalse(CrashUtils.securityCrashDetected(mCrashes, true,
+                Pattern.compile("")));
     }
 
     @Test
     public void testSIGABRT() throws Exception {
-        Assert.assertFalse(CrashUtils.detectCrash(new String[] {"installd"}, true, mCrashes));
+        Assert.assertFalse(CrashUtils.securityCrashDetected(mCrashes, true,
+                Pattern.compile("installd")));
     }
 
     @Test
     public void testFaultAddressBelowMin() throws Exception {
-        Assert.assertFalse(CrashUtils.detectCrash(new String[] {"Binder:12736_2"}, true, mCrashes));
+        Assert.assertFalse(CrashUtils.securityCrashDetected(mCrashes, true,
+                Pattern.compile("synthetic_process_1")));
     }
 
     @Test
     public void testIgnoreMinAddressCheck() throws Exception {
-        Assert.assertTrue(CrashUtils.detectCrash(new String[] {"Binder:12736_2"}, false, mCrashes));
+        Assert.assertTrue(CrashUtils.securityCrashDetected(mCrashes, false,
+                Pattern.compile("synthetic_process_1")));
+    }
+
+    @Test
+    public void testBadAbortMessage() throws Exception {
+        Assert.assertFalse(CrashUtils.securityCrashDetected(mCrashes, true,
+                Pattern.compile("generic")));
     }
 
     @Test
     public void testGoodAndBadCrashes() throws Exception {
-        Assert.assertTrue(
-                CrashUtils.detectCrash(new String[] {"AudioOut_D", "generic"}, true, mCrashes));
+        Assert.assertTrue(CrashUtils.securityCrashDetected(mCrashes, true,
+                Pattern.compile("synthetic_process_0"), Pattern.compile("generic")));
     }
 
     @Test
     public void testNullFaultAddress() throws Exception {
         JSONArray crashes = new JSONArray();
-        crashes.put(createCrashJson(8373, 8414, "loo", null, "SIGSEGV"));
-        Assert.assertTrue(CrashUtils.detectCrash(new String[] {"loo"}, true, crashes));
+        crashes.put(createCrashJson(8373, 8414, "loo", "com.android.bluetooth", null, "SIGSEGV"));
+        Assert.assertTrue(CrashUtils.securityCrashDetected(crashes, true,
+                Pattern.compile("com\\.android\\.bluetooth")));
     }
 }
diff --git a/hostsidetests/incident/src/com/android/server/cts/BatteryStatsValidationTest.java b/hostsidetests/incident/src/com/android/server/cts/BatteryStatsValidationTest.java
index 33d72b1..1fcbf91 100644
--- a/hostsidetests/incident/src/com/android/server/cts/BatteryStatsValidationTest.java
+++ b/hostsidetests/incident/src/com/android/server/cts/BatteryStatsValidationTest.java
@@ -58,7 +58,7 @@
     private static final int STATE_TIME_CACHED_INDEX = 9;
 
     private static final long TIME_SPENT_IN_TOP = 2000;
-    private static final long TIME_SPENT_IN_FOREGROUND = 2000;
+    private static final long TIME_SPENT_IN_FOREGROUND = 4000;
     private static final long TIME_SPENT_IN_BACKGROUND = 2000;
     private static final long TIME_SPENT_IN_CACHED = 4000;
     private static final long SCREEN_STATE_CHANGE_TIMEOUT = 4000;
diff --git a/hostsidetests/theme/src/android/theme/cts/ThemeHostTest.java b/hostsidetests/theme/src/android/theme/cts/ThemeHostTest.java
index 169e651..d549e03 100644
--- a/hostsidetests/theme/src/android/theme/cts/ThemeHostTest.java
+++ b/hostsidetests/theme/src/android/theme/cts/ThemeHostTest.java
@@ -146,7 +146,7 @@
     @CddTest(requirement="3.8.6/C-1-1,C-1-2")
     public void testThemes() throws Exception {
         if (checkHardwareTypeSkipTest(mDevice.executeShellCommand(HARDWARE_TYPE_CMD).trim())) {
-            Log.logAndDisplay(LogLevel.INFO, LOG_TAG, "Skipped themes test for watch / TV");
+            Log.logAndDisplay(LogLevel.INFO, LOG_TAG, "Skipped themes test for watch / TV / automotive");
             return;
         }
 
@@ -290,6 +290,7 @@
 
     private static boolean checkHardwareTypeSkipTest(String hardwareTypeString) {
         return hardwareTypeString.contains("android.hardware.type.watch")
-                || hardwareTypeString.contains("android.hardware.type.television");
+                || hardwareTypeString.contains("android.hardware.type.television")
+                || hardwareTypeString.contains("android.hardware.type.automotive");
     }
 }
diff --git a/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java b/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java
index 24cb6bd..5eed3e8 100644
--- a/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java
+++ b/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java
@@ -61,7 +61,7 @@
     private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE);
 
     private static final int CONFIGURE_TIMEOUT = 5000; //ms
-    private static final int CAPTURE_TIMEOUT = 1000; //ms
+    private static final int CAPTURE_TIMEOUT = 1500; //ms
 
     // For testTriggerInteractions
     private static final int PREVIEW_WARMUP_FRAMES = 60;
diff --git a/tests/tests/media/src/android/media/cts/MediaCodecListTest.java b/tests/tests/media/src/android/media/cts/MediaCodecListTest.java
index 987d365..2104118 100644
--- a/tests/tests/media/src/android/media/cts/MediaCodecListTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaCodecListTest.java
@@ -302,6 +302,11 @@
                 && !pm.hasSystemFeature(pm.FEATURE_TELEVISION);
     }
 
+    private boolean isAutomotive() {
+        PackageManager pm = getContext().getPackageManager();
+        return pm.hasSystemFeature(pm.FEATURE_AUTOMOTIVE);
+    }
+
     // Find whether the given codec can be found using MediaCodecList.find methods.
     private boolean codecCanBeFound(boolean isEncoder, MediaFormat format) {
         String codecName = isEncoder
@@ -395,7 +400,11 @@
             list.add(new VideoCodec(MediaFormat.MIMETYPE_VIDEO_VP8, false));   // vp8 decoder
             list.add(new VideoCodec(MediaFormat.MIMETYPE_VIDEO_VP8, true));    // vp8 encoder
             list.add(new VideoCodec(MediaFormat.MIMETYPE_VIDEO_VP9, false));   // vp9 decoder
-            list.add(new VideoCodec(MediaFormat.MIMETYPE_VIDEO_HEVC, false));  // hevc decoder
+
+            //According to CDD, hevc decoding is not mandatory for automotive devices
+            if (!isAutomotive()) {
+                list.add(new VideoCodec(MediaFormat.MIMETYPE_VIDEO_HEVC, false));  // hevc decoder
+            }
             list.add(new VideoCodec(MediaFormat.MIMETYPE_VIDEO_MPEG4, false)); // m4v decoder
             list.add(new VideoCodec(MediaFormat.MIMETYPE_VIDEO_H263, false));  // h263 decoder
             if (hasCamera()) {
diff --git a/tests/tests/media/src/android/media/cts/MediaMuxerTest.java b/tests/tests/media/src/android/media/cts/MediaMuxerTest.java
index 15d08a3..fa09149 100644
--- a/tests/tests/media/src/android/media/cts/MediaMuxerTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaMuxerTest.java
@@ -480,6 +480,12 @@
         // parsing String location and recover the location information in floats
         // Make sure the tolerance is very small - due to rounding errors.
 
+        // Trim the trailing slash, if any.
+        int lastIndex = location.lastIndexOf('/');
+        if (lastIndex != -1) {
+            location = location.substring(0, lastIndex);
+        }
+
         // Get the position of the -/+ sign in location String, which indicates
         // the beginning of the longitude.
         int minusIndex = location.lastIndexOf('-');
@@ -489,12 +495,8 @@
                 (minusIndex > 0 || plusIndex > 0));
         int index = Math.max(minusIndex, plusIndex);
 
-        float latitude = Float.parseFloat(location.substring(0, index - 1));
-        int lastIndex = location.lastIndexOf('/', index);
-        if (lastIndex == -1) {
-            lastIndex = location.length();
-        }
-        float longitude = Float.parseFloat(location.substring(index, lastIndex - 1));
+        float latitude = Float.parseFloat(location.substring(0, index));
+        float longitude = Float.parseFloat(location.substring(index));
         assertTrue("Incorrect latitude: " + latitude + " [" + location + "]",
                 Math.abs(latitude - LATITUDE) <= TOLERANCE);
         assertTrue("Incorrect longitude: " + longitude + " [" + location + "]",
diff --git a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
index 3782416..3578e4f 100644
--- a/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaRecorderTest.java
@@ -507,6 +507,12 @@
         // Make sure the tolerance is very small - due to rounding errors?.
         Log.v(TAG, "location: " + location);
 
+        // Trim the trailing slash, if any.
+        int lastIndex = location.lastIndexOf('/');
+        if (lastIndex != -1) {
+            location = location.substring(0, lastIndex);
+        }
+
         // Get the position of the -/+ sign in location String, which indicates
         // the beginning of the longtitude.
         int index = location.lastIndexOf('-');
@@ -515,12 +521,8 @@
         }
         assertTrue("+ or - is not found", index != -1);
         assertTrue("+ or - is only found at the beginning", index != 0);
-        float latitude = Float.parseFloat(location.substring(0, index - 1));
-        int lastIndex = location.lastIndexOf('/', index);
-        if (lastIndex == -1) {
-            lastIndex = location.length();
-        }
-        float longitude = Float.parseFloat(location.substring(index, lastIndex - 1));
+        float latitude = Float.parseFloat(location.substring(0, index));
+        float longitude = Float.parseFloat(location.substring(index));
         assertTrue("Incorrect latitude: " + latitude, Math.abs(latitude - LATITUDE) <= TOLERANCE);
         assertTrue("Incorrect longitude: " + longitude, Math.abs(longitude - LONGITUDE) <= TOLERANCE);
         retriever.release();
diff --git a/tests/tests/net/jni/NativeMultinetworkJni.c b/tests/tests/net/jni/NativeMultinetworkJni.c
index 9156504..c2dff8d 100644
--- a/tests/tests/net/jni/NativeMultinetworkJni.c
+++ b/tests/tests/net/jni/NativeMultinetworkJni.c
@@ -179,13 +179,17 @@
     setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &timeo, sizeof(timeo));
 
     // For reference see:
-    //     https://tools.ietf.org/html/draft-tsvwg-quic-protocol-01#section-6.1
-    uint8_t quic_packet[] = {
-        0x0c,                    // public flags: 64bit conn ID, 8bit sequence number
+    //     https://tools.ietf.org/html/draft-tsvwg-quic-protocol#section-6.1
+    uint8_t quic_packet[1200] = {
+        0x0d,                    // public flags:
+                                 //   - version present (0x01),
+                                 //   - 64bit connection ID (0x0c),
+                                 //   - 1 byte packet number (0x00)
         0, 0, 0, 0, 0, 0, 0, 0,  // 64bit connection ID
-        0x01,                    // sequence number
+        0xaa, 0xda, 0xca, 0xaa,  // reserved-space version number
+        1,                       // 1 byte packet number
         0x00,                    // private flags
-        0x07,                    // type: regular frame type "PING"
+        0x07,                    // PING frame (cuz why not)
     };
 
     arc4random_buf(quic_packet + 1, 8);  // random connection ID
@@ -213,7 +217,7 @@
                   i + 1, MAX_RETRIES, rcvd, errnum);
         }
     }
-    if (rcvd < sent) {
+    if (rcvd < 9) {
         ALOGD("QUIC UDP %s: sent=%zd but rcvd=%zd, errno=%d", kPort, sent, rcvd, errnum);
         if (rcvd <= 0) {
             ALOGD("Does this network block UDP port %s?", kPort);
@@ -229,8 +233,7 @@
         return -EPROTO;
     }
 
-    // TODO: log, and compare to the IP address encoded in the
-    // response, since this should be a public reset packet.
+    // TODO: Replace this quick 'n' dirty test with proper QUIC-capable code.
 
     close(fd);
     return 0;
diff --git a/tests/tests/security/Android.mk b/tests/tests/security/Android.mk
index b22f6c7..537a987 100644
--- a/tests/tests/security/Android.mk
+++ b/tests/tests/security/Android.mk
@@ -27,6 +27,7 @@
     ctstestserver \
     ctstestrunner \
     compatibility-device-util \
+    compatibility-common-util-devicesidelib \
     guava \
     platform-test-annotations \
     legacy-android-test
diff --git a/tests/tests/security/src/android/security/cts/EncryptionTest.java b/tests/tests/security/src/android/security/cts/EncryptionTest.java
index f7b279a..6adb96d 100644
--- a/tests/tests/security/src/android/security/cts/EncryptionTest.java
+++ b/tests/tests/security/src/android/security/cts/EncryptionTest.java
@@ -24,6 +24,7 @@
 import junit.framework.TestCase;
 
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.util.Log;
 import java.io.BufferedReader;
 import java.io.FileReader;
@@ -46,6 +47,12 @@
     private static native boolean aesIsFast();
 
     private boolean isRequired() {
+        PackageManager pm = this.getContext().getPackageManager();
+        if (pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) {
+            Log.i(TAG, "Device encryption is not needed for automotive device type");
+            return false;
+        }
+
         // Optional before MIN_API_LEVEL
         return PropertyUtil.getFirstApiLevel() >= MIN_API_LEVEL;
     }
diff --git a/tests/tests/security/src/android/security/cts/StagefrightTest.java b/tests/tests/security/src/android/security/cts/StagefrightTest.java
index 6cc6988..72bdb3a 100644
--- a/tests/tests/security/src/android/security/cts/StagefrightTest.java
+++ b/tests/tests/security/src/android/security/cts/StagefrightTest.java
@@ -57,6 +57,7 @@
 import java.util.HashMap;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.ReentrantLock;
+import java.util.regex.Pattern;
 
 import org.json.JSONArray;
 import org.json.JSONException;
@@ -556,8 +557,23 @@
         MediaPlayer.OnPreparedListener,
         MediaPlayer.OnCompletionListener {
 
-        private final String[] validProcessNames = {
-            "mediaserver", "mediadrmserver", "media.extractor", "media.codec", "media.metrics"
+        private final Pattern[] validProcessPatterns = {
+            Pattern.compile("adsprpcd"),
+            Pattern.compile("android\\.hardware\\.cas@\\d+?\\.\\d+?-service"),
+            Pattern.compile("android\\.hardware\\.drm@\\d+?\\.\\d+?-service"),
+            Pattern.compile("android\\.hardware\\.drm@\\d+?\\.\\d+?-service\\.clearkey"),
+            Pattern.compile("android\\.hardware\\.drm@\\d+?\\.\\d+?-service\\.widevine"),
+            Pattern.compile("android\\.process\\.media"),
+            Pattern.compile("mediadrmserver"),
+            Pattern.compile("media\\.extractor"),
+            Pattern.compile("media\\.metrics"),
+            Pattern.compile("mediaserver"),
+            Pattern.compile("media\\.codec"),
+            Pattern.compile("media\\.swcodec"),
+            Pattern.compile("\\[?sdcard\\]?"), // name:/system/bin/sdcard, user:media_rw
+            // Match any vendor processes.
+            // It should only catch crashes that happen during the test.
+            Pattern.compile("vendor.*"),
         };
 
         @Override
@@ -605,7 +621,7 @@
                 if (crashes == null) {
                     Log.e(TAG, "Crash results not found for test " + getName());
                     return what;
-                } else if (CrashUtils.detectCrash(validProcessNames, true, crashes)) {
+                } else if (CrashUtils.securityCrashDetected(crashes, true, validProcessPatterns)) {
                     return what;
                 } else {
                     Log.i(TAG, "Crash ignored due to no security crash found for test " +
diff --git a/tests/tests/text/src/android/text/format/cts/TimeTest.java b/tests/tests/text/src/android/text/format/cts/TimeTest.java
index f43ad12..df93f34 100644
--- a/tests/tests/text/src/android/text/format/cts/TimeTest.java
+++ b/tests/tests/text/src/android/text/format/cts/TimeTest.java
@@ -2825,6 +2825,13 @@
         Fields.verifyTimeEquals(expected, t);
     }
 
+    @Test
+    public void test_bug118835133() {
+        Time t = new Time("Asia/Singapore");
+        Fields.set(t, 2018, 9, 30, 12, 48, 32, 0 /* isDst */, 0, 0, 0);
+        // With http://b/118835133 toMillis() returns -1.
+        assertEquals(1540874912000L, t.toMillis(true /* ignoreDst */));
+    }
     private static void verifyNormalizeResult(boolean normalizeArgument, Time toNormalize,
             Time expectedTime, long expectedTimeMillis) {
         long actualTimeMillis = toNormalize.normalize(normalizeArgument /* ignore isDst */);
diff --git a/tests/tests/view/res/layout/view_layout.xml b/tests/tests/view/res/layout/view_layout.xml
index 6f886bb..fbdddc2 100644
--- a/tests/tests/view/res/layout/view_layout.xml
+++ b/tests/tests/view/res/layout/view_layout.xml
@@ -26,8 +26,8 @@
 
     <android.view.cts.MockView
         android:id="@+id/mock_view"
-        android:layout_width="100dp"
-        android:layout_height="75dp"/>
+        android:layout_width="75dp"
+        android:layout_height="100dp"/>
 
     <android.view.cts.MockView
         android:id="@+id/scroll_view"
diff --git a/tests/tests/view/src/android/view/cts/ViewTest.java b/tests/tests/view/src/android/view/cts/ViewTest.java
index 194fd78..cdb2223 100644
--- a/tests/tests/view/src/android/view/cts/ViewTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewTest.java
@@ -1824,8 +1824,8 @@
         final MockView view = (MockView) mActivity.findViewById(R.id.mock_view);
 
         float density = view.getContext().getResources().getDisplayMetrics().density;
-        int size1 = (int) (100 * density + 0.5);
-        int size2 = (int) (75 * density + 0.5);
+        int size1 = (int) (75 * density + 0.5);
+        int size2 = (int) (100 * density + 0.5);
 
         assertTrue(view.hasCalledOnMeasure());
         assertEquals(size1, view.getMeasuredWidth());
@@ -2424,8 +2424,8 @@
         Rect rect = new Rect();
 
         float density = view.getContext().getResources().getDisplayMetrics().density;
-        int size1 = (int) (100 * density + 0.5);
-        int size2 = (int) (75 * density + 0.5);
+        int size1 = (int) (75 * density + 0.5);
+        int size2 = (int) (100 * density + 0.5);
 
         assertTrue(view.getLocalVisibleRect(rect));
         assertEquals(0, rect.left);
diff --git a/tools/cts-tradefed/Android.mk b/tools/cts-tradefed/Android.mk
index 50100ad..a84fb093 100644
--- a/tools/cts-tradefed/Android.mk
+++ b/tools/cts-tradefed/Android.mk
@@ -29,7 +29,7 @@
 LOCAL_SUITE_TARGET_ARCH := $(TARGET_ARCH)
 LOCAL_SUITE_NAME := CTS
 LOCAL_SUITE_FULLNAME := "Compatibility Test Suite"
-LOCAL_SUITE_VERSION := 8.1_r16
+LOCAL_SUITE_VERSION := 8.1_r17
 LOCAL_STATIC_JAVA_LIBRARIES += cts-tradefed-harness
 
 LOCAL_MODULE := cts-tradefed