Merge "CTS Test Metrics: Remove Details from result xml." into nyc-dev
am: 79ca18845a

* commit '79ca18845a900db79abea5c301d67c65edf02e95':
  CTS Test Metrics: Remove Details from result xml.

Change-Id: I9fbb65f9a19b1840523da56f7196acc9a94faab3
diff --git a/hostsidetests/security/src/android/cts/security/FileSystemPermissionTest.java b/hostsidetests/security/src/android/cts/security/FileSystemPermissionTest.java
new file mode 100644
index 0000000..0cbd1cc
--- /dev/null
+++ b/hostsidetests/security/src/android/cts/security/FileSystemPermissionTest.java
@@ -0,0 +1,137 @@
+package android.cts.security;
+
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.testtype.DeviceTestCase;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public class FileSystemPermissionTest extends DeviceTestCase {
+
+   /**
+    * A reference to the device under test.
+    */
+    private ITestDevice mDevice;
+
+    /**
+     * Used to build the find command for finding insecure file system components
+     */
+    private static final String INSECURE_DEVICE_ADB_COMMAND = "find %s -type %s -perm /o=rwx 2>/dev/null";
+
+    /**
+     * Whitelist exceptions of allowed world accessbale char files under /dev
+     */
+    private static final Set<String> CHAR_DEV_EXCEPTIONS = new HashSet<String>(
+        Arrays.asList(
+            // All exceptions should be alphabetical and associated with a bug number.
+            "/dev/adsprpc-smd", // b/11710243
+            "/dev/alarm",      // b/9035217
+            "/dev/ashmem",
+            "/dev/binder",
+            "/dev/card0",       // b/13159510
+            "/dev/renderD128",
+            "/dev/renderD129",  // b/23798677
+            "/dev/dri/card0",   // b/13159510
+            "/dev/dri/renderD128",
+            "/dev/dri/renderD129", // b/23798677
+            "/dev/felica",     // b/11142586
+            "/dev/felica_ant", // b/11142586
+            "/dev/felica_cen", // b/11142586
+            "/dev/felica_pon", // b/11142586
+            "/dev/felica_rfs", // b/11142586
+            "/dev/felica_rws", // b/11142586
+            "/dev/felica_uicc", // b/11142586
+            "/dev/full",
+            "/dev/galcore",
+            "/dev/genlock",    // b/9035217
+            "/dev/graphics/galcore",
+            "/dev/ion",
+            "/dev/kgsl-2d0",   // b/11271533
+            "/dev/kgsl-2d1",   // b/11271533
+            "/dev/kgsl-3d0",   // b/9035217
+            "/dev/log/events", // b/9035217
+            "/dev/log/main",   // b/9035217
+            "/dev/log/radio",  // b/9035217
+            "/dev/log/system", // b/9035217
+            "/dev/mali0",       // b/9106968
+            "/dev/mali",        // b/11142586
+            "/dev/mm_interlock", // b/12955573
+            "/dev/mm_isp",      // b/12955573
+            "/dev/mm_v3d",      // b/12955573
+            "/dev/msm_rotator", // b/9035217
+            "/dev/null",
+            "/dev/nvhost-as-gpu",
+            "/dev/nvhost-ctrl", // b/9088251
+            "/dev/nvhost-ctrl-gpu",
+            "/dev/nvhost-dbg-gpu",
+            "/dev/nvhost-gpu",
+            "/dev/nvhost-gr2d", // b/9088251
+            "/dev/nvhost-gr3d", // b/9088251
+            "/dev/nvhost-tsec",
+            "/dev/nvhost-prof-gpu",
+            "/dev/nvhost-vic",
+            "/dev/nvmap",       // b/9088251
+            "/dev/ptmx",        // b/9088251
+            "/dev/pvrsrvkm",    // b/9108170
+            "/dev/pvr_sync",
+            "/dev/quadd",
+            "/dev/random",
+            "/dev/snfc_cen",    // b/11142586
+            "/dev/snfc_hsel",   // b/11142586
+            "/dev/snfc_intu_poll", // b/11142586
+            "/dev/snfc_rfs",    // b/11142586
+            "/dev/tegra-throughput",
+            "/dev/tiler",       // b/9108170
+            "/dev/tty",
+            "/dev/urandom",
+            "/dev/ump",         // b/11142586
+            "/dev/xt_qtaguid",  // b/9088251
+            "/dev/zero",
+            "/dev/fimg2d",      // b/10428016
+            "/dev/mobicore-user" // b/10428016
+    ));
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mDevice = getDevice();
+    }
+
+    public void testAllCharacterDevicesAreSecure() throws DeviceNotAvailableException {
+        Set <String> insecure = getAllInsecureDevicesInDirAndSubdir("/dev", "c");
+        Set <String> insecurePts = getAllInsecureDevicesInDirAndSubdir("/dev/pts", "c");
+        insecure.removeAll(CHAR_DEV_EXCEPTIONS);
+        insecure.removeAll(insecurePts);
+        assertTrue("Found insecure character devices: " + insecure.toString(),
+                insecure.isEmpty());
+    }
+
+    public void testAllBlockDevicesAreSecure() throws Exception {
+        Set<String> insecure = getAllInsecureDevicesInDirAndSubdir("/dev", "b");
+        assertTrue("Found insecure block devices: " + insecure.toString(),
+                insecure.isEmpty());
+    }
+
+    /**
+     * Searches for all world accessable files, note this may need sepolicy to search the desired
+     * location and stat files.
+     * @path The path to search, must be a directory.
+     * @type The type of file to search for, must be a valid find command argument to the type
+     *       option.
+     * @returns The set of insecure fs objects found.
+     */
+    private Set<String> getAllInsecureDevicesInDirAndSubdir(String path, String type) throws DeviceNotAvailableException {
+
+        String cmd = getInsecureDeviceAdbCommand(path, type);
+        String output = mDevice.executeShellCommand(cmd);
+        // Splitting an empty string results in an array of an empty string.
+        String [] found = output.length() > 0 ? output.split("\\s") : new String[0];
+        return new HashSet<String>(Arrays.asList(found));
+    }
+
+    private static String getInsecureDeviceAdbCommand(String path, String type) {
+        return String.format(INSECURE_DEVICE_ADB_COMMAND, path, type);
+    }
+}
diff --git a/suite/audio_quality/test/Android.mk b/suite/audio_quality/test/Android.mk
index 21b0250..ed0f4c9 100644
--- a/suite/audio_quality/test/Android.mk
+++ b/suite/audio_quality/test/Android.mk
@@ -19,15 +19,25 @@
 LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
 
 #$(info $(LOCAL_SRC_FILES))
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/../lib/include $(LOCAL_PATH)/../lib/src external/gtest/include \
-    external/tinyalsa/include/  libcore/include
-LOCAL_STATIC_LIBRARIES := libutils libgtest_host libgtest_main_host  liblog libcutils libtinyalsa \
-    libtinyxml
+LOCAL_C_INCLUDES := \
+    $(LOCAL_PATH)/../lib/include \
+    $(LOCAL_PATH)/../lib/src \
+    external/tinyalsa/include/ \
+    libcore/include \
+
+LOCAL_STATIC_LIBRARIES := \
+    libutils \
+    liblog \
+    libcutils \
+    libtinyalsa \
+    libtinyxml \
+
 # need to keep everything in libcts_.. Otherwise, linker will drop some
 # functions and linker error happens
 LOCAL_WHOLE_STATIC_LIBRARIES := libcts_audio_quality
 LOCAL_CFLAGS:= -g -fno-exceptions
 LOCAL_LDFLAGS:= -g -lrt -ldl -lm -fno-exceptions -lpthread
 LOCAL_MODULE_HOST_OS := linux
-LOCAL_MODULE:= cts_audio_quality_test
-include $(BUILD_HOST_EXECUTABLE)
+LOCAL_MODULE := cts_audio_quality_test
+LOCAL_MULTILIB := first
+include $(BUILD_HOST_NATIVE_TEST)
diff --git a/tests/core/libcore/tests/Android.mk b/tests/core/libcore/tests/Android.mk
index 6429558..e9b9422 100644
--- a/tests/core/libcore/tests/Android.mk
+++ b/tests/core/libcore/tests/Android.mk
@@ -16,6 +16,6 @@
 
 include $(CLEAR_VARS)
 LOCAL_PACKAGE_NAME := android.core.tests.libcore.package.tests
-LOCAL_STATIC_JAVA_LIBRARIES := core-tests mockito-target-minus-junit4
+LOCAL_STATIC_JAVA_LIBRARIES := core-tests mockito-api
 LOCAL_JAVA_LANGUAGE_VERSION := 1.8
 include $(BUILD_CTSCORE_PACKAGE)
diff --git a/tests/openglperf2/test/Android.mk b/tests/openglperf2/test/Android.mk
index e83e584..a9ec558 100644
--- a/tests/openglperf2/test/Android.mk
+++ b/tests/openglperf2/test/Android.mk
@@ -18,9 +18,9 @@
 LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
 LOCAL_SRC_FILES += ../jni/graphics/Matrix.cpp
 
-LOCAL_C_INCLUDES += external/gtest/include $(LOCAL_PATH)/../jni/graphics/
-LOCAL_STATIC_LIBRARIES := libgtest_host libgtest_main_host liblog
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/../jni/graphics/
+LOCAL_STATIC_LIBRARIES := liblog
 LOCAL_LDFLAGS:= -g -lpthread
 LOCAL_MODULE_HOST_OS := linux
 LOCAL_MODULE:= cts_device_opengl_test
-include $(BUILD_HOST_EXECUTABLE)
+include $(BUILD_HOST_NATIVE_TEST)
diff --git a/tests/tests/bionic/Android.mk b/tests/tests/bionic/Android.mk
index 627841f..949ca73 100644
--- a/tests/tests/bionic/Android.mk
+++ b/tests/tests/bionic/Android.mk
@@ -44,7 +44,7 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 LOCAL_LDLIBS += \
-    -lrt -ldl -lutil \
+    -lresolv -lrt -ldl -lutil \
 
 LOCAL_WHOLE_STATIC_LIBRARIES += \
     libBionicTests \
diff --git a/tests/tests/libcorefileio/Android.mk b/tests/tests/libcorefileio/Android.mk
new file mode 100644
index 0000000..29226bf
--- /dev/null
+++ b/tests/tests/libcorefileio/Android.mk
@@ -0,0 +1,33 @@
+# 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)
+
+# don't include this package in any target
+LOCAL_MODULE_TAGS := optional
+# and when built explicitly put it in the data partition
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := CtsLibcoreFileIOTestCases
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts
+
+include $(BUILD_CTS_PACKAGE)
diff --git a/tests/tests/libcorefileio/AndroidManifest.xml b/tests/tests/libcorefileio/AndroidManifest.xml
new file mode 100644
index 0000000..4557eec
--- /dev/null
+++ b/tests/tests/libcorefileio/AndroidManifest.xml
@@ -0,0 +1,46 @@
+<?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
+  -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+          package="android.libcorefileio.cts">
+
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+
+    <application>
+        <uses-library android:name="android.test.runner"/>
+        <service android:name="android.cts.LockHoldingService"
+                 android:process=":lockHoldingService"
+                 android:permission="android.permission.WRITE_EXTERNAL_STORAGE"
+        />
+        <receiver android:name="android.cts.FileChannelTryLockTest$IntentReceiver">
+
+            <intent-filter>
+                <action android:name="android.cts.CtsLibcoreFileIOTestCases">
+                </action>
+            </intent-filter>
+
+        </receiver>
+    </application>
+
+    <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
+                     android:targetPackage="android.libcorefileio.cts">
+        <meta-data android:name="listener"
+                   android:value="com.android.cts.runner.CtsTestRunListener"/>
+    </instrumentation>
+
+</manifest>
+
diff --git a/tests/tests/libcorefileio/AndroidTest.xml b/tests/tests/libcorefileio/AndroidTest.xml
new file mode 100644
index 0000000..9baa713
--- /dev/null
+++ b/tests/tests/libcorefileio/AndroidTest.xml
@@ -0,0 +1,23 @@
+<!-- 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.
+-->
+<configuration description="Config for CTS Legacy Libcore test cases">
+    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.ApkInstaller">
+        <option name="cleanup-apks" value="true" />
+        <option name="test-file-name" value="CtsLibcoreFileIOTestCases.apk" />
+    </target_preparer>
+    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+        <option name="package" value="android.libcorefileio.cts" />
+    </test>
+</configuration>
\ No newline at end of file
diff --git a/tests/tests/libcorefileio/src/android/cts/FileChannelTryLockTest.java b/tests/tests/libcorefileio/src/android/cts/FileChannelTryLockTest.java
new file mode 100644
index 0000000..61a59ca
--- /dev/null
+++ b/tests/tests/libcorefileio/src/android/cts/FileChannelTryLockTest.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.cts;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Environment;
+import android.test.AndroidTestCase;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.channels.FileLock;
+import java.nio.channels.OverlappingFileLockException;
+
+@SuppressWarnings("deprecation")
+public class FileChannelTryLockTest extends AndroidTestCase {
+
+    final static String dirName = "CtsFIleIOTest";
+
+    final static String sharedFileName = "sharedFile";
+
+    public void testFileLockWithMultipleProcess() throws InterruptedException, IOException {
+        IntentReceiver receiver = new IntentReceiver();
+        getContext().startService(new Intent(getContext(), LockHoldingService.class));
+        synchronized (receiver.notifier) {
+            receiver.notifier.wait(10000);
+        }
+        File sharedFile = createFileInDir(dirName, sharedFileName);
+        assertNull(new FileOutputStream(sharedFile).getChannel().tryLock());
+        getContext().stopService(new Intent(getContext(), LockHoldingService.class));
+    }
+
+    public void testFileLockWithSingleProcess() throws IOException {
+        File file = createFileInDir(dirName, "sharedFileForSingleProcess");
+        FileLock fileLock1 = new FileOutputStream(file).getChannel().tryLock();
+        try {
+            new FileOutputStream(file).getChannel().tryLock();
+            fail();
+        } catch (OverlappingFileLockException expected) {
+        }
+    }
+
+    static File createFileInDir(String dirName, String fileName) throws IOException {
+        File dir = new File(Environment.getExternalStorageDirectory(), dirName);
+        if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+            throw new IOException("External storage is not mounted");
+        } else if (!dir.mkdirs() && !dir.isDirectory()) {
+            throw new IOException("Cannot create directory for device info files");
+        } else {
+            return new File(dir, fileName);
+        }
+    }
+
+    static void deleteDir() {
+        File dir = new File(Environment.getExternalStorageDirectory(), dirName);
+        if (dir.isDirectory()) {
+            String[] children = dir.list();
+            for (int i = 0; i < children.length; i++) {
+                new File(dir, children[i]).delete();
+            }
+            dir.delete();
+        }
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        getContext().stopService(new Intent(getContext(), LockHoldingService.class));
+        deleteDir();
+    }
+
+    public static class IntentReceiver extends BroadcastReceiver {
+
+        public final static Object notifier = new Object();
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            synchronized (notifier) {
+                notifier.notify();
+            }
+        }
+    }
+}
+
diff --git a/tests/tests/libcorefileio/src/android/cts/LockHoldingService.java b/tests/tests/libcorefileio/src/android/cts/LockHoldingService.java
new file mode 100644
index 0000000..be6a352
--- /dev/null
+++ b/tests/tests/libcorefileio/src/android/cts/LockHoldingService.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.cts;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.IBinder;
+import android.util.Log;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.channels.FileLock;
+
+public class LockHoldingService extends Service {
+
+    final String TAG = "CtsLibcoreFileIOTestCases";
+
+    File file = null;
+
+    FileLock fileLock = null;
+
+    public IBinder onBind(Intent intent) {
+        return null;
+    }
+
+    @Override
+    public int onStartCommand(Intent intent, int flags, int startID) {
+        try {
+            this.file = FileChannelTryLockTest.createFileInDir(FileChannelTryLockTest.dirName,
+                    FileChannelTryLockTest.sharedFileName);
+            try {
+                this.fileLock = new FileOutputStream(file).getChannel().tryLock();
+            } catch (IOException e) {
+                Log.e(TAG, e.getMessage());
+            }
+        } catch (IOException e) {
+            Log.e(TAG, e.getMessage());
+        }
+        sendBroadcast(new Intent().setAction("android.cts.CtsLibcoreFileIOTestCases"));
+        return START_STICKY;
+    }
+
+    @Override
+    public void onDestroy() {
+        try {
+            fileLock.close();
+        } catch (IOException e) {
+            Log.e(TAG, e.getMessage());
+        }
+        FileChannelTryLockTest.deleteDir();
+    }
+}
diff --git a/tests/tests/nativemedia/sl/Android.mk b/tests/tests/nativemedia/sl/Android.mk
index e782994..23c0d06 100644
--- a/tests/tests/nativemedia/sl/Android.mk
+++ b/tests/tests/nativemedia/sl/Android.mk
@@ -30,7 +30,6 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 LOCAL_C_INCLUDES := \
-    external/gtest/include \
     $(call include-path-for, wilhelm) \
     $(call include-path-for, wilhelm-ut)
 
diff --git a/tests/tests/nativemedia/xa/Android.mk b/tests/tests/nativemedia/xa/Android.mk
index f71d853..e8017cd 100644
--- a/tests/tests/nativemedia/xa/Android.mk
+++ b/tests/tests/nativemedia/xa/Android.mk
@@ -30,7 +30,6 @@
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
 LOCAL_C_INCLUDES := \
-    external/gtest/include \
     $(call include-path-for, wilhelm) \
     $(call include-path-for, wilhelm-ut)
 
diff --git a/tests/tests/net/jni/NativeDnsJni.c b/tests/tests/net/jni/NativeDnsJni.c
index 4eb3c7a..352c0c5 100644
--- a/tests/tests/net/jni/NativeDnsJni.c
+++ b/tests/tests/net/jni/NativeDnsJni.c
@@ -126,7 +126,7 @@
         return JNI_FALSE;
     }
 
-    memset(buf, sizeof(buf), 0);
+    memset(buf, 0, sizeof(buf));
     res = getnameinfo((const struct sockaddr*)&sa6, sizeof(sa6), buf, sizeof(buf), NULL, 0, flags);
     if (res != 0) {
         ALOGD("getnameinfo(%s (GoogleDNS) ) gave error %d (%s)", GoogleDNSIpV6Address2,
diff --git a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
index 617f0ab..2cac73d 100644
--- a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
@@ -816,91 +816,6 @@
         assertTrue("/data is not mounted NODEV", (vfs.f_flag & OsConstants.ST_NODEV) != 0);
     }
 
-    public void testAllBlockDevicesAreSecure() throws Exception {
-        Set<File> insecure = getAllInsecureDevicesInDirAndSubdir(new File("/dev"), FileUtils.S_IFBLK);
-        assertTrue("Found insecure block devices: " + insecure.toString(),
-                insecure.isEmpty());
-    }
-
-    private static final Set<File> CHAR_DEV_EXCEPTIONS = new HashSet<File>(
-            Arrays.asList(
-                // All exceptions should be alphabetical and associated with a bug number.
-                new File("/dev/adsprpc-smd"), // b/11710243
-                new File("/dev/alarm"),      // b/9035217
-                new File("/dev/ashmem"),
-                new File("/dev/binder"),
-                new File("/dev/card0"),       // b/13159510
-                new File("/dev/renderD128"),
-                new File("/dev/renderD129"),  // b/23798677
-                new File("/dev/dri/card0"),   // b/13159510
-                new File("/dev/dri/renderD128"),
-                new File("/dev/dri/renderD129"), // b/23798677
-                new File("/dev/felica"),     // b/11142586
-                new File("/dev/felica_ant"), // b/11142586
-                new File("/dev/felica_cen"), // b/11142586
-                new File("/dev/felica_pon"), // b/11142586
-                new File("/dev/felica_rfs"), // b/11142586
-                new File("/dev/felica_rws"), // b/11142586
-                new File("/dev/felica_uicc"), // b/11142586
-                new File("/dev/full"),
-                new File("/dev/galcore"),
-                new File("/dev/genlock"),    // b/9035217
-                new File("/dev/graphics/galcore"),
-                new File("/dev/ion"),
-                new File("/dev/kgsl-2d0"),   // b/11271533
-                new File("/dev/kgsl-2d1"),   // b/11271533
-                new File("/dev/kgsl-3d0"),   // b/9035217
-                new File("/dev/log/events"), // b/9035217
-                new File("/dev/log/main"),   // b/9035217
-                new File("/dev/log/radio"),  // b/9035217
-                new File("/dev/log/system"), // b/9035217
-                new File("/dev/mali0"),       // b/9106968
-                new File("/dev/mali"),        // b/11142586
-                new File("/dev/mm_interlock"), // b/12955573
-                new File("/dev/mm_isp"),      // b/12955573
-                new File("/dev/mm_v3d"),      // b/12955573
-                new File("/dev/msm_rotator"), // b/9035217
-                new File("/dev/null"),
-                new File("/dev/nvhost-as-gpu"),
-                new File("/dev/nvhost-ctrl"), // b/9088251
-                new File("/dev/nvhost-ctrl-gpu"),
-                new File("/dev/nvhost-dbg-gpu"),
-                new File("/dev/nvhost-gpu"),
-                new File("/dev/nvhost-gr2d"), // b/9088251
-                new File("/dev/nvhost-gr3d"), // b/9088251
-                new File("/dev/nvhost-tsec"),
-                new File("/dev/nvhost-prof-gpu"),
-                new File("/dev/nvhost-vic"),
-                new File("/dev/nvmap"),       // b/9088251
-                new File("/dev/ptmx"),        // b/9088251
-                new File("/dev/pvrsrvkm"),    // b/9108170
-                new File("/dev/pvr_sync"),
-                new File("/dev/quadd"),
-                new File("/dev/random"),
-                new File("/dev/snfc_cen"),    // b/11142586
-                new File("/dev/snfc_hsel"),   // b/11142586
-                new File("/dev/snfc_intu_poll"), // b/11142586
-                new File("/dev/snfc_rfs"),    // b/11142586
-                new File("/dev/tegra-throughput"),
-                new File("/dev/tiler"),       // b/9108170
-                new File("/dev/tty"),
-                new File("/dev/urandom"),
-                new File("/dev/ump"),         // b/11142586
-                new File("/dev/xt_qtaguid"),  // b/9088251
-                new File("/dev/zero"),
-                new File("/dev/fimg2d"),      // b/10428016
-                new File("/dev/mobicore-user") // b/10428016
-            ));
-
-    public void testAllCharacterDevicesAreSecure() throws Exception {
-        Set<File> insecure = getAllInsecureDevicesInDirAndSubdir(new File("/dev"), FileUtils.S_IFCHR);
-        Set<File> insecurePts = getAllInsecureDevicesInDirAndSubdir(new File("/dev/pts"), FileUtils.S_IFCHR);
-        insecure.removeAll(CHAR_DEV_EXCEPTIONS);
-        insecure.removeAll(insecurePts);
-        assertTrue("Found insecure character devices: " + insecure.toString(),
-                insecure.isEmpty());
-    }
-
     public void testDevRandomWorldReadableAndWritable() throws Exception {
         File f = new File("/dev/random");
 
diff --git a/tests/tests/simpleperf/Android.mk b/tests/tests/simpleperf/Android.mk
index 040e153..e43b46a 100644
--- a/tests/tests/simpleperf/Android.mk
+++ b/tests/tests/simpleperf/Android.mk
@@ -14,23 +14,28 @@
 LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
 LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
 
-LOCAL_SHARED_LIBRARIES += \
-  libbacktrace \
-  libunwind \
-  libbase \
-  liblog \
-  libutils \
-  libLLVM \
-
 LOCAL_WHOLE_STATIC_LIBRARIES = \
   libsimpleperf_cts_test \
 
 LOCAL_STATIC_LIBRARIES += \
-  libgtest \
   libbacktrace_offline \
+  libbacktrace \
+  libunwind \
   libziparchive \
   libz \
+  libgtest \
+  libbase \
+  libcutils \
+  liblog \
+  libutils \
   liblzma \
+  libLLVMObject \
+  libLLVMBitReader \
+  libLLVMMC \
+  libLLVMMCParser \
+  libLLVMCore \
+  libLLVMSupport \
+  libc \
 
 LOCAL_POST_LINK_CMD =  \
   TMP_FILE=`mktemp $(OUT_DIR)/simpleperf-post-link-XXXXXXXXXX` && \
@@ -41,6 +46,8 @@
 LOCAL_COMPATIBILITY_SUITE := cts
 
 LOCAL_CTS_TEST_PACKAGE := android.simpleperf
+LOCAL_FORCE_STATIC_EXECUTABLE := true
+include $(LLVM_DEVICE_BUILD_MK)
 include $(BUILD_CTS_EXECUTABLE)
 
 
diff --git a/tools/cfassembler/Android.mk b/tools/cfassembler/Android.mk
index 8e0f351..df736ed 100644
--- a/tools/cfassembler/Android.mk
+++ b/tools/cfassembler/Android.mk
@@ -22,14 +22,9 @@
 LOCAL_IS_HOST_MODULE := true
 LOCAL_MODULE_CLASS := EXECUTABLES
 LOCAL_MODULE := cfassembler
-
-include $(BUILD_SYSTEM)/base_rules.mk
-
-$(LOCAL_BUILT_MODULE): $(HOST_OUT_JAVA_LIBRARIES)/cfassembler$(COMMON_JAVA_PACKAGE_SUFFIX)
-$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/etc/cfassembler | $(ACP)
-	@echo "Copy: $(PRIVATE_MODULE) ($@)"
-	$(copy-file-to-new-target)
-	$(hide) chmod 755 $@
+LOCAL_SRC_FILES := etc/cfassembler
+LOCAL_ADDITIONAL_DEPENDENCIES := $(HOST_OUT_JAVA_LIBRARIES)/cfassembler$(COMMON_JAVA_PACKAGE_SUFFIX)
+include $(BUILD_PREBUILT)
 
 INTERNAL_DALVIK_MODULES += $(LOCAL_INSTALLED_MODULE)
 
diff --git a/tools/cts-api-coverage/Android.mk b/tools/cts-api-coverage/Android.mk
index 2382d61..3f66961 100644
--- a/tools/cts-api-coverage/Android.mk
+++ b/tools/cts-api-coverage/Android.mk
@@ -14,25 +14,15 @@
 
 LOCAL_PATH := $(call my-dir)
 
-# We use copy-file-to-new-target so that the installed
-# script file's timestamp is at least as new as the
-# .jar file it wraps.
-
 # the hat script
 # ============================================================
 include $(CLEAR_VARS)
 LOCAL_IS_HOST_MODULE := true
 LOCAL_MODULE_CLASS := EXECUTABLES
 LOCAL_MODULE := cts-api-coverage
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SYSTEM)/base_rules.mk
-
-$(LOCAL_BUILT_MODULE): $(HOST_OUT_JAVA_LIBRARIES)/$(LOCAL_MODULE)$(COMMON_JAVA_PACKAGE_SUFFIX)
-$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/etc/$(LOCAL_MODULE) | $(ACP)
-	@echo "Copy: $(PRIVATE_MODULE) ($@)"
-	$(copy-file-to-new-target)
-	$(hide) chmod 755 $@
+LOCAL_SRC_FILES := etc/$(LOCAL_MODULE)
+LOCAL_ADDITIONAL_DEPENDENCIES := $(HOST_OUT_JAVA_LIBRARIES)/$(LOCAL_MODULE)$(COMMON_JAVA_PACKAGE_SUFFIX)
+include $(BUILD_PREBUILT)
 
 # the other stuff
 # ============================================================
diff --git a/tools/cts-java-scanner/Android.mk b/tools/cts-java-scanner/Android.mk
index 8b6c906..644f1c0 100644
--- a/tools/cts-java-scanner/Android.mk
+++ b/tools/cts-java-scanner/Android.mk
@@ -14,25 +14,15 @@
 
 LOCAL_PATH := $(call my-dir)
 
-# We use copy-file-to-new-target so that the installed
-# script file's timestamp is at least as new as the
-# .jar file it wraps.
-
 # the hat script
 # ============================================================
 include $(CLEAR_VARS)
 LOCAL_IS_HOST_MODULE := true
 LOCAL_MODULE_CLASS := EXECUTABLES
 LOCAL_MODULE := cts-java-scanner
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SYSTEM)/base_rules.mk
-
-$(LOCAL_BUILT_MODULE): $(HOST_OUT_JAVA_LIBRARIES)/$(LOCAL_MODULE)$(COMMON_JAVA_PACKAGE_SUFFIX)
-$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/etc/$(LOCAL_MODULE) | $(ACP)
-	@echo "Copy: $(PRIVATE_MODULE) ($@)"
-	$(copy-file-to-new-target)
-	$(hide) chmod 755 $@
+LOCAL_SRC_FILES := etc/$(LOCAL_MODULE)
+LOCAL_ADDITIONAL_DEPENDENCIES := $(HOST_OUT_JAVA_LIBRARIES)/$(LOCAL_MODULE)$(COMMON_JAVA_PACKAGE_SUFFIX)
+include $(BUILD_PREBUILT)
 
 # the other stuff
 # ============================================================
diff --git a/tools/cts-native-scanner/Android.mk b/tools/cts-native-scanner/Android.mk
index 8bcff1c..203b482 100644
--- a/tools/cts-native-scanner/Android.mk
+++ b/tools/cts-native-scanner/Android.mk
@@ -14,25 +14,15 @@
 
 LOCAL_PATH := $(call my-dir)
 
-# We use copy-file-to-new-target so that the installed
-# script file's timestamp is at least as new as the
-# .jar file it wraps.
-
 # the hat script
 # ============================================================
 include $(CLEAR_VARS)
 LOCAL_IS_HOST_MODULE := true
 LOCAL_MODULE_CLASS := EXECUTABLES
 LOCAL_MODULE := cts-native-scanner
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SYSTEM)/base_rules.mk
-
-$(LOCAL_BUILT_MODULE): $(HOST_OUT_JAVA_LIBRARIES)/$(LOCAL_MODULE)$(COMMON_JAVA_PACKAGE_SUFFIX)
-$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/etc/$(LOCAL_MODULE) | $(ACP)
-	@echo "Copy: $(PRIVATE_MODULE) ($@)"
-	$(copy-file-to-new-target)
-	$(hide) chmod 755 $@
+LOCAL_SRC_FILES := etc/$(LOCAL_MODULE)
+LOCAL_ADDITIONAL_DEPENDENCIES := $(HOST_OUT_JAVA_LIBRARIES)/$(LOCAL_MODULE)$(COMMON_JAVA_PACKAGE_SUFFIX)
+include $(BUILD_PREBUILT)
 
 # Build all sub-directories
 include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tools/cts-xml-generator/Android.mk b/tools/cts-xml-generator/Android.mk
index 5842dd8..23256f3 100644
--- a/tools/cts-xml-generator/Android.mk
+++ b/tools/cts-xml-generator/Android.mk
@@ -14,25 +14,15 @@
 
 LOCAL_PATH := $(call my-dir)
 
-# We use copy-file-to-new-target so that the installed
-# script file's timestamp is at least as new as the
-# .jar file it wraps.
-
 # the hat script
 # ============================================================
 include $(CLEAR_VARS)
 LOCAL_IS_HOST_MODULE := true
 LOCAL_MODULE_CLASS := EXECUTABLES
 LOCAL_MODULE := cts-xml-generator
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SYSTEM)/base_rules.mk
-
-$(LOCAL_BUILT_MODULE): $(HOST_OUT_JAVA_LIBRARIES)/$(LOCAL_MODULE)$(COMMON_JAVA_PACKAGE_SUFFIX)
-$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/etc/$(LOCAL_MODULE) | $(ACP)
-	@echo "Copy: $(PRIVATE_MODULE) ($@)"
-	$(copy-file-to-new-target)
-	$(hide) chmod 755 $@
+LOCAL_SRC_FILES := etc/$(LOCAL_MODULE)
+LOCAL_ADDITIONAL_DEPENDENCIES := $(HOST_OUT_JAVA_LIBRARIES)/$(LOCAL_MODULE)$(COMMON_JAVA_PACKAGE_SUFFIX)
+include $(BUILD_PREBUILT)
 
 # the other stuff
 # ============================================================
diff --git a/tools/dasm/Android.mk b/tools/dasm/Android.mk
index c18e677..1b1f328 100644
--- a/tools/dasm/Android.mk
+++ b/tools/dasm/Android.mk
@@ -22,14 +22,9 @@
 LOCAL_IS_HOST_MODULE := true
 LOCAL_MODULE_CLASS := EXECUTABLES
 LOCAL_MODULE := dasm
-
-include $(BUILD_SYSTEM)/base_rules.mk
-
-$(LOCAL_BUILT_MODULE): $(HOST_OUT_JAVA_LIBRARIES)/dasm$(COMMON_JAVA_PACKAGE_SUFFIX)
-$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/etc/dasm | $(ACP)
-	@echo "Copy: $(PRIVATE_MODULE) ($@)"
-	$(copy-file-to-new-target)
-	$(hide) chmod 755 $@
+LOCAL_SRC_FILES := etc/dasm
+LOCAL_ADDITIONAL_DEPENDENCIES := $(HOST_OUT_JAVA_LIBRARIES)/dasm$(COMMON_JAVA_PACKAGE_SUFFIX)
+include $(BUILD_PREBUILT)
 
 INTERNAL_DALVIK_MODULES += $(LOCAL_INSTALLED_MODULE)
 
diff --git a/tools/vm-tests-tf/Android.mk b/tools/vm-tests-tf/Android.mk
index ef6aa84..4a4e7ae 100644
--- a/tools/vm-tests-tf/Android.mk
+++ b/tools/vm-tests-tf/Android.mk
@@ -55,7 +55,6 @@
 #
 include $(CLEAR_VARS)
 
-LOCAL_JACK_ENABLED := $(strip $(LOCAL_JACK_ENABLED))
 LOCAL_MODULE := vm-tests-tf
 LOCAL_MODULE_CLASS := JAVA_LIBRARIES
 LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)
@@ -75,9 +74,7 @@
 
 $(LOCAL_BUILT_MODULE): PRIVATE_JACK_EXTRA_ARGS := $(LOCAL_JACK_EXTRA_ARGS)
 
-ifdef LOCAL_JACK_ENABLED
-    vmteststf_dep_jars += $(cts-tf-dalvik-lib.jack)
-endif
+vmteststf_dep_jars += $(cts-tf-dalvik-lib.jack)
 
 $(LOCAL_BUILT_MODULE): PRIVATE_SRC_FOLDER := $(LOCAL_PATH)/src
 $(LOCAL_BUILT_MODULE): PRIVATE_INTERMEDIATES_CLASSES := $(call intermediates-dir-for,JAVA_LIBRARIES,cts-tf-dalvik-buildutil,HOST)/classes
@@ -87,23 +84,6 @@
 $(LOCAL_BUILT_MODULE): PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES := $(intermediates)/hostjunit_files
 $(LOCAL_BUILT_MODULE): PRIVATE_CLASS_PATH := $(subst $(space),:,$(vmteststf_dep_jars)):$(HOST_JDK_TOOLS_JAR)
 $(LOCAL_BUILT_MODULE): PRIVATE_JACK_VERSION := $(LOCAL_JACK_VERSION)
-ifndef LOCAL_JACK_ENABLED
-$(LOCAL_BUILT_MODULE) : $(vmteststf_dep_jars) $(HOST_OUT_JAVA_LIBRARIES)/tradefed-prebuilt.jar
-	$(hide) rm -rf $(dir $@) && mkdir -p $(dir $@)
-	$(hide) mkdir -p $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES)/dot/junit $(dir $(PRIVATE_INTERMEDIATES_DEXCORE_JAR))
-	# generated and compile the host side junit tests
-	@echo "Write generated Main_*.java files to $(PRIVATE_INTERMEDIATES_MAIN_FILES)"
-	$(hide) java -cp $(PRIVATE_CLASS_PATH) util.build.BuildDalvikSuite $(PRIVATE_SRC_FOLDER) $(PRIVATE_INTERMEDIATES) \
-		$(HOST_OUT_JAVA_LIBRARIES)/cts-tf-dalvik-buildutil.jar:$(HOST_OUT_JAVA_LIBRARIES)/tradefed-prebuilt.jar \
-		$(PRIVATE_INTERMEDIATES_MAIN_FILES) $(PRIVATE_INTERMEDIATES_CLASSES) $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES) $$RUN_VM_TESTS_RTO
-	@echo "Generate $(PRIVATE_INTERMEDIATES_DEXCORE_JAR)"
-	$(hide) jar -cf $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jar \
-		$(addprefix -C $(PRIVATE_INTERMEDIATES_CLASSES) , dot/junit/DxUtil.class dot/junit/DxAbstractMain.class)
-	$(hide) $(DX) -JXms16M -JXmx768M --dex --output=$(PRIVATE_INTERMEDIATES_DEXCORE_JAR) \
-		$(if $(NO_OPTIMIZE_DX), --no-optimize) $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jar && rm -f $(PRIVATE_INTERMEDIATES_DEXCORE_JAR).jar
-	$(hide) cd $(PRIVATE_INTERMEDIATES_HOSTJUNIT_FILES)/classes && zip -q -r ../../$(notdir $@) .
-	$(hide) cd $(dir $@) && zip -q -r $(notdir $@) tests
-else # LOCAL_JACK_ENABLED
 oj_jack := $(call intermediates-dir-for,JAVA_LIBRARIES,core-oj,,COMMON)/classes.jack
 libart_jack := $(call intermediates-dir-for,JAVA_LIBRARIES,core-libart,,COMMON)/classes.jack
 $(LOCAL_BUILT_MODULE): PRIVATE_DALVIK_SUITE_CLASSPATH := $(oj_jack):$(libart_jack):$(cts-tf-dalvik-lib.jack):$(HOST_OUT_JAVA_LIBRARIES)/tradefed-prebuilt.jar
@@ -127,7 +107,6 @@
 	$(hide) cd $(dir $@) && zip -q -r $(notdir $@) tests
 oj_jack :=
 libart_jack :=
-endif # LOCAL_JACK_ENABLED
 
 # Clean up temp vars
 intermediates :=