1//
2// Copyright (C) 2018 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
17// =========================================================================
18// Native library to write stats log to statsd socket on Android R and later
19// =========================================================================
20package {
21    default_applicable_licenses: ["Android-Apache-2.0"],
22}
23
24cc_defaults {
25    name: "libstatssocket_defaults",
26    srcs: [
27        "stats_buffer_writer.c",
28        "stats_event.c",
29        "stats_socket.c",
30        "statsd_writer.c",
31    ],
32    export_include_dirs: ["include"],
33    header_libs: ["liblog_headers"],
34    cflags: [
35        "-Wall",
36        "-Werror",
37    ],
38}
39
40cc_library {
41    name: "libstatssocket",
42    defaults: [
43        "libstatssocket_defaults",
44    ],
45    host_supported: true,
46    target: {
47        // On android, libstatssocket should only be linked as a shared lib
48        android: {
49            static: {
50                enabled: false,
51            },
52        },
53        host: {
54            shared: {
55                enabled: false,
56            },
57        },
58    },
59    stl: "libc++_static",
60
61    // enumerate stable entry points for APEX use
62    stubs: {
63        symbol_file: "libstatssocket.map.txt",
64        versions: [
65            "30",
66        ],
67    },
68    apex_available: [
69        "com.android.os.statsd",
70        "test_com.android.os.statsd",
71    ],
72    min_sdk_version: "30",
73}
74
75//TODO (b/149842105): Figure out if there is a better solution for this.
76cc_test_library {
77    name: "libstatssocket_private",
78    defaults: [
79        "libstatssocket_defaults",
80    ],
81    visibility: [
82        "//packages/modules/StatsD/apex/tests/libstatspull",
83        "//packages/modules/StatsD/statsd",
84    ],
85}
86
87cc_library_headers {
88    name: "libstatssocket_headers",
89    export_include_dirs: ["include"],
90    apex_available: [
91        "com.android.resolv",
92        "//apex_available:platform",
93    ],
94    min_sdk_version: "29",
95}
96
97cc_test {
98    name: "libstatssocket_test",
99    srcs: [
100        "tests/stats_event_test.cpp",
101        "tests/stats_writer_test.cpp",
102    ],
103    cflags: [
104        "-Wall",
105        "-Werror",
106    ],
107    static_libs: [
108        "libgmock",
109        "libstatssocket_private",
110    ],
111    shared_libs: [
112        "libutils",
113    ],
114    test_suites: ["device-tests", "mts-statsd"],
115    test_config: "libstatssocket_test.xml",
116    //TODO(b/153588990): Remove when the build system properly separates.
117    //32bit and 64bit architectures.
118    compile_multilib: "both",
119    multilib: {
120        lib64: {
121            suffix: "64",
122        },
123        lib32: {
124            suffix: "32",
125        },
126    },
127    require_root: true,
128}
129