GKI cleanup - Moved GKI_get_os_tick_count() to OSI

 * Renamed function GKI_get_os_tick_count() to time_get_os_boottime_ms()
   and moved it to the OSI module: to the new file osi/src/time.c .
   The corresponding header file is osi/include/time.h

 * Added unit tests for function time_get_os_boottime_ms() in file
   osi/test/time_test.cpp

 * Removed "osi/include" from the list of paths to search for include
   files. This is needed, because file name collision of "time.h"
   in osi/include and the system <time.h>

Change-Id: I934be0c8f392150a352947326546bcf8aa070f97
diff --git a/bta/Android.mk b/bta/Android.mk
index 9f3de3a..7a43a7b 100644
--- a/bta/Android.mk
+++ b/bta/Android.mk
@@ -101,7 +101,6 @@
                    $(LOCAL_PATH)/../include \
                    $(LOCAL_PATH)/../stack/include \
                    $(LOCAL_PATH)/../stack/btm \
-                   $(LOCAL_PATH)/../osi/include \
                    $(LOCAL_PATH)/../udrv/include \
                    $(LOCAL_PATH)/../vnd/include \
                    $(LOCAL_PATH)/../utils/include \
diff --git a/bta/BUILD.gn b/bta/BUILD.gn
index 756a80d..2f42bac 100644
--- a/bta/BUILD.gn
+++ b/bta/BUILD.gn
@@ -106,7 +106,6 @@
     "//include",
     "//stack/include",
     "//stack/btm",
-    "//osi/include",
     "//udrv/include",
     "//utils/include",
     "//vnd/include",
diff --git a/bta/av/bta_av_int.h b/bta/av/bta_av_int.h
index 6764e94..5527472 100644
--- a/bta/av/bta_av_int.h
+++ b/bta/av/bta_av_int.h
@@ -24,12 +24,12 @@
 #ifndef BTA_AV_INT_H
 #define BTA_AV_INT_H
 
+#include "osi/include/list.h"
 #include "bta_sys.h"
 #include "bta_api.h"
 #include "bta_av_api.h"
 #include "avdt_api.h"
 #include "bta_av_co.h"
-#include "list.h"
 
 #define BTA_AV_DEBUG TRUE
 /*****************************************************************************
diff --git a/btcore/Android.mk b/btcore/Android.mk
index 8c9e1f1..508c5f8 100644
--- a/btcore/Android.mk
+++ b/btcore/Android.mk
@@ -40,7 +40,6 @@
 
 btcoreCommonIncludes := \
     $(LOCAL_PATH)/include \
-    $(LOCAL_PATH)/../osi/include \
     $(LOCAL_PATH)/..
 
 # libbtcore static library for target
diff --git a/btcore/BUILD.gn b/btcore/BUILD.gn
index 624733b..356115e 100644
--- a/btcore/BUILD.gn
+++ b/btcore/BUILD.gn
@@ -27,7 +27,6 @@
 
   include_dirs = [
     "include",
-    "//osi/include",
     "//",
   ]
 }
diff --git a/btif/BUILD.gn b/btif/BUILD.gn
index cee6c03..3ede9c8 100644
--- a/btif/BUILD.gn
+++ b/btif/BUILD.gn
@@ -76,7 +76,6 @@
     "//embdrv/sbc/encoder/include",
     "//gki/common",
     "//hci/include",
-    "//osi/include",
     "//stack/a2dp",
     "//stack/btm",
     "//stack/include",
diff --git a/btif/include/btif_common.h b/btif/include/btif_common.h
index bbf837c..d85ef3c 100644
--- a/btif/include/btif_common.h
+++ b/btif/include/btif_common.h
@@ -24,10 +24,10 @@
 
 #include <hardware/bluetooth.h>
 
+#include "osi/include/osi.h"
+#include "osi/include/log.h"
 #include "bt_types.h"
 #include "bta_api.h"
-#include "osi.h"
-#include "osi/include/log.h"
 
 /*******************************************************************************
 **  Constants & Macros
diff --git a/btif/include/stack_manager.h b/btif/include/stack_manager.h
index 08f7f00..b80d6dd 100644
--- a/btif/include/stack_manager.h
+++ b/btif/include/stack_manager.h
@@ -18,9 +18,10 @@
 
 #pragma once
 
-#include "future.h"
 #include <stdbool.h>
 
+#include "osi/include/future.h"
+
 typedef struct {
   void (*init_stack)(void);
   void (*start_up_stack_async)(void);
diff --git a/device/Android.mk b/device/Android.mk
index 1ed85e1..8d6e6e5 100644
--- a/device/Android.mk
+++ b/device/Android.mk
@@ -27,7 +27,6 @@
     $(LOCAL_PATH)/../gki/common \
     $(LOCAL_PATH)/../hci/include \
     $(LOCAL_PATH)/../include \
-    $(LOCAL_PATH)/../osi/include \
     $(LOCAL_PATH)/../stack/include \
     $(bdroid_C_INCLUDES)
 
@@ -50,7 +49,6 @@
 
 LOCAL_C_INCLUDES := \
     $(LOCAL_PATH)/.. \
-    $(LOCAL_PATH)/../osi/include \
     $(bdroid_C_INCLUDES)
 
 LOCAL_SRC_FILES := \
diff --git a/device/BUILD.gn b/device/BUILD.gn
index 1ca0288..b64b39d 100644
--- a/device/BUILD.gn
+++ b/device/BUILD.gn
@@ -26,7 +26,6 @@
     "//gki/common",
     "//hci/include",
     "//include",
-    "//osi/include",
     "//stack/include",
   ]
 }
diff --git a/gki/Android.mk b/gki/Android.mk
index 76f5790..440ae04 100644
--- a/gki/Android.mk
+++ b/gki/Android.mk
@@ -7,7 +7,6 @@
 	$(LOCAL_PATH)/ulinux \
 	$(LOCAL_PATH)/../btcore/include \
 	$(LOCAL_PATH)/../include \
-	$(LOCAL_PATH)/../osi/include \
 	$(LOCAL_PATH)/../stack/include \
 	$(LOCAL_PATH)/../utils/include \
 	$(LOCAL_PATH)/../ \
diff --git a/gki/common/gki.h b/gki/common/gki.h
index c881302..9ee118f 100644
--- a/gki/common/gki.h
+++ b/gki/common/gki.h
@@ -84,6 +84,3 @@
 */
 void    GKI_enable(void);
 void    GKI_disable(void);
-
-/* os timer operation */
-UINT32 GKI_get_os_tick_count(void);
diff --git a/gki/ulinux/gki_ulinux.c b/gki/ulinux/gki_ulinux.c
index a13e170..acaaacf 100644
--- a/gki/ulinux/gki_ulinux.c
+++ b/gki/ulinux/gki_ulinux.c
@@ -60,12 +60,6 @@
   }
 };
 
-UINT32 GKI_get_os_tick_count(void) {
-  struct timespec timespec;
-  clock_gettime(CLOCK_BOOTTIME, &timespec);
-  return (timespec.tv_sec * 1000) + (timespec.tv_nsec / 1000000);
-}
-
 void GKI_enable(void) {
   pthread_mutex_unlock(&gki_cb.lock);
 }
diff --git a/hci/Android.mk b/hci/Android.mk
index a36d6b7..06dc6c8 100644
--- a/hci/Android.mk
+++ b/hci/Android.mk
@@ -32,7 +32,6 @@
     $(LOCAL_PATH)/../btcore/include \
     $(LOCAL_PATH)/../gki/common \
     $(LOCAL_PATH)/../gki/ulinux \
-    $(LOCAL_PATH)/../osi/include \
     $(LOCAL_PATH)/../stack/include \
     $(LOCAL_PATH)/../utils/include \
     $(bdroid_C_INCLUDES)
@@ -54,7 +53,6 @@
     $(LOCAL_PATH)/../btcore/include \
     $(LOCAL_PATH)/../gki/common \
     $(LOCAL_PATH)/../gki/ulinux \
-    $(LOCAL_PATH)/../osi/include \
     $(LOCAL_PATH)/../osi/test \
     $(LOCAL_PATH)/../stack/include \
     $(LOCAL_PATH)/../utils/include \
diff --git a/hci/BUILD.gn b/hci/BUILD.gn
index c199ff0..79e658f 100644
--- a/hci/BUILD.gn
+++ b/hci/BUILD.gn
@@ -39,7 +39,6 @@
     "//include",
     "//btcore/include",
     "//gki/common",
-    "//osi/include",
     "//stack/include",
   ]
 }
@@ -61,8 +60,6 @@
     "//include",
     "//btcore/include",
     "//hci/include",
-    "//osi/include",
-    "//osi/test",
     "//stack/include",
   ]
 
diff --git a/hci/include/buffer_allocator.h b/hci/include/buffer_allocator.h
index b44b0f0..f71e00d 100644
--- a/hci/include/buffer_allocator.h
+++ b/hci/include/buffer_allocator.h
@@ -18,6 +18,6 @@
 
 #pragma once
 
-#include "allocator.h"
+#include "osi/include/allocator.h"
 
 const allocator_t *buffer_allocator_get_interface();
diff --git a/hci/include/hci_hal.h b/hci/include/hci_hal.h
index b0b3c67..c82bb57 100644
--- a/hci/include/hci_hal.h
+++ b/hci/include/hci_hal.h
@@ -21,7 +21,7 @@
 #include <stdbool.h>
 #include <stdint.h>
 
-#include "thread.h"
+#include "osi/include/thread.h"
 #include "vendor.h"
 
 typedef enum {
diff --git a/hci/include/hci_layer.h b/hci/include/hci_layer.h
index bdc4681..fe5a2ca 100644
--- a/hci/include/hci_layer.h
+++ b/hci/include/hci_layer.h
@@ -20,12 +20,12 @@
 
 #include <stdbool.h>
 
-#include "allocator.h"
+#include "osi/include/allocator.h"
+#include "osi/include/data_dispatcher.h"
+#include "osi/include/fixed_queue.h"
+#include "osi/include/future.h"
+#include "osi/include/osi.h"
 #include "bt_types.h"
-#include "data_dispatcher.h"
-#include "fixed_queue.h"
-#include "future.h"
-#include "osi.h"
 
 static const char HCI_MODULE[] = "hci_module";
 
diff --git a/hci/include/hci_packet_parser.h b/hci/include/hci_packet_parser.h
index 57e5d1c..14b38ab 100644
--- a/hci/include/hci_packet_parser.h
+++ b/hci/include/hci_packet_parser.h
@@ -20,7 +20,7 @@
 
 #include <stdint.h>
 
-#include "allocator.h"
+#include "osi/include/allocator.h"
 #include "bdaddr.h"
 #include "bt_types.h"
 #include "device_features.h"
diff --git a/hci/include/packet_fragmenter.h b/hci/include/packet_fragmenter.h
index c7f643e..58f6ed6 100644
--- a/hci/include/packet_fragmenter.h
+++ b/hci/include/packet_fragmenter.h
@@ -18,7 +18,7 @@
 
 #pragma once
 
-#include "allocator.h"
+#include "osi/include/allocator.h"
 #include "bt_types.h"
 #include "hci_layer.h"
 
diff --git a/hci/test/hci_hal_h4_test.cpp b/hci/test/hci_hal_h4_test.cpp
index 2c4030d..870b258 100644
--- a/hci/test/hci_hal_h4_test.cpp
+++ b/hci/test/hci_hal_h4_test.cpp
@@ -26,9 +26,9 @@
 #include <sys/socket.h>
 #include <unistd.h>
 
+#include "osi/include/osi.h"
+#include "osi/include/semaphore.h"
 #include "hci_hal.h"
-#include "osi.h"
-#include "semaphore.h"
 #include "test_stubs.h"
 #include "vendor.h"
 }
diff --git a/hci/test/hci_hal_mct_test.cpp b/hci/test/hci_hal_mct_test.cpp
index 911aabc..bc331d4 100644
--- a/hci/test/hci_hal_mct_test.cpp
+++ b/hci/test/hci_hal_mct_test.cpp
@@ -26,9 +26,9 @@
 #include <sys/socket.h>
 #include <unistd.h>
 
+#include "osi/include/osi.h"
+#include "osi/include/semaphore.h"
 #include "hci_hal.h"
-#include "osi.h"
-#include "semaphore.h"
 #include "test_stubs.h"
 #include "vendor.h"
 }
diff --git a/hci/test/hci_layer_test.cpp b/hci/test/hci_layer_test.cpp
index 81a5e11..e02bdc5 100644
--- a/hci/test/hci_layer_test.cpp
+++ b/hci/test/hci_layer_test.cpp
@@ -23,19 +23,19 @@
 extern "C" {
 #include <stdint.h>
 
-#include "allocation_tracker.h"
-#include "allocator.h"
-#include "btsnoop.h"
 #include "device/include/controller.h"
+#include "osi/include/allocation_tracker.h"
+#include "osi/include/allocator.h"
+#include "osi/include/osi.h"
+#include "osi/include/semaphore.h"
+#include "btsnoop.h"
 #include "hcimsgs.h"
 #include "hci_hal.h"
 #include "hci_inject.h"
 #include "hci_layer.h"
 #include "low_power_manager.h"
 #include "module.h"
-#include "osi.h"
 #include "packet_fragmenter.h"
-#include "semaphore.h"
 #include "test_stubs.h"
 #include "vendor.h"
 
diff --git a/hci/test/low_power_manager_test.cpp b/hci/test/low_power_manager_test.cpp
index bb18bff..69b938c 100644
--- a/hci/test/low_power_manager_test.cpp
+++ b/hci/test/low_power_manager_test.cpp
@@ -24,10 +24,10 @@
 #include <stdint.h>
 
 #include "low_power_manager.h"
-#include "osi.h"
-#include "semaphore.h"
+#include "osi/include/osi.h"
+#include "osi/include/semaphore.h"
+#include "osi/include/thread.h"
 #include "test_stubs.h"
-#include "thread.h"
 #include "vendor.h"
 }
 
diff --git a/hci/test/packet_fragmenter_test.cpp b/hci/test/packet_fragmenter_test.cpp
index 765b91e..2924fe9 100644
--- a/hci/test/packet_fragmenter_test.cpp
+++ b/hci/test/packet_fragmenter_test.cpp
@@ -23,11 +23,11 @@
 extern "C" {
 #include <stdint.h>
 
-#include "allocator.h"
 #include "device/include/controller.h"
+#include "osi/include/allocator.h"
+#include "osi/include/osi.h"
 #include "hci_internals.h"
 #include "packet_fragmenter.h"
-#include "osi.h"
 #include "test_stubs.h"
 }
 
diff --git a/include/stack_config.h b/include/stack_config.h
index a4262c5..a211634 100644
--- a/include/stack_config.h
+++ b/include/stack_config.h
@@ -20,7 +20,7 @@
 
 #include <stdbool.h>
 
-#include "config.h"
+#include "osi/include/config.h"
 #include "module.h"
 
 static const char STACK_CONFIG_MODULE[] = "stack_config_module";
diff --git a/main/Android.mk b/main/Android.mk
index ff7b4a5..9e0e9b7 100644
--- a/main/Android.mk
+++ b/main/Android.mk
@@ -87,7 +87,6 @@
 	$(LOCAL_PATH)/../bta/sys \
 	$(LOCAL_PATH)/../bta/dm \
 	$(LOCAL_PATH)/../btcore/include \
-	$(LOCAL_PATH)/../osi/include \
 	$(LOCAL_PATH)/../gki/common \
 	$(LOCAL_PATH)/../gki/ulinux \
 	$(LOCAL_PATH)/../include \
diff --git a/main/BUILD.gn b/main/BUILD.gn
index 37cafbe..2de1f81 100644
--- a/main/BUILD.gn
+++ b/main/BUILD.gn
@@ -35,7 +35,6 @@
     "//bta/sys",
     "//bta/dm",
     "//btcore/include",
-    "//osi/include",
     "//gki/common",
     "//gki/ulinux",
     "//include",
diff --git a/osi/Android.mk b/osi/Android.mk
index b665b05..464def6 100644
--- a/osi/Android.mk
+++ b/osi/Android.mk
@@ -46,7 +46,8 @@
     ./src/socket.c \
     ./src/socket_utils/socket_local_client.c \
     ./src/socket_utils/socket_local_server.c \
-    ./src/thread.c
+    ./src/thread.c \
+    ./src/time.c
 
 btosiCommonTestSrc := \
     ./test/AlarmTestHarness.cpp \
@@ -64,10 +65,10 @@
     ./test/list_test.cpp \
     ./test/reactor_test.cpp \
     ./test/ringbuffer_test.cpp \
-    ./test/thread_test.cpp
+    ./test/thread_test.cpp \
+    ./test/time_test.cpp
 
 btosiCommonIncludes := \
-    $(LOCAL_PATH)/include \
     $(LOCAL_PATH)/.. \
     $(LOCAL_PATH)/../utils/include
 
diff --git a/osi/BUILD.gn b/osi/BUILD.gn
index af72693..fcfbb45 100644
--- a/osi/BUILD.gn
+++ b/osi/BUILD.gn
@@ -43,10 +43,10 @@
     "src/socket_utils/socket_local_server.c",
 
     "src/thread.c",
+    "src/time.c",
   ]
 
   include_dirs = [
-    "include",
     "//",
     "//utils/include",
   ]
@@ -71,10 +71,10 @@
     "test/reactor_test.cpp",
     "test/ringbuffer_test.cpp",
     "test/thread_test.cpp",
+    "test/time_test.cpp",
   ]
 
   include_dirs = [
-    "include",
     "//",
   ]
 
diff --git a/osi/include/data_dispatcher.h b/osi/include/data_dispatcher.h
index 4eb8fdf..3cdb07d 100644
--- a/osi/include/data_dispatcher.h
+++ b/osi/include/data_dispatcher.h
@@ -21,7 +21,7 @@
 #include <stdbool.h>
 #include <stdint.h>
 
-#include "fixed_queue.h"
+#include "osi/include/fixed_queue.h"
 
 #define DISPATCHER_NAME_MAX 16
 
diff --git a/osi/include/eager_reader.h b/osi/include/eager_reader.h
index 3bf1e6e..542df45 100644
--- a/osi/include/eager_reader.h
+++ b/osi/include/eager_reader.h
@@ -22,7 +22,7 @@
 #include <stddef.h>
 #include <stdint.h>
 
-#include "allocator.h"
+#include "osi/include/allocator.h"
 
 typedef struct eager_reader_t eager_reader_t;
 typedef struct reactor_t reactor_t;
diff --git a/osi/include/hash_functions.h b/osi/include/hash_functions.h
index ad7d095..7127d51 100644
--- a/osi/include/hash_functions.h
+++ b/osi/include/hash_functions.h
@@ -18,7 +18,7 @@
 
 #pragma once
 
-#include "hash_map.h"
+#include "osi/include/hash_map.h"
 
 hash_index_t hash_function_naive(const void *key);
 
diff --git a/osi/include/non_repeating_timer.h b/osi/include/non_repeating_timer.h
index de8aabf..b08d7bc 100644
--- a/osi/include/non_repeating_timer.h
+++ b/osi/include/non_repeating_timer.h
@@ -20,7 +20,7 @@
 
 #include <stdbool.h>
 
-#include "alarm.h"
+#include "osi/include/alarm.h"
 
 typedef struct non_repeating_timer_t non_repeating_timer_t;
 
diff --git a/osi/include/reactor.h b/osi/include/reactor.h
index 100c762..c5206c2 100644
--- a/osi/include/reactor.h
+++ b/osi/include/reactor.h
@@ -21,7 +21,7 @@
 #include <stdbool.h>
 #include <stdint.h>
 
-#include "osi.h"
+#include "osi/include/osi.h"
 
 // This module implements the Reactor pattern.
 // See http://en.wikipedia.org/wiki/Reactor_pattern for details.
diff --git a/osi/include/time.h b/osi/include/time.h
new file mode 100644
index 0000000..fc9a750
--- /dev/null
+++ b/osi/include/time.h
@@ -0,0 +1,30 @@
+/******************************************************************************
+ *
+ *  Copyright (C) 2015 Google, Inc.
+ *
+ *  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.
+ *
+ ******************************************************************************/
+
+#pragma once
+
+#include <stdint.h>
+
+// Get the OS boot time in milliseconds.
+//
+// NOTE: The return value will rollover every 49.7 days,
+// hence it cannot be used for absolute time comparison.
+// Relative time comparison using 32-bits integers such
+// as (t2_u32 - t1_u32 < delta_u32) should work as expected as long
+// as there is no multiple rollover between t2_u32 and t1_u32.
+uint32_t time_get_os_boottime_ms(void);
diff --git a/osi/src/hash_map.c b/osi/src/hash_map.c
index c483948..478cc5d 100644
--- a/osi/src/hash_map.c
+++ b/osi/src/hash_map.c
@@ -17,10 +17,10 @@
  ******************************************************************************/
 
 #include <assert.h>
-#include <list.h>
-#include <hash_map.h>
 
 #include "osi/include/allocator.h"
+#include "osi/include/hash_map.h"
+#include "osi/include/list.h"
 #include "osi/include/osi.h"
 
 struct hash_map_t;
diff --git a/osi/src/time.c b/osi/src/time.c
new file mode 100644
index 0000000..f1d8dca
--- /dev/null
+++ b/osi/src/time.c
@@ -0,0 +1,29 @@
+/******************************************************************************
+ *
+ *  Copyright (C) 2015 Google, Inc.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at:
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+
+#define LOG_TAG "bt_osi_time"
+
+#include <time.h>
+
+#include "osi/include/time.h"
+
+uint32_t time_get_os_boottime_ms(void) {
+  struct timespec timespec;
+  clock_gettime(CLOCK_BOOTTIME, &timespec);
+  return (timespec.tv_sec * 1000) + (timespec.tv_nsec / 1000000);
+}
diff --git a/osi/test/AlarmTestHarness.cpp b/osi/test/AlarmTestHarness.cpp
index 496c70d..1f0cdb5 100644
--- a/osi/test/AlarmTestHarness.cpp
+++ b/osi/test/AlarmTestHarness.cpp
@@ -23,8 +23,8 @@
 #include "AlarmTestHarness.h"
 
 extern "C" {
-#include "alarm.h"
-#include "allocation_tracker.h"
+#include "osi/include/alarm.h"
+#include "osi/include/allocation_tracker.h"
 }
 
 static timer_t timer;
diff --git a/osi/test/alarm_test.cpp b/osi/test/alarm_test.cpp
index 287d408..32e1103 100644
--- a/osi/test/alarm_test.cpp
+++ b/osi/test/alarm_test.cpp
@@ -21,9 +21,9 @@
 #include "AlarmTestHarness.h"
 
 extern "C" {
-#include "alarm.h"
-#include "osi.h"
-#include "semaphore.h"
+#include "osi/include/alarm.h"
+#include "osi/include/osi.h"
+#include "osi/include/semaphore.h"
 }
 
 static semaphore_t *semaphore;
diff --git a/osi/test/allocation_tracker_test.cpp b/osi/test/allocation_tracker_test.cpp
index 052d468..ab5f61f 100644
--- a/osi/test/allocation_tracker_test.cpp
+++ b/osi/test/allocation_tracker_test.cpp
@@ -19,7 +19,7 @@
 #include <gtest/gtest.h>
 
 extern "C" {
-#include "allocation_tracker.h"
+#include "osi/include/allocation_tracker.h"
 
 void allocation_tracker_uninit(void);
 }
diff --git a/osi/test/array_test.cpp b/osi/test/array_test.cpp
index 1a815d1..9cd40dc 100644
--- a/osi/test/array_test.cpp
+++ b/osi/test/array_test.cpp
@@ -3,7 +3,7 @@
 #include "AllocationTestHarness.h"
 
 extern "C" {
-#include "array.h"
+#include "osi/include/array.h"
 }
 
 class ArrayTest : public AllocationTestHarness {};
diff --git a/osi/test/config_test.cpp b/osi/test/config_test.cpp
index 70e5a24..4a0c4f8 100644
--- a/osi/test/config_test.cpp
+++ b/osi/test/config_test.cpp
@@ -3,7 +3,7 @@
 #include "AllocationTestHarness.h"
 
 extern "C" {
-#include "config.h"
+#include "osi/include/config.h"
 }
 
 static const char CONFIG_FILE[] = "/data/local/tmp/config_test.conf";
diff --git a/osi/test/data_dispatcher_test.cpp b/osi/test/data_dispatcher_test.cpp
index 1985fee..98354bc 100644
--- a/osi/test/data_dispatcher_test.cpp
+++ b/osi/test/data_dispatcher_test.cpp
@@ -5,9 +5,9 @@
 #include "AllocationTestHarness.h"
 
 extern "C" {
-#include "data_dispatcher.h"
-#include "fixed_queue.h"
-#include "osi.h"
+#include "osi/include/data_dispatcher.h"
+#include "osi/include/fixed_queue.h"
+#include "osi/include/osi.h"
 }
 
 #define DUMMY_TYPE_0 34
diff --git a/osi/test/eager_reader_test.cpp b/osi/test/eager_reader_test.cpp
index ad00e17..65c1dbd 100644
--- a/osi/test/eager_reader_test.cpp
+++ b/osi/test/eager_reader_test.cpp
@@ -24,11 +24,11 @@
 #include <stdint.h>
 #include <unistd.h>
 
-#include "allocator.h"
-#include "eager_reader.h"
-#include "osi.h"
-#include "semaphore.h"
-#include "thread.h"
+#include "osi/include/allocator.h"
+#include "osi/include/eager_reader.h"
+#include "osi/include/osi.h"
+#include "osi/include/semaphore.h"
+#include "osi/include/thread.h"
 }
 
 #define BUFFER_SIZE 32
diff --git a/osi/test/future_test.cpp b/osi/test/future_test.cpp
index 880f892..a7a11af 100644
--- a/osi/test/future_test.cpp
+++ b/osi/test/future_test.cpp
@@ -21,9 +21,9 @@
 #include "AllocationTestHarness.h"
 
 extern "C" {
-#include "future.h"
-#include "osi.h"
-#include "thread.h"
+#include "osi/include/future.h"
+#include "osi/include/osi.h"
+#include "osi/include/thread.h"
 }
 
 static const char *pass_back_data0 = "fancy a sandwich? it's a fancy sandwich";
diff --git a/osi/test/hash_map_test.cpp b/osi/test/hash_map_test.cpp
index 086b414..92dae16 100644
--- a/osi/test/hash_map_test.cpp
+++ b/osi/test/hash_map_test.cpp
@@ -21,8 +21,8 @@
 #include "AllocationTestHarness.h"
 
 extern "C" {
-#include "hash_map.h"
-#include "osi.h"
+#include "osi/include/hash_map.h"
+#include "osi/include/osi.h"
 }
 
 class HashMapTest : public AllocationTestHarness {};
diff --git a/osi/test/list_test.cpp b/osi/test/list_test.cpp
index 6301e7e..ce5a158 100644
--- a/osi/test/list_test.cpp
+++ b/osi/test/list_test.cpp
@@ -3,8 +3,8 @@
 #include "AllocationTestHarness.h"
 
 extern "C" {
-#include "list.h"
-#include "osi.h"
+#include "osi/include/list.h"
+#include "osi/include/osi.h"
 }
 
 class ListTest : public AllocationTestHarness {};
diff --git a/osi/test/reactor_test.cpp b/osi/test/reactor_test.cpp
index 6e3a009..a2c7b6e 100644
--- a/osi/test/reactor_test.cpp
+++ b/osi/test/reactor_test.cpp
@@ -7,7 +7,7 @@
 #include "AllocationTestHarness.h"
 
 extern "C" {
-#include "reactor.h"
+#include "osi/include/reactor.h"
 }
 
 class ReactorTest : public AllocationTestHarness {};
diff --git a/osi/test/ringbuffer_test.cpp b/osi/test/ringbuffer_test.cpp
index 2ebdeca..88ff64c 100644
--- a/osi/test/ringbuffer_test.cpp
+++ b/osi/test/ringbuffer_test.cpp
@@ -1,8 +1,8 @@
 #include <gtest/gtest.h>
 
 extern "C" {
-#include "ringbuffer.h"
-#include "osi.h"
+#include "osi/include/ringbuffer.h"
+#include "osi/include/osi.h"
 }
 
 TEST(RingbufferTest, test_new_simple) {
diff --git a/osi/test/thread_test.cpp b/osi/test/thread_test.cpp
index e626c73..d624d7d 100644
--- a/osi/test/thread_test.cpp
+++ b/osi/test/thread_test.cpp
@@ -5,10 +5,10 @@
 extern "C" {
 #include <sys/select.h>
 
-#include "reactor.h"
-#include "semaphore.h"
-#include "thread.h"
-#include "osi.h"
+#include "osi/include/reactor.h"
+#include "osi/include/semaphore.h"
+#include "osi/include/thread.h"
+#include "osi/include/osi.h"
 }
 
 class ThreadTest : public AllocationTestHarness {};
diff --git a/osi/test/time_test.cpp b/osi/test/time_test.cpp
new file mode 100644
index 0000000..e2059f0
--- /dev/null
+++ b/osi/test/time_test.cpp
@@ -0,0 +1,76 @@
+/******************************************************************************
+ *
+ *  Copyright (C) 2015 Google, Inc.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at:
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+
+#include <gtest/gtest.h>
+
+#include "AllocationTestHarness.h"
+
+extern "C" {
+#include "osi/include/time.h"
+}
+
+// Generous upper bound: 10 seconds
+static const uint32_t TEST_TIME_DELTA_UPPER_BOUND_MS = 10 * 1000;
+
+class TimeTest : public AllocationTestHarness {};
+
+//
+// Test that the return value of time_get_os_boottime_ms() is not zero.
+//
+// NOTE: For now this test is disabled, because the return value
+// of time_get_os_boottime_ms() is 32-bits integer that could wrap-around
+// in 49.7 days. It should be re-enabled if/after the wrap-around issue
+// is resolved (e.g., if the return value is 64-bits integer).
+//
+#if 0
+TEST_F(TimeTest, test_time_get_os_boottime_ms_not_zero) {
+  uint32_t t1 = time_get_os_boottime_ms();
+  ASSERT_TRUE(t1 > 0);
+}
+#endif
+
+//
+// Test that the return value of time_get_os_boottime_ms()
+// is monotonically increasing within reasonable boundries.
+//
+TEST_F(TimeTest, test_time_get_os_boottime_ms_increases_upper_bound) {
+  uint32_t t1 = time_get_os_boottime_ms();
+  uint32_t t2 = time_get_os_boottime_ms();
+  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS);
+}
+
+//
+// Test that the return value of time_get_os_boottime_ms()
+// is increasing.
+//
+TEST_F(TimeTest, test_time_get_os_boottime_ms_increases_lower_bound) {
+  static const uint32_t TEST_TIME_SLEEP_MS = 100;
+  struct timespec delay;
+
+  delay.tv_sec = TEST_TIME_SLEEP_MS / 1000;
+  delay.tv_nsec = 1000 * 1000 * (TEST_TIME_SLEEP_MS % 1000);
+
+  // Take two timestamps with sleep in-between
+  uint32_t t1 = time_get_os_boottime_ms();
+  int err = nanosleep(&delay, &delay);
+  uint32_t t2 = time_get_os_boottime_ms();
+
+  ASSERT_TRUE(err == 0);
+  ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_MS);
+  ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS);
+}
diff --git a/profile/Android.mk b/profile/Android.mk
index 5683d7f..5d3e5c9 100644
--- a/profile/Android.mk
+++ b/profile/Android.mk
@@ -25,7 +25,6 @@
     $(LOCAL_PATH)/include \
     $(LOCAL_PATH)/../btcore/include \
     $(LOCAL_PATH)/../include \
-    $(LOCAL_PATH)/../osi/include \
     $(bdroid_C_INCLUDES)
 
 LOCAL_SRC_FILES := \
diff --git a/stack/Android.mk b/stack/Android.mk
index ccb5dc6..fa68850 100644
--- a/stack/Android.mk
+++ b/stack/Android.mk
@@ -25,7 +25,6 @@
                    $(LOCAL_PATH)/../include \
                    $(LOCAL_PATH)/../gki/common \
                    $(LOCAL_PATH)/../gki/ulinux \
-                   $(LOCAL_PATH)/../osi/include \
                    $(LOCAL_PATH)/../udrv/include \
                    $(LOCAL_PATH)/../rpc/include \
                    $(LOCAL_PATH)/../hcis \
diff --git a/stack/BUILD.gn b/stack/BUILD.gn
index f8ea514..3474532 100644
--- a/stack/BUILD.gn
+++ b/stack/BUILD.gn
@@ -156,7 +156,6 @@
     "//include",
     "//gki/common",
     "//gki/ulinux",
-    "//osi/include",
     "//udrv/include",
     "//rpc/include",
     "//hcis",
diff --git a/stack/btm/btm_inq.c b/stack/btm/btm_inq.c
index a668f85..2bb4dbb 100644
--- a/stack/btm/btm_inq.c
+++ b/stack/btm/btm_inq.c
@@ -1988,7 +1988,7 @@
             p_cur->dev_class[2]       = dc[2];
             p_cur->clock_offset       = clock_offset  | BTM_CLOCK_OFFSET_VALID;
 
-            p_i->time_of_resp = GKI_get_os_tick_count();
+            p_i->time_of_resp = time_get_os_boottime_ms();
 
             if (p_i->inq_count != p_inq->inq_counter)
                 p_inq->inq_cmpl_info.num_resp++;       /* A new response was found */
diff --git a/stack/btm/btm_sec.c b/stack/btm/btm_sec.c
index 754608d..0989970 100644
--- a/stack/btm/btm_sec.c
+++ b/stack/btm/btm_sec.c
@@ -3968,9 +3968,9 @@
     tBTM_SEC_DEV_REC *p_dev_rec;
 
     if (!btm_cb.collision_start_time)
-        btm_cb.collision_start_time = GKI_get_os_tick_count();
+        btm_cb.collision_start_time = time_get_os_boottime_ms();
 
-    if ((GKI_get_os_tick_count() - btm_cb.collision_start_time) < btm_cb.max_collision_delay)
+    if ((time_get_os_boottime_ms() - btm_cb.collision_start_time) < btm_cb.max_collision_delay)
     {
         if (handle == BTM_SEC_INVALID_HANDLE)
         {
diff --git a/stack/btu/btu_hcif.c b/stack/btu/btu_hcif.c
index 426749a..28bcbd7 100644
--- a/stack/btu/btu_hcif.c
+++ b/stack/btu/btu_hcif.c
@@ -32,18 +32,18 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "device/include/controller.h"
+#include "osi/include/log.h"
+#include "osi/include/osi.h"
 #include "bt_types.h"
 #include "bt_utils.h"
 #include "btm_api.h"
 #include "btm_int.h"
 #include "btu.h"
-#include "device/include/controller.h"
 #include "gki.h"
 #include "hci_layer.h"
 #include "hcimsgs.h"
 #include "l2c_int.h"
-#include "osi.h"
-#include "osi/include/log.h"
 
 // TODO(zachoverflow): remove this horrible hack
 #include "btu.h"
diff --git a/stack/l2cap/l2c_csm.c b/stack/l2cap/l2c_csm.c
index 7a77f36..82f3e17 100644
--- a/stack/l2cap/l2c_csm.c
+++ b/stack/l2cap/l2c_csm.c
@@ -779,7 +779,7 @@
                 }
 
 #if (L2CAP_ERTM_STATS == TRUE)
-                p_ccb->fcrb.connect_tick_count = GKI_get_os_tick_count();
+                p_ccb->fcrb.connect_tick_count = time_get_os_boottime_ms();
 #endif
                 /* See if we can forward anything on the hold queue */
                 if (!GKI_queue_is_empty(&p_ccb->xmit_hold_q))
@@ -861,7 +861,7 @@
             l2c_fcr_start_timer(p_ccb);
 
 #if (L2CAP_ERTM_STATS == TRUE)
-        p_ccb->fcrb.connect_tick_count = GKI_get_os_tick_count();
+        p_ccb->fcrb.connect_tick_count = time_get_os_boottime_ms();
 #endif
 
         /* See if we can forward anything on the hold queue */
diff --git a/stack/l2cap/l2c_fcr.c b/stack/l2cap/l2c_fcr.c
index f80dc6e..a98d031 100644
--- a/stack/l2cap/l2c_fcr.c
+++ b/stack/l2cap/l2c_fcr.c
@@ -241,7 +241,7 @@
 #if (L2CAP_ERTM_STATS == TRUE)
     if ( (p_ccb->local_cid >= L2CAP_BASE_APPL_CID) && (p_ccb->peer_cfg.fcr.mode == L2CAP_FCR_ERTM_MODE) )
     {
-        UINT32  dur = GKI_get_os_tick_count() - p_ccb->fcrb.connect_tick_count;
+        UINT32  dur = time_get_os_boottime_ms() - p_ccb->fcrb.connect_tick_count;
         char    *p_str = (char *)GKI_getbuf(120);
         UINT16  i;
         UINT32  throughput_avg, ack_delay_avg, ack_q_count_avg;
@@ -1728,7 +1728,7 @@
 #if (L2CAP_ERTM_STATS == TRUE)
             /* set timestamp at the end of tx I-frame to get acking delay */
             p = ((UINT8 *) (p_wack+1)) + p_wack->offset + p_wack->len;
-            UINT32_TO_STREAM (p, GKI_get_os_tick_count());
+            UINT32_TO_STREAM (p, time_get_os_boottime_ms());
 #endif
             /* We will not save the FCS in case we reconfigure and change options */
             if (p_ccb->bypass_fcs != L2CAP_BYPASS_FCS)
@@ -2277,8 +2277,8 @@
                 p += L2CAP_FCS_LEN;
             }
 
-            STREAM_TO_UINT32 (timestamp, p);
-            delay = GKI_get_os_tick_count() - timestamp;
+            STREAM_TO_UINT32(timestamp, p);
+            delay = time_get_os_boottime_ms() - timestamp;
 
             p_ccb->fcrb.ack_delay_avg[index] += delay;
             if ( delay > p_ccb->fcrb.ack_delay_max[index] )
@@ -2301,8 +2301,8 @@
         p_ccb->fcrb.ack_delay_avg[index] /= L2CAP_ERTM_STATS_AVG_NUM_SAMPLES;
 
         /* calculate throughput */
-        timestamp = GKI_get_os_tick_count();
-        if (timestamp - p_ccb->fcrb.throughput_start > 0 )
+        timestamp = time_get_os_boottime_ms();
+        if (timestamp - p_ccb->fcrb.throughput_start > 0)
             p_ccb->fcrb.throughput[index] /= (timestamp - p_ccb->fcrb.throughput_start);
 
         p_ccb->fcrb.throughput_start = timestamp;
diff --git a/stack/l2cap/l2c_int.h b/stack/l2cap/l2c_int.h
index c6cf9a8..72a084d 100644
--- a/stack/l2cap/l2c_int.h
+++ b/stack/l2cap/l2c_int.h
@@ -26,11 +26,11 @@
 
 #include <stdbool.h>
 
+#include "osi/include/list.h"
 #include "btm_api.h"
 #include "gki.h"
 #include "l2c_api.h"
 #include "l2cdefs.h"
-#include "list.h"
 
 #define L2CAP_MIN_MTU   48      /* Minimum acceptable MTU is 48 bytes */
 
diff --git a/stack/rfcomm/rfc_l2cap_if.c b/stack/rfcomm/rfc_l2cap_if.c
index d72a40a..a5dc84b 100644
--- a/stack/rfcomm/rfc_l2cap_if.c
+++ b/stack/rfcomm/rfc_l2cap_if.c
@@ -106,7 +106,7 @@
             RFCOMM_TRACE_DEBUG ("RFCOMM_ConnectInd start timer for collision, initiator's LCID(0x%x), acceptor's LCID(0x%x)",
                                   p_mcb->lcid, p_mcb->pending_lcid);
 
-            rfc_timer_start(p_mcb, (UINT16)(GKI_get_os_tick_count()%10 + 2));
+            rfc_timer_start(p_mcb, (UINT16)(time_get_os_boottime_ms() % 10 + 2));
             return;
         }
         else
diff --git a/utils/Android.mk b/utils/Android.mk
index 8e3fe39..5e71457 100644
--- a/utils/Android.mk
+++ b/utils/Android.mk
@@ -5,7 +5,6 @@
 LOCAL_C_INCLUDES := \
 	$(LOCAL_PATH)/include \
 	$(LOCAL_PATH)/../btcore/include \
-	$(LOCAL_PATH)/../osi/include \
 	$(LOCAL_PATH)/../stack/include \
 	$(LOCAL_PATH)/../ \
 	$(bdroid_C_INCLUDES)
diff --git a/vendor_libs/test_vendor_lib/Android.mk b/vendor_libs/test_vendor_lib/Android.mk
index fde7789..c43aa66 100644
--- a/vendor_libs/test_vendor_lib/Android.mk
+++ b/vendor_libs/test_vendor_lib/Android.mk
@@ -21,7 +21,6 @@
     $(LOCAL_PATH)/include \
     $(BT_DIR) \
     $(BT_DIR)/hci/include \
-    $(BT_DIR)/osi/include \
     $(BT_DIR)/stack/include \
     $(BT_DIR)/third_party/gtest/include
 
@@ -53,7 +52,6 @@
     $(LOCAL_PATH)/include \
     $(BT_DIR) \
     $(BT_DIR)/hci/include \
-    $(BT_DIR)/osi/include \
     $(BT_DIR)/stack/include
 
 LOCAL_SHARED_LIBRARIES := \
diff --git a/vendor_libs/test_vendor_lib/BUILD.gn b/vendor_libs/test_vendor_lib/BUILD.gn
index ac36703..4bcbd11 100644
--- a/vendor_libs/test_vendor_lib/BUILD.gn
+++ b/vendor_libs/test_vendor_lib/BUILD.gn
@@ -16,7 +16,6 @@
     "//",
     # TODO(dennischeng): Ideally we should need to have the lines below for
     # indirect includes.
-    "//osi/include",
     "//stack/include",
   ]
 }
@@ -37,7 +36,6 @@
     "//",
     "//btcore/include",
     "//hci/include",
-    "//osi/include",
     "//stack/include",
   ]