summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jack He <siyuanh@google.com> 2018-08-15 12:38:37 -0700
committer Jack He <siyuanh@google.com> 2018-08-27 18:11:00 +0000
commit4282398549f8f87967d76ee739a77e6faaa9581a (patch)
treefb68cfb7393e2c7878dca0074702143cfc1d73c5
parent197aeea2e85dbe6ddd138e94e7438ecf74ed4672 (diff)
Move metrics and time library to libbt-common
* libbt-osi is being deprecated and libbt-common will replace it * Move recently implemented metrics library to libbt-common * Move time library from libbt-osi to libbt-common and renamed as time_util to avoid potention name collision with system time libraries * Need to keep time library for now because we need to use CLOCK_BOOTTIME that include system suspension time for A2DP encoding * Use libchrome logging methods in metrics library * Put both metrics and time_util into bluetooth::common namespace * Return uint64_t for time_get_os_boottime_ms and update various receiver types * Remove tBTM_CB.max_collision_delay and use the constant BTM_SEC_MAX_COLLISION_DELAY instead Bug: 111568640 Test: mm -j40, unit test, stream music Change-Id: I8c384a810d592bb6b9eb322134e947d066489ba4
-rw-r--r--system/bta/Android.bp1
-rw-r--r--system/bta/hearing_aid/hearing_aid_audio_source.cc7
-rw-r--r--system/btif/src/bluetooth.cc4
-rw-r--r--system/btif/src/btif_a2dp_audio_interface.cc15
-rw-r--r--system/btif/src/btif_a2dp_source.cc37
-rw-r--r--system/btif/src/btif_debug_btsnoop.cc1
-rw-r--r--system/btif/src/btif_debug_conn.cc4
-rw-r--r--system/btif/src/btif_dm.cc14
-rw-r--r--system/btif/src/btif_hf.cc4
-rw-r--r--system/common/Android.bp32
-rw-r--r--system/common/leaky_bonded_queue.h (renamed from system/osi/include/leaky_bonded_queue.h)12
-rw-r--r--system/common/leaky_bonded_queue_unittest.cc (renamed from system/osi/test/leaky_bonded_queue_test.cc)6
-rw-r--r--system/common/metrics.cc (renamed from system/osi/src/metrics.cc)54
-rw-r--r--system/common/metrics.h (renamed from system/osi/include/metrics.h)11
-rw-r--r--system/common/metrics_unittest.cc (renamed from system/osi/test/metrics_test.cc)78
-rw-r--r--system/common/time_util.cc (renamed from system/osi/src/time.cc)26
-rw-r--r--system/common/time_util.h (renamed from system/osi/include/time.h)26
-rw-r--r--system/common/time_util_unittest.cc146
-rw-r--r--system/hci/src/btsnoop.cc4
-rw-r--r--system/osi/Android.bp5
-rw-r--r--system/osi/include/alarm.h1
-rw-r--r--system/osi/src/wakelock.cc8
-rw-r--r--system/osi/test/time_test.cc154
-rw-r--r--system/stack/Android.bp1
-rw-r--r--system/stack/a2dp/a2dp_aac_encoder.cc4
-rw-r--r--system/stack/a2dp/a2dp_sbc_encoder.cc4
-rw-r--r--system/stack/a2dp/a2dp_vendor_aptx_encoder.cc4
-rw-r--r--system/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc4
-rw-r--r--system/stack/a2dp/a2dp_vendor_ldac_encoder.cc4
-rw-r--r--system/stack/btm/btm_inq.cc6
-rw-r--r--system/stack/btm/btm_int_types.h5
-rw-r--r--system/stack/btm/btm_sec.cc9
-rw-r--r--system/stack/include/a2dp_aac_encoder.h1
-rw-r--r--system/stack/include/a2dp_codec_api.h1
-rw-r--r--system/stack/include/a2dp_sbc_encoder.h1
-rw-r--r--system/stack/include/a2dp_vendor_aptx_encoder.h1
-rw-r--r--system/stack/include/a2dp_vendor_aptx_hd_encoder.h1
-rw-r--r--system/stack/include/a2dp_vendor_ldac_encoder.h1
-rw-r--r--system/stack/l2cap/l2c_csm.cc7
-rw-r--r--system/stack/l2cap/l2c_fcr.cc14
-rw-r--r--system/stack/l2cap/l2c_int.h2
-rw-r--r--system/stack/rfcomm/rfc_l2cap_if.cc6
42 files changed, 380 insertions, 346 deletions
diff --git a/system/bta/Android.bp b/system/bta/Android.bp
index d1cce826bd..c2f64d5429 100644
--- a/system/bta/Android.bp
+++ b/system/bta/Android.bp
@@ -143,5 +143,6 @@ cc_test {
"libbluetooth-types",
"libbt-protos-lite",
"libosi",
+ "libbt-common",
],
}
diff --git a/system/bta/hearing_aid/hearing_aid_audio_source.cc b/system/bta/hearing_aid/hearing_aid_audio_source.cc
index e03b040437..b56f83cbd0 100644
--- a/system/bta/hearing_aid/hearing_aid_audio_source.cc
+++ b/system/bta/hearing_aid/hearing_aid_audio_source.cc
@@ -24,6 +24,8 @@
#include <base/files/file_util.h>
#include <include/hardware/bt_av.h>
+#include "common/time_util.h"
+
using base::FilePath;
extern const char* audio_ha_hw_dump_ctrl_event(tHEARING_AID_CTRL_CMD event);
@@ -67,7 +69,8 @@ void send_audio_data(void*) {
if (bytes_read < bytes_per_tick) {
stats.media_read_total_underflow_bytes += bytes_per_tick - bytes_read;
stats.media_read_total_underflow_count++;
- stats.media_read_last_underflow_us = time_get_os_boottime_us();
+ stats.media_read_last_underflow_us =
+ bluetooth::common::time_get_os_boottime_us();
}
std::vector<uint8_t> data(p_buf, p_buf + bytes_read);
@@ -296,7 +299,7 @@ void HearingAidAudioSource::CleanUp() {
}
void HearingAidAudioSource::DebugDump(int fd) {
- uint64_t now_us = time_get_os_boottime_us();
+ uint64_t now_us = bluetooth::common::time_get_os_boottime_us();
std::stringstream stream;
stream << " Hearing Aid Audio HAL:"
<< "\n Counts (underflow) : "
diff --git a/system/btif/src/bluetooth.cc b/system/btif/src/bluetooth.cc
index 4fb8f6426e..eb98d14bdf 100644
--- a/system/btif/src/bluetooth.cc
+++ b/system/btif/src/bluetooth.cc
@@ -62,11 +62,11 @@
#include "btif_storage.h"
#include "btsnoop.h"
#include "btsnoop_mem.h"
+#include "common/metrics.h"
#include "device/include/interop.h"
#include "osi/include/alarm.h"
#include "osi/include/allocation_tracker.h"
#include "osi/include/log.h"
-#include "osi/include/metrics.h"
#include "osi/include/osi.h"
#include "osi/include/wakelock.h"
#include "stack_manager.h"
@@ -329,7 +329,7 @@ static void dump(int fd, const char** arguments) {
}
static void dumpMetrics(std::string* output) {
- system_bt_osi::BluetoothMetricsLogger::GetInstance()->WriteString(output);
+ bluetooth::common::BluetoothMetricsLogger::GetInstance()->WriteString(output);
}
static const void* get_profile_interface(const char* profile_id) {
diff --git a/system/btif/src/btif_a2dp_audio_interface.cc b/system/btif/src/btif_a2dp_audio_interface.cc
index ff0312993f..01fe029b81 100644
--- a/system/btif/src/btif_a2dp_audio_interface.cc
+++ b/system/btif/src/btif_a2dp_audio_interface.cc
@@ -40,12 +40,13 @@
#include "btif_av.h"
#include "btif_av_co.h"
#include "btif_hf.h"
-#include "osi/include/metrics.h"
+#include "common/metrics.h"
+#include "common/time_util.h"
#include "osi/include/osi.h"
#include "stack/include/btu.h"
-using system_bt_osi::A2dpSessionMetrics;
-using system_bt_osi::BluetoothMetricsLogger;
+using bluetooth::common::A2dpSessionMetrics;
+using bluetooth::common::BluetoothMetricsLogger;
using android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioOffload;
using android::hardware::bluetooth::a2dp::V1_0::IBluetoothAudioHost;
@@ -108,11 +109,11 @@ class A2dpOffloadAudioStats {
}
void LogAudioStart() {
std::lock_guard<std::recursive_mutex> lock(lock_);
- audio_start_time_ms_ = time_get_os_boottime_ms();
+ audio_start_time_ms_ = bluetooth::common::time_get_os_boottime_ms();
}
void LogAudioStop() {
std::lock_guard<std::recursive_mutex> lock(lock_);
- audio_stop_time_ms_ = time_get_os_boottime_ms();
+ audio_stop_time_ms_ = bluetooth::common::time_get_os_boottime_ms();
}
void LogAudioStopMetricsAndReset() {
std::lock_guard<std::recursive_mutex> lock(lock_);
@@ -300,7 +301,7 @@ static void btif_a2dp_audio_interface_deinit() {
void btif_a2dp_audio_interface_start_session() {
LOG_INFO(LOG_TAG, "%s", __func__);
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
- system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
+ bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
a2dp_offload_audio_stats.Reset();
btif_a2dp_audio_interface_init();
CHECK(btAudio != nullptr);
@@ -314,7 +315,7 @@ void btif_a2dp_audio_interface_end_session() {
LOG_INFO(LOG_TAG, "%s", __func__);
a2dp_offload_audio_stats.LogAudioStopMetricsAndReset();
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
- system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0);
+ bluetooth::common::DISCONNECT_REASON_UNKNOWN, 0);
a2dp_offload_audio_stats.Reset();
if (btAudio == nullptr) return;
auto ret = btAudio->endSession();
diff --git a/system/btif/src/btif_a2dp_source.cc b/system/btif/src/btif_a2dp_source.cc
index 4fc8d0ff95..14f7021c28 100644
--- a/system/btif/src/btif_a2dp_source.cc
+++ b/system/btif/src/btif_a2dp_source.cc
@@ -40,15 +40,15 @@
#include "btif_av_co.h"
#include "btif_util.h"
#include "common/message_loop_thread.h"
+#include "common/metrics.h"
+#include "common/time_util.h"
#include "osi/include/fixed_queue.h"
#include "osi/include/log.h"
-#include "osi/include/metrics.h"
#include "osi/include/osi.h"
-#include "osi/include/time.h"
#include "uipc.h"
-using system_bt_osi::BluetoothMetricsLogger;
-using system_bt_osi::A2dpSessionMetrics;
+using bluetooth::common::A2dpSessionMetrics;
+using bluetooth::common::BluetoothMetricsLogger;
extern std::unique_ptr<tUIPC_STATE> a2dp_uipc;
@@ -382,7 +382,7 @@ static void btif_a2dp_source_start_session_delayed(
btif_a2dp_audio_interface_start_session();
} else {
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
- system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
+ bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
}
}
@@ -437,7 +437,7 @@ static void btif_a2dp_source_end_session_delayed(
btif_a2dp_source_cb.StateStr().c_str());
if (!btif_av_is_a2dp_offload_enabled()) {
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
- system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0);
+ bluetooth::common::DISCONNECT_REASON_UNKNOWN, 0);
}
if (btif_a2dp_source_cb.State() == BtifA2dpSource::kStateRunning) {
btif_av_stream_stop(peer_address);
@@ -722,9 +722,11 @@ static void btif_a2dp_source_audio_tx_start_event(void) {
btif_a2dp_source_alarm_cb, nullptr);
btif_a2dp_source_cb.stats.Reset();
- // Assign session_start_us to 1 when time_get_os_boottime_us() is 0 to
- // indicate btif_a2dp_source_start_audio_req() has been called
- btif_a2dp_source_cb.stats.session_start_us = time_get_os_boottime_us();
+ // Assign session_start_us to 1 when
+ // bluetooth::common::time_get_os_boottime_us() is 0 to indicate
+ // btif_a2dp_source_start_audio_req() has been called
+ btif_a2dp_source_cb.stats.session_start_us =
+ bluetooth::common::time_get_os_boottime_us();
if (btif_a2dp_source_cb.stats.session_start_us == 0) {
btif_a2dp_source_cb.stats.session_start_us = 1;
}
@@ -744,7 +746,8 @@ static void btif_a2dp_source_audio_tx_stop_event(void) {
if (btif_av_is_a2dp_offload_enabled()) return;
- btif_a2dp_source_cb.stats.session_end_us = time_get_os_boottime_us();
+ btif_a2dp_source_cb.stats.session_end_us =
+ bluetooth::common::time_get_os_boottime_us();
btif_a2dp_source_update_metrics();
btif_a2dp_source_accumulate_stats(&btif_a2dp_source_cb.stats,
&btif_a2dp_source_cb.accumulated_stats);
@@ -793,7 +796,7 @@ static void btif_a2dp_source_alarm_cb(UNUSED_ATTR void* context) {
static void btif_a2dp_source_audio_handle_timer(void) {
if (btif_av_is_a2dp_offload_enabled()) return;
- uint64_t timestamp_us = time_get_os_boottime_us();
+ uint64_t timestamp_us = bluetooth::common::time_get_os_boottime_us();
log_tstamps_us("A2DP Source tx timer", timestamp_us);
if (!alarm_is_scheduled(btif_a2dp_source_cb.media_alarm)) {
@@ -831,7 +834,7 @@ static uint32_t btif_a2dp_source_read_callback(uint8_t* p_buf, uint32_t len) {
(len - bytes_read);
btif_a2dp_source_cb.stats.media_read_total_underflow_count++;
btif_a2dp_source_cb.stats.media_read_last_underflow_us =
- time_get_os_boottime_us();
+ bluetooth::common::time_get_os_boottime_us();
}
return bytes_read;
@@ -839,7 +842,7 @@ static uint32_t btif_a2dp_source_read_callback(uint8_t* p_buf, uint32_t len) {
static bool btif_a2dp_source_enqueue_callback(BT_HDR* p_buf, size_t frames_n,
uint32_t bytes_read) {
- uint64_t now_us = time_get_os_boottime_us();
+ uint64_t now_us = bluetooth::common::time_get_os_boottime_us();
btif_a2dp_control_log_bytes_read(bytes_read);
/* Check if timer was stopped (media task stopped) */
@@ -931,7 +934,7 @@ static void btif_a2dp_source_audio_tx_flush_event(void) {
btif_a2dp_source_cb.stats.tx_queue_total_flushed_messages +=
fixed_queue_length(btif_a2dp_source_cb.tx_audio_queue);
btif_a2dp_source_cb.stats.tx_queue_last_flushed_us =
- time_get_os_boottime_us();
+ bluetooth::common::time_get_os_boottime_us();
fixed_queue_flush(btif_a2dp_source_cb.tx_audio_queue, osi_free);
UIPC_Ioctl(*a2dp_uipc, UIPC_CH_ID_AV_AUDIO, UIPC_REQ_RX_FLUSH, nullptr);
@@ -947,7 +950,7 @@ static bool btif_a2dp_source_audio_tx_flush_req(void) {
}
BT_HDR* btif_a2dp_source_audio_readbuf(void) {
- uint64_t now_us = time_get_os_boottime_us();
+ uint64_t now_us = bluetooth::common::time_get_os_boottime_us();
BT_HDR* p_buf =
(BT_HDR*)fixed_queue_try_dequeue(btif_a2dp_source_cb.tx_audio_queue);
@@ -1014,7 +1017,7 @@ static void update_scheduling_stats(SchedulingStats* stats, uint64_t now_us,
void btif_a2dp_source_debug_dump(int fd) {
btif_a2dp_source_accumulate_stats(&btif_a2dp_source_cb.stats,
&btif_a2dp_source_cb.accumulated_stats);
- uint64_t now_us = time_get_os_boottime_us();
+ uint64_t now_us = bluetooth::common::time_get_os_boottime_us();
BtifMediaStats* accumulated_stats = &btif_a2dp_source_cb.accumulated_stats;
SchedulingStats* enqueue_stats = &accumulated_stats->tx_queue_enqueue_stats;
SchedulingStats* dequeue_stats = &accumulated_stats->tx_queue_dequeue_stats;
@@ -1186,7 +1189,7 @@ static void btif_a2dp_source_update_metrics(void) {
// mark the metric duration as invalid (-1) in this case
if (stats.session_start_us != 0) {
int64_t session_end_us = stats.session_end_us == 0
- ? time_get_os_boottime_us()
+ ? bluetooth::common::time_get_os_boottime_us()
: stats.session_end_us;
if (static_cast<uint64_t>(session_end_us) > stats.session_start_us) {
metrics.audio_duration_ms =
diff --git a/system/btif/src/btif_debug_btsnoop.cc b/system/btif/src/btif_debug_btsnoop.cc
index 1dcb835e71..3ebbe06649 100644
--- a/system/btif/src/btif_debug_btsnoop.cc
+++ b/system/btif/src/btif_debug_btsnoop.cc
@@ -27,7 +27,6 @@
#include "hci/include/btsnoop_mem.h"
#include "internal_include/bt_target.h"
#include "osi/include/ringbuffer.h"
-#include "osi/include/time.h"
#define REDUCE_HCI_TYPE_TO_SIGNIFICANT_BITS(type) ((type) >> 8)
diff --git a/system/btif/src/btif_debug_conn.cc b/system/btif/src/btif_debug_conn.cc
index 6b4d96fc90..dc36c451db 100644
--- a/system/btif/src/btif_debug_conn.cc
+++ b/system/btif/src/btif_debug_conn.cc
@@ -21,7 +21,7 @@
#include <time.h>
#include "btif/include/btif_debug_conn.h"
-#include "osi/include/time.h"
+#include "common/time_util.h"
#define NUM_CONNECTION_EVENTS 16
#define TEMP_BUFFER_SIZE 30
@@ -69,7 +69,7 @@ void btif_debug_conn_state(const RawAddress& bda,
next_event();
conn_event_t* evt = &connection_events[current_event];
- evt->ts = time_gettimeofday_us();
+ evt->ts = bluetooth::common::time_gettimeofday_us();
evt->state = state;
evt->disconnect_reason = disconnect_reason;
evt->bda = bda;
diff --git a/system/btif/src/btif_dm.cc b/system/btif/src/btif_dm.cc
index 8a8da8514f..b86749fef5 100644
--- a/system/btif/src/btif_dm.cc
+++ b/system/btif/src/btif_dm.cc
@@ -59,12 +59,12 @@
#include "btif_storage.h"
#include "btif_util.h"
#include "btu.h"
+#include "common/metrics.h"
#include "device/include/controller.h"
#include "device/include/interop.h"
#include "internal_include/stack_config.h"
#include "osi/include/allocator.h"
#include "osi/include/log.h"
-#include "osi/include/metrics.h"
#include "osi/include/osi.h"
#include "osi/include/properties.h"
#include "stack/btm/btm_int.h"
@@ -3230,26 +3230,26 @@ static void btif_stats_add_bond_event(const RawAddress& bd_addr,
int type;
btif_get_device_type(bd_addr, &type);
- system_bt_osi::device_type_t device_type;
+ bluetooth::common::device_type_t device_type;
switch (type) {
case BT_DEVICE_TYPE_BREDR:
- device_type = system_bt_osi::DEVICE_TYPE_BREDR;
+ device_type = bluetooth::common::DEVICE_TYPE_BREDR;
break;
case BT_DEVICE_TYPE_BLE:
- device_type = system_bt_osi::DEVICE_TYPE_LE;
+ device_type = bluetooth::common::DEVICE_TYPE_LE;
break;
case BT_DEVICE_TYPE_DUMO:
- device_type = system_bt_osi::DEVICE_TYPE_DUMO;
+ device_type = bluetooth::common::DEVICE_TYPE_DUMO;
break;
default:
- device_type = system_bt_osi::DEVICE_TYPE_UNKNOWN;
+ device_type = bluetooth::common::DEVICE_TYPE_UNKNOWN;
break;
}
uint32_t cod = get_cod(&bd_addr);
uint64_t ts =
event->timestamp.tv_sec * 1000 + event->timestamp.tv_nsec / 1000000;
- system_bt_osi::BluetoothMetricsLogger::GetInstance()->LogPairEvent(
+ bluetooth::common::BluetoothMetricsLogger::GetInstance()->LogPairEvent(
0, ts, cod, device_type);
}
diff --git a/system/btif/src/btif_hf.cc b/system/btif/src/btif_hf.cc
index 038af2ed1d..f5c971bdde 100644
--- a/system/btif/src/btif_hf.cc
+++ b/system/btif/src/btif_hf.cc
@@ -43,7 +43,7 @@
#include "btif_hf.h"
#include "btif_profile_queue.h"
#include "btif_util.h"
-#include "osi/include/metrics.h"
+#include "common/metrics.h"
namespace bluetooth {
namespace headset {
@@ -331,7 +331,7 @@ static void btif_hf_upstreams_evt(uint16_t event, char* p_param) {
btif_hf_cb[idx].state = BTHF_CONNECTION_STATE_CONNECTED;
btif_hf_cb[idx].peer_feat = 0;
clear_phone_state_multihf(&btif_hf_cb[idx]);
- system_bt_osi::BluetoothMetricsLogger::GetInstance()
+ bluetooth::common::BluetoothMetricsLogger::GetInstance()
->LogHeadsetProfileRfcConnection(p_data->open.service_id);
bt_hf_callbacks->ConnectionStateCallback(
btif_hf_cb[idx].state, &btif_hf_cb[idx].connected_bda);
diff --git a/system/common/Android.bp b/system/common/Android.bp
index e19cc43ac9..2fe9aa8dff 100644
--- a/system/common/Android.bp
+++ b/system/common/Android.bp
@@ -2,10 +2,18 @@ cc_library_static {
name: "libbt-common",
defaults: ["fluoride_defaults"],
host_supported: true,
- include_dirs: ["packages/modules/Bluetooth/system"],
+ include_dirs: [
+ "packages/modules/Bluetooth/system",
+ "packages/modules/Bluetooth/system/stack/include",
+ ],
srcs: [
"message_loop_thread.cc",
"execution_barrier.cc",
+ "metrics.cc",
+ "time_util.cc",
+ ],
+ static_libs: [
+ "libbt-protos-lite",
],
}
@@ -14,14 +22,28 @@ cc_test {
test_suites: ["device-tests"],
defaults: ["fluoride_defaults"],
host_supported: true,
- include_dirs: ["packages/modules/Bluetooth/system"],
+ include_dirs: [
+ "packages/modules/Bluetooth/system",
+ "packages/modules/Bluetooth/system/stack/include",
+ ],
srcs : [
- "message_loop_thread_unittest.cc",
"execution_barrier_unittest.cc",
+ "leaky_bonded_queue_unittest.cc",
+ "message_loop_thread_unittest.cc",
+ "metrics_unittest.cc",
+ "time_util_unittest.cc",
+ ],
+ shared_libs: [
+ "libprotobuf-cpp-lite",
],
static_libs : [
+ "libgmock",
"libbt-common",
- ]
+ "libbt-protos-lite",
+ ],
+ sanitize: {
+ cfi: false,
+ },
}
cc_test {
@@ -56,4 +78,4 @@ cc_benchmark {
"libosi",
"libbt-common"
],
-} \ No newline at end of file
+}
diff --git a/system/osi/include/leaky_bonded_queue.h b/system/common/leaky_bonded_queue.h
index 6861e8beb5..087b192cfc 100644
--- a/system/osi/include/leaky_bonded_queue.h
+++ b/system/common/leaky_bonded_queue.h
@@ -21,7 +21,9 @@
#include <mutex>
#include <queue>
-namespace system_bt_osi {
+namespace bluetooth {
+
+namespace common {
/*
* LeakyBondedQueue<T>
@@ -86,8 +88,8 @@ class LeakyBondedQueue {
};
/*
-* Definitions must be in the header for template classes
-*/
+ * Definitions must be in the header for template classes
+ */
template <class T>
LeakyBondedQueue<T>::LeakyBondedQueue(size_t capacity) {
@@ -155,4 +157,6 @@ bool LeakyBondedQueue<T>::Empty() {
return queue_.empty();
}
-} // namespace system_bt_osi
+} // namespace common
+
+} // namespace bluetooth
diff --git a/system/osi/test/leaky_bonded_queue_test.cc b/system/common/leaky_bonded_queue_unittest.cc
index 116676b4c7..fcd55cd7e4 100644
--- a/system/osi/test/leaky_bonded_queue_test.cc
+++ b/system/common/leaky_bonded_queue_unittest.cc
@@ -20,11 +20,11 @@
#include <base/logging.h>
-#include "osi/include/leaky_bonded_queue.h"
+#include "common/leaky_bonded_queue.h"
namespace testing {
-using system_bt_osi::LeakyBondedQueue;
+using bluetooth::common::LeakyBondedQueue;
#define ITEM_EQ(a, b) \
do { \
@@ -239,4 +239,4 @@ TEST(LeakyBondedQueueTest, TestPushNullDeleteQueue) {
queue->Enqueue(item2);
delete queue;
}
-}
+} // namespace testing
diff --git a/system/osi/src/metrics.cc b/system/common/metrics.cc
index 73450b9444..ace021be30 100644
--- a/system/osi/src/metrics.cc
+++ b/system/common/metrics.cc
@@ -15,7 +15,6 @@
* limitations under the License.
*
******************************************************************************/
-#define LOG_TAG "bt_osi_metrics"
#include <unistd.h>
#include <algorithm>
@@ -32,15 +31,16 @@
#include <include/hardware/bt_av.h>
#include "bluetooth/metrics/bluetooth.pb.h"
-#include "osi/include/leaky_bonded_queue.h"
-#include "osi/include/log.h"
#include "osi/include/osi.h"
-#include "osi/include/time.h"
#include "stack/include/btm_api_types.h"
-#include "osi/include/metrics.h"
+#include "leaky_bonded_queue.h"
+#include "metrics.h"
+#include "time_util.h"
-namespace system_bt_osi {
+namespace bluetooth {
+
+namespace common {
using bluetooth::metrics::BluetoothMetricsProto::A2DPSession;
using bluetooth::metrics::BluetoothMetricsProto::A2dpSourceCodec;
@@ -52,24 +52,18 @@ using bluetooth::metrics::BluetoothMetricsProto::
BluetoothSession_DisconnectReasonType;
using bluetooth::metrics::BluetoothMetricsProto::DeviceInfo;
using bluetooth::metrics::BluetoothMetricsProto::DeviceInfo_DeviceType;
+using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileConnectionStats;
+using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType;
+using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_ARRAYSIZE;
+using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_IsValid;
+using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_MAX;
+using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_MIN;
using bluetooth::metrics::BluetoothMetricsProto::PairEvent;
using bluetooth::metrics::BluetoothMetricsProto::ScanEvent;
-using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanTechnologyType;
using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanEventType;
+using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanTechnologyType;
using bluetooth::metrics::BluetoothMetricsProto::WakeEvent;
using bluetooth::metrics::BluetoothMetricsProto::WakeEvent_WakeEventType;
-using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType;
-using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_MIN;
-using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_MAX;
-using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_ARRAYSIZE;
-using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType_IsValid;
-using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileConnectionStats;
-/*
- * Get current OS boot time in millisecond
- */
-static int64_t time_get_os_boottime_ms(void) {
- return time_get_os_boottime_us() / 1000;
-}
static float combine_averages(float avg_a, int64_t ct_a, float avg_b,
int64_t ct_b) {
@@ -359,7 +353,7 @@ void BluetoothMetricsLogger::LogBluetoothSessionStart(
0);
}
if (timestamp_ms == 0) {
- timestamp_ms = time_get_os_boottime_ms();
+ timestamp_ms = bluetooth::common::time_get_os_boottime_ms();
}
pimpl_->bluetooth_session_start_time_ms_ = timestamp_ms;
pimpl_->bluetooth_session_ = new BluetoothSession();
@@ -374,7 +368,7 @@ void BluetoothMetricsLogger::LogBluetoothSessionEnd(
return;
}
if (timestamp_ms == 0) {
- timestamp_ms = time_get_os_boottime_ms();
+ timestamp_ms = bluetooth::common::time_get_os_boottime_ms();
}
int64_t session_duration_sec =
(timestamp_ms - pimpl_->bluetooth_session_start_time_ms_) / 1000;
@@ -458,11 +452,11 @@ void BluetoothMetricsLogger::LogHeadsetProfileRfcConnection(
void BluetoothMetricsLogger::WriteString(std::string* serialized) {
std::lock_guard<std::recursive_mutex> lock(pimpl_->bluetooth_log_lock_);
- LOG_DEBUG(LOG_TAG, "%s building metrics", __func__);
+ LOG(INFO) << __func__ << ": building metrics";
Build();
- LOG_DEBUG(LOG_TAG, "%s serializing metrics", __func__);
+ LOG(INFO) << __func__ << ": serializing metrics";
if (!pimpl_->bluetooth_log_->SerializeToString(serialized)) {
- LOG_ERROR(LOG_TAG, "%s: error serializing metrics", __func__);
+ LOG(ERROR) << __func__ << ": error serializing metrics";
}
// Always clean up log objects
pimpl_->bluetooth_log_->Clear();
@@ -479,8 +473,9 @@ void BluetoothMetricsLogger::WriteBase64(int fd) {
ssize_t ret;
OSI_NO_INTR(ret = write(fd, protoBase64.c_str(), protoBase64.size()));
if (ret == -1) {
- LOG_ERROR(LOG_TAG, "%s: error writing to dumpsys fd: %s (%d)", __func__,
- strerror(errno), errno);
+ LOG(ERROR) << __func__
+ << ": error writing to dumpsys fd: " << strerror(errno) << " ("
+ << std::to_string(errno) << ")";
}
}
@@ -493,7 +488,8 @@ void BluetoothMetricsLogger::CutoffSession() {
new_bt_session->clear_rfcomm_session();
LogBluetoothSessionEnd(DISCONNECT_REASON_METRICS_DUMP, 0);
pimpl_->bluetooth_session_ = new_bt_session;
- pimpl_->bluetooth_session_start_time_ms_ = time_get_os_boottime_ms();
+ pimpl_->bluetooth_session_start_time_ms_ =
+ bluetooth::common::time_get_os_boottime_ms();
pimpl_->a2dp_session_metrics_ = A2dpSessionMetrics();
}
}
@@ -571,4 +567,6 @@ void BluetoothMetricsLogger::Reset() {
pimpl_->scan_event_queue_->Clear();
}
-} // namespace system_bt_osi
+} // namespace common
+
+} // namespace bluetooth
diff --git a/system/osi/include/metrics.h b/system/common/metrics.h
index 504a16a5a7..b441801ad2 100644
--- a/system/osi/include/metrics.h
+++ b/system/common/metrics.h
@@ -23,7 +23,9 @@
#include <memory>
#include <string>
-namespace system_bt_osi {
+namespace bluetooth {
+
+namespace common {
// Typedefs to hide protobuf definition to the rest of stack
@@ -76,7 +78,7 @@ typedef enum {
* buffer_underruns_count: number of times there was no enough
* audio data to add to the media buffer.
* NOTE: Negative values are invalid
-*/
+ */
class A2dpSessionMetrics {
public:
A2dpSessionMetrics() {}
@@ -273,4 +275,7 @@ class BluetoothMetricsLogger {
struct impl;
std::unique_ptr<impl> const pimpl_;
};
-}
+
+} // namespace common
+
+} // namespace bluetooth
diff --git a/system/osi/test/metrics_test.cc b/system/common/metrics_unittest.cc
index bfb548f63e..03a427aa00 100644
--- a/system/osi/test/metrics_test.cc
+++ b/system/common/metrics_unittest.cc
@@ -28,13 +28,15 @@
#include <include/hardware/bt_av.h>
#include "bluetooth/metrics/bluetooth.pb.h"
-#include "osi/include/metrics.h"
-#include "osi/include/time.h"
+#include "common/metrics.h"
+#include "common/time_util.h"
#define BTM_COD_MAJOR_AUDIO_TEST 0x04
namespace testing {
+using bluetooth::common::A2dpSessionMetrics;
+using bluetooth::common::BluetoothMetricsLogger;
using bluetooth::metrics::BluetoothMetricsProto::A2DPSession;
using bluetooth::metrics::BluetoothMetricsProto::A2dpSourceCodec;
using bluetooth::metrics::BluetoothMetricsProto::BluetoothLog;
@@ -45,29 +47,20 @@ using bluetooth::metrics::BluetoothMetricsProto::
BluetoothSession_DisconnectReasonType;
using bluetooth::metrics::BluetoothMetricsProto::DeviceInfo;
using bluetooth::metrics::BluetoothMetricsProto::DeviceInfo_DeviceType;
+using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileConnectionStats;
+using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType;
using bluetooth::metrics::BluetoothMetricsProto::PairEvent;
using bluetooth::metrics::BluetoothMetricsProto::RFCommSession;
using bluetooth::metrics::BluetoothMetricsProto::ScanEvent;
-using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanTechnologyType;
using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanEventType;
+using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanTechnologyType;
using bluetooth::metrics::BluetoothMetricsProto::WakeEvent;
using bluetooth::metrics::BluetoothMetricsProto::WakeEvent_WakeEventType;
-using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileType;
-using bluetooth::metrics::BluetoothMetricsProto::HeadsetProfileConnectionStats;
-using system_bt_osi::BluetoothMetricsLogger;
-using system_bt_osi::A2dpSessionMetrics;
namespace {
const size_t kMaxEventGenerationLimit = 5000;
}
-/*
- * Get current OS boot time in ms
- */
-static int64_t time_get_os_boottime_ms(void) {
- return time_get_os_boottime_us() / 1000;
-}
-
static void sleep_ms(int64_t t) {
std::this_thread::sleep_for(std::chrono::milliseconds(t));
}
@@ -429,7 +422,7 @@ TEST_F(BluetoothMetricsLoggerTest, PairEventTest) {
42, DeviceInfo_DeviceType::DeviceInfo_DeviceType_DEVICE_TYPE_BREDR)));
UpdateLog();
BluetoothMetricsLogger::GetInstance()->LogPairEvent(
- 35, 12345, 42, system_bt_osi::DEVICE_TYPE_BREDR);
+ 35, 12345, 42, bluetooth::common::DEVICE_TYPE_BREDR);
std::string msg_str;
BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -441,7 +434,7 @@ TEST_F(BluetoothMetricsLoggerTest, WakeEventTest) {
"TEST_REQ", "TEST_NAME", 12345));
UpdateLog();
BluetoothMetricsLogger::GetInstance()->LogWakeEvent(
- system_bt_osi::WAKE_EVENT_ACQUIRED, "TEST_REQ", "TEST_NAME", 12345);
+ bluetooth::common::WAKE_EVENT_ACQUIRED, "TEST_REQ", "TEST_NAME", 12345);
std::string msg_str;
BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -455,8 +448,8 @@ TEST_F(BluetoothMetricsLoggerTest, WakeEventOverrunTest) {
UpdateLog();
for (size_t i = 0; i < kMaxEventGenerationLimit; ++i) {
BluetoothMetricsLogger::GetInstance()->LogWakeEvent(
- i % 2 == 0 ? system_bt_osi::WAKE_EVENT_ACQUIRED
- : system_bt_osi::WAKE_EVENT_RELEASED,
+ i % 2 == 0 ? bluetooth::common::WAKE_EVENT_ACQUIRED
+ : bluetooth::common::WAKE_EVENT_RELEASED,
"TEST_REQ", "TEST_NAME", i);
}
std::string msg_str;
@@ -467,12 +460,14 @@ TEST_F(BluetoothMetricsLoggerTest, WakeEventOverrunTest) {
TEST_F(BluetoothMetricsLoggerTest, ScanEventTest) {
scan_events_.push_back(MakeScanEvent(
ScanEvent_ScanEventType::ScanEvent_ScanEventType_SCAN_EVENT_STOP,
- "TEST_INITIATOR", ScanEvent_ScanTechnologyType::
- ScanEvent_ScanTechnologyType_SCAN_TECH_TYPE_BREDR,
+ "TEST_INITIATOR",
+ ScanEvent_ScanTechnologyType::
+ ScanEvent_ScanTechnologyType_SCAN_TECH_TYPE_BREDR,
42, 123456));
UpdateLog();
BluetoothMetricsLogger::GetInstance()->LogScanEvent(
- false, "TEST_INITIATOR", system_bt_osi::SCAN_TECH_TYPE_BREDR, 42, 123456);
+ false, "TEST_INITIATOR", bluetooth::common::SCAN_TECH_TYPE_BREDR, 42,
+ 123456);
std::string msg_str;
BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -488,9 +483,9 @@ TEST_F(BluetoothMetricsLoggerTest, BluetoothSessionTest) {
nullptr, nullptr, nullptr));
UpdateLog();
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
- system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_LE, 123456);
+ bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_LE, 123456);
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
- system_bt_osi::DISCONNECT_REASON_UNKNOWN, 133456);
+ bluetooth::common::DISCONNECT_REASON_UNKNOWN, 133456);
std::string msg_str;
BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -506,7 +501,8 @@ TEST_F(BluetoothMetricsLoggerTest, BluetoothSessionDumpBeforeEndTest) {
nullptr, nullptr, nullptr));
UpdateLog();
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
- system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_LE, time_get_os_boottime_ms());
+ bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_LE,
+ bluetooth::common::time_get_os_boottime_ms());
sleep_ms(1000);
std::string msg_str;
BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
@@ -530,10 +526,10 @@ TEST_F(BluetoothMetricsLoggerTest, BluetoothSessionStartBeforeEndTest) {
nullptr, nullptr, nullptr));
UpdateLog();
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
- system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_UNKNOWN, 0);
+ bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_UNKNOWN, 0);
sleep_ms(1000);
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
- system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_LE, 0);
+ bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_LE, 0);
sleep_ms(2000);
std::string msg_str;
BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
@@ -601,13 +597,13 @@ TEST_F(BluetoothMetricsLoggerTest, A2DPSessionTwoUpdatesTest) {
info, nullptr, session));
UpdateLog();
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
- system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 123456);
+ bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 123456);
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionDeviceInfo(
- BTM_COD_MAJOR_AUDIO_TEST, system_bt_osi::DEVICE_TYPE_BREDR);
+ BTM_COD_MAJOR_AUDIO_TEST, bluetooth::common::DEVICE_TYPE_BREDR);
BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics1);
BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics2);
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
- system_bt_osi::DISCONNECT_REASON_UNKNOWN, 133456);
+ bluetooth::common::DISCONNECT_REASON_UNKNOWN, 133456);
std::string msg_str;
BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -662,9 +658,9 @@ TEST_F(BluetoothMetricsLoggerTest, A2DPSessionTwoUpdatesSeparatedbyDumpTest) {
info, nullptr, session));
UpdateLog();
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
- system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
+ bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionDeviceInfo(
- BTM_COD_MAJOR_AUDIO_TEST, system_bt_osi::DEVICE_TYPE_BREDR);
+ BTM_COD_MAJOR_AUDIO_TEST, bluetooth::common::DEVICE_TYPE_BREDR);
BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics1);
sleep_ms(1000);
std::string msg_str;
@@ -686,7 +682,7 @@ TEST_F(BluetoothMetricsLoggerTest, A2DPSessionTwoUpdatesSeparatedbyDumpTest) {
sleep_ms(1000);
BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics2);
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
- system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0);
+ bluetooth::common::DISCONNECT_REASON_UNKNOWN, 0);
msg_str.clear();
BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -731,13 +727,13 @@ TEST_F(BluetoothMetricsLoggerTest, A2DPSessionTwoUpdatesSeparatedbyEndTest) {
info, nullptr, session));
UpdateLog();
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
- system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
+ bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionDeviceInfo(
- BTM_COD_MAJOR_AUDIO_TEST, system_bt_osi::DEVICE_TYPE_BREDR);
+ BTM_COD_MAJOR_AUDIO_TEST, bluetooth::common::DEVICE_TYPE_BREDR);
BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics1);
sleep_ms(1000);
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
- system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0);
+ bluetooth::common::DISCONNECT_REASON_UNKNOWN, 0);
std::string msg_str;
BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -762,11 +758,11 @@ TEST_F(BluetoothMetricsLoggerTest, A2DPSessionTwoUpdatesSeparatedbyEndTest) {
nullptr, nullptr, session));
UpdateLog();
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
- system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
+ bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
sleep_ms(1000);
BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics2);
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
- system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0);
+ bluetooth::common::DISCONNECT_REASON_UNKNOWN, 0);
msg_str.clear();
BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -892,9 +888,9 @@ TEST_F(BluetoothMetricsLoggerTest, A2DPSessionDumpBeforeTwoUpdatesTest) {
info, nullptr, nullptr));
UpdateLog();
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart(
- system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
+ bluetooth::common::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0);
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionDeviceInfo(
- BTM_COD_MAJOR_AUDIO_TEST, system_bt_osi::DEVICE_TYPE_BREDR);
+ BTM_COD_MAJOR_AUDIO_TEST, bluetooth::common::DEVICE_TYPE_BREDR);
sleep_ms(1000);
std::string msg_str;
BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
@@ -917,7 +913,7 @@ TEST_F(BluetoothMetricsLoggerTest, A2DPSessionDumpBeforeTwoUpdatesTest) {
BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics2);
sleep_ms(1000);
BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd(
- system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0);
+ bluetooth::common::DISCONNECT_REASON_UNKNOWN, 0);
msg_str.clear();
BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str);
EXPECT_THAT(msg_str, StrEq(bt_log_str_));
@@ -1009,4 +1005,4 @@ TEST_F(BluetoothMetricsLoggerTest, LogHeadsetProfileRfcConnectionErrorTest) {
EXPECT_EQ(metrics->headset_profile_connection_stats_size(), 0);
delete metrics;
}
-}
+} // namespace testing
diff --git a/system/osi/src/time.cc b/system/common/time_util.cc
index 1a47504b0d..273be181d0 100644
--- a/system/osi/src/time.cc
+++ b/system/common/time_util.cc
@@ -16,28 +16,32 @@
*
******************************************************************************/
-#define LOG_TAG "bt_osi_time"
-
#include <sys/time.h>
#include <time.h>
-#include "osi/include/time.h"
+#include "common/time_util.h"
-uint32_t time_get_os_boottime_ms(void) {
- return (uint32_t)(time_get_os_boottime_us() / 1000);
-}
+namespace bluetooth {
+
+namespace common {
-uint64_t time_get_os_boottime_us(void) {
- struct timespec ts_now;
+uint64_t time_get_os_boottime_ms() { return time_get_os_boottime_us() / 1000; }
+
+uint64_t time_get_os_boottime_us() {
+ struct timespec ts_now = {};
clock_gettime(CLOCK_BOOTTIME, &ts_now);
return ((uint64_t)ts_now.tv_sec * 1000000L) +
((uint64_t)ts_now.tv_nsec / 1000);
}
-uint64_t time_gettimeofday_us(void) {
- struct timeval tv;
- gettimeofday(&tv, NULL);
+uint64_t time_gettimeofday_us() {
+ struct timeval tv = {};
+ gettimeofday(&tv, nullptr);
return static_cast<uint64_t>(tv.tv_sec) * 1000000ULL +
static_cast<uint64_t>(tv.tv_usec);
}
+
+} // namespace common
+
+} // namespace bluetooth \ No newline at end of file
diff --git a/system/osi/include/time.h b/system/common/time_util.h
index f3f233c6aa..70a64d2cba 100644
--- a/system/osi/include/time.h
+++ b/system/common/time_util.h
@@ -18,23 +18,21 @@
#pragma once
-#include <stdint.h>
+#include <cstdint>
+
+namespace bluetooth {
+
+namespace common {
// 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.
-//
-// TODO: This function's return type should be modified to |uint64_t|.
-// Be careful: some of the code that is using it assumes the return type
-// is uint32_t.
-uint32_t time_get_os_boottime_ms(void);
+uint64_t time_get_os_boottime_ms();
// Get the OS boot time in microseconds.
-uint64_t time_get_os_boottime_us(void);
+uint64_t time_get_os_boottime_us();
// Get the current wall clock time in microseconds.
-uint64_t time_gettimeofday_us(void);
+uint64_t time_gettimeofday_us();
+
+} // namespace common
+
+} // namespace bluetooth
diff --git a/system/common/time_util_unittest.cc b/system/common/time_util_unittest.cc
new file mode 100644
index 0000000000..77e205d3a6
--- /dev/null
+++ b/system/common/time_util_unittest.cc
@@ -0,0 +1,146 @@
+/******************************************************************************
+ *
+ * Copyright 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 "common/time_util.h"
+
+// Generous upper bound: 10 seconds
+static const uint32_t TEST_TIME_DELTA_UPPER_BOUND_MS = 10 * 1000;
+
+//
+// Test that the return value of bluetooth::common::time_get_os_boottime_ms() is
+// not zero.
+//
+TEST(TimeTest, test_time_get_os_boottime_ms_not_zero) {
+ uint64_t t1 = bluetooth::common::time_get_os_boottime_ms();
+ ASSERT_GT(t1, uint64_t(0));
+}
+
+//
+// Test that the return value of bluetooth::common::time_get_os_boottime_us() is
+// not zero.
+//
+TEST(TimeTest, test_time_get_os_boottime_us_not_zero) {
+ uint64_t t1 = bluetooth::common::time_get_os_boottime_us();
+ ASSERT_GT(t1, uint64_t(0));
+}
+
+//
+// Test that the return value of bluetooth::common::time_get_os_boottime_ms()
+// is monotonically increasing within reasonable boundries.
+//
+TEST(TimeTest, test_time_get_os_boottime_ms_increases_upper_bound) {
+ uint64_t t1 = bluetooth::common::time_get_os_boottime_ms();
+ uint64_t t2 = bluetooth::common::time_get_os_boottime_ms();
+ ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS);
+}
+
+//
+// Test that the return value of bluetooth::common::time_get_os_boottime_us()
+// is monotonically increasing within reasonable boundries.
+//
+TEST(TimeTest, test_time_get_os_boottime_us_increases_upper_bound) {
+ uint64_t t1 = bluetooth::common::time_get_os_boottime_us();
+ uint64_t t2 = bluetooth::common::time_get_os_boottime_us();
+ ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
+}
+
+//
+// Test that the return value of bluetooth::common::time_get_os_boottime_ms()
+// is increasing.
+//
+TEST(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
+ uint64_t t1 = bluetooth::common::time_get_os_boottime_ms();
+ int err = nanosleep(&delay, &delay);
+ uint64_t t2 = bluetooth::common::time_get_os_boottime_ms();
+
+ ASSERT_EQ(err, 0);
+ ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_MS);
+ ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS);
+}
+
+//
+// Test that the return value of bluetooth::common::time_get_os_boottime_us()
+// is increasing.
+//
+TEST(TimeTest, test_time_get_os_boottime_us_increases_lower_bound) {
+ static const uint64_t TEST_TIME_SLEEP_US = 100 * 1000;
+ struct timespec delay = {};
+
+ delay.tv_sec = TEST_TIME_SLEEP_US / (1000 * 1000);
+ delay.tv_nsec = 1000 * (TEST_TIME_SLEEP_US % (1000 * 1000));
+
+ // Take two timestamps with sleep in-between
+ uint64_t t1 = bluetooth::common::time_get_os_boottime_us();
+ int err = nanosleep(&delay, &delay);
+ uint64_t t2 = bluetooth::common::time_get_os_boottime_us();
+
+ ASSERT_EQ(err, 0);
+ ASSERT_GT(t2, t1);
+ ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_US);
+ ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
+}
+
+//
+// Test that the return value of bluetooth::common::time_gettimeofday_us() is
+// not zero.
+//
+TEST(TimeTest, test_time_gettimeofday_us_not_zero) {
+ uint64_t t1 = bluetooth::common::time_gettimeofday_us();
+ ASSERT_GT(t1, uint64_t(0));
+}
+
+//
+// Test that the return value of bluetooth::common::time_gettimeofday_us()
+// is monotonically increasing within reasonable boundaries.
+//
+TEST(TimeTest, test_time_gettimeofday_us_increases_upper_bound) {
+ uint64_t t1 = bluetooth::common::time_gettimeofday_us();
+ uint64_t t2 = bluetooth::common::time_gettimeofday_us();
+ ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
+}
+
+//
+// Test that the return value of bluetooth::common::time_gettimeofday_us()
+// is increasing.
+//
+TEST(TimeTest, test_time_gettimeofday_us_increases_lower_bound) {
+ static const uint64_t TEST_TIME_SLEEP_US = 100 * 1000;
+ struct timespec delay = {};
+
+ delay.tv_sec = TEST_TIME_SLEEP_US / (1000 * 1000);
+ delay.tv_nsec = 1000 * (TEST_TIME_SLEEP_US % (1000 * 1000));
+
+ // Take two timestamps with sleep in-between
+ uint64_t t1 = bluetooth::common::time_gettimeofday_us();
+ int err = nanosleep(&delay, &delay);
+ uint64_t t2 = bluetooth::common::time_gettimeofday_us();
+
+ ASSERT_EQ(err, 0);
+ ASSERT_GT(t2, t1);
+ ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_US);
+ ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
+}
diff --git a/system/hci/src/btsnoop.cc b/system/hci/src/btsnoop.cc
index 9812b617c3..6938725a9c 100644
--- a/system/hci/src/btsnoop.cc
+++ b/system/hci/src/btsnoop.cc
@@ -36,12 +36,12 @@
#include <unistd.h>
#include "bt_types.h"
+#include "common/time_util.h"
#include "hci/include/btsnoop.h"
#include "hci/include/btsnoop_mem.h"
#include "hci_layer.h"
#include "osi/include/log.h"
#include "osi/include/properties.h"
-#include "osi/include/time.h"
#include "stack_config.h"
// The number of of packets per btsnoop file before we rotate to the next
@@ -129,7 +129,7 @@ static void capture(const BT_HDR* buffer, bool is_received) {
uint8_t* p = const_cast<uint8_t*>(buffer->data + buffer->offset);
std::lock_guard<std::mutex> lock(btsnoop_mutex);
- uint64_t timestamp_us = time_gettimeofday_us();
+ uint64_t timestamp_us = bluetooth::common::time_gettimeofday_us();
btsnoop_mem_capture(buffer, timestamp_us);
if (logfile_fd == INVALID_FD) return;
diff --git a/system/osi/Android.bp b/system/osi/Android.bp
index de33bfa80e..81a0c0f330 100644
--- a/system/osi/Android.bp
+++ b/system/osi/Android.bp
@@ -54,7 +54,6 @@ cc_library_static {
"src/future.cc",
"src/hash_map_utils.cc",
"src/list.cc",
- "src/metrics.cc",
"src/mutex.cc",
"src/osi.cc",
"src/properties.cc",
@@ -65,7 +64,6 @@ cc_library_static {
"src/socket_utils/socket_local_client.cc",
"src/socket_utils/socket_local_server.cc",
"src/thread.cc",
- "src/time.cc",
"src/wakelock.cc",
],
shared_libs: [
@@ -104,16 +102,13 @@ cc_test {
"test/fixed_queue_test.cc",
"test/future_test.cc",
"test/hash_map_utils_test.cc",
- "test/leaky_bonded_queue_test.cc",
"test/list_test.cc",
- "test/metrics_test.cc",
"test/properties_test.cc",
"test/rand_test.cc",
"test/reactor_test.cc",
"test/ringbuffer_test.cc",
"test/semaphore_test.cc",
"test/thread_test.cc",
- "test/time_test.cc",
"test/wakelock_test.cc",
],
shared_libs: [
diff --git a/system/osi/include/alarm.h b/system/osi/include/alarm.h
index 2d07b9aeb6..2db228bf79 100644
--- a/system/osi/include/alarm.h
+++ b/system/osi/include/alarm.h
@@ -20,7 +20,6 @@
#include <stdbool.h>
#include <stdint.h>
-#include "osi/include/time.h"
typedef struct alarm_t alarm_t;
typedef struct fixed_queue_t fixed_queue_t;
diff --git a/system/osi/src/wakelock.cc b/system/osi/src/wakelock.cc
index aec9ea9624..44f59608a9 100644
--- a/system/osi/src/wakelock.cc
+++ b/system/osi/src/wakelock.cc
@@ -34,15 +34,15 @@
#include <string>
#include "base/logging.h"
+#include "common/metrics.h"
#include "osi/include/alarm.h"
#include "osi/include/allocator.h"
#include "osi/include/log.h"
-#include "osi/include/metrics.h"
#include "osi/include/osi.h"
#include "osi/include/thread.h"
#include "osi/include/wakelock.h"
-using system_bt_osi::BluetoothMetricsLogger;
+using bluetooth::common::BluetoothMetricsLogger;
static bt_os_callouts_t* wakelock_os_callouts = NULL;
static bool is_native = true;
@@ -281,7 +281,7 @@ static void update_wakelock_acquired_stats(bt_status_t acquired_status) {
wakelock_stats.last_acquired_timestamp_ms = just_now_ms;
BluetoothMetricsLogger::GetInstance()->LogWakeEvent(
- system_bt_osi::WAKE_EVENT_ACQUIRED, "", "", just_now_ms);
+ bluetooth::common::WAKE_EVENT_ACQUIRED, "", "", just_now_ms);
}
//
@@ -323,7 +323,7 @@ static void update_wakelock_released_stats(bt_status_t released_status) {
wakelock_stats.total_acquired_interval_ms += delta_ms;
BluetoothMetricsLogger::GetInstance()->LogWakeEvent(
- system_bt_osi::WAKE_EVENT_RELEASED, "", "", just_now_ms);
+ bluetooth::common::WAKE_EVENT_RELEASED, "", "", just_now_ms);
}
void wakelock_debug_dump(int fd) {
diff --git a/system/osi/test/time_test.cc b/system/osi/test/time_test.cc
deleted file mode 100644
index f14842d20a..0000000000
--- a/system/osi/test/time_test.cc
+++ /dev/null
@@ -1,154 +0,0 @@
-/******************************************************************************
- *
- * Copyright 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"
-
-#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_us() is not zero.
-//
-TEST_F(TimeTest, test_time_get_os_boottime_us_not_zero) {
- uint64_t t1 = time_get_os_boottime_us();
- ASSERT_TRUE(t1 > 0);
-}
-
-//
-// 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_us()
-// is monotonically increasing within reasonable boundries.
-//
-TEST_F(TimeTest, test_time_get_os_boottime_us_increases_upper_bound) {
- uint64_t t1 = time_get_os_boottime_us();
- uint64_t t2 = time_get_os_boottime_us();
- ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
-}
-
-//
-// 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);
-}
-
-//
-// Test that the return value of time_get_os_boottime_us()
-// is increasing.
-//
-TEST_F(TimeTest, test_time_get_os_boottime_us_increases_lower_bound) {
- static const uint64_t TEST_TIME_SLEEP_US = 100 * 1000;
- struct timespec delay;
-
- delay.tv_sec = TEST_TIME_SLEEP_US / (1000 * 1000);
- delay.tv_nsec = 1000 * (TEST_TIME_SLEEP_US % (1000 * 1000));
-
- // Take two timestamps with sleep in-between
- uint64_t t1 = time_get_os_boottime_us();
- int err = nanosleep(&delay, &delay);
- uint64_t t2 = time_get_os_boottime_us();
-
- ASSERT_TRUE(err == 0);
- ASSERT_TRUE(t2 > t1);
- ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_US);
- ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
-}
-
-//
-// Test that the return value of time_gettimeofday_us() is not zero.
-//
-TEST_F(TimeTest, test_time_gettimeofday_us_not_zero) {
- uint64_t t1 = time_gettimeofday_us();
- ASSERT_TRUE(t1 > 0);
-}
-
-//
-// Test that the return value of time_gettimeofday_us()
-// is monotonically increasing within reasonable boundaries.
-//
-TEST_F(TimeTest, test_time_gettimeofday_us_increases_upper_bound) {
- uint64_t t1 = time_gettimeofday_us();
- uint64_t t2 = time_gettimeofday_us();
- ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
-}
-
-//
-// Test that the return value of time_gettimeofday_us()
-// is increasing.
-//
-TEST_F(TimeTest, test_time_gettimeofday_us_increases_lower_bound) {
- static const uint64_t TEST_TIME_SLEEP_US = 100 * 1000;
- struct timespec delay;
-
- delay.tv_sec = TEST_TIME_SLEEP_US / (1000 * 1000);
- delay.tv_nsec = 1000 * (TEST_TIME_SLEEP_US % (1000 * 1000));
-
- // Take two timestamps with sleep in-between
- uint64_t t1 = time_gettimeofday_us();
- int err = nanosleep(&delay, &delay);
- uint64_t t2 = time_gettimeofday_us();
-
- ASSERT_TRUE(err == 0);
- ASSERT_TRUE(t2 > t1);
- ASSERT_TRUE((t2 - t1) >= TEST_TIME_SLEEP_US);
- ASSERT_TRUE((t2 - t1) < TEST_TIME_DELTA_UPPER_BOUND_MS * 1000);
-}
diff --git a/system/stack/Android.bp b/system/stack/Android.bp
index edbd888284..80e35e26bb 100644
--- a/system/stack/Android.bp
+++ b/system/stack/Android.bp
@@ -274,6 +274,7 @@ cc_test {
"liblog",
"libgmock",
"libosi",
+ "libbt-common",
"libbt-protos-lite",
],
sanitize: {
diff --git a/system/stack/a2dp/a2dp_aac_encoder.cc b/system/stack/a2dp/a2dp_aac_encoder.cc
index 65b81de767..f6c68a6bf7 100644
--- a/system/stack/a2dp/a2dp_aac_encoder.cc
+++ b/system/stack/a2dp/a2dp_aac_encoder.cc
@@ -27,6 +27,7 @@
#include "a2dp_aac.h"
#include "bt_common.h"
+#include "common/time_util.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
@@ -125,7 +126,8 @@ void a2dp_aac_encoder_init(const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params,
aacEncClose(&a2dp_aac_encoder_cb.aac_handle);
memset(&a2dp_aac_encoder_cb, 0, sizeof(a2dp_aac_encoder_cb));
- a2dp_aac_encoder_cb.stats.session_start_us = time_get_os_boottime_us();
+ a2dp_aac_encoder_cb.stats.session_start_us =
+ bluetooth::common::time_get_os_boottime_us();
a2dp_aac_encoder_cb.read_callback = read_callback;
a2dp_aac_encoder_cb.enqueue_callback = enqueue_callback;
diff --git a/system/stack/a2dp/a2dp_sbc_encoder.cc b/system/stack/a2dp/a2dp_sbc_encoder.cc
index 3161362bed..c814253adb 100644
--- a/system/stack/a2dp/a2dp_sbc_encoder.cc
+++ b/system/stack/a2dp/a2dp_sbc_encoder.cc
@@ -28,6 +28,7 @@
#include "a2dp_sbc.h"
#include "a2dp_sbc_up_sample.h"
#include "bt_common.h"
+#include "common/time_util.h"
#include "embdrv/sbc/encoder/include/sbc_encoder.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
@@ -137,7 +138,8 @@ void a2dp_sbc_encoder_init(const tA2DP_ENCODER_INIT_PEER_PARAMS* p_peer_params,
a2dp_source_enqueue_callback_t enqueue_callback) {
memset(&a2dp_sbc_encoder_cb, 0, sizeof(a2dp_sbc_encoder_cb));
- a2dp_sbc_encoder_cb.stats.session_start_us = time_get_os_boottime_us();
+ a2dp_sbc_encoder_cb.stats.session_start_us =
+ bluetooth::common::time_get_os_boottime_us();
a2dp_sbc_encoder_cb.read_callback = read_callback;
a2dp_sbc_encoder_cb.enqueue_callback = enqueue_callback;
diff --git a/system/stack/a2dp/a2dp_vendor_aptx_encoder.cc b/system/stack/a2dp/a2dp_vendor_aptx_encoder.cc
index 1b65776bb0..0d605c057c 100644
--- a/system/stack/a2dp/a2dp_vendor_aptx_encoder.cc
+++ b/system/stack/a2dp/a2dp_vendor_aptx_encoder.cc
@@ -26,6 +26,7 @@
#include "a2dp_vendor.h"
#include "a2dp_vendor_aptx.h"
#include "bt_common.h"
+#include "common/time_util.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
@@ -174,7 +175,8 @@ void a2dp_vendor_aptx_encoder_init(
a2dp_source_enqueue_callback_t enqueue_callback) {
memset(&a2dp_aptx_encoder_cb, 0, sizeof(a2dp_aptx_encoder_cb));
- a2dp_aptx_encoder_cb.stats.session_start_us = time_get_os_boottime_us();
+ a2dp_aptx_encoder_cb.stats.session_start_us =
+ bluetooth::common::time_get_os_boottime_us();
a2dp_aptx_encoder_cb.read_callback = read_callback;
a2dp_aptx_encoder_cb.enqueue_callback = enqueue_callback;
diff --git a/system/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc b/system/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc
index dc045e399b..fb782dd8df 100644
--- a/system/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc
+++ b/system/stack/a2dp/a2dp_vendor_aptx_hd_encoder.cc
@@ -26,6 +26,7 @@
#include "a2dp_vendor.h"
#include "a2dp_vendor_aptx_hd.h"
#include "bt_common.h"
+#include "common/time_util.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
@@ -174,7 +175,8 @@ void a2dp_vendor_aptx_hd_encoder_init(
a2dp_source_enqueue_callback_t enqueue_callback) {
memset(&a2dp_aptx_hd_encoder_cb, 0, sizeof(a2dp_aptx_hd_encoder_cb));
- a2dp_aptx_hd_encoder_cb.stats.session_start_us = time_get_os_boottime_us();
+ a2dp_aptx_hd_encoder_cb.stats.session_start_us =
+ bluetooth::common::time_get_os_boottime_us();
a2dp_aptx_hd_encoder_cb.read_callback = read_callback;
a2dp_aptx_hd_encoder_cb.enqueue_callback = enqueue_callback;
diff --git a/system/stack/a2dp/a2dp_vendor_ldac_encoder.cc b/system/stack/a2dp/a2dp_vendor_ldac_encoder.cc
index 6c01db120f..bd1653b2e4 100644
--- a/system/stack/a2dp/a2dp_vendor_ldac_encoder.cc
+++ b/system/stack/a2dp/a2dp_vendor_ldac_encoder.cc
@@ -33,6 +33,7 @@
#include "a2dp_vendor_ldac.h"
#include "a2dp_vendor_ldac_abr.h"
#include "bt_common.h"
+#include "common/time_util.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
@@ -285,7 +286,8 @@ void a2dp_vendor_ldac_encoder_init(
a2dp_ldac_abr_free_handle(a2dp_ldac_encoder_cb.ldac_abr_handle);
memset(&a2dp_ldac_encoder_cb, 0, sizeof(a2dp_ldac_encoder_cb));
- a2dp_ldac_encoder_cb.stats.session_start_us = time_get_os_boottime_us();
+ a2dp_ldac_encoder_cb.stats.session_start_us =
+ bluetooth::common::time_get_os_boottime_us();
a2dp_ldac_encoder_cb.read_callback = read_callback;
a2dp_ldac_encoder_cb.enqueue_callback = enqueue_callback;
diff --git a/system/stack/btm/btm_inq.cc b/system/stack/btm/btm_inq.cc
index 383d290381..1a5d7f526a 100644
--- a/system/stack/btm/btm_inq.cc
+++ b/system/stack/btm/btm_inq.cc
@@ -30,9 +30,9 @@
#include <stdlib.h>
#include <string.h>
+#include "common/time_util.h"
#include "device/include/controller.h"
#include "osi/include/osi.h"
-#include "osi/include/time.h"
#include "advertise_data_parser.h"
#include "bt_common.h"
@@ -1324,7 +1324,7 @@ tINQ_DB_ENT* btm_inq_db_new(const RawAddress& p_bda) {
uint16_t xx;
tINQ_DB_ENT* p_ent = btm_cb.btm_inq_vars.inq_db;
tINQ_DB_ENT* p_old = btm_cb.btm_inq_vars.inq_db;
- uint32_t ot = 0xFFFFFFFF;
+ uint64_t ot = UINT64_MAX;
for (xx = 0; xx < BTM_INQ_DB_SIZE; xx++, p_ent++) {
if (!p_ent->in_use) {
@@ -1738,7 +1738,7 @@ void btm_process_inq_results(uint8_t* p, uint8_t inq_res_mode) {
p_cur->dev_class[2] = dc[2];
p_cur->clock_offset = clock_offset | BTM_CLOCK_OFFSET_VALID;
- p_i->time_of_resp = time_get_os_boottime_ms();
+ p_i->time_of_resp = bluetooth::common::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/system/stack/btm/btm_int_types.h b/system/stack/btm/btm_int_types.h
index 95acb5dff7..c4398a62e2 100644
--- a/system/stack/btm/btm_int_types.h
+++ b/system/stack/btm/btm_int_types.h
@@ -210,7 +210,7 @@ typedef struct {
} tINQ_BDADDR;
typedef struct {
- uint32_t time_of_resp;
+ uint64_t time_of_resp;
uint32_t
inq_count; /* "timestamps" the entry with a particular inquiry count */
/* Used for determining if a response has already been */
@@ -801,8 +801,7 @@ typedef struct {
tBTM_SEC_DEV_REC* p_collided_dev_rec;
alarm_t* sec_collision_timer;
- uint32_t collision_start_time;
- uint32_t max_collision_delay;
+ uint64_t collision_start_time;
uint32_t dev_rec_count; /* Counter used for device record timestamp */
uint8_t security_mode;
bool pairing_disabled;
diff --git a/system/stack/btm/btm_sec.cc b/system/stack/btm/btm_sec.cc
index 54415ffeb7..4fb497f519 100644
--- a/system/stack/btm/btm_sec.cc
+++ b/system/stack/btm/btm_sec.cc
@@ -28,10 +28,10 @@
#include <stdio.h>
#include <string.h>
+#include "common/time_util.h"
#include "device/include/controller.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
-#include "osi/include/time.h"
#include "bt_types.h"
#include "bt_utils.h"
@@ -2688,7 +2688,6 @@ void btm_sec_check_pending_reqs(void) {
void btm_sec_init(uint8_t sec_mode) {
btm_cb.security_mode = sec_mode;
btm_cb.pairing_bda = RawAddress::kAny;
- btm_cb.max_collision_delay = BTM_SEC_MAX_COLLISION_DELAY;
}
/*******************************************************************************
@@ -3677,10 +3676,10 @@ static void btm_sec_auth_collision(uint16_t handle) {
tBTM_SEC_DEV_REC* p_dev_rec;
if (!btm_cb.collision_start_time)
- btm_cb.collision_start_time = time_get_os_boottime_ms();
+ btm_cb.collision_start_time = bluetooth::common::time_get_os_boottime_ms();
- if ((time_get_os_boottime_ms() - btm_cb.collision_start_time) <
- btm_cb.max_collision_delay) {
+ if ((bluetooth::common::time_get_os_boottime_ms() -
+ btm_cb.collision_start_time) < BTM_SEC_MAX_COLLISION_DELAY) {
if (handle == BTM_SEC_INVALID_HANDLE) {
p_dev_rec = btm_sec_find_dev_by_sec_state(BTM_SEC_STATE_AUTHENTICATING);
if (p_dev_rec == NULL)
diff --git a/system/stack/include/a2dp_aac_encoder.h b/system/stack/include/a2dp_aac_encoder.h
index 5adf2184e3..143a5774a2 100644
--- a/system/stack/include/a2dp_aac_encoder.h
+++ b/system/stack/include/a2dp_aac_encoder.h
@@ -22,7 +22,6 @@
#define A2DP_AAC_ENCODER_H
#include "a2dp_codec_api.h"
-#include "osi/include/time.h"
// Loads the A2DP AAC encoder.
// Return true on success, otherwise false.
diff --git a/system/stack/include/a2dp_codec_api.h b/system/stack/include/a2dp_codec_api.h
index f5e1573927..a9e78e6fc0 100644
--- a/system/stack/include/a2dp_codec_api.h
+++ b/system/stack/include/a2dp_codec_api.h
@@ -34,7 +34,6 @@
#include "a2dp_api.h"
#include "audio_a2dp_hw/include/audio_a2dp_hw.h"
#include "avdt_api.h"
-#include "osi/include/time.h"
class tBT_A2DP_OFFLOAD;
diff --git a/system/stack/include/a2dp_sbc_encoder.h b/system/stack/include/a2dp_sbc_encoder.h
index d97e78ce4e..0acf16f052 100644
--- a/system/stack/include/a2dp_sbc_encoder.h
+++ b/system/stack/include/a2dp_sbc_encoder.h
@@ -25,7 +25,6 @@
#define A2DP_SBC_ENCODER_H
#include "a2dp_codec_api.h"
-#include "osi/include/time.h"
// Loads the A2DP SBC encoder.
// Return true on success, otherwise false.
diff --git a/system/stack/include/a2dp_vendor_aptx_encoder.h b/system/stack/include/a2dp_vendor_aptx_encoder.h
index 585819de27..c0954fada1 100644
--- a/system/stack/include/a2dp_vendor_aptx_encoder.h
+++ b/system/stack/include/a2dp_vendor_aptx_encoder.h
@@ -22,7 +22,6 @@
#define A2DP_VENDOR_APTX_ENCODER_H
#include "a2dp_codec_api.h"
-#include "osi/include/time.h"
// Loads the A2DP aptX encoder.
// Return true on success, otherwise false.
diff --git a/system/stack/include/a2dp_vendor_aptx_hd_encoder.h b/system/stack/include/a2dp_vendor_aptx_hd_encoder.h
index c7b5de3260..84ef8a035c 100644
--- a/system/stack/include/a2dp_vendor_aptx_hd_encoder.h
+++ b/system/stack/include/a2dp_vendor_aptx_hd_encoder.h
@@ -22,7 +22,6 @@
#define A2DP_VENDOR_APTX_HD_ENCODER_H
#include "a2dp_codec_api.h"
-#include "osi/include/time.h"
// Loads the A2DP aptX-HD encoder.
// Return true on success, otherwise false.
diff --git a/system/stack/include/a2dp_vendor_ldac_encoder.h b/system/stack/include/a2dp_vendor_ldac_encoder.h
index 9980f398a8..f5e320aa8f 100644
--- a/system/stack/include/a2dp_vendor_ldac_encoder.h
+++ b/system/stack/include/a2dp_vendor_ldac_encoder.h
@@ -22,7 +22,6 @@
#define A2DP_VENDOR_LDAC_ENCODER_H
#include "a2dp_codec_api.h"
-#include "osi/include/time.h"
// Loads the A2DP LDAC encoder.
// Return true on success, otherwise false.
diff --git a/system/stack/l2cap/l2c_csm.cc b/system/stack/l2cap/l2c_csm.cc
index 34184738dd..06ef7e868e 100644
--- a/system/stack/l2cap/l2c_csm.cc
+++ b/system/stack/l2cap/l2c_csm.cc
@@ -30,6 +30,7 @@
#include "bt_target.h"
#include "btm_int.h"
#include "btu.h"
+#include "common/time_util.h"
#include "hcidefs.h"
#include "hcimsgs.h"
#include "l2c_int.h"
@@ -816,7 +817,8 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
}
#if (L2CAP_ERTM_STATS == TRUE)
- p_ccb->fcrb.connect_tick_count = time_get_os_boottime_ms();
+ p_ccb->fcrb.connect_tick_count =
+ bluetooth::common::time_get_os_boottime_ms();
#endif
/* See if we can forward anything on the hold queue */
if (!fixed_queue_is_empty(p_ccb->xmit_hold_q)) {
@@ -904,7 +906,8 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data) {
if (p_ccb->fcrb.wait_ack) l2c_fcr_start_timer(p_ccb);
#if (L2CAP_ERTM_STATS == TRUE)
- p_ccb->fcrb.connect_tick_count = time_get_os_boottime_ms();
+ p_ccb->fcrb.connect_tick_count =
+ bluetooth::common::time_get_os_boottime_ms();
#endif
/* See if we can forward anything on the hold queue */
diff --git a/system/stack/l2cap/l2c_fcr.cc b/system/stack/l2cap/l2c_fcr.cc
index b20b9c1de7..d543ec4686 100644
--- a/system/stack/l2cap/l2c_fcr.cc
+++ b/system/stack/l2cap/l2c_fcr.cc
@@ -34,6 +34,7 @@
#include "btm_api.h"
#include "btm_int.h"
#include "btu.h"
+#include "common/time_util.h"
#include "hcimsgs.h"
#include "l2c_api.h"
#include "l2c_int.h"
@@ -231,7 +232,8 @@ void l2c_fcr_cleanup(tL2C_CCB* p_ccb) {
#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_t dur = time_get_os_boottime_ms() - p_ccb->fcrb.connect_tick_count;
+ uint64_t dur = bluetooth::common::time_get_os_boottime_ms() -
+ p_ccb->fcrb.connect_tick_count;
size_t p_str_size = 120;
char* p_str = (char*)osi_malloc(p_str_size);
uint16_t i;
@@ -1786,7 +1788,9 @@ BT_HDR* l2c_fcr_get_next_xmit_sdu_seg(tL2C_CCB* p_ccb,
* to include extra 4 octets at the end.
*/
p = ((uint8_t*)(p_wack + 1)) + p_wack->offset + p_wack->len;
- UINT32_TO_STREAM(p, time_get_os_boottime_ms());
+ // Have to cast to uint32_t which wraps in 49.7 days
+ UINT32_TO_STREAM(p, static_cast<uint32_t>(
+ bluetooth::common::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) p_wack->len -= L2CAP_FCS_LEN;
@@ -2377,7 +2381,9 @@ static void l2c_fcr_collect_ack_delay(tL2C_CCB* p_ccb, uint8_t num_bufs_acked) {
}
STREAM_TO_UINT32(timestamp, p);
- delay = time_get_os_boottime_ms() - timestamp;
+ delay = static_cast<uint32_t>(
+ bluetooth::common::time_get_os_boottime_ms()) -
+ timestamp;
p_ccb->fcrb.ack_delay_avg[index] += delay;
if (delay > p_ccb->fcrb.ack_delay_max[index])
@@ -2398,7 +2404,7 @@ static void l2c_fcr_collect_ack_delay(tL2C_CCB* p_ccb, uint8_t num_bufs_acked) {
p_ccb->fcrb.ack_delay_avg[index] /= L2CAP_ERTM_STATS_AVG_NUM_SAMPLES;
/* calculate throughput */
- timestamp = time_get_os_boottime_ms();
+ timestamp = bluetooth::common::time_get_os_boottime_ms();
if (timestamp - p_ccb->fcrb.throughput_start > 0)
p_ccb->fcrb.throughput[index] /=
(timestamp - p_ccb->fcrb.throughput_start);
diff --git a/system/stack/l2cap/l2c_int.h b/system/stack/l2cap/l2c_int.h
index b024637525..d32c56f6fa 100644
--- a/system/stack/l2cap/l2c_int.h
+++ b/system/stack/l2cap/l2c_int.h
@@ -212,7 +212,7 @@ typedef struct {
alarm_t* mon_retrans_timer; /* Timer Monitor or Retransmission */
#if (L2CAP_ERTM_STATS == TRUE)
- uint32_t connect_tick_count; /* Time channel was established */
+ uint64_t connect_tick_count; /* Time channel was established */
uint32_t ertm_pkt_counts[2]; /* Packets sent and received */
uint32_t ertm_byte_counts[2]; /* Bytes sent and received */
uint32_t s_frames_sent[4]; /* S-frames sent (RR, REJ, RNR, SREJ) */
diff --git a/system/stack/rfcomm/rfc_l2cap_if.cc b/system/stack/rfcomm/rfc_l2cap_if.cc
index 380f5bf000..3275d770c3 100644
--- a/system/stack/rfcomm/rfc_l2cap_if.cc
+++ b/system/stack/rfcomm/rfc_l2cap_if.cc
@@ -26,8 +26,8 @@
#include "bt_target.h"
#include "bt_common.h"
+#include "common/time_util.h"
#include "osi/include/osi.h"
-#include "osi/include/time.h"
#include "bt_utils.h"
#include "l2c_api.h"
@@ -105,7 +105,9 @@ void RFCOMM_ConnectInd(const RawAddress& bd_addr, uint16_t lcid,
"LCID(0x%x), acceptor's LCID(0x%x)",
p_mcb->lcid, p_mcb->pending_lcid);
- rfc_timer_start(p_mcb, (uint16_t)(time_get_os_boottime_ms() % 10 + 2));
+ rfc_timer_start(
+ p_mcb,
+ (uint16_t)(bluetooth::common::time_get_os_boottime_ms() % 10 + 2));
return;
} else {
/* we cannot accept connection request from peer at this state */