Merge "Don't TEMP_FAILURE_RETRY on close."
diff --git a/Android.bp b/Android.bp
index d8a4f6a..4766b71 100644
--- a/Android.bp
+++ b/Android.bp
@@ -6,13 +6,13 @@
         "libaudio_system_headers",
         "libsystem_headers",
         "libcutils_headers",
-	"libbluetooth-types-header",
+        "libbluetooth-types-header",
     ],
     export_header_lib_headers: [
         "libaudio_system_headers",
         "libsystem_headers",
         "libcutils_headers",
-	"libbluetooth-types-header",
+        "libbluetooth-types-header",
     ],
 
     export_include_dirs: ["include"],
@@ -44,8 +44,3 @@
         support_system_process: true,
     },
 }
-
-subdirs = [
-    "modules/*",
-    "tests/*",
-]
diff --git a/Android.mk b/Android.mk
index 8744f46..d764008 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,3 +1,3 @@
 # Copyright 2006 The Android Open Source Project
 
-include $(call all-named-subdir-makefiles,modules tests)
+include $(call all-named-subdir-makefiles,modules)
diff --git a/modules/Android.mk b/modules/Android.mk
index 462081d..9d934c5 100644
--- a/modules/Android.mk
+++ b/modules/Android.mk
@@ -1,14 +1,5 @@
 hardware_modules := \
-    audio_remote_submix \
     camera \
     gralloc \
-    hwcomposer \
-    input \
-    radio \
-    sensors \
-    thermal \
-    usbaudio \
-    usbcamera \
-    vehicle \
-    vr
+    sensors
 include $(call all-named-subdir-makefiles,$(hardware_modules))
diff --git a/modules/audio_remote_submix/Android.bp b/modules/audio_remote_submix/Android.bp
new file mode 100644
index 0000000..c7d018c
--- /dev/null
+++ b/modules/audio_remote_submix/Android.bp
@@ -0,0 +1,34 @@
+// Copyright (C) 2012 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.
+
+cc_library_shared {
+    name: "audio.r_submix.default",
+    relative_install_path: "hw",
+    vendor: true,
+    srcs: ["audio_hw.cpp"],
+    include_dirs: [
+        "system/media/audio_utils/include",
+    ],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+        "libutils",
+        "libnbaio_mono",
+    ],
+    static_libs: ["libmedia_helper"],
+
+    cflags: ["-Wno-unused-parameter"],
+
+    header_libs: ["libhardware_headers"],
+}
diff --git a/modules/audio_remote_submix/Android.mk b/modules/audio_remote_submix/Android.mk
deleted file mode 100644
index 2f59f3a..0000000
--- a/modules/audio_remote_submix/Android.mk
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright (C) 2012 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 := audio.r_submix.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_PROPRIETARY_MODULE := true
-LOCAL_SRC_FILES := \
-	audio_hw.cpp
-LOCAL_C_INCLUDES += \
-	frameworks/av/include/ \
-	frameworks/native/include/ \
-	$(call include-path-for, audio-utils)
-LOCAL_SHARED_LIBRARIES := liblog libcutils libutils libnbaio_mono
-LOCAL_STATIC_LIBRARIES := libmedia_helper
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := -Wno-unused-parameter
-
-LOCAL_HEADER_LIBRARIES += libhardware_headers
-include $(BUILD_SHARED_LIBRARY)
-
diff --git a/modules/camera/3_0/Android.bp b/modules/camera/3_0/Android.bp
new file mode 100644
index 0000000..6d6d1d7
--- /dev/null
+++ b/modules/camera/3_0/Android.bp
@@ -0,0 +1,47 @@
+// Copyright (C) 2012 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.
+
+cc_library_shared {
+    name: "camera.default",
+    relative_install_path: "hw",
+
+    include_dirs: [
+        "system/core/include",
+        "system/media/camera/include",
+    ],
+
+    srcs: [
+        "CameraHAL.cpp",
+        "Camera.cpp",
+        "ExampleCamera.cpp",
+        "Metadata.cpp",
+        "Stream.cpp",
+        "VendorTags.cpp",
+    ],
+
+    shared_libs: [
+        "libcamera_metadata",
+        "libcutils",
+        "liblog",
+        "libsync",
+        "libutils",
+    ],
+
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+        "-fvisibility=hidden",
+    ],
+}
diff --git a/modules/camera/3_0/Android.mk b/modules/camera/3_0/Android.mk
deleted file mode 100644
index 3071a03..0000000
--- a/modules/camera/3_0/Android.mk
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright (C) 2012 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 := camera.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-
-LOCAL_C_INCLUDES += \
-	system/core/include \
-	system/media/camera/include \
-
-LOCAL_SRC_FILES := \
-	CameraHAL.cpp \
-	Camera.cpp \
-	ExampleCamera.cpp \
-	Metadata.cpp \
-	Stream.cpp \
-	VendorTags.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-	libcamera_metadata \
-	libcutils \
-	liblog \
-	libsync \
-	libutils \
-
-LOCAL_CFLAGS += -Wall -Wextra -Werror -fvisibility=hidden
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/camera/3_4/Android.mk b/modules/camera/3_4/Android.mk
index d4201ba..05ddf5a 100644
--- a/modules/camera/3_4/Android.mk
+++ b/modules/camera/3_4/Android.mk
@@ -32,7 +32,7 @@
 
 v4l2_static_libs :=
 
-v4l2_cflags := -fno-short-enums -Wall -Wextra -fvisibility=hidden
+v4l2_cflags := -fno-short-enums -Wall -Wno-error -Wextra -fvisibility=hidden
 
 v4l2_c_includes := $(call include-path-for, camera)
 
diff --git a/modules/gralloc/framebuffer.cpp b/modules/gralloc/framebuffer.cpp
index 7ef8098..9796457 100644
--- a/modules/gralloc/framebuffer.cpp
+++ b/modules/gralloc/framebuffer.cpp
@@ -63,35 +63,17 @@
 static int fb_setSwapInterval(struct framebuffer_device_t* dev,
             int interval)
 {
-    fb_context_t* ctx = (fb_context_t*)dev;
     if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval)
         return -EINVAL;
     // FIXME: implement fb_setSwapInterval
     return 0;
 }
 
-static int fb_setUpdateRect(struct framebuffer_device_t* dev,
-        int l, int t, int w, int h)
-{
-    if (((w|h) <= 0) || ((l|t)<0))
-        return -EINVAL;
-        
-    fb_context_t* ctx = (fb_context_t*)dev;
-    private_module_t* m = reinterpret_cast<private_module_t*>(
-            dev->common.module);
-    m->info.reserved[0] = 0x54445055; // "UPDT";
-    m->info.reserved[1] = (uint16_t)l | ((uint32_t)t << 16);
-    m->info.reserved[2] = (uint16_t)(l+w) | ((uint32_t)(t+h) << 16);
-    return 0;
-}
-
 static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer)
 {
     if (private_handle_t::validate(buffer) < 0)
         return -EINVAL;
 
-    fb_context_t* ctx = (fb_context_t*)dev;
-
     private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(buffer);
     private_module_t* m = reinterpret_cast<private_module_t*>(
             dev->common.module);
@@ -279,7 +261,6 @@
      * map the framebuffer
      */
 
-    int err;
     size_t fbSize = roundUpToPageSize(finfo.line_length * info.yres_virtual);
     module->framebuffer = new private_handle_t(dup(fd), fbSize, 0);
 
diff --git a/modules/hwcomposer/Android.bp b/modules/hwcomposer/Android.bp
new file mode 100644
index 0000000..4f429be
--- /dev/null
+++ b/modules/hwcomposer/Android.bp
@@ -0,0 +1,32 @@
+// Copyright (C) 2008 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.
+
+// HAL module implemenation stored in
+// hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
+cc_library_shared {
+    name: "hwcomposer.default",
+    relative_install_path: "hw",
+    vendor: true,
+    shared_libs: [
+        "liblog",
+        "libEGL",
+    ],
+    srcs: ["hwcomposer.cpp"],
+    header_libs: ["libhardware_headers"],
+    cflags: [
+        "-DLOG_TAG=\"hwcomposer\"",
+        "-Wall",
+        "-Werror",
+    ],
+}
diff --git a/modules/hwcomposer/Android.mk b/modules/hwcomposer/Android.mk
deleted file mode 100644
index a179eac..0000000
--- a/modules/hwcomposer/Android.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-# Copyright (C) 2008 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)
-
-# HAL module implemenation stored in
-# hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_PROPRIETARY_MODULE := true
-LOCAL_SHARED_LIBRARIES := liblog libEGL
-LOCAL_SRC_FILES := hwcomposer.cpp
-LOCAL_HEADER_LIBRARIES := libhardware_headers
-LOCAL_MODULE := hwcomposer.default
-LOCAL_CFLAGS:= -DLOG_TAG=\"hwcomposer\"
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS += -Wall -Werror
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/input/Android.mk b/modules/input/Android.mk
deleted file mode 100644
index 3011b2e..0000000
--- a/modules/input/Android.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright (C) 2015 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)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/modules/input/evdev/Android.bp b/modules/input/evdev/Android.bp
new file mode 100644
index 0000000..26e711f
--- /dev/null
+++ b/modules/input/evdev/Android.bp
@@ -0,0 +1,60 @@
+// Copyright (C) 2015 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.
+
+// Evdev module implementation
+cc_library_shared {
+    name: "libinput_evdev",
+
+    srcs: [
+        "BitUtils.cpp",
+        "InputHub.cpp",
+        "InputDevice.cpp",
+        "InputDeviceManager.cpp",
+        "InputHost.cpp",
+        "InputMapper.cpp",
+        "MouseInputMapper.cpp",
+        "SwitchInputMapper.cpp",
+    ],
+
+    shared_libs: [
+        "libhardware_legacy",
+        "liblog",
+        "libutils",
+    ],
+
+    export_include_dirs: ["."],
+
+    cppflags: [
+        "-Wno-unused-parameter",
+    ],
+}
+
+// HAL module
+cc_library_shared {
+    name: "input.evdev.default",
+    relative_install_path: "hw",
+
+    srcs: ["EvdevModule.cpp"],
+
+    shared_libs: [
+        "libinput_evdev",
+        "liblog",
+    ],
+
+    cppflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+    ],
+}
diff --git a/modules/input/evdev/Android.mk b/modules/input/evdev/Android.mk
deleted file mode 100644
index 8c391b2..0000000
--- a/modules/input/evdev/Android.mk
+++ /dev/null
@@ -1,61 +0,0 @@
-# Copyright (C) 2015 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)
-
-# Evdev module implementation
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    BitUtils.cpp \
-    InputHub.cpp \
-    InputDevice.cpp \
-    InputDeviceManager.cpp \
-    InputHost.cpp \
-    InputMapper.cpp \
-    MouseInputMapper.cpp \
-    SwitchInputMapper.cpp
-
-LOCAL_SHARED_LIBRARIES := \
-    libhardware_legacy \
-    liblog \
-    libutils
-
-LOCAL_CLANG := true
-LOCAL_CPPFLAGS += -Wno-unused-parameter
-
-LOCAL_MODULE := libinput_evdev
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
-
-# HAL module
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := input.evdev.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-
-LOCAL_SRC_FILES := \
-    EvdevModule.cpp
-
-LOCAL_SHARED_LIBRARIES := \
-    libinput_evdev \
-    liblog
-
-LOCAL_CLANG := true
-LOCAL_CPPFLAGS += -Wall -Werror -Wno-unused-parameter
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/input/evdev/InputHub.cpp b/modules/input/evdev/InputHub.cpp
index e2c65fa..af7b28e 100644
--- a/modules/input/evdev/InputHub.cpp
+++ b/modules/input/evdev/InputHub.cpp
@@ -66,20 +66,6 @@
     }
 }
 
-static bool processHasCapability(int capability) {
-    LOG_ALWAYS_FATAL_IF(!cap_valid(capability), "invalid linux capability: %d", capability);
-    struct __user_cap_header_struct cap_header_data;
-    struct __user_cap_data_struct cap_data_data[2];
-    cap_user_header_t caphdr = &cap_header_data;
-    cap_user_data_t capdata = cap_data_data;
-    caphdr->pid = 0;
-    caphdr->version = _LINUX_CAPABILITY_VERSION_3;
-    LOG_ALWAYS_FATAL_IF(capget(caphdr, capdata) != 0,
-            "Could not get process capabilities. errno=%d", errno);
-    int idx = CAP_TO_INDEX(capability);
-    return capdata[idx].effective & CAP_TO_MASK(capability);
-}
-
 class EvdevDeviceNode : public InputDeviceNode {
 public:
     static EvdevDeviceNode* openDeviceNode(const std::string& path);
@@ -691,7 +677,6 @@
     }
 
     size_t event_pos = 0;
-    nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
     while (res >= static_cast<int>(sizeof(*event))) {
         event = reinterpret_cast<struct inotify_event*>(event_buf + event_pos);
         if (event->len) {
diff --git a/modules/input/evdev/InputHub.h b/modules/input/evdev/InputHub.h
index 1abdc09..827cbde 100644
--- a/modules/input/evdev/InputHub.h
+++ b/modules/input/evdev/InputHub.h
@@ -213,8 +213,6 @@
     int mEpollFd;
     int mINotifyFd;
     int mWakeEventFd;
-    int mWakeReadPipeFd;
-    int mWakeWritePipeFd;
 
     // Callback for input events
     std::shared_ptr<InputCallbackInterface> mInputCallback;
diff --git a/modules/input/evdev/MouseInputMapper.h b/modules/input/evdev/MouseInputMapper.h
index 1f8bc06..73eab98 100644
--- a/modules/input/evdev/MouseInputMapper.h
+++ b/modules/input/evdev/MouseInputMapper.h
@@ -45,8 +45,6 @@
     int32_t mRelX = 0;
     int32_t mRelY = 0;
 
-    bool mHaveRelWheel = false;
-    bool mHaveRelHWheel = false;
     int32_t mRelWheel = 0;
     int32_t mRelHWheel = 0;
 };
diff --git a/modules/sensors/Android.bp b/modules/sensors/Android.bp
index f39ba52..3d14bdf 100644
--- a/modules/sensors/Android.bp
+++ b/modules/sensors/Android.bp
@@ -3,7 +3,7 @@
     vendor: true,
     srcs: [
         "multihal.cpp",
-        "SensorEventQueue.cpp"
+        "SensorEventQueue.cpp",
     ],
     header_libs: [
         "libhardware_headers",
@@ -12,8 +12,28 @@
         "liblog",
         "libcutils",
         "libutils",
-        "libdl"
+        "libdl",
     ],
     export_include_dirs: ["."],
-    cflags: ["-Wall", "-Werror"],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+}
+
+cc_test_host {
+    name: "sensorstests",
+    gtest: false,
+    srcs: [
+        "SensorEventQueue.cpp",
+        "tests/SensorEventQueue_test.cpp",
+    ],
+    static_libs: [
+        "libcutils",
+        "libutils",
+    ],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
 }
diff --git a/modules/sensors/Android.mk b/modules/sensors/Android.mk
index f0045af..bc6a21b 100644
--- a/modules/sensors/Android.mk
+++ b/modules/sensors/Android.mk
@@ -45,5 +45,3 @@
 include $(BUILD_SHARED_LIBRARY)
 
 endif # USE_SENSOR_MULTI_HAL
-
-include $(call all-makefiles-under, $(LOCAL_PATH))
diff --git a/modules/sensors/dynamic_sensor/Android.bp b/modules/sensors/dynamic_sensor/Android.bp
new file mode 100644
index 0000000..214d97c
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/Android.bp
@@ -0,0 +1,134 @@
+// 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.
+
+cc_defaults {
+    name: "dynamic_sensor_defaults",
+
+    // intended to be integrated into hal, thus vendor
+    vendor: true,
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+    ],
+    export_include_dirs: ["."],
+
+    shared_libs: [
+        "libhidparser",
+    ],
+
+    target: {
+        android: {
+            srcs: [
+                "BaseDynamicSensorDaemon.cpp",
+                "BaseSensorObject.cpp",
+                "ConnectionDetector.cpp",
+                "DummyDynamicAccelDaemon.cpp",
+                "DynamicSensorManager.cpp",
+                "HidRawDevice.cpp",
+                "HidRawSensor.cpp",
+                "HidRawSensorDaemon.cpp",
+                "HidRawSensorDevice.cpp",
+                "RingBuffer.cpp",
+            ],
+            shared_libs: [
+                "libbase",
+                "libcutils",
+                "liblog",
+                "libutils",
+            ],
+            header_libs: [
+                "libhardware_headers",
+                "libstagefright_foundation_headers",
+            ],
+        },
+
+        host: {
+            local_include_dirs: [
+                "test",
+                "HidUtils/test",
+            ],
+        },
+
+        // host test is targeting linux host only
+        darwin: {
+            enabled: false,
+        },
+    },
+}
+
+//
+// There are two ways to utilize the dynamic sensor module:
+//   1. Use as an extension in an existing hal: declare dependency on libdynamic_sensor_ext shared
+//      library in existing sensor hal.
+//   2. Use as a standalone sensor HAL and configure multihal to combine it with sensor hal that
+//      hosts other sensors: add dependency on sensors.dynamic_sensor_hal in device level makefile and
+//      write multihal configuration file accordingly.
+//
+// Please take only one of these two options to avoid conflict over hardware resource.
+//
+//
+// Option 1: sensor extension module
+//
+cc_library_shared {
+    name: "libdynamic_sensor_ext",
+    defaults: ["dynamic_sensor_defaults"],
+
+    cflags: ["-DLOG_TAG=\"DynamicSensorExt\""],
+}
+
+//
+// Option 2: independent sensor hal
+//
+cc_library_shared {
+    name: "sensors.dynamic_sensor_hal",
+    defaults: ["dynamic_sensor_defaults"],
+    relative_install_path: "hw",
+
+    cflags: ["-DLOG_TAG=\"DynamicSensorHal\""],
+
+    srcs: ["sensors.cpp"],
+}
+
+//
+// Host test for HidRawSensor. Test with dummy test HID descriptors.
+//
+cc_binary_host {
+    name: "hidrawsensor_host_test",
+    defaults: ["dynamic_sensor_defaults"],
+
+    srcs: [
+        "HidRawSensor.cpp",
+        "BaseSensorObject.cpp",
+        "HidUtils/test/TestHidDescriptor.cpp",
+        "test/HidRawSensorTest.cpp",
+    ],
+}
+
+//
+// Host test for HidRawDevice and HidRawSensor. Test with hidraw
+// device node.
+//
+cc_binary_host {
+    name: "hidrawdevice_host_test",
+    defaults: ["dynamic_sensor_defaults"],
+
+    srcs: [
+        "HidRawDevice.cpp",
+        "HidRawSensor.cpp",
+        "BaseSensorObject.cpp",
+        "test/HidRawDeviceTest.cpp",
+    ],
+}
diff --git a/modules/sensors/dynamic_sensor/Android.mk b/modules/sensors/dynamic_sensor/Android.mk
deleted file mode 100644
index 52809dc..0000000
--- a/modules/sensors/dynamic_sensor/Android.mk
+++ /dev/null
@@ -1,138 +0,0 @@
-# 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)
-COMMON_CFLAGS := -Wall -Werror -Wextra
-
-dynamic_sensor_src := \
-    BaseDynamicSensorDaemon.cpp \
-    BaseSensorObject.cpp \
-    ConnectionDetector.cpp \
-    DummyDynamicAccelDaemon.cpp \
-    DynamicSensorManager.cpp \
-    HidRawDevice.cpp \
-    HidRawSensor.cpp \
-    HidRawSensorDaemon.cpp \
-    HidRawSensorDevice.cpp \
-    RingBuffer.cpp
-
-dynamic_sensor_shared_lib := \
-    libbase \
-    libcutils \
-    libhidparser \
-    liblog \
-    libutils
-#
-# There are two ways to utilize the dynamic sensor module:
-#   1. Use as an extension in an existing hal: declare dependency on libdynamic_sensor_ext shared
-#      library in existing sensor hal.
-#   2. Use as a standalone sensor HAL and configure multihal to combine it with sensor hal that
-#      hosts other sensors: add dependency on sensors.dynamic_sensor_hal in device level makefile and
-#      write multihal configuration file accordingly.
-#
-# Please take only one of these two options to avoid conflict over hardware resource.
-#
-#
-# Option 1: sensor extension module
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := libdynamic_sensor_ext
-LOCAL_MODULE_TAGS := optional
-# intended to be integrated into hal, thus proprietary
-LOCAL_PROPRIETARY_MODULE := true
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS) -DLOG_TAG=\"DynamicSensorExt\"
-
-LOCAL_SRC_FILES := $(dynamic_sensor_src)
-
-LOCAL_HEADER_LIBRARIES := \
-    libhardware_headers \
-    libstagefright_foundation_headers \
-
-LOCAL_SHARED_LIBRARIES := $(dynamic_sensor_shared_lib)
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-
-include $(BUILD_SHARED_LIBRARY)
-
-#
-# Option 2: independent sensor hal
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := sensors.dynamic_sensor_hal
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_MODULE_TAGS := optional
-# hal module, thus proprietary
-LOCAL_PROPRIETARY_MODULE := true
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS) -DLOG_TAG=\"DynamicSensorHal\"
-
-LOCAL_SRC_FILES := $(dynamic_sensor_src) sensors.cpp
-
-LOCAL_HEADER_LIBRARIES := \
-    libhardware_headers \
-    libstagefright_foundation_headers \
-
-LOCAL_SHARED_LIBRARIES := $(dynamic_sensor_shared_lib)
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-
-include $(BUILD_SHARED_LIBRARY)
-
-#
-# Host test for HidRawSensor. Test with dummy test HID descriptors.
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := hidrawsensor_host_test
-LOCAL_MODULE_TAGS := optional
-# host test is targeting linux host only
-LOCAL_MODULE_HOST_OS := linux
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS)
-
-LOCAL_SRC_FILES := \
-    HidRawSensor.cpp \
-    BaseSensorObject.cpp \
-    HidUtils/test/TestHidDescriptor.cpp \
-    test/HidRawSensorTest.cpp
-
-LOCAL_SHARED_LIBRARIES := libhidparser_host
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/test $(LOCAL_PATH)/HidUtils/test
-include $(BUILD_HOST_EXECUTABLE)
-
-#
-# Host test for HidRawDevice and HidRawSensor. Test with hidraw
-# device node.
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := hidrawdevice_host_test
-LOCAL_MODULE_TAGS := optional
-# host test is targeting linux host only
-LOCAL_MODULE_HOST_OS := linux
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS)
-
-LOCAL_SRC_FILES := \
-    HidRawDevice.cpp \
-    HidRawSensor.cpp \
-    BaseSensorObject.cpp \
-    test/HidRawDeviceTest.cpp
-
-LOCAL_SHARED_LIBRARIES := libhidparser_host
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/test $(LOCAL_PATH)/HidUtils/test
-include $(BUILD_HOST_EXECUTABLE)
-
-include $(LOCAL_PATH)/HidUtils/Android.mk
diff --git a/modules/sensors/dynamic_sensor/HidUtils/Android.bp b/modules/sensors/dynamic_sensor/HidUtils/Android.bp
new file mode 100644
index 0000000..0eb43f8
--- /dev/null
+++ b/modules/sensors/dynamic_sensor/HidUtils/Android.bp
@@ -0,0 +1,92 @@
+// 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.
+
+cc_defaults {
+    name: "hid_defaults",
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+    ],
+}
+
+cc_library {
+    name: "libhidparser",
+    defaults: ["hid_defaults"],
+    host_supported: true,
+
+    // indended to be used by hal components, thus vendor
+    vendor: true,
+
+    srcs: [
+        "HidGlobal.cpp",
+        "HidItem.cpp",
+        "HidLocal.cpp",
+        "HidParser.cpp",
+        "HidReport.cpp",
+        "HidTree.cpp",
+    ],
+    export_include_dirs: ["."],
+
+    target: {
+        android: {
+            cflags: ["-DLOG_TAG=\"HidUtil\""],
+            shared_libs: ["libbase"],
+        },
+    },
+}
+
+//
+// Example of HidParser
+//
+cc_binary_host {
+    name: "hidparser_example",
+    defaults: ["hid_defaults"],
+
+    srcs: [
+        "test/HidParserExample.cpp",
+        "test/TestHidDescriptor.cpp",
+    ],
+    static_libs: ["libhidparser"],
+
+    local_include_dirs: ["test"],
+}
+
+//
+// Another example of HidParser
+//
+cc_binary_host {
+    name: "hidparser_example2",
+    defaults: ["hid_defaults"],
+
+    srcs: [
+        "test/HidParserExample2.cpp",
+        "test/TestHidDescriptor.cpp",
+    ],
+    static_libs: ["libhidparser"],
+
+    local_include_dirs: ["test"],
+}
+
+//
+// Test for TriState template
+//
+cc_test_host {
+    name: "tristate_test",
+    defaults: ["hid_defaults"],
+
+    srcs: ["test/TriStateTest.cpp"],
+
+    local_include_dirs: ["test"],
+}
diff --git a/modules/sensors/dynamic_sensor/HidUtils/Android.mk b/modules/sensors/dynamic_sensor/HidUtils/Android.mk
deleted file mode 100644
index 5a1d890..0000000
--- a/modules/sensors/dynamic_sensor/HidUtils/Android.mk
+++ /dev/null
@@ -1,99 +0,0 @@
-# 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)
-COMMON_CFLAGS := -Wall -Werror -Wextra
-
-hidparser_src := \
-    HidGlobal.cpp \
-    HidItem.cpp \
-    HidLocal.cpp \
-    HidParser.cpp \
-    HidReport.cpp \
-    HidTree.cpp
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := libhidparser
-LOCAL_MODULE_TAGS := optional
-# indended to be used by hal components, thus propietary
-LOCAL_PROPRIETARY_MODULE := true
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS) -DLOG_TAG=\"HidUtil\"
-LOCAL_SRC_FILES := $(hidparser_src)
-LOCAL_SHARED_LIBRARIES := libbase
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-include $(BUILD_SHARED_LIBRARY)
-
-#
-# host side shared library (for host test, example, etc)
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := libhidparser_host
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS)
-
-LOCAL_SRC_FILES := $(hidparser_src)
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)
-include $(BUILD_HOST_SHARED_LIBRARY)
-
-#
-# Example of HidParser
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := hidparser_example
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS)
-LOCAL_SRC_FILES := \
-    $(hidparser_src) \
-    test/HidParserExample.cpp \
-    test/TestHidDescriptor.cpp
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/test
-include $(BUILD_HOST_EXECUTABLE)
-
-#
-# Another example of HidParser
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := hidparser_example2
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS)
-LOCAL_SRC_FILES := \
-    $(hidparser_src) \
-    test/HidParserExample2.cpp \
-    test/TestHidDescriptor.cpp
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/test
-include $(BUILD_HOST_EXECUTABLE)
-
-#
-# Test for TriState template
-#
-include $(CLEAR_VARS)
-LOCAL_MODULE := tristate_test
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += $(COMMON_CFLAGS)
-LOCAL_SRC_FILES := test/TriStateTest.cpp
-
-LOCAL_STATIC_LIBRARIES := \
-     libgtest \
-     libgtest_main
-
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/test
-include $(BUILD_HOST_NATIVE_TEST)
diff --git a/modules/sensors/tests/Android.mk b/modules/sensors/tests/Android.mk
deleted file mode 100644
index dcf4f24..0000000
--- a/modules/sensors/tests/Android.mk
+++ /dev/null
@@ -1,17 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-	SensorEventQueue_test.cpp
-
-LOCAL_CFLAGS := -Wall -Werror
-LOCAL_MODULE := sensorstests
-
-LOCAL_STATIC_LIBRARIES := libcutils libutils
-
-LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. bionic
-
-LOCAL_LDLIBS += -lpthread
-
-include $(BUILD_HOST_EXECUTABLE)
diff --git a/modules/sensors/tests/SensorEventQueue_test.cpp b/modules/sensors/tests/SensorEventQueue_test.cpp
index d3d75ee..07db4c0 100644
--- a/modules/sensors/tests/SensorEventQueue_test.cpp
+++ b/modules/sensors/tests/SensorEventQueue_test.cpp
@@ -4,14 +4,14 @@
 #include <pthread.h>
 #include <cutils/atomic.h>
 
-#include "SensorEventQueue.cpp"
+#include "SensorEventQueue.h"
 
 // Unit tests for the SensorEventQueue.
 
 // Run it like this:
 //
-// make sensorstests -j32 && \
-// out/host/linux-x86/obj/EXECUTABLES/sensorstests_intermediates/sensorstests
+// m sensorstests && \
+// out/host/linux-x86/nativetest64/sensorstests/sensorstests
 
 bool checkWritableBufferSize(SensorEventQueue* queue, int requested, int expected) {
     sensors_event_t* buffer;
diff --git a/modules/soundtrigger/Android.bp b/modules/soundtrigger/Android.bp
new file mode 100644
index 0000000..aa5e804
--- /dev/null
+++ b/modules/soundtrigger/Android.bp
@@ -0,0 +1,32 @@
+// Copyright (C) 2011 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.
+
+// Stub sound_trigger HAL module, used for tests
+cc_library_shared {
+    name: "sound_trigger.stub.default",
+    relative_install_path: "hw",
+    vendor: true,
+    srcs: ["sound_trigger_hw.c"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+    ],
+    header_libs: ["libhardware_headers"],
+    cflags: [
+        "-Wno-error=incompatible-pointer-types",
+        "-Wno-unused-function",
+        "-Wno-unused-parameter",
+        "-Wno-unused-variable",
+    ],
+}
diff --git a/modules/soundtrigger/Android.mk b/modules/soundtrigger/Android.mk
deleted file mode 100644
index 8250f9b..0000000
--- a/modules/soundtrigger/Android.mk
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (C) 2011 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)
-
-# Stub sound_trigger HAL module, used for tests
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := sound_trigger.stub.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_PROPRIETARY_MODULE := true
-LOCAL_SRC_FILES := sound_trigger_hw.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/thermal/Android.bp b/modules/thermal/Android.bp
new file mode 100644
index 0000000..ab5c408
--- /dev/null
+++ b/modules/thermal/Android.bp
@@ -0,0 +1,27 @@
+// Copyright (C) 2015 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.
+
+cc_library_shared {
+    name: "thermal.default",
+    relative_install_path: "hw",
+    vendor: true,
+    srcs: ["thermal.c"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+        "libutils",
+    ],
+    header_libs: ["libhardware_headers"],
+    cflags: ["-Wno-unused-parameter"],
+}
diff --git a/modules/thermal/Android.mk b/modules/thermal/Android.mk
deleted file mode 100644
index 1ad55d8..0000000
--- a/modules/thermal/Android.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-# Copyright (C) 2015 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 := thermal.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_PROPRIETARY_MODULE := true
-LOCAL_SRC_FILES := thermal.c
-LOCAL_SHARED_LIBRARIES := liblog libcutils libutils
-LOCAL_HEADER_LIBRARIES := libhardware_headers
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := -Wno-unused-parameter
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/usbaudio/Android.bp b/modules/usbaudio/Android.bp
new file mode 100644
index 0000000..c7d403f
--- /dev/null
+++ b/modules/usbaudio/Android.bp
@@ -0,0 +1,29 @@
+// Copyright (C) 2012 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.
+
+cc_library_shared {
+    name: "audio.usb.default",
+    relative_install_path: "hw",
+    vendor: true,
+    srcs: ["audio_hal.c"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+        "libtinyalsa",
+        "libaudioutils",
+        "libalsautils",
+    ],
+    cflags: ["-Wno-unused-parameter"],
+    header_libs: ["libhardware_headers"],
+}
diff --git a/modules/usbaudio/Android.mk b/modules/usbaudio/Android.mk
deleted file mode 100644
index 6c8a98f..0000000
--- a/modules/usbaudio/Android.mk
+++ /dev/null
@@ -1,34 +0,0 @@
-# Copyright (C) 2012 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 := audio.usb.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_PROPRIETARY_MODULE := true
-LOCAL_SRC_FILES := \
-	audio_hal.c
-LOCAL_C_INCLUDES += \
-	external/tinyalsa/include \
-	$(call include-path-for, audio-utils) \
-	$(call include-path-for, alsa-utils)
-LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa libaudioutils libalsautils
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := -Wno-unused-parameter
-
-LOCAL_HEADER_LIBRARIES += libhardware_headers
-include $(BUILD_SHARED_LIBRARY)
-
diff --git a/modules/usbcamera/Android.bp b/modules/usbcamera/Android.bp
new file mode 100644
index 0000000..5e44d3c
--- /dev/null
+++ b/modules/usbcamera/Android.bp
@@ -0,0 +1,42 @@
+// Copyright (C) 2015 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.
+
+cc_library_shared {
+    name: "camera.usb.default",
+    relative_install_path: "hw",
+
+    srcs: [
+        "CameraHAL.cpp",
+        "Camera.cpp",
+        "UsbCamera.cpp",
+        "Metadata.cpp",
+        "Stream.cpp",
+        "HotplugThread.cpp",
+    ],
+
+    shared_libs: [
+        "libcamera_metadata",
+        "libcutils",
+        "liblog",
+        "libsync",
+        "libutils",
+    ],
+
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+        "-fvisibility=hidden",
+    ],
+}
diff --git a/modules/usbcamera/Android.mk b/modules/usbcamera/Android.mk
deleted file mode 100644
index 6a36ac4..0000000
--- a/modules/usbcamera/Android.mk
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright (C) 2015 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 := camera.usb.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-
-LOCAL_C_INCLUDES += \
-	system/core/include \
-	system/media/camera/include \
-
-LOCAL_SRC_FILES := \
-	CameraHAL.cpp \
-	Camera.cpp \
-	UsbCamera.cpp \
-	Metadata.cpp \
-	Stream.cpp \
-	HotplugThread.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-	libcamera_metadata \
-	libcutils \
-	liblog \
-	libsync \
-	libutils \
-
-LOCAL_CFLAGS += -Wall -Wextra -Werror -fvisibility=hidden
-
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/vehicle/Android.bp b/modules/vehicle/Android.bp
new file mode 100644
index 0000000..cb0406a
--- /dev/null
+++ b/modules/vehicle/Android.bp
@@ -0,0 +1,34 @@
+// Copyright (C) 2012 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.
+
+cc_library_shared {
+    name: "vehicle.default",
+
+    relative_install_path: "hw",
+    vendor: true,
+    srcs: [
+        "vehicle.c",
+        "timeUtil.cpp",
+    ],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+    header_libs: ["libhardware_headers"],
+    shared_libs: [
+        "liblog",
+        "libcutils",
+        "libutils",
+    ],
+}
diff --git a/modules/vehicle/Android.mk b/modules/vehicle/Android.mk
deleted file mode 100644
index ad2e527..0000000
--- a/modules/vehicle/Android.mk
+++ /dev/null
@@ -1,30 +0,0 @@
-# Copyright (C) 2012 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 := vehicle.default
-
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_PROPRIETARY_MODULE := true
-LOCAL_SRC_FILES := vehicle.c timeUtil.cpp
-LOCAL_CFLAGS := -Wall -Werror
-LOCAL_HEADER_LIBRARIES := libhardware_headers
-LOCAL_SHARED_LIBRARIES := liblog libcutils libutils
-LOCAL_MODULE_TAGS := optional
-
-include $(BUILD_SHARED_LIBRARY)
-
diff --git a/modules/vr/Android.bp b/modules/vr/Android.bp
new file mode 100644
index 0000000..40f4510
--- /dev/null
+++ b/modules/vr/Android.bp
@@ -0,0 +1,28 @@
+// 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.
+
+cc_library_shared {
+    name: "vr.default",
+    relative_install_path: "hw",
+    vendor: true,
+    srcs: ["vr.c"],
+    header_libs: ["libhardware_headers"],
+    shared_libs: ["libcutils"],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+    ],
+}
diff --git a/modules/vr/Android.mk b/modules/vr/Android.mk
deleted file mode 100644
index 2cdcb1b..0000000
--- a/modules/vr/Android.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-# 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 := vr.default
-LOCAL_MODULE_RELATIVE_PATH := hw
-LOCAL_PROPRIETARY_MODULE := true
-LOCAL_SRC_FILES := vr.c
-LOCAL_HEADER_LIBRARIES := libhardware_headers
-LOCAL_SHARED_LIBRARIES := libcutils
-LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS += -Wall -Werror -Wno-unused-parameter
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/tests/Android.mk b/tests/Android.mk
deleted file mode 100644
index 5053e7d..0000000
--- a/tests/Android.mk
+++ /dev/null
@@ -1 +0,0 @@
-include $(call all-subdir-makefiles)
diff --git a/tests/camera3/Android.bp b/tests/camera3/Android.bp
new file mode 100644
index 0000000..55486ba
--- /dev/null
+++ b/tests/camera3/Android.bp
@@ -0,0 +1,16 @@
+cc_test {
+    name: "camera3_tests",
+    srcs: ["camera3tests.cpp"],
+
+    shared_libs: [
+        "liblog",
+        "libhardware",
+        "libcamera_metadata",
+    ],
+
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+    ],
+}
diff --git a/tests/camera3/Android.mk b/tests/camera3/Android.mk
deleted file mode 100644
index fbfde68..0000000
--- a/tests/camera3/Android.mk
+++ /dev/null
@@ -1,20 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    camera3tests.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-    liblog \
-    libhardware \
-    libcamera_metadata \
-
-LOCAL_C_INCLUDES += \
-    system/media/camera/include \
-
-LOCAL_CFLAGS += -Wall -Wextra -Werror
-
-LOCAL_MODULE:= camera3_tests
-LOCAL_MODULE_TAGS := tests
-
-include $(BUILD_NATIVE_TEST)
diff --git a/tests/hardware/Android.bp b/tests/hardware/Android.bp
new file mode 100644
index 0000000..2f5db12
--- /dev/null
+++ b/tests/hardware/Android.bp
@@ -0,0 +1,16 @@
+cc_library_static {
+    name: "static-hal-check",
+    srcs: [
+        "struct-size.cpp",
+        "struct-offset.cpp",
+        "struct-last.cpp",
+    ],
+    shared_libs: ["libhardware"],
+    cflags: [
+        "-O0",
+        "-Wall",
+        "-Werror",
+    ],
+
+    include_dirs: ["system/media/camera/include"],
+}
diff --git a/tests/hardware/Android.mk b/tests/hardware/Android.mk
deleted file mode 100644
index 02a3596..0000000
--- a/tests/hardware/Android.mk
+++ /dev/null
@@ -1,12 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := static-hal-check
-LOCAL_SRC_FILES := struct-size.cpp struct-offset.cpp struct-last.cpp
-LOCAL_SHARED_LIBRARIES := libhardware
-LOCAL_CFLAGS := -O0 -Wall -Werror
-
-LOCAL_C_INCLUDES += \
-    system/media/camera/include
-
-include $(BUILD_STATIC_LIBRARY)
diff --git a/tests/hwc/Android.bp b/tests/hwc/Android.bp
new file mode 100644
index 0000000..782a314
--- /dev/null
+++ b/tests/hwc/Android.bp
@@ -0,0 +1,37 @@
+cc_library_static {
+    name: "libcnativewindow",
+    srcs: [
+        "cnativewindow.c",
+        "util.c",
+    ],
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+    ],
+    shared_libs: [
+        "libEGL",
+        "libGLESv2",
+        "libdl",
+        "libhardware",
+        "libnativewindow",
+    ],
+}
+
+cc_binary {
+    name: "hwc-test-arrows",
+    srcs: ["test-arrows.c"],
+    static_libs: ["libcnativewindow"],
+    shared_libs: [
+        "libEGL",
+        "libGLESv2",
+        "libdl",
+        "libhardware",
+        "libnativewindow",
+    ],
+    cflags: [
+        "-DGL_GLEXT_PROTOTYPES",
+        "-Wall",
+        "-Werror",
+    ],
+}
diff --git a/tests/hwc/Android.mk b/tests/hwc/Android.mk
deleted file mode 100644
index a5f59f1..0000000
--- a/tests/hwc/Android.mk
+++ /dev/null
@@ -1,16 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := libcnativewindow
-LOCAL_SRC_FILES := cnativewindow.c util.c
-LOCAL_CFLAGS := -Wall -Werror -Wno-unused-parameter
-LOCAL_SHARED_LIBRARIES := libEGL libGLESv2 libdl libhardware libnativewindow
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE := hwc-test-arrows
-LOCAL_SRC_FILES := test-arrows.c
-LOCAL_STATIC_LIBRARIES := libcnativewindow
-LOCAL_SHARED_LIBRARIES := libEGL libGLESv2 libdl libhardware libnativewindow
-LOCAL_CFLAGS := -DGL_GLEXT_PROTOTYPES -Wall -Werror
-include $(BUILD_EXECUTABLE)
diff --git a/tests/input/Android.mk b/tests/input/Android.mk
deleted file mode 100644
index 3011b2e..0000000
--- a/tests/input/Android.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright (C) 2015 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)
-
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/tests/input/evdev/Android.bp b/tests/input/evdev/Android.bp
new file mode 100644
index 0000000..fa03a00
--- /dev/null
+++ b/tests/input/evdev/Android.bp
@@ -0,0 +1,33 @@
+cc_test {
+    name: "libinput_evdevtests",
+
+    srcs: [
+        "BitUtils_test.cpp",
+        "InputDevice_test.cpp",
+        "InputHub_test.cpp",
+        "InputMocks.cpp",
+        "MouseInputMapper_test.cpp",
+        "SwitchInputMapper_test.cpp",
+        "TestHelpers.cpp",
+    ],
+
+    static_libs: ["libgmock"],
+
+    shared_libs: [
+        "libinput_evdev",
+        "liblog",
+        "libutils",
+    ],
+
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+        "-Wno-unused-parameter",
+
+        // TestHelpers uses mktemp. As the path is given to TempFile, we can't do too much
+        // here (e.g., use mkdtemp first). At least races will lead to an early failure, as
+        // mkfifo fails on existing files.
+        "-Wno-deprecated-declarations",
+    ],
+}
diff --git a/tests/input/evdev/Android.mk b/tests/input/evdev/Android.mk
deleted file mode 100644
index b09a8ac..0000000
--- a/tests/input/evdev/Android.mk
+++ /dev/null
@@ -1,33 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_C_INCLUDES += hardware/libhardware/modules/input/evdev
-
-LOCAL_SRC_FILES:= \
-    BitUtils_test.cpp \
-    InputDevice_test.cpp \
-    InputHub_test.cpp \
-    InputMocks.cpp \
-    MouseInputMapper_test.cpp \
-    SwitchInputMapper_test.cpp \
-    TestHelpers.cpp
-
-LOCAL_STATIC_LIBRARIES := libgmock
-
-LOCAL_SHARED_LIBRARIES := \
-    libinput_evdev \
-    liblog \
-    libutils
-
-LOCAL_CLANG := true
-LOCAL_CFLAGS += -Wall -Wextra -Werror -Wno-unused-parameter
-
-# TestHelpers uses mktemp. As the path is given to TempFile, we can't do too much
-# here (e.g., use mkdtemp first). At least races will lead to an early failure, as
-# mkfifo fails on existing files.
-LOCAL_CFLAGS += -Wno-deprecated-declarations
-
-LOCAL_MODULE := libinput_evdevtests
-LOCAL_MODULE_TAGS := tests
-
-include $(BUILD_NATIVE_TEST)
diff --git a/tests/keymaster/Android.bp b/tests/keymaster/Android.bp
new file mode 100644
index 0000000..8c027e0
--- /dev/null
+++ b/tests/keymaster/Android.bp
@@ -0,0 +1,17 @@
+// Build the keymaster unit tests
+cc_test {
+    name: "keymaster_test",
+    srcs: ["keymaster_test.cpp"],
+
+    shared_libs: [
+        "liblog",
+        "libutils",
+        "libcrypto",
+        "libhardware",
+    ],
+
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+}
diff --git a/tests/keymaster/Android.mk b/tests/keymaster/Android.mk
deleted file mode 100644
index 173fccc..0000000
--- a/tests/keymaster/Android.mk
+++ /dev/null
@@ -1,21 +0,0 @@
-# Build the keymaster unit tests
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    keymaster_test.cpp
-
-LOCAL_SHARED_LIBRARIES := \
-    liblog \
-    libutils \
-    libcrypto \
-    libhardware \
-
-LOCAL_MODULE := keymaster_test
-
-LOCAL_CFLAGS := -Wall -Werror
-
-LOCAL_MODULE_TAGS := tests
-
-include $(BUILD_NATIVE_TEST)
diff --git a/tests/vehicle/Android.bp b/tests/vehicle/Android.bp
new file mode 100644
index 0000000..cbe2a11
--- /dev/null
+++ b/tests/vehicle/Android.bp
@@ -0,0 +1,48 @@
+//
+//  Copyright (C) 2015 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.
+
+// Build native tests.
+cc_test {
+    name: "vehicle_tests",
+    srcs: ["vehicle_tests.cpp"],
+
+    shared_libs: [
+        "liblog",
+        "libhardware",
+    ],
+
+    cflags: [
+        "-Wall",
+        "-Wextra",
+        "-Werror",
+    ],
+}
+
+// Build HAL command line utility.
+cc_binary {
+    name: "vehicle-hal-tool",
+    srcs: ["vehicle-hal-tool.c"],
+    cflags: [
+        "-Wall",
+        "-Wno-unused-parameter",
+        "-Werror",
+    ],
+
+    shared_libs: [
+        "libcutils",
+        "libhardware",
+        "liblog",
+    ],
+}
diff --git a/tests/vehicle/Android.mk b/tests/vehicle/Android.mk
deleted file mode 100644
index ab412fb..0000000
--- a/tests/vehicle/Android.mk
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-#  Copyright (C) 2015 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)
-
-# Build native tests.
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-    vehicle_tests.cpp \
-
-LOCAL_SHARED_LIBRARIES := \
-    liblog \
-    libhardware \
-
-LOCAL_CFLAGS += -Wall -Wextra -Werror
-
-LOCAL_MODULE:= vehicle_tests
-LOCAL_MODULE_TAGS := tests
-
-include $(BUILD_NATIVE_TEST)
-
-# Build HAL command line utility.
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := vehicle-hal-tool.c
-LOCAL_MODULE := vehicle-hal-tool
-LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SHARED_LIBRARIES := libcutils libhardware liblog
-
-include $(BUILD_EXECUTABLE)