1// 2// Copyright (C) 2017 The Android Open Source Project 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15// 16 17package { 18 default_applicable_licenses: ["Android-Apache-2.0"], 19 default_team: "trendy_team_android_telemetry_client_infra", 20} 21 22cc_defaults { 23 name: "statsd_defaults", 24 25 cflags: [ 26 "-Wno-deprecated-declarations", 27 "-Wthread-safety", 28 ], 29 tidy: true, 30 tidy_flags: [ 31 // Only check our headers 32 "-header-filter=^packages/modules/StatsD/statsd", 33 ], 34 35 tidy_checks: [ 36 "android-*", 37 "bugprone-*", 38 "cert-*", 39 "clang-analyzer-security*", 40 "google-*", 41 "misc-*", 42 "performance-*", 43 "-bugprone-narrowing-conversions", // lots of unsigned -> int conversions 44 "-cert-err34-c", 45 "-cert-msc30-c", // warning: rand() has limited randomness; use C++11 random library 46 "-cert-msc50-cpp", // warning: rand() has limited randomness; use C++11 random library 47 ], 48 tidy_checks_as_errors: [ 49 "android-*", 50 "bugprone-*", 51 "cert-*", 52 "clang-analyzer-security*", 53 "google-*", 54 "misc-*", 55 "performance-*", 56 ], 57 srcs: [ 58 "src/active_config_list.proto", 59 "src/anomaly/AlarmMonitor.cpp", 60 "src/anomaly/AlarmTracker.cpp", 61 "src/anomaly/AnomalyTracker.cpp", 62 "src/anomaly/DurationAnomalyTracker.cpp", 63 "src/anomaly/subscriber_util.cpp", 64 "src/condition/CombinationConditionTracker.cpp", 65 "src/condition/condition_util.cpp", 66 "src/condition/ConditionWizard.cpp", 67 "src/condition/SimpleConditionTracker.cpp", 68 "src/config/ConfigKey.cpp", 69 "src/config/ConfigListener.cpp", 70 "src/config/ConfigManager.cpp", 71 "src/experiment_ids.proto", 72 "src/external/Perfetto.cpp", 73 "src/external/PullResultReceiver.cpp", 74 "src/external/puller_util.cpp", 75 "src/external/StatsCallbackPuller.cpp", 76 "src/external/StatsPuller.cpp", 77 "src/external/StatsPullerManager.cpp", 78 "src/external/TrainInfoPuller.cpp", 79 "src/external/Uprobestats.cpp", 80 "src/FieldValue.cpp", 81 "src/flags/FlagProvider.cpp", 82 "src/guardrail/StatsdStats.cpp", 83 "src/hash.cpp", 84 "src/HashableDimensionKey.cpp", 85 "src/logd/LogEvent.cpp", 86 "src/logd/LogEventQueue.cpp", 87 "src/logd/logevent_util.cpp", 88 "src/matchers/CombinationAtomMatchingTracker.cpp", 89 "src/matchers/EventMatcherWizard.cpp", 90 "src/matchers/matcher_util.cpp", 91 "src/matchers/SimpleAtomMatchingTracker.cpp", 92 "src/metadata_util.cpp", 93 "src/metrics/CountMetricProducer.cpp", 94 "src/metrics/duration_helper/MaxDurationTracker.cpp", 95 "src/metrics/duration_helper/OringDurationTracker.cpp", 96 "src/metrics/DurationMetricProducer.cpp", 97 "src/metrics/EventMetricProducer.cpp", 98 "src/metrics/RestrictedEventMetricProducer.cpp", 99 "src/metrics/GaugeMetricProducer.cpp", 100 "src/metrics/HistogramValue.cpp", 101 "src/metrics/KllMetricProducer.cpp", 102 "src/metrics/MetricProducer.cpp", 103 "src/metrics/MetricsManager.cpp", 104 "src/metrics/NumericValue.cpp", 105 "src/metrics/ValueMetricProducer.cpp", 106 "src/metrics/parsing_utils/config_update_utils.cpp", 107 "src/metrics/parsing_utils/metrics_manager_util.cpp", 108 "src/metrics/parsing_utils/histogram_parsing_utils.cpp", 109 "src/metrics/NumericValueMetricProducer.cpp", 110 "src/packages/UidMap.cpp", 111 "src/shell/shell_config.proto", 112 "src/shell/ShellSubscriber.cpp", 113 "src/shell/ShellSubscriberClient.cpp", 114 "src/socket/StatsSocketListener.cpp", 115 "src/state/StateManager.cpp", 116 "src/state/StateTracker.cpp", 117 "src/stats_log_util.cpp", 118 "src/stats_policy_config.proto", 119 "src/statscompanion_util.cpp", 120 "src/statsd_config.proto", 121 "src/statsd_metadata.proto", 122 "src/guardrail/stats_log_enums.proto", 123 "src/StatsLogProcessor.cpp", 124 "src/StatsService.cpp", 125 "src/storage/StorageManager.cpp", 126 "src/subscriber/IncidentdReporter.cpp", 127 "src/subscriber/SubscriberReporter.cpp", 128 "src/uid_data.proto", 129 "src/utils/MultiConditionTrigger.cpp", 130 "src/utils/DbUtils.cpp", 131 "src/utils/Regex.cpp", 132 "src/utils/RestrictedPolicyManager.cpp", 133 "src/utils/ShardOffsetProvider.cpp", 134 ], 135 136 local_include_dirs: [ 137 "src", 138 ], 139 140 static_libs: [ 141 "libbase", 142 "libcutils", 143 "libkll", 144 "libmodules-utils-build", 145 "libprotoutil", 146 "libstatslog_statsd", 147 "libsysutils", 148 "libutils", 149 "server_configurable_flags", 150 "statsd-aidl-ndk", 151 "statsd_flags_c_lib", 152 "libsqlite_static_noicu", 153 ], 154 shared_libs: [ 155 "libbinder_ndk", 156 "libincident", 157 "liblog", 158 "libstatssocket#impl", 159 ], 160 header_libs: [ 161 "libgtest_prod_headers", 162 ], 163 min_sdk_version: "30", 164} 165 166genrule { 167 name: "statslog_statsd.h", 168 tools: ["stats-log-api-gen"], 169 cmd: "$(location stats-log-api-gen) " + 170 "--header $(genDir)/statslog_statsd.h " + 171 "--module statsd " + 172 "--namespace android,os,statsd,util", 173 out: [ 174 "statslog_statsd.h", 175 ], 176} 177 178genrule { 179 name: "statslog_statsd.cpp", 180 tools: ["stats-log-api-gen"], 181 cmd: "$(location stats-log-api-gen) " + 182 "--cpp $(genDir)/statslog_statsd.cpp " + 183 "--module statsd " + 184 "--namespace android,os,statsd,util " + 185 "--importHeader statslog_statsd.h", 186 out: [ 187 "statslog_statsd.cpp", 188 ], 189} 190 191genrule { 192 name: "statslog_statsdtest.h", 193 tools: ["stats-log-api-gen"], 194 cmd: "$(location stats-log-api-gen) " + 195 "--header $(genDir)/statslog_statsdtest.h " + 196 "--module statsdtest " + 197 "--namespace android,os,statsd,util", 198 out: [ 199 "statslog_statsdtest.h", 200 ], 201} 202 203genrule { 204 name: "statslog_statsdtest.cpp", 205 tools: ["stats-log-api-gen"], 206 cmd: "$(location stats-log-api-gen) " + 207 "--cpp $(genDir)/statslog_statsdtest.cpp " + 208 "--module statsdtest " + 209 "--namespace android,os,statsd,util " + 210 "--importHeader statslog_statsdtest.h", 211 out: [ 212 "statslog_statsdtest.cpp", 213 ], 214} 215 216cc_library_static { 217 name: "libstatslog_statsdtest", 218 generated_sources: ["statslog_statsdtest.cpp"], 219 generated_headers: ["statslog_statsdtest.h"], 220 export_generated_headers: ["statslog_statsdtest.h"], 221 shared_libs: [ 222 "libstatssocket", 223 "libstatspull", 224 ], 225} 226 227cc_library_static { 228 name: "libstatslog_statsd", 229 generated_sources: ["statslog_statsd.cpp"], 230 generated_headers: ["statslog_statsd.h"], 231 export_generated_headers: ["statslog_statsd.h"], 232 apex_available: [ 233 "com.android.os.statsd", 234 "test_com.android.os.statsd", 235 ], 236 min_sdk_version: "30", 237 shared_libs: [ 238 "libstatssocket", 239 "libstatspull", 240 ], 241 export_shared_lib_headers: [ 242 "libstatspull", 243 ], 244} 245 246// ========= 247// statsd 248// ========= 249 250cc_binary { 251 name: "statsd", 252 defaults: ["statsd_defaults"], 253 254 srcs: ["src/main.cpp"], 255 256 cflags: [ 257 "-Wall", 258 "-Wextra", 259 "-Werror", 260 "-Wno-unused-parameter", 261 // "-g", 262 // "-O0", 263 ], 264 265 // optimize for size (protobuf glop can get big) 266 optimize_for_size: true, 267 268 proto: { 269 type: "lite", 270 static: true, 271 }, 272 stl: "libc++_static", 273 274 apex_available: [ 275 "com.android.os.statsd", 276 "test_com.android.os.statsd", 277 ], 278 runtime_libs: ["libuprobestats_client"], 279 min_sdk_version: "30", 280} 281 282cc_defaults { 283 name: "statsd_test_defaults", 284 defaults: ["statsd_defaults"], 285 srcs: [ 286 // atom_field_options.proto needs field_options.proto, but that is 287 // not included in libprotobuf-cpp-lite, so compile it here. 288 ":libprotobuf-internal-protos", 289 ":libstats_internal_protos", 290 291 "src/shell/shell_data.proto", 292 "src/stats_log.proto", 293 ], 294 cflags: [ 295 "-Wall", 296 "-Werror", 297 "-Wno-enum-compare", 298 "-Wno-missing-field-initializers", 299 "-Wno-unused-function", 300 "-Wno-unused-parameter", 301 "-Wno-unused-variable", 302 ], 303 static_libs: [ 304 "libgmock", 305 "libstatslog_statsdtest", 306 ], 307 header_libs: [ 308 "libstatssocket_test_headers", 309 ], 310 proto: { 311 type: "lite", 312 include_dirs: [ 313 "external/protobuf/src", 314 "frameworks/proto_logging/stats", 315 ], 316 static: true, 317 }, 318} 319 320cc_library_static { 321 name: "libstats_test_utils", 322 defaults: ["statsd_test_defaults"], 323 srcs: [ 324 "tests/metrics/metrics_test_helper.cpp", 325 "tests/metrics/parsing_utils/parsing_test_utils.cpp", 326 "tests/statsd_test_util.cpp", 327 ], 328 tidy_timeout_srcs: [ 329 "tests/statsd_test_util.cpp", 330 ], 331} 332 333// ============== 334// statsd_test 335// ============== 336 337filegroup { 338 name: "statsd_test_default_map", 339 srcs: ["statsd_test_default.map"], 340} 341 342cc_test { 343 name: "statsd_test", 344 defaults: ["statsd_test_defaults"], 345 test_suites: [ 346 "device-tests", 347 "mts-statsd", 348 ], 349 test_config: "statsd_test.xml", 350 351 //TODO(b/153588990): Remove when the build system properly separates 352 //32bit and 64bit architectures. 353 compile_multilib: "both", 354 multilib: { 355 lib64: { 356 suffix: "64", 357 }, 358 lib32: { 359 suffix: "32", 360 }, 361 }, 362 363 // These tests run on older platform versions, so many libraries (such as libbase and libc++) 364 // need to be linked statically. The tests also need to be linked with a version script to 365 // ensure that the statically-linked library isn't exported from the executable, where it 366 // would override the shared libraries that the platform itself uses. 367 // See http://b/333438055 for an example of what goes wrong when libc++ is partially exported 368 // from an executable. 369 version_script: ":statsd_test_default_map", 370 stl: "c++_static", 371 372 require_root: true, 373 374 tidy_timeout_srcs: [ 375 "tests/condition/SimpleConditionTracker_test.cpp", 376 "tests/ConfigManager_test.cpp", 377 "tests/e2e/Anomaly_count_e2e_test.cpp", 378 "tests/e2e/Anomaly_duration_sum_e2e_test.cpp", 379 "tests/e2e/ConfigUpdate_e2e_ab_test.cpp", 380 "tests/e2e/ConfigUpdate_e2e_test.cpp", 381 "tests/e2e/CountMetric_e2e_test.cpp", 382 "tests/e2e/DurationMetric_e2e_test.cpp", 383 "tests/e2e/GaugeMetric_e2e_pull_test.cpp", 384 "tests/e2e/MetricActivation_e2e_test.cpp", 385 "tests/e2e/PartialBucket_e2e_test.cpp", 386 "tests/e2e/ValueMetric_pull_e2e_test.cpp", 387 "tests/e2e/WakelockDuration_e2e_test.cpp", 388 "tests/external/puller_util_test.cpp", 389 "tests/external/StatsPuller_test.cpp", 390 "tests/FieldValue_test.cpp", 391 "tests/guardrail/StatsdStats_test.cpp", 392 "tests/LogEvent_test.cpp", 393 "tests/metrics/CountMetricProducer_test.cpp", 394 "tests/metrics/DurationMetricProducer_test.cpp", 395 "tests/metrics/EventMetricProducer_test.cpp", 396 "tests/metrics/GaugeMetricProducer_test.cpp", 397 "tests/metrics/KllMetricProducer_test.cpp", 398 "tests/metrics/MaxDurationTracker_test.cpp", 399 "tests/metrics/NumericValueMetricProducer_test.cpp", 400 "tests/metrics/OringDurationTracker_test.cpp", 401 "tests/metrics/RestrictedEventMetricProducer_test.cpp", 402 "tests/MetricsManager_test.cpp", 403 "tests/metrics/parsing_utils/config_update_utils_test.cpp", 404 "tests/metrics/parsing_utils/metrics_manager_util_test.cpp", 405 "tests/state/StateTracker_test.cpp", 406 "tests/StatsLogProcessor_test.cpp", 407 "tests/UidMap_test.cpp", 408 ], 409 410 srcs: [ 411 "tests/AlarmMonitor_test.cpp", 412 "tests/anomaly/AlarmTracker_test.cpp", 413 "tests/anomaly/AnomalyTracker_test.cpp", 414 "tests/condition/CombinationConditionTracker_test.cpp", 415 "tests/condition/ConditionTimer_test.cpp", 416 "tests/condition/SimpleConditionTracker_test.cpp", 417 "tests/ConfigManager_test.cpp", 418 "tests/e2e/Alarm_e2e_test.cpp", 419 "tests/e2e/Anomaly_count_e2e_test.cpp", 420 "tests/e2e/Anomaly_duration_sum_e2e_test.cpp", 421 "tests/e2e/Attribution_e2e_test.cpp", 422 "tests/e2e/ConfigTtl_e2e_test.cpp", 423 "tests/e2e/ConfigUpdate_e2e_ab_test.cpp", 424 "tests/e2e/ConfigUpdate_e2e_test.cpp", 425 "tests/e2e/CountMetric_e2e_test.cpp", 426 "tests/e2e/DurationMetric_e2e_test.cpp", 427 "tests/e2e/EventMetric_e2e_test.cpp", 428 "tests/e2e/GaugeMetric_e2e_pull_test.cpp", 429 "tests/e2e/GaugeMetric_e2e_push_test.cpp", 430 "tests/e2e/KllMetric_e2e_test.cpp", 431 "tests/e2e/MetricActivation_e2e_test.cpp", 432 "tests/e2e/MetricConditionLink_e2e_test.cpp", 433 "tests/e2e/PartialBucket_e2e_test.cpp", 434 "tests/e2e/RestrictedConfig_e2e_test.cpp", 435 "tests/e2e/RestrictedEventMetric_e2e_test.cpp", 436 "tests/e2e/StringReplace_e2e_test.cpp", 437 "tests/e2e/ValueMetric_histogram_e2e_test.cpp", 438 "tests/e2e/ValueMetric_pull_e2e_test.cpp", 439 "tests/e2e/WakelockDuration_e2e_test.cpp", 440 "tests/external/puller_util_test.cpp", 441 "tests/external/StatsCallbackPuller_test.cpp", 442 "tests/external/StatsPuller_test.cpp", 443 "tests/external/StatsPullerManager_test.cpp", 444 "tests/FieldValue_test.cpp", 445 "tests/flags/FlagProvider_test.cpp", 446 "tests/guardrail/StatsdStats_test.cpp", 447 "tests/HashableDimensionKey_test.cpp", 448 "tests/indexed_priority_queue_test.cpp", 449 "tests/log_event/LogEventQueue_test.cpp", 450 "tests/LogEntryMatcher_test.cpp", 451 "tests/LogEvent_test.cpp", 452 "tests/metadata_util_test.cpp", 453 "tests/metrics/CountMetricProducer_test.cpp", 454 "tests/metrics/DurationMetricProducer_test.cpp", 455 "tests/metrics/EventMetricProducer_test.cpp", 456 "tests/metrics/GaugeMetricProducer_test.cpp", 457 "tests/metrics/HistogramValue_test.cpp", 458 "tests/metrics/KllMetricProducer_test.cpp", 459 "tests/metrics/MaxDurationTracker_test.cpp", 460 "tests/metrics/OringDurationTracker_test.cpp", 461 "tests/metrics/NumericValueMetricProducer_test.cpp", 462 "tests/metrics/RestrictedEventMetricProducer_test.cpp", 463 "tests/metrics/parsing_utils/config_update_utils_test.cpp", 464 "tests/metrics/parsing_utils/histogram_parsing_utils_test.cpp", 465 "tests/metrics/parsing_utils/metrics_manager_util_test.cpp", 466 "tests/subscriber/SubscriberReporter_test.cpp", 467 "tests/DataCorruptionReason_test.cpp", 468 "tests/LogEventFilter_test.cpp", 469 "tests/MetricsManager_test.cpp", 470 "tests/shell/ShellSubscriber_test.cpp", 471 "tests/state/StateTracker_test.cpp", 472 "tests/statsd_test_util_test.cpp", 473 "tests/SocketListener_test.cpp", 474 "tests/StatsLogProcessor_test.cpp", 475 "tests/StatsService_test.cpp", 476 "tests/storage/StorageManager_test.cpp", 477 "tests/UidMap_test.cpp", 478 "tests/utils/DbUtils_test.cpp", 479 "tests/utils/MultiConditionTrigger_test.cpp", 480 ], 481 482 static_libs: [ 483 "libstatsgtestmatchers", 484 "libstats_test_utils", 485 ], 486 487 min_sdk_version: "30", 488} 489 490//############################# 491// statsd micro benchmark 492//############################# 493 494cc_benchmark { 495 name: "statsd_benchmark", 496 defaults: ["statsd_test_defaults"], 497 498 srcs: [ 499 "benchmark/data_structures_benchmark.cpp", 500 "benchmark/db_benchmark.cpp", 501 "benchmark/duration_metric_benchmark.cpp", 502 "benchmark/filter_value_benchmark.cpp", 503 "benchmark/get_dimensions_for_condition_benchmark.cpp", 504 "benchmark/hello_world_benchmark.cpp", 505 "benchmark/log_event_benchmark.cpp", 506 "benchmark/log_event_filter_benchmark.cpp", 507 "benchmark/main.cpp", 508 "benchmark/on_log_event_benchmark.cpp", 509 "benchmark/stats_write_benchmark.cpp", 510 "benchmark/loss_info_container_benchmark.cpp", 511 "benchmark/string_transform_benchmark.cpp", 512 "benchmark/value_metric_benchmark.cpp", 513 "benchmark/tex_metric_benchmark.cpp", 514 ], 515 516 cflags: [ 517 // Bug: http://b/29823425 Disable -Wvarargs for Clang update to r271374 518 "-Wno-varargs", 519 ], 520 521 static_libs: [ 522 "libgtest", 523 "libstats_test_utils", 524 ], 525 526} 527 528// ==== java proto device library (for test only) ============================== 529java_library { 530 name: "statsdprotolite", 531 sdk_version: "core_current", 532 proto: { 533 type: "lite", 534 include_dirs: [ 535 "external/protobuf/src", 536 "frameworks/proto_logging/stats", 537 ], 538 }, 539 540 srcs: [ 541 ":libstats_atoms_proto", 542 "src/shell/shell_config.proto", 543 "src/shell/shell_data.proto", 544 "src/stats_log.proto", 545 "src/statsd_config.proto", 546 "src/guardrail/stats_log_enums.proto", 547 ], 548 549 static_libs: [ 550 "platformprotoslite", 551 ], 552 // Protos have lots of MissingOverride and similar. 553 errorprone: { 554 javacflags: ["-XepDisableAllChecks"], 555 }, 556} 557 558java_library { 559 name: "statsdprotonano", 560 sdk_version: "9", 561 proto: { 562 type: "nano", 563 output_params: ["store_unknown_fields=true"], 564 include_dirs: [ 565 "external/protobuf/src", 566 "frameworks/proto_logging/stats", 567 ], 568 }, 569 srcs: [ 570 ":libstats_atoms_proto", 571 "src/shell/shell_config.proto", 572 "src/shell/shell_data.proto", 573 "src/stats_log.proto", 574 "src/statsd_config.proto", 575 "src/guardrail/stats_log_enums.proto", 576 ], 577 static_libs: [ 578 "platformprotosnano", 579 ], 580 // Protos have lots of MissingOverride and similar. 581 errorprone: { 582 javacflags: ["-XepDisableAllChecks"], 583 }, 584} 585 586// Filegroup for statsd config proto definition. 587filegroup { 588 name: "libstats_config_protos", 589 srcs: ["src/statsd_config.proto"], 590} 591 592// Filegroup for statsd report protos. 593filegroup { 594 name: "libstats_log_protos", 595 srcs: [ 596 "src/stats_log.proto", 597 "src/guardrail/stats_log_enums.proto", 598 ], 599} 600 601// Filegroup for all statsd protos 602filegroup { 603 name: "statsd_internal_protos", 604 srcs: [ 605 "src/active_config_list.proto", 606 "src/experiment_ids.proto", 607 "src/shell/shell_config.proto", 608 "src/shell/shell_data.proto", 609 "src/statsd_config.proto", 610 "src/statsd_metadata.proto", 611 "src/stats_log.proto", 612 "src/uid_data.proto", 613 "src/guardrail/stats_log_enums.proto", 614 ], 615} 616 617cc_fuzz { 618 name: "statsd_service_fuzzer", 619 defaults: [ 620 "statsd_defaults", 621 "service_fuzzer_defaults", 622 "fuzzer_disable_leaks", 623 ], 624 srcs: [ 625 "fuzzers/statsd_service_fuzzer.cpp", 626 ], 627 shared_libs: [ 628 "libvndksupport", 629 ], 630 cflags: [ 631 "-Wall", 632 "-Wextra", 633 "-Werror", 634 "-Wno-unused-parameter", 635 ], 636 fuzz_config: { 637 triage_assignee: "[email protected]", 638 cc: [ 639 "[email protected]", 640 "[email protected]", 641 ], 642 }, 643 proto: { 644 type: "lite", 645 static: true, 646 }, 647} 648 649cc_fuzz { 650 name: "statsd_fuzzer", 651 defaults: [ 652 "statsd_defaults", 653 ], 654 srcs: [ 655 "fuzzers/statsd_socket_data_fuzzer.cpp", 656 ], 657 cflags: [ 658 "-Wall", 659 "-Wextra", 660 "-Werror", 661 "-Wno-unused-parameter", 662 ], 663 fuzz_config: { 664 cc: [ 665 "[email protected]", 666 "[email protected]", 667 ], 668 }, 669 proto: { 670 type: "lite", 671 static: true, 672 }, 673} 674 675// Filegroup for subscription protos. 676filegroup { 677 name: "libstats_subscription_protos", 678 srcs: [ 679 ":libstats_internal_protos", 680 ":libstats_config_protos", 681 "src/shell/shell_config.proto", 682 "src/shell/shell_data.proto", 683 ], 684} 685