xref: /aosp_15_r20/external/ot-br-posix/Android.bp (revision 4a64e381480ef79f0532b2421e44e6ee336b8e0d)
1//
2//  Copyright (c) 2021, The OpenThread Authors.
3//  All rights reserved.
4//
5//  Redistribution and use in source and binary forms, with or without
6//  modification, are permitted provided that the following conditions are met:
7//  1. Redistributions of source code must retain the above copyright
8//     notice, this list of conditions and the following disclaimer.
9//  2. Redistributions in binary form must reproduce the above copyright
10//     notice, this list of conditions and the following disclaimer in the
11//     documentation and/or other materials provided with the distribution.
12//  3. Neither the name of the copyright holder nor the
13//     names of its contributors may be used to endorse or promote products
14//     derived from this software without specific prior written permission.
15//
16//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17//  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18//  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19//  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20//  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21//  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22//  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23//  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24//  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25//  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26//  POSSIBILITY OF SUCH DAMAGE.
27//
28
29package {
30    default_team: "trendy_team_fwk_thread_network",
31    default_applicable_licenses: ["external_ot-br-posix_license"],
32}
33
34// Added automatically by a large-scale-change that took the approach of
35// 'apply every license found to every target'. While this makes sure we respect
36// every license restriction, it may not be entirely correct.
37//
38// e.g. GPL in an MIT project might only apply to the contrib/ directory.
39//
40// Please consider splitting the single license below into multiple licenses,
41// taking care not to lose any license_kind information, and overriding the
42// default license using the 'licenses: [...]' property on targets as needed.
43//
44// For unused files, consider creating a 'fileGroup' with "//visibility:private"
45// to attach the license to, and including a comment whether the files may be
46// used in the current project.
47//
48// large-scale-change included anything that looked like it might be a license
49// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc.
50//
51// Please consider removing redundant or irrelevant files from 'license_text:'.
52// See: http://go/android-license-faq
53license {
54    name: "external_ot-br-posix_license",
55    visibility: [":__subpackages__"],
56    license_kinds: [
57        "SPDX-license-identifier-Apache-2.0",
58        "SPDX-license-identifier-BSD",
59        "SPDX-license-identifier-MIT",
60    ],
61    license_text: [
62        "LICENSE",
63        "NOTICE",
64    ],
65}
66
67genrule {
68    name: "otbr_version_header",
69    cmd: "$(location src/android/config-android-version-gen.sh) < $(in) > $(out)",
70    srcs: ["src/android/otbr-config-android-version.h.in"],
71    out: ["otbr-config-android-version.h"],
72    tool_files: [
73        "src/android/config-android-version-gen.sh",
74    ],
75}
76
77// The config shared by all ot-daemon dependency libraries
78cc_defaults {
79    name: "ot-daemon-debuggable-cc-defaults",
80    cflags: [
81        // Optimize for size
82        "-Os",
83
84        // Disable exception since OT never uses exceptions
85        "-fno-exceptions",
86        "-fno-asynchronous-unwind-tables",
87        "-fno-unwind-tables",
88    ],
89    product_variables: {
90        debuggable: {
91            cflags: [
92                // Optimize for debugging
93                "-Og",
94            ],
95        },
96    },
97
98    // Enable security checks
99    sanitize: {
100        misc_undefined: ["bounds"],
101        cfi: true,
102        scs: true,
103    },
104}
105
106cc_defaults {
107    name: "ot-daemon-defaults",
108    generated_headers: ["otbr_version_header"],
109
110    include_dirs: [
111        "external/mdnsresponder/mDNSShared",
112        "external/openthread/include",
113        "external/openthread/src",
114        "external/openthread/src/posix/platform/include",
115        "external/openthread/third_party/mbedtls/repo/include",
116    ],
117
118    local_include_dirs: [
119        "include",
120        "src",
121    ],
122
123    cflags: [
124        "-Wall",
125        "-Wextra",
126        "-Wno-unused-function",
127
128        // The HAL client implementation requires features which are
129        // available on only 31+, but it's guaranteed that ot-daemon
130        // will never run on Android U- devices.
131        "-Wno-unguarded-availability",
132
133        "-DOTBR_ENABLE_PLATFORM_ANDROID=1",
134        "-DOTBR_CONFIG_ANDROID_PROPERTY_ENABLE=1",
135        "-DOTBR_CONFIG_ANDROID_VERSION_HEADER_ENABLE=1",
136        "-DOTBR_CONFIG_FILE=\"src/android/otbr-config-android.h\"",
137        "-DOTBR_ENABLE_VENDOR_SERVER=1", // for OtDaemonServer
138        "-DOTBR_ENABLE_BACKBONE_ROUTER=1",
139        "-DOTBR_ENABLE_BACKBONE_ROUTER_ON_INIT=0",
140        "-DOTBR_ENABLE_BORDER_ROUTING=1",
141        "-DOTBR_ENABLE_BORDER_ROUTING_COUNTERS=1",
142        "-DOTBR_ENABLE_BORDER_AGENT=1",
143        "-DOTBR_ENABLE_PUBLISH_MESHCOP_BA_ID=1",
144        // Used for bypassing the macro check. In fact mdnssd is not used because we don't compile
145        // the related source files.
146        "-DOTBR_ENABLE_MDNS_MDNSSD=1",
147        "-DOTBR_ENABLE_SRP_ADVERTISING_PROXY=1",
148        "-DOTBR_ENABLE_DNSSD_DISCOVERY_PROXY=1",
149        "-DOTBR_ENABLE_SRP_SERVER_AUTO_ENABLE_MODE=1",
150        "-DOTBR_PACKAGE_NAME=\"OTBR_AGENT\"",
151        "-DOTBR_STOP_BORDER_AGENT_ON_INIT=1",
152        // The platform specific rules for selecting infrastructure link do not apply to Android
153        "-DOTBR_ENABLE_VENDOR_INFRA_LINK_SELECT=0",
154
155        "-DOTBR_ENABLE_TREL=1",
156
157        // For the following 1.4 features, the `OTBR_ENABLE_*` macros are set to 0 because they
158        // only guard code which deals with feature flagging or telemetry. Such code is targeting
159        // other Linux platforms but not Android.
160        "-DOTBR_ENABLE_NAT64=0",
161        "-DOTBR_ENABLE_DNS_UPSTREAM_QUERY=0",
162        "-DOTBR_ENABLE_DHCP6_PD=0",
163        "-DOTBR_ENABLE_EPSKC=0",
164    ],
165
166    srcs: [
167        "src/agent/application.cpp",
168        "src/android/android_rcp_host.cpp",
169        "src/android/common_utils.cpp",
170        "src/android/mdns_publisher.cpp",
171        "src/android/otdaemon_server.cpp",
172        "src/android/otdaemon_telemetry.cpp",
173        "src/backbone_router/backbone_agent.cpp",
174        "src/border_agent/border_agent.cpp",
175        "src/common/code_utils.cpp",
176        "src/common/dns_utils.cpp",
177        "src/common/logging.cpp",
178        "src/common/mainloop_manager.cpp",
179        "src/common/mainloop.cpp",
180        "src/common/task_runner.cpp",
181        "src/common/types.cpp",
182        "src/mdns/mdns.cpp",
183        "src/ncp/async_task.cpp",
184        "src/ncp/ncp_host.cpp",
185        "src/ncp/ncp_spinel.cpp",
186        "src/ncp/posix/netif_linux.cpp",
187        "src/ncp/posix/netif.cpp",
188        "src/ncp/rcp_host.cpp",
189        "src/ncp/thread_host.cpp",
190        "src/sdp_proxy/advertising_proxy.cpp",
191        "src/sdp_proxy/discovery_proxy.cpp",
192        "src/trel_dnssd/trel_dnssd.cpp",
193        "src/utils/crc16.cpp",
194        "src/utils/dns_utils.cpp",
195        "src/utils/hex.cpp",
196        "src/utils/infra_link_selector.cpp",
197        "src/utils/pskc.cpp",
198        "src/utils/socket_utils.cpp",
199        "src/utils/steering_data.cpp",
200        "src/utils/string_utils.cpp",
201        "src/utils/system_utils.cpp",
202        "src/utils/thread_helper.cpp",
203    ],
204
205    shared_libs: [
206        "libbase",
207        "libutils",
208        "libcutils",
209        "libbinder_ndk",
210        "android.hardware.threadnetwork-V1-ndk",
211        "liblog",
212        "libstatssocket",
213    ],
214
215    static_libs: [
216        "libopenthread-cli",
217        "ot-core",
218        "ot-daemon-aidl-ndk",
219        "libstatslog_threadnetwork",
220        "threadnetwork-atom-cc-proto-lite",
221        "libprotobuf-cpp-lite",
222    ],
223
224    host_ldlibs: ["-lutil"],
225    min_sdk_version: "30",
226    apex_available: ["com.android.tethering"],
227}
228
229cc_binary {
230    name: "ot-daemon",
231    defaults: [
232        "ot-daemon-defaults",
233        "ot-daemon-debuggable-cc-defaults",
234    ],
235    srcs: [
236        "src/agent/main.cpp",
237    ],
238}
239
240cc_fuzz {
241    name: "ot_daemon_service_fuzzer",
242    defaults: [
243        "ot-daemon-defaults",
244        "service_fuzzer_defaults",
245    ],
246    srcs: [
247        "src/android/otdaemon_fuzzer.cpp",
248    ],
249    shared_libs: [
250        "liblog",
251    ],
252    fuzz_config: {
253        cc: [
254            "[email protected]",
255        ],
256    },
257}
258
259cc_library_static {
260    name: "libstatslog_threadnetwork",
261    generated_sources: ["statslog_threadnetwork.cpp"],
262    generated_headers: ["statslog_threadnetwork.h"],
263    cflags: [
264        "-Wall",
265        "-Werror",
266    ],
267    export_generated_headers: ["statslog_threadnetwork.h"],
268    shared_libs: [
269        "libcutils",
270        "liblog",
271        "libstatssocket",
272        "libutils",
273    ],
274    min_sdk_version: "30",
275    apex_available: ["com.android.tethering"],
276}
277
278genrule {
279    name: "statslog_threadnetwork.h",
280    tools: ["stats-log-api-gen"],
281    cmd: "$(location stats-log-api-gen) --header $(genDir)/statslog_threadnetwork.h --module threadnetwork --namespace threadnetwork",
282    out: [
283        "statslog_threadnetwork.h",
284    ],
285}
286
287genrule {
288    name: "statslog_threadnetwork.cpp",
289    tools: ["stats-log-api-gen"],
290    cmd: "$(location stats-log-api-gen) --cpp $(genDir)/statslog_threadnetwork.cpp --module threadnetwork --namespace threadnetwork --importHeader statslog_threadnetwork.h",
291    out: [
292        "statslog_threadnetwork.cpp",
293    ],
294}
295