From 34a892d2f5d770ceea4d7a5bbb6de2bb41588f4d Mon Sep 17 00:00:00 2001 From: Jack He Date: Thu, 20 Dec 2018 00:42:31 -0800 Subject: [PATCH] Statsd: Enable host_supported for libstatslog * libutils must be used as a static library when compiled on host * Host does not have Android system properties and hence we cannot use . In fact, properties.cpp is not even compiled on host for libcutils. Therefore, this CL adds a check for __ANDROID__ macro before including and before calling properties_get_bool() * On host, statsd logging will be disabled since host does not use statsd for anything Fixes: 121294178 Test: test drive statsd Change-Id: I838ff02468c650c5f7d85e68fa5008b98f08ce8c --- tools/stats_log_api_gen/Android.bp | 14 +++++++++++++- tools/stats_log_api_gen/main.cpp | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/stats_log_api_gen/Android.bp b/tools/stats_log_api_gen/Android.bp index 703a67b791be4..5725f0cdae6e7 100644 --- a/tools/stats_log_api_gen/Android.bp +++ b/tools/stats_log_api_gen/Android.bp @@ -96,6 +96,7 @@ genrule { cc_library_shared { name: "libstatslog", + host_supported: true, generated_sources: ["statslog.cpp"], generated_headers: ["statslog.h"], cflags: [ @@ -105,8 +106,19 @@ cc_library_shared { export_generated_headers: ["statslog.h"], shared_libs: [ "liblog", - "libutils", "libcutils", ], static_libs: ["libstatssocket"], + target: { + android: { + shared_libs: [ + "libutils", + ], + }, + host: { + static_libs: [ + "libutils", + ], + }, + }, } diff --git a/tools/stats_log_api_gen/main.cpp b/tools/stats_log_api_gen/main.cpp index 485fc46387e49..2478b9154b108 100644 --- a/tools/stats_log_api_gen/main.cpp +++ b/tools/stats_log_api_gen/main.cpp @@ -108,7 +108,9 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, fprintf(out, "#include \n"); fprintf(out, "#include \n"); fprintf(out, "#include \n"); + fprintf(out, "#ifdef __ANDROID__\n"); fprintf(out, "#include \n"); + fprintf(out, "#endif\n"); fprintf(out, "#include \n"); fprintf(out, "#include \n"); fprintf(out, "#include \n"); @@ -119,7 +121,11 @@ static int write_stats_log_cpp(FILE *out, const Atoms &atoms, fprintf(out, "namespace util {\n"); fprintf(out, "// the single event tag id for all stats logs\n"); fprintf(out, "const static int kStatsEventTag = 1937006964;\n"); + fprintf(out, "#ifdef __ANDROID__\n"); fprintf(out, "const static bool kStatsdEnabled = property_get_bool(\"ro.statsd.enable\", true);\n"); + fprintf(out, "#else\n"); + fprintf(out, "const static bool kStatsdEnabled = false;\n"); + fprintf(out, "#endif\n"); std::set kTruncatingAtomNames = {"mobile_radio_power_state_changed", "audio_state_changed",