1package {
2    // See: http://go/android-license-faq
3    // A large-scale-change added 'default_applicable_licenses' to import
4    // all of the 'license_kinds' from "system_bt_license"
5    // to get the below license kinds:
6    //   SPDX-license-identifier-Apache-2.0
7    //   SPDX-license-identifier-BSD
8    default_applicable_licenses: ["system_bt_license"],
9}
10
11cc_defaults {
12    name: "gd_defaults",
13    defaults: [
14        "bluetooth_cflags",
15    ],
16    tidy_checks: [
17        "-performance-unnecessary-value-param",
18    ],
19    target: {
20        android: {
21            test_config_template: "AndroidTestTemplate.xml",
22            shared_libs: [
23                "liblog",
24            ],
25            sanitize: {
26                misc_undefined: ["bounds"],
27            },
28        },
29        darwin: {
30            enabled: false,
31        },
32    },
33    cflags: [
34        "-DEXPORT_SYMBOL=__attribute__((visibility(\"default\")))",
35        "-DGOOGLE_PROTOBUF_NO_RTTI",
36        "-DLOG_NDEBUG=0",
37        "-Wno-unused-result",
38        "-fvisibility=hidden",
39    ],
40    header_libs: ["jni_headers"],
41}
42
43cc_defaults {
44    name: "gd_clang_tidy",
45    tidy: true,
46    tidy_checks: [
47        "-bugprone*",
48        "-cert-dcl21-cpp", // warning: overloaded returns a non-constant object instead of a constant object type
49        "-cert-dcl59-cpp", // warning: do not use unnamed namespaces in header files
50        "-cert-msc30-c", // warning: rand() has limited randomness; use C++11 random library instead
51        "-cert-msc50-cpp", // warning: rand() has limited randomness; use C++11 random library instead
52        "-cert-oop54-cpp", // warning: operator=() does not handle self-assignment properly
53        "-google*",
54        "-performance*",
55        "clang-analyzer-core.CallAndMessage",
56        "clang-analyzer-optin.cplusplus.UninitializedObject",
57    ],
58    tidy_checks_as_errors: [
59        "clang-analyzer-core.CallAndMessage",
60        "clang-analyzer-optin.cplusplus.UninitializedObject",
61        "cppcoreguidelines-pro-type-member-init",
62    ],
63    tidy_flags: [
64        "--header-filter=^.*packages/modules/Bluetooth/system/.*.h$",
65
66        "--extra-arg-before=-Xclang",
67        "--extra-arg-before=-analyzer-config",
68
69        "--extra-arg-before=-Xclang",
70        "--extra-arg-before=optin.cplusplus.UninitializedObject:Pedantic=true",
71
72        "--extra-arg-before=-Xclang",
73        "--extra-arg-before=-analyzer-config",
74
75        "--extra-arg-before=-Xclang",
76        "--extra-arg-before=optin.cplusplus.UninitializedObject:CheckPointeeInitialization=true",
77
78    ],
79}
80
81// Clang is targeted for android core libraries but other base libraries
82// may not support clang tidy recommendations (e.g. MacOS)
83cc_defaults {
84    name: "gd_clang_tidy_ignore_android",
85    tidy: true,
86    tidy_checks: [
87        "-android-cloexec-accept", // warning: prefer accept4() to accept() because accept4() allows SOCK_CLOEXEC
88        "-android-cloexec-pipe2", //  warning: 'pipe2' should use O_CLOEXEC where possible
89        "-android-cloexec-socket", // warning: 'pipe2' should use O_CLOEXEC where possible
90    ],
91}
92
93cc_defaults {
94    name: "libbluetooth_gd_defaults",
95    defaults: [
96        "gd_defaults",
97    ],
98    host_supported: true,
99    target: {
100        linux: {
101            srcs: [
102                ":BluetoothOsSources_linux_generic",
103            ],
104        },
105        host: {
106            srcs: [
107                ":BluetoothHalSources_hci_host",
108                ":BluetoothHalSources_ranging_host",
109                ":BluetoothOsSources_host",
110                ":BluetoothSyspropsSources",
111            ],
112        },
113        android: {
114            srcs: [
115                ":BluetoothHalSources_hci_android_hidl",
116                ":BluetoothHalSources_ranging_android",
117                ":BluetoothOsSources_android",
118            ],
119            shared_libs: [
120                "android.hardware.bluetooth@1.0",
121                "android.hardware.bluetooth@1.1",
122                "android.system.suspend-V1-ndk",
123                "android.system.suspend.control-V1-ndk",
124                "libbinder_ndk",
125                "libcutils",
126                "libhidlbase",
127                "libstatslog_bt",
128                "libutils",
129            ],
130            whole_static_libs: [
131                "android.hardware.bluetooth-V1-ndk",
132                "android.hardware.bluetooth.ranging-V1-ndk",
133            ],
134        },
135    },
136    srcs: [
137        ":BluetoothCommonSources",
138        ":BluetoothDumpsysSources",
139        ":BluetoothHalSources",
140        ":BluetoothHciSources",
141        ":BluetoothL2capSources",
142        ":BluetoothLogRedactionSources",
143        ":BluetoothMetricsSources",
144        ":BluetoothNeighborSources",
145        ":BluetoothOsSources",
146        ":BluetoothPacketSources",
147        ":BluetoothSecuritySources",
148        ":BluetoothStorageSources",
149        "module.cc",
150        "module_dumper.cc",
151        "stack_manager.cc",
152    ],
153    generated_headers: [
154        "BluetoothGeneratedBundlerSchema_h_bfbs",
155        "BluetoothGeneratedDumpsysDataSchema_h",
156    ],
157    shared_libs: [
158        "libcrypto",
159        "libflatbuffers-cpp",
160        "liblog",
161    ],
162    export_shared_lib_headers: [
163        "libflatbuffers-cpp",
164    ],
165    whole_static_libs: [
166        "bluetooth_flags_c_lib",
167        "libbluetooth_hci_pdl",
168        "libbluetooth_l2cap_pdl",
169        "libbluetooth_ras_pdl",
170        "libbluetooth_smp_pdl",
171    ],
172    static_libs: [
173        "libaconfig_storage_read_api_cc",
174        "libbase",
175        "libbluetooth-dumpsys",
176        "libbluetooth-protos",
177        "libbluetooth-types",
178        "libbluetooth_crypto_toolbox",
179        "libbluetooth_log",
180        "libbluetooth_rust_interop",
181        "libbt-common",
182        "libbt-platform-protos-lite",
183        "libbt_shim_bridge",
184        "libbt_shim_ffi",
185        "libcom.android.sysprop.bluetooth.wrapped",
186        "libosi",
187        "server_configurable_flags",
188    ],
189    include_dirs: [
190        "packages/modules/Bluetooth/system/include",
191        "packages/modules/Bluetooth/system/types",
192    ],
193    export_static_lib_headers: ["libbluetooth_rust_interop"],
194}
195
196cc_library {
197    name: "libbluetooth_gd",
198    defaults: [
199        "libbluetooth_gd_defaults",
200    ],
201    include_dirs: [
202        "packages/modules/Bluetooth/system",
203    ],
204    apex_available: [
205        "com.android.btservices",
206    ],
207    min_sdk_version: "31",
208    static_libs: ["libchrome"],
209}
210
211cc_library_static {
212    name: "libbluetooth-gdx",
213    defaults: [
214        "libbluetooth_gd_defaults",
215    ],
216    srcs: [
217        ":BluetoothDiscoverySources",
218        ":BluetoothShimSources",
219    ],
220    include_dirs: [
221        "packages/modules/Bluetooth/system",
222    ],
223    apex_available: [
224        "com.android.btservices",
225    ],
226    min_sdk_version: "31",
227    static_libs: ["libchrome"],
228}
229
230cc_library {
231    name: "libbluetooth_gd_fuzzing",
232    defaults: [
233        "libbluetooth_gd_defaults",
234    ],
235    include_dirs: [
236        "packages/modules/Bluetooth/system",
237    ],
238    srcs: [
239        ":BluetoothOsSources_fake_timer",
240    ],
241    cflags: [
242        "-DFUZZ_TARGET",
243        "-DUSE_FAKE_TIMERS",
244        "-Wno-unused-parameter",
245    ],
246    static_libs: [
247        "libbluetooth-types",
248        "libbt-common",
249        "libchrome",
250        "libosi",
251    ],
252}
253
254cc_library {
255    name: "libbluetooth_gd_unit_tests",
256    defaults: [
257        "libbluetooth_gd_defaults",
258    ],
259    include_dirs: [
260        "packages/modules/Bluetooth/system",
261    ],
262    srcs: [
263        ":BluetoothOsSources_fake_timer",
264    ],
265    cflags: [
266        "-DUSE_FAKE_TIMERS",
267    ],
268    static_libs: [
269        "libbluetooth-types",
270        "libbt-common",
271        "libchrome",
272        "libosi",
273    ],
274}
275
276cc_binary {
277    name: "bluetooth_stack_with_facade",
278    defaults: [
279        "gd_defaults",
280    ],
281    include_dirs: [
282        "packages/modules/Bluetooth/system",
283        "packages/modules/Bluetooth/system/include",
284        "packages/modules/Bluetooth/system/types",
285    ],
286    host_supported: true,
287    srcs: [
288        ":BluetoothFacade_hci_hal",
289        ":BluetoothFacade_hci_layer",
290        ":BluetoothFacade_l2cap_layer",
291        ":BluetoothFacade_neighbor",
292        ":BluetoothFacade_security_layer",
293        ":TestMockMainShimStack",
294        "facade/facade_main.cc",
295        "facade/grpc_root_server.cc",
296        "facade/read_only_property_server.cc",
297        "grpc/grpc_module.cc",
298    ],
299    generated_headers: [
300        "BlueberryFacadeGeneratedStub_h",
301        "BluetoothGeneratedBundlerSchema_h_bfbs",
302        "BluetoothGeneratedDumpsysDataSchema_h",
303        // Needed here to guarantee that generated zip file is created before
304        // bluetooth_cert_tests.zip is packaged
305        "BlueberryFacadeAndCertGeneratedStub_py",
306    ],
307    generated_sources: [
308        "BlueberryFacadeGeneratedStub_cc",
309    ],
310    static_libs: [
311        "breakpad_client",
312        "libPlatformProperties",
313        "libbluetooth-dumpsys",
314        "libbluetooth-gdx",
315        "libbluetooth-protos",
316        "libbluetooth-types",
317        "libbluetooth_crypto_toolbox",
318        "libbluetooth_gd",
319        "libbluetooth_hci_pdl",
320        "libbluetooth_l2cap_pdl",
321        "libbluetooth_log",
322        "libbluetooth_ras_pdl",
323        "libbluetooth_rust_interop",
324        "libbluetooth_smp_pdl",
325        "libbt-common",
326        "libbt_shim_bridge",
327        "libbt_shim_ffi",
328        "libchrome",
329        "libcom.android.sysprop.bluetooth.wrapped",
330        "libflatbuffers-cpp",
331        "libosi",
332    ],
333    shared_libs: [
334        "libaconfig_storage_read_api_cc",
335        "libbase",
336        "libcrypto",
337        "libgrpc++",
338        "libgrpc_wrap",
339        "liblog",
340        "libprotobuf-cpp-full",
341        "libunwindstack",
342        "server_configurable_flags",
343    ],
344    target: {
345        android: {
346            shared_libs: [
347                "android.hardware.bluetooth@1.0",
348                "android.hardware.bluetooth@1.1",
349                "libbinder_ndk",
350                "libcutils",
351                "libhidlbase",
352                "libstatssocket",
353                "libutils",
354            ],
355            static_libs: [
356                "android.system.suspend-V1-ndk",
357                "android.system.suspend.control-V1-ndk",
358                "libstatslog_bt",
359            ],
360        },
361        host: {
362            required: [
363                "root-canal",
364            ],
365        },
366    },
367    sanitize: {
368        address: true,
369        cfi: true,
370    },
371}
372
373cc_test {
374    name: "bluetooth_test_with_timerfd",
375    test_suites: ["general-tests"],
376    defaults: [
377        "gd_defaults",
378        "mts_defaults",
379    ],
380    include_dirs: [
381        "packages/modules/Bluetooth/system",
382        "packages/modules/Bluetooth/system/include",
383        "packages/modules/Bluetooth/system/types",
384    ],
385    host_supported: true,
386    target: {
387        host: {
388            srcs: [
389                ":BluetoothOsSystemProperties_host",
390            ],
391        },
392        android: {
393            srcs: [
394                ":BluetoothOsSystemProperties_android",
395            ],
396        },
397    },
398    srcs: [
399        ":BluetoothOsTestSources_timerfd",
400    ],
401    static_libs: [
402        "libbluetooth_log",
403        "libchrome",
404        "libgmock",
405    ],
406    shared_libs: [
407        "libbase",
408        "liblog",
409    ],
410    sanitize: {
411        address: true,
412    },
413    min_sdk_version: "Tiramisu",
414}
415
416cc_test {
417    name: "bluetooth_test_gd_unit",
418    test_suites: ["general-tests"],
419    defaults: [
420        "gd_defaults",
421        "mts_defaults",
422    ],
423    include_dirs: [
424        "packages/modules/Bluetooth/system",
425        "packages/modules/Bluetooth/system/include",
426        "packages/modules/Bluetooth/system/types",
427    ],
428    host_supported: true,
429    // TODO(b/231993739): Reenable isolated:true by deleting the explicit disable below
430    isolated: false,
431    target: {
432        linux: {
433            srcs: [
434                ":BluetoothOsTestSources_linux_generic",
435            ],
436        },
437        host: {
438            srcs: [
439                ":BluetoothHalTestSources_hci_host",
440                ":BluetoothOsTestSources_host",
441                ":BluetoothSyspropsUnitTestSources",
442            ],
443        },
444        android: {
445            srcs: [
446                ":BluetoothOsTestSources_android",
447            ],
448            static_libs: [
449                "android.hardware.bluetooth@1.0",
450                "android.hardware.bluetooth@1.1",
451                "android.system.suspend-V1-ndk",
452                "android.system.suspend.control-V1-ndk",
453                "libstatslog_bt",
454            ],
455            shared_libs: [
456                "libbinder_ndk",
457                "libcutils",
458                "libhidlbase",
459                "libstatssocket",
460                "libutils",
461            ],
462        },
463    },
464    srcs: [
465        ":BluetoothCommonTestSources",
466        ":BluetoothCryptoToolboxTestSources",
467        ":BluetoothHalTestSources",
468        ":BluetoothHciUnitTestSources",
469        ":BluetoothL2capUnitTestSources",
470        ":BluetoothMetricsTestSources",
471        ":BluetoothOsTestSources",
472        ":BluetoothPacketTestSources",
473        ":BluetoothSecurityUnitTestSources",
474        ":BluetoothStorageUnitTestSources",
475        "module_unittest.cc",
476        "stack_manager_unittest.cc",
477    ],
478    generated_headers: [
479        "BluetoothGeneratedBundlerSchema_h_bfbs",
480        "BluetoothGeneratedDumpsysDataSchema_h",
481        "BluetoothGeneratedDumpsysInternalTestData_h",
482        "BluetoothGeneratedDumpsysTestData_h",
483    ],
484    static_libs: [
485        "libbase",
486        "libbluetooth-protos",
487        "libbluetooth-types",
488        "libbluetooth_crypto_toolbox",
489        "libbluetooth_gd_unit_tests",
490        "libbluetooth_hci_pdl",
491        "libbluetooth_l2cap_pdl",
492        "libbluetooth_log",
493        "libbluetooth_ras_pdl",
494        "libbluetooth_rust_interop",
495        "libbluetooth_smp_pdl",
496        "libbt-common",
497        "libbt-platform-protos-lite",
498        "libbt_shim_bridge",
499        "libbt_shim_ffi",
500        "libchrome",
501        "libcom.android.sysprop.bluetooth.wrapped",
502        "libflagtest",
503        "libflatbuffers-cpp",
504        "libgmock",
505        "libosi",
506    ],
507    shared_libs: [
508        "libPlatformProperties",
509        "libaconfig_storage_read_api_cc",
510        "libcrypto",
511        "server_configurable_flags",
512    ],
513    sanitize: {
514        address: true,
515    },
516    min_sdk_version: "Tiramisu",
517}
518
519cc_test {
520    name: "bluetooth_test_gdx_unit",
521    test_suites: ["device-tests"],
522    defaults: [
523        "gd_defaults",
524        "mts_defaults",
525    ],
526    include_dirs: [
527        "packages/modules/Bluetooth/system",
528        "packages/modules/Bluetooth/system/include",
529        "packages/modules/Bluetooth/system/stack/include",
530        "packages/modules/Bluetooth/system/types",
531    ],
532    host_supported: true,
533    srcs: [
534        ":BluetoothDiscoveryTestSources",
535        ":BluetoothDumpsysTestSources",
536        ":BluetoothShimTestSources",
537        ":TestCommonMockFunctions",
538        ":TestMockMainShimStack",
539        "module_gdx_unittest.cc",
540        "module_jniloop_unittest.cc",
541        "module_mainloop_unittest.cc",
542        "module_state_dumper_unittest.cc",
543    ],
544    generated_headers: [
545        "BluetoothGeneratedBundlerSchema_h_bfbs",
546        "BluetoothGeneratedDumpsysDataSchema_h",
547        "BluetoothGeneratedDumpsysInternalTestData_h",
548        "BluetoothGeneratedDumpsysTestData_h",
549    ],
550    static_libs: [
551        "libaconfig_storage_read_api_cc",
552        "libbase",
553        "libbluetooth-dumpsys",
554        "libbluetooth-dumpsys-test",
555        "libbluetooth-dumpsys-unittest",
556        "libbluetooth-gdx",
557        "libbluetooth-types",
558        "libbluetooth_gd",
559        "libbluetooth_log",
560        "libbt-btu-main-thread",
561        "libbt-common",
562        "libbt-jni-thread",
563        "libbt_shim_bridge",
564        "libbt_shim_ffi",
565        "libchrome",
566        "libevent",
567        "libflatbuffers-cpp",
568        "libgmock",
569        "liblog",
570        "libosi",
571        "server_configurable_flags",
572    ],
573    shared_libs: [
574        "libcrypto",
575    ],
576    sanitize: {
577        address: true,
578    },
579    min_sdk_version: "Tiramisu",
580}
581
582cc_test {
583    name: "bluetooth_packet_parser_test",
584    test_suites: ["general-tests"],
585    defaults: [
586        "gd_defaults",
587        "mts_defaults",
588    ],
589    include_dirs: ["packages/modules/Bluetooth/system/gd"],
590    host_supported: true,
591    test_options: {
592        unit_test: true,
593    },
594    srcs: [
595        ":BluetoothPacketParserTestPacketTestSources",
596        ":BluetoothPacketSources",
597    ],
598    generated_headers: [
599        "BluetoothPacketParserTestPacketPdlGen_h",
600    ],
601    sanitize: {
602        address: true,
603        cfi: true,
604    },
605    static_libs: [
606        "libbase",
607        "libbluetooth_log",
608        "libbluetooth_rust_interop",
609        "libbt_shim_bridge",
610        "libbt_shim_ffi",
611        "liblog",
612    ],
613    target: {
614        android: {
615            shared_libs: [
616                "libcutils",
617                "libhidlbase",
618                "libutils",
619            ],
620        },
621        host_linux: {
622            shared_libs: [
623                "libcutils",
624                "libhidlbase",
625                "libutils",
626            ],
627        },
628    },
629    min_sdk_version: "30",
630}
631
632cc_defaults {
633    name: "gd_fuzz_defaults",
634    defaults: ["gd_defaults"],
635    srcs: [
636        ":BluetoothFuzzHelperSources",
637        ":BluetoothHciFuzzHelperSources",
638    ],
639    static_libs: [
640        "libbluetooth-protos",
641        "libbluetooth-types",
642        "libbluetooth_crypto_toolbox",
643        "libbluetooth_gd_fuzzing",
644        "libbluetooth_log",
645        "libbluetooth_rust_interop",
646        "libbt-common",
647        "libbt_shim_bridge",
648        "libbt_shim_ffi",
649        "libchrome",
650        "libcom.android.sysprop.bluetooth.wrapped",
651        "libgmock",
652        "libgtest",
653        "libosi",
654    ],
655    host_supported: true,
656    generated_headers: [
657        "BluetoothGeneratedDumpsysDataSchema_h",
658    ],
659    shared_libs: [
660        "libPlatformProperties",
661        "libaconfig_storage_read_api_cc",
662        "libbase",
663        "libcrypto",
664        "libgrpc++",
665        "libgrpc_wrap",
666        "liblog",
667        "server_configurable_flags",
668    ],
669    cflags: [
670        "-DFUZZ_TARGET",
671        "-DUSE_FAKE_TIMERS",
672    ],
673    target: {
674        android: {
675            shared_libs: [
676                "android.hardware.bluetooth@1.0",
677                "android.hardware.bluetooth@1.1",
678                "android.system.suspend.control-V1-ndk",
679                "libbinder_ndk",
680                "libcutils",
681                "libhidlbase",
682                "libstatslog_bt",
683                "libutils",
684            ],
685        },
686    },
687}
688
689cc_fuzz {
690    name: "bluetooth_gd_fuzz_test",
691    defaults: ["gd_fuzz_defaults"],
692    srcs: [
693        ":BluetoothHciFuzzTestSources",
694        ":BluetoothL2capFuzzTestSources",
695        "fuzz_test.cc",
696    ],
697    fuzz_config: {
698        cc: ["android-bluetooth-security@google.com"],
699        componentid: 27441,
700    },
701    cflags: ["-Wno-unused-parameter"],
702}
703
704cc_fuzz {
705    name: "bluetooth_gd_hci_layer_fuzz_test",
706    defaults: ["gd_fuzz_defaults"],
707    srcs: [
708        ":BluetoothHalFuzzSources",
709        "hci/fuzz/hci_layer_fuzz_test.cc",
710    ],
711    cflags: ["-Wno-unused-parameter"],
712}
713
714cc_fuzz {
715    name: "bluetooth_gd_acl_manager_fuzz_test",
716    defaults: ["gd_fuzz_defaults"],
717    srcs: [
718        "hci/fuzz/acl_manager_fuzz_test.cc",
719    ],
720    fuzz_config: {
721        cc: ["android-bluetooth-security@google.com"],
722        componentid: 27441,
723    },
724    cflags: ["-Wno-unused-parameter"],
725}
726
727cc_benchmark {
728    name: "bluetooth_benchmark_gd",
729    defaults: [
730        "gd_defaults",
731    ],
732    host_supported: true,
733    srcs: [
734        ":BluetoothOsBenchmarkSources",
735        "benchmark.cc",
736    ],
737    static_libs: [
738        "libbase",
739        "libbluetooth_gd",
740        "libbluetooth_log",
741        "libbt_shim_bridge",
742        "libchrome",
743        "liblog",
744    ],
745}
746
747// Generates binary schema data to be bundled and source file generated
748genrule {
749    name: "BluetoothGeneratedDumpsysBinarySchema_bfbs",
750    tools: [
751        "flatc",
752    ],
753    cmd: "$(location flatc) -I packages/modules/Bluetooth/system/gd -b --schema -o $(genDir) $(in) ",
754    srcs: [
755        "common/init_flags.fbs",
756        "dumpsys_data.fbs",
757        "hci/hci_acl_manager.fbs",
758        "hci/hci_controller.fbs",
759        "l2cap/classic/l2cap_classic_module.fbs",
760        "module_unittest.fbs",
761        "os/wakelock_manager.fbs",
762        "shim/dumpsys.fbs",
763    ],
764    out: [
765        "dumpsys.bfbs",
766        "dumpsys_data.bfbs",
767        "hci_acl_manager.bfbs",
768        "hci_controller.bfbs",
769        "init_flags.bfbs",
770        "l2cap_classic_module.bfbs",
771        "wakelock_manager.bfbs",
772    ],
773}
774
775genrule {
776    name: "BluetoothGeneratedDumpsysDataSchema_h",
777    tools: [
778        "flatc",
779    ],
780    cmd: "$(location flatc) -I packages/modules/Bluetooth/system/gd -o $(genDir) --cpp $(in) ",
781    srcs: [
782        "common/init_flags.fbs",
783        "dumpsys_data.fbs",
784        "hci/hci_acl_manager.fbs",
785        "hci/hci_controller.fbs",
786        "l2cap/classic/l2cap_classic_module.fbs",
787        "module_unittest.fbs",
788        "os/wakelock_manager.fbs",
789        "shim/dumpsys.fbs",
790    ],
791    out: [
792        "dumpsys_data_generated.h",
793        "dumpsys_generated.h",
794        "hci_acl_manager_generated.h",
795        "hci_controller_generated.h",
796        "init_flags_generated.h",
797        "l2cap_classic_module_generated.h",
798        "wakelock_manager_generated.h",
799    ],
800}
801