diff options
author | 2024-11-22 01:00:15 +0000 | |
---|---|---|
committer | 2024-11-25 23:02:56 +0000 | |
commit | 14a4e988ce41a09ef57d1d4fca7ed2fe65ea292a (patch) | |
tree | 3a8dd05180a73d54694b514ff701f69ea2a919b1 | |
parent | 8703e24dc528e905b29423af9ae898ddf950e042 (diff) |
gd/dumpsys: Remove flatbuffer abtraction for dumpsys output
Bug: 331817295
Test: m com.android.btservices
Flag: EXEMPT, no logical change
Change-Id: I0300fcef76f90bc21d642eebba13f3ec4638b2d5
94 files changed, 16 insertions, 3663 deletions
diff --git a/android/app/Android.bp b/android/app/Android.bp index 0d1a735787..4cc4932525 100644 --- a/android/app/Android.bp +++ b/android/app/Android.bp @@ -108,7 +108,6 @@ cc_library_shared { "libaconfig_storage_read_api_cc", "libbase", "libbluetooth", - "libbluetooth-dumpsys", "libbluetooth-types", "libbluetooth_core_rs", "libbluetooth_core_rs_bridge", diff --git a/system/BUILD.gn b/system/BUILD.gn index 783428604a..01286ec4e8 100644 --- a/system/BUILD.gn +++ b/system/BUILD.gn @@ -55,7 +55,6 @@ group("bluetooth") { group("tools") { deps = [ - "//bt/system/gd/dumpsys/bundler:bluetooth_flatbuffer_bundler", "//bt/system/gd/packet/parser:bluetooth_packetgen", ] } diff --git a/system/audio/Android.bp b/system/audio/Android.bp index d5dde594e1..481182dc5f 100644 --- a/system/audio/Android.bp +++ b/system/audio/Android.bp @@ -83,9 +83,6 @@ cc_library_host_shared { "liblog", ], stl: "libc++_static", - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], } python_test_host { diff --git a/system/audio_hal_interface/Android.bp b/system/audio_hal_interface/Android.bp index f485de80aa..a074c7f959 100644 --- a/system/audio_hal_interface/Android.bp +++ b/system/audio_hal_interface/Android.bp @@ -228,7 +228,6 @@ cc_defaults { "android.hardware.common.fmq-V1-ndk", "libFraunhoferAAC", "libbase", - "libbluetooth-dumpsys", "libbluetooth-protos", "libbluetooth-types", "libbluetooth_core_rs", diff --git a/system/audio_hal_interface/fuzzer/Android.bp b/system/audio_hal_interface/fuzzer/Android.bp index 9a32f910e3..f2301b6d00 100644 --- a/system/audio_hal_interface/fuzzer/Android.bp +++ b/system/audio_hal_interface/fuzzer/Android.bp @@ -59,7 +59,6 @@ cc_defaults { "bluetooth_flags_c_lib", "libFraunhoferAAC", "libbase", - "libbluetooth-dumpsys", "libbluetooth-protos", "libbluetooth-types", "libbluetooth_core_rs", diff --git a/system/bta/Android.bp b/system/bta/Android.bp index f99f437bd4..698752dbb4 100644 --- a/system/bta/Android.bp +++ b/system/bta/Android.bp @@ -27,9 +27,6 @@ cc_defaults { "packages/modules/Bluetooth/system/udrv/include", ], header_libs: ["libbluetooth_headers"], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], } filegroup { @@ -238,7 +235,6 @@ cc_library_static { cc_test { name: "net_test_bta", defaults: [ - "bluetooth_flatbuffer_bundler_defaults", "fluoride_bta_defaults", "latest_android_hardware_audio_common_ndk_static", "latest_android_hardware_bluetooth_audio_ndk_static", @@ -288,9 +284,6 @@ cc_test { "test/bta_sdp_test.cc", "test/bta_sec_test.cc", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], shared_libs: [ "libaconfig_storage_read_api_cc", "libcrypto", @@ -376,9 +369,6 @@ cc_test { "test/gatt/database_builder_test.cc", "test/gatt/database_test.cc", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], shared_libs: [ "libaconfig_storage_read_api_cc", "libbase", @@ -466,9 +456,6 @@ cc_test { "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system/gd", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":TestCommonMockFunctions", ":TestFakeOsi", @@ -764,7 +751,6 @@ cc_test { test_suites: ["general-tests"], defaults: [ "aconfig_lib_cc_shared_link.defaults", - "bluetooth_flatbuffer_bundler_defaults", "fluoride_defaults", "mts_defaults", ], @@ -811,7 +797,6 @@ cc_test { ":audio_set_scenarios_json", ], generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", "LeAudioSetConfigSchemas_h", ], shared_libs: [ @@ -848,7 +833,6 @@ cc_test { name: "bluetooth_le_audio_test", test_suites: ["general-tests"], defaults: [ - "bluetooth_flatbuffer_bundler_defaults", "fluoride_defaults", "mts_defaults", ], @@ -921,7 +905,6 @@ cc_test { ":audio_set_scenarios_json", ], generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", "LeAudioSetConfigSchemas_h", ], shared_libs: [ @@ -959,7 +942,6 @@ cc_test { name: "bluetooth_le_audio_client_test", test_suites: ["general-tests"], defaults: [ - "bluetooth_flatbuffer_bundler_defaults", "fluoride_bta_defaults", "mts_defaults", ], @@ -1149,7 +1131,6 @@ cc_test { test_suites: ["general-tests"], defaults: [ "aconfig_lib_cc_shared_link.defaults", - "bluetooth_flatbuffer_bundler_defaults", "fluoride_bta_defaults", "mts_defaults", ], @@ -1346,9 +1327,6 @@ cc_test { "libgmock", "libosi", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], sanitize: { cfi: true, scs: true, @@ -1417,9 +1395,6 @@ cc_test { "libgmock", "libosi", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], sanitize: { cfi: true, scs: true, diff --git a/system/bta/BUILD.gn b/system/bta/BUILD.gn index 928359ab22..425289338b 100644 --- a/system/bta/BUILD.gn +++ b/system/bta/BUILD.gn @@ -14,8 +14,7 @@ # limitations under the License. # -import("//bt/system/gd/dumpsys/bundler/bundler.gni") -import("//common-mk/flatbuffer.gni") +import("//bt/system/bta/bundler.gni") static_library("bta") { sources = [ diff --git a/system/gd/dumpsys/bundler/bundler.gni b/system/bta/bundler.gni index 2942bbee1d..2942bbee1d 100644 --- a/system/gd/dumpsys/bundler/bundler.gni +++ b/system/bta/bundler.gni diff --git a/system/btif/Android.bp b/system/btif/Android.bp index d442e0c2cf..85b937b26d 100644 --- a/system/btif/Android.bp +++ b/system/btif/Android.bp @@ -123,9 +123,6 @@ cc_library_static { "src/btif_rc.cc", "src/btif_vc.cc", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], local_include_dirs: [ "include", ], @@ -213,9 +210,6 @@ cc_library_static { "src/btif_util.cc", "src/stack_manager.cc", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], target: { android: { whole_static_libs: [ @@ -308,7 +302,6 @@ cc_test { "bluetooth_flags_c_lib_for_test", "libFraunhoferAAC", "libbase", - "libbluetooth-dumpsys", "libbluetooth-for-tests", "libbluetooth-types", "libbluetooth_core_rs", @@ -390,9 +383,6 @@ cc_test { "test/btif_profile_queue_test.cc", ], header_libs: ["libbluetooth_headers"], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], static_libs: [ "libbluetooth-types", "libbluetooth_gd", @@ -426,9 +416,6 @@ cc_test { "test/btif_avrcp_audio_track_test.cc", ], header_libs: ["libbluetooth_headers"], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], static_libs: [ "libbluetooth-types", "libbluetooth_log", @@ -574,10 +561,6 @@ cc_test { ":TestMockUdrv", "test/btif_hh_test.cc", ], - generated_headers: [ - "BluetoothGeneratedBundlerSchema_h_bfbs", - "BluetoothGeneratedDumpsysDataSchema_h", - ], header_libs: ["libbluetooth_headers"], aidl: { libs: ["bluetooth_constants"], @@ -699,10 +682,6 @@ cc_test { ":TestMockUdrv", "test/btif_core_test.cc", ], - generated_headers: [ - "BluetoothGeneratedBundlerSchema_h_bfbs", - "BluetoothGeneratedDumpsysDataSchema_h", - ], header_libs: ["libbluetooth_headers"], aidl: { libs: ["bluetooth_constants"], diff --git a/system/device/Android.bp b/system/device/Android.bp index 5411561278..eb71e3f414 100644 --- a/system/device/Android.bp +++ b/system/device/Android.bp @@ -29,9 +29,6 @@ cc_library_static { apex_available: [ "com.android.btservices", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], min_sdk_version: "Tiramisu", header_libs: ["libbluetooth_headers"], static_libs: [ diff --git a/system/device/fuzzer/Android.bp b/system/device/fuzzer/Android.bp index d1b7357de9..c7a6917898 100644 --- a/system/device/fuzzer/Android.bp +++ b/system/device/fuzzer/Android.bp @@ -40,9 +40,6 @@ cc_fuzz { "liblog", "server_configurable_flags", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], static_libs: [ "bluetooth_flags_c_lib", "libbluetooth-types", diff --git a/system/gd/Android.bp b/system/gd/Android.bp index 9a11d3a90b..d128823eed 100644 --- a/system/gd/Android.bp +++ b/system/gd/Android.bp @@ -122,7 +122,6 @@ cc_defaults { }, srcs: [ ":BluetoothCommonSources", - ":BluetoothDumpsysSources", ":BluetoothHalSources", ":BluetoothHciSources", ":BluetoothMetricsSources", @@ -132,13 +131,8 @@ cc_defaults { ":BluetoothShimSources", ":BluetoothStorageSources", "module.cc", - "module_dumper.cc", "stack_manager.cc", ], - generated_headers: [ - "BluetoothGeneratedBundlerSchema_h_bfbs", - "BluetoothGeneratedDumpsysDataSchema_h", - ], shared_libs: [ "libcrypto", "libflatbuffers-cpp", @@ -156,7 +150,6 @@ cc_defaults { static_libs: [ "libaconfig_storage_read_api_cc", "libbase", - "libbluetooth-dumpsys", "libbluetooth-protos", "libbluetooth-types", "libbluetooth_crypto_toolbox", @@ -264,8 +257,6 @@ cc_binary { ], generated_headers: [ "BlueberryFacadeGeneratedStub_h", - "BluetoothGeneratedBundlerSchema_h_bfbs", - "BluetoothGeneratedDumpsysDataSchema_h", ], generated_sources: [ "BlueberryFacadeGeneratedStub_cc", @@ -274,7 +265,6 @@ cc_binary { "bluetooth_flags_c_lib", "breakpad_client", "libPlatformProperties", - "libbluetooth-dumpsys", "libbluetooth-protos", "libbluetooth-types", "libbluetooth_crypto_toolbox", @@ -433,12 +423,6 @@ cc_test { "module_unittest.cc", "stack_manager_unittest.cc", ], - generated_headers: [ - "BluetoothGeneratedBundlerSchema_h_bfbs", - "BluetoothGeneratedDumpsysDataSchema_h", - "BluetoothGeneratedDumpsysInternalTestData_h", - "BluetoothGeneratedDumpsysTestData_h", - ], static_libs: [ "bluetooth_flags_c_lib_for_test", "libbase", @@ -541,9 +525,6 @@ cc_defaults { "libosi", ], host_supported: true, - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], shared_libs: [ "libPlatformProperties", "libaconfig_storage_read_api_cc", @@ -629,34 +610,3 @@ cc_benchmark { "server_configurable_flags", ], } - -// Generates binary schema data to be bundled and source file generated -genrule { - name: "BluetoothGeneratedDumpsysBinarySchema_bfbs", - tools: [ - "flatc", - ], - cmd: "$(location flatc) -I packages/modules/Bluetooth/system/gd -b --schema -o $(genDir) $(in) ", - srcs: [ - "dumpsys_data.fbs", - "module_unittest.fbs", - ], - out: [ - "dumpsys_data.bfbs", - ], -} - -genrule { - name: "BluetoothGeneratedDumpsysDataSchema_h", - tools: [ - "flatc", - ], - cmd: "$(location flatc) -I packages/modules/Bluetooth/system/gd -o $(genDir) --cpp $(in) ", - srcs: [ - "dumpsys_data.fbs", - "module_unittest.fbs", - ], - out: [ - "dumpsys_data_generated.h", - ], -} diff --git a/system/gd/BUILD.gn b/system/gd/BUILD.gn index cff0c11583..fc4b808fb7 100644 --- a/system/gd/BUILD.gn +++ b/system/gd/BUILD.gn @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//bt/system/gd/dumpsys/bundler/bundler.gni") import("//bt/system/gd/packet/parser/packetgen.gni") import("//common-mk/flatbuffer.gni") @@ -47,8 +46,6 @@ config("rust_defaults") { group("gd_default_deps") { deps = [ "//bt/system:libbt-platform-protos-lite", - "//bt/system/gd:BluetoothGeneratedDumpsysDataSchema_h", - "//bt/system/gd/dumpsys:libbluetooth-dumpsys", "//bt/system/pdl:BluetoothGeneratedPackets_h", ] } @@ -56,7 +53,6 @@ group("gd_default_deps") { static_library("libbluetooth_gd") { sources = [ "module.cc", - "module_dumper.cc", "stack_manager.cc", ] @@ -65,7 +61,6 @@ static_library("libbluetooth_gd") { deps = [ "//bt/system/gd/rust/topshim:libbluetooth_topshim", "//bt/system/gd/common:BluetoothCommonSources", - "//bt/system/gd/dumpsys:BluetoothDumpsysSources", "//bt/system/gd/hal:BluetoothHalSources", "//bt/system/gd/hal:BluetoothHalSources_hci_host", "//bt/system/gd/hal:BluetoothHalSources_ranging_host", @@ -77,17 +72,3 @@ static_library("libbluetooth_gd") { "//bt/system/pdl:BluetoothGeneratedPackets_h", ] } - -flatbuffer("BluetoothGeneratedDumpsysDataSchema_h") { - sources = [ - "dumpsys_data.fbs", - ] -} - -bt_flatc_binary_schema("BluetoothGeneratedDumpsysBinarySchema_bfbs") { - sources = [ - "dumpsys_data.fbs", - ] - - include_dir = "system/gd" -} diff --git a/system/gd/dumpsys/Android.bp b/system/gd/dumpsys/Android.bp deleted file mode 100644 index 84074824ac..0000000000 --- a/system/gd/dumpsys/Android.bp +++ /dev/null @@ -1,212 +0,0 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "system_bt_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["system_bt_license"], -} - -filegroup { - name: "BluetoothDumpsysSources", - srcs: [ - "filter.cc", - "internal/filter_internal.cc", - "reflection_schema.cc", - ], -} - -filegroup { - name: "BluetoothDumpsysTestSources", - srcs: [ - "filter_test.cc", - "internal/filter_internal_test.cc", - "reflection_schema_test.cc", - ], -} - -genrule { - name: "BluetoothGeneratedDumpsysTestData_h", - tools: [ - "flatc", - ], - cmd: "$(location flatc) -I packages/modules/Bluetooth/system/gd -b --schema -o $(genDir) --cpp $(in) ", - srcs: [ - "test_data/bar.fbs", - "test_data/baz.fbs", - "test_data/foo.fbs", - "test_data/qux.fbs", - "test_data/root.fbs", - ], - out: [ - "bar_generated.h", - "baz_generated.h", - "foo_generated.h", - "qux_generated.h", - "root_generated.h", - ], -} - -genrule { - name: "BluetoothGeneratedDumpsysTestData_bfbs", - visibility: ["//visibility:private"], - tools: [ - "flatc", - ], - cmd: "$(location flatc) -I packages/modules/Bluetooth/system/gd -b --schema -o $(genDir) --cpp $(in) ", - srcs: [ - "test_data/bar.fbs", - "test_data/baz.fbs", - "test_data/foo.fbs", - "test_data/qux.fbs", - "test_data/root.fbs", - ], - out: [ - "bar.bfbs", - "baz.bfbs", - "foo.bfbs", - "qux.bfbs", - "root.bfbs", - ], -} - -genrule { - name: "BluetoothGeneratedDumpsysTestSchema_cc", - visibility: ["//visibility:private"], - tools: [ - "bluetooth_flatbuffer_bundler", - ], - cmd: "$(location bluetooth_flatbuffer_bundler) -w -m bluetooth.DumpsysData -f dumpsys_module_schema_data -n testing -g $(genDir) $(locations :BluetoothGeneratedDumpsysBinarySchema_bfbs)", - srcs: [ - ":BluetoothGeneratedDumpsysBinarySchema_bfbs", - ], - out: [ - "dumpsys_module_schema_data.cc", - ], -} - -genrule { - name: "BluetoothGeneratedDumpsysBundledSchema_cc", - visibility: ["//visibility:private"], - tools: [ - "bluetooth_flatbuffer_bundler", - ], - cmd: "$(location bluetooth_flatbuffer_bundler) -w -m bluetooth.DumpsysData -f generated_dumpsys_bundled_schema -n bluetooth::dumpsys -g $(genDir) $(locations :BluetoothGeneratedDumpsysBinarySchema_bfbs)", - srcs: [ - ":BluetoothGeneratedDumpsysBinarySchema_bfbs", - ], - out: [ - "generated_dumpsys_bundled_schema.cc", - ], -} - -genrule { - name: "BluetoothGeneratedDumpsysBundledTestSchema_cc", - visibility: ["//visibility:private"], - tools: [ - "bluetooth_flatbuffer_bundler", - ], - cmd: "$(location bluetooth_flatbuffer_bundler) -w -m testing.DumpsysTestDataRoot -f generated_dumpsys_bundled_test_schema -n testing -g $(genDir) $(locations :BluetoothGeneratedDumpsysTestData_bfbs)", - srcs: [ - ":BluetoothGeneratedDumpsysTestData_bfbs", - ], - out: [ - "generated_dumpsys_bundled_test_schema.cc", - ], -} - -genrule { - name: "BluetoothFlatbufferTestData_h", - tools: [ - "flatc", - ], - cmd: "$(location flatc) -I packages/modules/Bluetooth/system/gd -b --schema -o $(genDir) --cpp $(in) ", - srcs: [ - "bluetooth_flatbuffer_test.fbs", - ], - out: [ - "bluetooth_flatbuffer_test.bfbs", - "bluetooth_flatbuffer_test_generated.h", - ], -} - -genrule { - name: "BluetoothGeneratedDumpsysInternalTestData_h", - tools: [ - "flatc", - ], - cmd: "$(location flatc) --cpp -o $(genDir)/dumpsys/internal/test_data $(in)", - srcs: [ - "internal/test_data/float.fbs", - "internal/test_data/integer.fbs", - "internal/test_data/string.fbs", - "internal/test_data/struct.fbs", - ], - out: [ - "dumpsys/internal/test_data/float_generated.h", - "dumpsys/internal/test_data/integer_generated.h", - "dumpsys/internal/test_data/string_generated.h", - "dumpsys/internal/test_data/struct_generated.h", - ], -} - -cc_library { - name: "libbluetooth-dumpsys", - host_supported: true, - defaults: [ - "gd_defaults", - ], - generated_sources: [ - "BluetoothGeneratedDumpsysBundledSchema_cc", - ], - apex_available: [ - "com.android.btservices", - ], - min_sdk_version: "30", -} - -cc_library { - name: "libbluetooth-dumpsys-test", - host_supported: true, - defaults: [ - "gd_defaults", - ], - generated_sources: [ - "BluetoothGeneratedDumpsysBundledTestSchema_cc", - ], -} - -cc_library { - name: "libbluetooth-dumpsys-unittest", - host_supported: true, - defaults: [ - "gd_defaults", - ], - generated_headers: [ - "BluetoothGeneratedDumpsysTestSchema_cc", - ], -} - -cc_test { - name: "bluetooth_flatbuffer_tests", - test_suites: ["general-tests"], - defaults: [ - "bluetooth_cflags", - "mts_defaults", - ], - host_supported: true, - test_options: { - unit_test: true, - }, - static_libs: [ - "libflatbuffers-cpp", - "libgmock", - ], - srcs: [ - "bluetooth_flatbuffer_test.cc", - ], - generated_headers: [ - "BluetoothFlatbufferTestData_h", - ], - min_sdk_version: "30", -} diff --git a/system/gd/dumpsys/BUILD.gn b/system/gd/dumpsys/BUILD.gn deleted file mode 100644 index 327089c2ed..0000000000 --- a/system/gd/dumpsys/BUILD.gn +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright 2021 Google, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at: -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//bt/system/gd/dumpsys/bundler/bundler.gni") - -source_set("BluetoothDumpsysSources") { - sources = [ - "filter.cc", - "internal/filter_internal.cc", - "reflection_schema.cc", - ] - - cflags_cc = [ "-Wno-enum-compare-switch" ] - - configs += [ - "//bt/system/gd:gd_defaults", - "//bt/system/log:log_defaults", - ] - deps = [ "//bt/system/gd:gd_default_deps" ] -} - -bt_flatc_bundler("libbluetooth-dumpsys") { - root_name = "bluetooth.DumpsysData" - filename = "generated_dumpsys_bundled_schema" - namespace = "bluetooth::dumpsys" - deps = [ "//bt/system/gd:BluetoothGeneratedDumpsysBinarySchema_bfbs" ] - configs = [ - "//bt/system/gd:gd_defaults", - "//bt/system/log:log_defaults", - ] -} diff --git a/system/gd/dumpsys/bluetooth_flatbuffer_test.cc b/system/gd/dumpsys/bluetooth_flatbuffer_test.cc deleted file mode 100644 index 7c77e1075d..0000000000 --- a/system/gd/dumpsys/bluetooth_flatbuffer_test.cc +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <gmock/gmock.h> -#include <gtest/gtest.h> - -#include "bluetooth_flatbuffer_test_generated.h" -#include "flatbuffers/flatbuffers.h" -#include "flatbuffers/idl.h" -#include "flatbuffers/util.h" - -namespace bluetooth { -namespace dumpsys { - -class BluetoothFlatbufferTest : public ::testing::Test { -protected: - void SetUp() override {} - - void TearDown() override {} -}; - -TEST_F(BluetoothFlatbufferTest, precondition) {} - -TEST_F(BluetoothFlatbufferTest, BuilderTest) { - flatbuffers::FlatBufferBuilder builder(1024); - auto string_private = builder.CreateString("String private"); - auto string_opaque = builder.CreateString("String opaque"); - auto string_anonymized = builder.CreateString("String anonymized"); - auto string_any = builder.CreateString("String any"); - - TestTableBuilder table_builder(builder); - table_builder.add_string_private(string_private); - table_builder.add_string_opaque(string_opaque); - table_builder.add_string_anonymized(string_anonymized); - table_builder.add_string_any(string_any); - - table_builder.add_int_private(123); - table_builder.add_int_opaque(456); - table_builder.add_int_anonymized(789); - table_builder.add_int_any(0xabc); - - builder.Finish(table_builder.Finish()); - - const TestTable* test_table = GetTestTable(builder.GetBufferPointer()); - - ASSERT_EQ("String private", test_table->string_private()->str()); - ASSERT_EQ("String opaque", test_table->string_opaque()->str()); - ASSERT_EQ("String anonymized", test_table->string_anonymized()->str()); - ASSERT_EQ("String any", test_table->string_any()->str()); - - ASSERT_EQ(123, test_table->int_private()); - ASSERT_EQ(456, test_table->int_opaque()); - ASSERT_EQ(789, test_table->int_anonymized()); - ASSERT_EQ(0xabc, test_table->int_any()); -} - -} // namespace dumpsys -} // namespace bluetooth diff --git a/system/gd/dumpsys/bluetooth_flatbuffer_test.fbs b/system/gd/dumpsys/bluetooth_flatbuffer_test.fbs deleted file mode 100644 index f449813620..0000000000 --- a/system/gd/dumpsys/bluetooth_flatbuffer_test.fbs +++ /dev/null @@ -1,17 +0,0 @@ -// Bluetooth module test schema - -attribute "privacy"; - -table TestTable { - string_private:string; // no privacy attribute implies private - string_opaque:string (privacy:"Opaque"); - string_anonymized:string (privacy:"Anonymized"); - string_any:string (privacy:"Any"); - - int_private:int32 (privacy:"Private"); // Explicitly private - int_opaque:int32 (privacy:"Opaque"); - int_anonymized:int32 (privacy:"Anonymized"); - int_any:int32 (privacy:"Any"); -} - -root_type TestTable; diff --git a/system/gd/dumpsys/bundler/Android.bp b/system/gd/dumpsys/bundler/Android.bp deleted file mode 100644 index 301346ec6c..0000000000 --- a/system/gd/dumpsys/bundler/Android.bp +++ /dev/null @@ -1,91 +0,0 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "system_bt_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["system_bt_license"], -} - -filegroup { - name: "BluetoothFlatbufferBundlerSources", - visibility: ["//visibility:private"], - srcs: [ - "bundler.cc", - "main.cc", - ], -} - -filegroup { - name: "BluetoothFlatbufferBundlerTestSources", - visibility: ["//visibility:private"], - srcs: [ - "bundler.cc", - "test.cc", - ], -} - -// Flatbuffer bundler schema that wraps the bundled binary module schema -genrule { - name: "BluetoothGeneratedBundlerSchema_h_bfbs", - visibility: [ - "//packages/modules/Bluetooth/system/bta", - "//packages/modules/Bluetooth/system/btif", - "//packages/modules/Bluetooth/system/btm", - "//packages/modules/Bluetooth/system/gd", - "//packages/modules/Bluetooth/system/main", - "//packages/modules/Bluetooth/system/rust", - "//packages/modules/Bluetooth/system/stack", - ], - tools: [ - "flatc", - ], - cmd: "$(location flatc) -I packages/modules/Bluetooth/system/gd -b --schema -o $(genDir) --cpp $(in) ", - srcs: [ - "bundler_schema.fbs", - ], - out: [ - "bundler_schema.bfbs", - "bundler_schema_generated.h", - ], -} - -cc_defaults { - name: "bluetooth_flatbuffer_bundler_defaults", - defaults: ["bluetooth_cflags"], - generated_headers: [ - "BluetoothGeneratedBundlerSchema_h_bfbs", - ], - sanitize: { - misc_undefined: ["bounds"], - }, - static_libs: [ - "libflatbuffers-cpp", - ], -} - -cc_binary_host { - name: "bluetooth_flatbuffer_bundler", - srcs: [ - ":BluetoothFlatbufferBundlerSources", - ], - defaults: [ - "bluetooth_flatbuffer_bundler_defaults", - ], -} - -cc_test_host { - name: "bluetooth_flatbuffer_bundler_test", - srcs: [ - ":BluetoothFlatbufferBundlerTestSources", - ], - defaults: [ - "bluetooth_flatbuffer_bundler_defaults", - ], - data: [ - "test.bfbs", - ], - test_options: { - unit_test: true, - }, -} diff --git a/system/gd/dumpsys/bundler/BUILD.gn b/system/gd/dumpsys/bundler/BUILD.gn deleted file mode 100644 index 324afbb4f1..0000000000 --- a/system/gd/dumpsys/bundler/BUILD.gn +++ /dev/null @@ -1,50 +0,0 @@ -# -# Copyright 2021 Google, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at: -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//bt/system/gd/dumpsys/bundler/bundler.gni") -import("//common-mk/flatbuffer.gni") - -bt_flatc_binary_schema("BluetoothGeneratedBundlerSchema_h_bfbs") { - sources = [ "bundler_schema.fbs" ] - include_dir = "bt/system/gd" - gen_header = true -} - -# -# The remaining rules are for building on the host -# - -config("bundler_defaults") { - cflags = [ "-fPIC" ] - - cflags_cc = [ - "-std=c++17", - "-Wno-unused-variable", - "-Wno-poison-system-directories", - ] -} - -executable("bluetooth_flatbuffer_bundler") { - sources = [ - "bundler.cc", - "main.cc", - ] - - libs = [ "flatbuffers" ] - - deps = [ ":BluetoothGeneratedBundlerSchema_h_bfbs" ] - - configs += [ ":bundler_defaults" ] -} diff --git a/system/gd/dumpsys/bundler/bundler.cc b/system/gd/dumpsys/bundler/bundler.cc deleted file mode 100644 index 72097ac101..0000000000 --- a/system/gd/dumpsys/bundler/bundler.cc +++ /dev/null @@ -1,322 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "bundler.h" - -#include <assert.h> -#include <stdlib.h> -#include <unistd.h> - -#include <cassert> -#include <list> -#include <map> -#include <vector> - -#include "bundler_schema_generated.h" -#include "flatbuffers/idl.h" -#include "flatbuffers/util.h" - -// TODO(b/369381361) Enfore -Wmissing-prototypes -#pragma GCC diagnostic ignored "-Wmissing-prototypes" - -using namespace bluetooth; -using namespace dumpsys; - -struct Opts opts; - -/** - * Load a binary schema from persistent store using flatbuffer API. - * - * @param filename; Name of file to open and read. - * @param binary_schema: Backing store for flatbuffer binary schema data. - * - * @return: True if operation successful, false otherwise. - */ -bool LoadBinarySchema(const char* filename, std::string* binary_schema) { - assert(filename != nullptr); - assert(binary_schema != nullptr); - if (!flatbuffers::LoadFile(filename, helper::AsBinaryFile, binary_schema)) { - fprintf(stderr, "Unable to open binary flatbuffer schema file:%s\n", filename); - return false; - }; - return true; -} - -/** - * Verify a binary schema using flatbuffer API. - * - * @param schema: Raw binary schema to verify - * - * @return: True if operation successful, false otherwise. - */ -bool VerifyBinarySchema(const std::vector<uint8_t>& raw_schema) { - flatbuffers::Verifier verifier(raw_schema.data(), raw_schema.size()); - if (!reflection::VerifySchemaBuffer(verifier)) { - return false; - } - return true; -} - -/** - * Bundle a set of binary flatbuffer schema into the bundler database. - * - * @param builder; Flatbuffer builder - * @param filenames: Set of filenames to include in bundle - * @param vector_map: Filename to filedata mapping - * - * @return: True if operation successful, false otherwise. - */ -bool CreateBinarySchemaBundle(flatbuffers::FlatBufferBuilder* builder, - const std::vector<std::string>& filenames, - std::vector<flatbuffers::Offset<BundledSchemaMap>>* vector_map, - std::list<std::string>* bundled_names) { - assert(builder != nullptr); - assert(vector_map != nullptr); - assert(bundled_names != nullptr); - - for (auto filename : filenames) { - std::string string_schema; - if (!LoadBinarySchema(filename.c_str(), &string_schema)) { - fprintf(stderr, "Unable to load binary schema from filename:%s\n", filename.c_str()); - return false; - } - std::vector<uint8_t> raw_schema(string_schema.begin(), string_schema.end()); - if (!VerifyBinarySchema(raw_schema)) { - fprintf(stderr, "Failed verification on binary schema filename:%s\n", filename.c_str()); - return false; - } - - const reflection::Schema* schema = reflection::GetSchema(raw_schema.data()); - if (schema->root_table() == nullptr) { - fprintf(stderr, "Unable to find root table for binary flatbuffer schema:%s\n", - filename.c_str()); - return false; - } - - bundled_names->push_back(schema->root_table()->name()->str()); - auto name = builder->CreateString(schema->root_table()->name()->str()); - auto data = builder->CreateVector<uint8_t>(raw_schema.data(), raw_schema.size()); - vector_map->push_back(CreateBundledSchemaMap(*builder, name, data)); - - if (opts.verbose) { - fprintf(stdout, "Bundled binary schema file:%s\n", schema->root_table()->name()->c_str()); - } - } - return true; -} - -/** - * Write generated header file containing the bundled binary schema - * data and meta data - * - * @param data: Source file data. - * @param data_len: length of data - */ -void WriteHeaderFile(FILE* fp, const uint8_t* data, size_t data_len) { - assert(fp != nullptr); - std::string delim(kDefaultNamespaceDelim); - std::string ns_string(opts.ns_name); - std::vector<std::string> namespaces; - - size_t start = 0; - size_t end = ns_string.find(delim); - while (end != std::string::npos) { - namespaces.push_back(ns_string.substr(start, end - start)); - start = end + delim.size(); - end = ns_string.find(delim, start); - } - if (start != 0 && start != std::string::npos) { - namespaces.push_back(ns_string.substr(start)); - } else if (!ns_string.empty()) { - namespaces.push_back(ns_string); - } - - std::string namespace_prefix; - for (const auto& name : namespaces) { - namespace_prefix += (name + '_'); - } - - fprintf(fp, - "// Generated file by bluetooth_flatbuffer bundler\n" - "#include <string>\n"); - for_each(namespaces.begin(), namespaces.end(), - [fp](const std::string& s) { fprintf(fp, "namespace %s {\n", s.c_str()); }); - fprintf(fp, "extern const std::string& GetBundledSchemaData();\n"); - fprintf(fp, "const unsigned char %sdata_[%zu] = {\n", namespace_prefix.c_str(), data_len); - - for (size_t i = 0; i < data_len; i++) { - fprintf(fp, " 0x%02x", data[i]); - if (i != data_len - 1) { - fprintf(fp, ","); - } - if ((i + 1) % 16 == 0) { - fprintf(fp, "\n"); - } - } - fprintf(fp, " };\n"); - fprintf(fp, "const std::string %sstring_data_(%sdata_, %sdata_ + sizeof(%sdata_));\n", - namespace_prefix.c_str(), namespace_prefix.c_str(), namespace_prefix.c_str(), - namespace_prefix.c_str()); - fprintf(fp, "const std::string& GetBundledSchemaData() { return %sstring_data_; }\n", - namespace_prefix.c_str()); - - for_each(namespaces.crbegin(), namespaces.crend(), - [fp](const std::string& s) { fprintf(fp, "} // namespace %s\n", s.c_str()); }); -} - -int ReadBundledSchema() { - const char* filename = opts.filename; - assert(filename != nullptr); - - std::string flatfile_data; - if (!flatbuffers::LoadFile(filename, helper::AsBinaryFile, &flatfile_data)) { - fprintf(stderr, "Unable to load schema data file:%s\n", filename); - return -5; - } - - auto bundle_schema = flatbuffers::GetRoot<BundledSchema>(flatfile_data.c_str()); - const flatbuffers::Vector<flatbuffers::Offset<BundledSchemaMap>>* map = bundle_schema->map(); - - fprintf(stdout, "Bundle schema title:%s\n", bundle_schema->title()->c_str()); - fprintf(stdout, "Bundle schema root_name:%s\n", bundle_schema->root_name()->c_str()); - int cnt = 0; - for (auto it = map->cbegin(); it != map->cend(); ++it, cnt++) { - fprintf(stdout, " %d name:%s schema:%s\n", cnt, it->name()->c_str(), "schema"); - } - return EXIT_SUCCESS; -} - -int WriteBundledSchema() { - const char* filename = opts.filename; - assert(filename != nullptr); - - const char* main_root_name = opts.main_root_name; - if (main_root_name == nullptr) { - fprintf(stderr, "Must specify the name of the main root name for this bundle\n"); - return EXIT_FAILURE; - } - - std::vector<std::string> bfbs_filenames; - for (int i = 0; i < opts.arg.c; i++) { - bfbs_filenames.push_back(std::string(opts.arg.v[i])); - } - if (bfbs_filenames.empty()) { - fprintf(stderr, "No bfbs files are specified to bundle\n"); - return EXIT_FAILURE; - } - - flatbuffers::FlatBufferBuilder builder(1024); - - std::list<std::string> bundled_names; - std::vector<flatbuffers::Offset<BundledSchemaMap>> vector_map; - if (!CreateBinarySchemaBundle(&builder, bfbs_filenames, &vector_map, &bundled_names)) { - fprintf(stderr, "Unable to bundle schema bfbs files\n"); - return EXIT_FAILURE; - } - - if (std::find(bundled_names.begin(), bundled_names.end(), main_root_name) == - bundled_names.end()) { - fprintf(stderr, "The main root name must match one of the bundled schema names\n"); - fprintf(stderr, " main root name:%s\n", main_root_name); - for (auto name : bundled_names) { - fprintf(stderr, " bundled schema name:%s\n", name.c_str()); - } - return EXIT_FAILURE; - } - - const char* title = opts.title; - auto schema_offset = CreateBundledSchemaDirect(builder, title, main_root_name, &vector_map); - builder.Finish(schema_offset); - - std::string final_filename(opts.gen); - final_filename.append("/"); - final_filename.append(filename); - if (!flatbuffers::SaveFile(final_filename.c_str(), (const char*)builder.GetBufferPointer(), - builder.GetSize(), helper::AsBinaryFile)) { - fprintf(stderr, "Unable to save file:%s\n", final_filename.c_str()); - return EXIT_FAILURE; - } - - std::string header(opts.gen); - header += ("/" + std::string(opts.filename) + ".cc"); - FILE* fp = fopen(header.c_str(), "w+"); - if (fp == nullptr) { - fprintf(stdout, "Unable to open for writing header file:%s\n", header.c_str()); - return EXIT_FAILURE; - } - WriteHeaderFile(fp, builder.GetBufferPointer(), builder.GetSize()); - fclose(fp); - return EXIT_SUCCESS; -} - -int Usage(int /*argc*/, char** argv) { - fprintf(stderr, - "Usage: %s [-r | -w] [-f <filename>] [-g <gen_out_path>] [-n <namespace> ] [-v] -m " - "<main_root_name> <file.bfbs " - "...>\n", - argv[0]); - fprintf(stderr, " -r|-w : Read or write a dumpsys file\n"); - fprintf(stderr, " -f : Filename bundled schema to read or write (default:%s)\n", - kDefaultBundleDataFile); - fprintf(stderr, " -g : Generated file output path\n"); - fprintf(stderr, " -n : Namespace to embed binary output bundle data source\n"); - fprintf(stderr, " -m : Name of the main root of this bundle\n"); - fprintf(stderr, " -v : Verbose printing mode\n"); - return EXIT_FAILURE; -} - -void ParseArgs(int argc, char** argv) { - int opt; - int parsed_cnt = 1; - while ((opt = getopt(argc, argv, "f:g:m:n:rt:vw")) != -1) { - parsed_cnt++; - switch (opt) { - case 'f': - opts.filename = optarg; - parsed_cnt++; - break; - case 'g': - opts.gen = optarg; - parsed_cnt++; - break; - case 'm': - opts.main_root_name = optarg; - parsed_cnt++; - break; - case 'n': - opts.ns_name = optarg; - parsed_cnt++; - break; - case 'r': - opts.read = true; - break; - case 'w': - opts.write = true; - break; - case 't': - opts.title = optarg; - parsed_cnt++; - break; - case 'v': - opts.verbose = true; - break; - default: - exit(Usage(argc, argv)); - break; - } - } - opts.arg.c = argc - parsed_cnt; - opts.arg.v = &argv[parsed_cnt]; -} diff --git a/system/gd/dumpsys/bundler/bundler.h b/system/gd/dumpsys/bundler/bundler.h deleted file mode 100644 index 9dc4b243d2..0000000000 --- a/system/gd/dumpsys/bundler/bundler.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -namespace { -constexpr char kDefaultBundleDataFile[] = "bundle_bfbs.bin"; -constexpr char kDefaultGeneratedOutputPath[] = "."; -constexpr char kDefaultNamespace[] = ""; -constexpr char kDefaultNamespaceDelim[] = "::"; -constexpr char kDefaultTitle[] = "Bundled schema tables"; -} // namespace - -struct Opts { - bool verbose{false}; - bool read{false}; - bool write{false}; - const char* filename{kDefaultBundleDataFile}; - const char* gen{kDefaultGeneratedOutputPath}; - const char* main_root_name{nullptr}; - const char* ns_name{kDefaultNamespace}; - const char* title{kDefaultTitle}; - struct { - int c{0}; - char** v{nullptr}; - } arg; -}; -extern Opts opts; - -namespace { -namespace helper { // Part of flatbuffers API -constexpr bool AsBinaryFile = true; -constexpr bool AsTextFile = false; -} // namespace helper - -} // namespace - -/** - * Read and parse a previously generated bundle data file - * - **/ -int ReadBundledSchema(); - -/** - * Generate a bundle data file from the binary flatbuffer schema - * files provided as input - * - **/ -int WriteBundledSchema(); - -/** - * Print tool usage options - */ -int Usage(int argc, char** argv); - -/** - * Parse tool usage options - */ -void ParseArgs(int argc, char** argv); diff --git a/system/gd/dumpsys/bundler/bundler_schema.fbs b/system/gd/dumpsys/bundler/bundler_schema.fbs deleted file mode 100644 index a11fb7f150..0000000000 --- a/system/gd/dumpsys/bundler/bundler_schema.fbs +++ /dev/null @@ -1,19 +0,0 @@ -// Bundled Schema -// -// Describes a collection of binary flatbuffer schema. -// - -namespace bluetooth.dumpsys; - -table BundledSchemaMap { - name:string; - data:[ubyte]; -} - -table BundledSchema { - title:string; - root_name:string; - map:[BundledSchemaMap]; -} - -root_type BundledSchema; diff --git a/system/gd/dumpsys/bundler/extract_files_and_call.py b/system/gd/dumpsys/bundler/extract_files_and_call.py deleted file mode 100755 index df0415f611..0000000000 --- a/system/gd/dumpsys/bundler/extract_files_and_call.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# Copyright 2021 Google, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at: -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -""" Get contents of given files and pass as args to remaining params. - -Example: - a.files = [ "foo", "bar" ] - b.files = [ "fizz", "buzz" ] - - extract_files_and_call.py a.files b.files -- somebin -a --set foo -c -o - - will result in this call: - - somebin -a --set foo -c -o foo bar fizz buzz - -""" - -from __future__ import print_function - -import subprocess -import sys - - -def file_to_args(filename): - """ Read file and return lines with empties removed. - """ - with open(filename, 'r') as f: - return [x.strip() for x in f.readlines() if x.strip()] - - -def main(): - file_contents = [] - args = [] - for i in range(1, len(sys.argv) - 1): - if sys.argv[i] == '--': - args = sys.argv[i + 1:] + file_contents - break - else: - file_contents.extend(file_to_args(sys.argv[i])) - - subprocess.check_call(args) - - -if __name__ == "__main__": - main() diff --git a/system/gd/dumpsys/bundler/main.cc b/system/gd/dumpsys/bundler/main.cc deleted file mode 100644 index e040ef2b8e..0000000000 --- a/system/gd/dumpsys/bundler/main.cc +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "bundler.h" -#include "bundler_schema_generated.h" - -int main(int argc, char** argv) { - ParseArgs(argc, argv); - if (opts.read) { - exit(ReadBundledSchema()); - } - if (opts.write) { - exit(WriteBundledSchema()); - } -} diff --git a/system/gd/dumpsys/bundler/test.bfbs b/system/gd/dumpsys/bundler/test.bfbs Binary files differdeleted file mode 100644 index 0dda6e54f8..0000000000 --- a/system/gd/dumpsys/bundler/test.bfbs +++ /dev/null diff --git a/system/gd/dumpsys/bundler/test.cc b/system/gd/dumpsys/bundler/test.cc deleted file mode 100644 index eebd2eacbb..0000000000 --- a/system/gd/dumpsys/bundler/test.cc +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include <gtest/gtest.h> - -#include <list> -#include <vector> - -#include "bundler.h" -#include "bundler_schema_generated.h" -#include "flatbuffers/flatbuffers.h" - -// Must be run from the same directory as the test data 'test.bfbs'. -// This is how the presubmit unit test pipeline functions. -constexpr char kTestFilename[] = "test.bfbs"; - -bool LoadBinarySchema(const char* filename, std::string* binary_schema); -bool VerifyBinarySchema(const std::vector<uint8_t>& raw_schema); -bool CreateBinarySchemaBundle( - flatbuffers::FlatBufferBuilder* builder, const std::vector<std::string>& filenames, - std::vector<flatbuffers::Offset<bluetooth::dumpsys::BundledSchemaMap>>* vector_map, - std::list<std::string>* bundled_names); -int WriteHeaderFile(FILE* fp, const uint8_t* data, size_t data_len); - -class BundlerTest : public ::testing::Test { -public: - void SetUp() override {} - - void TearDown() override {} -}; - -TEST_F(BundlerTest, LoadBinarySchema) { - std::string string_schema; - ASSERT_FALSE(LoadBinarySchema(nullptr, &string_schema)); - ASSERT_DEATH(LoadBinarySchema(kTestFilename, nullptr), ""); - ASSERT_TRUE(LoadBinarySchema(kTestFilename, &string_schema)); - ASSERT_FALSE(LoadBinarySchema("does_not_exist.bfbs", &string_schema)); -} - -TEST_F(BundlerTest, VerifyBinarySchema) { - std::string string_schema; - ASSERT_TRUE(LoadBinarySchema(kTestFilename, &string_schema)); - std::vector<uint8_t> raw_schema(string_schema.begin(), string_schema.end()); - ASSERT_TRUE(VerifyBinarySchema(raw_schema)); - - std::vector<uint8_t> bogus_raw_schema(string_schema.begin() + 1, string_schema.end()); - ASSERT_FALSE(VerifyBinarySchema(bogus_raw_schema)); -} - -TEST_F(BundlerTest, CreateBinarySchemaBundle) { - flatbuffers::FlatBufferBuilder builder; - std::vector<std::string> filenames; - std::vector<flatbuffers::Offset<bluetooth::dumpsys::BundledSchemaMap>> vector_map; - std::list<std::string> bundled_names; - ASSERT_TRUE(CreateBinarySchemaBundle(&builder, filenames, &vector_map, &bundled_names)); - ASSERT_EQ((unsigned int)0, vector_map.size()); -} - -TEST_F(BundlerTest, WriteHeaderFile) { - std::vector<uint8_t> data; - data.push_back(0x10); - data.push_back(0x11); - data.push_back(0x12); - data.push_back(0x13); - ASSERT_DEATH(WriteHeaderFile(nullptr, data.data(), data.size()), ""); - FILE* fp = fopen("/tmp/test.h", "w+"); - ASSERT_NE(fp, nullptr); - WriteHeaderFile(fp, data.data(), data.size()); - fseek(fp, 0L, SEEK_SET); - char buf[16]; - fread(buf, 1, 15, fp); - buf[12] = '\0'; - std::string s(buf); - ASSERT_EQ("// Generated", s); - fclose(fp); - unlink("/tmp/test.h"); -} diff --git a/system/gd/dumpsys/dumpsys.h b/system/gd/dumpsys/dumpsys.h deleted file mode 100644 index 6d2cafd465..0000000000 --- a/system/gd/dumpsys/dumpsys.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once -#include <string> - -namespace bluetooth { -namespace dumpsys { -const std::string& GetBundledSchemaData(); -} // namespace dumpsys -} // namespace bluetooth diff --git a/system/gd/dumpsys/dumpsys_test_data.h b/system/gd/dumpsys/dumpsys_test_data.h deleted file mode 100644 index 763d702f48..0000000000 --- a/system/gd/dumpsys/dumpsys_test_data.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once -#include <string> - -namespace testing { -const std::string& GetBundledSchemaData(); -} // namespace testing diff --git a/system/gd/dumpsys/filter.cc b/system/gd/dumpsys/filter.cc deleted file mode 100644 index 13cd2e5adf..0000000000 --- a/system/gd/dumpsys/filter.cc +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dumpsys/filter.h" - -#include <bluetooth/log.h> - -#include <memory> - -using namespace bluetooth; -using namespace dumpsys; - -class Filter { -public: - Filter(const dumpsys::ReflectionSchema& reflection_schema) - : reflection_schema_(reflection_schema) {} - - virtual ~Filter() = default; - - virtual void FilterInPlace(char* dumpsys_data) = 0; - - static std::unique_ptr<Filter> Factory(const dumpsys::ReflectionSchema& reflection_schema); - -protected: - /** - * Given both reflection field data and the populated flatbuffer table data, if any, - * filter the contents of the field based upon the filtering privacy level. - * - * Primitives and composite strings may be successfully processed at this point. - * Other composite types (e.g. structs or tables) must be expanded into the - * respective grouping of subfields. - * - * @param field The reflection field information from the bundled schema - * @param table The populated field data, if any - * - * @return true if field was filtered successfully, false otherwise. - */ - virtual bool FilterField(const reflection::Field* /* field */, flatbuffers::Table* /* table */) { - return false; - } - - /** - * Given both reflection object data and the populated flatbuffer table data, if any, - * filter the object fields based upon the filtering privacy level. - * - * @param object The reflection object information from the bundled schema - * @param table The populated field data, if any - * - */ - virtual void FilterObject(const reflection::Object* /* object */, - flatbuffers::Table* /* table */) {} - - /** - * Given both reflection field data and the populated table data, if any, - * filter the contents of the table based upon the filtering privacy level. - * - * @param schema The reflection schema information from the bundled schema - * @param table The populated field data, if any - * - */ - virtual void FilterTable(const reflection::Schema* /* schema */, - flatbuffers::Table* /* table */) {} - - const dumpsys::ReflectionSchema& reflection_schema_; -}; - -class DeveloperPrivacyFilter : public Filter { -public: - DeveloperPrivacyFilter(const dumpsys::ReflectionSchema& reflection_schema) - : Filter(reflection_schema) {} - void FilterInPlace(char* /* dumpsys_data */) override { /* Nothing to do in this mode */ } -}; - -std::unique_ptr<Filter> Filter::Factory(const dumpsys::ReflectionSchema& reflection_schema) { - return std::make_unique<DeveloperPrivacyFilter>(reflection_schema); -} - -void bluetooth::dumpsys::FilterSchema(const ReflectionSchema& reflection_schema, - std::string* dumpsys_data) { - auto filter = Filter::Factory(reflection_schema); - filter->FilterInPlace(dumpsys_data->data()); -} diff --git a/system/gd/dumpsys/filter.h b/system/gd/dumpsys/filter.h deleted file mode 100644 index b932b4c6bf..0000000000 --- a/system/gd/dumpsys/filter.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <string> - -#include "dumpsys/reflection_schema.h" - -namespace bluetooth { -namespace dumpsys { - -void FilterSchema(const ReflectionSchema& reflection_schema, std::string* dumpsys_data); - -} // namespace dumpsys -} // namespace bluetooth diff --git a/system/gd/dumpsys/filter_test.cc b/system/gd/dumpsys/filter_test.cc deleted file mode 100644 index a1678ec373..0000000000 --- a/system/gd/dumpsys/filter_test.cc +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dumpsys/filter.h" - -#include <gmock/gmock.h> -#include <gtest/gtest.h> - -#include <list> -#include <queue> - -#include "dumpsys/dumpsys_test_data.h" -#include "test_data/bar.h" -#include "test_data/baz.h" -#include "test_data/foo.h" -#include "test_data/qux.h" -#include "test_data/root.h" - -using namespace bluetooth; - -namespace testing { - -class DumpsysFilterTest : public Test { -protected: - void SetUp() override { - test_data_classes_.push_back(std::make_unique<BarTestDataClass>()); - test_data_classes_.push_back(std::make_unique<BazTestDataClass>()); - test_data_classes_.push_back(std::make_unique<FooTestDataClass>()); - test_data_classes_.push_back(std::make_unique<QuxTestDataClass>()); - } - - void TearDown() override {} - - std::list<std::unique_ptr<DumpsysTestDataClass>> test_data_classes_; - - std::string PopulateTestSchema(); -}; - -std::string DumpsysFilterTest::PopulateTestSchema() { - flatbuffers::FlatBufferBuilder fb_builder(1024); - - auto string_private = fb_builder.CreateString("String private"); - auto string_opaque = fb_builder.CreateString("String opaque"); - auto string_anonymized = fb_builder.CreateString("String anonymized"); - auto string_any = fb_builder.CreateString("String any"); - - std::queue<TableAddFunction> queue; - for (auto& test_data_class : test_data_classes_) { - queue.push(test_data_class->GetTable(fb_builder)); - } - - testing::DumpsysTestDataRootBuilder builder(fb_builder); - - builder.add_string_private(string_private); - builder.add_string_opaque(string_opaque); - builder.add_string_anonymized(string_anonymized); - builder.add_string_any(string_any); - - builder.add_int_private(123); - builder.add_int_opaque(456); - builder.add_int_anonymized(789); - builder.add_int_any(0xabc); - - while (!queue.empty()) { - queue.front()(&builder); - queue.pop(); - } - fb_builder.Finish(builder.Finish()); - - return std::string(fb_builder.GetBufferPointer(), - fb_builder.GetBufferPointer() + fb_builder.GetSize()); -} - -TEST_F(DumpsysFilterTest, filter_as_developer) { - std::string dumpsys_data = PopulateTestSchema(); - dumpsys::ReflectionSchema reflection_schema(testing::GetBundledSchemaData()); - - dumpsys::FilterSchema(reflection_schema, &dumpsys_data); - - const testing::DumpsysTestDataRoot* data_root = GetDumpsysTestDataRoot(dumpsys_data.data()); - - ASSERT_EQ("String private", data_root->string_private()->str()); - ASSERT_EQ("String opaque", data_root->string_opaque()->str()); - ASSERT_EQ("String anonymized", data_root->string_anonymized()->str()); - ASSERT_EQ("String any", data_root->string_any()->str()); - - ASSERT_EQ(123, data_root->int_private()); - ASSERT_EQ(456, data_root->int_opaque()); - ASSERT_EQ(789, data_root->int_anonymized()); - ASSERT_EQ(0xabc, data_root->int_any()); - - ASSERT_EQ(nullptr, data_root->bar_module_data()); - - const testing::FooTestSchema* foo = data_root->foo_module_data(); - - ASSERT_EQ(123, foo->foo_int_private()); - ASSERT_EQ(123, foo->foo_int_opaque()); - ASSERT_EQ(123, foo->foo_int_anonymized()); - ASSERT_EQ(123, foo->foo_int_any()); - ASSERT_STREQ("123", foo->foo_int_string()->c_str()); - - ASSERT_FLOAT_EQ(123.456, foo->foo_float_private()); - ASSERT_FLOAT_EQ(123.456, foo->foo_float_opaque()); - ASSERT_FLOAT_EQ(123.456, foo->foo_float_anonymized()); - ASSERT_FLOAT_EQ(123.456, foo->foo_float_any()); - ASSERT_STREQ("123.456", foo->foo_float_string()->c_str()); -} - -} // namespace testing diff --git a/system/gd/dumpsys/internal/filter_internal.cc b/system/gd/dumpsys/internal/filter_internal.cc deleted file mode 100644 index 2db2878f95..0000000000 --- a/system/gd/dumpsys/internal/filter_internal.cc +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dumpsys/internal/filter_internal.h" - -#include <bluetooth/log.h> - -#include <algorithm> -#include <string> - -#include "flatbuffers/flatbuffers.h" -#include "flatbuffers/idl.h" - -#define DBG 0 - -using namespace bluetooth; -using namespace dumpsys; - -constexpr flatbuffers::voffset_t kErasedFromTable = 0; -constexpr bool kFieldIsNotPopulated = true; -constexpr bool kFieldHasBeenFiltered = true; -constexpr bool kFieldContinueFiltering = false; - -void internal::ScrubFromTable(flatbuffers::Table* table, flatbuffers::voffset_t field_offset) { - log::assert_that(table != nullptr, "assert failed: table != nullptr"); - uint8_t* vtable = const_cast<uint8_t*>(table->GetVTable()); - vtable[field_offset] = kErasedFromTable; -} - -void internal::ReplaceInString(flatbuffers::String* string, int c) { - uint8_t* p = const_cast<uint8_t*>(string->Data()); - memset(p, c, string->size()); -} - -void internal::RandomizeInString(flatbuffers::String* string) { - std::size_t hash = std::hash<std::string>{}(string->str()); - std::string hashed_string = std::to_string(hash); - ReplaceInString(string, ' '); - size_t len = std::min(static_cast<size_t>(string->size()), hashed_string.size()); - uint8_t* p = const_cast<uint8_t*>(string->Data()); - memcpy(p, hashed_string.c_str(), len); -} - -const char* internal::PrivacyLevelName(PrivacyLevel privacy_level) { - switch (privacy_level) { - case kPrivate: - return "Private"; - break; - case kOpaque: - return "Opaque"; - break; - case kAnonymized: - return "Anonymized"; - break; - case kAny: - return "Any"; - break; - } -} -internal::PrivacyLevel internal::GetPrivacyLevelAttribute(const std::string& string) { - if (string == "Any") { - return kAny; - } else if (string == "Anonymized") { - return kAnonymized; - } else if (string == "Opaque") { - return kOpaque; - } else if (string == "Private") { - return kPrivate; - } - return kDefaultPrivacyLevel; -} - -internal::PrivacyLevel internal::FindFieldPrivacyLevel(const reflection::Field& field) { - PrivacyLevel privacy_level = kDefaultPrivacyLevel; - - if (field.attributes() != nullptr) { - auto key = field.attributes()->LookupByKey(kPrivacyAttributeKeyword); - if (key != nullptr) { - privacy_level = internal::GetPrivacyLevelAttribute(key->value()->str()); - } - } - return privacy_level; -} - -const reflection::Object* internal::FindReflectionObject( - const flatbuffers::Vector<flatbuffers::Offset<reflection::Object>>* objects, - const flatbuffers::String* name) { - log::assert_that(objects != nullptr, "assert failed: objects != nullptr"); - log::assert_that(name != nullptr, "assert failed: name != nullptr"); - for (auto it = objects->cbegin(); it != objects->cend(); ++it) { - if (it->name()->str() == name->str()) { - return *it; - } - } - return nullptr; -} - -bool internal::FilterTypeBool(const reflection::Field& field, flatbuffers::Table* table, - PrivacyLevel privacy_level) { - log::assert_that(table != nullptr, "assert failed: table != nullptr"); - - const bool default_val = flatbuffers::GetFieldDefaultI<int8_t>(field); - flatbuffers::voffset_t field_offset = field.offset(); - - // boolean privacy levels are simpler. - switch (privacy_level) { - case kPrivate: - case kOpaque: - case kAnonymized: - flatbuffers::SetField<int8_t>(table, field, default_val); - internal::ScrubFromTable(table, field_offset); - break; - default: - case kAny: - break; - } - return kFieldHasBeenFiltered; -} - -bool internal::FilterTypeInteger(const reflection::Field& field, flatbuffers::Table* table, - PrivacyLevel privacy_level) { - log::assert_that(table != nullptr, "assert failed: table != nullptr"); - log::assert_that(flatbuffers::IsInteger(field.type()->base_type()), - "assert failed: flatbuffers::IsInteger(field.type()->base_type())"); - - int32_t default_val = flatbuffers::GetFieldDefaultI<int32_t>(field); - flatbuffers::voffset_t field_offset = field.offset(); - [[maybe_unused]] int32_t val = table->GetField<int32_t>(field_offset, default_val); - - switch (privacy_level) { - case kPrivate: - flatbuffers::SetField<int32_t>(table, field, default_val); - internal::ScrubFromTable(table, field_offset); - break; - case kOpaque: - flatbuffers::SetField<int32_t>(table, field, default_val); - break; - case kAnonymized: { - auto target_field = flatbuffers::GetFieldI<int32_t>(*table, field); - int32_t new_val = - static_cast<int32_t>(std::hash<std::string>{}(std::to_string(target_field))); - flatbuffers::SetField<int32_t>(table, field, new_val); - } break; - default: - case kAny: - break; - } - - if (DBG) { - log::info("Integer Field_name:{} privacy_level:{} old_value:{} / 0x{:x} ==> new_value:{}", - field.name()->c_str(), PrivacyLevelName(privacy_level), val, val, - table->GetField<int32_t>(field_offset, default_val)); - } - return kFieldHasBeenFiltered; -} - -bool internal::FilterTypeFloat(const reflection::Field& field, flatbuffers::Table* table, - PrivacyLevel privacy_level) { - log::assert_that(table != nullptr, "assert failed: table != nullptr"); - log::assert_that(flatbuffers::IsFloat(field.type()->base_type()), - "assert failed: flatbuffers::IsFloat(field.type()->base_type())"); - - float default_val = flatbuffers::GetFieldDefaultI<float>(field); - flatbuffers::voffset_t field_offset = field.offset(); - [[maybe_unused]] float val = table->GetField<float>(field_offset, default_val); - switch (privacy_level) { - case kPrivate: - flatbuffers::SetField<float>(table, field, default_val); - internal::ScrubFromTable(table, field_offset); - break; - case kOpaque: - flatbuffers::SetField<float>(table, field, default_val); - break; - case kAnonymized: { - auto target_field = flatbuffers::GetFieldF<float>(*table, field); - int32_t new_val = static_cast<float>(std::hash<std::string>{}(std::to_string(target_field))); - flatbuffers::SetField<float>(table, field, new_val); - } break; - default: - case kAny: - break; - } - if (DBG) { - log::info("Float Field_name:{} privacy_level:{} old_value:{:f} ==> new_value:{:f}", - field.name()->c_str(), PrivacyLevelName(privacy_level), val, - table->GetField<float>(field_offset, default_val)); - } - return kFieldHasBeenFiltered; -} - -bool internal::FilterTypeLong(const reflection::Field& field, flatbuffers::Table* table, - PrivacyLevel privacy_level) { - log::assert_that(table != nullptr, "assert failed: table != nullptr"); - - const int64_t default_val = flatbuffers::GetFieldDefaultI<int64_t>(field); - flatbuffers::voffset_t field_offset = field.offset(); - - switch (privacy_level) { - case kPrivate: - flatbuffers::SetField<int64_t>(table, field, default_val); - internal::ScrubFromTable(table, field_offset); - break; - case kOpaque: - flatbuffers::SetField<int64_t>(table, field, default_val); - break; - case kAnonymized: { - auto target_field = flatbuffers::GetFieldI<int64_t>(*table, field); - int64_t new_val = - static_cast<int64_t>(std::hash<std::string>{}(std::to_string(target_field))); - flatbuffers::SetField<int64_t>(table, field, new_val); - } break; - default: - case kAny: - break; - } - return kFieldHasBeenFiltered; -} - -bool internal::FilterTypeString(const reflection::Field& field, flatbuffers::Table* table, - PrivacyLevel privacy_level) { - log::assert_that(table != nullptr, "assert failed: table != nullptr"); - log::assert_that(field.type()->base_type() == reflection::BaseType::String, - "assert failed: field.type()->base_type() == reflection::BaseType::String"); - - flatbuffers::voffset_t field_offset = field.offset(); - - const flatbuffers::String* string = flatbuffers::GetFieldS(*table, field); - if (string == nullptr) { - return kFieldIsNotPopulated; - // Field is not populated - } - log::assert_that(string != nullptr, "assert failed: string != nullptr"); - flatbuffers::String* mutable_string = const_cast<flatbuffers::String*>(string); - - [[maybe_unused]] std::string old_string(string->str()); - switch (privacy_level) { - case kPrivate: - internal::ReplaceInString(mutable_string, '*'); - internal::ScrubFromTable(table, field_offset); - break; - case kOpaque: - internal::ReplaceInString(mutable_string, '*'); - break; - case kAnonymized: - internal::RandomizeInString(mutable_string); - break; - default: - case kAny: - break; - } - if (DBG) { - log::info("Field_name:{} size:{} privacy_level:{} old_string:{} ==> new_string:{}", - field.name()->c_str(), string->size(), PrivacyLevelName(privacy_level), old_string, - string->c_str()); - } - return kFieldHasBeenFiltered; -} - -bool internal::FilterTypeStruct(const reflection::Field& field, flatbuffers::Table* table, - PrivacyLevel privacy_level) { - log::assert_that(table != nullptr, "assert failed: table != nullptr"); - log::assert_that(!flatbuffers::IsScalar(field.type()->base_type()), - "assert failed: !flatbuffers::IsScalar(field.type()->base_type())"); - - flatbuffers::voffset_t field_offset = field.offset(); - - if (privacy_level != kAny) { - flatbuffers::SetFieldT(table, field, nullptr); - internal::ScrubFromTable(table, field_offset); - if (DBG) { - log::info("Table Removing field name:{} privacy_level:{}", field.name()->c_str(), - PrivacyLevelName(privacy_level)); - } - } - return kFieldContinueFiltering; -} diff --git a/system/gd/dumpsys/internal/filter_internal.h b/system/gd/dumpsys/internal/filter_internal.h deleted file mode 100644 index a18575c72f..0000000000 --- a/system/gd/dumpsys/internal/filter_internal.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include <base/strings/stringprintf.h> - -#include <string> - -#include "flatbuffers/flatbuffers.h" -#include "flatbuffers/idl.h" -#include "macros.h" - -namespace bluetooth { -namespace dumpsys { -namespace internal { - -constexpr char kPrivacyAttributeKeyword[] = "privacy"; - -enum PrivacyLevel { - kPrivate = 0, - kOpaque = 1, - kAnonymized = 2, - kAny = 4, - kDefaultPrivacyLevel = kPrivate, -}; - -/** - * Remove the field offset from flatbuffer table eliminating ability to - * access value. - * - * @param table Table under consideration for field removeal - * @param field_offset Virtual offset of field into table. - */ -void ScrubFromTable(flatbuffers::Table* table, flatbuffers::voffset_t field_offset); - -/** - * Overwrite ihe contents of flatbuffer string with the integer value proviced. - * The entire size of the string will be set to the value provided. - * - * @param string Flatbuffer string under consideration for content changing. - * @param value Value to overwrite the string contents. - */ -void ReplaceInString(flatbuffers::String* string, int value); - -/** - * Overwrite the contents of flatbuffer string with a hashed value. - * The portion of the string greater than the hash value will be set to SPACE. - * If the string is not large enough for the entire hash value, the hash - * value will be truncated to the size of the string. - * - * @param string Flatbuffer string under consideration for content changing. - */ -void RandomizeInString(flatbuffers::String* string); - -/** - * Returns the privacy level name corresponding to the axtual numeric level. - * - * @param privacy_level PrivacyLevel - * - * @return Name of privacy level. - */ -const char* PrivacyLevelName(PrivacyLevel privacy_level); - -/** - * Returns the privacy level for the given field. If there is no explicitly - * privacy level for this field, the default privacy level is returned. - * - * @param field The reflection field for the schema - * - * @return Privacy level enumeration value - */ -PrivacyLevel FindFieldPrivacyLevel(const reflection::Field& field); - -/** - * Returns the privacy level for given privacy level keyword name. - * If the privacy level for this field, the default privacy level is returned. - * - * @param name The privacy level name. - * - * @return Privacy level enumeration value. - */ -PrivacyLevel GetPrivacyLevelAttribute(const std::string& name); - -/** - * Find a the reflection object that corresponds to the name provided. - * Returns nullptr is not found. - * - * @param objects Vector container of flatbuffer objects - * @param name Flatbuffer string name to search - * - * @return Reflection object if found, nullptr otherwise. - */ -const reflection::Object* FindReflectionObject( - const flatbuffers::Vector<flatbuffers::Offset<reflection::Object>>* objects, - const flatbuffers::String* name); - -/** - * Process and filter the respective data types. - * - * @param field The reflection field schema. - * @param table The mutable table data corresponding to the schema. - * @param privacy_level The privacy level in which to filter the data. - * - * @return true if successfully filtered, false otherwise. - */ -bool FilterTypeBool(const reflection::Field& field, flatbuffers::Table* table, - PrivacyLevel privacy_level); -bool FilterTypeFloat(const reflection::Field& field, flatbuffers::Table* table, - PrivacyLevel privacy_level); -bool FilterTypeInteger(const reflection::Field& field, flatbuffers::Table* table, - PrivacyLevel privacy_level); -bool FilterTypeLong(const reflection::Field& field, flatbuffers::Table* table, - PrivacyLevel privacy_level); -bool FilterTypeString(const reflection::Field& field, flatbuffers::Table* table, - PrivacyLevel privacy_level); -bool FilterTypeStruct(const reflection::Field& field, flatbuffers::Table* table, - PrivacyLevel privacy_level); - -inline std::string FlatbufferTypeText(const flatbuffers::BaseType& type) { - switch (type) { - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_NONE); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_BOOL); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_CHAR); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_UCHAR); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_SHORT); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_USHORT); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_INT); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_UINT); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_LONG); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_ULONG); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_FLOAT); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_DOUBLE); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_STRING); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_VECTOR); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_STRUCT); - CASE_RETURN_TEXT(flatbuffers::BASE_TYPE_UNION); - default: - return base::StringPrintf("UNKNOWN[%d]", (int)type); - } -} - -} // namespace internal -} // namespace dumpsys -} // namespace bluetooth diff --git a/system/gd/dumpsys/internal/filter_internal_test.cc b/system/gd/dumpsys/internal/filter_internal_test.cc deleted file mode 100644 index 38f3481f0c..0000000000 --- a/system/gd/dumpsys/internal/filter_internal_test.cc +++ /dev/null @@ -1,424 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dumpsys/internal/filter_internal.h" - -#include <gmock/gmock.h> -#include <gtest/gtest.h> - -#include "dumpsys/internal/test_data/float_bfbs.h" -#include "dumpsys/internal/test_data/float_generated.h" -#include "dumpsys/internal/test_data/integer_bfbs.h" -#include "dumpsys/internal/test_data/integer_generated.h" -#include "dumpsys/internal/test_data/string_bfbs.h" -#include "dumpsys/internal/test_data/string_generated.h" -#include "dumpsys/internal/test_data/struct_bfbs.h" -#include "dumpsys/internal/test_data/struct_generated.h" - -namespace testing { - -class DumpsysFilterInternalTest : public Test { -protected: - void SetUp() override {} - void TearDown() override {} - - flatbuffers::Table* GetMutableTable() const { - return flatbuffers::GetMutableRoot<flatbuffers::Table>(fb_builder_.GetBufferPointer()); - } - - void ParseReflectionSchema(unsigned char* bfbs, unsigned int bfbs_len) { - ASSERT_TRUE(reflection_schema_.empty()); - reflection_schema_ = std::vector<uint8_t>(bfbs, bfbs + bfbs_len); - flatbuffers::Verifier verifier(reflection_schema_.data(), reflection_schema_.size()); - ASSERT_TRUE(reflection::VerifySchemaBuffer(verifier)); - schema_ = reflection::GetSchema(reflection_schema_.data()); - ASSERT_TRUE(schema_ != nullptr); - } - - const reflection::Schema* schema_{nullptr}; - flatbuffers::FlatBufferBuilder fb_builder_ = flatbuffers::FlatBufferBuilder(1024); - -private: - std::vector<uint8_t> reflection_schema_; -}; - -class DumpsysFilterInternalIntegerTest : public DumpsysFilterInternalTest { -protected: - void SetUp() override { this->ParseReflectionSchema(integer_bfbs, integer_bfbs_len); } - - const testing::TestTableInteger* CreateInteger(int32_t value) { - TestTableIntegerBuilder builder(fb_builder_); - builder.add_test_int(value); - fb_builder_.Finish(builder.Finish()); - return GetTestTableInteger(fb_builder_.GetBufferPointer()); - } -}; - -class DumpsysFilterInternalFloatTest : public DumpsysFilterInternalTest { -protected: - void SetUp() override { this->ParseReflectionSchema(float_bfbs, float_bfbs_len); } - - const testing::TestTableFloat* CreateFloat(double value) { - TestTableFloatBuilder builder(fb_builder_); - builder.add_test_float(value); - fb_builder_.Finish(builder.Finish()); - return GetTestTableFloat(fb_builder_.GetBufferPointer()); - } -}; - -class DumpsysFilterInternalStringTest : public DumpsysFilterInternalTest { -protected: - void SetUp() override { this->ParseReflectionSchema(string_bfbs, string_bfbs_len); } - - const testing::TestTableString* CreateString(std::string string) { - auto test_string = fb_builder_.CreateString(string); - TestTableStringBuilder builder(fb_builder_); - builder.add_test_string(test_string); - fb_builder_.Finish(builder.Finish()); - return GetTestTableString(fb_builder_.GetBufferPointer()); - } -}; - -class DumpsysFilterInternalStructTest : public DumpsysFilterInternalTest { -protected: - void SetUp() override { this->ParseReflectionSchema(struct_bfbs, struct_bfbs_len); } - - flatbuffers::Offset<TestSubTable> CreateSubTable(int val) { - TestSubTableBuilder builder(fb_builder_); - builder.add_placeholder(val); - return builder.Finish(); - } - - const testing::TestTableStruct* CreateStruct(int val) { - auto sub_table = CreateSubTable(val); - - TestTableStructBuilder builder(fb_builder_); - builder.add_sub_table(sub_table); - fb_builder_.Finish(builder.Finish()); - return GetTestTableStruct(fb_builder_.GetBufferPointer()); - } -}; - -TEST_F(DumpsysFilterInternalIntegerTest, filter_type_integer_any) { - const testing::TestTableInteger* test_table = CreateInteger(123); - ASSERT_EQ(123, test_table->test_int()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeInteger( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kAny); - } - ASSERT_EQ(123, test_table->test_int()); -} - -TEST_F(DumpsysFilterInternalIntegerTest, filter_type_integer_anonymized) { - const testing::TestTableInteger* test_table = CreateInteger(123); - ASSERT_EQ(123, test_table->test_int()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeInteger( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kAnonymized); - } - ASSERT_NE(123, test_table->test_int()); -} - -TEST_F(DumpsysFilterInternalIntegerTest, filter_type_integer_opaque) { - const testing::TestTableInteger* test_table = CreateInteger(123); - ASSERT_EQ(123, test_table->test_int()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeInteger( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kOpaque); - } - ASSERT_EQ(0, test_table->test_int()); -} - -TEST_F(DumpsysFilterInternalIntegerTest, filter_type_integer_privacy) { - const testing::TestTableInteger* test_table = CreateInteger(123); - ASSERT_EQ(123, test_table->test_int()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeInteger( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kPrivate); - } - ASSERT_EQ(0, test_table->test_int()); -} - -TEST_F(DumpsysFilterInternalFloatTest, filter_type_float_any) { - const testing::TestTableFloat* test_table = CreateFloat(1.23); - ASSERT_FLOAT_EQ(1.23, test_table->test_float()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeFloat(**it, table, - bluetooth::dumpsys::internal::PrivacyLevel::kAny); - } - ASSERT_FLOAT_EQ(1.23, test_table->test_float()); -} - -TEST_F(DumpsysFilterInternalFloatTest, filter_type_float_anonymized) { - const testing::TestTableFloat* test_table = CreateFloat(1.23); - ASSERT_FLOAT_EQ(1.23, test_table->test_float()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeFloat( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kAnonymized); - } - ASSERT_THAT(test_table->test_float(), Not(FloatEq(1.23))); -} - -TEST_F(DumpsysFilterInternalFloatTest, filter_type_float_opaque) { - const testing::TestTableFloat* test_table = CreateFloat(1.23); - ASSERT_FLOAT_EQ(1.23, test_table->test_float()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeFloat( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kOpaque); - } - ASSERT_FLOAT_EQ(0.0, test_table->test_float()); -} - -TEST_F(DumpsysFilterInternalFloatTest, filter_type_float_private) { - const testing::TestTableFloat* test_table = CreateFloat(1.23); - ASSERT_FLOAT_EQ(1.23, test_table->test_float()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeFloat( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kPrivate); - } - ASSERT_FLOAT_EQ(0.0, test_table->test_float()); -} - -TEST_F(DumpsysFilterInternalStringTest, filter_type_string_any) { - const testing::TestTableString* test_table = CreateString("This is a string"); - ASSERT_STREQ("This is a string", test_table->test_string()->c_str()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeString( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kAny); - } - ASSERT_STREQ("This is a string", test_table->test_string()->c_str()); -} - -TEST_F(DumpsysFilterInternalStringTest, filter_type_string_anonymous) { - const testing::TestTableString* test_table = CreateString("This is a string"); - ASSERT_STREQ("This is a string", test_table->test_string()->c_str()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeString( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kAnonymized); - } - ASSERT_NE("This is a string", test_table->test_string()->c_str()); -} - -TEST_F(DumpsysFilterInternalStringTest, filter_type_string_anonymous_small) { - const testing::TestTableString* test_table = CreateString("A"); - ASSERT_STREQ("A", test_table->test_string()->c_str()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeString( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kAnonymized); - } - ASSERT_NE("A", test_table->test_string()->c_str()); -} - -TEST_F(DumpsysFilterInternalStringTest, filter_type_string_anonymous_large) { - const testing::TestTableString* test_table = - CreateString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); - ASSERT_STREQ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", - test_table->test_string()->c_str()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeString( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kAnonymized); - } - ASSERT_NE("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", - test_table->test_string()->c_str()); -} - -TEST_F(DumpsysFilterInternalStringTest, filter_type_string_opaque) { - const testing::TestTableString* test_table = CreateString("This is a string"); - ASSERT_STREQ("This is a string", test_table->test_string()->c_str()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeString( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kOpaque); - } - - std::string opaque_expected(strlen("This is a string"), '*'); - ASSERT_STREQ(opaque_expected.c_str(), test_table->test_string()->c_str()); -} - -TEST_F(DumpsysFilterInternalStringTest, filter_type_string_private) { - const testing::TestTableString* test_table = CreateString("This is a string"); - ASSERT_STREQ("This is a string", test_table->test_string()->c_str()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeString( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kPrivate); - } - ASSERT_EQ(nullptr, test_table->test_string()); -} - -TEST_F(DumpsysFilterInternalStringTest, filter_type_string_private_small) { - const testing::TestTableString* test_table = CreateString("A"); - ASSERT_STREQ("A", test_table->test_string()->c_str()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeString( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kPrivate); - } - ASSERT_EQ(nullptr, test_table->test_string()); -} - -TEST_F(DumpsysFilterInternalStructTest, filter_type_struct_any) { - const testing::TestTableStruct* test_table = CreateStruct(456); - ASSERT_EQ(456, test_table->sub_table()->placeholder()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeStruct( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kAny); - } - ASSERT_EQ(456, test_table->sub_table()->placeholder()); -} - -TEST_F(DumpsysFilterInternalStructTest, filter_type_struct_anonymous) { - const testing::TestTableStruct* test_table = CreateStruct(456); - ASSERT_EQ(456, test_table->sub_table()->placeholder()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeStruct( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kAnonymized); - } - ASSERT_EQ(nullptr, test_table->sub_table()); -} - -TEST_F(DumpsysFilterInternalStructTest, filter_type_struct_opaque) { - const testing::TestTableStruct* test_table = CreateStruct(456); - ASSERT_EQ(456, test_table->sub_table()->placeholder()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeStruct( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kOpaque); - } - ASSERT_EQ(nullptr, test_table->sub_table()); -} - -TEST_F(DumpsysFilterInternalStructTest, filter_type_struct_private) { - const testing::TestTableStruct* test_table = CreateStruct(456); - ASSERT_EQ(456, test_table->sub_table()->placeholder()); - - flatbuffers::Table* table = GetMutableTable(); - - const reflection::Object* object = schema_->root_table(); - ASSERT_TRUE(object != nullptr); - - for (auto it = object->fields()->cbegin(); it != object->fields()->cend(); ++it) { - bluetooth::dumpsys::internal::FilterTypeStruct( - **it, table, bluetooth::dumpsys::internal::PrivacyLevel::kPrivate); - } - ASSERT_EQ(nullptr, test_table->sub_table()); -} - -} // namespace testing diff --git a/system/gd/dumpsys/internal/test_data/float.bfbs b/system/gd/dumpsys/internal/test_data/float.bfbs Binary files differdeleted file mode 100644 index 547ecd93bf..0000000000 --- a/system/gd/dumpsys/internal/test_data/float.bfbs +++ /dev/null diff --git a/system/gd/dumpsys/internal/test_data/float.fbs b/system/gd/dumpsys/internal/test_data/float.fbs deleted file mode 100644 index 2f832e685c..0000000000 --- a/system/gd/dumpsys/internal/test_data/float.fbs +++ /dev/null @@ -1,7 +0,0 @@ -namespace testing; - -table TestTableFloat { - test_float:float; -} - -root_type TestTableFloat; diff --git a/system/gd/dumpsys/internal/test_data/float_bfbs.h b/system/gd/dumpsys/internal/test_data/float_bfbs.h deleted file mode 100644 index 06488b95a8..0000000000 --- a/system/gd/dumpsys/internal/test_data/float_bfbs.h +++ /dev/null @@ -1,18 +0,0 @@ -unsigned char float_bfbs[] = { - 0x18, 0x00, 0x00, 0x00, 0x42, 0x46, 0x42, 0x53, 0x10, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x08, - 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 0x18, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, - 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x3c, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x14, 0x00, 0x14, 0x00, 0x04, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x14, - 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x2c, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, - 0x67, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x6c, 0x6f, 0x61, - 0x74, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x06, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, - 0x00, 0x10, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x01, 0x00, 0x00, 0x00, 0x0a, - 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x00, 0x00}; -unsigned int float_bfbs_len = 240; diff --git a/system/gd/dumpsys/internal/test_data/integer.bfbs b/system/gd/dumpsys/internal/test_data/integer.bfbs Binary files differdeleted file mode 100644 index 110c65dbee..0000000000 --- a/system/gd/dumpsys/internal/test_data/integer.bfbs +++ /dev/null diff --git a/system/gd/dumpsys/internal/test_data/integer.fbs b/system/gd/dumpsys/internal/test_data/integer.fbs deleted file mode 100644 index b8a5569eb2..0000000000 --- a/system/gd/dumpsys/internal/test_data/integer.fbs +++ /dev/null @@ -1,7 +0,0 @@ -namespace testing; - -table TestTableInteger { - test_int:int; -} - -root_type TestTableInteger; diff --git a/system/gd/dumpsys/internal/test_data/integer_bfbs.h b/system/gd/dumpsys/internal/test_data/integer_bfbs.h deleted file mode 100644 index 7f6ba61d7e..0000000000 --- a/system/gd/dumpsys/internal/test_data/integer_bfbs.h +++ /dev/null @@ -1,19 +0,0 @@ -unsigned char integer_bfbs[] = { - 0x18, 0x00, 0x00, 0x00, 0x42, 0x46, 0x42, 0x53, 0x10, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x08, - 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 0x18, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, - 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x3c, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x14, 0x00, 0x14, 0x00, 0x04, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x14, - 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x30, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, - 0x67, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x49, 0x6e, 0x74, 0x65, - 0x67, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x08, 0x00, 0x0c, 0x00, - 0x00, 0x00, 0x06, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, - 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, - 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x6e, 0x74, - 0x00, 0x00, 0x00, 0x00}; -unsigned int integer_bfbs_len = 244; diff --git a/system/gd/dumpsys/internal/test_data/mkfiles b/system/gd/dumpsys/internal/test_data/mkfiles deleted file mode 100644 index 95577d05d2..0000000000 --- a/system/gd/dumpsys/internal/test_data/mkfiles +++ /dev/null @@ -1,9 +0,0 @@ -../../../../../out/host/linux-x86/bin/flatc -b --schema --cpp string.fbs -xxd -i string.bfbs > string_bfbs.h -../../../../../out/host/linux-x86/bin/flatc -b --schema --cpp integer.fbs -xxd -i integer.bfbs > integer_bfbs.h -../../../../../out/host/linux-x86/bin/flatc -b --schema --cpp float.fbs -xxd -i float.bfbs > float_bfbs.h -../../../../../out/host/linux-x86/bin/flatc -b --schema --cpp struct.fbs -xxd -i struct.bfbs > struct_bfbs.h - diff --git a/system/gd/dumpsys/internal/test_data/root.h b/system/gd/dumpsys/internal/test_data/root.h deleted file mode 100644 index 5830ee8cf0..0000000000 --- a/system/gd/dumpsys/internal/test_data/root.h +++ /dev/null @@ -1,17 +0,0 @@ - - -#pragma once - -#include "flatbuffers/flatbuffers.h" -#include "root_generated.h" - -using TableAddFunction = std::function<void(testing::DumpsysTestDataRootBuilder* root_builder)>; - -namespace testing { - -struct DumpsysTestDataClass { - virtual TableAddFunction GetTable(flatbuffers::FlatBufferBuilder& builder) = 0; - virtual ~DumpsysTestDataClass() = default; -}; - -} // namespace testing diff --git a/system/gd/dumpsys/internal/test_data/string.bfbs b/system/gd/dumpsys/internal/test_data/string.bfbs Binary files differdeleted file mode 100644 index a414802b43..0000000000 --- a/system/gd/dumpsys/internal/test_data/string.bfbs +++ /dev/null diff --git a/system/gd/dumpsys/internal/test_data/string.fbs b/system/gd/dumpsys/internal/test_data/string.fbs deleted file mode 100644 index ba4f2fdfc9..0000000000 --- a/system/gd/dumpsys/internal/test_data/string.fbs +++ /dev/null @@ -1,7 +0,0 @@ -namespace testing; - -table TestTableString { - test_string:string; -} - -root_type TestTableString; diff --git a/system/gd/dumpsys/internal/test_data/string_bfbs.h b/system/gd/dumpsys/internal/test_data/string_bfbs.h deleted file mode 100644 index 1b241352ce..0000000000 --- a/system/gd/dumpsys/internal/test_data/string_bfbs.h +++ /dev/null @@ -1,16 +0,0 @@ -unsigned char string_bfbs[] = { - 0x18, 0x00, 0x00, 0x00, 0x42, 0x46, 0x42, 0x53, 0x10, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x08, - 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 0x18, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, - 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x34, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x04, 0x00, - 0x08, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x08, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, - 0x17, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x2e, 0x54, 0x65, 0x73, - 0x74, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x00, 0x0c, 0x00, - 0x12, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x04, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, - 0x08, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x0b, 0x00, 0x00, - 0x00, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x00}; -unsigned int string_bfbs_len = 208; diff --git a/system/gd/dumpsys/internal/test_data/struct.bfbs b/system/gd/dumpsys/internal/test_data/struct.bfbs Binary files differdeleted file mode 100644 index c3ecca8841..0000000000 --- a/system/gd/dumpsys/internal/test_data/struct.bfbs +++ /dev/null diff --git a/system/gd/dumpsys/internal/test_data/struct.fbs b/system/gd/dumpsys/internal/test_data/struct.fbs deleted file mode 100644 index 83d4974f9b..0000000000 --- a/system/gd/dumpsys/internal/test_data/struct.fbs +++ /dev/null @@ -1,11 +0,0 @@ -namespace testing; - -table TestSubTable { - placeholder:int; -} - -table TestTableStruct{ - sub_table:TestSubTable; -} - -root_type TestTableStruct; diff --git a/system/gd/dumpsys/internal/test_data/struct_bfbs.h b/system/gd/dumpsys/internal/test_data/struct_bfbs.h deleted file mode 100644 index 5df51a98f4..0000000000 --- a/system/gd/dumpsys/internal/test_data/struct_bfbs.h +++ /dev/null @@ -1,29 +0,0 @@ -unsigned char struct_bfbs[] = { - 0x18, 0x00, 0x00, 0x00, 0x42, 0x46, 0x42, 0x53, 0x10, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x08, - 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 0x18, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, - 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x2c, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6c, 0xff, - 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xac, - 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, - 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x54, 0x61, 0x62, - 0x6c, 0x65, 0x53, 0x74, 0x72, 0x75, 0x63, 0x74, 0x00, 0x1c, 0x00, 0x10, 0x00, 0x08, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, - 0x28, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x07, 0x00, 0x00, - 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x73, - 0x75, 0x62, 0x5f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x14, 0x00, 0x14, 0x00, - 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, - 0x00, 0x14, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, - 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x74, 0x65, 0x73, 0x74, - 0x69, 0x6e, 0x67, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x53, 0x75, 0x62, 0x54, 0x61, 0x62, 0x6c, - 0x65, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x14, - 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x08, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, 0x00, 0x00, - 0x00, 0x0b, 0x00, 0x00, 0x00, 0x70, 0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, - 0x72, 0x00}; -unsigned int struct_bfbs_len = 392; diff --git a/system/gd/dumpsys/reflection_schema.cc b/system/gd/dumpsys/reflection_schema.cc deleted file mode 100644 index b2d79313eb..0000000000 --- a/system/gd/dumpsys/reflection_schema.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dumpsys/reflection_schema.h" - -#include <bluetooth/log.h> - -#include <string> - -#include "bundler_schema_generated.h" -#include "flatbuffers/flatbuffers.h" -#include "flatbuffers/idl.h" - -using namespace bluetooth; - -dumpsys::ReflectionSchema::ReflectionSchema(const std::string& pre_bundled_schema) - : pre_bundled_schema_(pre_bundled_schema) { - bundled_schema_ = - flatbuffers::GetRoot<bluetooth::dumpsys::BundledSchema>(pre_bundled_schema_.data()); - log::assert_that(bundled_schema_ != nullptr, "assert failed: bundled_schema_ != nullptr"); -} - -int dumpsys::ReflectionSchema::GetNumberOfBundledSchemas() const { - return bundled_schema_->map()->size(); -} - -std::string dumpsys::ReflectionSchema::GetTitle() const { return bundled_schema_->title()->str(); } - -std::string dumpsys::ReflectionSchema::GetRootName() const { - return bundled_schema_->root_name()->str(); -} - -const reflection::Schema* dumpsys::ReflectionSchema::GetRootReflectionSchema() const { - return FindInReflectionSchema(GetRootName()); -} - -const reflection::Schema* dumpsys::ReflectionSchema::FindInReflectionSchema( - const std::string& name) const { - const flatbuffers::Vector<flatbuffers::Offset<bluetooth::dumpsys::BundledSchemaMap>>* map = - bundled_schema_->map(); - - for (auto it = map->cbegin(); it != map->cend(); ++it) { - if (it->name()->str() == name) { - flatbuffers::Verifier verifier(reinterpret_cast<const uint8_t*>(it->data()->Data()), - it->data()->size()); - if (!reflection::VerifySchemaBuffer(verifier)) { - log::warn("Unable to verify schema buffer name:{}", name); - return nullptr; - } - return reflection::GetSchema(it->data()->Data()); - } - } - return nullptr; -} - -void dumpsys::ReflectionSchema::PrintReflectionSchema() const { - const flatbuffers::Vector<flatbuffers::Offset<bluetooth::dumpsys::BundledSchemaMap>>* map = - bundled_schema_->map(); - log::info("Bundled schema title:{} root_name:{}", bundled_schema_->title()->c_str(), - bundled_schema_->root_name()->c_str()); - for (auto it = map->cbegin(); it != map->cend(); ++it) { - log::info("schema:{}", it->name()->c_str()); - } -} - -bool dumpsys::ReflectionSchema::VerifyReflectionSchema() const { - const flatbuffers::Vector<flatbuffers::Offset<bluetooth::dumpsys::BundledSchemaMap>>* map = - bundled_schema_->map(); - - for (auto it = map->cbegin(); it != map->cend(); ++it) { - flatbuffers::Verifier verifier(reinterpret_cast<const uint8_t*>(it->data()->Data()), - it->data()->size()); - if (!reflection::VerifySchemaBuffer(verifier)) { - return false; - } - } - return true; -} diff --git a/system/gd/dumpsys/reflection_schema.h b/system/gd/dumpsys/reflection_schema.h deleted file mode 100644 index 7100a6b1b6..0000000000 --- a/system/gd/dumpsys/reflection_schema.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <string> - -#include "bundler_schema_generated.h" -#include "flatbuffers/flatbuffers.h" -#include "flatbuffers/idl.h" - -namespace bluetooth { -namespace dumpsys { - -class ReflectionSchema { -public: - ReflectionSchema(const std::string& pre_bundled_schema); - - std::string GetTitle() const; - std::string GetRootName() const; - int GetNumberOfBundledSchemas() const; - - bool VerifyReflectionSchema() const; - const reflection::Schema* GetRootReflectionSchema() const; - const reflection::Schema* FindInReflectionSchema(const std::string& name) const; - void PrintReflectionSchema() const; - -private: - const BundledSchema* bundled_schema_; - const std::string pre_bundled_schema_; -}; - -} // namespace dumpsys -} // namespace bluetooth diff --git a/system/gd/dumpsys/reflection_schema_test.cc b/system/gd/dumpsys/reflection_schema_test.cc deleted file mode 100644 index 83e433eddd..0000000000 --- a/system/gd/dumpsys/reflection_schema_test.cc +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "dumpsys/reflection_schema.h" - -#include <gtest/gtest.h> - -#include "dumpsys/dumpsys_test_data.h" - -namespace bluetooth { -namespace dumpsys { -extern const unsigned char* data; -extern const size_t data_size; -const std::string& GetBundledSchemaData(); -} // namespace dumpsys -} // namespace bluetooth - -namespace testing { - -using namespace bluetooth; - -class ReflectionSchemaTest : public Test { -protected: - void SetUp() override {} - - void TearDown() override {} -}; - -TEST_F(ReflectionSchemaTest, verify_test_content) { - dumpsys::ReflectionSchema reflection_schema(testing::GetBundledSchemaData()); - ASSERT_EQ(5, reflection_schema.GetNumberOfBundledSchemas()); - ASSERT_TRUE(reflection_schema.FindInReflectionSchema("testing.DumpsysTestDataRoot") != nullptr); - ASSERT_TRUE(reflection_schema.FindInReflectionSchema("testing.BarTestSchema") != nullptr); - ASSERT_TRUE(reflection_schema.FindInReflectionSchema("testing.BazTestSchema") != nullptr); - ASSERT_TRUE(reflection_schema.FindInReflectionSchema("testing.FooTestSchema") != nullptr); - ASSERT_TRUE(reflection_schema.FindInReflectionSchema("testing.QuxTestSchema") != nullptr); - ASSERT_TRUE(reflection_schema.FindInReflectionSchema("DoesNotExist") == nullptr); -} - -TEST_F(ReflectionSchemaTest, verify_test_schema) { - dumpsys::ReflectionSchema reflection_schema(testing::GetBundledSchemaData()); - ASSERT_TRUE(reflection_schema.VerifyReflectionSchema()); -} - -TEST_F(ReflectionSchemaTest, verify_production_schema) { - dumpsys::ReflectionSchema reflection_schema(bluetooth::dumpsys::GetBundledSchemaData()); - ASSERT_TRUE(reflection_schema.VerifyReflectionSchema()); -} - -} // namespace testing diff --git a/system/gd/dumpsys/test_data/bar.fbs b/system/gd/dumpsys/test_data/bar.fbs deleted file mode 100644 index dc423fea9e..0000000000 --- a/system/gd/dumpsys/test_data/bar.fbs +++ /dev/null @@ -1,12 +0,0 @@ -namespace testing; - -attribute "privacy"; - -table BarTestSchema { - bar_x:int; - bar_y:int; - another_field:string (privacy:"Any"); -} - -root_type BarTestSchema; - diff --git a/system/gd/dumpsys/test_data/bar.h b/system/gd/dumpsys/test_data/bar.h deleted file mode 100644 index 26af6c09e2..0000000000 --- a/system/gd/dumpsys/test_data/bar.h +++ /dev/null @@ -1,17 +0,0 @@ -/** - * - **/ -#include "bar_generated.h" -#include "root.h" -#include "root_generated.h" - -namespace testing { - -class BarTestDataClass : public DumpsysTestDataClass { -public: - TableAddFunction GetTable(flatbuffers::FlatBufferBuilder& /* fb_builder */) override { - return [](DumpsysTestDataRootBuilder* /* builder */) {}; - } -}; - -} // namespace testing diff --git a/system/gd/dumpsys/test_data/baz.fbs b/system/gd/dumpsys/test_data/baz.fbs deleted file mode 100644 index 38649a9c8c..0000000000 --- a/system/gd/dumpsys/test_data/baz.fbs +++ /dev/null @@ -1,35 +0,0 @@ -namespace testing; - -attribute "privacy"; - -table BazSubTablePrivate { - subtable_int_any:int (privacy:"Any"); - subtable_string_any:string (privacy:"Any"); -} - -table BazSubTableOpaque { - subtable_int_any:int (privacy:"Any"); - subtable_string_any:string (privacy:"Any"); -} - -table BazSubTableAnonymized { - subtable_int_any:int (privacy:"Any"); - subtable_string_any:string (privacy:"Any"); -} - -table BazSubTableAny { - subtable_int_private:int (privacy:"Private"); - subtable_int_opaque:int (privacy:"Opaque"); - subtable_int_anonymized:int (privacy:"Anonymized"); - subtable_int_any:int (privacy:"Any"); - subtable_string_any:string (privacy:"Any"); -} - -table BazTestSchema { - sub_table_private:BazSubTablePrivate; // private by default - sub_table_opaque:BazSubTableOpaque (privacy:"Opaque"); - sub_table_anonymized:BazSubTableAnonymized (privacy:"Anonymized"); - sub_table_any:BazSubTableAny (privacy:"Any"); -} - -root_type BazTestSchema; diff --git a/system/gd/dumpsys/test_data/baz.h b/system/gd/dumpsys/test_data/baz.h deleted file mode 100644 index 326f025bb9..0000000000 --- a/system/gd/dumpsys/test_data/baz.h +++ /dev/null @@ -1,34 +0,0 @@ - -#include "baz_generated.h" -#include "root.h" -#include "root_generated.h" - -namespace testing { - -class BazTestDataClass : public DumpsysTestDataClass { -public: - TableAddFunction GetTable(flatbuffers::FlatBufferBuilder& fb_builder) override { - auto sub_name_private = fb_builder.CreateString("Baz Subtable Private"); - auto sub_name_opaque = fb_builder.CreateString("Baz Subtable Opaque"); - auto sub_name_anonymized = fb_builder.CreateString("Baz Subtable Anonymized"); - auto sub_name_any = fb_builder.CreateString("Baz Subtable Any"); - - auto private_subtable = CreateBazSubTablePrivate(fb_builder, 1, sub_name_private); - auto opaque_subtable = CreateBazSubTableOpaque(fb_builder, 1, sub_name_opaque); - auto anonymized_subtable = CreateBazSubTableAnonymized(fb_builder, 1, sub_name_anonymized); - auto any_subtable = CreateBazSubTableAny(fb_builder, 1, 2, 3, 4, sub_name_any); - - BazTestSchemaBuilder builder(fb_builder); - builder.add_sub_table_private(private_subtable); - builder.add_sub_table_opaque(opaque_subtable); - builder.add_sub_table_anonymized(anonymized_subtable); - builder.add_sub_table_any(any_subtable); - auto baz_table = builder.Finish(); - - return [baz_table](DumpsysTestDataRootBuilder* builder) { - builder->add_baz_module_data(baz_table); - }; - } -}; - -} // namespace testing diff --git a/system/gd/dumpsys/test_data/foo.fbs b/system/gd/dumpsys/test_data/foo.fbs deleted file mode 100644 index b7482c326f..0000000000 --- a/system/gd/dumpsys/test_data/foo.fbs +++ /dev/null @@ -1,25 +0,0 @@ -namespace testing; - -attribute "privacy"; - -table FooTestSchema { - foo_int_private:int; - foo_int_opaque:int (privacy:"Opaque"); - foo_int_anonymized:int (privacy:"Anonymized"); - foo_int_any:int (privacy:"Any"); - foo_int_string:string (privacy:"Any"); - - foo_float_private:float; - foo_float_opaque:float (privacy:"Opaque"); - foo_float_anonymized:float (privacy:"Anonymized"); - foo_float_any:float (privacy:"Any"); - foo_float_string:string (privacy:"Any"); - - foo_bool_private:bool (privacy:"Private"); - foo_bool_opaque:bool (privacy:"Opaque"); - foo_bool_anonymized:bool (privacy:"Anonymized"); - foo_bool_any:bool (privacy:"Any"); - foo_bool_string:string (privacy:"Any"); -} - -root_type FooTestSchema; diff --git a/system/gd/dumpsys/test_data/foo.h b/system/gd/dumpsys/test_data/foo.h deleted file mode 100644 index 7d346657d4..0000000000 --- a/system/gd/dumpsys/test_data/foo.h +++ /dev/null @@ -1,42 +0,0 @@ - -#include "foo_generated.h" -#include "root.h" -#include "root_generated.h" - -namespace testing { - -class FooTestDataClass : public DumpsysTestDataClass { -public: - TableAddFunction GetTable(flatbuffers::FlatBufferBuilder& fb_builder) override { - auto int_string = fb_builder.CreateString("123"); - auto float_string = fb_builder.CreateString("123.456"); - auto bool_string = fb_builder.CreateString("true"); - - FooTestSchemaBuilder builder(fb_builder); - builder.add_foo_int_private(123); - builder.add_foo_int_opaque(123); - builder.add_foo_int_anonymized(123); - builder.add_foo_int_any(123); - builder.add_foo_int_string(int_string); - - builder.add_foo_float_private(123.456); - builder.add_foo_float_opaque(123.456); - builder.add_foo_float_anonymized(123.456); - builder.add_foo_float_any(123.456); - builder.add_foo_float_string(float_string); - - builder.add_foo_bool_private(true); - builder.add_foo_bool_opaque(true); - builder.add_foo_bool_anonymized(true); - builder.add_foo_bool_any(true); - builder.add_foo_bool_string(bool_string); - - auto foo_table = builder.Finish(); - - return [foo_table](DumpsysTestDataRootBuilder* builder) { - builder->add_foo_module_data(foo_table); - }; - } -}; - -} // namespace testing diff --git a/system/gd/dumpsys/test_data/qux.fbs b/system/gd/dumpsys/test_data/qux.fbs deleted file mode 100644 index 15e17dab7d..0000000000 --- a/system/gd/dumpsys/test_data/qux.fbs +++ /dev/null @@ -1,13 +0,0 @@ -namespace testing; - -attribute "privacy"; - -table QuxTestSchema { - qux_int_private:int; - qux_int_opaque:int (privacy:"Opaque"); - qux_int_anonymized:int (privacy:"Anonymized"); - qux_int_any:int (privacy:"Any"); - qux_string_name:string (privacy:"Any"); -} - -root_type QuxTestSchema; diff --git a/system/gd/dumpsys/test_data/qux.h b/system/gd/dumpsys/test_data/qux.h deleted file mode 100644 index 1e70de3879..0000000000 --- a/system/gd/dumpsys/test_data/qux.h +++ /dev/null @@ -1,28 +0,0 @@ - -#include "qux_generated.h" -#include "root.h" -#include "root_generated.h" - -namespace testing { - -class QuxTestDataClass : public DumpsysTestDataClass { -public: - TableAddFunction GetTable(flatbuffers::FlatBufferBuilder& fb_builder) override { - auto name = fb_builder.CreateString("Qux Module String"); - - QuxTestSchemaBuilder builder(fb_builder); - builder.add_qux_int_private(123); - builder.add_qux_int_opaque(456); - builder.add_qux_int_anonymized(789); - builder.add_qux_int_any(0xabc); - builder.add_qux_string_name(name); - - auto qux_table = builder.Finish(); - - return [qux_table](DumpsysTestDataRootBuilder* builder) { - builder->add_qux_module_data(qux_table); - }; - } -}; - -} // namespace testing diff --git a/system/gd/dumpsys/test_data/root.fbs b/system/gd/dumpsys/test_data/root.fbs deleted file mode 100644 index cedd310d11..0000000000 --- a/system/gd/dumpsys/test_data/root.fbs +++ /dev/null @@ -1,27 +0,0 @@ -include "foo.fbs"; -include "bar.fbs"; -include "baz.fbs"; -include "qux.fbs"; - -namespace testing; - -attribute "privacy"; - -table DumpsysTestDataRoot { - string_private:string; - string_opaque:string (privacy:"Opaque"); - string_anonymized:string (privacy:"Anonymized"); - string_any:string (privacy:"Any"); - - int_private:int32 (privacy:"Private"); - int_opaque:int32 (privacy:"Opaque"); - int_anonymized:int32 (privacy:"Anonymized"); - int_any:int32 (privacy:"Any"); - - foo_module_data:FooTestSchema (privacy:"Any"); - bar_module_data:BarTestSchema (privacy:"Any"); - baz_module_data:BazTestSchema (privacy:"Any"); - qux_module_data:QuxTestSchema (privacy:"Any"); -} - -root_type DumpsysTestDataRoot; diff --git a/system/gd/dumpsys/test_data/root.h b/system/gd/dumpsys/test_data/root.h deleted file mode 100644 index 9f58c8ebed..0000000000 --- a/system/gd/dumpsys/test_data/root.h +++ /dev/null @@ -1,17 +0,0 @@ - - -#pragma once - -#include "flatbuffers/flatbuffers.h" -#include "root_generated.h" - -using TableAddFunction = std::function<void(testing::DumpsysTestDataRootBuilder* root_builder)>; - -namespace testing { - -struct DumpsysTestDataClass { - virtual TableAddFunction GetTable(flatbuffers::FlatBufferBuilder& fb_builder) = 0; - virtual ~DumpsysTestDataClass() = default; -}; - -} // namespace testing diff --git a/system/gd/dumpsys_data.fbs b/system/gd/dumpsys_data.fbs deleted file mode 100644 index 931d553937..0000000000 --- a/system/gd/dumpsys_data.fbs +++ /dev/null @@ -1,23 +0,0 @@ -// Top level module dumpsys data schema -// -// Possible field privacy levels from strongest to weakest. -// When unspecified defaults to the strongest privacy level. -// -// privacy:"Private" -// privacy:"Opaque" -// privacy:"Anonymized" -// privacy:"Any" - - -include "module_unittest.fbs"; - -namespace bluetooth; - -attribute "privacy"; - -table DumpsysData { - title:string (privacy:"Any"); - module_unittest_data:bluetooth.ModuleUnitTestData; // private -} - -root_type DumpsysData; diff --git a/system/gd/hal/snoop_logger.cc b/system/gd/hal/snoop_logger.cc index 84eb0302e5..2e587cbfd6 100644 --- a/system/gd/hal/snoop_logger.cc +++ b/system/gd/hal/snoop_logger.cc @@ -35,7 +35,6 @@ #include "common/strings.h" #include "hal/snoop_logger_common.h" #include "hci/hci_packets.h" -#include "module_dumper_flatbuffer.h" #include "os/files.h" #include "os/parameter_provider.h" #include "os/system_properties.h" diff --git a/system/gd/hal/snoop_logger_test.cc b/system/gd/hal/snoop_logger_test.cc index 380e68a0e5..bfe81f3194 100644 --- a/system/gd/hal/snoop_logger_test.cc +++ b/system/gd/hal/snoop_logger_test.cc @@ -129,7 +129,6 @@ public: class SnoopLoggerModuleTest : public Test { public: - flatbuffers::FlatBufferBuilder* builder_; TestModuleRegistry* test_registry; protected: @@ -149,7 +148,6 @@ protected: temp_dir_ / (std::string(test_info->name()) + "_btsnoop_hci.log.filtered"); temp_snoop_log_filtered_last = temp_dir_ / (std::string(test_info->name()) + "_btsnoop_hci.log.filtered.last"); - builder_ = new flatbuffers::FlatBufferBuilder(); DeleteSnoopLogFiles(); ASSERT_FALSE(std::filesystem::exists(temp_snoop_log_)); @@ -164,7 +162,6 @@ protected: void TearDown() override { DeleteSnoopLogFiles(); - delete builder_; fake_timerfd_reset(); test_registry->StopAll(); delete test_registry; diff --git a/system/gd/hci/acl_manager.cc b/system/gd/hci/acl_manager.cc index 682800522c..a8edc9ea39 100644 --- a/system/gd/hci/acl_manager.cc +++ b/system/gd/hci/acl_manager.cc @@ -29,7 +29,6 @@ #include "common/bidi_queue.h" #include "common/byte_array.h" -#include "dumpsys_data_generated.h" #include "hci/acl_manager/acl_scheduler.h" #include "hci/acl_manager/classic_impl.h" #include "hci/acl_manager/le_acceptlist_callbacks.h" diff --git a/system/gd/hci/controller.cc b/system/gd/hci/controller.cc index 18180a547c..18743a1038 100644 --- a/system/gd/hci/controller.cc +++ b/system/gd/hci/controller.cc @@ -25,7 +25,6 @@ #include <string> #include <utility> -#include "dumpsys_data_generated.h" #include "hci/controller_interface.h" #include "hci/event_checkers.h" #include "hci/hci_layer.h" diff --git a/system/gd/hci/controller_test.cc b/system/gd/hci/controller_test.cc index 04b1380fa4..05dcaf9d7e 100644 --- a/system/gd/hci/controller_test.cc +++ b/system/gd/hci/controller_test.cc @@ -29,7 +29,6 @@ #include "common/bind.h" #include "hci/address.h" #include "hci/hci_layer_fake.h" -#include "module_dumper.h" #include "os/thread.h" #include "packet/raw_builder.h" diff --git a/system/gd/module.cc b/system/gd/module.cc index 5a2cdf142c..97f6132f31 100644 --- a/system/gd/module.cc +++ b/system/gd/module.cc @@ -45,13 +45,6 @@ Module* Module::GetDependency(const ModuleFactory* module) const { log::fatal("Module was not listed as a dependency in ListDependencies"); } -bluetooth::DumpsysDataFinisher EmptyDumpsysDataFinisher = - [](bluetooth::DumpsysDataBuilder* /* dumpsys_data_builder */) {}; - -DumpsysDataFinisher Module::GetDumpsysData(flatbuffers::FlatBufferBuilder* /* builder */) const { - return EmptyDumpsysDataFinisher; -} - Module* ModuleRegistry::Get(const ModuleFactory* module) const { auto instance = started_modules_.find(module); log::assert_that(instance != started_modules_.end(), diff --git a/system/gd/module.h b/system/gd/module.h index 44aa0bcb29..80b2369edf 100644 --- a/system/gd/module.h +++ b/system/gd/module.h @@ -17,7 +17,6 @@ #pragma once #include <bluetooth/log.h> -#include <flatbuffers/flatbuffers.h> #include <chrono> #include <functional> @@ -35,7 +34,6 @@ namespace bluetooth { class Module; -class ModuleDumper; class ModuleRegistry; class TestModuleRegistry; class FuzzTestModuleRegistry; @@ -68,11 +66,6 @@ private: std::vector<const ModuleFactory*> list_; }; -struct DumpsysDataBuilder; -using DumpsysDataFinisher = std::function<void(DumpsysDataBuilder*)>; - -extern DumpsysDataFinisher EmptyDumpsysDataFinisher; - // Each leaf node module must have a factory like so: // // static const ModuleFactory Factory; @@ -81,7 +74,6 @@ extern DumpsysDataFinisher EmptyDumpsysDataFinisher; // The module registry will also use the factory as the identifier // for that module. class Module { - friend ModuleDumper; friend ModuleRegistry; friend TestModuleRegistry; @@ -120,8 +112,6 @@ protected: GetHandler()->CallOn(obj, std::forward<Functor>(functor), std::forward<Args>(args)...); } - virtual DumpsysDataFinisher GetDumpsysData(flatbuffers::FlatBufferBuilder* builder) const; - private: Module* GetDependency(const ModuleFactory* module) const; @@ -132,7 +122,6 @@ private: class ModuleRegistry { friend Module; - friend ModuleDumper; friend class StackManager; public: diff --git a/system/gd/module_dumper.cc b/system/gd/module_dumper.cc deleted file mode 100644 index 483598a3fc..0000000000 --- a/system/gd/module_dumper.cc +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#define LOG_TAG "BtGdModule" - -#include "module_dumper.h" - -#include <sstream> - -#include "dumpsys_data_generated.h" -#include "module.h" -#include "os/wakelock_manager.h" - -using ::bluetooth::os::WakelockManager; - -namespace bluetooth { - -void ModuleDumper::DumpState(std::string* output, std::ostringstream& /*oss*/) const { - *output = ""; -} - -} // namespace bluetooth diff --git a/system/gd/module_dumper.h b/system/gd/module_dumper.h deleted file mode 100644 index 4d48911275..0000000000 --- a/system/gd/module_dumper.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <sstream> -#include <string> - -#include "module.h" - -namespace bluetooth { - -class ModuleRegistry; - -class ModuleDumper { -public: - ModuleDumper(int /*fd*/, const ModuleRegistry& module_registry, const char* title) - : module_registry_(module_registry), title_(title) {} - void DumpState(std::string* output, std::ostringstream& oss) const; - -private: - [[maybe_unused]] const ModuleRegistry& module_registry_; - [[maybe_unused]] const std::string title_; -}; - -} // namespace bluetooth diff --git a/system/gd/module_dumper_flatbuffer.h b/system/gd/module_dumper_flatbuffer.h deleted file mode 100644 index 21b19a7291..0000000000 --- a/system/gd/module_dumper_flatbuffer.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <functional> - -namespace bluetooth { - -struct DumpsysDataBuilder; -using DumpsysDataFinisher = std::function<void(DumpsysDataBuilder* dumpsys_data_builder)>; - -extern DumpsysDataFinisher EmptyDumpsysDataFinisher; - -} // namespace bluetooth diff --git a/system/gd/module_unittest.cc b/system/gd/module_unittest.cc index 97be5efde7..24ccc8b3d2 100644 --- a/system/gd/module_unittest.cc +++ b/system/gd/module_unittest.cc @@ -22,10 +22,7 @@ #include <sstream> #include <string> -#include "dumpsys_data_generated.h" #include "gtest/gtest.h" -#include "module_dumper.h" -#include "module_unittest_generated.h" #include "os/handler.h" #include "os/thread.h" @@ -161,48 +158,6 @@ protected: const ModuleFactory TestModuleTwoDependencies::Factory = ModuleFactory([]() { return new TestModuleTwoDependencies(); }); -// To generate module unittest flatbuffer headers: -// $ flatc --cpp module_unittest.fbs -class TestModuleDumpState : public Module { -public: - static const ModuleFactory Factory; - - std::string test_string_{"Initial Test String"}; - -protected: - void ListDependencies(ModuleList* list) const { list->add<TestModuleNoDependency>(); } - - void Start() override { - EXPECT_TRUE(GetModuleRegistry()->IsStarted<TestModuleNoDependency>()); - - // A module is not considered started until Start() finishes - EXPECT_FALSE(GetModuleRegistry()->IsStarted<TestModuleDumpState>()); - test_module_one_dependency_handler = GetHandler(); - } - - void Stop() override { - EXPECT_TRUE(GetModuleRegistry()->IsStarted<TestModuleNoDependency>()); - - // A module is not considered stopped until after Stop() finishes - EXPECT_TRUE(GetModuleRegistry()->IsStarted<TestModuleDumpState>()); - } - - std::string ToString() const override { return std::string("TestModuleDumpState"); } - - DumpsysDataFinisher GetDumpsysData(flatbuffers::FlatBufferBuilder* fb_builder) const override { - auto string = fb_builder->CreateString(test_string_.c_str()); - - auto builder = ModuleUnitTestDataBuilder(*fb_builder); - builder.add_title(string); - auto table = builder.Finish(); - - return [table](DumpsysDataBuilder* builder) { builder->add_module_unittest_data(table); }; - } -}; - -const ModuleFactory TestModuleDumpState::Factory = - ModuleFactory([]() { return new TestModuleDumpState(); }); - TEST_F(ModuleTest, no_dependency) { ModuleList list; list.add<TestModuleNoDependency>(); diff --git a/system/gd/module_unittest.fbs b/system/gd/module_unittest.fbs deleted file mode 100644 index 3c0a1b6bd0..0000000000 --- a/system/gd/module_unittest.fbs +++ /dev/null @@ -1,10 +0,0 @@ -// module_unittest -namespace bluetooth; - -attribute "privacy"; - -table ModuleUnitTestData { - title:string (privacy:"Any"); -} - -root_type ModuleUnitTestData; diff --git a/system/gd/module_unittest_generated.h b/system/gd/module_unittest_generated.h deleted file mode 100644 index 1176e5cbc9..0000000000 --- a/system/gd/module_unittest_generated.h +++ /dev/null @@ -1,86 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - -#ifndef FLATBUFFERS_GENERATED_MODULEUNITTEST_BLUETOOTH_H_ -#define FLATBUFFERS_GENERATED_MODULEUNITTEST_BLUETOOTH_H_ - -#include "flatbuffers/flatbuffers.h" - -namespace bluetooth { - -struct ModuleUnitTestData; -struct ModuleUnitTestDataBuilder; - -struct ModuleUnitTestData FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - typedef ModuleUnitTestDataBuilder Builder; - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { VT_TITLE = 4 }; - const flatbuffers::String* title() const { - return GetPointer<const flatbuffers::String*>(VT_TITLE); - } - bool Verify(flatbuffers::Verifier& verifier) const { - return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_TITLE) && - verifier.VerifyString(title()) && verifier.EndTable(); - } -}; - -struct ModuleUnitTestDataBuilder { - typedef ModuleUnitTestData Table; - flatbuffers::FlatBufferBuilder& fbb_; - flatbuffers::uoffset_t start_; - void add_title(flatbuffers::Offset<flatbuffers::String> title) { - fbb_.AddOffset(ModuleUnitTestData::VT_TITLE, title); - } - explicit ModuleUnitTestDataBuilder(flatbuffers::FlatBufferBuilder& _fbb) : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ModuleUnitTestDataBuilder& operator=(const ModuleUnitTestDataBuilder&); - flatbuffers::Offset<ModuleUnitTestData> Finish() { - const auto end = fbb_.EndTable(start_); - auto o = flatbuffers::Offset<ModuleUnitTestData>(end); - return o; - } -}; - -inline flatbuffers::Offset<ModuleUnitTestData> CreateModuleUnitTestData( - flatbuffers::FlatBufferBuilder& _fbb, flatbuffers::Offset<flatbuffers::String> title = 0) { - ModuleUnitTestDataBuilder builder_(_fbb); - builder_.add_title(title); - return builder_.Finish(); -} - -inline flatbuffers::Offset<ModuleUnitTestData> CreateModuleUnitTestDataDirect( - flatbuffers::FlatBufferBuilder& _fbb, const char* title = nullptr) { - auto title__ = title ? _fbb.CreateString(title) : 0; - return bluetooth::CreateModuleUnitTestData(_fbb, title__); -} - -inline const bluetooth::ModuleUnitTestData* GetModuleUnitTestData(const void* buf) { - return flatbuffers::GetRoot<bluetooth::ModuleUnitTestData>(buf); -} - -inline const bluetooth::ModuleUnitTestData* GetSizePrefixedModuleUnitTestData(const void* buf) { - return flatbuffers::GetSizePrefixedRoot<bluetooth::ModuleUnitTestData>(buf); -} - -inline bool VerifyModuleUnitTestDataBuffer(flatbuffers::Verifier& verifier) { - return verifier.VerifyBuffer<bluetooth::ModuleUnitTestData>(nullptr); -} - -inline bool VerifySizePrefixedModuleUnitTestDataBuffer(flatbuffers::Verifier& verifier) { - return verifier.VerifySizePrefixedBuffer<bluetooth::ModuleUnitTestData>(nullptr); -} - -inline void FinishModuleUnitTestDataBuffer( - flatbuffers::FlatBufferBuilder& fbb, - flatbuffers::Offset<bluetooth::ModuleUnitTestData> root) { - fbb.Finish(root); -} - -inline void FinishSizePrefixedModuleUnitTestDataBuffer( - flatbuffers::FlatBufferBuilder& fbb, - flatbuffers::Offset<bluetooth::ModuleUnitTestData> root) { - fbb.FinishSizePrefixed(root); -} - -} // namespace bluetooth - -#endif // FLATBUFFERS_GENERATED_MODULEUNITTEST_BLUETOOTH_H_ diff --git a/system/gd/os/wakelock_manager.h b/system/gd/os/wakelock_manager.h index 3f1b91f554..d920a5b4b4 100644 --- a/system/gd/os/wakelock_manager.h +++ b/system/gd/os/wakelock_manager.h @@ -18,8 +18,6 @@ #pragma once -#include <flatbuffers/flatbuffers.h> - #include <memory> #include <mutex> #include <string> diff --git a/system/gd/rust/topshim/Android.bp b/system/gd/rust/topshim/Android.bp index b7d3af79ea..5d0e9c2102 100644 --- a/system/gd/rust/topshim/Android.bp +++ b/system/gd/rust/topshim/Android.bp @@ -52,7 +52,6 @@ cc_library_static { "vc/vc_shim.cc", ], generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", "cxx-bridge-header", "libbt_topshim_bridge_header", ], diff --git a/system/gd/rust/topshim/facade/Android.bp b/system/gd/rust/topshim/facade/Android.bp index 505d5e8624..cc51c5f435 100644 --- a/system/gd/rust/topshim/facade/Android.bp +++ b/system/gd/rust/topshim/facade/Android.bp @@ -38,7 +38,6 @@ rust_defaults { "lib-bt-packets-avrcp", "lib-bt-packets-base", "libFraunhoferAAC", - "libbluetooth-dumpsys", "libbluetooth-types", "libbluetooth_crypto_toolbox", "libbluetooth_gd", // Gabeldorsche diff --git a/system/gd/shim/Android.bp b/system/gd/shim/Android.bp index c2b1d8b68e..d91ba15804 100644 --- a/system/gd/shim/Android.bp +++ b/system/gd/shim/Android.bp @@ -13,10 +13,3 @@ filegroup { "dumpsys.cc", ], } - -filegroup { - name: "BluetoothShimTestSources", - srcs: [ - "dumpsys_test.cc", - ], -} diff --git a/system/gd/shim/BUILD.gn b/system/gd/shim/BUILD.gn index d30e609c2f..89d318afc1 100644 --- a/system/gd/shim/BUILD.gn +++ b/system/gd/shim/BUILD.gn @@ -20,8 +20,6 @@ source_set("BluetoothShimSources") { deps = [ "//bt/flags:bluetooth_flags_c_lib", - "//bt/system/gd/dumpsys:libbluetooth-dumpsys", - "//bt/system/gd/dumpsys/bundler:BluetoothGeneratedBundlerSchema_h_bfbs", "//bt/system/pdl:BluetoothGeneratedPackets_h", ] diff --git a/system/gd/shim/dumpsys.cc b/system/gd/shim/dumpsys.cc index f4a9282e1c..b93ffd9efb 100644 --- a/system/gd/shim/dumpsys.cc +++ b/system/gd/shim/dumpsys.cc @@ -15,8 +15,6 @@ */ #define LOG_TAG "bt_gd_shim" -#include "dumpsys/dumpsys.h" - #include <bluetooth/log.h> #include <com_android_bluetooth_flags.h> #include <unistd.h> @@ -25,14 +23,12 @@ #include <sstream> #include <string> -#include "dumpsys/filter.h" #include "hal/snoop_logger.h" #include "hci/acl_manager.h" #include "hci/controller_interface.h" #include "main/shim/entry.h" #include "main/shim/stack.h" #include "module.h" -#include "module_dumper.h" #include "os/system_properties.h" #include "os/wakelock_manager.h" #include "shim/dumpsys.h" @@ -40,102 +36,31 @@ namespace bluetooth { namespace shim { -static const std::string kReadOnlyDebuggableProperty = "ro.debuggable"; - namespace { constexpr char kModuleName[] = "shim::Dumpsys"; -constexpr char kDumpsysTitle[] = "----- Gd Dumpsys ------"; } // namespace struct Dumpsys::impl { public: - void DumpWithArgsSync(int fd, const char** args, std::promise<void> promise); + void DumpSync(int fd, std::promise<void> promise); int GetNumberOfBundledSchemas() const; - impl(const Dumpsys& dumpsys_module, const dumpsys::ReflectionSchema& reflection_schema); + impl(const Dumpsys& dumpsys_module); ~impl() = default; -protected: - void FilterSchema(std::string* dumpsys_data) const; - std::string PrintAsJson(std::string* dumpsys_data) const; - - bool IsDebuggable() const; - private: - void DumpWithArgsAsync(int fd, const char** args) const; + void DumpAsync(int fd) const; const Dumpsys& dumpsys_module_; - const dumpsys::ReflectionSchema reflection_schema_; }; const ModuleFactory Dumpsys::Factory = - ModuleFactory([]() { return new Dumpsys(bluetooth::dumpsys::GetBundledSchemaData()); }); - -Dumpsys::impl::impl(const Dumpsys& dumpsys_module, - const dumpsys::ReflectionSchema& reflection_schema) - : dumpsys_module_(dumpsys_module), reflection_schema_(std::move(reflection_schema)) {} - -int Dumpsys::impl::GetNumberOfBundledSchemas() const { - return reflection_schema_.GetNumberOfBundledSchemas(); -} - -bool Dumpsys::impl::IsDebuggable() const { - return os::GetSystemProperty(kReadOnlyDebuggableProperty) == "1"; -} - -void Dumpsys::impl::FilterSchema(std::string* dumpsys_data) const { - log::assert_that(dumpsys_data != nullptr, "assert failed: dumpsys_data != nullptr"); - dumpsys::FilterSchema(reflection_schema_, dumpsys_data); -} - -std::string Dumpsys::impl::PrintAsJson(std::string* dumpsys_data) const { - log::assert_that(dumpsys_data != nullptr, "assert failed: dumpsys_data != nullptr"); - - const std::string root_name = reflection_schema_.GetRootName(); - if (root_name.empty()) { - char buf[255]; - snprintf(buf, sizeof(buf), "ERROR: Unable to find root name in prebundled reflection schema\n"); - log::warn("{}", buf); - return std::string(buf); - } - - const reflection::Schema* schema = reflection_schema_.FindInReflectionSchema(root_name); - if (schema == nullptr) { - char buf[255]; - snprintf(buf, sizeof(buf), "ERROR: Unable to find schema root name:%s\n", root_name.c_str()); - log::warn("{}", buf); - return std::string(buf); - } - - flatbuffers::IDLOptions options{}; - options.output_default_scalars_in_json = true; - flatbuffers::Parser parser{options}; - if (!parser.Deserialize(schema)) { - char buf[255]; - snprintf(buf, sizeof(buf), "ERROR: Unable to deserialize bundle root name:%s\n", - root_name.c_str()); - log::warn("{}", buf); - return std::string(buf); - } + ModuleFactory([]() { return new Dumpsys(); }); - std::string jsongen; - // GenerateText was renamed to GenText in 23.5.26 because the return behavior was changed. - // https://github.com/google/flatbuffers/commit/950a71ab893e96147c30dd91735af6db73f72ae0 -#if FLATBUFFERS_VERSION_MAJOR < 23 || \ - (FLATBUFFERS_VERSION_MAJOR == 23 && \ - (FLATBUFFERS_VERSION_MINOR < 5 || \ - (FLATBUFFERS_VERSION_MINOR == 5 && FLATBUFFERS_VERSION_REVISION < 26))) - flatbuffers::GenerateText(parser, dumpsys_data->data(), &jsongen); -#else - const char* error = flatbuffers::GenText(parser, dumpsys_data->data(), &jsongen); - if (error != nullptr) { - log::warn("{}", error); - } -#endif - return jsongen; -} +Dumpsys::impl::impl(const Dumpsys& dumpsys_module) + : dumpsys_module_(dumpsys_module) {} -void Dumpsys::impl::DumpWithArgsAsync(int fd, const char** /*args*/) const { +void Dumpsys::impl::DumpAsync(int fd) const { const auto registry = dumpsys_module_.GetModuleRegistry(); bluetooth::shim::GetController()->Dump(fd); bluetooth::shim::GetAclManager()->Dump(fd); @@ -143,10 +68,10 @@ void Dumpsys::impl::DumpWithArgsAsync(int fd, const char** /*args*/) const { bluetooth::shim::GetSnoopLogger()->DumpSnoozLogToFile(); } -void Dumpsys::impl::DumpWithArgsSync(int fd, const char** args, std::promise<void> promise) { +void Dumpsys::impl::DumpSync(int fd, std::promise<void> promise) { if (bluetooth::shim::Stack::GetInstance()->LockForDumpsys([=, *this]() { log::info("Started dumpsys procedure"); - this->DumpWithArgsAsync(fd, args); + this->DumpAsync(fd); })) { log::info("Successful dumpsys procedure"); } else { @@ -155,15 +80,14 @@ void Dumpsys::impl::DumpWithArgsSync(int fd, const char** args, std::promise<voi promise.set_value(); } -Dumpsys::Dumpsys(const std::string& pre_bundled_schema) - : reflection_schema_(dumpsys::ReflectionSchema(pre_bundled_schema)) {} +Dumpsys::Dumpsys() {} -void Dumpsys::Dump(int fd, const char** args, std::promise<void> promise) { +void Dumpsys::Dump(int fd, const char** /*args*/, std::promise<void> promise) { if (fd <= 0) { promise.set_value(); return; } - CallOn(pimpl_.get(), &Dumpsys::impl::DumpWithArgsSync, fd, args, std::move(promise)); + CallOn(pimpl_.get(), &Dumpsys::impl::DumpSync, fd, std::move(promise)); } /** @@ -171,7 +95,7 @@ void Dumpsys::Dump(int fd, const char** args, std::promise<void> promise) { */ void Dumpsys::ListDependencies(ModuleList* /* list */) const {} -void Dumpsys::Start() { pimpl_ = std::make_unique<impl>(*this, reflection_schema_); } +void Dumpsys::Start() { pimpl_ = std::make_unique<impl>(*this); } void Dumpsys::Stop() { pimpl_.reset(); } diff --git a/system/gd/shim/dumpsys.h b/system/gd/shim/dumpsys.h index 95756cdfe9..5ead5839b2 100644 --- a/system/gd/shim/dumpsys.h +++ b/system/gd/shim/dumpsys.h @@ -19,19 +19,16 @@ #include <memory> #include <string> -#include "dumpsys/reflection_schema.h" #include "module.h" namespace bluetooth { namespace shim { -constexpr char kArgumentDeveloper[] = "--dev"; - class Dumpsys : public bluetooth::Module { public: void Dump(int fd, const char** args, std::promise<void> promise); - Dumpsys(const std::string& pre_bundled_schema); + Dumpsys(); Dumpsys(const Dumpsys&) = delete; Dumpsys& operator=(const Dumpsys&) = delete; @@ -48,7 +45,6 @@ protected: private: struct impl; std::unique_ptr<impl> pimpl_; - const dumpsys::ReflectionSchema reflection_schema_; }; } // namespace shim diff --git a/system/gd/shim/dumpsys_test.cc b/system/gd/shim/dumpsys_test.cc deleted file mode 100644 index 8107f20a6c..0000000000 --- a/system/gd/shim/dumpsys_test.cc +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "shim/dumpsys.h" - -#include <gtest/gtest.h> -#include <sys/socket.h> -#include <sys/types.h> - -#include <future> - -#include "module.h" -#include "os/thread.h" -#include "test_data/dumpsys_test_data_bin.h" - -namespace testing { - -using bluetooth::TestModuleRegistry; -using namespace bluetooth; - -namespace { - -bool SimpleJsonValidator(int fd, int* dumpsys_byte_cnt) { - char buf{0}; - bool within_double_quotes{false}; - int left_bracket{0}, right_bracket{0}; - while (read(fd, &buf, 1) != -1) { - switch (buf) { - (*dumpsys_byte_cnt)++; - case '"': - within_double_quotes = !within_double_quotes; - break; - case '{': - if (!within_double_quotes) { - left_bracket++; - } - break; - case '}': - if (!within_double_quotes) { - right_bracket++; - } - break; - default: - break; - } - } - return left_bracket == right_bracket; -} - -} // namespace - -// To create dumpsys_test_header_bin.h: -// make bluetooth_flatbuffer_bundler -// ${ANDROID_BUILD_TOP}/out/host/linux-x86/bin/bluetooth_flatbuffer_bundler -w -m -// bluetooth.DumpsysData -f test_gen/dumpsys_test_data_bin -n bluetooth::test test_gen/* - -class DumpsysTest : public Test { -protected: - void SetUp() override { - dumpsys_module_ = new bluetooth::shim::Dumpsys(bluetooth::test::GetBundledSchemaData()); - fake_registry_.InjectTestModule(&shim::Dumpsys::Factory, dumpsys_module_); - } - - void TearDown() override { fake_registry_.StopAll(); } - - int GetSocketBufferSize(int sockfd) { - int socket_buffer_size; - socklen_t optlen = sizeof(socket_buffer_size); - getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (void*)&socket_buffer_size, &optlen); - return socket_buffer_size; - } - - void SetSocketBufferSize(int sockfd, int socket_buffer_size) { - socklen_t optlen = sizeof(socket_buffer_size); - ASSERT_EQ(0, - setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (const void*)&socket_buffer_size, optlen)); - } - - TestModuleRegistry fake_registry_; - os::Thread& thread_ = fake_registry_.GetTestThread(); - bluetooth::shim::Dumpsys* dumpsys_module_ = nullptr; - os::Handler* client_handler_ = nullptr; -}; - -TEST_F(DumpsysTest, dump_as_developer) { - const char* args[]{bluetooth::shim::kArgumentDeveloper, nullptr}; - - int sv[2]; - ASSERT_EQ(0, socketpair(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK, 0, sv)); - int socket_buffer_size = GetSocketBufferSize(sv[0]); - - std::promise<void> promise; - std::future future = promise.get_future(); - dumpsys_module_->Dump(sv[0], args, std::move(promise)); - future.wait(); - - int dumpsys_byte_cnt = 0; - ASSERT_TRUE(SimpleJsonValidator(sv[1], &dumpsys_byte_cnt)); - ASSERT_TRUE(dumpsys_byte_cnt < socket_buffer_size); -} - -TEST_F(DumpsysTest, dump_as_user) { - const char* args[]{"not-a-developer-option", nullptr}; - - int sv[2]; - ASSERT_EQ(0, socketpair(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK, 0, sv)); - int socket_buffer_size = GetSocketBufferSize(sv[0]); - - std::promise<void> promise; - std::future future = promise.get_future(); - dumpsys_module_->Dump(sv[0], args, std::move(promise)); - future.wait(); - - int dumpsys_byte_cnt = 0; - ASSERT_TRUE(SimpleJsonValidator(sv[1], &dumpsys_byte_cnt)); - ASSERT_TRUE(dumpsys_byte_cnt < socket_buffer_size); -} - -} // namespace testing diff --git a/system/gd/shim/test_data/dumpsys_data.bfbs b/system/gd/shim/test_data/dumpsys_data.bfbs Binary files differdeleted file mode 100644 index afe2ea5407..0000000000 --- a/system/gd/shim/test_data/dumpsys_data.bfbs +++ /dev/null diff --git a/system/gd/shim/test_data/dumpsys_test_data_bin b/system/gd/shim/test_data/dumpsys_test_data_bin Binary files differdeleted file mode 100644 index b9c410d5c7..0000000000 --- a/system/gd/shim/test_data/dumpsys_test_data_bin +++ /dev/null diff --git a/system/gd/shim/test_data/dumpsys_test_data_bin.h b/system/gd/shim/test_data/dumpsys_test_data_bin.h deleted file mode 100644 index d1f118d0fa..0000000000 --- a/system/gd/shim/test_data/dumpsys_test_data_bin.h +++ /dev/null @@ -1,76 +0,0 @@ -// Generated file by bluetooth_flatbuffer bundler -#pragma once -#include <sys/types.h> - -#include <string> -namespace bluetooth { -namespace test { -extern const unsigned char* data; -extern const size_t data_size; -const std::string& GetBundledSchemaData(); -} // namespace test -} // namespace bluetooth -const unsigned char data_[] = { - 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, - 0x00, 0x0a, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x62, - 0x6c, 0x75, 0x65, 0x74, 0x6f, 0x6f, 0x74, 0x68, 0x2e, 0x44, 0x75, 0x6d, 0x70, 0x73, 0x79, - 0x73, 0x44, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x42, 0x75, 0x6e, - 0x64, 0x6c, 0x65, 0x64, 0x20, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x20, 0x74, 0x61, 0x62, - 0x6c, 0x65, 0x73, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x04, 0x00, 0x08, 0x00, 0x08, - 0x00, 0x00, 0x00, 0xec, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xe0, 0x02, 0x00, 0x00, - 0x18, 0x00, 0x00, 0x00, 0x42, 0x46, 0x42, 0x53, 0x10, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x08, - 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 0x18, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, - 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, - 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xd8, 0x01, 0x00, 0x00, 0x38, 0x01, - 0x00, 0x00, 0x3c, 0xfe, 0xff, 0xff, 0x1c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x62, 0x6c, 0x75, 0x65, 0x74, 0x6f, 0x6f, - 0x74, 0x68, 0x2e, 0x44, 0x75, 0x6d, 0x70, 0x73, 0x79, 0x73, 0x44, 0x61, 0x74, 0x61, 0x00, - 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x04, 0x00, 0x06, 0x00, 0x0c, - 0x00, 0x00, 0x00, 0x02, 0x00, 0x08, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x82, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x0f, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, - 0x00, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x5f, 0x75, 0x6e, 0x69, 0x74, 0x74, 0x65, 0x73, - 0x74, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x14, 0x00, 0x08, - 0x00, 0x0c, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x10, 0x00, 0x18, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x4c, 0x00, 0x00, - 0x00, 0x3c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x74, 0xfe, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, - 0x00, 0x00, 0x00, 0x41, 0x6e, 0x79, 0x00, 0x07, 0x00, 0x00, 0x00, 0x70, 0x72, 0x69, 0x76, - 0x61, 0x63, 0x79, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, - 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x02, 0x00, 0x00, 0x00, 0x11, 0x00, - 0x00, 0x00, 0x73, 0x68, 0x69, 0x6d, 0x5f, 0x64, 0x75, 0x6d, 0x70, 0x73, 0x79, 0x73, 0x5f, - 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x08, 0x00, 0x0c, 0x00, - 0x00, 0x00, 0x06, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, - 0x00, 0x04, 0x00, 0x00, 0x00, 0xb6, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x0d, 0x05, 0x00, - 0x00, 0x00, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x70, 0xff, 0xff, 0xff, 0x14, - 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x62, 0x6c, 0x75, 0x65, 0x74, 0x6f, 0x6f, - 0x74, 0x68, 0x2e, 0x73, 0x68, 0x69, 0x6d, 0x2e, 0x44, 0x75, 0x6d, 0x70, 0x73, 0x79, 0x73, - 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00, 0x68, - 0xff, 0xff, 0xff, 0x00, 0x00, 0x04, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x50, 0xff, 0xff, - 0xff, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x41, 0x6e, - 0x79, 0x00, 0x07, 0x00, 0x00, 0x00, 0x70, 0x72, 0x69, 0x76, 0x61, 0x63, 0x79, 0x00, 0x46, - 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x0d, 0x05, 0x00, 0x00, 0x00, 0x74, 0x69, 0x74, 0x6c, - 0x65, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x0c, - 0x00, 0x0c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, - 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x62, - 0x6c, 0x75, 0x65, 0x74, 0x6f, 0x6f, 0x74, 0x68, 0x2e, 0x4d, 0x6f, 0x64, 0x75, 0x6c, 0x65, - 0x55, 0x6e, 0x69, 0x74, 0x54, 0x65, 0x73, 0x74, 0x44, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, - 0x00, 0x18, 0x00, 0x14, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x04, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x04, 0x00, 0x08, - 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, - 0x00, 0x00, 0x41, 0x6e, 0x79, 0x00, 0x07, 0x00, 0x00, 0x00, 0x70, 0x72, 0x69, 0x76, 0x61, - 0x63, 0x79, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x0d, 0x05, 0x00, 0x00, 0x00, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x00, 0x00, - 0x00, 0x15, 0x00, 0x00, 0x00, 0x62, 0x6c, 0x75, 0x65, 0x74, 0x6f, 0x6f, 0x74, 0x68, 0x2e, - 0x44, 0x75, 0x6d, 0x70, 0x73, 0x79, 0x73, 0x44, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00}; -const std::string string_data_(data_, data_ + sizeof(data_)); -const unsigned char* bluetooth::test::data = data_; -const size_t bluetooth::test::data_size = 884; -const std::string& bluetooth::test::GetBundledSchemaData() { return string_data_; } diff --git a/system/main/Android.bp b/system/main/Android.bp index 5b270923f4..27c00e6232 100644 --- a/system/main/Android.bp +++ b/system/main/Android.bp @@ -41,10 +41,6 @@ cc_library_static { "packages/modules/Bluetooth/system/udrv/include", "system/security/keystore/include", ], - generated_headers: [ - "BluetoothGeneratedBundlerSchema_h_bfbs", - "BluetoothGeneratedDumpsysDataSchema_h", - ], apex_available: [ "com.android.btservices", ], @@ -129,10 +125,6 @@ cc_library_static { "packages/modules/Bluetooth/system/gd", "packages/modules/Bluetooth/system/stack/include", ], - generated_headers: [ - "BluetoothGeneratedBundlerSchema_h_bfbs", - "BluetoothGeneratedDumpsysDataSchema_h", - ], whole_static_libs: [ "libbluetooth_gd", // Gabeldorsche ], @@ -197,7 +189,6 @@ cc_test { static_libs: [ "bluetooth_flags_c_lib_for_test", "libbase", - "libbluetooth-dumpsys", "libbluetooth-types", "libbluetooth_core_rs_bridge", "libbluetooth_crypto_toolbox", @@ -236,10 +227,6 @@ cc_test { undefined: true, }, }, - generated_headers: [ - "BluetoothGeneratedBundlerSchema_h_bfbs", - "BluetoothGeneratedDumpsysDataSchema_h", - ], min_sdk_version: "Tiramisu", header_libs: ["libbluetooth_headers"], } diff --git a/system/main/shim/BUILD.gn b/system/main/shim/BUILD.gn index 88bbba0c6b..5e73e0f22c 100644 --- a/system/main/shim/BUILD.gn +++ b/system/main/shim/BUILD.gn @@ -29,9 +29,7 @@ source_set("BluetoothStackManagerSources") { ] deps = [ - "//bt/system/gd:BluetoothGeneratedDumpsysDataSchema_h", "//bt/system/gd/common:BluetoothCommonSources", - "//bt/system/gd/dumpsys/bundler:BluetoothGeneratedBundlerSchema_h_bfbs", "//bt/system/gd/hci:BluetoothHciSources", "//bt/system/gd/os:BluetoothOsSources_linux_generic", "//bt/system/gd/packet:BluetoothPacketSources", @@ -75,9 +73,7 @@ source_set("LibBluetoothShimSources") { deps = [ "//bt/sysprop:libcom.android.sysprop.bluetooth", - "//bt/system/gd:BluetoothGeneratedDumpsysDataSchema_h", "//bt/system/gd/common:BluetoothCommonSources", - "//bt/system/gd/dumpsys/bundler:BluetoothGeneratedBundlerSchema_h_bfbs", "//bt/system/gd/hci:BluetoothHciSources", "//bt/system/gd/os:BluetoothOsSources_linux_generic", "//bt/system/gd/packet:BluetoothPacketSources", diff --git a/system/main/test/main_shim_dumpsys_test.cc b/system/main/test/main_shim_dumpsys_test.cc index a61a55cda5..0670c991c6 100644 --- a/system/main/test/main_shim_dumpsys_test.cc +++ b/system/main/test/main_shim_dumpsys_test.cc @@ -30,14 +30,6 @@ using namespace bluetooth; using namespace testing; -namespace { - -constexpr char kTrue[] = "1"; -constexpr char kFalse[] = "0"; -constexpr char kReadOnlyDebuggableProperty[] = "ro.debuggable"; - -} // namespace - class MainShimDumpsysTest : public testing::Test { public: protected: @@ -55,18 +47,7 @@ protected: os::Handler* handler_{nullptr}; }; -TEST_F(MainShimDumpsysTest, dumpsys_developer) { - ASSERT_TRUE(os::SetSystemProperty(kReadOnlyDebuggableProperty, kTrue)); - - std::promise<void> promise; - auto future = promise.get_future(); - stack_manager_.GetInstance<shim::Dumpsys>()->Dump(STDOUT_FILENO, nullptr, std::move(promise)); - future.get(); -} - -TEST_F(MainShimDumpsysTest, dumpsys_user) { - ASSERT_TRUE(os::SetSystemProperty(kReadOnlyDebuggableProperty, kFalse)); - +TEST_F(MainShimDumpsysTest, dumpsys) { std::promise<void> promise; auto future = promise.get_future(); stack_manager_.GetInstance<shim::Dumpsys>()->Dump(STDOUT_FILENO, nullptr, std::move(promise)); diff --git a/system/rust/Android.bp b/system/rust/Android.bp index 04be44dbec..1ff271b6c6 100644 --- a/system/rust/Android.bp +++ b/system/rust/Android.bp @@ -127,9 +127,6 @@ cc_library_static { generated_headers: [ "cxx-bridge-header", "libbluetooth_core_rs_bridge_codegen_header", - - "BluetoothGeneratedBundlerSchema_h_bfbs", - "BluetoothGeneratedDumpsysDataSchema_h", ], export_generated_headers: [ "cxx-bridge-header", diff --git a/system/stack/Android.bp b/system/stack/Android.bp index 155dcd4208..06b2ce1587 100644 --- a/system/stack/Android.bp +++ b/system/stack/Android.bp @@ -72,9 +72,6 @@ cc_library_static { "packages/modules/Bluetooth/system/gd/hal", "packages/modules/Bluetooth/system/udrv/include", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ "a2dp/a2dp_aac.cc", "a2dp/a2dp_aac_decoder.cc", @@ -322,7 +319,6 @@ cc_library_static { "srvc/srvc_eng.cc", ], generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", "cxx-bridge-header", ], cflags: [ @@ -358,7 +354,6 @@ cc_defaults { host_supported: true, defaults: [ "bluetooth_cflags", - "bluetooth_flatbuffer_bundler_defaults", ], include_dirs: [ "packages/modules/Bluetooth/system", @@ -465,9 +460,6 @@ cc_fuzz { "packages/modules/Bluetooth/system/stack/test/common", "packages/modules/Bluetooth/system/stack/test/rfcomm", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":BluetoothPacketSources", ":TestCommonMockFunctions", @@ -519,9 +511,6 @@ cc_fuzz { "external/rust/crates/quiche/deps/boringssl/src/include", "packages/modules/Bluetooth/system/stack/btm", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":BluetoothPacketSources", ":TestCommonMockFunctions", @@ -574,9 +563,6 @@ cc_fuzz { "external/rust/crates/quiche/deps/boringssl/src/include", "packages/modules/Bluetooth/system/stack/btm", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":BluetoothPacketSources", ":TestCommonMockFunctions", @@ -623,9 +609,6 @@ cc_fuzz { "external/rust/crates/quiche/deps/boringssl/src/include", "packages/modules/Bluetooth/system/stack/btm", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":BluetoothPacketSources", ":TestCommonMockFunctions", @@ -664,9 +647,6 @@ cc_fuzz { "external/rust/crates/quiche/deps/boringssl/src/include", "packages/modules/Bluetooth/system/stack/btm", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":BluetoothPacketSources", ":TestCommonMockFunctions", @@ -714,9 +694,6 @@ cc_fuzz { "external/rust/crates/quiche/deps/boringssl/src/include", "packages/modules/Bluetooth/system/stack/btm", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":BluetoothPacketSources", ":TestCommonMockFunctions", @@ -807,7 +784,6 @@ cc_test { "bluetooth_flags_c_lib_for_test", "libFraunhoferAAC", "libbase", - "libbluetooth-dumpsys", "libbluetooth-for-tests", "libbluetooth-types", "libbluetooth_core_rs", @@ -909,9 +885,6 @@ cc_test { "test/rfcomm/stack_rfcomm_test_utils.cc", "test/rfcomm/stack_rfcomm_test_utils_test.cc", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], shared_libs: [ "libcrypto", "libcutils", @@ -957,7 +930,6 @@ cc_test { cc_test { name: "net_test_stack_smp", defaults: [ - "bluetooth_flatbuffer_bundler_defaults", "fluoride_defaults", "mts_defaults", ], @@ -998,9 +970,6 @@ cc_test { "smp/smp_utils.cc", "test/stack_smp_test.cc", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], shared_libs: [ "libaconfig_storage_read_api_cc", "libcrypto", @@ -1572,7 +1541,6 @@ cc_test { unit_test: true, }, defaults: [ - "bluetooth_flatbuffer_bundler_defaults", "fluoride_defaults", "mts_defaults", ], @@ -1581,9 +1549,6 @@ cc_test { "include", "test/common", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], include_dirs: [ "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system/gd", @@ -1634,7 +1599,6 @@ cc_test { unit_test: true, }, defaults: [ - "bluetooth_flatbuffer_bundler_defaults", "fluoride_defaults", "mts_defaults", ], @@ -1651,9 +1615,6 @@ cc_test { "packages/modules/Bluetooth/system/bta", "packages/modules/Bluetooth/system/gd", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":TestCommonMainHandler", ":TestCommonMockFunctions", @@ -1712,7 +1673,6 @@ cc_test { unit_test: true, }, defaults: [ - "bluetooth_flatbuffer_bundler_defaults", "fluoride_defaults", "mts_defaults", ], @@ -1725,9 +1685,6 @@ cc_test { "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system/gd", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":BluetoothHalSources_hci_host", ":BluetoothHalSources_ranging_host", @@ -1981,9 +1938,6 @@ cc_test { "packages/modules/Bluetooth/system/gd", "packages/modules/Bluetooth/system/stack/btm", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":TestCommonMockFunctions", ":TestMockBta", @@ -2057,9 +2011,6 @@ cc_test { "packages/modules/Bluetooth/system/gd", "packages/modules/Bluetooth/system/stack/btm", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":OsiCompatSources", ":TestCommonMainHandler", @@ -2150,7 +2101,6 @@ cc_test { test_suites: ["general-tests"], host_supported: true, defaults: [ - "bluetooth_flatbuffer_bundler_defaults", "fluoride_defaults", "mts_defaults", ], @@ -2163,9 +2113,6 @@ cc_test { "packages/modules/Bluetooth/system/gd", "packages/modules/Bluetooth/system/stack/btm", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":OsiCompatSources", ":TestCommonMainHandler", @@ -2250,7 +2197,6 @@ cc_test { test_suites: ["general-tests"], host_supported: true, defaults: [ - "bluetooth_flatbuffer_bundler_defaults", "fluoride_defaults", "mts_defaults", ], @@ -2263,9 +2209,6 @@ cc_test { "packages/modules/Bluetooth/system/gd", "packages/modules/Bluetooth/system/stack/btm", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":OsiCompatSources", ":TestCommonMainHandler", @@ -2348,7 +2291,6 @@ cc_test { unit_test: true, }, defaults: [ - "bluetooth_flatbuffer_bundler_defaults", "fluoride_defaults", "mts_defaults", ], @@ -2361,9 +2303,6 @@ cc_test { "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system/gd", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], srcs: [ ":BluetoothHalSources_hci_host", ":BluetoothHalSources_ranging_host", diff --git a/system/stack/test/fuzzers/Android.bp b/system/stack/test/fuzzers/Android.bp index af2ad8623c..30ad5a5092 100644 --- a/system/stack/test/fuzzers/Android.bp +++ b/system/stack/test/fuzzers/Android.bp @@ -38,7 +38,6 @@ cc_defaults { "android.system.suspend.control-V1-ndk", "bluetooth_flags_c_lib", "libFraunhoferAAC", - "libbluetooth-dumpsys", "libbluetooth-types", "libbluetooth_core_rs", "libbluetooth_crypto_toolbox", diff --git a/system/test/headless/Android.bp b/system/test/headless/Android.bp index ec61ea012f..09a08f8fec 100644 --- a/system/test/headless/Android.bp +++ b/system/test/headless/Android.bp @@ -82,7 +82,6 @@ cc_binary { "lib-bt-packets-base", "libFraunhoferAAC", "libbase", - "libbluetooth-dumpsys", "libbluetooth-types", "libbluetooth_core_rs", "libbluetooth_crypto_toolbox", diff --git a/system/test/suite/Android.bp b/system/test/suite/Android.bp index 98307ada71..ac4a5e3b24 100644 --- a/system/test/suite/Android.bp +++ b/system/test/suite/Android.bp @@ -65,7 +65,6 @@ cc_defaults { "lib-bt-packets-avrcp", "lib-bt-packets-base", "libFraunhoferAAC", - "libbluetooth-dumpsys", "libbluetooth-types", "libbluetooth_core_rs", "libbluetooth_core_rs_bridge", @@ -142,9 +141,6 @@ cc_test { "libbinder", "server_configurable_flags", ], - generated_headers: [ - "BluetoothGeneratedDumpsysDataSchema_h", - ], target: { android: { static_libs: [ |