diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000000000000000000000000000000000000..b49e6481e6702c1a05871d013296ccd86777936a
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,11 @@
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 4
+
+[*.{cc,cpp,c,h}]
+indent_size = 2
diff --git a/.gitignore b/.gitignore
index 0bf0233c1990e1cb17e45b7d29206cc01be0d613..3e6891d63f92bc5e07030d36e1c14e83d8b368ef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,6 @@ compile_commands.json
.vscode/
*.profraw
*.iml
+**/.idea
+**/__pycache__/
+*.py[cod]
diff --git a/Android.bp b/Android.bp
index beaeb680cbb3a0d1a2659b633f5f16c869a8a733..d585c6c9ca8ca57197d8b9b4ebd8f333271eb60b 100644
--- a/Android.bp
+++ b/Android.bp
@@ -38,26 +38,37 @@ filegroup {
],
}
-filegroup {
- name: "BluetoothGTestForce32ConfigTemplate",
- srcs: [
- "AndroidGTestForce32Template.xml",
- ],
-}
-
-// Address Sanitizer is flaky on Android x86_64 binaries but it's not on x86
-// binaries.
-// This default workaround the x86_64 ASAN flakyness by running 32bit binaries
-// on 64bit targets.
-// TODO(b/154347133): Remove this workaround
+// This default contains properties that should be common to all the cc targets
+// developed by the Bluetooth team.
+//
+// Be careful when adding new properties here:
+// - The option should not impact negatively any target, for example "-Wno-*"
+// options should not be added here but instead on every targets needing
+// them to avoid allowing adding new warnings in targets that didn't contained
+// them (you can use the bpmodify tool to ease the work of adding this warning
+// everywhere) and also allows cleaning them one at a time.
+//
+// - The option should apply to all the c/c++ code developed by the Bluetooth team:
+// test, tools, fuzzers, etc, not only production targets, if you need to add an option
+// for a subset of Bluetooth cc targets you should look at the defaults including this
+// defaults like "fluoride_defaults" and "gd_defaults".
+//
+// - Try to keep the name as precise as possible to document to the dependent of what
+// this default contains. This also means that if you add a new option that isn't
+// documented by the name of this default, rename it.
+//
+// - Try avoiding adding option that would not fit "future" targets, for exemple dependencies,
+// even if every modules of Bluetooth depends on a specific dependency it should be left out
+// from this default to not push it for future targets that might not need it.
cc_defaults {
- name: "bluetooth_gtest_x86_asan_workaround",
- target: {
- android_x86: {
- test_config_template: ":BluetoothGTestForce32ConfigTemplate",
- },
- android_x86_64: {
- enabled: false,
- },
- },
+ name: "bluetooth_cflags",
+ cflags: [
+ "-Wall",
+ "-Werror",
+ "-Wextra",
+ // Override global.go that demote the error to a warning
+ "-Werror=reorder-init-list",
+ ],
+ c_std: "c99",
+ cpp_std: "c++17",
}
diff --git a/AndroidGTestForce32Template.xml b/AndroidGTestForce32Template.xml
deleted file mode 100644
index bad033a2936f8689537a4494113e1d4741e1ebe4..0000000000000000000000000000000000000000
--- a/AndroidGTestForce32Template.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Cargo.toml b/Cargo.toml
index e9fef56c38600ba8ec2b0e48d6976b1ca2e592cd..341abaa58307203bbd1ea63793218ba57603ffd3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,7 +20,9 @@ default-members = [
"system/gd/rust/topshim",
"system/gd/rust/linux/mgmt",
"system/gd/rust/linux/service",
+ "system/gd/rust/linux/stack",
"system/gd/rust/linux/client",
+ "system/gd/rust/linux/utils",
]
members = [
@@ -28,6 +30,8 @@ members = [
"system/gd/rust/topshim",
"system/gd/rust/linux/mgmt",
"system/gd/rust/linux/service",
+ "system/gd/rust/linux/stack",
"system/gd/rust/linux/client",
+ "system/gd/rust/linux/utils",
"floss/hcidoc",
]
diff --git a/OWNERS b/OWNERS
index fa4d5e7243ce97fcc35717bc103990984c0c20cb..6511a489aab972db7afd8835fac5cfbedb9b46e8 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,3 +1,5 @@
+# Bug component: 27441
+
# Project owners
girardier@google.com #{LAST_RESORT_SUGGESTION}
muhammadfalam@google.com #{LAST_RESORT_SUGGESTION}
@@ -7,8 +9,8 @@ sungsoo@google.com #{LAST_RESORT_SUGGESTION}
# Per-file ownership
-per-file *.bp,*.xml=wescande@google.com
-per-file TEST_MAPPING,*.bp,*.xml=licorne@google.com
+# Build files / test_config / presubmit / preupload
+per-file PREUPLOAD.cfg,TEST_MAPPING,*.bp,*.xml=file:/OWNERS_build
# ChromeOS team owns Linux build files
# - build.py is used for Linux build
diff --git a/OWNERS_automotive b/OWNERS_automotive
index 7ecd87651514786390f1d59eb88e120fc34a59ab..267d177006f5c4a8de6456c310087021d1195555 100644
--- a/OWNERS_automotive
+++ b/OWNERS_automotive
@@ -1,3 +1,2 @@
# Project owners
-pirozzoj@google.com
salsavage@google.com
diff --git a/OWNERS_build b/OWNERS_build
new file mode 100644
index 0000000000000000000000000000000000000000..263e0532b6ba983665554ebbeb49c3c0540039df
--- /dev/null
+++ b/OWNERS_build
@@ -0,0 +1,2 @@
+licorne@google.com
+wescande@google.com
diff --git a/OWNERS_chromeos b/OWNERS_chromeos
index 2bc73f23088758220be1f5c2a60f43e2656fe0e5..0280ec47df9af042be2674c2d55beaeb5ceb43cc 100644
--- a/OWNERS_chromeos
+++ b/OWNERS_chromeos
@@ -5,6 +5,8 @@ sonnysasaka@google.com
# Audio
enshuo@google.com
hychao@google.com
+jrwu@google.com
+whalechang@google.com
# General review
michaelfsun@google.com
diff --git a/OWNERS_hearingaid b/OWNERS_hearingaid
new file mode 100644
index 0000000000000000000000000000000000000000..09f245c2fcca2b51b7bb92e2f0d95d318f0ace8f
--- /dev/null
+++ b/OWNERS_hearingaid
@@ -0,0 +1,2 @@
+charliebout@google.com
+licorne@google.com
diff --git a/OWNERS_leaudio b/OWNERS_leaudio
new file mode 100644
index 0000000000000000000000000000000000000000..30db38d7995a5464633021e6f1f61d743d5e8eb1
--- /dev/null
+++ b/OWNERS_leaudio
@@ -0,0 +1,3 @@
+siyuanh@google.com
+jpawlowski@google.com
+rongxuan@google.com
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index a5534dafc06225a6a2786565c43ea02488a40b04..dd650a05874e00400782eceba784fc01f2a47f14 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -2,7 +2,6 @@
ignore_merged_commits = true
[Builtin Hooks]
-aidl_format = true
commit_msg_bug_field = true
google_java_format = true
clang_format = true
@@ -15,6 +14,7 @@ rustfmt = --config-path=rustfmt.toml
# Only turn on clang-format check for C and C++ headers and sources
clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp,hpp
ktfmt = --kotlinlang-style
+bpfmt = -s
[Hook Scripts]
checkstyle_hook = ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT}
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 278530e4779842cf3c7f5575038a8987ad82a8df..4e568c8a98c06c3a7713d86f40c1649b3667f671 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -7,15 +7,16 @@
{
"name": "BluetoothInstrumentationTests"
},
- //{
- // "name": "GoogleBluetoothInstrumentationTests"
- //},
- //{
- // "name": "FrameworkBluetoothTests"
- //},
- //{
- // "name": "ServiceBluetoothTests"
- //},
+ {
+ "name": "GoogleBluetoothInstrumentationTests",
+ "keywords": ["internal"]
+ },
+ {
+ "name": "FrameworkBluetoothTests"
+ },
+ {
+ "name": "ServiceBluetoothTests"
+ },
// device only tests
// Broken
//{
@@ -69,9 +70,6 @@
{
"name": "net_test_stack_ad_parser"
},
- {
- "name": "net_test_stack_multi_adv"
- },
// go/a-unit-tests tests (unit_test: true)
// Thoses test run on the host in the CI automatically.
// Run the one that are available on the device on the
@@ -118,9 +116,6 @@
{
"name": "bluetooth_vc_test"
},
- {
- "name": "bt_host_test_bta"
- },
{
"name": "libaptx_enc_tests"
},
@@ -154,9 +149,6 @@
{
"name": "net_test_eatt"
},
- {
- "name": "net_test_hci_fragmenter_native"
- },
{
"name": "net_test_main_shim"
},
@@ -220,15 +212,15 @@
{
"name": "BluetoothInstrumentationTests"
},
- //{
- // "name": "GoogleBluetoothInstrumentationTests"
- //},
- //{
- // "name": "FrameworkBluetoothTests"
- //},
- //{
- // "name": "ServiceBluetoothTests"
- //},
+ {
+ "name": "GoogleBluetoothInstrumentationTests"
+ },
+ {
+ "name": "FrameworkBluetoothTests"
+ },
+ {
+ "name": "ServiceBluetoothTests"
+ },
// device only tests
// Broken
//{
@@ -270,160 +262,72 @@
{
"name": "net_test_gatt_conn_multiplexing"
},
- {
- "name": "net_test_hci"
- },
{
"name": "net_test_stack"
},
- {
- "name": "net_test_stack_a2dp_codecs_native"
- },
{
"name": "net_test_stack_ad_parser"
},
- {
- "name": "net_test_stack_multi_adv"
- },
// go/a-unit-tests tests (unit_test: true)
// Thoses test run on the host in the CI automatically.
// Run the one that are available on the device on the
// device as well
- {
- "name": "bluetooth_csis_test"
- },
{
"name": "bluetooth_flatbuffer_tests"
},
- {
- "name": "bluetooth_groups_test"
- },
- {
- "name": "bluetooth_has_test"
- },
- {
- "name": "bluetooth_hh_test"
- },
- {
- "name": "bluetooth_le_audio_client_test"
- },
// b/271319421
// {
// "name": "bluetooth_le_audio_test"
// },
- {
- "name": "bluetooth_packet_parser_test"
- },
- {
- "name": "bluetooth_test_broadcaster"
- },
- {
- "name": "bluetooth_test_broadcaster_state_machine"
- },
{
"name": "bluetooth_test_common"
},
- {
- "name": "bluetooth_test_gd_unit"
- },
{
"name": "bluetooth_test_sdp"
},
{
"name": "bluetooth_vc_test"
},
- {
- "name": "bt_host_test_bta"
- },
- {
- "name": "libaptx_enc_tests"
- },
- {
- "name": "libaptxhd_enc_tests"
- },
{
"name": "net_test_avrcp"
},
- {
- "name": "net_test_btcore"
- },
{
"name": "net_test_btif_config_cache"
},
- {
- "name": "net_test_btif_hh"
- },
- {
- "name": "net_test_btif_rc"
- },
- {
- "name": "net_test_btif_stack"
- },
- {
- "name": "net_test_btm_iso"
- },
{
"name": "net_test_btpackets"
},
{
"name": "net_test_eatt"
},
- {
- "name": "net_test_hci_fragmenter_native"
- },
- {
- "name": "net_test_main_shim"
- },
- {
- "name": "net_test_osi"
- },
{
"name": "net_test_performance"
},
- {
- "name": "net_test_stack_a2dp_native"
- },
- {
- "name": "net_test_stack_acl"
- },
- {
- "name": "net_test_stack_avdtp"
- },
- {
- "name": "net_test_stack_btm"
- },
- {
- "name": "net_test_stack_btu"
- },
- {
- "name": "net_test_stack_gatt"
- },
- {
- "name": "net_test_stack_gatt_native"
- },
{
"name": "net_test_stack_gatt_sr_hash_native"
},
{
- "name": "net_test_stack_hci"
+ "name": "net_test_stack_rfcomm"
},
{
- "name": "net_test_stack_hid"
+ "name": "net_test_stack_sdp"
},
{
- "name": "net_test_stack_l2cap"
+ "name": "net_test_stack_smp"
},
{
- "name": "net_test_stack_rfcomm"
- },
+ "name": "net_test_types"
+ }
+ ],
+ "postsubmit": [
{
- "name": "net_test_stack_sdp"
+ "name": "bluetooth_le_audio_codec_manager_test"
},
{
- "name": "net_test_stack_smp"
+ "name": "bluetooth_test_gdx_unit"
},
{
- "name": "net_test_types"
+ "name": "asrc_resampler_test"
}
]
}
diff --git a/android/BluetoothLegacyMigration/OWNERS b/android/BluetoothLegacyMigration/OWNERS
index 8f5c903d7e8759d22a59ff162a43fd73a6309d16..fad553d703c19b3439dac3133d1a68a31fe97eae 100644
--- a/android/BluetoothLegacyMigration/OWNERS
+++ b/android/BluetoothLegacyMigration/OWNERS
@@ -1,8 +1,6 @@
# Reviewers for /android/BluetoothLegacyMigration
eruffieux@google.com
-rahulsabnis@google.com
sattiraju@google.com
siyuanh@google.com
wescande@google.com
-zachoverflow@google.com
diff --git a/android/apishim/OWNERS b/android/apishim/OWNERS
index c0cdca9fa575b927cacc5f9e3e6096910e61a078..231e3b66efe9f7124405655024df5ff1dcc6a261 100644
--- a/android/apishim/OWNERS
+++ b/android/apishim/OWNERS
@@ -1,13 +1,9 @@
# Reviewers for /android/apishim
cmanton@google.com
-cncn@google.com
eruffieux@google.com
jpawlowski@google.com
mylesgw@google.com
-optedoblivion@google.com
-qasimj@google.com
-rahulsabnis@google.com
sattiraju@google.com
siyuanh@google.com
wescande@google.com
\ No newline at end of file
diff --git a/android/app/Android.bp b/android/app/Android.bp
index 4e5e6845a07bb6e496ae6f1920ba1cd963b71a91..1d43cfefa3445f04077b9f95e0a66543e8dbac17 100644
--- a/android/app/Android.bp
+++ b/android/app/Android.bp
@@ -55,8 +55,14 @@ java_library {
cc_library_shared {
name: "libbluetooth_jni",
- defaults: ["fluoride_basic_defaults"],
+ defaults: [
+ "fluoride_defaults",
+ "latest_android_hardware_audio_common_ndk_static",
+ "latest_android_hardware_bluetooth_audio_ndk_static",
+ "latest_android_media_audio_common_types_ndk_static",
+ ],
srcs: ["jni/**/*.cpp"],
+ version_script: "libbluetooth_jni.map",
header_libs: [
"jni_headers",
"libbluetooth_headers",
@@ -66,22 +72,49 @@ cc_library_shared {
"packages/modules/Bluetooth/system/gd",
"packages/modules/Bluetooth/system/types",
],
+ // libbluetooth_jni is the jni lib included in the btservices apex.
+ // As this library is inside an APEX the shared_libs that does not
+ // expose stubs are copied inside it. As a result using those as
+ // shared libraries is less interesting as they are not shared, so we link
+ // them statically to allow the linker to perform more optimisation.
+ //
+ // The only exception to this is libcrypto because the shared version
+ // is required to maintain FIPS compliance.
+ stl: "libc++_static",
static_libs: [
+ "android.hardware.audio.common@5.0",
+ "android.hardware.bluetooth.audio@2.0",
+ "android.hardware.bluetooth.audio@2.1",
+ "android.hardware.bluetooth@1.0",
+ "android.hardware.bluetooth@1.1",
+ "android.hardware.common-V2-ndk",
+ "android.hardware.common.fmq-V1-ndk",
+ "android.system.suspend-V1-ndk",
+ "android.system.suspend.control-V1-ndk",
"avrcp-target-service",
"lib-bt-packets-avrcp",
"lib-bt-packets-base",
+ "libFraunhoferAAC",
"libaudio-a2dp-hw-utils",
+ "libbase",
"libbluetooth",
+ "libbluetooth-dumpsys",
"libbluetooth-types",
"libbluetooth_core_rs",
"libbluetooth_core_rs_bridge",
+ "libbluetooth_crypto_toolbox",
+ "libbluetooth_gd",
"libbt-audio-hal-interface",
"libbt-bta",
"libbt-bta-core",
+ "libbt-btu-main-thread",
"libbt-common",
"libbt-hci",
+ "libbt-sbc-decoder",
+ "libbt-sbc-encoder",
"libbt-stack",
"libbt-stack-core",
+ "libbt_shim_bridge",
"libbtcore",
"libbtdevice",
"libbte",
@@ -89,14 +122,30 @@ cc_library_shared {
"libbtif-core",
"libc++fs",
"libchrome",
+ "libcutils",
"libevent",
+ "libflatbuffers-cpp",
+ "libfmq",
+ "libg722codec",
+ "libhidlbase",
+ "liblc3",
"libmodpb64",
+ "libopus",
"libosi",
+ "libprotobuf-cpp-lite",
+ "libstatslog_bt",
+ "libudrv-uipc",
+ "libutils",
+ "server_configurable_flags",
],
shared_libs: [
- "android.hardware.bluetooth.audio-V3-ndk",
- "android.hardware.bluetooth@1.0",
- "android.hardware.bluetooth@1.1",
+ "libaaudio",
+ "libbinder_ndk",
+ "libcrypto",
+ "liblog",
+ "libnativehelper",
+ "libstatssocket",
+ "libvndksupport",
],
sanitize: {
scs: true,
@@ -109,7 +158,7 @@ cc_library_shared {
cc_library {
name: "libbluetooth-core",
- defaults: ["fluoride_basic_defaults"],
+ defaults: ["fluoride_defaults"],
header_libs: [
"jni_headers",
"libbluetooth_headers",
@@ -160,8 +209,13 @@ android_app {
srcs: [
":statslog-bluetooth-java-gen",
":statslog-bt-restricted-java-gen",
+ ":system-messages-proto-src",
+ "proto/keystore.proto",
"src/**/*.java",
],
+ proto: {
+ type: "lite",
+ },
aaptflags: [
"--custom-package",
"com.android.bluetooth",
@@ -169,6 +223,7 @@ android_app {
certificate: "bluetooth",
jarjar_rules: ":bluetooth-jarjar-rules",
+ privapp_allowlist: ":privapp_allowlist_com.android.bluetooth.xml",
jni_uses_platform_apis: true,
libs: [
@@ -178,12 +233,17 @@ android_app {
"framework-bluetooth-pre-jarjar",
"framework-configinfrastructure",
"framework-connectivity.stubs.module_lib",
+ "framework-location.stubs.module_lib",
"framework-mediaprovider",
"framework-statsd.stubs.module_lib",
"framework-tethering.stubs.module_lib",
"unsupportedappusage",
+
+ // Need to link the class at runtime
+ "framework-bluetooth",
],
static_libs: [
+ "BluetoothApiShims",
"android.hardware.radio-V1.0-java",
"android.hardware.radio.sap-V1-java",
"androidx.annotation_annotation",
@@ -191,11 +251,11 @@ android_app {
"androidx.lifecycle_lifecycle-livedata",
"androidx.media_media",
"androidx.room_room-runtime",
- "BluetoothApiShims",
"bluetooth-proto-enums-java-gen",
"bluetooth-protos-lite",
"bluetooth.change-ids",
"bluetooth.mapsapi",
+ "bluetooth_flags_java_lib",
"com.android.obex",
"com.android.vcard",
"guava",
@@ -204,7 +264,6 @@ android_app {
"modules-utils-backgroundthread",
"modules-utils-bytesmatcher",
"modules-utils-statemachine",
- "modules-utils-synchronous-result-receiver",
"net-utils-services-common",
"networkstack-client",
"sap-api-java-static",
@@ -214,13 +273,32 @@ android_app {
"androidx.room_room-compiler-plugin",
],
- // Add in path to Bluetooth directory because local path does not exist
+ // Export schemas to the test directory so that we have an history
+ // to be able to test migrations
+ // The following path is absolute because a relative path doesn't work
+ // TODO(b/147596836): Refactor this
javacflags: ["-Aroom.schemaLocation=packages/modules/Bluetooth/android/app/tests/unit/src/com/android/bluetooth/btservice/storage/schemas"],
+ lint: {
+ error_checks: [
+ "ExtraText",
+ "MissingClass",
+ "NewApi",
+ "ObsoleteSdkInt",
+ "Recycle",
+ "RtlHardcoded",
+ "UseSparseArrays",
+ "UseValueOf",
+ ],
+ strict_updatability_linting: true,
+ },
+
optimize: {
enabled: true,
shrink: true,
optimize: false,
+ // TODO(b/289285719): Revisit after resolving mocking issues in testing.
+ proguard_compatibility: true,
proguard_flags_files: ["proguard.flags"],
},
apex_available: [
diff --git a/android/app/AndroidManifest.xml b/android/app/AndroidManifest.xml
index bdcc793aac448b045fe8c41fe478be9f5a625acc..3e07cc5b0f58da57d85960c1436b8b34b8b55d36 100644
--- a/android/app/AndroidManifest.xml
+++ b/android/app/AndroidManifest.xml
@@ -103,6 +103,16 @@
+
+
+
+
+
+
-
-
-
-
-
-
-
-
@@ -442,7 +440,7 @@
android:process="@string/process"
android:excludeFromRecents="true"
android:theme="@style/dialog"
- android:enabled="false">>
+ android:enabled="false">
GetMethodID(clazz, "bqrDeliver", "([BIII[B)V");
-
- LOG(INFO) << __func__ << ": succeeds";
-}
-
static void initNative(JNIEnv* env, jobject object) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -131,7 +125,7 @@ static void initNative(JNIEnv* env, jobject object) {
sBluetoothQualityReportInterface->init(&sBluetoothQualityReportCallbacks);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -151,17 +145,28 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative", "()V", (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
-};
-
int register_com_android_bluetooth_btservice_BluetoothQualityReport(
JNIEnv* env) {
- return jniRegisterNativeMethods(env,
- "com/android/bluetooth/btservice/"
- "BluetoothQualityReportNativeInterface",
- sMethods, NELEM(sMethods));
+ const JNINativeMethod methods[] = {
+ {"initNative", "()V", (void*)initNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env,
+ "com/android/bluetooth/btservice/BluetoothQualityReportNativeInterface",
+ methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"bqrDeliver", "([BIII[B)V", &method_bqrDeliver},
+ };
+ GET_JAVA_METHODS(
+ env,
+ "com/android/bluetooth/btservice/BluetoothQualityReportNativeInterface",
+ javaMethods);
+
+ return 0;
}
} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_a2dp.cpp b/android/app/jni/com_android_bluetooth_a2dp.cpp
index 991bc1b69493fb80e296b36206d793e704047536..c2427e10bf04ae2dc0ce21f64aae627c65bfc063 100644
--- a/android/app/jni/com_android_bluetooth_a2dp.cpp
+++ b/android/app/jni/com_android_bluetooth_a2dp.cpp
@@ -51,7 +51,7 @@ static std::shared_timed_mutex callbacks_mutex;
static void bta2dp_connection_state_callback(const RawAddress& bd_addr,
btav_connection_state_t state,
- const btav_error_t& error) {
+ const btav_error_t& /* error */) {
ALOGI("%s", __func__);
std::shared_lock lock(callbacks_mutex);
@@ -191,50 +191,8 @@ static btav_source_callbacks_t sBluetoothA2dpCallbacks = {
bta2dp_mandatory_codec_preferred_callback,
};
-static void classInitNative(JNIEnv* env, jclass clazz) {
- jclass jniBluetoothCodecConfigClass =
- env->FindClass("android/bluetooth/BluetoothCodecConfig");
- android_bluetooth_BluetoothCodecConfig.constructor =
- env->GetMethodID(jniBluetoothCodecConfigClass, "", "(IIIIIJJJJ)V");
- android_bluetooth_BluetoothCodecConfig.getCodecType =
- env->GetMethodID(jniBluetoothCodecConfigClass, "getCodecType", "()I");
- android_bluetooth_BluetoothCodecConfig.getCodecPriority =
- env->GetMethodID(jniBluetoothCodecConfigClass, "getCodecPriority", "()I");
- android_bluetooth_BluetoothCodecConfig.getSampleRate =
- env->GetMethodID(jniBluetoothCodecConfigClass, "getSampleRate", "()I");
- android_bluetooth_BluetoothCodecConfig.getBitsPerSample =
- env->GetMethodID(jniBluetoothCodecConfigClass, "getBitsPerSample", "()I");
- android_bluetooth_BluetoothCodecConfig.getChannelMode =
- env->GetMethodID(jniBluetoothCodecConfigClass, "getChannelMode", "()I");
- android_bluetooth_BluetoothCodecConfig.getCodecSpecific1 = env->GetMethodID(
- jniBluetoothCodecConfigClass, "getCodecSpecific1", "()J");
- android_bluetooth_BluetoothCodecConfig.getCodecSpecific2 = env->GetMethodID(
- jniBluetoothCodecConfigClass, "getCodecSpecific2", "()J");
- android_bluetooth_BluetoothCodecConfig.getCodecSpecific3 = env->GetMethodID(
- jniBluetoothCodecConfigClass, "getCodecSpecific3", "()J");
- android_bluetooth_BluetoothCodecConfig.getCodecSpecific4 = env->GetMethodID(
- jniBluetoothCodecConfigClass, "getCodecSpecific4", "()J");
-
- method_onConnectionStateChanged =
- env->GetMethodID(clazz, "onConnectionStateChanged", "([BI)V");
-
- method_onAudioStateChanged =
- env->GetMethodID(clazz, "onAudioStateChanged", "([BI)V");
-
- method_onCodecConfigChanged =
- env->GetMethodID(clazz, "onCodecConfigChanged",
- "([BLandroid/bluetooth/BluetoothCodecConfig;"
- "[Landroid/bluetooth/BluetoothCodecConfig;"
- "[Landroid/bluetooth/BluetoothCodecConfig;)V");
-
- method_isMandatoryCodecPreferred =
- env->GetMethodID(clazz, "isMandatoryCodecPreferred", "([B)Z");
-
- ALOGI("%s: succeeds", __func__);
-}
-
static std::vector prepareCodecPreferences(
- JNIEnv* env, jobject object, jobjectArray codecConfigArray) {
+ JNIEnv* env, jobject /* object */, jobjectArray codecConfigArray) {
std::vector codec_preferences;
int numConfigs = env->GetArrayLength(codecConfigArray);
@@ -347,7 +305,7 @@ static void initNative(JNIEnv* env, jobject object,
}
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -371,7 +329,52 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static jboolean connectA2dpNative(JNIEnv* env, jobject object,
+static jobjectArray getSupportedCodecTypesNative(JNIEnv* env) {
+ ALOGI("%s: %p", __func__, sBluetoothA2dpInterface);
+
+ jclass android_bluetooth_BluetoothCodecType_clazz = (jclass)env->NewGlobalRef(
+ env->FindClass("android/bluetooth/BluetoothCodecType"));
+ if (android_bluetooth_BluetoothCodecType_clazz == nullptr) {
+ ALOGE("%s: Failed to allocate Global Ref for BluetoothCodecType class",
+ __func__);
+ return nullptr;
+ }
+
+ jmethodID createFromType = env->GetStaticMethodID(
+ android_bluetooth_BluetoothCodecType_clazz, "createFromType",
+ "(I)Landroid/bluetooth/BluetoothCodecType;");
+ if (createFromType == nullptr) {
+ ALOGE(
+ "%s: Failed to find method createFromType of BluetoothCodecType class",
+ __func__);
+ return nullptr;
+ }
+
+ std::array default_supported_codecs = {
+ BTAV_A2DP_CODEC_INDEX_SOURCE_SBC, BTAV_A2DP_CODEC_INDEX_SOURCE_AAC,
+ BTAV_A2DP_CODEC_INDEX_SOURCE_APTX, BTAV_A2DP_CODEC_INDEX_SOURCE_APTX_HD,
+ BTAV_A2DP_CODEC_INDEX_SOURCE_LDAC, BTAV_A2DP_CODEC_INDEX_SOURCE_OPUS,
+ };
+ jobjectArray result =
+ env->NewObjectArray(default_supported_codecs.size(),
+ android_bluetooth_BluetoothCodecType_clazz, nullptr);
+ if (result == nullptr) {
+ ALOGE("%s: Failed to allocate result array of BluetoothCodecType",
+ __func__);
+ return nullptr;
+ }
+
+ for (size_t index = 0; index < default_supported_codecs.size(); index++) {
+ jobject codec_type = env->CallStaticObjectMethod(
+ android_bluetooth_BluetoothCodecType_clazz, createFromType,
+ (jint)default_supported_codecs[index]);
+ env->SetObjectArrayElement(result, index, codec_type);
+ }
+
+ return result;
+}
+
+static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
std::shared_lock lock(interface_mutex);
@@ -396,7 +399,7 @@ static jboolean connectA2dpNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean disconnectA2dpNative(JNIEnv* env, jobject object,
+static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
std::shared_lock lock(interface_mutex);
@@ -421,7 +424,7 @@ static jboolean disconnectA2dpNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean setSilenceDeviceNative(JNIEnv* env, jobject object,
+static jboolean setSilenceDeviceNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jboolean silence) {
ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
std::shared_lock lock(interface_mutex);
@@ -448,7 +451,7 @@ static jboolean setSilenceDeviceNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean setActiveDeviceNative(JNIEnv* env, jobject object,
+static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
std::shared_lock lock(interface_mutex);
@@ -501,24 +504,68 @@ static jboolean setCodecConfigPreferenceNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative",
- "(I[Landroid/bluetooth/BluetoothCodecConfig;[Landroid/bluetooth/BluetoothCodecConfig;)V",
- (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"connectA2dpNative", "([B)Z", (void*)connectA2dpNative},
- {"disconnectA2dpNative", "([B)Z", (void*)disconnectA2dpNative},
- {"setSilenceDeviceNative", "([BZ)Z", (void*)setSilenceDeviceNative},
- {"setActiveDeviceNative", "([B)Z", (void*)setActiveDeviceNative},
- {"setCodecConfigPreferenceNative",
- "([B[Landroid/bluetooth/BluetoothCodecConfig;)Z",
- (void*)setCodecConfigPreferenceNative},
-};
-
int register_com_android_bluetooth_a2dp(JNIEnv* env) {
- return jniRegisterNativeMethods(
- env, "com/android/bluetooth/a2dp/A2dpNativeInterface", sMethods,
- NELEM(sMethods));
+ const JNINativeMethod methods[] = {
+ {"initNative",
+ "(I[Landroid/bluetooth/BluetoothCodecConfig;"
+ "[Landroid/bluetooth/BluetoothCodecConfig;)V",
+ (void*)initNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"getSupportedCodecTypesNative",
+ "()[Landroid/bluetooth/BluetoothCodecType;",
+ (void*)getSupportedCodecTypesNative},
+ {"connectA2dpNative", "([B)Z", (void*)connectA2dpNative},
+ {"disconnectA2dpNative", "([B)Z", (void*)disconnectA2dpNative},
+ {"setSilenceDeviceNative", "([BZ)Z", (void*)setSilenceDeviceNative},
+ {"setActiveDeviceNative", "([B)Z", (void*)setActiveDeviceNative},
+ {"setCodecConfigPreferenceNative",
+ "([B[Landroid/bluetooth/BluetoothCodecConfig;)Z",
+ (void*)setCodecConfigPreferenceNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/a2dp/A2dpNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onConnectionStateChanged", "([BI)V", &method_onConnectionStateChanged},
+ {"onAudioStateChanged", "([BI)V", &method_onAudioStateChanged},
+ {"onCodecConfigChanged",
+ "([BLandroid/bluetooth/BluetoothCodecConfig;"
+ "[Landroid/bluetooth/BluetoothCodecConfig;"
+ "[Landroid/bluetooth/BluetoothCodecConfig;)V",
+ &method_onCodecConfigChanged},
+ {"isMandatoryCodecPreferred", "([B)Z", &method_isMandatoryCodecPreferred},
+ };
+ GET_JAVA_METHODS(env, "com/android/bluetooth/a2dp/A2dpNativeInterface",
+ javaMethods);
+
+ const JNIJavaMethod codecConfigCallbacksMethods[] = {
+ {"", "(IIIIIJJJJ)V",
+ &android_bluetooth_BluetoothCodecConfig.constructor},
+ {"getCodecType", "()I",
+ &android_bluetooth_BluetoothCodecConfig.getCodecType},
+ {"getCodecPriority", "()I",
+ &android_bluetooth_BluetoothCodecConfig.getCodecPriority},
+ {"getSampleRate", "()I",
+ &android_bluetooth_BluetoothCodecConfig.getSampleRate},
+ {"getBitsPerSample", "()I",
+ &android_bluetooth_BluetoothCodecConfig.getBitsPerSample},
+ {"getChannelMode", "()I",
+ &android_bluetooth_BluetoothCodecConfig.getChannelMode},
+ {"getCodecSpecific1", "()J",
+ &android_bluetooth_BluetoothCodecConfig.getCodecSpecific1},
+ {"getCodecSpecific2", "()J",
+ &android_bluetooth_BluetoothCodecConfig.getCodecSpecific2},
+ {"getCodecSpecific3", "()J",
+ &android_bluetooth_BluetoothCodecConfig.getCodecSpecific3},
+ {"getCodecSpecific4", "()J",
+ &android_bluetooth_BluetoothCodecConfig.getCodecSpecific4},
+ };
+ GET_JAVA_METHODS(env, "android/bluetooth/BluetoothCodecConfig",
+ codecConfigCallbacksMethods);
+
+ return 0;
}
}
diff --git a/android/app/jni/com_android_bluetooth_a2dp_sink.cpp b/android/app/jni/com_android_bluetooth_a2dp_sink.cpp
index 2419e4e45e9f8bdc5b0c8926541bed5d39e02a02..d2abfb6055a0c09fa3e7b6869698c2a525b43358 100644
--- a/android/app/jni/com_android_bluetooth_a2dp_sink.cpp
+++ b/android/app/jni/com_android_bluetooth_a2dp_sink.cpp
@@ -34,9 +34,9 @@ static const btav_sink_interface_t* sBluetoothA2dpInterface = NULL;
static jobject mCallbacksObj = NULL;
static std::shared_timed_mutex callbacks_mutex;
-static void a2dp_sink_connection_state_callback(const RawAddress& bd_addr,
- btav_connection_state_t state,
- const btav_error_t& error) {
+static void a2dp_sink_connection_state_callback(
+ const RawAddress& bd_addr, btav_connection_state_t state,
+ const btav_error_t& /* error */) {
ALOGI("%s", __func__);
std::shared_lock lock(callbacks_mutex);
if (!mCallbacksObj) return;
@@ -110,19 +110,6 @@ static btav_sink_callbacks_t sBluetoothA2dpCallbacks = {
a2dp_sink_audio_config_callback,
};
-static void classInitNative(JNIEnv* env, jclass clazz) {
- method_onConnectionStateChanged =
- env->GetMethodID(clazz, "onConnectionStateChanged", "([BI)V");
-
- method_onAudioStateChanged =
- env->GetMethodID(clazz, "onAudioStateChanged", "([BI)V");
-
- method_onAudioConfigChanged =
- env->GetMethodID(clazz, "onAudioConfigChanged", "([BII)V");
-
- ALOGI("%s: succeeds", __func__);
-}
-
static void initNative(JNIEnv* env, jobject object,
jint maxConnectedAudioDevices) {
std::unique_lock lock(callbacks_mutex);
@@ -164,7 +151,7 @@ static void initNative(JNIEnv* env, jobject object,
mCallbacksObj = env->NewGlobalRef(object);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock lock(callbacks_mutex);
const bt_interface_t* btInf = getBluetoothInterface();
@@ -184,7 +171,7 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static jboolean connectA2dpNative(JNIEnv* env, jobject object,
+static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
ALOGI("%s: sBluetoothA2dpInterface: %p", __func__, sBluetoothA2dpInterface);
if (!sBluetoothA2dpInterface) return JNI_FALSE;
@@ -205,7 +192,7 @@ static jboolean connectA2dpNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean disconnectA2dpNative(JNIEnv* env, jobject object,
+static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
if (!sBluetoothA2dpInterface) return JNI_FALSE;
@@ -225,19 +212,19 @@ static jboolean disconnectA2dpNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static void informAudioFocusStateNative(JNIEnv* env, jobject object,
+static void informAudioFocusStateNative(JNIEnv* /* env */, jobject /* object */,
jint focus_state) {
if (!sBluetoothA2dpInterface) return;
sBluetoothA2dpInterface->set_audio_focus_state((uint8_t)focus_state);
}
-static void informAudioTrackGainNative(JNIEnv* env, jobject object,
+static void informAudioTrackGainNative(JNIEnv* /* env */, jobject /* object */,
jfloat gain) {
if (!sBluetoothA2dpInterface) return;
sBluetoothA2dpInterface->set_audio_track_gain((float)gain);
}
-static jboolean setActiveDeviceNative(JNIEnv* env, jobject object,
+static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
if (!sBluetoothA2dpInterface) return JNI_FALSE;
@@ -260,20 +247,32 @@ static jboolean setActiveDeviceNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative", "(I)V", (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"connectA2dpNative", "([B)Z", (void*)connectA2dpNative},
- {"disconnectA2dpNative", "([B)Z", (void*)disconnectA2dpNative},
- {"informAudioFocusStateNative", "(I)V", (void*)informAudioFocusStateNative},
- {"informAudioTrackGainNative", "(F)V", (void*)informAudioTrackGainNative},
- {"setActiveDeviceNative", "([B)Z", (void*)setActiveDeviceNative},
-};
-
int register_com_android_bluetooth_a2dp_sink(JNIEnv* env) {
- return jniRegisterNativeMethods(
- env, "com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface", sMethods,
- NELEM(sMethods));
+ const JNINativeMethod methods[] = {
+ {"initNative", "(I)V", (void*)initNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"connectA2dpNative", "([B)Z", (void*)connectA2dpNative},
+ {"disconnectA2dpNative", "([B)Z", (void*)disconnectA2dpNative},
+ {"informAudioFocusStateNative", "(I)V",
+ (void*)informAudioFocusStateNative},
+ {"informAudioTrackGainNative", "(F)V", (void*)informAudioTrackGainNative},
+ {"setActiveDeviceNative", "([B)Z", (void*)setActiveDeviceNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onConnectionStateChanged", "([BI)V", &method_onConnectionStateChanged},
+ {"onAudioStateChanged", "([BI)V", &method_onAudioStateChanged},
+ {"onAudioConfigChanged", "([BII)V", &method_onAudioConfigChanged},
+ };
+ GET_JAVA_METHODS(env,
+ "com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface",
+ javaMethods);
+
+ return 0;
}
}
diff --git a/android/app/jni/com_android_bluetooth_avrcp_controller.cpp b/android/app/jni/com_android_bluetooth_avrcp_controller.cpp
index 316e1d0ac17c52e14582530fb368797064223257..6382f460937bfc2b9a6cbcd8699cfe2c2f805d02 100644
--- a/android/app/jni/com_android_bluetooth_avrcp_controller.cpp
+++ b/android/app/jni/com_android_bluetooth_avrcp_controller.cpp
@@ -24,10 +24,7 @@
#include
namespace android {
-static jmethodID method_handlePassthroughRsp;
static jmethodID method_onConnectionStateChanged;
-static jmethodID method_getRcFeatures;
-static jmethodID method_setplayerappsettingrsp;
static jmethodID method_handleplayerappsetting;
static jmethodID method_handleplayerappsettingchanged;
static jmethodID method_handleSetAbsVolume;
@@ -37,7 +34,6 @@ static jmethodID method_handleplaypositionchanged;
static jmethodID method_handleplaystatuschanged;
static jmethodID method_handleGetFolderItemsRsp;
static jmethodID method_handleGetPlayerItemsRsp;
-static jmethodID method_handleGroupNavigationRsp;
static jmethodID method_createFromNativeMediaItem;
static jmethodID method_createFromNativeFolderItem;
static jmethodID method_createFromNativePlayerItem;
@@ -49,6 +45,7 @@ static jmethodID method_handleNowPlayingContentChanged;
static jmethodID method_onAvailablePlayerChanged;
static jmethodID method_getRcPsm;
+static jclass class_AvrcpControllerNativeInterface;
static jclass class_AvrcpItem;
static jclass class_AvrcpPlayer;
@@ -56,42 +53,13 @@ static const btrc_ctrl_interface_t* sBluetoothAvrcpInterface = NULL;
static jobject sCallbacksObj = NULL;
static std::shared_timed_mutex sCallbacks_mutex;
-static void btavrcp_passthrough_response_callback(const RawAddress& bd_addr,
- int id, int pressed) {
- ALOGI("%s: id: %d, pressed: %d", __func__, id, pressed);
- std::shared_lock lock(sCallbacks_mutex);
- CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
- if (!sCallbacksObj) {
- ALOGE("%s: sCallbacksObj is null", __func__);
- return;
- }
-
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
- if (!addr.get()) {
- ALOGE("%s: Failed to allocate a new byte array", __func__);
- return;
- }
-
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handlePassthroughRsp,
- (jint)id, (jint)pressed, addr.get());
+static void btavrcp_passthrough_response_callback(
+ const RawAddress& /* bd_addr */, int id, int pressed) {
+ ALOGV("%s: id: %d, pressed: %d --- Not implemented", __func__, id, pressed);
}
static void btavrcp_groupnavigation_response_callback(int id, int pressed) {
- ALOGV("%s", __func__);
- std::shared_lock lock(sCallbacks_mutex);
- CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
- if (!sCallbacksObj) {
- ALOGE("%s: sCallbacksObj is null", __func__);
- return;
- }
-
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleGroupNavigationRsp,
- (jint)id, (jint)pressed);
+ ALOGV("%s: id: %d, pressed: %d --- Not implemented", __func__, id, pressed);
}
static void btavrcp_connection_state_callback(bool rc_connect, bool br_connect,
@@ -119,58 +87,19 @@ static void btavrcp_connection_state_callback(bool rc_connect, bool br_connect,
addr.get());
}
-static void btavrcp_get_rcfeatures_callback(const RawAddress& bd_addr,
- int features) {
- ALOGV("%s", __func__);
- std::shared_lock lock(sCallbacks_mutex);
- CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
- if (!sCallbacksObj) {
- ALOGE("%s: sCallbacksObj is null", __func__);
- return;
- }
-
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
- if (!addr.get()) {
- ALOGE("%s: Failed to allocate a new byte array", __func__);
- return;
- }
-
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_getRcFeatures, addr.get(),
- (jint)features);
+static void btavrcp_get_rcfeatures_callback(const RawAddress& /* bd_addr */,
+ int /* features */) {
+ ALOGV("%s --- Not implemented", __func__);
}
-
static void btavrcp_setplayerapplicationsetting_rsp_callback(
- const RawAddress& bd_addr, uint8_t accepted) {
- ALOGV("%s", __func__);
- std::shared_lock lock(sCallbacks_mutex);
- CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
- if (!sCallbacksObj) {
- ALOGE("%s: sCallbacksObj is null", __func__);
- return;
- }
-
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
- if (!addr.get()) {
- ALOGE("%s: Failed to allocate a new byte array", __func__);
- return;
- }
-
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_setplayerappsettingrsp,
- addr.get(), (jint)accepted);
+ const RawAddress& /* bd_addr */, uint8_t /* accepted */) {
+ ALOGV("%s --- Not implemented", __func__);
}
static void btavrcp_playerapplicationsetting_callback(
const RawAddress& bd_addr, uint8_t num_attr,
- btrc_player_app_attr_t* app_attrs, uint8_t num_ext_attr,
- btrc_player_app_ext_attr_t* ext_attrs) {
+ btrc_player_app_attr_t* app_attrs, uint8_t /* num_ext_attr */,
+ btrc_player_app_ext_attr_t* /* ext_attrs */) {
ALOGI("%s", __func__);
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
@@ -509,10 +438,11 @@ static void btavrcp_get_folder_items_callback(
ScopedLocalRef mediaObj(
sCallbackEnv.get(),
- (jobject)sCallbackEnv->CallObjectMethod(
- sCallbacksObj, method_createFromNativeMediaItem, addr.get(),
- uid, (jint)item->media.type, mediaName.get(),
- attrIdArray.get(), attrValArray.get()));
+ (jobject)sCallbackEnv->CallStaticObjectMethod(
+ class_AvrcpControllerNativeInterface,
+ method_createFromNativeMediaItem, addr.get(), uid,
+ (jint)item->media.type, mediaName.get(), attrIdArray.get(),
+ attrValArray.get()));
if (!mediaObj.get()) {
ALOGE("%s failed to create AvrcpItem for type ITEM_MEDIA", __func__);
return;
@@ -534,9 +464,10 @@ static void btavrcp_get_folder_items_callback(
long long uid = *(long long*)item->folder.uid;
ScopedLocalRef folderObj(
sCallbackEnv.get(),
- (jobject)sCallbackEnv->CallObjectMethod(
- sCallbacksObj, method_createFromNativeFolderItem, addr.get(),
- uid, (jint)item->folder.type, folderName.get(),
+ (jobject)sCallbackEnv->CallStaticObjectMethod(
+ class_AvrcpControllerNativeInterface,
+ method_createFromNativeFolderItem, addr.get(), uid,
+ (jint)item->folder.type, folderName.get(),
(jint)item->folder.playable));
if (!folderObj.get()) {
ALOGE("%s failed to create AvrcpItem for type ITEM_FOLDER", __func__);
@@ -574,9 +505,10 @@ static void btavrcp_get_folder_items_callback(
}
ScopedLocalRef playerObj(
sCallbackEnv.get(),
- (jobject)sCallbackEnv->CallObjectMethod(
- sCallbacksObj, method_createFromNativePlayerItem, addr.get(),
- id, playerName.get(), featureBitArray.get(), playStatus,
+ (jobject)sCallbackEnv->CallStaticObjectMethod(
+ class_AvrcpControllerNativeInterface,
+ method_createFromNativePlayerItem, addr.get(), id,
+ playerName.get(), featureBitArray.get(), playStatus,
playerType));
if (!playerObj.get()) {
ALOGE("%s failed to create AvrcpPlayer from ITEM_PLAYER", __func__);
@@ -788,81 +720,8 @@ static btrc_ctrl_callbacks_t sBluetoothAvrcpCallbacks = {
btavrcp_addressed_player_changed_callback,
btavrcp_now_playing_content_changed_callback,
btavrcp_available_player_changed_callback,
- btavrcp_get_rcpsm_callback};
-
-static void classInitNative(JNIEnv* env, jclass clazz) {
- method_handlePassthroughRsp =
- env->GetMethodID(clazz, "handlePassthroughRsp", "(II[B)V");
-
- method_handleGroupNavigationRsp =
- env->GetMethodID(clazz, "handleGroupNavigationRsp", "(II)V");
-
- method_onConnectionStateChanged =
- env->GetMethodID(clazz, "onConnectionStateChanged", "(ZZ[B)V");
-
- method_getRcFeatures = env->GetMethodID(clazz, "getRcFeatures", "([BI)V");
-
- method_getRcPsm = env->GetMethodID(clazz, "getRcPsm", "([BI)V");
-
- method_setplayerappsettingrsp =
- env->GetMethodID(clazz, "setPlayerAppSettingRsp", "([BB)V");
-
- method_handleplayerappsetting =
- env->GetMethodID(clazz, "handlePlayerAppSetting", "([B[BI)V");
-
- method_handleplayerappsettingchanged =
- env->GetMethodID(clazz, "onPlayerAppSettingChanged", "([B[BI)V");
-
- method_handleSetAbsVolume =
- env->GetMethodID(clazz, "handleSetAbsVolume", "([BBB)V");
-
- method_handleRegisterNotificationAbsVol =
- env->GetMethodID(clazz, "handleRegisterNotificationAbsVol", "([BB)V");
-
- method_handletrackchanged =
- env->GetMethodID(clazz, "onTrackChanged", "([BB[I[Ljava/lang/String;)V");
-
- method_handleplaypositionchanged =
- env->GetMethodID(clazz, "onPlayPositionChanged", "([BII)V");
-
- method_handleplaystatuschanged =
- env->GetMethodID(clazz, "onPlayStatusChanged", "([BB)V");
-
- method_handleGetFolderItemsRsp =
- env->GetMethodID(clazz, "handleGetFolderItemsRsp",
- "([BI[Lcom/android/bluetooth/avrcpcontroller/"
- "AvrcpItem;)V");
- method_handleGetPlayerItemsRsp = env->GetMethodID(
- clazz, "handleGetPlayerItemsRsp",
- "([B[Lcom/android/bluetooth/avrcpcontroller/AvrcpPlayer;)V");
-
- method_createFromNativeMediaItem =
- env->GetMethodID(clazz, "createFromNativeMediaItem",
- "([BJILjava/lang/String;[I[Ljava/lang/String;)Lcom/"
- "android/bluetooth/avrcpcontroller/AvrcpItem;");
- method_createFromNativeFolderItem = env->GetMethodID(
- clazz, "createFromNativeFolderItem",
- "([BJILjava/lang/String;I)Lcom/android/bluetooth/avrcpcontroller/"
- "AvrcpItem;");
- method_createFromNativePlayerItem =
- env->GetMethodID(clazz, "createFromNativePlayerItem",
- "([BILjava/lang/String;[BII)Lcom/android/bluetooth/"
- "avrcpcontroller/AvrcpPlayer;");
- method_handleChangeFolderRsp =
- env->GetMethodID(clazz, "handleChangeFolderRsp", "([BI)V");
- method_handleSetBrowsedPlayerRsp =
- env->GetMethodID(clazz, "handleSetBrowsedPlayerRsp", "([BII)V");
- method_handleSetAddressedPlayerRsp =
- env->GetMethodID(clazz, "handleSetAddressedPlayerRsp", "([BI)V");
- method_handleAddressedPlayerChanged =
- env->GetMethodID(clazz, "handleAddressedPlayerChanged", "([BI)V");
- method_handleNowPlayingContentChanged =
- env->GetMethodID(clazz, "handleNowPlayingContentChanged", "([B)V");
- method_onAvailablePlayerChanged =
- env->GetMethodID(clazz, "onAvailablePlayerChanged", "([B)V");
-
- ALOGI("%s: succeeds", __func__);
-}
+ btavrcp_get_rcpsm_callback,
+};
static void initNative(JNIEnv* env, jobject object) {
std::unique_lock lock(sCallbacks_mutex);
@@ -875,6 +734,11 @@ static void initNative(JNIEnv* env, jobject object) {
env->FindClass("com/android/bluetooth/avrcpcontroller/AvrcpPlayer");
class_AvrcpPlayer = (jclass)env->NewGlobalRef(tmpBtPlayer);
+ jclass tmpControllerInterface = env->FindClass(
+ "com/android/bluetooth/avrcpcontroller/AvrcpControllerNativeInterface");
+ class_AvrcpControllerNativeInterface =
+ (jclass)env->NewGlobalRef(tmpControllerInterface);
+
const bt_interface_t* btInf = getBluetoothInterface();
if (btInf == NULL) {
ALOGE("Bluetooth module is not loaded");
@@ -913,7 +777,7 @@ static void initNative(JNIEnv* env, jobject object) {
sCallbacksObj = env->NewGlobalRef(object);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock lock(sCallbacks_mutex);
const bt_interface_t* btInf = getBluetoothInterface();
@@ -933,7 +797,7 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static jboolean sendPassThroughCommandNative(JNIEnv* env, jobject object,
+static jboolean sendPassThroughCommandNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jint key_code,
jint key_state) {
if (!sBluetoothAvrcpInterface) return JNI_FALSE;
@@ -960,7 +824,8 @@ static jboolean sendPassThroughCommandNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean sendGroupNavigationCommandNative(JNIEnv* env, jobject object,
+static jboolean sendGroupNavigationCommandNative(JNIEnv* env,
+ jobject /* object */,
jbyteArray address,
jint key_code,
jint key_state) {
@@ -988,11 +853,9 @@ static jboolean sendGroupNavigationCommandNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static void setPlayerApplicationSettingValuesNative(JNIEnv* env, jobject object,
- jbyteArray address,
- jbyte num_attrib,
- jbyteArray attrib_ids,
- jbyteArray attrib_val) {
+static void setPlayerApplicationSettingValuesNative(
+ JNIEnv* env, jobject /* object */, jbyteArray address, jbyte num_attrib,
+ jbyteArray attrib_ids, jbyteArray attrib_val) {
ALOGI("%s: sBluetoothAvrcpInterface: %p", __func__, sBluetoothAvrcpInterface);
if (!sBluetoothAvrcpInterface) return;
@@ -1039,8 +902,8 @@ static void setPlayerApplicationSettingValuesNative(JNIEnv* env, jobject object,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void sendAbsVolRspNative(JNIEnv* env, jobject object, jbyteArray address,
- jint abs_vol, jint label) {
+static void sendAbsVolRspNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jint abs_vol, jint label) {
if (!sBluetoothAvrcpInterface) return;
jbyte* addr = env->GetByteArrayElements(address, NULL);
@@ -1061,7 +924,7 @@ static void sendAbsVolRspNative(JNIEnv* env, jobject object, jbyteArray address,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void sendRegisterAbsVolRspNative(JNIEnv* env, jobject object,
+static void sendRegisterAbsVolRspNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jbyte rsp_type,
jint abs_vol, jint label) {
if (!sBluetoothAvrcpInterface) return;
@@ -1085,7 +948,7 @@ static void sendRegisterAbsVolRspNative(JNIEnv* env, jobject object,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void getCurrentMetadataNative(JNIEnv* env, jobject object,
+static void getCurrentMetadataNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
if (!sBluetoothAvrcpInterface) return;
@@ -1106,7 +969,7 @@ static void getCurrentMetadataNative(JNIEnv* env, jobject object,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void getPlaybackStateNative(JNIEnv* env, jobject object,
+static void getPlaybackStateNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
if (!sBluetoothAvrcpInterface) return;
@@ -1127,7 +990,7 @@ static void getPlaybackStateNative(JNIEnv* env, jobject object,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void getNowPlayingListNative(JNIEnv* env, jobject object,
+static void getNowPlayingListNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jint start, jint end) {
if (!sBluetoothAvrcpInterface) return;
jbyte* addr = env->GetByteArrayElements(address, NULL);
@@ -1147,8 +1010,8 @@ static void getNowPlayingListNative(JNIEnv* env, jobject object,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void getFolderListNative(JNIEnv* env, jobject object, jbyteArray address,
- jint start, jint end) {
+static void getFolderListNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jint start, jint end) {
if (!sBluetoothAvrcpInterface) return;
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
@@ -1167,8 +1030,8 @@ static void getFolderListNative(JNIEnv* env, jobject object, jbyteArray address,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void getPlayerListNative(JNIEnv* env, jobject object, jbyteArray address,
- jint start, jint end) {
+static void getPlayerListNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jint start, jint end) {
if (!sBluetoothAvrcpInterface) return;
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
@@ -1187,7 +1050,7 @@ static void getPlayerListNative(JNIEnv* env, jobject object, jbyteArray address,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void changeFolderPathNative(JNIEnv* env, jobject object,
+static void changeFolderPathNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jbyte direction,
jlong uid) {
if (!sBluetoothAvrcpInterface) return;
@@ -1215,7 +1078,7 @@ static void changeFolderPathNative(JNIEnv* env, jobject object,
// env->ReleaseByteArrayElements(address, addr, 0);
}
-static void setBrowsedPlayerNative(JNIEnv* env, jobject object,
+static void setBrowsedPlayerNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jint id) {
if (!sBluetoothAvrcpInterface) return;
jbyte* addr = env->GetByteArrayElements(address, NULL);
@@ -1235,7 +1098,7 @@ static void setBrowsedPlayerNative(JNIEnv* env, jobject object,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void setAddressedPlayerNative(JNIEnv* env, jobject object,
+static void setAddressedPlayerNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jint id) {
if (!sBluetoothAvrcpInterface) return;
jbyte* addr = env->GetByteArrayElements(address, NULL);
@@ -1256,8 +1119,9 @@ static void setAddressedPlayerNative(JNIEnv* env, jobject object,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void playItemNative(JNIEnv* env, jobject object, jbyteArray address,
- jbyte scope, jlong uid, jint uidCounter) {
+static void playItemNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jbyte scope, jlong uid,
+ jint uidCounter) {
if (!sBluetoothAvrcpInterface) return;
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
@@ -1282,33 +1146,84 @@ static void playItemNative(JNIEnv* env, jobject object, jbyteArray address,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative", "()V", (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"sendPassThroughCommandNative", "([BII)Z",
- (void*)sendPassThroughCommandNative},
- {"sendGroupNavigationCommandNative", "([BII)Z",
- (void*)sendGroupNavigationCommandNative},
- {"setPlayerApplicationSettingValuesNative", "([BB[B[B)V",
- (void*)setPlayerApplicationSettingValuesNative},
- {"sendAbsVolRspNative", "([BII)V", (void*)sendAbsVolRspNative},
- {"sendRegisterAbsVolRspNative", "([BBII)V",
- (void*)sendRegisterAbsVolRspNative},
- {"getCurrentMetadataNative", "([B)V", (void*)getCurrentMetadataNative},
- {"getPlaybackStateNative", "([B)V", (void*)getPlaybackStateNative},
- {"getNowPlayingListNative", "([BII)V", (void*)getNowPlayingListNative},
- {"getFolderListNative", "([BII)V", (void*)getFolderListNative},
- {"getPlayerListNative", "([BII)V", (void*)getPlayerListNative},
- {"changeFolderPathNative", "([BBJ)V", (void*)changeFolderPathNative},
- {"playItemNative", "([BBJI)V", (void*)playItemNative},
- {"setBrowsedPlayerNative", "([BI)V", (void*)setBrowsedPlayerNative},
- {"setAddressedPlayerNative", "([BI)V", (void*)setAddressedPlayerNative},
-};
-
int register_com_android_bluetooth_avrcp_controller(JNIEnv* env) {
- return jniRegisterNativeMethods(
- env, "com/android/bluetooth/avrcpcontroller/AvrcpControllerService",
- sMethods, NELEM(sMethods));
-}
+ const JNINativeMethod methods[] = {
+ {"initNative", "()V", (void*)initNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"sendPassThroughCommandNative", "([BII)Z",
+ (void*)sendPassThroughCommandNative},
+ {"sendGroupNavigationCommandNative", "([BII)Z",
+ (void*)sendGroupNavigationCommandNative},
+ {"setPlayerApplicationSettingValuesNative", "([BB[B[B)V",
+ (void*)setPlayerApplicationSettingValuesNative},
+ {"sendAbsVolRspNative", "([BII)V", (void*)sendAbsVolRspNative},
+ {"sendRegisterAbsVolRspNative", "([BBII)V",
+ (void*)sendRegisterAbsVolRspNative},
+ {"getCurrentMetadataNative", "([B)V", (void*)getCurrentMetadataNative},
+ {"getPlaybackStateNative", "([B)V", (void*)getPlaybackStateNative},
+ {"getNowPlayingListNative", "([BII)V", (void*)getNowPlayingListNative},
+ {"getFolderListNative", "([BII)V", (void*)getFolderListNative},
+ {"getPlayerListNative", "([BII)V", (void*)getPlayerListNative},
+ {"changeFolderPathNative", "([BBJ)V", (void*)changeFolderPathNative},
+ {"playItemNative", "([BBJI)V", (void*)playItemNative},
+ {"setBrowsedPlayerNative", "([BI)V", (void*)setBrowsedPlayerNative},
+ {"setAddressedPlayerNative", "([BI)V", (void*)setAddressedPlayerNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env,
+ "com/android/bluetooth/avrcpcontroller/AvrcpControllerNativeInterface",
+ methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onConnectionStateChanged", "(ZZ[B)V", &method_onConnectionStateChanged},
+ {"getRcPsm", "([BI)V", &method_getRcPsm},
+ {"handlePlayerAppSetting", "([B[BI)V", &method_handleplayerappsetting},
+ {"onPlayerAppSettingChanged", "([B[BI)V",
+ &method_handleplayerappsettingchanged},
+ {"handleSetAbsVolume", "([BBB)V", &method_handleSetAbsVolume},
+ {"handleRegisterNotificationAbsVol", "([BB)V",
+ &method_handleRegisterNotificationAbsVol},
+ {"onTrackChanged", "([BB[I[Ljava/lang/String;)V",
+ &method_handletrackchanged},
+ {"onPlayPositionChanged", "([BII)V", &method_handleplaypositionchanged},
+ {"onPlayStatusChanged", "([BB)V", &method_handleplaystatuschanged},
+ {"handleGetFolderItemsRsp",
+ "([BI[Lcom/android/bluetooth/avrcpcontroller/AvrcpItem;)V",
+ &method_handleGetFolderItemsRsp},
+ {"handleGetPlayerItemsRsp",
+ "([B[Lcom/android/bluetooth/avrcpcontroller/AvrcpPlayer;)V",
+ &method_handleGetPlayerItemsRsp},
+ {"handleChangeFolderRsp", "([BI)V", &method_handleChangeFolderRsp},
+ {"handleSetBrowsedPlayerRsp", "([BII)V",
+ &method_handleSetBrowsedPlayerRsp},
+ {"handleSetAddressedPlayerRsp", "([BI)V",
+ &method_handleSetAddressedPlayerRsp},
+ {"handleAddressedPlayerChanged", "([BI)V",
+ &method_handleAddressedPlayerChanged},
+ {"handleNowPlayingContentChanged", "([B)V",
+ &method_handleNowPlayingContentChanged},
+ {"onAvailablePlayerChanged", "([B)V", &method_onAvailablePlayerChanged},
+ // Fetch static method
+ {"createFromNativeMediaItem",
+ "([BJILjava/lang/String;[I[Ljava/lang/String;)"
+ "Lcom/android/bluetooth/avrcpcontroller/AvrcpItem;",
+ &method_createFromNativeMediaItem, true},
+ {"createFromNativeFolderItem",
+ "([BJILjava/lang/String;I)"
+ "Lcom/android/bluetooth/avrcpcontroller/AvrcpItem;",
+ &method_createFromNativeFolderItem, true},
+ {"createFromNativePlayerItem",
+ "([BILjava/lang/String;[BII)"
+ "Lcom/android/bluetooth/avrcpcontroller/AvrcpPlayer;",
+ &method_createFromNativePlayerItem, true},
+ };
+ GET_JAVA_METHODS(
+ env,
+ "com/android/bluetooth/avrcpcontroller/AvrcpControllerNativeInterface",
+ javaMethods);
+ return 0;
}
+} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_avrcp_target.cpp b/android/app/jni/com_android_bluetooth_avrcp_target.cpp
index edfb684b5c792f9a51393ab88f4f154ca0ec54af..a5e4949de33a5aaaa1750307fa01833c0d0f1ae3 100644
--- a/android/app/jni/com_android_bluetooth_avrcp_target.cpp
+++ b/android/app/jni/com_android_bluetooth_avrcp_target.cpp
@@ -150,7 +150,7 @@ class AvrcpMediaInterfaceImpl : public MediaInterface {
mServiceCallbacks = callback;
}
- void UnregisterUpdateCallback(MediaCallbacks* callback) override {
+ void UnregisterUpdateCallback(MediaCallbacks* /* callback */) override {
mServiceCallbacks = nullptr;
}
@@ -232,63 +232,6 @@ static jmethodID method_listPlayerSettingValues;
static jmethodID method_getPlayerSettings;
static jmethodID method_setPlayerSettings;
-static void classInitNative(JNIEnv* env, jclass clazz) {
- method_getCurrentSongInfo = env->GetMethodID(
- clazz, "getCurrentSongInfo", "()Lcom/android/bluetooth/audio_util/Metadata;");
-
- method_getPlaybackStatus = env->GetMethodID(
- clazz, "getPlayStatus", "()Lcom/android/bluetooth/audio_util/PlayStatus;");
-
- method_sendMediaKeyEvent =
- env->GetMethodID(clazz, "sendMediaKeyEvent", "(IZ)V");
-
- method_getCurrentMediaId =
- env->GetMethodID(clazz, "getCurrentMediaId", "()Ljava/lang/String;");
-
- method_getNowPlayingList =
- env->GetMethodID(clazz, "getNowPlayingList", "()Ljava/util/List;");
-
- method_getCurrentPlayerId =
- env->GetMethodID(clazz, "getCurrentPlayerId", "()I");
-
- method_getMediaPlayerList =
- env->GetMethodID(clazz, "getMediaPlayerList", "()Ljava/util/List;");
-
- method_setBrowsedPlayer = env->GetMethodID(clazz, "setBrowsedPlayer", "(I)V");
-
- method_getFolderItemsRequest = env->GetMethodID(
- clazz, "getFolderItemsRequest", "(ILjava/lang/String;)V");
-
- method_playItem =
- env->GetMethodID(clazz, "playItem", "(IZLjava/lang/String;)V");
-
- method_setActiveDevice =
- env->GetMethodID(clazz, "setActiveDevice", "(Ljava/lang/String;)V");
-
- // Volume Management functions
- method_volumeDeviceConnected =
- env->GetMethodID(clazz, "deviceConnected", "(Ljava/lang/String;Z)V");
-
- method_volumeDeviceDisconnected =
- env->GetMethodID(clazz, "deviceDisconnected", "(Ljava/lang/String;)V");
-
- method_setVolume = env->GetMethodID(clazz, "setVolume", "(I)V");
-
- method_listPlayerSettings =
- env->GetMethodID(clazz, "listPlayerSettingsRequest", "()V");
-
- method_listPlayerSettingValues =
- env->GetMethodID(clazz, "listPlayerSettingValuesRequest", "(B)V");
-
- method_getPlayerSettings =
- env->GetMethodID(clazz, "getCurrentPlayerSettingValuesRequest", "([B)V");
-
- method_setPlayerSettings =
- env->GetMethodID(clazz, "setPlayerSettingsRequest", "([B[B)V");
-
- ALOGI("%s: AvrcpTargetJni initialized!", __func__);
-}
-
static void initNative(JNIEnv* env, jobject object) {
ALOGD("%s", __func__);
std::unique_lock interface_lock(interface_mutex);
@@ -300,7 +243,7 @@ static void initNative(JNIEnv* env, jobject object) {
&mPlayerSettingsInterface);
}
-static void registerBipServerNative(JNIEnv* env, jobject object,
+static void registerBipServerNative(JNIEnv* /* env */, jobject /* object */,
jint l2cap_psm) {
ALOGD("%s: l2cap_psm=%d", __func__, (int)l2cap_psm);
std::unique_lock interface_lock(interface_mutex);
@@ -311,7 +254,7 @@ static void registerBipServerNative(JNIEnv* env, jobject object,
sServiceInterface->RegisterBipServer((int)l2cap_psm);
}
-static void unregisterBipServerNative(JNIEnv* env, jobject object) {
+static void unregisterBipServerNative(JNIEnv* /* env */, jobject /* object */) {
ALOGD("%s", __func__);
std::unique_lock interface_lock(interface_mutex);
if (sServiceInterface == nullptr) {
@@ -321,7 +264,7 @@ static void unregisterBipServerNative(JNIEnv* env, jobject object) {
sServiceInterface->UnregisterBipServer();
}
-static void sendMediaUpdateNative(JNIEnv* env, jobject object,
+static void sendMediaUpdateNative(JNIEnv* /* env */, jobject /* object */,
jboolean metadata, jboolean state,
jboolean queue) {
ALOGD("%s", __func__);
@@ -335,7 +278,7 @@ static void sendMediaUpdateNative(JNIEnv* env, jobject object,
queue == JNI_TRUE);
}
-static void sendFolderUpdateNative(JNIEnv* env, jobject object,
+static void sendFolderUpdateNative(JNIEnv* /* env */, jobject /* object */,
jboolean available_players,
jboolean addressed_player, jboolean uids) {
ALOGD("%s", __func__);
@@ -350,7 +293,7 @@ static void sendFolderUpdateNative(JNIEnv* env, jobject object,
uids == JNI_TRUE);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -364,7 +307,8 @@ static void cleanupNative(JNIEnv* env, jobject object) {
sServiceInterface = nullptr;
}
-jboolean connectDeviceNative(JNIEnv* env, jobject object, jstring address) {
+jboolean connectDeviceNative(JNIEnv* env, jobject /* object */,
+ jstring address) {
ALOGD("%s", __func__);
std::unique_lock interface_lock(interface_mutex);
if (mServiceCallbacks == nullptr) {
@@ -383,7 +327,8 @@ jboolean connectDeviceNative(JNIEnv* env, jobject object, jstring address) {
: JNI_FALSE;
}
-jboolean disconnectDeviceNative(JNIEnv* env, jobject object, jstring address) {
+jboolean disconnectDeviceNative(JNIEnv* env, jobject /* object */,
+ jstring address) {
ALOGD("%s", __func__);
std::unique_lock interface_lock(interface_mutex);
if (mServiceCallbacks == nullptr) {
@@ -762,9 +707,10 @@ static void setBrowsedPlayer(uint16_t player_id, SetBrowsedPlayerCb cb) {
player_id);
}
-static void setBrowsedPlayerResponseNative(JNIEnv* env, jobject object,
- jint player_id, jboolean success,
- jstring root_id, jint num_items) {
+static void setBrowsedPlayerResponseNative(JNIEnv* env, jobject /* object */,
+ jint /* player_id */,
+ jboolean success, jstring root_id,
+ jint num_items) {
ALOGD("%s", __func__);
std::string root;
@@ -777,7 +723,7 @@ static void setBrowsedPlayerResponseNative(JNIEnv* env, jobject object,
set_browsed_player_cb.Run(success == JNI_TRUE, root, num_items);
}
-static void getFolderItemsResponseNative(JNIEnv* env, jobject object,
+static void getFolderItemsResponseNative(JNIEnv* env, jobject /* object */,
jstring parent_id, jobject list) {
ALOGD("%s", __func__);
@@ -932,7 +878,7 @@ static void volumeDeviceDisconnected(const RawAddress& address) {
j_bdaddr);
}
-static void sendVolumeChangedNative(JNIEnv* env, jobject object,
+static void sendVolumeChangedNative(JNIEnv* env, jobject /* object */,
jstring address, jint volume) {
const char* tmp_addr = env->GetStringUTFChars(address, 0);
RawAddress bdaddr;
@@ -956,8 +902,8 @@ static void setVolume(int8_t volume) {
sCallbackEnv->CallVoidMethod(mJavaInterface, method_setVolume, volume);
}
-static void setBipClientStatusNative(JNIEnv* env, jobject object,
- jstring address, jboolean connected) {
+static void setBipClientStatusNative(JNIEnv* env, jobject /* object */,
+ jstring address, jboolean connected) {
std::unique_lock interface_lock(interface_mutex);
if (mServiceCallbacks == nullptr) {
ALOGW("%s: Service not loaded.", __func__);
@@ -986,7 +932,7 @@ static void listPlayerSettings(ListPlayerSettingsCb cb) {
sCallbackEnv->CallVoidMethod(mJavaInterface, method_listPlayerSettings);
}
-static void listPlayerSettingsResponseNative(JNIEnv* env, jobject object,
+static void listPlayerSettingsResponseNative(JNIEnv* env, jobject /* object */,
jbyteArray attributes) {
ALOGD("%s", __func__);
@@ -1009,7 +955,8 @@ static void listPlayerSettingValues(PlayerAttribute attribute,
(jbyte)attribute);
}
-static void listPlayerSettingValuesResponseNative(JNIEnv* env, jobject object,
+static void listPlayerSettingValuesResponseNative(JNIEnv* env,
+ jobject /* object */,
jbyte attribute,
jbyteArray values) {
ALOGD("%s", __func__);
@@ -1037,7 +984,7 @@ static void getPlayerSettings(std::vector attributes,
attributes_array);
}
-static void getPlayerSettingsResponseNative(JNIEnv* env, jobject object,
+static void getPlayerSettingsResponseNative(JNIEnv* env, jobject /* object */,
jbyteArray attributes,
jbyteArray values) {
ALOGD("%s", __func__);
@@ -1074,13 +1021,14 @@ static void setPlayerSettings(std::vector attributes,
attributes_array, values_array);
}
-static void setPlayerSettingsResponseNative(JNIEnv* env, jobject object,
+static void setPlayerSettingsResponseNative(JNIEnv* /* env */,
+ jobject /* object */,
jboolean success) {
ALOGD("%s", __func__);
set_player_setting_value_cb.Run(success);
}
-static void sendPlayerSettingsNative(JNIEnv* env, jobject object,
+static void sendPlayerSettingsNative(JNIEnv* env, jobject /* object */,
jbyteArray attributes, jbyteArray values) {
ALOGD("%s", __func__);
std::unique_lock interface_lock(interface_mutex);
@@ -1096,41 +1044,73 @@ static void sendPlayerSettingsNative(JNIEnv* env, jobject object,
values_vector);
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative", "()V", (void*)initNative},
- {"registerBipServerNative", "(I)V", (void*)registerBipServerNative},
- {"unregisterBipServerNative", "()V", (void*)unregisterBipServerNative},
- {"sendMediaUpdateNative", "(ZZZ)V", (void*)sendMediaUpdateNative},
- {"sendFolderUpdateNative", "(ZZZ)V", (void*)sendFolderUpdateNative},
- {"setBrowsedPlayerResponseNative", "(IZLjava/lang/String;I)V",
- (void*)setBrowsedPlayerResponseNative},
- {"getFolderItemsResponseNative", "(Ljava/lang/String;Ljava/util/List;)V",
- (void*)getFolderItemsResponseNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"connectDeviceNative", "(Ljava/lang/String;)Z",
- (void*)connectDeviceNative},
- {"disconnectDeviceNative", "(Ljava/lang/String;)Z",
- (void*)disconnectDeviceNative},
- {"sendVolumeChangedNative", "(Ljava/lang/String;I)V",
- (void*)sendVolumeChangedNative},
- {"setBipClientStatusNative", "(Ljava/lang/String;Z)V",
- (void*)setBipClientStatusNative},
- {"listPlayerSettingsResponseNative", "([B)V",
- (void*)listPlayerSettingsResponseNative},
- {"listPlayerSettingValuesResponseNative", "(B[B)V",
- (void*)listPlayerSettingValuesResponseNative},
- {"getPlayerSettingsResponseNative", "([B[B)V",
- (void*)getPlayerSettingsResponseNative},
- {"setPlayerSettingsResponseNative", "(Z)V",
- (void*)setPlayerSettingsResponseNative},
- {"sendPlayerSettingsNative", "([B[B)V", (void*)sendPlayerSettingsNative},
-};
-
int register_com_android_bluetooth_avrcp_target(JNIEnv* env) {
- return jniRegisterNativeMethods(
- env, "com/android/bluetooth/avrcp/AvrcpNativeInterface", sMethods,
- NELEM(sMethods));
+ const JNINativeMethod methods[] = {
+ {"initNative", "()V", (void*)initNative},
+ {"registerBipServerNative", "(I)V", (void*)registerBipServerNative},
+ {"unregisterBipServerNative", "()V", (void*)unregisterBipServerNative},
+ {"sendMediaUpdateNative", "(ZZZ)V", (void*)sendMediaUpdateNative},
+ {"sendFolderUpdateNative", "(ZZZ)V", (void*)sendFolderUpdateNative},
+ {"setBrowsedPlayerResponseNative", "(IZLjava/lang/String;I)V",
+ (void*)setBrowsedPlayerResponseNative},
+ {"getFolderItemsResponseNative", "(Ljava/lang/String;Ljava/util/List;)V",
+ (void*)getFolderItemsResponseNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"connectDeviceNative", "(Ljava/lang/String;)Z",
+ (void*)connectDeviceNative},
+ {"disconnectDeviceNative", "(Ljava/lang/String;)Z",
+ (void*)disconnectDeviceNative},
+ {"sendVolumeChangedNative", "(Ljava/lang/String;I)V",
+ (void*)sendVolumeChangedNative},
+ {"setBipClientStatusNative", "(Ljava/lang/String;Z)V",
+ (void*)setBipClientStatusNative},
+ {"listPlayerSettingsResponseNative", "([B)V",
+ (void*)listPlayerSettingsResponseNative},
+ {"listPlayerSettingValuesResponseNative", "(B[B)V",
+ (void*)listPlayerSettingValuesResponseNative},
+ {"getPlayerSettingsResponseNative", "([B[B)V",
+ (void*)getPlayerSettingsResponseNative},
+ {"setPlayerSettingsResponseNative", "(Z)V",
+ (void*)setPlayerSettingsResponseNative},
+ {"sendPlayerSettingsNative", "([B[B)V", (void*)sendPlayerSettingsNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/avrcp/AvrcpNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"getCurrentSongInfo", "()Lcom/android/bluetooth/audio_util/Metadata;",
+ &method_getCurrentSongInfo},
+ {"getPlayStatus", "()Lcom/android/bluetooth/audio_util/PlayStatus;",
+ &method_getPlaybackStatus},
+ {"sendMediaKeyEvent", "(IZ)V", &method_sendMediaKeyEvent},
+ {"getCurrentMediaId", "()Ljava/lang/String;", &method_getCurrentMediaId},
+ {"getNowPlayingList", "()Ljava/util/List;", &method_getNowPlayingList},
+ {"getCurrentPlayerId", "()I", &method_getCurrentPlayerId},
+ {"getMediaPlayerList", "()Ljava/util/List;", &method_getMediaPlayerList},
+ {"setBrowsedPlayer", "(I)V", &method_setBrowsedPlayer},
+ {"getFolderItemsRequest", "(ILjava/lang/String;)V",
+ &method_getFolderItemsRequest},
+ {"playItem", "(IZLjava/lang/String;)V", &method_playItem},
+ {"setActiveDevice", "(Ljava/lang/String;)V", &method_setActiveDevice},
+ {"deviceConnected", "(Ljava/lang/String;Z)V",
+ &method_volumeDeviceConnected},
+ {"deviceDisconnected", "(Ljava/lang/String;)V",
+ &method_volumeDeviceDisconnected},
+ {"setVolume", "(I)V", &method_setVolume},
+ {"listPlayerSettingsRequest", "()V", &method_listPlayerSettings},
+ {"listPlayerSettingValuesRequest", "(B)V",
+ &method_listPlayerSettingValues},
+ {"getCurrentPlayerSettingValuesRequest", "([B)V",
+ &method_getPlayerSettings},
+ {"setPlayerSettingsRequest", "([B[B)V", &method_setPlayerSettings},
+ };
+ GET_JAVA_METHODS(env, "com/android/bluetooth/avrcp/AvrcpNativeInterface",
+ javaMethods);
+
+ return 0;
}
} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_btservice_ActivityAttribution.cpp b/android/app/jni/com_android_bluetooth_btservice_ActivityAttribution.cpp
deleted file mode 100644
index 4e0247dcccd6591b368e2f0e356d15f03087fe4a..0000000000000000000000000000000000000000
--- a/android/app/jni/com_android_bluetooth_btservice_ActivityAttribution.cpp
+++ /dev/null
@@ -1,205 +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.
- */
-
-#define LOG_TAG "BluetoothActivityAttributionJni"
-
-#include
-
-#include
-
-#include "base/logging.h"
-#include "com_android_bluetooth.h"
-#include "hardware/bt_activity_attribution.h"
-
-using bluetooth::activity_attribution::ActivityAttributionCallbacks;
-using bluetooth::activity_attribution::ActivityAttributionInterface;
-
-namespace android {
-static jmethodID method_onWakeup;
-static jmethodID method_onActivityLogsReady;
-
-static ActivityAttributionInterface* sActivityAttributionInterface = nullptr;
-static std::shared_timed_mutex interface_mutex;
-
-static jobject mCallbacksObj = nullptr;
-static std::shared_timed_mutex callbacks_mutex;
-
-class ActivityAttributionCallbacksImpl : public ActivityAttributionCallbacks {
- public:
- ~ActivityAttributionCallbacksImpl() = default;
-
- void OnWakeup(const Activity activity, const RawAddress& bd_addr) override {
- LOG(INFO) << __func__;
-
- std::shared_lock lock(callbacks_mutex);
- CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) return;
-
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
- if (!addr.get()) {
- LOG(ERROR)
- << "Failed to allocate jbyteArray for bd_addr of wakeup callback";
- return;
- }
-
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr);
- sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onWakeup, (jint)activity,
- addr.get());
- }
-
- void OnActivityLogsReady(
- const std::vector logs) override {
- LOG(INFO) << __func__;
-
- std::shared_lock lock(callbacks_mutex);
- CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) return;
-
- jsize logs_size = logs.size() * sizeof(BtaaAggregationEntry);
- ScopedLocalRef addr(sCallbackEnv.get(),
- sCallbackEnv->NewByteArray(logs_size));
- if (!addr.get()) {
- LOG(ERROR) << "Failed to allocate jbyteArray for logs from activity "
- "logging callback";
- return;
- }
-
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, logs_size,
- (jbyte*)logs.data());
- sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onActivityLogsReady,
- addr.get());
- }
-};
-
-static ActivityAttributionCallbacksImpl sActivityAttributionCallbacks;
-
-static void classInitNative(JNIEnv* env, jclass clazz) {
- method_onWakeup = env->GetMethodID(clazz, "onWakeup", "(I[B)V");
- method_onActivityLogsReady =
- env->GetMethodID(clazz, "onActivityLogsReady", "([B)V");
-
- LOG(INFO) << __func__ << ": succeeds";
-}
-
-static void initNative(JNIEnv* env, jobject object) {
- std::unique_lock interface_lock(interface_mutex);
- std::unique_lock callbacks_lock(callbacks_mutex);
- const bt_interface_t* btInf = getBluetoothInterface();
- if (btInf == nullptr) {
- LOG(ERROR) << "Bluetooth module is not loaded";
- return;
- }
-
- if (sActivityAttributionInterface != nullptr) {
- LOG(INFO)
- << "Cleaning up ActivityAttribution Interface before initializing...";
- sActivityAttributionInterface->Cleanup();
- sActivityAttributionInterface = nullptr;
- }
-
- if (mCallbacksObj != nullptr) {
- LOG(INFO) << "Cleaning up ActivityAttribution callback object";
- env->DeleteGlobalRef(mCallbacksObj);
- mCallbacksObj = nullptr;
- }
-
- if ((mCallbacksObj = env->NewGlobalRef(object)) == nullptr) {
- LOG(ERROR)
- << "Failed to allocate Global Ref for ActivityAttribution Callbacks";
- return;
- }
-
- sActivityAttributionInterface =
- (ActivityAttributionInterface*)btInf->get_profile_interface(
- BT_ACTIVITY_ATTRIBUTION_ID);
- if (sActivityAttributionInterface == nullptr) {
- LOG(ERROR) << "Failed to get ActivityAttribution Interface";
- return;
- }
-
- sActivityAttributionInterface->RegisterCallbacks(
- &sActivityAttributionCallbacks);
-}
-
-static void cleanupNative(JNIEnv* env, jobject object) {
- std::unique_lock interface_lock(interface_mutex);
- std::unique_lock callbacks_lock(callbacks_mutex);
-
- const bt_interface_t* btInf = getBluetoothInterface();
- if (btInf == nullptr) {
- LOG(ERROR) << "Bluetooth module is not loaded";
- return;
- }
-
- if (sActivityAttributionInterface != nullptr) {
- sActivityAttributionInterface->Cleanup();
- sActivityAttributionInterface = nullptr;
- }
-
- if (mCallbacksObj != nullptr) {
- env->DeleteGlobalRef(mCallbacksObj);
- mCallbacksObj = nullptr;
- }
-}
-
-static void notifyActivityAttributionInfoNative(JNIEnv* env, jobject object,
- jint uid, jstring packageName,
- jstring deviceAddress) {
- const bt_interface_t* btInf = getBluetoothInterface();
- if (btInf == nullptr) {
- LOG(ERROR) << "Bluetooth module is not loaded";
- return;
- }
- sActivityAttributionInterface =
- (ActivityAttributionInterface*)btInf->get_profile_interface(
- BT_ACTIVITY_ATTRIBUTION_ID);
- if (sActivityAttributionInterface == nullptr) {
- LOG(ERROR) << "Failed to get ActivityAttribution Interface";
- return;
- }
-
- if (packageName == nullptr || deviceAddress == nullptr) {
- LOG(ERROR) << "Failed to get package name or device address";
- return;
- }
- const char* nativeName = env->GetStringUTFChars(packageName, nullptr);
- const char* nativeAddress = env->GetStringUTFChars(deviceAddress, nullptr);
- sActivityAttributionInterface->NotifyActivityAttributionInfo(uid, nativeName,
- nativeAddress);
- env->ReleaseStringUTFChars(packageName, nativeName);
- env->ReleaseStringUTFChars(deviceAddress, nativeAddress);
-}
-
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative", "()V", (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"notifyActivityAttributionInfoNative",
- "(ILjava/lang/String;Ljava/lang/String;)V",
- (void*)notifyActivityAttributionInfoNative},
-};
-
-int register_com_android_bluetooth_btservice_activity_attribution(JNIEnv* env) {
- return jniRegisterNativeMethods(
- env,
- "com/android/bluetooth/btservice/activityattribution/"
- "ActivityAttributionNativeInterface",
- sMethods, NELEM(sMethods));
-}
-
-} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp b/android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp
index 186c3457b1d07708e89173072d8dfdfbfb46ff0f..e3b197afc2bb2552b4ab348da5fc9959290a86de 100644
--- a/android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp
+++ b/android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp
@@ -66,7 +66,6 @@ static jmethodID method_discoveryStateChangeCallback;
static jmethodID method_linkQualityReportCallback;
static jmethodID method_switchBufferSizeCallback;
static jmethodID method_switchCodecCallback;
-static jmethodID method_setWakeAlarm;
static jmethodID method_acquireWakeLock;
static jmethodID method_releaseWakeLock;
static jmethodID method_energyInfo;
@@ -401,7 +400,7 @@ static void acl_state_changed_callback(bt_status_t status, RawAddress* bd_addr,
bt_acl_state_t state,
int transport_link_type,
bt_hci_error_code_t hci_reason,
- bt_conn_direction_t direction,
+ bt_conn_direction_t /* direction */,
uint16_t acl_handle) {
if (!bd_addr) {
ALOGE("Address is null in %s", __func__);
@@ -532,8 +531,21 @@ static void ssp_request_callback(RawAddress* bd_addr, bt_bdname_t* bdname,
static jobject createClassicOobDataObject(JNIEnv* env, bt_oob_data_t oob_data) {
ALOGV("%s", __func__);
- jclass classicBuilderClass =
- env->FindClass("android/bluetooth/OobData$ClassicBuilder");
+ jmethodID classicBuilderConstructor;
+ jmethodID setRMethod;
+ jmethodID setNameMethod;
+ jmethodID buildMethod;
+
+ const JNIJavaMethod javaMethods[] = {
+ {"", "([B[B[B)V", &classicBuilderConstructor},
+ {"setRandomizerHash", "([B)Landroid/bluetooth/OobData$ClassicBuilder;",
+ &setRMethod},
+ {"setDeviceName", "([B)Landroid/bluetooth/OobData$ClassicBuilder;",
+ &setNameMethod},
+ {"build", "()Landroid/bluetooth/OobData;", &buildMethod},
+ };
+ GET_JAVA_METHODS(env, "android/bluetooth/OobData$ClassicBuilder",
+ javaMethods);
jbyteArray confirmationHash = env->NewByteArray(OOB_C_SIZE);
env->SetByteArrayRegion(confirmationHash, 0, OOB_C_SIZE,
@@ -547,16 +559,15 @@ static jobject createClassicOobDataObject(JNIEnv* env, bt_oob_data_t oob_data) {
env->SetByteArrayRegion(address, 0, OOB_ADDRESS_SIZE,
reinterpret_cast(oob_data.address));
- jmethodID classicBuilderConstructor =
- env->GetMethodID(classicBuilderClass, "", "([B[B[B)V");
+ jclass classicBuilderClass =
+ env->FindClass("android/bluetooth/OobData$ClassicBuilder");
jobject oobDataClassicBuilder =
env->NewObject(classicBuilderClass, classicBuilderConstructor,
confirmationHash, oobDataLength, address);
- jmethodID setRMethod =
- env->GetMethodID(classicBuilderClass, "setRandomizerHash",
- "([B)Landroid/bluetooth/OobData$ClassicBuilder;");
+ env->DeleteLocalRef(classicBuilderClass);
+
jbyteArray randomizerHash = env->NewByteArray(OOB_R_SIZE);
env->SetByteArrayRegion(randomizerHash, 0, OOB_R_SIZE,
reinterpret_cast(oob_data.r));
@@ -564,10 +575,6 @@ static jobject createClassicOobDataObject(JNIEnv* env, bt_oob_data_t oob_data) {
oobDataClassicBuilder =
env->CallObjectMethod(oobDataClassicBuilder, setRMethod, randomizerHash);
- jmethodID setNameMethod =
- env->GetMethodID(classicBuilderClass, "setDeviceName",
- "([B)Landroid/bluetooth/OobData$ClassicBuilder;");
-
int name_char_count = 0;
for (int i = 0; i < OOB_NAME_MAX_SIZE; i++) {
if (oob_data.device_name[i] == 0) {
@@ -583,16 +590,26 @@ static jobject createClassicOobDataObject(JNIEnv* env, bt_oob_data_t oob_data) {
oobDataClassicBuilder =
env->CallObjectMethod(oobDataClassicBuilder, setNameMethod, deviceName);
- jmethodID buildMethod = env->GetMethodID(classicBuilderClass, "build",
- "()Landroid/bluetooth/OobData;");
-
return env->CallObjectMethod(oobDataClassicBuilder, buildMethod);
}
static jobject createLeOobDataObject(JNIEnv* env, bt_oob_data_t oob_data) {
ALOGV("%s", __func__);
- jclass leBuilderClass = env->FindClass("android/bluetooth/OobData$LeBuilder");
+ jmethodID leBuilderConstructor;
+ jmethodID setRMethod;
+ jmethodID setNameMethod;
+ jmethodID buildMethod;
+
+ const JNIJavaMethod javaMethods[] = {
+ {"", "([B[BI)V", &leBuilderConstructor},
+ {"setRandomizerHash", "([B)Landroid/bluetooth/OobData$LeBuilder;",
+ &setRMethod},
+ {"setDeviceName", "([B)Landroid/bluetooth/OobData$LeBuilder;",
+ &setNameMethod},
+ {"build", "()Landroid/bluetooth/OobData;", &buildMethod},
+ };
+ GET_JAVA_METHODS(env, "android/bluetooth/OobData$LeBuilder", javaMethods);
jbyteArray confirmationHash = env->NewByteArray(OOB_C_SIZE);
env->SetByteArrayRegion(confirmationHash, 0, OOB_C_SIZE,
@@ -604,15 +621,13 @@ static jobject createLeOobDataObject(JNIEnv* env, bt_oob_data_t oob_data) {
jint le_role = (jint)oob_data.le_device_role;
- jmethodID leBuilderConstructor =
- env->GetMethodID(leBuilderClass, "", "([B[BI)V");
+ jclass leBuilderClass = env->FindClass("android/bluetooth/OobData$LeBuilder");
jobject oobDataLeBuilder = env->NewObject(
leBuilderClass, leBuilderConstructor, confirmationHash, address, le_role);
- jmethodID setRMethod =
- env->GetMethodID(leBuilderClass, "setRandomizerHash",
- "([B)Landroid/bluetooth/OobData$LeBuilder;");
+ env->DeleteLocalRef(leBuilderClass);
+
jbyteArray randomizerHash = env->NewByteArray(OOB_R_SIZE);
env->SetByteArrayRegion(randomizerHash, 0, OOB_R_SIZE,
reinterpret_cast(oob_data.r));
@@ -620,10 +635,6 @@ static jobject createLeOobDataObject(JNIEnv* env, bt_oob_data_t oob_data) {
oobDataLeBuilder =
env->CallObjectMethod(oobDataLeBuilder, setRMethod, randomizerHash);
- jmethodID setNameMethod =
- env->GetMethodID(leBuilderClass, "setDeviceName",
- "([B)Landroid/bluetooth/OobData$LeBuilder;");
-
int name_char_count = 0;
for (int i = 0; i < OOB_NAME_MAX_SIZE; i++) {
if (oob_data.device_name[i] == 0) {
@@ -639,9 +650,6 @@ static jobject createLeOobDataObject(JNIEnv* env, bt_oob_data_t oob_data) {
oobDataLeBuilder =
env->CallObjectMethod(oobDataLeBuilder, setNameMethod, deviceName);
- jmethodID buildMethod = env->GetMethodID(leBuilderClass, "build",
- "()Landroid/bluetooth/OobData;");
-
return env->CallObjectMethod(oobDataLeBuilder, buildMethod);
}
@@ -740,7 +748,7 @@ static void switch_codec_callback(bool is_low_latency_buffer_size) {
(jboolean)is_low_latency_buffer_size);
}
-static void le_rand_callback(uint64_t random) {
+static void le_rand_callback(uint64_t /* random */) {
// Android doesn't support the LeRand API.
}
@@ -766,6 +774,14 @@ static void callback_thread_event(bt_cb_thread_evt event) {
}
}
+static void dut_mode_recv_callback(uint16_t /* opcode */, uint8_t* /* buf */,
+ uint8_t /* len */) {}
+
+static void le_test_mode_recv_callback(bt_status_t status,
+ uint16_t packet_count) {
+ ALOGV("%s: status:%d packet_count:%d ", __func__, status, packet_count);
+}
+
static void energy_info_recv_callback(bt_activity_energy_info* p_energy_info,
bt_uid_traffic_t* uid_data) {
std::shared_lock lock(jniObjMutex);
@@ -797,7 +813,7 @@ static void energy_info_recv_callback(bt_activity_energy_info* p_energy_info,
}
sCallbackEnv->CallVoidMethod(
- sJniAdapterServiceObj, method_energyInfo, p_energy_info->status,
+ sJniCallbacksObj, method_energyInfo, p_energy_info->status,
p_energy_info->ctrl_state, p_energy_info->tx_time, p_energy_info->rx_time,
p_energy_info->idle_time, p_energy_info->energy_used, array.get());
}
@@ -815,6 +831,8 @@ static bt_callbacks_t sBluetoothCallbacks = {sizeof(sBluetoothCallbacks),
le_address_associate_callback,
acl_state_changed_callback,
callback_thread_event,
+ dut_mode_recv_callback,
+ le_test_mode_recv_callback,
energy_info_recv_callback,
link_quality_report_callback,
generate_local_oob_data_callback,
@@ -822,12 +840,6 @@ static bt_callbacks_t sBluetoothCallbacks = {sizeof(sBluetoothCallbacks),
switch_codec_callback,
le_rand_callback};
-// The callback to call when the wake alarm fires.
-static alarm_cb sAlarmCallback;
-
-// The data to pass to the wake alarm callback.
-static void* sAlarmCallbackData;
-
class JNIThreadAttacher {
public:
JNIThreadAttacher(JavaVM* vm) : vm_(vm), env_(nullptr) {
@@ -874,37 +886,6 @@ class JNIThreadAttacher {
jint status_;
};
-static bool set_wake_alarm_callout(uint64_t delay_millis, bool should_wake,
- alarm_cb cb, void* data) {
- std::shared_lock lock(jniObjMutex);
- if (!sJniAdapterServiceObj) {
- ALOGE("%s, JNI obj is null. Failed to call JNI callback", __func__);
- return false;
- }
-
- JNIThreadAttacher attacher(vm);
- JNIEnv* env = attacher.getEnv();
-
- if (env == nullptr) {
- ALOGE("%s: Unable to get JNI Env", __func__);
- return false;
- }
-
- sAlarmCallback = cb;
- sAlarmCallbackData = data;
-
- jboolean jshould_wake = should_wake ? JNI_TRUE : JNI_FALSE;
- jboolean ret =
- env->CallBooleanMethod(sJniAdapterServiceObj, method_setWakeAlarm,
- (jlong)delay_millis, jshould_wake);
- if (!ret) {
- sAlarmCallback = NULL;
- sAlarmCallbackData = NULL;
- }
-
- return (ret == JNI_TRUE);
-}
-
static int acquire_wake_lock_callout(const char* lock_name) {
std::shared_lock lock(jniObjMutex);
if (!sJniAdapterServiceObj) {
@@ -925,7 +906,7 @@ static int acquire_wake_lock_callout(const char* lock_name) {
ScopedLocalRef lock_name_jni(env, env->NewStringUTF(lock_name));
if (lock_name_jni.get()) {
bool acquired = env->CallBooleanMethod(
- sJniAdapterServiceObj, method_acquireWakeLock, lock_name_jni.get());
+ sJniCallbacksObj, method_acquireWakeLock, lock_name_jni.get());
if (!acquired) ret = BT_STATUS_WAKELOCK_ERROR;
} else {
ALOGE("%s unable to allocate string: %s", __func__, lock_name);
@@ -956,7 +937,7 @@ static int release_wake_lock_callout(const char* lock_name) {
ScopedLocalRef lock_name_jni(env, env->NewStringUTF(lock_name));
if (lock_name_jni.get()) {
bool released = env->CallBooleanMethod(
- sJniAdapterServiceObj, method_releaseWakeLock, lock_name_jni.get());
+ sJniCallbacksObj, method_releaseWakeLock, lock_name_jni.get());
if (!released) ret = BT_STATUS_WAKELOCK_ERROR;
} else {
ALOGE("%s unable to allocate string: %s", __func__, lock_name);
@@ -967,19 +948,10 @@ static int release_wake_lock_callout(const char* lock_name) {
return ret;
}
-// Called by Java code when alarm is fired. A wake lock is held by the caller
-// over the duration of this callback.
-static void alarmFiredNative(JNIEnv* env, jobject obj) {
- if (sAlarmCallback) {
- sAlarmCallback(sAlarmCallbackData);
- } else {
- ALOGE("%s() - Alarm fired with callback not set!", __func__);
- }
-}
-
static bt_os_callouts_t sBluetoothOsCallouts = {
- sizeof(sBluetoothOsCallouts), set_wake_alarm_callout,
- acquire_wake_lock_callout, release_wake_lock_callout,
+ sizeof(sBluetoothOsCallouts),
+ acquire_wake_lock_callout,
+ release_wake_lock_callout,
};
int hal_util_load_bt_library(const bt_interface_t** interface) {
@@ -1019,75 +991,6 @@ error:
#endif
}
-static void classInitNative(JNIEnv* env, jclass clazz) {
- jclass jniUidTrafficClass = env->FindClass("android/bluetooth/UidTraffic");
- android_bluetooth_UidTraffic.constructor =
- env->GetMethodID(jniUidTrafficClass, "", "(IJJ)V");
-
- jclass jniCallbackClass =
- env->FindClass("com/android/bluetooth/btservice/JniCallbacks");
- sJniCallbacksField = env->GetFieldID(
- clazz, "mJniCallbacks", "Lcom/android/bluetooth/btservice/JniCallbacks;");
-
- method_oobDataReceivedCallback =
- env->GetMethodID(jniCallbackClass, "oobDataReceivedCallback",
- "(ILandroid/bluetooth/OobData;)V");
-
- method_stateChangeCallback =
- env->GetMethodID(jniCallbackClass, "stateChangeCallback", "(I)V");
-
- method_adapterPropertyChangedCallback = env->GetMethodID(
- jniCallbackClass, "adapterPropertyChangedCallback", "([I[[B)V");
- method_discoveryStateChangeCallback = env->GetMethodID(
- jniCallbackClass, "discoveryStateChangeCallback", "(I)V");
-
- method_devicePropertyChangedCallback = env->GetMethodID(
- jniCallbackClass, "devicePropertyChangedCallback", "([B[I[[B)V");
- method_deviceFoundCallback =
- env->GetMethodID(jniCallbackClass, "deviceFoundCallback", "([B)V");
- method_pinRequestCallback =
- env->GetMethodID(jniCallbackClass, "pinRequestCallback", "([B[BIZ)V");
- method_sspRequestCallback =
- env->GetMethodID(jniCallbackClass, "sspRequestCallback", "([B[BIII)V");
-
- method_bondStateChangeCallback =
- env->GetMethodID(jniCallbackClass, "bondStateChangeCallback", "(I[BII)V");
-
- method_addressConsolidateCallback = env->GetMethodID(
- jniCallbackClass, "addressConsolidateCallback", "([B[B)V");
-
- method_leAddressAssociateCallback = env->GetMethodID(
- jniCallbackClass, "leAddressAssociateCallback", "([B[B)V");
-
- method_aclStateChangeCallback = env->GetMethodID(
- jniCallbackClass, "aclStateChangeCallback", "(I[BIIII)V");
-
- method_linkQualityReportCallback = env->GetMethodID(
- jniCallbackClass, "linkQualityReportCallback", "(JIIIIII)V");
-
- method_switchBufferSizeCallback =
- env->GetMethodID(jniCallbackClass, "switchBufferSizeCallback", "(Z)V");
-
- method_switchCodecCallback =
- env->GetMethodID(jniCallbackClass, "switchCodecCallback", "(Z)V");
-
- method_setWakeAlarm = env->GetMethodID(clazz, "setWakeAlarm", "(JZ)Z");
- method_acquireWakeLock =
- env->GetMethodID(clazz, "acquireWakeLock", "(Ljava/lang/String;)Z");
- method_releaseWakeLock =
- env->GetMethodID(clazz, "releaseWakeLock", "(Ljava/lang/String;)Z");
- method_energyInfo = env->GetMethodID(
- clazz, "energyInfoCallback", "(IIJJJJ[Landroid/bluetooth/UidTraffic;)V");
-
- if (env->GetJavaVM(&vm) != JNI_OK) {
- ALOGE("Could not get JavaVM");
- }
-
- if (hal_util_load_bt_library((bt_interface_t const**)&sBluetoothInterface)) {
- ALOGE("No Bluetooth Library found");
- }
-}
-
static bool initNative(JNIEnv* env, jobject obj, jboolean isGuest,
jboolean isCommonCriteriaMode, int configCompareResult,
jobjectArray initFlags, jboolean isAtvDevice,
@@ -1160,7 +1063,7 @@ static bool initNative(JNIEnv* env, jobject obj, jboolean isGuest,
return JNI_TRUE;
}
-static bool cleanupNative(JNIEnv* env, jobject obj) {
+static bool cleanupNative(JNIEnv* env, jobject /* obj */) {
std::unique_lock lock(jniObjMutex);
ALOGV("%s", __func__);
@@ -1187,7 +1090,7 @@ static bool cleanupNative(JNIEnv* env, jobject obj) {
return JNI_TRUE;
}
-static jboolean enableNative(JNIEnv* env, jobject obj) {
+static jboolean enableNative(JNIEnv* /* env */, jobject /* obj */) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1196,7 +1099,7 @@ static jboolean enableNative(JNIEnv* env, jobject obj) {
: JNI_FALSE;
}
-static jboolean disableNative(JNIEnv* env, jobject obj) {
+static jboolean disableNative(JNIEnv* /* env */, jobject /* obj */) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1209,7 +1112,7 @@ static jboolean disableNative(JNIEnv* env, jobject obj) {
return (ret == BT_STATUS_FAIL) ? JNI_FALSE : JNI_TRUE;
}
-static jboolean startDiscoveryNative(JNIEnv* env, jobject obj) {
+static jboolean startDiscoveryNative(JNIEnv* /* env */, jobject /* obj */) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1218,7 +1121,7 @@ static jboolean startDiscoveryNative(JNIEnv* env, jobject obj) {
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean cancelDiscoveryNative(JNIEnv* env, jobject obj) {
+static jboolean cancelDiscoveryNative(JNIEnv* /* env */, jobject /* obj */) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1227,8 +1130,9 @@ static jboolean cancelDiscoveryNative(JNIEnv* env, jobject obj) {
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean createBondNative(JNIEnv* env, jobject obj, jbyteArray address,
- jint addrType, jint transport) {
+static jboolean createBondNative(JNIEnv* env, jobject /* obj */,
+ jbyteArray address, jint addrType,
+ jint transport) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1260,6 +1164,7 @@ static jbyteArray callByteArrayGetter(JNIEnv* env, jobject object,
const char* methodName) {
jclass myClass = env->FindClass(className);
jmethodID myMethod = env->GetMethodID(myClass, methodName, "()[B");
+ env->DeleteLocalRef(myClass);
return (jbyteArray)env->CallObjectMethod(object, myMethod);
}
@@ -1267,6 +1172,7 @@ static jint callIntGetter(JNIEnv* env, jobject object, const char* className,
const char* methodName) {
jclass myClass = env->FindClass(className);
jmethodID myMethod = env->GetMethodID(myClass, methodName, "()I");
+ env->DeleteLocalRef(myClass);
return env->CallIntMethod(object, myMethod);
}
@@ -1450,7 +1356,7 @@ static jboolean set_data(JNIEnv* env, bt_oob_data_t& oob_data, jobject oobData,
return JNI_TRUE;
}
-static void generateLocalOobDataNative(JNIEnv* env, jobject obj,
+static void generateLocalOobDataNative(JNIEnv* /* env */, jobject /* obj */,
jint transport) {
// No BT interface? Can't do anything.
if (!sBluetoothInterface) return;
@@ -1464,7 +1370,7 @@ static void generateLocalOobDataNative(JNIEnv* env, jobject obj,
}
}
-static jboolean createBondOutOfBandNative(JNIEnv* env, jobject obj,
+static jboolean createBondOutOfBandNative(JNIEnv* env, jobject /* obj */,
jbyteArray address, jint transport,
jobject p192Data, jobject p256Data) {
// No BT interface? Can't do anything.
@@ -1526,7 +1432,8 @@ static jboolean createBondOutOfBandNative(JNIEnv* env, jobject obj,
: JNI_FALSE;
}
-static jboolean removeBondNative(JNIEnv* env, jobject obj, jbyteArray address) {
+static jboolean removeBondNative(JNIEnv* env, jobject /* obj */,
+ jbyteArray address) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1543,7 +1450,8 @@ static jboolean removeBondNative(JNIEnv* env, jobject obj, jbyteArray address) {
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean cancelBondNative(JNIEnv* env, jobject obj, jbyteArray address) {
+static jboolean cancelBondNative(JNIEnv* env, jobject /* obj */,
+ jbyteArray address) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1559,7 +1467,7 @@ static jboolean cancelBondNative(JNIEnv* env, jobject obj, jbyteArray address) {
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static int getConnectionStateNative(JNIEnv* env, jobject obj,
+static int getConnectionStateNative(JNIEnv* env, jobject /* obj */,
jbyteArray address) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1576,8 +1484,9 @@ static int getConnectionStateNative(JNIEnv* env, jobject obj,
return ret;
}
-static jboolean pinReplyNative(JNIEnv* env, jobject obj, jbyteArray address,
- jboolean accept, jint len, jbyteArray pinArray) {
+static jboolean pinReplyNative(JNIEnv* env, jobject /* obj */,
+ jbyteArray address, jboolean accept, jint len,
+ jbyteArray pinArray) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1606,8 +1515,9 @@ static jboolean pinReplyNative(JNIEnv* env, jobject obj, jbyteArray address,
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean sspReplyNative(JNIEnv* env, jobject obj, jbyteArray address,
- jint type, jboolean accept, jint passkey) {
+static jboolean sspReplyNative(JNIEnv* env, jobject /* obj */,
+ jbyteArray address, jint type, jboolean accept,
+ jint passkey) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1625,8 +1535,8 @@ static jboolean sspReplyNative(JNIEnv* env, jobject obj, jbyteArray address,
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean setAdapterPropertyNative(JNIEnv* env, jobject obj, jint type,
- jbyteArray value) {
+static jboolean setAdapterPropertyNative(JNIEnv* env, jobject /* obj */,
+ jint type, jbyteArray value) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1643,7 +1553,8 @@ static jboolean setAdapterPropertyNative(JNIEnv* env, jobject obj, jint type,
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean getAdapterPropertiesNative(JNIEnv* env, jobject obj) {
+static jboolean getAdapterPropertiesNative(JNIEnv* /* env */,
+ jobject /* obj */) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1652,7 +1563,8 @@ static jboolean getAdapterPropertiesNative(JNIEnv* env, jobject obj) {
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean getAdapterPropertyNative(JNIEnv* env, jobject obj, jint type) {
+static jboolean getAdapterPropertyNative(JNIEnv* /* env */, jobject /* obj */,
+ jint type) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1661,7 +1573,7 @@ static jboolean getAdapterPropertyNative(JNIEnv* env, jobject obj, jint type) {
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean getDevicePropertyNative(JNIEnv* env, jobject obj,
+static jboolean getDevicePropertyNative(JNIEnv* env, jobject /* obj */,
jbyteArray address, jint type) {
ALOGV("%s", __func__);
@@ -1679,7 +1591,7 @@ static jboolean getDevicePropertyNative(JNIEnv* env, jobject obj,
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean setDevicePropertyNative(JNIEnv* env, jobject obj,
+static jboolean setDevicePropertyNative(JNIEnv* env, jobject /* obj */,
jbyteArray address, jint type,
jbyteArray value) {
ALOGV("%s", __func__);
@@ -1712,7 +1624,7 @@ static jboolean setDevicePropertyNative(JNIEnv* env, jobject obj,
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean getRemoteServicesNative(JNIEnv* env, jobject obj,
+static jboolean getRemoteServicesNative(JNIEnv* env, jobject /* obj */,
jbyteArray address, jint transport) {
ALOGV("%s", __func__);
@@ -1730,7 +1642,7 @@ static jboolean getRemoteServicesNative(JNIEnv* env, jobject obj,
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static int readEnergyInfo() {
+static int readEnergyInfoNative() {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1738,7 +1650,7 @@ static int readEnergyInfo() {
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static void dumpNative(JNIEnv* env, jobject obj, jobject fdObj,
+static void dumpNative(JNIEnv* env, jobject /* obj */, jobject fdObj,
jobjectArray argArray) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return;
@@ -1770,7 +1682,7 @@ static void dumpNative(JNIEnv* env, jobject obj, jobject fdObj,
delete[] argObjs;
}
-static jbyteArray dumpMetricsNative(JNIEnv* env, jobject obj) {
+static jbyteArray dumpMetricsNative(JNIEnv* env, jobject /* obj */) {
ALOGI("%s", __func__);
if (!sBluetoothInterface) return env->NewByteArray(0);
@@ -1783,14 +1695,14 @@ static jbyteArray dumpMetricsNative(JNIEnv* env, jobject obj) {
return output_bytes;
}
-static jboolean factoryResetNative(JNIEnv* env, jobject obj) {
+static jboolean factoryResetNative(JNIEnv* /* env */, jobject /* obj */) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
int ret = sBluetoothInterface->config_clear();
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jbyteArray obfuscateAddressNative(JNIEnv* env, jobject obj,
+static jbyteArray obfuscateAddressNative(JNIEnv* env, jobject /* obj */,
jbyteArray address) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return env->NewByteArray(0);
@@ -1809,8 +1721,9 @@ static jbyteArray obfuscateAddressNative(JNIEnv* env, jobject obj,
return output_bytes;
}
-static jboolean setBufferLengthMillisNative(JNIEnv* env, jobject obj,
- jint codec, jint size) {
+static jboolean setBufferLengthMillisNative(JNIEnv* /* env */,
+ jobject /* obj */, jint codec,
+ jint size) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -1819,9 +1732,9 @@ static jboolean setBufferLengthMillisNative(JNIEnv* env, jobject obj,
return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jint connectSocketNative(JNIEnv* env, jobject obj, jbyteArray address,
- jint type, jbyteArray uuid, jint port,
- jint flag, jint callingUid) {
+static jint connectSocketNative(JNIEnv* env, jobject /* obj */,
+ jbyteArray address, jint type, jbyteArray uuid,
+ jint port, jint flag, jint callingUid) {
int socket_fd = INVALID_FD;
jbyte* addr = nullptr;
jbyte* uuidBytes = nullptr;
@@ -1850,7 +1763,7 @@ done:
return socket_fd;
}
-static jint createSocketChannelNative(JNIEnv* env, jobject obj, jint type,
+static jint createSocketChannelNative(JNIEnv* env, jobject /* obj */, jint type,
jstring serviceName, jbyteArray uuid,
jint port, jint flag, jint callingUid) {
int socket_fd = INVALID_FD;
@@ -1884,7 +1797,7 @@ done:
return socket_fd;
}
-static void requestMaximumTxDataLengthNative(JNIEnv* env, jobject obj,
+static void requestMaximumTxDataLengthNative(JNIEnv* env, jobject /* obj */,
jbyteArray address) {
if (!sBluetoothSocketInterface) {
return;
@@ -1900,7 +1813,8 @@ static void requestMaximumTxDataLengthNative(JNIEnv* env, jobject obj,
env->ReleaseByteArrayElements(address, addr, 1);
}
-static int getMetricIdNative(JNIEnv* env, jobject obj, jbyteArray address) {
+static int getMetricIdNative(JNIEnv* env, jobject /* obj */,
+ jbyteArray address) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return 0; // 0 is invalid id
jbyte* addr = env->GetByteArrayElements(address, nullptr);
@@ -1913,7 +1827,7 @@ static int getMetricIdNative(JNIEnv* env, jobject obj, jbyteArray address) {
return sBluetoothInterface->get_metric_id(addr_obj);
}
-static jboolean allowLowLatencyAudioNative(JNIEnv* env, jobject obj,
+static jboolean allowLowLatencyAudioNative(JNIEnv* env, jobject /* obj */,
jboolean allowed,
jbyteArray address) {
ALOGV("%s", __func__);
@@ -1930,8 +1844,9 @@ static jboolean allowLowLatencyAudioNative(JNIEnv* env, jobject obj,
return true;
}
-static void metadataChangedNative(JNIEnv* env, jobject obj, jbyteArray address,
- jint key, jbyteArray value) {
+static void metadataChangedNative(JNIEnv* env, jobject /* obj */,
+ jbyteArray address, jint key,
+ jbyteArray value) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return;
jbyte* addr = env->GetByteArrayElements(address, nullptr);
@@ -1959,12 +1874,13 @@ static void metadataChangedNative(JNIEnv* env, jobject obj, jbyteArray address,
return;
}
-static jboolean isLogRedactionEnabled(JNIEnv* env, jobject obj) {
+static jboolean isLogRedactionEnabledNative(JNIEnv* /* env */,
+ jobject /* obj */) {
ALOGV("%s", __func__);
return bluetooth::os::should_log_be_redacted();
}
-static jboolean interopMatchAddrNative(JNIEnv* env, jclass clazz,
+static jboolean interopMatchAddrNative(JNIEnv* env, jclass /* clazz */,
jstring feature_name, jstring address) {
ALOGV("%s", __func__);
@@ -2001,7 +1917,7 @@ static jboolean interopMatchAddrNative(JNIEnv* env, jclass clazz,
return matched ? JNI_TRUE : JNI_FALSE;
}
-static jboolean interopMatchNameNative(JNIEnv* env, jclass clazz,
+static jboolean interopMatchNameNative(JNIEnv* env, jclass /* clazz */,
jstring feature_name, jstring name) {
ALOGV("%s", __func__);
@@ -2031,7 +1947,7 @@ static jboolean interopMatchNameNative(JNIEnv* env, jclass clazz,
return matched ? JNI_TRUE : JNI_FALSE;
}
-static jboolean interopMatchAddrOrNameNative(JNIEnv* env, jclass clazz,
+static jboolean interopMatchAddrOrNameNative(JNIEnv* env, jclass /* clazz */,
jstring feature_name,
jstring address) {
ALOGV("%s", __func__);
@@ -2069,7 +1985,7 @@ static jboolean interopMatchAddrOrNameNative(JNIEnv* env, jclass clazz,
return matched ? JNI_TRUE : JNI_FALSE;
}
-static void interopDatabaseAddRemoveAddrNative(JNIEnv* env, jclass clazz,
+static void interopDatabaseAddRemoveAddrNative(JNIEnv* env, jclass /* clazz */,
jboolean do_add,
jstring feature_name,
jstring address, jint length) {
@@ -2113,7 +2029,7 @@ static void interopDatabaseAddRemoveAddrNative(JNIEnv* env, jclass clazz,
env->ReleaseStringUTFChars(feature_name, feature_name_str);
}
-static void interopDatabaseAddRemoveNameNative(JNIEnv* env, jclass clazz,
+static void interopDatabaseAddRemoveNameNative(JNIEnv* env, jclass /* clazz */,
jboolean do_add,
jstring feature_name,
jstring name) {
@@ -2144,7 +2060,7 @@ static void interopDatabaseAddRemoveNameNative(JNIEnv* env, jclass clazz,
env->ReleaseStringUTFChars(name, name_str);
}
-static int getRemotePbapPceVersionNative(JNIEnv* env, jobject obj,
+static int getRemotePbapPceVersionNative(JNIEnv* env, jobject /* obj */,
jstring address) {
ALOGV("%s", __func__);
@@ -2169,8 +2085,8 @@ static int getRemotePbapPceVersionNative(JNIEnv* env, jobject obj,
return sBluetoothInterface->get_remote_pbap_pce_version(&bdaddr);
}
-static jboolean pbapPseDynamicVersionUpgradeIsEnabledNative(JNIEnv* env,
- jobject obj) {
+static jboolean pbapPseDynamicVersionUpgradeIsEnabledNative(JNIEnv* /* env */,
+ jobject /* obj */) {
ALOGV("%s", __func__);
if (!sBluetoothInterface) return JNI_FALSE;
@@ -2180,72 +2096,126 @@ static jboolean pbapPseDynamicVersionUpgradeIsEnabledNative(JNIEnv* env,
: JNI_FALSE;
}
-static JNINativeMethod sMethods[] = {
- /* name, signature, funcPtr */
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative", "(ZZI[Ljava/lang/String;ZLjava/lang/String;)Z",
- (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"enableNative", "()Z", (void*)enableNative},
- {"disableNative", "()Z", (void*)disableNative},
- {"setAdapterPropertyNative", "(I[B)Z", (void*)setAdapterPropertyNative},
- {"getAdapterPropertiesNative", "()Z", (void*)getAdapterPropertiesNative},
- {"getAdapterPropertyNative", "(I)Z", (void*)getAdapterPropertyNative},
- {"getDevicePropertyNative", "([BI)Z", (void*)getDevicePropertyNative},
- {"setDevicePropertyNative", "([BI[B)Z", (void*)setDevicePropertyNative},
- {"startDiscoveryNative", "()Z", (void*)startDiscoveryNative},
- {"cancelDiscoveryNative", "()Z", (void*)cancelDiscoveryNative},
- {"createBondNative", "([BII)Z", (void*)createBondNative},
- {"createBondOutOfBandNative",
- "([BILandroid/bluetooth/OobData;Landroid/bluetooth/OobData;)Z",
- (void*)createBondOutOfBandNative},
- {"removeBondNative", "([B)Z", (void*)removeBondNative},
- {"cancelBondNative", "([B)Z", (void*)cancelBondNative},
- {"generateLocalOobDataNative", "(I)V", (void*)generateLocalOobDataNative},
- {"getConnectionStateNative", "([B)I", (void*)getConnectionStateNative},
- {"pinReplyNative", "([BZI[B)Z", (void*)pinReplyNative},
- {"sspReplyNative", "([BIZI)Z", (void*)sspReplyNative},
- {"getRemoteServicesNative", "([BI)Z", (void*)getRemoteServicesNative},
- {"alarmFiredNative", "()V", (void*)alarmFiredNative},
- {"readEnergyInfo", "()I", (void*)readEnergyInfo},
- {"dumpNative", "(Ljava/io/FileDescriptor;[Ljava/lang/String;)V",
- (void*)dumpNative},
- {"dumpMetricsNative", "()[B", (void*)dumpMetricsNative},
- {"factoryResetNative", "()Z", (void*)factoryResetNative},
- {"obfuscateAddressNative", "([B)[B", (void*)obfuscateAddressNative},
- {"setBufferLengthMillisNative", "(II)Z",
- (void*)setBufferLengthMillisNative},
- {"getMetricIdNative", "([B)I", (void*)getMetricIdNative},
- {"connectSocketNative", "([BI[BIII)I", (void*)connectSocketNative},
- {"createSocketChannelNative", "(ILjava/lang/String;[BIII)I",
- (void*)createSocketChannelNative},
- {"requestMaximumTxDataLengthNative", "([B)V",
- (void*)requestMaximumTxDataLengthNative},
- {"allowLowLatencyAudioNative", "(Z[B)Z", (void*)allowLowLatencyAudioNative},
- {"metadataChangedNative", "([BI[B)V", (void*)metadataChangedNative},
- {"isLogRedactionEnabled", "()Z", (void*)isLogRedactionEnabled},
- {"interopMatchAddrNative", "(Ljava/lang/String;Ljava/lang/String;)Z",
- (void*)interopMatchAddrNative},
- {"interopMatchNameNative", "(Ljava/lang/String;Ljava/lang/String;)Z",
- (void*)interopMatchNameNative},
- {"interopMatchAddrOrNameNative", "(Ljava/lang/String;Ljava/lang/String;)Z",
- (void*)interopMatchAddrOrNameNative},
- {"interopDatabaseAddRemoveAddrNative",
- "(ZLjava/lang/String;Ljava/lang/String;I)V",
- (void*)interopDatabaseAddRemoveAddrNative},
- {"interopDatabaseAddRemoveNameNative",
- "(ZLjava/lang/String;Ljava/lang/String;)V",
- (void*)interopDatabaseAddRemoveNameNative},
- {"getRemotePbapPceVersionNative", "(Ljava/lang/String;)I",
- (void*)getRemotePbapPceVersionNative},
- {"pbapPseDynamicVersionUpgradeIsEnabledNative", "()Z",
- (void*)pbapPseDynamicVersionUpgradeIsEnabledNative},
-};
-
int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) {
- return jniRegisterNativeMethods(
- env, "com/android/bluetooth/btservice/AdapterService", sMethods,
- NELEM(sMethods));
+ const JNINativeMethod methods[] = {
+ {"initNative", "(ZZI[Ljava/lang/String;ZLjava/lang/String;)Z",
+ (void*)initNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"enableNative", "()Z", (void*)enableNative},
+ {"disableNative", "()Z", (void*)disableNative},
+ {"setAdapterPropertyNative", "(I[B)Z", (void*)setAdapterPropertyNative},
+ {"getAdapterPropertiesNative", "()Z", (void*)getAdapterPropertiesNative},
+ {"getAdapterPropertyNative", "(I)Z", (void*)getAdapterPropertyNative},
+ {"getDevicePropertyNative", "([BI)Z", (void*)getDevicePropertyNative},
+ {"setDevicePropertyNative", "([BI[B)Z", (void*)setDevicePropertyNative},
+ {"startDiscoveryNative", "()Z", (void*)startDiscoveryNative},
+ {"cancelDiscoveryNative", "()Z", (void*)cancelDiscoveryNative},
+ {"createBondNative", "([BII)Z", (void*)createBondNative},
+ {"createBondOutOfBandNative",
+ "([BILandroid/bluetooth/OobData;Landroid/bluetooth/OobData;)Z",
+ (void*)createBondOutOfBandNative},
+ {"removeBondNative", "([B)Z", (void*)removeBondNative},
+ {"cancelBondNative", "([B)Z", (void*)cancelBondNative},
+ {"generateLocalOobDataNative", "(I)V", (void*)generateLocalOobDataNative},
+ {"getConnectionStateNative", "([B)I", (void*)getConnectionStateNative},
+ {"pinReplyNative", "([BZI[B)Z", (void*)pinReplyNative},
+ {"sspReplyNative", "([BIZI)Z", (void*)sspReplyNative},
+ {"getRemoteServicesNative", "([BI)Z", (void*)getRemoteServicesNative},
+ {"readEnergyInfoNative", "()I", (void*)readEnergyInfoNative},
+ {"dumpNative", "(Ljava/io/FileDescriptor;[Ljava/lang/String;)V",
+ (void*)dumpNative},
+ {"dumpMetricsNative", "()[B", (void*)dumpMetricsNative},
+ {"factoryResetNative", "()Z", (void*)factoryResetNative},
+ {"obfuscateAddressNative", "([B)[B", (void*)obfuscateAddressNative},
+ {"setBufferLengthMillisNative", "(II)Z",
+ (void*)setBufferLengthMillisNative},
+ {"getMetricIdNative", "([B)I", (void*)getMetricIdNative},
+ {"connectSocketNative", "([BI[BIII)I", (void*)connectSocketNative},
+ {"createSocketChannelNative", "(ILjava/lang/String;[BIII)I",
+ (void*)createSocketChannelNative},
+ {"requestMaximumTxDataLengthNative", "([B)V",
+ (void*)requestMaximumTxDataLengthNative},
+ {"allowLowLatencyAudioNative", "(Z[B)Z",
+ (void*)allowLowLatencyAudioNative},
+ {"metadataChangedNative", "([BI[B)V", (void*)metadataChangedNative},
+ {"isLogRedactionEnabledNative", "()Z",
+ (void*)isLogRedactionEnabledNative},
+ {"interopMatchAddrNative", "(Ljava/lang/String;Ljava/lang/String;)Z",
+ (void*)interopMatchAddrNative},
+ {"interopMatchNameNative", "(Ljava/lang/String;Ljava/lang/String;)Z",
+ (void*)interopMatchNameNative},
+ {"interopMatchAddrOrNameNative",
+ "(Ljava/lang/String;Ljava/lang/String;)Z",
+ (void*)interopMatchAddrOrNameNative},
+ {"interopDatabaseAddRemoveAddrNative",
+ "(ZLjava/lang/String;Ljava/lang/String;I)V",
+ (void*)interopDatabaseAddRemoveAddrNative},
+ {"interopDatabaseAddRemoveNameNative",
+ "(ZLjava/lang/String;Ljava/lang/String;)V",
+ (void*)interopDatabaseAddRemoveNameNative},
+ {"getRemotePbapPceVersionNative", "(Ljava/lang/String;)I",
+ (void*)getRemotePbapPceVersionNative},
+ {"pbapPseDynamicVersionUpgradeIsEnabledNative", "()Z",
+ (void*)pbapPseDynamicVersionUpgradeIsEnabledNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/btservice/AdapterNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ jclass jniAdapterNativeInterfaceClass =
+ env->FindClass("com/android/bluetooth/btservice/AdapterNativeInterface");
+ sJniCallbacksField =
+ env->GetFieldID(jniAdapterNativeInterfaceClass, "mJniCallbacks",
+ "Lcom/android/bluetooth/btservice/JniCallbacks;");
+ env->DeleteLocalRef(jniAdapterNativeInterfaceClass);
+
+ const JNIJavaMethod javaMethods[] = {
+ {"oobDataReceivedCallback", "(ILandroid/bluetooth/OobData;)V",
+ &method_oobDataReceivedCallback},
+ {"stateChangeCallback", "(I)V", &method_stateChangeCallback},
+ {"adapterPropertyChangedCallback", "([I[[B)V",
+ &method_adapterPropertyChangedCallback},
+ {"discoveryStateChangeCallback", "(I)V",
+ &method_discoveryStateChangeCallback},
+ {"devicePropertyChangedCallback", "([B[I[[B)V",
+ &method_devicePropertyChangedCallback},
+ {"deviceFoundCallback", "([B)V", &method_deviceFoundCallback},
+ {"pinRequestCallback", "([B[BIZ)V", &method_pinRequestCallback},
+ {"sspRequestCallback", "([B[BIII)V", &method_sspRequestCallback},
+ {"bondStateChangeCallback", "(I[BII)V", &method_bondStateChangeCallback},
+ {"addressConsolidateCallback", "([B[B)V",
+ &method_addressConsolidateCallback},
+ {"leAddressAssociateCallback", "([B[B)V",
+ &method_leAddressAssociateCallback},
+ {"aclStateChangeCallback", "(I[BIIII)V", &method_aclStateChangeCallback},
+ {"linkQualityReportCallback", "(JIIIIII)V",
+ &method_linkQualityReportCallback},
+ {"switchBufferSizeCallback", "(Z)V", &method_switchBufferSizeCallback},
+ {"switchCodecCallback", "(Z)V", &method_switchCodecCallback},
+ {"acquireWakeLock", "(Ljava/lang/String;)Z", &method_acquireWakeLock},
+ {"releaseWakeLock", "(Ljava/lang/String;)Z", &method_releaseWakeLock},
+ {"energyInfoCallback", "(IIJJJJ[Landroid/bluetooth/UidTraffic;)V",
+ &method_energyInfo},
+ };
+ GET_JAVA_METHODS(env, "com/android/bluetooth/btservice/JniCallbacks",
+ javaMethods);
+
+ const JNIJavaMethod javaUuidTrafficMethods[] = {
+ {"", "(IJJ)V", &android_bluetooth_UidTraffic.constructor},
+ };
+ GET_JAVA_METHODS(env, "android/bluetooth/UidTraffic", javaUuidTrafficMethods);
+
+ if (env->GetJavaVM(&vm) != JNI_OK) {
+ ALOGE("Could not get JavaVM");
+ }
+
+ if (hal_util_load_bt_library((bt_interface_t const**)&sBluetoothInterface)) {
+ ALOGE("No Bluetooth Library found");
+ }
+
+ return 0;
}
} /* namespace android */
@@ -2253,7 +2223,7 @@ int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) {
/*
* JNI Initialization
*/
-jint JNI_OnLoad(JavaVM* jvm, void* reserved) {
+jint JNI_OnLoad(JavaVM* jvm, void* /* reserved */) {
JNIEnv* e;
int status;
@@ -2271,13 +2241,6 @@ jint JNI_OnLoad(JavaVM* jvm, void* reserved) {
return JNI_ERR;
}
- status =
- android::register_com_android_bluetooth_btservice_activity_attribution(e);
- if (status < 0) {
- ALOGE("jni activity attribution registration failure: %d", status);
- return JNI_ERR;
- }
-
status =
android::register_com_android_bluetooth_btservice_BluetoothKeystore(e);
if (status < 0) {
@@ -2391,3 +2354,32 @@ jint JNI_OnLoad(JavaVM* jvm, void* reserved) {
return JNI_VERSION_1_6;
}
+
+namespace android {
+
+/** Load the java methods or die*/
+void jniGetMethodsOrDie(JNIEnv* env, const char* className,
+ const JNIJavaMethod* methods, int nMethods) {
+ jclass clazz = env->FindClass(className);
+ if (clazz == nullptr) {
+ LOG(FATAL) << "Native registration unable to find class '" << className
+ << "'; aborting...";
+ }
+
+ for (int i = 0; i < nMethods; i++) {
+ const JNIJavaMethod& method = methods[i];
+ if (method.is_static) {
+ *method.id = env->GetStaticMethodID(clazz, method.name, method.signature);
+ } else {
+ *method.id = env->GetMethodID(clazz, method.name, method.signature);
+ }
+ if (method.id == nullptr) {
+ LOG(FATAL) << "In class " << className << ": Unable to find '"
+ << method.name << "' with signature=" << method.signature
+ << " is_static=" << method.is_static;
+ }
+ }
+
+ env->DeleteLocalRef(clazz);
+}
+} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_btservice_BluetoothKeystore.cpp b/android/app/jni/com_android_bluetooth_btservice_BluetoothKeystore.cpp
index bceea1d735b7e7654fa05b87718f6e9cef51c0a8..1c5e382c52b07c6f3ad0fb13778ea2f021261861 100644
--- a/android/app/jni/com_android_bluetooth_btservice_BluetoothKeystore.cpp
+++ b/android/app/jni/com_android_bluetooth_btservice_BluetoothKeystore.cpp
@@ -86,17 +86,6 @@ class BluetoothKeystoreCallbacksImpl
static BluetoothKeystoreCallbacksImpl sBluetoothKeystoreCallbacks;
-static void classInitNative(JNIEnv* env, jclass clazz) {
- method_setEncryptKeyOrRemoveKeyCallback =
- env->GetMethodID(clazz, "setEncryptKeyOrRemoveKeyCallback",
- "(Ljava/lang/String;Ljava/lang/String;)V");
-
- method_getKeyCallback = env->GetMethodID(
- clazz, "getKeyCallback", "(Ljava/lang/String;)Ljava/lang/String;");
-
- LOG(INFO) << __func__ << ": succeeds";
-}
-
static void initNative(JNIEnv* env, jobject object) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -135,7 +124,7 @@ static void initNative(JNIEnv* env, jobject object) {
sBluetoothKeystoreInterface->init(&sBluetoothKeystoreCallbacks);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -155,17 +144,32 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative", "()V", (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
-};
-
int register_com_android_bluetooth_btservice_BluetoothKeystore(JNIEnv* env) {
- return jniRegisterNativeMethods(
+ const JNINativeMethod methods[] = {
+ {"initNative", "()V", (void*)initNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
env,
"com/android/bluetooth/btservice/bluetoothkeystore/"
"BluetoothKeystoreNativeInterface",
- sMethods, NELEM(sMethods));
+ methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"setEncryptKeyOrRemoveKeyCallback",
+ "(Ljava/lang/String;Ljava/lang/String;)V",
+ &method_setEncryptKeyOrRemoveKeyCallback},
+ {"getKeyCallback", "(Ljava/lang/String;)Ljava/lang/String;",
+ &method_getKeyCallback},
+ };
+ GET_JAVA_METHODS(env,
+ "com/android/bluetooth/btservice/bluetoothkeystore/"
+ "BluetoothKeystoreNativeInterface",
+ javaMethods);
+
+ return 0;
}
} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_csip_set_coordinator.cpp b/android/app/jni/com_android_bluetooth_csip_set_coordinator.cpp
index 1050bd2ad97e9c6671e5ae3dfb9b6b9259da69e0..bd24892a76443e2a2dc21a7eeebc9242f0c3dd41 100644
--- a/android/app/jni/com_android_bluetooth_csip_set_coordinator.cpp
+++ b/android/app/jni/com_android_bluetooth_csip_set_coordinator.cpp
@@ -75,7 +75,8 @@ class CsisClientCallbacksImpl : public CsisClientCallbacks {
void OnConnectionState(const RawAddress& bd_addr,
ConnectionState state) override {
- LOG(INFO) << __func__;
+ LOG(INFO) << __func__ << ", state:" << int(state)
+ << ", addr: " << bd_addr.ToRedactedStringForLogging();
std::shared_lock lock(callbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
@@ -152,22 +153,6 @@ class CsisClientCallbacksImpl : public CsisClientCallbacks {
static CsisClientCallbacksImpl sCsisClientCallbacks;
-static void classInitNative(JNIEnv* env, jclass clazz) {
- method_onConnectionStateChanged =
- env->GetMethodID(clazz, "onConnectionStateChanged", "([BI)V");
-
- method_onDeviceAvailable =
- env->GetMethodID(clazz, "onDeviceAvailable", "([BIIIJJ)V");
-
- method_onSetMemberAvailable =
- env->GetMethodID(clazz, "onSetMemberAvailable", "([BI)V");
-
- method_onGroupLockChanged =
- env->GetMethodID(clazz, "onGroupLockChanged", "(IZI)V");
-
- LOG(INFO) << __func__ << ": succeeds";
-}
-
static void initNative(JNIEnv* env, jobject object) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -205,7 +190,7 @@ static void initNative(JNIEnv* env, jobject object) {
sCsisClientInterface->Init(&sCsisClientCallbacks);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -226,7 +211,8 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static jboolean connectNative(JNIEnv* env, jobject object, jbyteArray address) {
+static jboolean connectNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sCsisClientInterface) {
LOG(ERROR) << __func__
@@ -246,7 +232,7 @@ static jboolean connectNative(JNIEnv* env, jobject object, jbyteArray address) {
return JNI_TRUE;
}
-static jboolean disconnectNative(JNIEnv* env, jobject object,
+static jboolean disconnectNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sCsisClientInterface) {
@@ -266,8 +252,8 @@ static jboolean disconnectNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static void groupLockSetNative(JNIEnv* env, jobject object, jint group_id,
- jboolean lock) {
+static void groupLockSetNative(JNIEnv* /* env */, jobject /* object */,
+ jint group_id, jboolean lock) {
LOG(INFO) << __func__;
if (!sCsisClientInterface) {
@@ -279,18 +265,31 @@ static void groupLockSetNative(JNIEnv* env, jobject object, jint group_id,
sCsisClientInterface->LockGroup(group_id, lock);
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative", "()V", (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"connectNative", "([B)Z", (void*)connectNative},
- {"disconnectNative", "([B)Z", (void*)disconnectNative},
- {"groupLockSetNative", "(IZ)V", (void*)groupLockSetNative},
-};
-
int register_com_android_bluetooth_csip_set_coordinator(JNIEnv* env) {
- return jniRegisterNativeMethods(
+ const JNINativeMethod methods[] = {
+ {"initNative", "()V", (void*)initNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"connectNative", "([B)Z", (void*)connectNative},
+ {"disconnectNative", "([B)Z", (void*)disconnectNative},
+ {"groupLockSetNative", "(IZ)V", (void*)groupLockSetNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/csip/CsipSetCoordinatorNativeInterface",
+ methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[]{
+ {"onConnectionStateChanged", "([BI)V", &method_onConnectionStateChanged},
+ {"onDeviceAvailable", "([BIIIJJ)V", &method_onDeviceAvailable},
+ {"onSetMemberAvailable", "([BI)V", &method_onSetMemberAvailable},
+ {"onGroupLockChanged", "(IZI)V", &method_onGroupLockChanged},
+ };
+ GET_JAVA_METHODS(
env, "com/android/bluetooth/csip/CsipSetCoordinatorNativeInterface",
- sMethods, NELEM(sMethods));
+ javaMethods);
+
+ return 0;
}
} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_gatt.cpp b/android/app/jni/com_android_bluetooth_gatt.cpp
index cf12ce0a8742b75f23d7010fe19b00345383357b..0e1836937369d713072fee24fffc594548e9bce8 100644
--- a/android/app/jni/com_android_bluetooth_gatt.cpp
+++ b/android/app/jni/com_android_bluetooth_gatt.cpp
@@ -28,6 +28,7 @@
#include "com_android_bluetooth.h"
#include "gd/common/init_flags.h"
#include "hardware/bt_gatt.h"
+#include "hardware/bt_gatt_types.h"
#include "rust/cxx.h"
#include "rust/src/gatt/ffi/gatt_shim.h"
#include "src/gatt/ffi.rs.h"
@@ -490,14 +491,19 @@ void fillGattDbElementArray(JNIEnv* env, jobject* array,
jmethodID gattDbElementConstructor =
env->GetMethodID(gattDbElementClazz.get(), "", "()V");
- ScopedLocalRef arrayListclazz(env,
- env->FindClass("java/util/ArrayList"));
- jmethodID arrayAdd =
- env->GetMethodID(arrayListclazz.get(), "add", "(Ljava/lang/Object;)Z");
+ jmethodID arrayAdd;
- ScopedLocalRef uuidClazz(env, env->FindClass("java/util/UUID"));
- jmethodID uuidConstructor =
- env->GetMethodID(uuidClazz.get(), "", "(JJ)V");
+ const JNIJavaMethod javaMethods[] = {
+ {"add", "(Ljava/lang/Object;)Z", &arrayAdd},
+ };
+ GET_JAVA_METHODS(env, "java/util/ArrayList", javaMethods);
+
+ jmethodID uuidConstructor;
+
+ const JNIJavaMethod javaUuidMethods[] = {
+ {"", "(JJ)V", &uuidConstructor},
+ };
+ GET_JAVA_METHODS(env, "java/util/UUID", javaUuidMethods);
for (int i = 0; i < count; i++) {
const btgatt_db_element_t& curr = db[i];
@@ -512,6 +518,7 @@ void fillGattDbElementArray(JNIEnv* env, jobject* array,
fid = env->GetFieldID(gattDbElementClazz.get(), "attributeHandle", "I");
env->SetIntField(element.get(), fid, curr.attribute_handle);
+ ScopedLocalRef uuidClazz(env, env->FindClass("java/util/UUID"));
ScopedLocalRef uuid(
env, env->NewObject(uuidClazz.get(), uuidConstructor,
uuid_msb(curr.uuid), uuid_lsb(curr.uuid)));
@@ -1232,121 +1239,6 @@ class JniDistanceMeasurementCallbacks : DistanceMeasurementCallbacks {
/**
* Native function definitions
*/
-static void classInitNative(JNIEnv* env, jclass clazz) {
- // Client callbacks
-
- method_onClientRegistered =
- env->GetMethodID(clazz, "onClientRegistered", "(IIJJ)V");
- method_onScannerRegistered =
- env->GetMethodID(clazz, "onScannerRegistered", "(IIJJ)V");
- method_onScanResult =
- env->GetMethodID(clazz, "onScanResult",
- "(IILjava/lang/String;IIIIII[BLjava/lang/String;)V");
- method_onConnected =
- env->GetMethodID(clazz, "onConnected", "(IIILjava/lang/String;)V");
- method_onDisconnected =
- env->GetMethodID(clazz, "onDisconnected", "(IIILjava/lang/String;)V");
- method_onReadCharacteristic =
- env->GetMethodID(clazz, "onReadCharacteristic", "(III[B)V");
- method_onWriteCharacteristic =
- env->GetMethodID(clazz, "onWriteCharacteristic", "(III[B)V");
- method_onExecuteCompleted =
- env->GetMethodID(clazz, "onExecuteCompleted", "(II)V");
- method_onSearchCompleted =
- env->GetMethodID(clazz, "onSearchCompleted", "(II)V");
- method_onReadDescriptor =
- env->GetMethodID(clazz, "onReadDescriptor", "(III[B)V");
- method_onWriteDescriptor =
- env->GetMethodID(clazz, "onWriteDescriptor", "(III[B)V");
- method_onNotify =
- env->GetMethodID(clazz, "onNotify", "(ILjava/lang/String;IZ[B)V");
- method_onRegisterForNotifications =
- env->GetMethodID(clazz, "onRegisterForNotifications", "(IIII)V");
- method_onReadRemoteRssi =
- env->GetMethodID(clazz, "onReadRemoteRssi", "(ILjava/lang/String;II)V");
- method_onConfigureMTU = env->GetMethodID(clazz, "onConfigureMTU", "(III)V");
- method_onScanFilterConfig =
- env->GetMethodID(clazz, "onScanFilterConfig", "(IIIII)V");
- method_onScanFilterParamsConfigured =
- env->GetMethodID(clazz, "onScanFilterParamsConfigured", "(IIII)V");
- method_onScanFilterEnableDisabled =
- env->GetMethodID(clazz, "onScanFilterEnableDisabled", "(III)V");
- method_onClientCongestion =
- env->GetMethodID(clazz, "onClientCongestion", "(IZ)V");
- method_onBatchScanStorageConfigured =
- env->GetMethodID(clazz, "onBatchScanStorageConfigured", "(II)V");
- method_onBatchScanStartStopped =
- env->GetMethodID(clazz, "onBatchScanStartStopped", "(III)V");
- method_onBatchScanReports =
- env->GetMethodID(clazz, "onBatchScanReports", "(IIII[B)V");
- method_onBatchScanThresholdCrossed =
- env->GetMethodID(clazz, "onBatchScanThresholdCrossed", "(I)V");
- method_createOnTrackAdvFoundLostObject =
- env->GetMethodID(clazz, "createOnTrackAdvFoundLostObject",
- "(II[BI[BIIILjava/lang/String;IIII)Lcom/android/"
- "bluetooth/gatt/AdvtFilterOnFoundOnLostInfo;");
- method_onTrackAdvFoundLost = env->GetMethodID(
- clazz, "onTrackAdvFoundLost",
- "(Lcom/android/bluetooth/gatt/AdvtFilterOnFoundOnLostInfo;)V");
- method_onScanParamSetupCompleted =
- env->GetMethodID(clazz, "onScanParamSetupCompleted", "(II)V");
- method_getSampleGattDbElement =
- env->GetMethodID(clazz, "getSampleGattDbElement",
- "()Lcom/android/bluetooth/gatt/GattDbElement;");
- method_onGetGattDb =
- env->GetMethodID(clazz, "onGetGattDb", "(ILjava/util/ArrayList;)V");
- method_onClientPhyRead =
- env->GetMethodID(clazz, "onClientPhyRead", "(ILjava/lang/String;III)V");
- method_onClientPhyUpdate =
- env->GetMethodID(clazz, "onClientPhyUpdate", "(IIII)V");
- method_onClientConnUpdate =
- env->GetMethodID(clazz, "onClientConnUpdate", "(IIIII)V");
- method_onServiceChanged =
- env->GetMethodID(clazz, "onServiceChanged", "(I)V");
- method_onClientSubrateChange =
- env->GetMethodID(clazz, "onClientSubrateChange", "(IIIIII)V");
-
- // Server callbacks
-
- method_onServerRegistered =
- env->GetMethodID(clazz, "onServerRegistered", "(IIJJ)V");
- method_onClientConnected =
- env->GetMethodID(clazz, "onClientConnected", "(Ljava/lang/String;ZII)V");
- method_onServiceAdded =
- env->GetMethodID(clazz, "onServiceAdded", "(IILjava/util/List;)V");
- method_onServiceStopped =
- env->GetMethodID(clazz, "onServiceStopped", "(III)V");
- method_onServiceDeleted =
- env->GetMethodID(clazz, "onServiceDeleted", "(III)V");
- method_onResponseSendCompleted =
- env->GetMethodID(clazz, "onResponseSendCompleted", "(II)V");
- method_onServerReadCharacteristic = env->GetMethodID(
- clazz, "onServerReadCharacteristic", "(Ljava/lang/String;IIIIZ)V");
- method_onServerReadDescriptor = env->GetMethodID(
- clazz, "onServerReadDescriptor", "(Ljava/lang/String;IIIIZ)V");
- method_onServerWriteCharacteristic = env->GetMethodID(
- clazz, "onServerWriteCharacteristic", "(Ljava/lang/String;IIIIIZZ[B)V");
- method_onServerWriteDescriptor = env->GetMethodID(
- clazz, "onServerWriteDescriptor", "(Ljava/lang/String;IIIIIZZ[B)V");
- method_onExecuteWrite =
- env->GetMethodID(clazz, "onExecuteWrite", "(Ljava/lang/String;III)V");
- method_onNotificationSent =
- env->GetMethodID(clazz, "onNotificationSent", "(II)V");
- method_onServerCongestion =
- env->GetMethodID(clazz, "onServerCongestion", "(IZ)V");
- method_onServerMtuChanged = env->GetMethodID(clazz, "onMtuChanged", "(II)V");
- method_onServerPhyRead =
- env->GetMethodID(clazz, "onServerPhyRead", "(ILjava/lang/String;III)V");
- method_onServerPhyUpdate =
- env->GetMethodID(clazz, "onServerPhyUpdate", "(IIII)V");
- method_onServerConnUpdate =
- env->GetMethodID(clazz, "onServerConnUpdate", "(IIIII)V");
- method_onServerSubrateChange =
- env->GetMethodID(clazz, "onServerSubrateChange", "(IIIIII)V");
-
- info("classInitNative: Success!");
-}
-
static const bt_interface_t* btIf;
static void initializeNative(JNIEnv* env, jobject object) {
@@ -1394,7 +1286,7 @@ static void initializeNative(JNIEnv* env, jobject object) {
mCallbacksObj = env->NewGlobalRef(object);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock lock(callbacks_mutex);
if (!btIf) return;
@@ -1415,13 +1307,13 @@ static void cleanupNative(JNIEnv* env, jobject object) {
* Native Client functions
*/
-static int gattClientGetDeviceTypeNative(JNIEnv* env, jobject object,
+static int gattClientGetDeviceTypeNative(JNIEnv* env, jobject /* object */,
jstring address) {
if (!sGattIf) return 0;
return sGattIf->client->get_device_type(str2addr(env, address));
}
-static void gattClientRegisterAppNative(JNIEnv* env, jobject object,
+static void gattClientRegisterAppNative(JNIEnv* /* env */, jobject /* object */,
jlong app_uuid_lsb, jlong app_uuid_msb,
jboolean eatt_support) {
if (!sGattIf) return;
@@ -1429,8 +1321,8 @@ static void gattClientRegisterAppNative(JNIEnv* env, jobject object,
sGattIf->client->register_client(uuid, eatt_support);
}
-static void gattClientUnregisterAppNative(JNIEnv* env, jobject object,
- jint clientIf) {
+static void gattClientUnregisterAppNative(JNIEnv* /* env */,
+ jobject /* object */, jint clientIf) {
if (!sGattIf) return;
sGattIf->client->unregister_client(clientIf);
}
@@ -1444,7 +1336,7 @@ void btgattc_register_scanner_cb(const Uuid& app_uuid, uint8_t scannerId,
status, scannerId, UUID_PARAMS(app_uuid));
}
-static void registerScannerNative(JNIEnv* env, jobject object,
+static void registerScannerNative(JNIEnv* /* env */, jobject /* object */,
jlong app_uuid_lsb, jlong app_uuid_msb) {
if (!sGattIf) return;
@@ -1453,22 +1345,23 @@ static void registerScannerNative(JNIEnv* env, jobject object,
uuid, base::Bind(&btgattc_register_scanner_cb, uuid));
}
-static void unregisterScannerNative(JNIEnv* env, jobject object,
+static void unregisterScannerNative(JNIEnv* /* env */, jobject /* object */,
jint scanner_id) {
if (!sGattIf) return;
sGattIf->scanner->Unregister(scanner_id);
}
-static void gattClientScanNative(JNIEnv* env, jobject object, jboolean start) {
+static void gattClientScanNative(JNIEnv* /* env */, jobject /* object */,
+ jboolean start) {
if (!sGattIf) return;
sGattIf->scanner->Scan(start);
}
-static void gattClientConnectNative(JNIEnv* env, jobject object, jint clientif,
- jstring address, jint addressType,
- jboolean isDirect, jint transport,
- jboolean opportunistic,
+static void gattClientConnectNative(JNIEnv* env, jobject /* object */,
+ jint clientif, jstring address,
+ jint addressType, jboolean isDirect,
+ jint transport, jboolean opportunistic,
jint initiating_phys) {
if (!sGattIf) return;
@@ -1476,17 +1369,17 @@ static void gattClientConnectNative(JNIEnv* env, jobject object, jint clientif,
isDirect, transport, opportunistic, initiating_phys);
}
-static void gattClientDisconnectNative(JNIEnv* env, jobject object,
+static void gattClientDisconnectNative(JNIEnv* env, jobject /* object */,
jint clientIf, jstring address,
jint conn_id) {
if (!sGattIf) return;
sGattIf->client->disconnect(clientIf, str2addr(env, address), conn_id);
}
-static void gattClientSetPreferredPhyNative(JNIEnv* env, jobject object,
- jint clientIf, jstring address,
- jint tx_phy, jint rx_phy,
- jint phy_options) {
+static void gattClientSetPreferredPhyNative(JNIEnv* env, jobject /* object */,
+ jint /* clientIf */,
+ jstring address, jint tx_phy,
+ jint rx_phy, jint phy_options) {
if (!sGattIf) return;
sGattIf->client->set_preferred_phy(str2addr(env, address), tx_phy, rx_phy,
phy_options);
@@ -1505,23 +1398,24 @@ static void readClientPhyCb(uint8_t clientIf, RawAddress bda, uint8_t tx_phy,
address.get(), tx_phy, rx_phy, status);
}
-static void gattClientReadPhyNative(JNIEnv* env, jobject object, jint clientIf,
- jstring address) {
+static void gattClientReadPhyNative(JNIEnv* env, jobject /* object */,
+ jint clientIf, jstring address) {
if (!sGattIf) return;
RawAddress bda = str2addr(env, address);
sGattIf->client->read_phy(bda, base::Bind(&readClientPhyCb, clientIf, bda));
}
-static void gattClientRefreshNative(JNIEnv* env, jobject object, jint clientIf,
- jstring address) {
+static void gattClientRefreshNative(JNIEnv* env, jobject /* object */,
+ jint clientIf, jstring address) {
if (!sGattIf) return;
sGattIf->client->refresh(clientIf, str2addr(env, address));
}
-static void gattClientSearchServiceNative(JNIEnv* env, jobject object,
- jint conn_id, jboolean search_all,
+static void gattClientSearchServiceNative(JNIEnv* /* env */,
+ jobject /* object */, jint conn_id,
+ jboolean search_all,
jlong service_uuid_lsb,
jlong service_uuid_msb) {
if (!sGattIf) return;
@@ -1530,7 +1424,8 @@ static void gattClientSearchServiceNative(JNIEnv* env, jobject object,
sGattIf->client->search_service(conn_id, search_all ? 0 : &uuid);
}
-static void gattClientDiscoverServiceByUuidNative(JNIEnv* env, jobject object,
+static void gattClientDiscoverServiceByUuidNative(JNIEnv* /* env */,
+ jobject /* object */,
jint conn_id,
jlong service_uuid_lsb,
jlong service_uuid_msb) {
@@ -1540,14 +1435,15 @@ static void gattClientDiscoverServiceByUuidNative(JNIEnv* env, jobject object,
sGattIf->client->btif_gattc_discover_service_by_uuid(conn_id, uuid);
}
-static void gattClientGetGattDbNative(JNIEnv* env, jobject object,
+static void gattClientGetGattDbNative(JNIEnv* /* env */, jobject /* object */,
jint conn_id) {
if (!sGattIf) return;
sGattIf->client->get_gatt_db(conn_id);
}
-static void gattClientReadCharacteristicNative(JNIEnv* env, jobject object,
+static void gattClientReadCharacteristicNative(JNIEnv* /* env */,
+ jobject /* object */,
jint conn_id, jint handle,
jint authReq) {
if (!sGattIf) return;
@@ -1556,8 +1452,8 @@ static void gattClientReadCharacteristicNative(JNIEnv* env, jobject object,
}
static void gattClientReadUsingCharacteristicUuidNative(
- JNIEnv* env, jobject object, jint conn_id, jlong uuid_lsb, jlong uuid_msb,
- jint s_handle, jint e_handle, jint authReq) {
+ JNIEnv* /* env */, jobject /* object */, jint conn_id, jlong uuid_lsb,
+ jlong uuid_msb, jint s_handle, jint e_handle, jint authReq) {
if (!sGattIf) return;
Uuid uuid = from_java_uuid(uuid_msb, uuid_lsb);
@@ -1565,15 +1461,16 @@ static void gattClientReadUsingCharacteristicUuidNative(
e_handle, authReq);
}
-static void gattClientReadDescriptorNative(JNIEnv* env, jobject object,
- jint conn_id, jint handle,
- jint authReq) {
+static void gattClientReadDescriptorNative(JNIEnv* /* env */,
+ jobject /* object */, jint conn_id,
+ jint handle, jint authReq) {
if (!sGattIf) return;
sGattIf->client->read_descriptor(conn_id, handle, authReq);
}
-static void gattClientWriteCharacteristicNative(JNIEnv* env, jobject object,
+static void gattClientWriteCharacteristicNative(JNIEnv* env,
+ jobject /* object */,
jint conn_id, jint handle,
jint write_type, jint auth_req,
jbyteArray value) {
@@ -1595,13 +1492,14 @@ static void gattClientWriteCharacteristicNative(JNIEnv* env, jobject object,
env->ReleaseByteArrayElements(value, p_value, 0);
}
-static void gattClientExecuteWriteNative(JNIEnv* env, jobject object,
- jint conn_id, jboolean execute) {
+static void gattClientExecuteWriteNative(JNIEnv* /* env */,
+ jobject /* object */, jint conn_id,
+ jboolean execute) {
if (!sGattIf) return;
sGattIf->client->execute_write(conn_id, execute ? 1 : 0);
}
-static void gattClientWriteDescriptorNative(JNIEnv* env, jobject object,
+static void gattClientWriteDescriptorNative(JNIEnv* env, jobject /* object */,
jint conn_id, jint handle,
jint auth_req, jbyteArray value) {
if (!sGattIf) return;
@@ -1622,8 +1520,8 @@ static void gattClientWriteDescriptorNative(JNIEnv* env, jobject object,
}
static void gattClientRegisterForNotificationsNative(
- JNIEnv* env, jobject object, jint clientIf, jstring address, jint handle,
- jboolean enable) {
+ JNIEnv* env, jobject /* object */, jint clientIf, jstring address,
+ jint handle, jboolean enable) {
if (!sGattIf) return;
RawAddress bd_addr = str2addr(env, address);
@@ -1633,7 +1531,7 @@ static void gattClientRegisterForNotificationsNative(
sGattIf->client->deregister_for_notification(clientIf, bd_addr, handle);
}
-static void gattClientReadRemoteRssiNative(JNIEnv* env, jobject object,
+static void gattClientReadRemoteRssiNative(JNIEnv* env, jobject /* object */,
jint clientif, jstring address) {
if (!sGattIf) return;
@@ -1648,7 +1546,7 @@ void set_scan_params_cmpl_cb(int client_if, uint8_t status) {
status, client_if);
}
-static void gattSetScanParametersNative(JNIEnv* env, jobject object,
+static void gattSetScanParametersNative(JNIEnv* /* env */, jobject /* object */,
jint client_if, jint scan_interval_unit,
jint scan_window_unit) {
if (!sGattIf) return;
@@ -1667,7 +1565,8 @@ void scan_filter_param_cb(uint8_t client_if, uint8_t avbl_space, uint8_t action,
status, client_if, avbl_space);
}
-static void gattClientScanFilterParamAddNative(JNIEnv* env, jobject object,
+static void gattClientScanFilterParamAddNative(JNIEnv* env,
+ jobject /* object */,
jobject params) {
if (!sGattIf) return;
const int add_scan_filter_params_action = 0;
@@ -1717,7 +1616,8 @@ static void gattClientScanFilterParamAddNative(JNIEnv* env, jobject object,
std::move(filt_params), base::Bind(&scan_filter_param_cb, client_if));
}
-static void gattClientScanFilterParamDeleteNative(JNIEnv* env, jobject object,
+static void gattClientScanFilterParamDeleteNative(JNIEnv* /* env */,
+ jobject /* object */,
jint client_if,
jint filt_index) {
if (!sGattIf) return;
@@ -1727,7 +1627,8 @@ static void gattClientScanFilterParamDeleteNative(JNIEnv* env, jobject object,
base::Bind(&scan_filter_param_cb, client_if));
}
-static void gattClientScanFilterParamClearAllNative(JNIEnv* env, jobject object,
+static void gattClientScanFilterParamClearAllNative(JNIEnv* /* env */,
+ jobject /* object */,
jint client_if) {
if (!sGattIf) return;
const int clear_scan_filter_params_action = 2;
@@ -1746,16 +1647,19 @@ static void scan_filter_cfg_cb(uint8_t client_if, uint8_t filt_type,
status, client_if, filt_type, avbl_space);
}
-static void gattClientScanFilterAddNative(JNIEnv* env, jobject object,
+static void gattClientScanFilterAddNative(JNIEnv* env, jobject /* object */,
jint client_if, jobjectArray filters,
jint filter_index) {
if (!sGattIf) return;
- jclass uuidClazz = env->FindClass("java/util/UUID");
- jmethodID uuidGetMsb =
- env->GetMethodID(uuidClazz, "getMostSignificantBits", "()J");
- jmethodID uuidGetLsb =
- env->GetMethodID(uuidClazz, "getLeastSignificantBits", "()J");
+ jmethodID uuidGetMsb;
+ jmethodID uuidGetLsb;
+
+ const JNIJavaMethod javaMethods[] = {
+ {"getMostSignificantBits", "()J", &uuidGetMsb},
+ {"getLeastSignificantBits", "()J", &uuidGetLsb},
+ };
+ GET_JAVA_METHODS(env, "java/util/UUID", javaMethods);
std::vector native_filters;
@@ -1904,7 +1808,8 @@ static void gattClientScanFilterAddNative(JNIEnv* env, jobject object,
base::Bind(&scan_filter_cfg_cb, client_if));
}
-static void gattClientScanFilterClearNative(JNIEnv* env, jobject object,
+static void gattClientScanFilterClearNative(JNIEnv* /* env */,
+ jobject /* object */,
jint client_if, jint filt_index) {
if (!sGattIf) return;
sGattIf->scanner->ScanFilterClear(filt_index,
@@ -1919,33 +1824,33 @@ void scan_enable_cb(uint8_t client_if, uint8_t action, uint8_t status) {
action, status, client_if);
}
-static void gattClientScanFilterEnableNative(JNIEnv* env, jobject object,
+static void gattClientScanFilterEnableNative(JNIEnv* /* env */,
+ jobject /* object */,
jint client_if, jboolean enable) {
if (!sGattIf) return;
sGattIf->scanner->ScanFilterEnable(enable,
base::Bind(&scan_enable_cb, client_if));
}
-static void gattClientConfigureMTUNative(JNIEnv* env, jobject object,
- jint conn_id, jint mtu) {
+static void gattClientConfigureMTUNative(JNIEnv* /* env */,
+ jobject /* object */, jint conn_id,
+ jint mtu) {
if (!sGattIf) return;
sGattIf->client->configure_mtu(conn_id, mtu);
}
-static void gattConnectionParameterUpdateNative(JNIEnv* env, jobject object,
- jint client_if, jstring address,
- jint min_interval,
- jint max_interval, jint latency,
- jint timeout, jint min_ce_len,
- jint max_ce_len) {
+static void gattConnectionParameterUpdateNative(
+ JNIEnv* env, jobject /* object */, jint /* client_if */, jstring address,
+ jint min_interval, jint max_interval, jint latency, jint timeout,
+ jint min_ce_len, jint max_ce_len) {
if (!sGattIf) return;
sGattIf->client->conn_parameter_update(
str2addr(env, address), min_interval, max_interval, latency, timeout,
(uint16_t)min_ce_len, (uint16_t)max_ce_len);
}
-static void gattSubrateRequestNative(JNIEnv* env, jobject object,
- jint client_if, jstring address,
+static void gattSubrateRequestNative(JNIEnv* env, jobject /* object */,
+ jint /* client_if */, jstring address,
jint subrate_min, jint subrate_max,
jint max_latency, jint cont_num,
jint sup_timeout) {
@@ -1964,8 +1869,9 @@ void batchscan_cfg_storage_cb(uint8_t client_if, uint8_t status) {
}
static void gattClientConfigBatchScanStorageNative(
- JNIEnv* env, jobject object, jint client_if, jint max_full_reports_percent,
- jint max_trunc_reports_percent, jint notify_threshold_level_percent) {
+ JNIEnv* /* env */, jobject /* object */, jint client_if,
+ jint max_full_reports_percent, jint max_trunc_reports_percent,
+ jint notify_threshold_level_percent) {
if (!sGattIf) return;
sGattIf->scanner->BatchscanConfigStorage(
client_if, max_full_reports_percent, max_trunc_reports_percent,
@@ -1981,8 +1887,9 @@ void batchscan_enable_cb(uint8_t client_if, uint8_t status) {
0 /* unused */, status, client_if);
}
-static void gattClientStartBatchScanNative(JNIEnv* env, jobject object,
- jint client_if, jint scan_mode,
+static void gattClientStartBatchScanNative(JNIEnv* /* env */,
+ jobject /* object */, jint client_if,
+ jint scan_mode,
jint scan_interval_unit,
jint scan_window_unit,
jint addr_type, jint discard_rule) {
@@ -1992,14 +1899,16 @@ static void gattClientStartBatchScanNative(JNIEnv* env, jobject object,
base::Bind(&batchscan_enable_cb, client_if));
}
-static void gattClientStopBatchScanNative(JNIEnv* env, jobject object,
+static void gattClientStopBatchScanNative(JNIEnv* /* env */,
+ jobject /* object */,
jint client_if) {
if (!sGattIf) return;
sGattIf->scanner->BatchscanDisable(
base::Bind(&batchscan_enable_cb, client_if));
}
-static void gattClientReadScanReportsNative(JNIEnv* env, jobject object,
+static void gattClientReadScanReportsNative(JNIEnv* /* env */,
+ jobject /* object */,
jint client_if, jint scan_type) {
if (!sGattIf) return;
sGattIf->scanner->BatchscanReadReports(client_if, scan_type);
@@ -2008,7 +1917,7 @@ static void gattClientReadScanReportsNative(JNIEnv* env, jobject object,
/**
* Native server functions
*/
-static void gattServerRegisterAppNative(JNIEnv* env, jobject object,
+static void gattServerRegisterAppNative(JNIEnv* /* env */, jobject /* object */,
jlong app_uuid_lsb, jlong app_uuid_msb,
jboolean eatt_support) {
if (!sGattIf) return;
@@ -2016,33 +1925,33 @@ static void gattServerRegisterAppNative(JNIEnv* env, jobject object,
sGattIf->server->register_server(uuid, eatt_support);
}
-static void gattServerUnregisterAppNative(JNIEnv* env, jobject object,
- jint serverIf) {
+static void gattServerUnregisterAppNative(JNIEnv* /* env */,
+ jobject /* object */, jint serverIf) {
if (!sGattIf) return;
bluetooth::gatt::close_server(serverIf);
sGattIf->server->unregister_server(serverIf);
}
-static void gattServerConnectNative(JNIEnv* env, jobject object, jint server_if,
- jstring address, jboolean is_direct,
- jint transport) {
+static void gattServerConnectNative(JNIEnv* env, jobject /* object */,
+ jint server_if, jstring address,
+ jboolean is_direct, jint transport) {
if (!sGattIf) return;
RawAddress bd_addr = str2addr(env, address);
sGattIf->server->connect(server_if, bd_addr, is_direct, transport);
}
-static void gattServerDisconnectNative(JNIEnv* env, jobject object,
+static void gattServerDisconnectNative(JNIEnv* env, jobject /* object */,
jint serverIf, jstring address,
jint conn_id) {
if (!sGattIf) return;
sGattIf->server->disconnect(serverIf, str2addr(env, address), conn_id);
}
-static void gattServerSetPreferredPhyNative(JNIEnv* env, jobject object,
- jint serverIf, jstring address,
- jint tx_phy, jint rx_phy,
- jint phy_options) {
+static void gattServerSetPreferredPhyNative(JNIEnv* env, jobject /* object */,
+ jint /* serverIf */,
+ jstring address, jint tx_phy,
+ jint rx_phy, jint phy_options) {
if (!sGattIf) return;
RawAddress bda = str2addr(env, address);
sGattIf->server->set_preferred_phy(bda, tx_phy, rx_phy, phy_options);
@@ -2061,32 +1970,39 @@ static void readServerPhyCb(uint8_t serverIf, RawAddress bda, uint8_t tx_phy,
address.get(), tx_phy, rx_phy, status);
}
-static void gattServerReadPhyNative(JNIEnv* env, jobject object, jint serverIf,
- jstring address) {
+static void gattServerReadPhyNative(JNIEnv* env, jobject /* object */,
+ jint serverIf, jstring address) {
if (!sGattIf) return;
RawAddress bda = str2addr(env, address);
sGattIf->server->read_phy(bda, base::Bind(&readServerPhyCb, serverIf, bda));
}
-static void gattServerAddServiceNative(JNIEnv* env, jobject object,
+static void gattServerAddServiceNative(JNIEnv* env, jobject /* object */,
jint server_if,
jobject gatt_db_elements) {
if (!sGattIf) return;
- jclass arrayListclazz = env->FindClass("java/util/List");
- jmethodID arrayGet =
- env->GetMethodID(arrayListclazz, "get", "(I)Ljava/lang/Object;");
- jmethodID arraySize = env->GetMethodID(arrayListclazz, "size", "()I");
+ jmethodID arrayGet;
+ jmethodID arraySize;
+
+ const JNIJavaMethod javaListMethods[] = {
+ {"get", "(I)Ljava/lang/Object;", &arrayGet},
+ {"size", "()I", &arraySize},
+ };
+ GET_JAVA_METHODS(env, "java/util/List", javaListMethods);
int count = env->CallIntMethod(gatt_db_elements, arraySize);
std::vector db;
- jclass uuidClazz = env->FindClass("java/util/UUID");
- jmethodID uuidGetMsb =
- env->GetMethodID(uuidClazz, "getMostSignificantBits", "()J");
- jmethodID uuidGetLsb =
- env->GetMethodID(uuidClazz, "getLeastSignificantBits", "()J");
+ jmethodID uuidGetMsb;
+ jmethodID uuidGetLsb;
+
+ const JNIJavaMethod javaUuidMethods[] = {
+ {"getMostSignificantBits", "()J", &uuidGetMsb},
+ {"getLeastSignificantBits", "()J", &uuidGetLsb},
+ };
+ GET_JAVA_METHODS(env, "java/util/UUID", javaUuidMethods);
jobject objectForClass =
env->CallObjectMethod(mCallbacksObj, method_getSampleGattDbElement);
@@ -2137,19 +2053,20 @@ static void gattServerAddServiceNative(JNIEnv* env, jobject object,
sGattIf->server->add_service(server_if, db.data(), db.size());
}
-static void gattServerStopServiceNative(JNIEnv* env, jobject object,
+static void gattServerStopServiceNative(JNIEnv* /* env */, jobject /* object */,
jint server_if, jint svc_handle) {
if (!sGattIf) return;
sGattIf->server->stop_service(server_if, svc_handle);
}
-static void gattServerDeleteServiceNative(JNIEnv* env, jobject object,
- jint server_if, jint svc_handle) {
+static void gattServerDeleteServiceNative(JNIEnv* /* env */,
+ jobject /* object */, jint server_if,
+ jint svc_handle) {
if (!sGattIf) return;
sGattIf->server->delete_service(server_if, svc_handle);
}
-static void gattServerSendIndicationNative(JNIEnv* env, jobject object,
+static void gattServerSendIndicationNative(JNIEnv* env, jobject /* object */,
jint server_if, jint attr_handle,
jint conn_id, jbyteArray val) {
if (!sGattIf) return;
@@ -2168,7 +2085,7 @@ static void gattServerSendIndicationNative(JNIEnv* env, jobject object,
env->ReleaseByteArrayElements(val, array, JNI_ABORT);
}
-static void gattServerSendNotificationNative(JNIEnv* env, jobject object,
+static void gattServerSendNotificationNative(JNIEnv* env, jobject /* object */,
jint server_if, jint attr_handle,
jint conn_id, jbyteArray val) {
if (!sGattIf) return;
@@ -2182,7 +2099,7 @@ static void gattServerSendNotificationNative(JNIEnv* env, jobject object,
env->ReleaseByteArrayElements(val, array, JNI_ABORT);
}
-static void gattServerSendResponseNative(JNIEnv* env, jobject object,
+static void gattServerSendResponseNative(JNIEnv* env, jobject /* object */,
jint server_if, jint conn_id,
jint trans_id, jint status,
jint handle, jint offset,
@@ -2197,10 +2114,10 @@ static void gattServerSendResponseNative(JNIEnv* env, jobject object,
response.attr_value.len = 0;
if (val != NULL) {
- if (env->GetArrayLength(val) < BTGATT_MAX_ATTR_LEN) {
+ if (env->GetArrayLength(val) < GATT_MAX_ATTR_LEN) {
response.attr_value.len = (uint16_t)env->GetArrayLength(val);
} else {
- response.attr_value.len = BTGATT_MAX_ATTR_LEN;
+ response.attr_value.len = GATT_MAX_ATTR_LEN;
}
jbyte* array = env->GetByteArrayElements(val, 0);
@@ -2219,27 +2136,6 @@ static void gattServerSendResponseNative(JNIEnv* env, jobject object,
}
}
-static void advertiseClassInitNative(JNIEnv* env, jclass clazz) {
- method_onAdvertisingSetStarted =
- env->GetMethodID(clazz, "onAdvertisingSetStarted", "(IIII)V");
- method_onOwnAddressRead =
- env->GetMethodID(clazz, "onOwnAddressRead", "(IILjava/lang/String;)V");
- method_onAdvertisingEnabled =
- env->GetMethodID(clazz, "onAdvertisingEnabled", "(IZI)V");
- method_onAdvertisingDataSet =
- env->GetMethodID(clazz, "onAdvertisingDataSet", "(II)V");
- method_onScanResponseDataSet =
- env->GetMethodID(clazz, "onScanResponseDataSet", "(II)V");
- method_onAdvertisingParametersUpdated =
- env->GetMethodID(clazz, "onAdvertisingParametersUpdated", "(III)V");
- method_onPeriodicAdvertisingParametersUpdated = env->GetMethodID(
- clazz, "onPeriodicAdvertisingParametersUpdated", "(II)V");
- method_onPeriodicAdvertisingDataSet =
- env->GetMethodID(clazz, "onPeriodicAdvertisingDataSet", "(II)V");
- method_onPeriodicAdvertisingEnabled =
- env->GetMethodID(clazz, "onPeriodicAdvertisingEnabled", "(IZI)V");
-}
-
static void advertiseInitializeNative(JNIEnv* env, jobject object) {
std::unique_lock lock(callbacks_mutex);
if (mAdvertiseCallbacksObj != NULL) {
@@ -2251,7 +2147,7 @@ static void advertiseInitializeNative(JNIEnv* env, jobject object) {
mAdvertiseCallbacksObj = env->NewGlobalRef(object);
}
-static void advertiseCleanupNative(JNIEnv* env, jobject object) {
+static void advertiseCleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock lock(callbacks_mutex);
if (mAdvertiseCallbacksObj != NULL) {
env->DeleteGlobalRef(mAdvertiseCallbacksObj);
@@ -2373,7 +2269,7 @@ static void ble_advertising_set_timeout_cb(uint8_t advertiser_id,
}
static void startAdvertisingSetNative(
- JNIEnv* env, jobject object, jobject parameters, jbyteArray adv_data,
+ JNIEnv* env, jobject /* object */, jobject parameters, jbyteArray adv_data,
jbyteArray scan_resp, jobject periodic_parameters, jbyteArray periodic_data,
jint duration, jint maxExtAdvEvents, jint reg_id, jint server_if) {
if (!sGattIf) return;
@@ -2400,12 +2296,13 @@ static void startAdvertisingSetNative(
env->ReleaseByteArrayElements(periodic_data, periodic_data_data, JNI_ABORT);
sGattIf->advertiser->StartAdvertisingSet(
- reg_id, base::Bind(&ble_advertising_set_started_cb, reg_id, server_if),
- params, data_vec, scan_resp_vec, periodicParams, periodic_data_vec,
- duration, maxExtAdvEvents, base::Bind(ble_advertising_set_timeout_cb));
+ kAdvertiserClientIdJni, reg_id,
+ base::Bind(&ble_advertising_set_started_cb, reg_id, server_if), params,
+ data_vec, scan_resp_vec, periodicParams, periodic_data_vec, duration,
+ maxExtAdvEvents, base::Bind(ble_advertising_set_timeout_cb));
}
-static void stopAdvertisingSetNative(JNIEnv* env, jobject object,
+static void stopAdvertisingSetNative(JNIEnv* /* env */, jobject /* object */,
jint advertiser_id) {
if (!sGattIf) return;
@@ -2426,7 +2323,7 @@ static void getOwnAddressCb(uint8_t advertiser_id, uint8_t address_type,
advertiser_id, address_type, addr.get());
}
-static void getOwnAddressNative(JNIEnv* env, jobject object,
+static void getOwnAddressNative(JNIEnv* /* env */, jobject /* object */,
jint advertiser_id) {
if (!sGattIf) return;
sGattIf->advertiser->GetOwnAddress(
@@ -2451,7 +2348,7 @@ static void enableSetCb(uint8_t advertiser_id, bool enable, uint8_t status) {
enable, status);
}
-static void enableAdvertisingSetNative(JNIEnv* env, jobject object,
+static void enableAdvertisingSetNative(JNIEnv* /* env */, jobject /* object */,
jint advertiser_id, jboolean enable,
jint duration, jint maxExtAdvEvents) {
if (!sGattIf) return;
@@ -2462,7 +2359,7 @@ static void enableAdvertisingSetNative(JNIEnv* env, jobject object,
base::Bind(&enableSetCb, advertiser_id, false));
}
-static void setAdvertisingDataNative(JNIEnv* env, jobject object,
+static void setAdvertisingDataNative(JNIEnv* env, jobject /* object */,
jint advertiser_id, jbyteArray data) {
if (!sGattIf) return;
@@ -2471,7 +2368,7 @@ static void setAdvertisingDataNative(JNIEnv* env, jobject object,
base::Bind(&callJniCallback, method_onAdvertisingDataSet, advertiser_id));
}
-static void setScanResponseDataNative(JNIEnv* env, jobject object,
+static void setScanResponseDataNative(JNIEnv* env, jobject /* object */,
jint advertiser_id, jbyteArray data) {
if (!sGattIf) return;
@@ -2491,7 +2388,7 @@ static void setAdvertisingParametersNativeCb(uint8_t advertiser_id,
advertiser_id, tx_power, status);
}
-static void setAdvertisingParametersNative(JNIEnv* env, jobject object,
+static void setAdvertisingParametersNative(JNIEnv* env, jobject /* object */,
jint advertiser_id,
jobject parameters) {
if (!sGattIf) return;
@@ -2503,7 +2400,7 @@ static void setAdvertisingParametersNative(JNIEnv* env, jobject object,
}
static void setPeriodicAdvertisingParametersNative(
- JNIEnv* env, jobject object, jint advertiser_id,
+ JNIEnv* env, jobject /* object */, jint advertiser_id,
jobject periodic_parameters) {
if (!sGattIf) return;
@@ -2515,7 +2412,7 @@ static void setPeriodicAdvertisingParametersNative(
method_onPeriodicAdvertisingParametersUpdated, advertiser_id));
}
-static void setPeriodicAdvertisingDataNative(JNIEnv* env, jobject object,
+static void setPeriodicAdvertisingDataNative(JNIEnv* env, jobject /* object */,
jint advertiser_id,
jbyteArray data) {
if (!sGattIf) return;
@@ -2536,7 +2433,8 @@ static void enablePeriodicSetCb(uint8_t advertiser_id, bool enable,
advertiser_id, enable, status);
}
-static void setPeriodicAdvertisingEnableNative(JNIEnv* env, jobject object,
+static void setPeriodicAdvertisingEnableNative(JNIEnv* /* env */,
+ jobject /* object */,
jint advertiser_id,
jboolean enable) {
if (!sGattIf) return;
@@ -2548,16 +2446,6 @@ static void setPeriodicAdvertisingEnableNative(JNIEnv* env, jobject object,
base::Bind(&enablePeriodicSetCb, advertiser_id, enable));
}
-static void periodicScanClassInitNative(JNIEnv* env, jclass clazz) {
- method_onSyncStarted =
- env->GetMethodID(clazz, "onSyncStarted", "(IIIILjava/lang/String;III)V");
- method_onSyncReport = env->GetMethodID(clazz, "onSyncReport", "(IIII[B)V");
- method_onSyncLost = env->GetMethodID(clazz, "onSyncLost", "(I)V");
- method_onSyncTransferredCallback = env->GetMethodID(
- clazz, "onSyncTransferredCallback", "(IILjava/lang/String;)V");
- method_onBigInfoReport = env->GetMethodID(clazz, "onBigInfoReport", "(IZ)V");
-}
-
static void periodicScanInitializeNative(JNIEnv* env, jobject object) {
std::unique_lock lock(callbacks_mutex);
if (mPeriodicScanCallbacksObj != NULL) {
@@ -2569,7 +2457,7 @@ static void periodicScanInitializeNative(JNIEnv* env, jobject object) {
mPeriodicScanCallbacksObj = env->NewGlobalRef(object);
}
-static void periodicScanCleanupNative(JNIEnv* env, jobject object) {
+static void periodicScanCleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock lock(callbacks_mutex);
if (mPeriodicScanCallbacksObj != NULL) {
env->DeleteGlobalRef(mPeriodicScanCallbacksObj);
@@ -2577,7 +2465,7 @@ static void periodicScanCleanupNative(JNIEnv* env, jobject object) {
}
}
-static void startSyncNative(JNIEnv* env, jobject object, jint sid,
+static void startSyncNative(JNIEnv* env, jobject /* object */, jint sid,
jstring address, jint skip, jint timeout,
jint reg_id) {
if (!sGattIf) return;
@@ -2585,34 +2473,35 @@ static void startSyncNative(JNIEnv* env, jobject object, jint sid,
reg_id);
}
-static void stopSyncNative(JNIEnv* env, jobject object, jint sync_handle) {
+static void stopSyncNative(JNIEnv* /* env */, jobject /* object */,
+ jint sync_handle) {
if (!sGattIf) return;
sGattIf->scanner->StopSync(sync_handle);
}
-static void cancelSyncNative(JNIEnv* env, jobject object, jint sid,
+static void cancelSyncNative(JNIEnv* env, jobject /* object */, jint sid,
jstring address) {
if (!sGattIf) return;
sGattIf->scanner->CancelCreateSync(sid, str2addr(env, address));
}
-static void syncTransferNative(JNIEnv* env, jobject object, jint pa_source,
- jstring addr, jint service_data,
+static void syncTransferNative(JNIEnv* env, jobject /* object */,
+ jint pa_source, jstring addr, jint service_data,
jint sync_handle) {
if (!sGattIf) return;
sGattIf->scanner->TransferSync(str2addr(env, addr), service_data, sync_handle,
pa_source);
}
-static void transferSetInfoNative(JNIEnv* env, jobject object, jint pa_source,
- jstring addr, jint service_data,
- jint adv_handle) {
+static void transferSetInfoNative(JNIEnv* env, jobject /* object */,
+ jint pa_source, jstring addr,
+ jint service_data, jint adv_handle) {
if (!sGattIf) return;
sGattIf->scanner->TransferSetInfo(str2addr(env, addr), service_data,
adv_handle, pa_source);
}
-static void gattTestNative(JNIEnv* env, jobject object, jint command,
+static void gattTestNative(JNIEnv* env, jobject /* object */, jint command,
jlong uuid1_lsb, jlong uuid1_msb, jstring bda1,
jint p1, jint p2, jint p3, jint p4, jint p5) {
if (!sGattIf) return;
@@ -2632,17 +2521,6 @@ static void gattTestNative(JNIEnv* env, jobject object, jint command,
sGattIf->client->test_command(command, params);
}
-static void distanceMeasurementClassInitNative(JNIEnv* env, jclass clazz) {
- method_onDistanceMeasurementStarted = env->GetMethodID(
- clazz, "onDistanceMeasurementStarted", "(Ljava/lang/String;I)V");
- method_onDistanceMeasurementStartFail = env->GetMethodID(
- clazz, "onDistanceMeasurementStartFail", "(Ljava/lang/String;II)V");
- method_onDistanceMeasurementStopped = env->GetMethodID(
- clazz, "onDistanceMeasurementStopped", "(Ljava/lang/String;II)V");
- method_onDistanceMeasurementResult = env->GetMethodID(
- clazz, "onDistanceMeasurementResult", "(Ljava/lang/String;IIIIIII)V");
-}
-
static void distanceMeasurementInitializeNative(JNIEnv* env, jobject object) {
std::unique_lock lock(callbacks_mutex);
if (mDistanceMeasurementCallbacksObj != NULL) {
@@ -2654,7 +2532,8 @@ static void distanceMeasurementInitializeNative(JNIEnv* env, jobject object) {
mDistanceMeasurementCallbacksObj = env->NewGlobalRef(object);
}
-static void distanceMeasurementCleanupNative(JNIEnv* env, jobject object) {
+static void distanceMeasurementCleanupNative(JNIEnv* env,
+ jobject /* object */) {
std::unique_lock lock(callbacks_mutex);
if (mDistanceMeasurementCallbacksObj != NULL) {
env->DeleteGlobalRef(mDistanceMeasurementCallbacksObj);
@@ -2662,7 +2541,7 @@ static void distanceMeasurementCleanupNative(JNIEnv* env, jobject object) {
}
}
-static void startDistanceMeasurementNative(JNIEnv* env, jobject object,
+static void startDistanceMeasurementNative(JNIEnv* env, jobject /* object */,
jstring address, jint frequency,
jint method) {
if (!sGattIf) return;
@@ -2670,7 +2549,7 @@ static void startDistanceMeasurementNative(JNIEnv* env, jobject object,
str2addr(env, address), frequency, method);
}
-static void stopDistanceMeasurementNative(JNIEnv* env, jobject object,
+static void stopDistanceMeasurementNative(JNIEnv* env, jobject /* object */,
jstring address, jint method) {
if (!sGattIf) return;
sGattIf->distance_measurement_manager->StopDistanceMeasurement(
@@ -2681,183 +2560,345 @@ static void stopDistanceMeasurementNative(JNIEnv* env, jobject object,
* JNI function definitinos
*/
-// JNI functions defined in AdvertiseManager class.
-static JNINativeMethod sAdvertiseMethods[] = {
- {"classInitNative", "()V", (void*)advertiseClassInitNative},
- {"initializeNative", "()V", (void*)advertiseInitializeNative},
- {"cleanupNative", "()V", (void*)advertiseCleanupNative},
- {"startAdvertisingSetNative",
- "(Landroid/bluetooth/le/AdvertisingSetParameters;[B[BLandroid/bluetooth/"
- "le/PeriodicAdvertisingParameters;[BIIII)V",
- (void*)startAdvertisingSetNative},
- {"getOwnAddressNative", "(I)V", (void*)getOwnAddressNative},
- {"stopAdvertisingSetNative", "(I)V", (void*)stopAdvertisingSetNative},
- {"enableAdvertisingSetNative", "(IZII)V",
- (void*)enableAdvertisingSetNative},
- {"setAdvertisingDataNative", "(I[B)V", (void*)setAdvertisingDataNative},
- {"setScanResponseDataNative", "(I[B)V", (void*)setScanResponseDataNative},
- {"setAdvertisingParametersNative",
- "(ILandroid/bluetooth/le/AdvertisingSetParameters;)V",
- (void*)setAdvertisingParametersNative},
- {"setPeriodicAdvertisingParametersNative",
- "(ILandroid/bluetooth/le/PeriodicAdvertisingParameters;)V",
- (void*)setPeriodicAdvertisingParametersNative},
- {"setPeriodicAdvertisingDataNative", "(I[B)V",
- (void*)setPeriodicAdvertisingDataNative},
- {"setPeriodicAdvertisingEnableNative", "(IZ)V",
- (void*)setPeriodicAdvertisingEnableNative},
-};
+// JNI functions defined in AdvertiseManagerNativeInterface class.
// JNI functions defined in PeriodicScanManager class.
-static JNINativeMethod sPeriodicScanMethods[] = {
- {"classInitNative", "()V", (void*)periodicScanClassInitNative},
- {"initializeNative", "()V", (void*)periodicScanInitializeNative},
- {"cleanupNative", "()V", (void*)periodicScanCleanupNative},
- {"startSyncNative", "(ILjava/lang/String;III)V", (void*)startSyncNative},
- {"stopSyncNative", "(I)V", (void*)stopSyncNative},
- {"cancelSyncNative", "(ILjava/lang/String;)V", (void*)cancelSyncNative},
- {"syncTransferNative", "(ILjava/lang/String;II)V",
- (void*)syncTransferNative},
- {"transferSetInfoNative", "(ILjava/lang/String;II)V",
- (void*)transferSetInfoNative},
-};
-
-// JNI functions defined in ScanNativeInterface class.
-static JNINativeMethod sScanMethods[] = {
- {"registerScannerNative", "(JJ)V", (void*)registerScannerNative},
- {"unregisterScannerNative", "(I)V", (void*)unregisterScannerNative},
- {"gattClientScanNative", "(Z)V", (void*)gattClientScanNative},
- // Batch scan JNI functions.
- {"gattClientConfigBatchScanStorageNative", "(IIII)V",
- (void*)gattClientConfigBatchScanStorageNative},
- {"gattClientStartBatchScanNative", "(IIIIII)V",
- (void*)gattClientStartBatchScanNative},
- {"gattClientStopBatchScanNative", "(I)V",
- (void*)gattClientStopBatchScanNative},
- {"gattClientReadScanReportsNative", "(II)V",
- (void*)gattClientReadScanReportsNative},
- // Scan filter JNI functions.
- {"gattClientScanFilterParamAddNative",
- "(Lcom/android/bluetooth/gatt/FilterParams;)V",
- (void*)gattClientScanFilterParamAddNative},
- {"gattClientScanFilterParamDeleteNative", "(II)V",
- (void*)gattClientScanFilterParamDeleteNative},
- {"gattClientScanFilterParamClearAllNative", "(I)V",
- (void*)gattClientScanFilterParamClearAllNative},
- {"gattClientScanFilterAddNative",
- "(I[Lcom/android/bluetooth/gatt/ScanFilterQueue$Entry;I)V",
- (void*)gattClientScanFilterAddNative},
- {"gattClientScanFilterClearNative", "(II)V",
- (void*)gattClientScanFilterClearNative},
- {"gattClientScanFilterEnableNative", "(IZ)V",
- (void*)gattClientScanFilterEnableNative},
- {"gattSetScanParametersNative", "(III)V",
- (void*)gattSetScanParametersNative},
-};
-
// JNI functions defined in DistanceMeasurementManager class.
-static JNINativeMethod sDistanceMeasurementMethods[] = {
- {"classInitNative", "()V", (void*)distanceMeasurementClassInitNative},
- {"initializeNative", "()V", (void*)distanceMeasurementInitializeNative},
- {"cleanupNative", "()V", (void*)distanceMeasurementCleanupNative},
- {"startDistanceMeasurementNative", "(Ljava/lang/String;II)V",
- (void*)startDistanceMeasurementNative},
- {"stopDistanceMeasurementNative", "(Ljava/lang/String;I)V",
- (void*)stopDistanceMeasurementNative},
-};
// JNI functions defined in GattNativeInterface class.
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initializeNative", "()V", (void*)initializeNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"gattClientGetDeviceTypeNative", "(Ljava/lang/String;)I",
- (void*)gattClientGetDeviceTypeNative},
- {"gattClientRegisterAppNative", "(JJZ)V",
- (void*)gattClientRegisterAppNative},
- {"gattClientUnregisterAppNative", "(I)V",
- (void*)gattClientUnregisterAppNative},
- {"gattClientConnectNative", "(ILjava/lang/String;IZIZI)V",
- (void*)gattClientConnectNative},
- {"gattClientDisconnectNative", "(ILjava/lang/String;I)V",
- (void*)gattClientDisconnectNative},
- {"gattClientSetPreferredPhyNative", "(ILjava/lang/String;III)V",
- (void*)gattClientSetPreferredPhyNative},
- {"gattClientReadPhyNative", "(ILjava/lang/String;)V",
- (void*)gattClientReadPhyNative},
- {"gattClientRefreshNative", "(ILjava/lang/String;)V",
- (void*)gattClientRefreshNative},
- {"gattClientSearchServiceNative", "(IZJJ)V",
- (void*)gattClientSearchServiceNative},
- {"gattClientDiscoverServiceByUuidNative", "(IJJ)V",
- (void*)gattClientDiscoverServiceByUuidNative},
- {"gattClientGetGattDbNative", "(I)V", (void*)gattClientGetGattDbNative},
- {"gattClientReadCharacteristicNative", "(III)V",
- (void*)gattClientReadCharacteristicNative},
- {"gattClientReadUsingCharacteristicUuidNative", "(IJJIII)V",
- (void*)gattClientReadUsingCharacteristicUuidNative},
- {"gattClientReadDescriptorNative", "(III)V",
- (void*)gattClientReadDescriptorNative},
- {"gattClientWriteCharacteristicNative", "(IIII[B)V",
- (void*)gattClientWriteCharacteristicNative},
- {"gattClientWriteDescriptorNative", "(III[B)V",
- (void*)gattClientWriteDescriptorNative},
- {"gattClientExecuteWriteNative", "(IZ)V",
- (void*)gattClientExecuteWriteNative},
- {"gattClientRegisterForNotificationsNative", "(ILjava/lang/String;IZ)V",
- (void*)gattClientRegisterForNotificationsNative},
- {"gattClientReadRemoteRssiNative", "(ILjava/lang/String;)V",
- (void*)gattClientReadRemoteRssiNative},
- {"gattClientConfigureMTUNative", "(II)V",
- (void*)gattClientConfigureMTUNative},
- {"gattConnectionParameterUpdateNative", "(ILjava/lang/String;IIIIII)V",
- (void*)gattConnectionParameterUpdateNative},
- {"gattServerRegisterAppNative", "(JJZ)V",
- (void*)gattServerRegisterAppNative},
- {"gattServerUnregisterAppNative", "(I)V",
- (void*)gattServerUnregisterAppNative},
- {"gattServerConnectNative", "(ILjava/lang/String;ZI)V",
- (void*)gattServerConnectNative},
- {"gattServerDisconnectNative", "(ILjava/lang/String;I)V",
- (void*)gattServerDisconnectNative},
- {"gattServerSetPreferredPhyNative", "(ILjava/lang/String;III)V",
- (void*)gattServerSetPreferredPhyNative},
- {"gattServerReadPhyNative", "(ILjava/lang/String;)V",
- (void*)gattServerReadPhyNative},
- {"gattServerAddServiceNative", "(ILjava/util/List;)V",
- (void*)gattServerAddServiceNative},
- {"gattServerStopServiceNative", "(II)V",
- (void*)gattServerStopServiceNative},
- {"gattServerDeleteServiceNative", "(II)V",
- (void*)gattServerDeleteServiceNative},
- {"gattServerSendIndicationNative", "(III[B)V",
- (void*)gattServerSendIndicationNative},
- {"gattServerSendNotificationNative", "(III[B)V",
- (void*)gattServerSendNotificationNative},
- {"gattServerSendResponseNative", "(IIIIII[BI)V",
- (void*)gattServerSendResponseNative},
- {"gattSubrateRequestNative", "(ILjava/lang/String;IIIII)V",
- (void*)gattSubrateRequestNative},
-
- {"gattTestNative", "(IJJLjava/lang/String;IIIII)V", (void*)gattTestNative},
-};
+static int register_com_android_bluetooth_gatt_scan(JNIEnv* env) {
+ const JNINativeMethod methods[] = {
+ {"registerScannerNative", "(JJ)V", (void*)registerScannerNative},
+ {"unregisterScannerNative", "(I)V", (void*)unregisterScannerNative},
+ {"gattClientScanNative", "(Z)V", (void*)gattClientScanNative},
+ // Batch scan JNI functions.
+ {"gattClientConfigBatchScanStorageNative", "(IIII)V",
+ (void*)gattClientConfigBatchScanStorageNative},
+ {"gattClientStartBatchScanNative", "(IIIIII)V",
+ (void*)gattClientStartBatchScanNative},
+ {"gattClientStopBatchScanNative", "(I)V",
+ (void*)gattClientStopBatchScanNative},
+ {"gattClientReadScanReportsNative", "(II)V",
+ (void*)gattClientReadScanReportsNative},
+ // Scan filter JNI functions.
+ {"gattClientScanFilterParamAddNative",
+ "(Lcom/android/bluetooth/gatt/FilterParams;)V",
+ (void*)gattClientScanFilterParamAddNative},
+ {"gattClientScanFilterParamDeleteNative", "(II)V",
+ (void*)gattClientScanFilterParamDeleteNative},
+ {"gattClientScanFilterParamClearAllNative", "(I)V",
+ (void*)gattClientScanFilterParamClearAllNative},
+ {"gattClientScanFilterAddNative",
+ "(I[Lcom/android/bluetooth/gatt/ScanFilterQueue$Entry;I)V",
+ (void*)gattClientScanFilterAddNative},
+ {"gattClientScanFilterClearNative", "(II)V",
+ (void*)gattClientScanFilterClearNative},
+ {"gattClientScanFilterEnableNative", "(IZ)V",
+ (void*)gattClientScanFilterEnableNative},
+ {"gattSetScanParametersNative", "(III)V",
+ (void*)gattSetScanParametersNative},
+ };
+ return REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/gatt/ScanNativeInterface", methods);
+}
+
+static int register_com_android_bluetooth_gatt_advertise_manager(JNIEnv* env) {
+ const JNINativeMethod methods[] = {
+ {"initializeNative", "()V", (void*)advertiseInitializeNative},
+ {"cleanupNative", "()V", (void*)advertiseCleanupNative},
+ {"startAdvertisingSetNative",
+ "(Landroid/bluetooth/le/AdvertisingSetParameters;"
+ "[B[BLandroid/bluetooth/le/PeriodicAdvertisingParameters;[BIIII)V",
+ (void*)startAdvertisingSetNative},
+ {"stopAdvertisingSetNative", "(I)V", (void*)stopAdvertisingSetNative},
+ {"getOwnAddressNative", "(I)V", (void*)getOwnAddressNative},
+ {"enableAdvertisingSetNative", "(IZII)V",
+ (void*)enableAdvertisingSetNative},
+ {"setAdvertisingDataNative", "(I[B)V", (void*)setAdvertisingDataNative},
+ {"setScanResponseDataNative", "(I[B)V", (void*)setScanResponseDataNative},
+ {"setAdvertisingParametersNative",
+ "(ILandroid/bluetooth/le/AdvertisingSetParameters;)V",
+ (void*)setAdvertisingParametersNative},
+ {"setPeriodicAdvertisingParametersNative",
+ "(ILandroid/bluetooth/le/PeriodicAdvertisingParameters;)V",
+ (void*)setPeriodicAdvertisingParametersNative},
+ {"setPeriodicAdvertisingDataNative", "(I[B)V",
+ (void*)setPeriodicAdvertisingDataNative},
+ {"setPeriodicAdvertisingEnableNative", "(IZ)V",
+ (void*)setPeriodicAdvertisingEnableNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/gatt/AdvertiseManagerNativeInterface",
+ methods);
+ if (result != 0) {
+ return result;
+ }
-int register_com_android_bluetooth_gatt(JNIEnv* env) {
- int register_success = jniRegisterNativeMethods(
- env, "com/android/bluetooth/gatt/ScanNativeInterface", sScanMethods,
- NELEM(sScanMethods));
- register_success &= jniRegisterNativeMethods(
- env, "com/android/bluetooth/gatt/AdvertiseManager", sAdvertiseMethods,
- NELEM(sAdvertiseMethods));
- register_success &= jniRegisterNativeMethods(
- env, "com/android/bluetooth/gatt/PeriodicScanManager",
- sPeriodicScanMethods, NELEM(sPeriodicScanMethods));
- register_success &= jniRegisterNativeMethods(
+ const JNIJavaMethod javaMethods[] = {
+ {"onAdvertisingSetStarted", "(IIII)V", &method_onAdvertisingSetStarted},
+ {"onOwnAddressRead", "(IILjava/lang/String;)V", &method_onOwnAddressRead},
+ {"onAdvertisingEnabled", "(IZI)V", &method_onAdvertisingEnabled},
+ {"onAdvertisingDataSet", "(II)V", &method_onAdvertisingDataSet},
+ {"onScanResponseDataSet", "(II)V", &method_onScanResponseDataSet},
+ {"onAdvertisingParametersUpdated", "(III)V",
+ &method_onAdvertisingParametersUpdated},
+ {"onPeriodicAdvertisingParametersUpdated", "(II)V",
+ &method_onPeriodicAdvertisingParametersUpdated},
+ {"onPeriodicAdvertisingDataSet", "(II)V",
+ &method_onPeriodicAdvertisingDataSet},
+ {"onPeriodicAdvertisingEnabled", "(IZI)V",
+ &method_onPeriodicAdvertisingEnabled},
+ };
+ GET_JAVA_METHODS(env,
+ "com/android/bluetooth/gatt/AdvertiseManagerNativeInterface",
+ javaMethods);
+
+ return 0;
+}
+
+static int register_com_android_bluetooth_gatt_periodic_scan(JNIEnv* env) {
+ const JNINativeMethod methods[] = {
+ {"initializeNative", "()V", (void*)periodicScanInitializeNative},
+ {"cleanupNative", "()V", (void*)periodicScanCleanupNative},
+ {"startSyncNative", "(ILjava/lang/String;III)V", (void*)startSyncNative},
+ {"stopSyncNative", "(I)V", (void*)stopSyncNative},
+ {"cancelSyncNative", "(ILjava/lang/String;)V", (void*)cancelSyncNative},
+ {"syncTransferNative", "(ILjava/lang/String;II)V",
+ (void*)syncTransferNative},
+ {"transferSetInfoNative", "(ILjava/lang/String;II)V",
+ (void*)transferSetInfoNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/gatt/PeriodicScanNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onSyncStarted", "(IIIILjava/lang/String;III)V", &method_onSyncStarted},
+ {"onSyncReport", "(IIII[B)V", &method_onSyncReport},
+ {"onSyncLost", "(I)V", &method_onSyncLost},
+ {"onSyncTransferredCallback", "(IILjava/lang/String;)V",
+ &method_onSyncTransferredCallback},
+ {"onBigInfoReport", "(IZ)V", &method_onBigInfoReport},
+ };
+ GET_JAVA_METHODS(env,
+ "com/android/bluetooth/gatt/PeriodicScanNativeInterface",
+ javaMethods);
+
+ return 0;
+}
+
+static int register_com_android_bluetooth_gatt_distance_measurement(
+ JNIEnv* env) {
+ const JNINativeMethod methods[] = {
+ {"initializeNative", "()V", (void*)distanceMeasurementInitializeNative},
+ {"cleanupNative", "()V", (void*)distanceMeasurementCleanupNative},
+ {"startDistanceMeasurementNative", "(Ljava/lang/String;II)V",
+ (void*)startDistanceMeasurementNative},
+ {"stopDistanceMeasurementNative", "(Ljava/lang/String;I)V",
+ (void*)stopDistanceMeasurementNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
env, "com/android/bluetooth/gatt/DistanceMeasurementNativeInterface",
- sDistanceMeasurementMethods, NELEM(sDistanceMeasurementMethods));
- return register_success &
- jniRegisterNativeMethods(
- env, "com/android/bluetooth/gatt/GattNativeInterface", sMethods,
- NELEM(sMethods));
+ methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onDistanceMeasurementStarted", "(Ljava/lang/String;I)V",
+ &method_onDistanceMeasurementStarted},
+ {"onDistanceMeasurementStartFail", "(Ljava/lang/String;II)V",
+ &method_onDistanceMeasurementStartFail},
+ {"onDistanceMeasurementStopped", "(Ljava/lang/String;II)V",
+ &method_onDistanceMeasurementStopped},
+ {"onDistanceMeasurementResult", "(Ljava/lang/String;IIIIIII)V",
+ &method_onDistanceMeasurementResult},
+ };
+ GET_JAVA_METHODS(
+ env, "com/android/bluetooth/gatt/DistanceMeasurementNativeInterface",
+ javaMethods);
+
+ return 0;
+}
+
+static int register_com_android_bluetooth_gatt_(JNIEnv* env) {
+ const JNINativeMethod methods[] = {
+ {"initializeNative", "()V", (void*)initializeNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"gattClientGetDeviceTypeNative", "(Ljava/lang/String;)I",
+ (void*)gattClientGetDeviceTypeNative},
+ {"gattClientRegisterAppNative", "(JJZ)V",
+ (void*)gattClientRegisterAppNative},
+ {"gattClientUnregisterAppNative", "(I)V",
+ (void*)gattClientUnregisterAppNative},
+ {"gattClientConnectNative", "(ILjava/lang/String;IZIZI)V",
+ (void*)gattClientConnectNative},
+ {"gattClientDisconnectNative", "(ILjava/lang/String;I)V",
+ (void*)gattClientDisconnectNative},
+ {"gattClientSetPreferredPhyNative", "(ILjava/lang/String;III)V",
+ (void*)gattClientSetPreferredPhyNative},
+ {"gattClientReadPhyNative", "(ILjava/lang/String;)V",
+ (void*)gattClientReadPhyNative},
+ {"gattClientRefreshNative", "(ILjava/lang/String;)V",
+ (void*)gattClientRefreshNative},
+ {"gattClientSearchServiceNative", "(IZJJ)V",
+ (void*)gattClientSearchServiceNative},
+ {"gattClientDiscoverServiceByUuidNative", "(IJJ)V",
+ (void*)gattClientDiscoverServiceByUuidNative},
+ {"gattClientGetGattDbNative", "(I)V", (void*)gattClientGetGattDbNative},
+ {"gattClientReadCharacteristicNative", "(III)V",
+ (void*)gattClientReadCharacteristicNative},
+ {"gattClientReadUsingCharacteristicUuidNative", "(IJJIII)V",
+ (void*)gattClientReadUsingCharacteristicUuidNative},
+ {"gattClientReadDescriptorNative", "(III)V",
+ (void*)gattClientReadDescriptorNative},
+ {"gattClientWriteCharacteristicNative", "(IIII[B)V",
+ (void*)gattClientWriteCharacteristicNative},
+ {"gattClientWriteDescriptorNative", "(III[B)V",
+ (void*)gattClientWriteDescriptorNative},
+ {"gattClientExecuteWriteNative", "(IZ)V",
+ (void*)gattClientExecuteWriteNative},
+ {"gattClientRegisterForNotificationsNative", "(ILjava/lang/String;IZ)V",
+ (void*)gattClientRegisterForNotificationsNative},
+ {"gattClientReadRemoteRssiNative", "(ILjava/lang/String;)V",
+ (void*)gattClientReadRemoteRssiNative},
+ {"gattClientConfigureMTUNative", "(II)V",
+ (void*)gattClientConfigureMTUNative},
+ {"gattConnectionParameterUpdateNative", "(ILjava/lang/String;IIIIII)V",
+ (void*)gattConnectionParameterUpdateNative},
+ {"gattServerRegisterAppNative", "(JJZ)V",
+ (void*)gattServerRegisterAppNative},
+ {"gattServerUnregisterAppNative", "(I)V",
+ (void*)gattServerUnregisterAppNative},
+ {"gattServerConnectNative", "(ILjava/lang/String;ZI)V",
+ (void*)gattServerConnectNative},
+ {"gattServerDisconnectNative", "(ILjava/lang/String;I)V",
+ (void*)gattServerDisconnectNative},
+ {"gattServerSetPreferredPhyNative", "(ILjava/lang/String;III)V",
+ (void*)gattServerSetPreferredPhyNative},
+ {"gattServerReadPhyNative", "(ILjava/lang/String;)V",
+ (void*)gattServerReadPhyNative},
+ {"gattServerAddServiceNative", "(ILjava/util/List;)V",
+ (void*)gattServerAddServiceNative},
+ {"gattServerStopServiceNative", "(II)V",
+ (void*)gattServerStopServiceNative},
+ {"gattServerDeleteServiceNative", "(II)V",
+ (void*)gattServerDeleteServiceNative},
+ {"gattServerSendIndicationNative", "(III[B)V",
+ (void*)gattServerSendIndicationNative},
+ {"gattServerSendNotificationNative", "(III[B)V",
+ (void*)gattServerSendNotificationNative},
+ {"gattServerSendResponseNative", "(IIIIII[BI)V",
+ (void*)gattServerSendResponseNative},
+ {"gattSubrateRequestNative", "(ILjava/lang/String;IIIII)V",
+ (void*)gattSubrateRequestNative},
+
+ {"gattTestNative", "(IJJLjava/lang/String;IIIII)V",
+ (void*)gattTestNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/gatt/GattNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ // Client callbacks
+ {"onClientRegistered", "(IIJJ)V", &method_onClientRegistered},
+ {"onScannerRegistered", "(IIJJ)V", &method_onScannerRegistered},
+ {"onScanResult", "(IILjava/lang/String;IIIIII[BLjava/lang/String;)V",
+ &method_onScanResult},
+ {"onConnected", "(IIILjava/lang/String;)V", &method_onConnected},
+ {"onDisconnected", "(IIILjava/lang/String;)V", &method_onDisconnected},
+ {"onReadCharacteristic", "(III[B)V", &method_onReadCharacteristic},
+ {"onWriteCharacteristic", "(III[B)V", &method_onWriteCharacteristic},
+ {"onExecuteCompleted", "(II)V", &method_onExecuteCompleted},
+ {"onSearchCompleted", "(II)V", &method_onSearchCompleted},
+ {"onReadDescriptor", "(III[B)V", &method_onReadDescriptor},
+ {"onWriteDescriptor", "(III[B)V", &method_onWriteDescriptor},
+ {"onNotify", "(ILjava/lang/String;IZ[B)V", &method_onNotify},
+ {"onRegisterForNotifications", "(IIII)V",
+ &method_onRegisterForNotifications},
+ {"onReadRemoteRssi", "(ILjava/lang/String;II)V",
+ &method_onReadRemoteRssi},
+ {"onConfigureMTU", "(III)V", &method_onConfigureMTU},
+ {"onScanFilterConfig", "(IIIII)V", &method_onScanFilterConfig},
+ {"onScanFilterParamsConfigured", "(IIII)V",
+ &method_onScanFilterParamsConfigured},
+ {"onScanFilterEnableDisabled", "(III)V",
+ &method_onScanFilterEnableDisabled},
+ {"onClientCongestion", "(IZ)V", &method_onClientCongestion},
+ {"onBatchScanStorageConfigured", "(II)V",
+ &method_onBatchScanStorageConfigured},
+ {"onBatchScanStartStopped", "(III)V", &method_onBatchScanStartStopped},
+ {"onBatchScanReports", "(IIII[B)V", &method_onBatchScanReports},
+ {"onBatchScanThresholdCrossed", "(I)V",
+ &method_onBatchScanThresholdCrossed},
+ {"createOnTrackAdvFoundLostObject",
+ "(II[BI[BIIILjava/lang/String;IIII)"
+ "Lcom/android/bluetooth/gatt/AdvtFilterOnFoundOnLostInfo;",
+ &method_createOnTrackAdvFoundLostObject},
+ {"onTrackAdvFoundLost",
+ "(Lcom/android/bluetooth/gatt/AdvtFilterOnFoundOnLostInfo;)V",
+ &method_onTrackAdvFoundLost},
+ {"onScanParamSetupCompleted", "(II)V", &method_onScanParamSetupCompleted},
+ {"getSampleGattDbElement", "()Lcom/android/bluetooth/gatt/GattDbElement;",
+ &method_getSampleGattDbElement},
+ {"onGetGattDb", "(ILjava/util/ArrayList;)V", &method_onGetGattDb},
+ {"onClientPhyRead", "(ILjava/lang/String;III)V", &method_onClientPhyRead},
+ {"onClientPhyUpdate", "(IIII)V", &method_onClientPhyUpdate},
+ {"onClientConnUpdate", "(IIIII)V", &method_onClientConnUpdate},
+ {"onServiceChanged", "(I)V", &method_onServiceChanged},
+ {"onClientSubrateChange", "(IIIIII)V", &method_onClientSubrateChange},
+
+ // Server callbacks
+ {"onServerRegistered", "(IIJJ)V", &method_onServerRegistered},
+ {"onClientConnected", "(Ljava/lang/String;ZII)V",
+ &method_onClientConnected},
+ {"onServiceAdded", "(IILjava/util/List;)V", &method_onServiceAdded},
+ {"onServiceStopped", "(III)V", &method_onServiceStopped},
+ {"onServiceDeleted", "(III)V", &method_onServiceDeleted},
+ {"onResponseSendCompleted", "(II)V", &method_onResponseSendCompleted},
+ {"onServerReadCharacteristic", "(Ljava/lang/String;IIIIZ)V",
+ &method_onServerReadCharacteristic},
+ {"onServerReadDescriptor", "(Ljava/lang/String;IIIIZ)V",
+ &method_onServerReadDescriptor},
+ {"onServerWriteCharacteristic", "(Ljava/lang/String;IIIIIZZ[B)V",
+ &method_onServerWriteCharacteristic},
+ {"onServerWriteDescriptor", "(Ljava/lang/String;IIIIIZZ[B)V",
+ &method_onServerWriteDescriptor},
+ {"onExecuteWrite", "(Ljava/lang/String;III)V", &method_onExecuteWrite},
+ {"onNotificationSent", "(II)V", &method_onNotificationSent},
+ {"onServerCongestion", "(IZ)V", &method_onServerCongestion},
+ {"onMtuChanged", "(II)V", &method_onServerMtuChanged},
+ {"onServerPhyRead", "(ILjava/lang/String;III)V", &method_onServerPhyRead},
+ {"onServerPhyUpdate", "(IIII)V", &method_onServerPhyUpdate},
+ {"onServerConnUpdate", "(IIIII)V", &method_onServerConnUpdate},
+ {"onServerSubrateChange", "(IIIIII)V", &method_onServerSubrateChange},
+ };
+ GET_JAVA_METHODS(env, "com/android/bluetooth/gatt/GattNativeInterface",
+ javaMethods);
+
+ return 0;
+}
+
+int register_com_android_bluetooth_gatt(JNIEnv* env) {
+ const std::array, 5> register_fns = {
+ register_com_android_bluetooth_gatt_scan,
+ register_com_android_bluetooth_gatt_advertise_manager,
+ register_com_android_bluetooth_gatt_periodic_scan,
+ register_com_android_bluetooth_gatt_distance_measurement,
+ register_com_android_bluetooth_gatt_,
+ };
+
+ for (const auto& fn : register_fns) {
+ const int result = fn(env);
+ if (result != 0) {
+ return result;
+ }
+ }
+ return 0;
}
} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_hap_client.cpp b/android/app/jni/com_android_bluetooth_hap_client.cpp
index 1d77a27eb33f000b2e6119b94c200f6dd681ad2f..067af34197bc08cf735b2ba8cd668da87a20c561 100644
--- a/android/app/jni/com_android_bluetooth_hap_client.cpp
+++ b/android/app/jni/com_android_bluetooth_hap_client.cpp
@@ -301,59 +301,6 @@ class HasClientCallbacksImpl : public HasClientCallbacks {
static HasClientCallbacksImpl sHasClientCallbacks;
-static void classInitNative(JNIEnv* env, jclass clazz) {
- jclass jniBluetoothBluetoothHapPresetInfoClass =
- env->FindClass("android/bluetooth/BluetoothHapPresetInfo");
- CHECK(jniBluetoothBluetoothHapPresetInfoClass != NULL);
-
- android_bluetooth_BluetoothHapPresetInfo.constructor =
- env->GetMethodID(jniBluetoothBluetoothHapPresetInfoClass, "",
- "(ILjava/lang/String;ZZ)V");
-
- method_onConnectionStateChanged =
- env->GetMethodID(clazz, "onConnectionStateChanged", "(I[B)V");
-
- method_onDeviceAvailable =
- env->GetMethodID(clazz, "onDeviceAvailable", "([BI)V");
-
- method_onFeaturesUpdate =
- env->GetMethodID(clazz, "onFeaturesUpdate", "([BI)V");
-
- method_onActivePresetSelected =
- env->GetMethodID(clazz, "onActivePresetSelected", "([BI)V");
-
- method_onGroupActivePresetSelected =
- env->GetMethodID(clazz, "onActivePresetGroupSelected", "(II)V");
-
- method_onActivePresetSelectError =
- env->GetMethodID(clazz, "onActivePresetSelectError", "([BI)V");
-
- method_onGroupActivePresetSelectError =
- env->GetMethodID(clazz, "onActivePresetGroupSelectError", "(II)V");
-
- method_onPresetInfo =
- env->GetMethodID(clazz, "onPresetInfo",
- "([BI[Landroid/bluetooth/BluetoothHapPresetInfo;)V");
-
- method_onGroupPresetInfo =
- env->GetMethodID(clazz, "onGroupPresetInfo",
- "(II[Landroid/bluetooth/BluetoothHapPresetInfo;)V");
-
- method_onPresetNameSetError =
- env->GetMethodID(clazz, "onPresetNameSetError", "([BII)V");
-
- method_onGroupPresetNameSetError =
- env->GetMethodID(clazz, "onGroupPresetNameSetError", "(III)V");
-
- method_onPresetInfoError =
- env->GetMethodID(clazz, "onPresetInfoError", "([BII)V");
-
- method_onGroupPresetInfoError =
- env->GetMethodID(clazz, "onGroupPresetInfoError", "(III)V");
-
- LOG(INFO) << __func__ << ": succeeds";
-}
-
static void initNative(JNIEnv* env, jobject object) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -400,7 +347,7 @@ static void initNative(JNIEnv* env, jobject object) {
sHasClientInterface->Init(&sHasClientCallbacks);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -421,7 +368,7 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static jboolean connectHapClientNative(JNIEnv* env, jobject object,
+static jboolean connectHapClientNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sHasClientInterface) {
@@ -441,7 +388,7 @@ static jboolean connectHapClientNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static jboolean disconnectHapClientNative(JNIEnv* env, jobject object,
+static jboolean disconnectHapClientNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sHasClientInterface) {
@@ -461,7 +408,7 @@ static jboolean disconnectHapClientNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static void selectActivePresetNative(JNIEnv* env, jobject object,
+static void selectActivePresetNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jint preset_index) {
std::shared_lock lock(interface_mutex);
if (!sHasClientInterface) {
@@ -480,8 +427,9 @@ static void selectActivePresetNative(JNIEnv* env, jobject object,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void groupSelectActivePresetNative(JNIEnv* env, jobject object,
- jint group_id, jint preset_index) {
+static void groupSelectActivePresetNative(JNIEnv* /* env */,
+ jobject /* object */, jint group_id,
+ jint preset_index) {
std::shared_lock lock(interface_mutex);
if (!sHasClientInterface) {
LOG(ERROR) << __func__ << ": Failed to get the Bluetooth HAP Interface";
@@ -491,7 +439,7 @@ static void groupSelectActivePresetNative(JNIEnv* env, jobject object,
sHasClientInterface->SelectActivePreset(group_id, preset_index);
}
-static void nextActivePresetNative(JNIEnv* env, jobject object,
+static void nextActivePresetNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sHasClientInterface) {
@@ -510,7 +458,7 @@ static void nextActivePresetNative(JNIEnv* env, jobject object,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void groupNextActivePresetNative(JNIEnv* env, jobject object,
+static void groupNextActivePresetNative(JNIEnv* /* env */, jobject /* object */,
jint group_id) {
std::shared_lock lock(interface_mutex);
if (!sHasClientInterface) {
@@ -521,7 +469,7 @@ static void groupNextActivePresetNative(JNIEnv* env, jobject object,
sHasClientInterface->NextActivePreset(group_id);
}
-static void previousActivePresetNative(JNIEnv* env, jobject object,
+static void previousActivePresetNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sHasClientInterface) {
@@ -540,7 +488,8 @@ static void previousActivePresetNative(JNIEnv* env, jobject object,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void groupPreviousActivePresetNative(JNIEnv* env, jobject object,
+static void groupPreviousActivePresetNative(JNIEnv* /* env */,
+ jobject /* object */,
jint group_id) {
std::shared_lock lock(interface_mutex);
if (!sHasClientInterface) {
@@ -551,8 +500,8 @@ static void groupPreviousActivePresetNative(JNIEnv* env, jobject object,
sHasClientInterface->PreviousActivePreset(group_id);
}
-static void getPresetInfoNative(JNIEnv* env, jobject object, jbyteArray address,
- jint preset_index) {
+static void getPresetInfoNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jint preset_index) {
std::shared_lock lock(interface_mutex);
if (!sHasClientInterface) {
LOG(ERROR) << __func__ << ": Failed to get the Bluetooth HAP Interface";
@@ -570,8 +519,9 @@ static void getPresetInfoNative(JNIEnv* env, jobject object, jbyteArray address,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void setPresetNameNative(JNIEnv* env, jobject object, jbyteArray address,
- jint preset_index, jstring name) {
+static void setPresetNameNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jint preset_index,
+ jstring name) {
std::shared_lock lock(interface_mutex);
if (!sHasClientInterface) {
LOG(ERROR) << __func__ << ": Failed to get the Bluetooth HAP Interface";
@@ -597,8 +547,9 @@ static void setPresetNameNative(JNIEnv* env, jobject object, jbyteArray address,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void groupSetPresetNameNative(JNIEnv* env, jobject object, jint group_id,
- jint preset_index, jstring name) {
+static void groupSetPresetNameNative(JNIEnv* env, jobject /* object */,
+ jint group_id, jint preset_index,
+ jstring name) {
std::shared_lock lock(interface_mutex);
if (!sHasClientInterface) {
LOG(ERROR) << __func__ << ": Failed to get the Bluetooth HAP Interface";
@@ -616,30 +567,65 @@ static void groupSetPresetNameNative(JNIEnv* env, jobject object, jint group_id,
std::move(name_str));
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative", "()V", (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"connectHapClientNative", "([B)Z", (void*)connectHapClientNative},
- {"disconnectHapClientNative", "([B)Z", (void*)disconnectHapClientNative},
- {"selectActivePresetNative", "([BI)V", (void*)selectActivePresetNative},
- {"groupSelectActivePresetNative", "(II)V",
- (void*)groupSelectActivePresetNative},
- {"nextActivePresetNative", "([B)V", (void*)nextActivePresetNative},
- {"groupNextActivePresetNative", "(I)V", (void*)groupNextActivePresetNative},
- {"previousActivePresetNative", "([B)V", (void*)previousActivePresetNative},
- {"groupPreviousActivePresetNative", "(I)V",
- (void*)groupPreviousActivePresetNative},
- {"getPresetInfoNative", "([BI)V", (void*)getPresetInfoNative},
- {"setPresetNameNative", "([BILjava/lang/String;)V",
- (void*)setPresetNameNative},
- {"groupSetPresetNameNative", "(IILjava/lang/String;)V",
- (void*)groupSetPresetNameNative},
-};
-
int register_com_android_bluetooth_hap_client(JNIEnv* env) {
- return jniRegisterNativeMethods(
- env, "com/android/bluetooth/hap/HapClientNativeInterface", sMethods,
- NELEM(sMethods));
+ const JNINativeMethod methods[] = {
+ {"initNative", "()V", (void*)initNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"connectHapClientNative", "([B)Z", (void*)connectHapClientNative},
+ {"disconnectHapClientNative", "([B)Z", (void*)disconnectHapClientNative},
+ {"selectActivePresetNative", "([BI)V", (void*)selectActivePresetNative},
+ {"groupSelectActivePresetNative", "(II)V",
+ (void*)groupSelectActivePresetNative},
+ {"nextActivePresetNative", "([B)V", (void*)nextActivePresetNative},
+ {"groupNextActivePresetNative", "(I)V",
+ (void*)groupNextActivePresetNative},
+ {"previousActivePresetNative", "([B)V",
+ (void*)previousActivePresetNative},
+ {"groupPreviousActivePresetNative", "(I)V",
+ (void*)groupPreviousActivePresetNative},
+ {"getPresetInfoNative", "([BI)V", (void*)getPresetInfoNative},
+ {"setPresetNameNative", "([BILjava/lang/String;)V",
+ (void*)setPresetNameNative},
+ {"groupSetPresetNameNative", "(IILjava/lang/String;)V",
+ (void*)groupSetPresetNameNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/hap/HapClientNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onConnectionStateChanged", "(I[B)V", &method_onConnectionStateChanged},
+ {"onDeviceAvailable", "([BI)V", &method_onDeviceAvailable},
+ {"onFeaturesUpdate", "([BI)V", &method_onFeaturesUpdate},
+ {"onActivePresetSelected", "([BI)V", &method_onActivePresetSelected},
+ {"onActivePresetGroupSelected", "(II)V",
+ &method_onGroupActivePresetSelected},
+ {"onActivePresetSelectError", "([BI)V",
+ &method_onActivePresetSelectError},
+ {"onActivePresetGroupSelectError", "(II)V",
+ &method_onGroupActivePresetSelectError},
+ {"onPresetInfo", "([BI[Landroid/bluetooth/BluetoothHapPresetInfo;)V",
+ &method_onPresetInfo},
+ {"onGroupPresetInfo", "(II[Landroid/bluetooth/BluetoothHapPresetInfo;)V",
+ &method_onGroupPresetInfo},
+ {"onPresetNameSetError", "([BII)V", &method_onPresetNameSetError},
+ {"onGroupPresetNameSetError", "(III)V",
+ &method_onGroupPresetNameSetError},
+ {"onPresetInfoError", "([BII)V", &method_onPresetInfoError},
+ {"onGroupPresetInfoError", "(III)V", &method_onGroupPresetInfoError},
+ };
+ GET_JAVA_METHODS(env, "com/android/bluetooth/hap/HapClientNativeInterface",
+ javaMethods);
+
+ const JNIJavaMethod javaHapPresetMethods[] = {
+ {"", "(ILjava/lang/String;ZZ)V",
+ &android_bluetooth_BluetoothHapPresetInfo.constructor},
+ };
+ GET_JAVA_METHODS(env, "android/bluetooth/BluetoothHapPresetInfo",
+ javaHapPresetMethods);
+
+ return 0;
}
} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_hearing_aid.cpp b/android/app/jni/com_android_bluetooth_hearing_aid.cpp
index 5e2f88e680ae990d09019bfe45b3cf25864fa688..648ff8d1d1d87ca56795a71ae49f22f0b92b8ac0 100644
--- a/android/app/jni/com_android_bluetooth_hearing_aid.cpp
+++ b/android/app/jni/com_android_bluetooth_hearing_aid.cpp
@@ -87,16 +87,6 @@ class HearingAidCallbacksImpl : public HearingAidCallbacks {
static HearingAidCallbacksImpl sHearingAidCallbacks;
-static void classInitNative(JNIEnv* env, jclass clazz) {
- method_onConnectionStateChanged =
- env->GetMethodID(clazz, "onConnectionStateChanged", "(I[B)V");
-
- method_onDeviceAvailable =
- env->GetMethodID(clazz, "onDeviceAvailable", "(BJ[B)V");
-
- LOG(INFO) << __func__ << ": succeeds";
-}
-
static void initNative(JNIEnv* env, jobject object) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -134,7 +124,7 @@ static void initNative(JNIEnv* env, jobject object) {
sHearingAidInterface->Init(&sHearingAidCallbacks);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -155,7 +145,7 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static jboolean connectHearingAidNative(JNIEnv* env, jobject object,
+static jboolean connectHearingAidNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
LOG(INFO) << __func__;
std::shared_lock lock(interface_mutex);
@@ -173,7 +163,7 @@ static jboolean connectHearingAidNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static jboolean disconnectHearingAidNative(JNIEnv* env, jobject object,
+static jboolean disconnectHearingAidNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
LOG(INFO) << __func__;
std::shared_lock lock(interface_mutex);
@@ -191,8 +181,8 @@ static jboolean disconnectHearingAidNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static jboolean addToAcceptlistNative(JNIEnv* env, jobject object,
- jbyteArray address) {
+static jboolean addToAcceptlistNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sHearingAidInterface) return JNI_FALSE;
jbyte* addr = env->GetByteArrayElements(address, nullptr);
@@ -207,7 +197,8 @@ static jboolean addToAcceptlistNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static void setVolumeNative(JNIEnv* env, jclass clazz, jint volume) {
+static void setVolumeNative(JNIEnv* /* env */, jclass /* clazz */,
+ jint volume) {
if (!sHearingAidInterface) {
LOG(ERROR) << __func__
<< ": Failed to get the Bluetooth Hearing Aid Interface";
@@ -216,19 +207,31 @@ static void setVolumeNative(JNIEnv* env, jclass clazz, jint volume) {
sHearingAidInterface->SetVolume(volume);
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative", "()V", (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"connectHearingAidNative", "([B)Z", (void*)connectHearingAidNative},
- {"disconnectHearingAidNative", "([B)Z", (void*)disconnectHearingAidNative},
- {"addToAcceptlistNative", "([B)Z", (void*)addToAcceptlistNative},
- {"setVolumeNative", "(I)V", (void*)setVolumeNative},
-};
-
int register_com_android_bluetooth_hearing_aid(JNIEnv* env) {
- return jniRegisterNativeMethods(
+ const JNINativeMethod methods[] = {
+ {"initNative", "()V", (void*)initNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"connectHearingAidNative", "([B)Z", (void*)connectHearingAidNative},
+ {"disconnectHearingAidNative", "([B)Z",
+ (void*)disconnectHearingAidNative},
+ {"addToAcceptlistNative", "([B)Z", (void*)addToAcceptlistNative},
+ {"setVolumeNative", "(I)V", (void*)setVolumeNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
env, "com/android/bluetooth/hearingaid/HearingAidNativeInterface",
- sMethods, NELEM(sMethods));
+ methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onConnectionStateChanged", "(I[B)V", &method_onConnectionStateChanged},
+ {"onDeviceAvailable", "(BJ[B)V", &method_onDeviceAvailable},
+ };
+ GET_JAVA_METHODS(env,
+ "com/android/bluetooth/hearingaid/HearingAidNativeInterface",
+ javaMethods);
+
+ return 0;
}
} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_hfp.cpp b/android/app/jni/com_android_bluetooth_hfp.cpp
index ede3e134a36a32ed84ec4e61eea19668434cfde9..d33669f49150ef7743d6e2e85c023cf08b4eafb7 100644
--- a/android/app/jni/com_android_bluetooth_hfp.cpp
+++ b/android/app/jni/com_android_bluetooth_hfp.cpp
@@ -237,7 +237,8 @@ class JniHeadsetCallbacks : bluetooth::headset::Callbacks {
addr.get());
}
- void SwbCallback(bluetooth::headset::bthf_swb_config_t swb_config,
+ void SwbCallback(bluetooth::headset::bthf_swb_codec_t swb_codec,
+ bluetooth::headset::bthf_swb_config_t swb_config,
RawAddress* bd_addr) override {
std::shared_lock lock(callbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
@@ -246,8 +247,8 @@ class JniHeadsetCallbacks : bluetooth::headset::Callbacks {
ScopedLocalRef addr(sCallbackEnv.get(), marshall_bda(bd_addr));
if (addr.get() == nullptr) return;
- sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onSWB, swb_config,
- addr.get());
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onSWB, swb_codec,
+ swb_config, addr.get());
}
void AtChldCallback(bluetooth::headset::bthf_chld_type_t chld,
@@ -409,41 +410,16 @@ class JniHeadsetCallbacks : bluetooth::headset::Callbacks {
sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAtBia, service, roam,
signal, battery, addr.get());
}
-};
-static void classInitNative(JNIEnv* env, jclass clazz) {
- method_onConnectionStateChanged =
- env->GetMethodID(clazz, "onConnectionStateChanged", "(I[B)V");
- method_onAudioStateChanged =
- env->GetMethodID(clazz, "onAudioStateChanged", "(I[B)V");
- method_onVrStateChanged =
- env->GetMethodID(clazz, "onVrStateChanged", "(I[B)V");
- method_onAnswerCall = env->GetMethodID(clazz, "onAnswerCall", "([B)V");
- method_onHangupCall = env->GetMethodID(clazz, "onHangupCall", "([B)V");
- method_onVolumeChanged =
- env->GetMethodID(clazz, "onVolumeChanged", "(II[B)V");
- method_onDialCall =
- env->GetMethodID(clazz, "onDialCall", "(Ljava/lang/String;[B)V");
- method_onSendDtmf = env->GetMethodID(clazz, "onSendDtmf", "(I[B)V");
- method_onNoiseReductionEnable =
- env->GetMethodID(clazz, "onNoiseReductionEnable", "(Z[B)V");
- method_onWBS = env->GetMethodID(clazz, "onWBS", "(I[B)V");
- method_onSWB = env->GetMethodID(clazz, "onSWB", "(I[B)V");
- method_onAtChld = env->GetMethodID(clazz, "onAtChld", "(I[B)V");
- method_onAtCnum = env->GetMethodID(clazz, "onAtCnum", "([B)V");
- method_onAtCind = env->GetMethodID(clazz, "onAtCind", "([B)V");
- method_onAtCops = env->GetMethodID(clazz, "onAtCops", "([B)V");
- method_onAtClcc = env->GetMethodID(clazz, "onAtClcc", "([B)V");
- method_onUnknownAt =
- env->GetMethodID(clazz, "onUnknownAt", "(Ljava/lang/String;[B)V");
- method_onKeyPressed = env->GetMethodID(clazz, "onKeyPressed", "([B)V");
- method_onAtBind =
- env->GetMethodID(clazz, "onATBind", "(Ljava/lang/String;[B)V");
- method_onAtBiev = env->GetMethodID(clazz, "onATBiev", "(II[B)V");
- method_onAtBia = env->GetMethodID(clazz, "onAtBia", "(ZZZZ[B)V");
-
- ALOGI("%s: succeeds", __func__);
-}
+ void DebugDumpCallback(bool /* active */, uint16_t /* codec_id */,
+ int /* total_num_decoded_frames */,
+ double /* pkt_loss_ratio */, uint64_t /* begin_ts */,
+ uint64_t /* end_ts */,
+ const char* /* pkt_status_in_hex */,
+ const char* /* pkt_status_in_binary */) override {
+ ALOGE("Not implemented and shouldn't be called");
+ }
+};
static void initializeNative(JNIEnv* env, jobject object, jint max_hf_clients,
jboolean inband_ringing_enabled) {
@@ -491,7 +467,7 @@ static void initializeNative(JNIEnv* env, jobject object, jint max_hf_clients,
mCallbacksObj = env->NewGlobalRef(object);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -514,7 +490,7 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static jboolean connectHfpNative(JNIEnv* env, jobject object,
+static jboolean connectHfpNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
@@ -537,7 +513,7 @@ static jboolean connectHfpNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean disconnectHfpNative(JNIEnv* env, jobject object,
+static jboolean disconnectHfpNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
@@ -560,7 +536,7 @@ static jboolean disconnectHfpNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean connectAudioNative(JNIEnv* env, jobject object,
+static jboolean connectAudioNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
@@ -576,7 +552,7 @@ static jboolean connectAudioNative(JNIEnv* env, jobject object,
ALOGI("%s: device %s", __func__,
ADDRESS_TO_LOGGABLE_CSTR(*((RawAddress*)addr)));
bt_status_t status =
- sBluetoothHfpInterface->ConnectAudio((RawAddress*)addr, false);
+ sBluetoothHfpInterface->ConnectAudio((RawAddress*)addr, 0);
if (status != BT_STATUS_SUCCESS) {
ALOGE("Failed HF audio connection, status: %d", status);
}
@@ -584,7 +560,7 @@ static jboolean connectAudioNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean disconnectAudioNative(JNIEnv* env, jobject object,
+static jboolean disconnectAudioNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
@@ -608,7 +584,8 @@ static jboolean disconnectAudioNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean isNoiseReductionSupportedNative(JNIEnv* env, jobject object,
+static jboolean isNoiseReductionSupportedNative(JNIEnv* env,
+ jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
@@ -627,7 +604,8 @@ static jboolean isNoiseReductionSupportedNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean isVoiceRecognitionSupportedNative(JNIEnv* env, jobject object,
+static jboolean isVoiceRecognitionSupportedNative(JNIEnv* env,
+ jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
@@ -646,7 +624,7 @@ static jboolean isVoiceRecognitionSupportedNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean startVoiceRecognitionNative(JNIEnv* env, jobject object,
+static jboolean startVoiceRecognitionNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
@@ -668,7 +646,7 @@ static jboolean startVoiceRecognitionNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean stopVoiceRecognitionNative(JNIEnv* env, jobject object,
+static jboolean stopVoiceRecognitionNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
@@ -690,8 +668,9 @@ static jboolean stopVoiceRecognitionNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean setVolumeNative(JNIEnv* env, jobject object, jint volume_type,
- jint volume, jbyteArray address) {
+static jboolean setVolumeNative(JNIEnv* env, jobject /* object */,
+ jint volume_type, jint volume,
+ jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
ALOGW("%s: sBluetoothHfpInterface is null", __func__);
@@ -713,7 +692,7 @@ static jboolean setVolumeNative(JNIEnv* env, jobject object, jint volume_type,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean notifyDeviceStatusNative(JNIEnv* env, jobject object,
+static jboolean notifyDeviceStatusNative(JNIEnv* env, jobject /* object */,
jint network_state, jint service_type,
jint signal, jint battery_charge,
jbyteArray address) {
@@ -739,7 +718,7 @@ static jboolean notifyDeviceStatusNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean copsResponseNative(JNIEnv* env, jobject object,
+static jboolean copsResponseNative(JNIEnv* env, jobject /* object */,
jstring operator_str, jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
@@ -763,8 +742,8 @@ static jboolean copsResponseNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean cindResponseNative(JNIEnv* env, jobject object, jint service,
- jint num_active, jint num_held,
+static jboolean cindResponseNative(JNIEnv* env, jobject /* object */,
+ jint service, jint num_active, jint num_held,
jint call_state, jint signal, jint roam,
jint battery_charge, jbyteArray address) {
std::shared_lock lock(interface_mutex);
@@ -789,7 +768,7 @@ static jboolean cindResponseNative(JNIEnv* env, jobject object, jint service,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean atResponseStringNative(JNIEnv* env, jobject object,
+static jboolean atResponseStringNative(JNIEnv* env, jobject /* object */,
jstring response_str,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
@@ -814,7 +793,7 @@ static jboolean atResponseStringNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean atResponseCodeNative(JNIEnv* env, jobject object,
+static jboolean atResponseCodeNative(JNIEnv* env, jobject /* object */,
jint response_code, jint cmee_code,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
@@ -838,10 +817,10 @@ static jboolean atResponseCodeNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean clccResponseNative(JNIEnv* env, jobject object, jint index,
- jint dir, jint callStatus, jint mode,
- jboolean mpty, jstring number_str, jint type,
- jbyteArray address) {
+static jboolean clccResponseNative(JNIEnv* env, jobject /* object */,
+ jint index, jint dir, jint callStatus,
+ jint mode, jboolean mpty, jstring number_str,
+ jint type, jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
ALOGW("%s: sBluetoothHfpInterface is null", __func__);
@@ -875,7 +854,7 @@ static jboolean clccResponseNative(JNIEnv* env, jobject object, jint index,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean phoneStateChangeNative(JNIEnv* env, jobject object,
+static jboolean phoneStateChangeNative(JNIEnv* env, jobject /* object */,
jint num_active, jint num_held,
jint call_state, jstring number_str,
jint type, jstring name_str,
@@ -911,7 +890,7 @@ static jboolean phoneStateChangeNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean setScoAllowedNative(JNIEnv* env, jobject object,
+static jboolean setScoAllowedNative(JNIEnv* /* env */, jobject /* object */,
jboolean value) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
@@ -925,8 +904,8 @@ static jboolean setScoAllowedNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean sendBsirNative(JNIEnv* env, jobject object, jboolean value,
- jbyteArray address) {
+static jboolean sendBsirNative(JNIEnv* env, jobject /* object */,
+ jboolean value, jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
ALOGW("%s: sBluetoothHfpInterface is null", __func__);
@@ -947,7 +926,7 @@ static jboolean sendBsirNative(JNIEnv* env, jobject object, jboolean value,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean setActiveDeviceNative(JNIEnv* env, jobject object,
+static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpInterface) {
@@ -969,42 +948,73 @@ static jboolean setActiveDeviceNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initializeNative", "(IZ)V", (void*)initializeNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"connectHfpNative", "([B)Z", (void*)connectHfpNative},
- {"disconnectHfpNative", "([B)Z", (void*)disconnectHfpNative},
- {"connectAudioNative", "([B)Z", (void*)connectAudioNative},
- {"disconnectAudioNative", "([B)Z", (void*)disconnectAudioNative},
- {"isNoiseReductionSupportedNative", "([B)Z",
- (void*)isNoiseReductionSupportedNative},
- {"isVoiceRecognitionSupportedNative", "([B)Z",
- (void*)isVoiceRecognitionSupportedNative},
- {"startVoiceRecognitionNative", "([B)Z",
- (void*)startVoiceRecognitionNative},
- {"stopVoiceRecognitionNative", "([B)Z", (void*)stopVoiceRecognitionNative},
- {"setVolumeNative", "(II[B)Z", (void*)setVolumeNative},
- {"notifyDeviceStatusNative", "(IIII[B)Z", (void*)notifyDeviceStatusNative},
- {"copsResponseNative", "(Ljava/lang/String;[B)Z",
- (void*)copsResponseNative},
- {"cindResponseNative", "(IIIIIII[B)Z", (void*)cindResponseNative},
- {"atResponseStringNative", "(Ljava/lang/String;[B)Z",
- (void*)atResponseStringNative},
- {"atResponseCodeNative", "(II[B)Z", (void*)atResponseCodeNative},
- {"clccResponseNative", "(IIIIZLjava/lang/String;I[B)Z",
- (void*)clccResponseNative},
- {"phoneStateChangeNative", "(IIILjava/lang/String;ILjava/lang/String;[B)Z",
- (void*)phoneStateChangeNative},
- {"setScoAllowedNative", "(Z)Z", (void*)setScoAllowedNative},
- {"sendBsirNative", "(Z[B)Z", (void*)sendBsirNative},
- {"setActiveDeviceNative", "([B)Z", (void*)setActiveDeviceNative},
-};
-
int register_com_android_bluetooth_hfp(JNIEnv* env) {
- return jniRegisterNativeMethods(
- env, "com/android/bluetooth/hfp/HeadsetNativeInterface", sMethods,
- NELEM(sMethods));
+ const JNINativeMethod methods[] = {
+ {"initializeNative", "(IZ)V", (void*)initializeNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"connectHfpNative", "([B)Z", (void*)connectHfpNative},
+ {"disconnectHfpNative", "([B)Z", (void*)disconnectHfpNative},
+ {"connectAudioNative", "([B)Z", (void*)connectAudioNative},
+ {"disconnectAudioNative", "([B)Z", (void*)disconnectAudioNative},
+ {"isNoiseReductionSupportedNative", "([B)Z",
+ (void*)isNoiseReductionSupportedNative},
+ {"isVoiceRecognitionSupportedNative", "([B)Z",
+ (void*)isVoiceRecognitionSupportedNative},
+ {"startVoiceRecognitionNative", "([B)Z",
+ (void*)startVoiceRecognitionNative},
+ {"stopVoiceRecognitionNative", "([B)Z",
+ (void*)stopVoiceRecognitionNative},
+ {"setVolumeNative", "(II[B)Z", (void*)setVolumeNative},
+ {"notifyDeviceStatusNative", "(IIII[B)Z",
+ (void*)notifyDeviceStatusNative},
+ {"copsResponseNative", "(Ljava/lang/String;[B)Z",
+ (void*)copsResponseNative},
+ {"cindResponseNative", "(IIIIIII[B)Z", (void*)cindResponseNative},
+ {"atResponseStringNative", "(Ljava/lang/String;[B)Z",
+ (void*)atResponseStringNative},
+ {"atResponseCodeNative", "(II[B)Z", (void*)atResponseCodeNative},
+ {"clccResponseNative", "(IIIIZLjava/lang/String;I[B)Z",
+ (void*)clccResponseNative},
+ {"phoneStateChangeNative",
+ "(IIILjava/lang/String;ILjava/lang/String;[B)Z",
+ (void*)phoneStateChangeNative},
+ {"setScoAllowedNative", "(Z)Z", (void*)setScoAllowedNative},
+ {"sendBsirNative", "(Z[B)Z", (void*)sendBsirNative},
+ {"setActiveDeviceNative", "([B)Z", (void*)setActiveDeviceNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/hfp/HeadsetNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onConnectionStateChanged", "(I[B)V", &method_onConnectionStateChanged},
+ {"onAudioStateChanged", "(I[B)V", &method_onAudioStateChanged},
+ {"onVrStateChanged", "(I[B)V", &method_onVrStateChanged},
+ {"onAnswerCall", "([B)V", &method_onAnswerCall},
+ {"onHangupCall", "([B)V", &method_onHangupCall},
+ {"onVolumeChanged", "(II[B)V", &method_onVolumeChanged},
+ {"onDialCall", "(Ljava/lang/String;[B)V", &method_onDialCall},
+ {"onSendDtmf", "(I[B)V", &method_onSendDtmf},
+ {"onNoiseReductionEnable", "(Z[B)V", &method_onNoiseReductionEnable},
+ {"onWBS", "(I[B)V", &method_onWBS},
+ {"onSWB", "(II[B)V", &method_onSWB},
+ {"onAtChld", "(I[B)V", &method_onAtChld},
+ {"onAtCnum", "([B)V", &method_onAtCnum},
+ {"onAtCind", "([B)V", &method_onAtCind},
+ {"onAtCops", "([B)V", &method_onAtCops},
+ {"onAtClcc", "([B)V", &method_onAtClcc},
+ {"onUnknownAt", "(Ljava/lang/String;[B)V", &method_onUnknownAt},
+ {"onKeyPressed", "([B)V", &method_onKeyPressed},
+ {"onATBind", "(Ljava/lang/String;[B)V", &method_onAtBind},
+ {"onATBiev", "(II[B)V", &method_onAtBiev},
+ {"onAtBia", "(ZZZZ[B)V", &method_onAtBia},
+ };
+ GET_JAVA_METHODS(env, "com/android/bluetooth/hfp/HeadsetNativeInterface",
+ javaMethods);
+
+ return 0;
}
} /* namespace android */
diff --git a/android/app/jni/com_android_bluetooth_hfpclient.cpp b/android/app/jni/com_android_bluetooth_hfpclient.cpp
index d5756845d83163379a9b32981da60f5e99873a86..b5d5910372fc1e2bc30c483d4148d6d1ee48b3c2 100644
--- a/android/app/jni/com_android_bluetooth_hfpclient.cpp
+++ b/android/app/jni/com_android_bluetooth_hfpclient.cpp
@@ -429,42 +429,6 @@ static bthf_client_callbacks_t sBluetoothHfpClientCallbacks = {
unknown_event_cb,
};
-static void classInitNative(JNIEnv* env, jclass clazz) {
- method_onConnectionStateChanged =
- env->GetMethodID(clazz, "onConnectionStateChanged", "(III[B)V");
- method_onAudioStateChanged =
- env->GetMethodID(clazz, "onAudioStateChanged", "(I[B)V");
- method_onVrStateChanged =
- env->GetMethodID(clazz, "onVrStateChanged", "(I[B)V");
- method_onNetworkState = env->GetMethodID(clazz, "onNetworkState", "(I[B)V");
- method_onNetworkRoaming = env->GetMethodID(clazz, "onNetworkRoaming", "(I[B)V");
- method_onNetworkSignal = env->GetMethodID(clazz, "onNetworkSignal", "(I[B)V");
- method_onBatteryLevel = env->GetMethodID(clazz, "onBatteryLevel", "(I[B)V");
- method_onCurrentOperator =
- env->GetMethodID(clazz, "onCurrentOperator", "(Ljava/lang/String;[B)V");
- method_onCall = env->GetMethodID(clazz, "onCall", "(I[B)V");
- method_onCallSetup = env->GetMethodID(clazz, "onCallSetup", "(I[B)V");
- method_onCallHeld = env->GetMethodID(clazz, "onCallHeld", "(I[B)V");
- method_onRespAndHold = env->GetMethodID(clazz, "onRespAndHold", "(I[B)V");
- method_onClip = env->GetMethodID(clazz, "onClip", "(Ljava/lang/String;[B)V");
- method_onCallWaiting =
- env->GetMethodID(clazz, "onCallWaiting", "(Ljava/lang/String;[B)V");
- method_onCurrentCalls =
- env->GetMethodID(clazz, "onCurrentCalls", "(IIIILjava/lang/String;[B)V");
- method_onVolumeChange = env->GetMethodID(clazz, "onVolumeChange", "(II[B)V");
- method_onCmdResult = env->GetMethodID(clazz, "onCmdResult", "(II[B)V");
- method_onSubscriberInfo =
- env->GetMethodID(clazz, "onSubscriberInfo", "(Ljava/lang/String;I[B)V");
- method_onInBandRing = env->GetMethodID(clazz, "onInBandRing", "(I[B)V");
- method_onLastVoiceTagNumber =
- env->GetMethodID(clazz, "onLastVoiceTagNumber", "(Ljava/lang/String;[B)V");
- method_onRingIndication = env->GetMethodID(clazz, "onRingIndication", "([B)V");
- method_onUnknownEvent =
- env->GetMethodID(clazz, "onUnknownEvent", "(Ljava/lang/String;[B)V");
-
- ALOGI("%s succeeds", __func__);
-}
-
static void initializeNative(JNIEnv* env, jobject object) {
ALOGD("%s: HfpClient", __func__);
std::unique_lock interface_lock(interface_mutex);
@@ -507,7 +471,7 @@ static void initializeNative(JNIEnv* env, jobject object) {
mCallbacksObj = env->NewGlobalRef(object);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -530,7 +494,8 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static jboolean connectNative(JNIEnv* env, jobject object, jbyteArray address) {
+static jboolean connectNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -549,7 +514,7 @@ static jboolean connectNative(JNIEnv* env, jobject object, jbyteArray address) {
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean disconnectNative(JNIEnv* env, jobject object,
+static jboolean disconnectNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -569,7 +534,7 @@ static jboolean disconnectNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean connectAudioNative(JNIEnv* env, jobject object,
+static jboolean connectAudioNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -589,7 +554,7 @@ static jboolean connectAudioNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean disconnectAudioNative(JNIEnv* env, jobject object,
+static jboolean disconnectAudioNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -609,7 +574,7 @@ static jboolean disconnectAudioNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean startVoiceRecognitionNative(JNIEnv* env, jobject object,
+static jboolean startVoiceRecognitionNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -629,7 +594,7 @@ static jboolean startVoiceRecognitionNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean stopVoiceRecognitionNative(JNIEnv* env, jobject object,
+static jboolean stopVoiceRecognitionNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -649,8 +614,9 @@ static jboolean stopVoiceRecognitionNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean setVolumeNative(JNIEnv* env, jobject object, jbyteArray address,
- jint volume_type, jint volume) {
+static jboolean setVolumeNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jint volume_type,
+ jint volume) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -669,8 +635,8 @@ static jboolean setVolumeNative(JNIEnv* env, jobject object, jbyteArray address,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean dialNative(JNIEnv* env, jobject object, jbyteArray address,
- jstring number_str) {
+static jboolean dialNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jstring number_str) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -698,7 +664,7 @@ static jboolean dialNative(JNIEnv* env, jobject object, jbyteArray address,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean dialMemoryNative(JNIEnv* env, jobject object,
+static jboolean dialMemoryNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jint location) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -719,7 +685,7 @@ static jboolean dialMemoryNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean handleCallActionNative(JNIEnv* env, jobject object,
+static jboolean handleCallActionNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jint action,
jint index) {
std::shared_lock lock(interface_mutex);
@@ -741,7 +707,7 @@ static jboolean handleCallActionNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean queryCurrentCallsNative(JNIEnv* env, jobject object,
+static jboolean queryCurrentCallsNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -762,7 +728,8 @@ static jboolean queryCurrentCallsNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean queryCurrentOperatorNameNative(JNIEnv* env, jobject object,
+static jboolean queryCurrentOperatorNameNative(JNIEnv* env,
+ jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -784,7 +751,7 @@ static jboolean queryCurrentOperatorNameNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean retrieveSubscriberInfoNative(JNIEnv* env, jobject object,
+static jboolean retrieveSubscriberInfoNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -805,8 +772,8 @@ static jboolean retrieveSubscriberInfoNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean sendDtmfNative(JNIEnv* env, jobject object, jbyteArray address,
- jbyte code) {
+static jboolean sendDtmfNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jbyte code) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -826,7 +793,8 @@ static jboolean sendDtmfNative(JNIEnv* env, jobject object, jbyteArray address,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean requestLastVoiceTagNumberNative(JNIEnv* env, jobject object,
+static jboolean requestLastVoiceTagNumberNative(JNIEnv* env,
+ jobject /* object */,
jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -849,9 +817,9 @@ static jboolean requestLastVoiceTagNumberNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean sendATCmdNative(JNIEnv* env, jobject object, jbyteArray address,
- jint cmd, jint val1, jint val2,
- jstring arg_str) {
+static jboolean sendATCmdNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jint cmd, jint val1,
+ jint val2, jstring arg_str) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -880,7 +848,7 @@ static jboolean sendATCmdNative(JNIEnv* env, jobject object, jbyteArray address,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean sendAndroidAtNative(JNIEnv* env, jobject object,
+static jboolean sendAndroidAtNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jstring arg_str) {
std::shared_lock lock(interface_mutex);
if (!sBluetoothHfpClientInterface) return JNI_FALSE;
@@ -911,38 +879,72 @@ static jboolean sendAndroidAtNative(JNIEnv* env, jobject object,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initializeNative", "()V", (void*)initializeNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"connectNative", "([B)Z", (void*)connectNative},
- {"disconnectNative", "([B)Z", (void*)disconnectNative},
- {"connectAudioNative", "([B)Z", (void*)connectAudioNative},
- {"disconnectAudioNative", "([B)Z", (void*)disconnectAudioNative},
- {"startVoiceRecognitionNative", "([B)Z",
- (void*)startVoiceRecognitionNative},
- {"stopVoiceRecognitionNative", "([B)Z", (void*)stopVoiceRecognitionNative},
- {"setVolumeNative", "([BII)Z", (void*)setVolumeNative},
- {"dialNative", "([BLjava/lang/String;)Z", (void*)dialNative},
- {"dialMemoryNative", "([BI)Z", (void*)dialMemoryNative},
- {"handleCallActionNative", "([BII)Z", (void*)handleCallActionNative},
- {"queryCurrentCallsNative", "([B)Z", (void*)queryCurrentCallsNative},
- {"queryCurrentOperatorNameNative", "([B)Z",
- (void*)queryCurrentOperatorNameNative},
- {"retrieveSubscriberInfoNative", "([B)Z",
- (void*)retrieveSubscriberInfoNative},
- {"sendDtmfNative", "([BB)Z", (void*)sendDtmfNative},
- {"requestLastVoiceTagNumberNative", "([B)Z",
- (void*)requestLastVoiceTagNumberNative},
- {"sendATCmdNative", "([BIIILjava/lang/String;)Z", (void*)sendATCmdNative},
- {"sendAndroidAtNative", "([BLjava/lang/String;)Z",
- (void*)sendAndroidAtNative},
-};
-
int register_com_android_bluetooth_hfpclient(JNIEnv* env) {
- return jniRegisterNativeMethods(
- env, "com/android/bluetooth/hfpclient/NativeInterface",
- sMethods, NELEM(sMethods));
+ const JNINativeMethod methods[] = {
+ {"initializeNative", "()V", (void*)initializeNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"connectNative", "([B)Z", (void*)connectNative},
+ {"disconnectNative", "([B)Z", (void*)disconnectNative},
+ {"connectAudioNative", "([B)Z", (void*)connectAudioNative},
+ {"disconnectAudioNative", "([B)Z", (void*)disconnectAudioNative},
+ {"startVoiceRecognitionNative", "([B)Z",
+ (void*)startVoiceRecognitionNative},
+ {"stopVoiceRecognitionNative", "([B)Z",
+ (void*)stopVoiceRecognitionNative},
+ {"setVolumeNative", "([BII)Z", (void*)setVolumeNative},
+ {"dialNative", "([BLjava/lang/String;)Z", (void*)dialNative},
+ {"dialMemoryNative", "([BI)Z", (void*)dialMemoryNative},
+ {"handleCallActionNative", "([BII)Z", (void*)handleCallActionNative},
+ {"queryCurrentCallsNative", "([B)Z", (void*)queryCurrentCallsNative},
+ {"queryCurrentOperatorNameNative", "([B)Z",
+ (void*)queryCurrentOperatorNameNative},
+ {"retrieveSubscriberInfoNative", "([B)Z",
+ (void*)retrieveSubscriberInfoNative},
+ {"sendDtmfNative", "([BB)Z", (void*)sendDtmfNative},
+ {"requestLastVoiceTagNumberNative", "([B)Z",
+ (void*)requestLastVoiceTagNumberNative},
+ {"sendATCmdNative", "([BIIILjava/lang/String;)Z", (void*)sendATCmdNative},
+ {"sendAndroidAtNative", "([BLjava/lang/String;)Z",
+ (void*)sendAndroidAtNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/hfpclient/NativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onConnectionStateChanged", "(III[B)V",
+ &method_onConnectionStateChanged},
+ {"onAudioStateChanged", "(I[B)V", &method_onAudioStateChanged},
+ {"onVrStateChanged", "(I[B)V", &method_onVrStateChanged},
+ {"onNetworkState", "(I[B)V", &method_onNetworkState},
+ {"onNetworkRoaming", "(I[B)V", &method_onNetworkRoaming},
+ {"onNetworkSignal", "(I[B)V", &method_onNetworkSignal},
+ {"onBatteryLevel", "(I[B)V", &method_onBatteryLevel},
+ {"onCurrentOperator", "(Ljava/lang/String;[B)V",
+ &method_onCurrentOperator},
+ {"onCall", "(I[B)V", &method_onCall},
+ {"onCallSetup", "(I[B)V", &method_onCallSetup},
+ {"onCallHeld", "(I[B)V", &method_onCallHeld},
+ {"onRespAndHold", "(I[B)V", &method_onRespAndHold},
+ {"onClip", "(Ljava/lang/String;[B)V", &method_onClip},
+ {"onCallWaiting", "(Ljava/lang/String;[B)V", &method_onCallWaiting},
+ {"onCurrentCalls", "(IIIILjava/lang/String;[B)V", &method_onCurrentCalls},
+ {"onVolumeChange", "(II[B)V", &method_onVolumeChange},
+ {"onCmdResult", "(II[B)V", &method_onCmdResult},
+ {"onSubscriberInfo", "(Ljava/lang/String;I[B)V",
+ &method_onSubscriberInfo},
+ {"onInBandRing", "(I[B)V", &method_onInBandRing},
+ {"onLastVoiceTagNumber", "(Ljava/lang/String;[B)V",
+ &method_onLastVoiceTagNumber},
+ {"onRingIndication", "([B)V", &method_onRingIndication},
+ {"onUnknownEvent", "(Ljava/lang/String;[B)V", &method_onUnknownEvent},
+ };
+ GET_JAVA_METHODS(env, "com/android/bluetooth/hfpclient/NativeInterface",
+ javaMethods);
+
+ return 0;
}
} /* namespace android */
diff --git a/android/app/jni/com_android_bluetooth_hid_device.cpp b/android/app/jni/com_android_bluetooth_hid_device.cpp
index 2146222acdb48f5c1e5849747b9646f95c9149d8..4a7c1553e1f45799ad12ac5b4f1e332909222302 100644
--- a/android/app/jni/com_android_bluetooth_hid_device.cpp
+++ b/android/app/jni/com_android_bluetooth_hid_device.cpp
@@ -150,21 +150,6 @@ static bthd_callbacks_t sHiddCb = {
vc_unplug_callback,
};
-static void classInitNative(JNIEnv* env, jclass clazz) {
- ALOGV("%s: done", __FUNCTION__);
-
- method_onApplicationStateChanged =
- env->GetMethodID(clazz, "onApplicationStateChanged", "([BZ)V");
- method_onConnectStateChanged =
- env->GetMethodID(clazz, "onConnectStateChanged", "([BI)V");
- method_onGetReport = env->GetMethodID(clazz, "onGetReport", "(BBS)V");
- method_onSetReport = env->GetMethodID(clazz, "onSetReport", "(BB[B)V");
- method_onSetProtocol = env->GetMethodID(clazz, "onSetProtocol", "(B)V");
- method_onInterruptData = env->GetMethodID(clazz, "onInterruptData", "(B[B)V");
- method_onVirtualCableUnplug =
- env->GetMethodID(clazz, "onVirtualCableUnplug", "()V");
-}
-
static void initNative(JNIEnv* env, jobject object) {
const bt_interface_t* btif;
bt_status_t status;
@@ -205,7 +190,7 @@ static void initNative(JNIEnv* env, jobject object) {
ALOGV("%s done", __FUNCTION__);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
ALOGV("%s enter", __FUNCTION__);
if (sHiddIf != NULL) {
@@ -252,7 +237,7 @@ static void fill_qos(JNIEnv* env, jintArray in, bthd_qos_param_t* out) {
free(buf);
}
-static jboolean registerAppNative(JNIEnv* env, jobject thiz, jstring name,
+static jboolean registerAppNative(JNIEnv* env, jobject /* thiz */, jstring name,
jstring description, jstring provider,
jbyte subclass, jbyteArray descriptors,
jintArray p_in_qos, jintArray p_out_qos) {
@@ -306,7 +291,7 @@ static jboolean registerAppNative(JNIEnv* env, jobject thiz, jstring name,
return result;
}
-static jboolean unregisterAppNative(JNIEnv* env, jobject thiz) {
+static jboolean unregisterAppNative(JNIEnv* /* env */, jobject /* thiz */) {
ALOGV("%s enter", __FUNCTION__);
jboolean result = JNI_FALSE;
@@ -329,7 +314,7 @@ static jboolean unregisterAppNative(JNIEnv* env, jobject thiz) {
return result;
}
-static jboolean sendReportNative(JNIEnv* env, jobject thiz, jint id,
+static jboolean sendReportNative(JNIEnv* env, jobject /* thiz */, jint id,
jbyteArray data) {
jboolean result = JNI_FALSE;
@@ -360,7 +345,7 @@ static jboolean sendReportNative(JNIEnv* env, jobject thiz, jint id,
return result;
}
-static jboolean replyReportNative(JNIEnv* env, jobject thiz, jbyte type,
+static jboolean replyReportNative(JNIEnv* env, jobject /* thiz */, jbyte type,
jbyte id, jbyteArray data) {
ALOGV("%s enter", __FUNCTION__);
@@ -397,7 +382,8 @@ static jboolean replyReportNative(JNIEnv* env, jobject thiz, jbyte type,
return result;
}
-static jboolean reportErrorNative(JNIEnv* env, jobject thiz, jbyte error) {
+static jboolean reportErrorNative(JNIEnv* /* env */, jobject /* thiz */,
+ jbyte error) {
ALOGV("%s enter", __FUNCTION__);
if (!sHiddIf) {
@@ -420,7 +406,7 @@ static jboolean reportErrorNative(JNIEnv* env, jobject thiz, jbyte error) {
return result;
}
-static jboolean unplugNative(JNIEnv* env, jobject thiz) {
+static jboolean unplugNative(JNIEnv* /* env */, jobject /* thiz */) {
ALOGV("%s enter", __FUNCTION__);
if (!sHiddIf) {
@@ -443,7 +429,8 @@ static jboolean unplugNative(JNIEnv* env, jobject thiz) {
return result;
}
-static jboolean connectNative(JNIEnv* env, jobject thiz, jbyteArray address) {
+static jboolean connectNative(JNIEnv* env, jobject /* thiz */,
+ jbyteArray address) {
ALOGV("%s enter", __FUNCTION__);
if (!sHiddIf) {
@@ -472,7 +459,7 @@ static jboolean connectNative(JNIEnv* env, jobject thiz, jbyteArray address) {
return result;
}
-static jboolean disconnectNative(JNIEnv* env, jobject thiz) {
+static jboolean disconnectNative(JNIEnv* /* env */, jobject /* thiz */) {
ALOGV("%s enter", __FUNCTION__);
if (!sHiddIf) {
@@ -495,25 +482,40 @@ static jboolean disconnectNative(JNIEnv* env, jobject thiz) {
return result;
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative", "()V", (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"registerAppNative",
- "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;B[B[I[I)Z",
- (void*)registerAppNative},
- {"unregisterAppNative", "()Z", (void*)unregisterAppNative},
- {"sendReportNative", "(I[B)Z", (void*)sendReportNative},
- {"replyReportNative", "(BB[B)Z", (void*)replyReportNative},
- {"reportErrorNative", "(B)Z", (void*)reportErrorNative},
- {"unplugNative", "()Z", (void*)unplugNative},
- {"connectNative", "([B)Z", (void*)connectNative},
- {"disconnectNative", "()Z", (void*)disconnectNative},
-};
-
int register_com_android_bluetooth_hid_device(JNIEnv* env) {
- return jniRegisterNativeMethods(
- env, "com/android/bluetooth/hid/HidDeviceNativeInterface", sMethods,
- NELEM(sMethods));
+ const JNINativeMethod methods[] = {
+ {"initNative", "()V", (void*)initNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"registerAppNative",
+ "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;B[B[I[I)Z",
+ (void*)registerAppNative},
+ {"unregisterAppNative", "()Z", (void*)unregisterAppNative},
+ {"sendReportNative", "(I[B)Z", (void*)sendReportNative},
+ {"replyReportNative", "(BB[B)Z", (void*)replyReportNative},
+ {"reportErrorNative", "(B)Z", (void*)reportErrorNative},
+ {"unplugNative", "()Z", (void*)unplugNative},
+ {"connectNative", "([B)Z", (void*)connectNative},
+ {"disconnectNative", "()Z", (void*)disconnectNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/hid/HidDeviceNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onApplicationStateChanged", "([BZ)V",
+ &method_onApplicationStateChanged},
+ {"onConnectStateChanged", "([BI)V", &method_onConnectStateChanged},
+ {"onGetReport", "(BBS)V", &method_onGetReport},
+ {"onSetReport", "(BB[B)V", &method_onSetReport},
+ {"onSetProtocol", "(B)V", &method_onSetProtocol},
+ {"onInterruptData", "(B[B)V", &method_onInterruptData},
+ {"onVirtualCableUnplug", "()V", &method_onVirtualCableUnplug},
+ };
+ GET_JAVA_METHODS(env, "com/android/bluetooth/hid/HidDeviceNativeInterface",
+ javaMethods);
+
+ return 0;
}
} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_hid_host.cpp b/android/app/jni/com_android_bluetooth_hid_host.cpp
index 7a164233bc1b5d7e315691c80f0e5364db3b3666..e89ce844c29a069b47dcb90dfb7c7ebdbde3661a 100644
--- a/android/app/jni/com_android_bluetooth_hid_host.cpp
+++ b/android/app/jni/com_android_bluetooth_hid_host.cpp
@@ -161,7 +161,8 @@ static void handshake_callback(RawAddress* bd_addr, bthh_status_t hh_status) {
(jint)hh_status);
}
-static void get_idle_time_callback(RawAddress* bd_addr, bthh_status_t hh_status,
+static void get_idle_time_callback(RawAddress* bd_addr,
+ bthh_status_t /* hh_status */,
int idle_time) {
std::shared_lock lock(mCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
@@ -187,20 +188,6 @@ static bthh_callbacks_t sBluetoothHidCallbacks = {
handshake_callback};
// Define native functions
-
-static void classInitNative(JNIEnv* env, jclass clazz) {
- method_onConnectStateChanged =
- env->GetMethodID(clazz, "onConnectStateChanged", "([BI)V");
- method_onGetProtocolMode =
- env->GetMethodID(clazz, "onGetProtocolMode", "([BI)V");
- method_onGetReport = env->GetMethodID(clazz, "onGetReport", "([B[BI)V");
- method_onHandshake = env->GetMethodID(clazz, "onHandshake", "([BI)V");
- method_onVirtualUnplug = env->GetMethodID(clazz, "onVirtualUnplug", "([BI)V");
- method_onGetIdleTime = env->GetMethodID(clazz, "onGetIdleTime", "([BI)V");
-
- ALOGI("%s: succeeds", __func__);
-}
-
static void initializeNative(JNIEnv* env, jobject object) {
std::unique_lock lock(mCallbacks_mutex);
const bt_interface_t* btInf = getBluetoothInterface();
@@ -238,7 +225,7 @@ static void initializeNative(JNIEnv* env, jobject object) {
mCallbacksObj = env->NewGlobalRef(object);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock lock(mCallbacks_mutex);
const bt_interface_t* btInf = getBluetoothInterface();
@@ -260,7 +247,7 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static jboolean connectHidNative(JNIEnv* env, jobject object,
+static jboolean connectHidNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
if (!sBluetoothHidInterface) return JNI_FALSE;
@@ -281,7 +268,7 @@ static jboolean connectHidNative(JNIEnv* env, jobject object,
return ret;
}
-static jboolean disconnectHidNative(JNIEnv* env, jobject object,
+static jboolean disconnectHidNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
jbyte* addr;
jboolean ret = JNI_TRUE;
@@ -303,7 +290,7 @@ static jboolean disconnectHidNative(JNIEnv* env, jobject object,
return ret;
}
-static jboolean getProtocolModeNative(JNIEnv* env, jobject object,
+static jboolean getProtocolModeNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
if (!sBluetoothHidInterface) return JNI_FALSE;
@@ -327,7 +314,7 @@ static jboolean getProtocolModeNative(JNIEnv* env, jobject object,
return ret;
}
-static jboolean virtualUnPlugNative(JNIEnv* env, jobject object,
+static jboolean virtualUnPlugNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
if (!sBluetoothHidInterface) return JNI_FALSE;
@@ -348,7 +335,7 @@ static jboolean virtualUnPlugNative(JNIEnv* env, jobject object,
return ret;
}
-static jboolean setProtocolModeNative(JNIEnv* env, jobject object,
+static jboolean setProtocolModeNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jint protocolMode) {
if (!sBluetoothHidInterface) return JNI_FALSE;
@@ -385,9 +372,9 @@ static jboolean setProtocolModeNative(JNIEnv* env, jobject object,
return ret;
}
-static jboolean getReportNative(JNIEnv* env, jobject object, jbyteArray address,
- jbyte reportType, jbyte reportId,
- jint bufferSize) {
+static jboolean getReportNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jbyte reportType,
+ jbyte reportId, jint bufferSize) {
ALOGV("%s: reportType = %d, reportId = %d, bufferSize = %d", __func__,
reportType, reportId, bufferSize);
if (!sBluetoothHidInterface) return JNI_FALSE;
@@ -413,8 +400,9 @@ static jboolean getReportNative(JNIEnv* env, jobject object, jbyteArray address,
return ret;
}
-static jboolean setReportNative(JNIEnv* env, jobject object, jbyteArray address,
- jbyte reportType, jstring report) {
+static jboolean setReportNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jbyte reportType,
+ jstring report) {
ALOGV("%s: reportType = %d", __func__, reportType);
if (!sBluetoothHidInterface) return JNI_FALSE;
@@ -439,8 +427,8 @@ static jboolean setReportNative(JNIEnv* env, jobject object, jbyteArray address,
return ret;
}
-static jboolean sendDataNative(JNIEnv* env, jobject object, jbyteArray address,
- jstring report) {
+static jboolean sendDataNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jstring report) {
ALOGV("%s", __func__);
jboolean ret = JNI_TRUE;
if (!sBluetoothHidInterface) return JNI_FALSE;
@@ -465,7 +453,7 @@ static jboolean sendDataNative(JNIEnv* env, jobject object, jbyteArray address,
return ret;
}
-static jboolean getIdleTimeNative(JNIEnv* env, jobject object,
+static jboolean getIdleTimeNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
if (!sBluetoothHidInterface) return JNI_FALSE;
@@ -484,7 +472,7 @@ static jboolean getIdleTimeNative(JNIEnv* env, jobject object,
return status == BT_STATUS_SUCCESS ? JNI_TRUE : JNI_FALSE;
}
-static jboolean setIdleTimeNative(JNIEnv* env, jobject object,
+static jboolean setIdleTimeNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jbyte idle_time) {
if (!sBluetoothHidInterface) return JNI_FALSE;
@@ -504,25 +492,39 @@ static jboolean setIdleTimeNative(JNIEnv* env, jobject object,
return status == BT_STATUS_SUCCESS ? JNI_TRUE : JNI_FALSE;
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initializeNative", "()V", (void*)initializeNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"connectHidNative", "([B)Z", (void*)connectHidNative},
- {"disconnectHidNative", "([B)Z", (void*)disconnectHidNative},
- {"getProtocolModeNative", "([B)Z", (void*)getProtocolModeNative},
- {"virtualUnPlugNative", "([B)Z", (void*)virtualUnPlugNative},
- {"setProtocolModeNative", "([BB)Z", (void*)setProtocolModeNative},
- {"getReportNative", "([BBBI)Z", (void*)getReportNative},
- {"setReportNative", "([BBLjava/lang/String;)Z", (void*)setReportNative},
- {"sendDataNative", "([BLjava/lang/String;)Z", (void*)sendDataNative},
- {"getIdleTimeNative", "([B)Z", (void*)getIdleTimeNative},
- {"setIdleTimeNative", "([BB)Z", (void*)setIdleTimeNative},
-};
-
int register_com_android_bluetooth_hid_host(JNIEnv* env) {
- return jniRegisterNativeMethods(env,
- "com/android/bluetooth/hid/HidHostService",
- sMethods, NELEM(sMethods));
+ const JNINativeMethod methods[] = {
+ {"initializeNative", "()V", (void*)initializeNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"connectHidNative", "([B)Z", (void*)connectHidNative},
+ {"disconnectHidNative", "([B)Z", (void*)disconnectHidNative},
+ {"getProtocolModeNative", "([B)Z", (void*)getProtocolModeNative},
+ {"virtualUnPlugNative", "([B)Z", (void*)virtualUnPlugNative},
+ {"setProtocolModeNative", "([BB)Z", (void*)setProtocolModeNative},
+ {"getReportNative", "([BBBI)Z", (void*)getReportNative},
+ {"setReportNative", "([BBLjava/lang/String;)Z", (void*)setReportNative},
+ {"sendDataNative", "([BLjava/lang/String;)Z", (void*)sendDataNative},
+ {"getIdleTimeNative", "([B)Z", (void*)getIdleTimeNative},
+ {"setIdleTimeNative", "([BB)Z", (void*)setIdleTimeNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/hid/HidHostNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onConnectStateChanged", "([BI)V", &method_onConnectStateChanged},
+ {"onGetProtocolMode", "([BI)V", &method_onGetProtocolMode},
+ {"onGetReport", "([B[BI)V", &method_onGetReport},
+ {"onHandshake", "([BI)V", &method_onHandshake},
+ {"onVirtualUnplug", "([BI)V", &method_onVirtualUnplug},
+ {"onGetIdleTime", "([BI)V", &method_onGetIdleTime},
+ };
+ GET_JAVA_METHODS(env, "com/android/bluetooth/hid/HidHostNativeInterface",
+ javaMethods);
+
+ return 0;
}
+
} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_le_audio.cpp b/android/app/jni/com_android_bluetooth_le_audio.cpp
index e69bb25fdd4ec118093e22e8eaa304821cc52b5e..e6f07c48f5b6b720e1e722419bf243f2c2c94b89 100644
--- a/android/app/jni/com_android_bluetooth_le_audio.cpp
+++ b/android/app/jni/com_android_bluetooth_le_audio.cpp
@@ -27,8 +27,12 @@
using bluetooth::le_audio::BroadcastId;
using bluetooth::le_audio::BroadcastState;
+using bluetooth::le_audio::btle_audio_bits_per_sample_index_t;
+using bluetooth::le_audio::btle_audio_channel_count_index_t;
using bluetooth::le_audio::btle_audio_codec_config_t;
using bluetooth::le_audio::btle_audio_codec_index_t;
+using bluetooth::le_audio::btle_audio_frame_duration_index_t;
+using bluetooth::le_audio::btle_audio_sample_rate_index_t;
using bluetooth::le_audio::ConnectionState;
using bluetooth::le_audio::GroupNodeStatus;
using bluetooth::le_audio::GroupStatus;
@@ -36,6 +40,7 @@ using bluetooth::le_audio::LeAudioBroadcasterCallbacks;
using bluetooth::le_audio::LeAudioBroadcasterInterface;
using bluetooth::le_audio::LeAudioClientCallbacks;
using bluetooth::le_audio::LeAudioClientInterface;
+using bluetooth::le_audio::UnicastMonitorModeStatus;
namespace android {
static jmethodID method_onInitialized;
@@ -45,12 +50,22 @@ static jmethodID method_onGroupNodeStatus;
static jmethodID method_onAudioConf;
static jmethodID method_onSinkAudioLocationAvailable;
static jmethodID method_onAudioLocalCodecCapabilities;
-static jmethodID method_onAudioGroupCodecConf;
+static jmethodID method_onAudioGroupCurrentCodecConf;
+static jmethodID method_onAudioGroupSelectableCodecConf;
+static jmethodID method_onHealthBasedRecommendationAction;
+static jmethodID method_onHealthBasedGroupRecommendationAction;
+static jmethodID method_onUnicastMonitorModeStatus;
static struct {
jclass clazz;
jmethodID constructor;
jmethodID getCodecType;
+ jmethodID getSampleRate;
+ jmethodID getBitsPerSample;
+ jmethodID getChannelCount;
+ jmethodID getFrameDuration;
+ jmethodID getOctetsPerFrame;
+ jmethodID getCodecPriority;
} android_bluetooth_BluetoothLeAudioCodecConfig;
static struct {
@@ -97,10 +112,21 @@ static std::shared_timed_mutex callbacks_mutex;
jobject prepareCodecConfigObj(JNIEnv* env,
btle_audio_codec_config_t codecConfig) {
- jobject codecConfigObj =
- env->NewObject(android_bluetooth_BluetoothLeAudioCodecConfig.clazz,
- android_bluetooth_BluetoothLeAudioCodecConfig.constructor,
- (jint)codecConfig.codec_type, 0, 0, 0, 0, 0, 0, 0, 0);
+ LOG(INFO) << __func__ << "ct: " << codecConfig.codec_type
+ << ", codec_priority: " << codecConfig.codec_priority
+ << ", sample_rate: " << codecConfig.sample_rate
+ << ", bits_per_sample: " << codecConfig.bits_per_sample
+ << ", channel_count: " << codecConfig.channel_count
+ << ", frame_duration: " << codecConfig.frame_duration
+ << ", octets_per_frame: " << codecConfig.octets_per_frame;
+
+ jobject codecConfigObj = env->NewObject(
+ android_bluetooth_BluetoothLeAudioCodecConfig.clazz,
+ android_bluetooth_BluetoothLeAudioCodecConfig.constructor,
+ (jint)codecConfig.codec_type, (jint)codecConfig.codec_priority,
+ (jint)codecConfig.sample_rate, (jint)codecConfig.bits_per_sample,
+ (jint)codecConfig.channel_count, (jint)codecConfig.frame_duration,
+ (jint)codecConfig.octets_per_frame, 0, 0);
return codecConfigObj;
}
@@ -135,7 +161,8 @@ class LeAudioClientCallbacksImpl : public LeAudioClientCallbacks {
void OnConnectionState(ConnectionState state,
const RawAddress& bd_addr) override {
- LOG(INFO) << __func__ << ", state:" << int(state);
+ LOG(INFO) << __func__ << ", state:" << int(state)
+ << ", addr: " << bd_addr.ToRedactedStringForLogging();
std::shared_lock lock(callbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
@@ -244,12 +271,9 @@ class LeAudioClientCallbacksImpl : public LeAudioClientCallbacks {
localInputCapCodecConfigArray, localOutputCapCodecConfigArray);
}
- void OnAudioGroupCodecConf(
+ void OnAudioGroupCurrentCodecConf(
int group_id, btle_audio_codec_config_t input_codec_conf,
- btle_audio_codec_config_t output_codec_conf,
- std::vector input_selectable_codec_conf,
- std::vector output_selectable_codec_conf)
- override {
+ btle_audio_codec_config_t output_codec_conf) override {
LOG(INFO) << __func__;
std::shared_lock lock(callbacks_mutex);
@@ -259,52 +283,89 @@ class LeAudioClientCallbacksImpl : public LeAudioClientCallbacks {
jobject inputCodecConfigObj =
prepareCodecConfigObj(sCallbackEnv.get(), input_codec_conf);
jobject outputCodecConfigObj =
- prepareCodecConfigObj(sCallbackEnv.get(), input_codec_conf);
+ prepareCodecConfigObj(sCallbackEnv.get(), output_codec_conf);
+
+ sCallbackEnv->CallVoidMethod(
+ mCallbacksObj, method_onAudioGroupCurrentCodecConf, (jint)group_id,
+ inputCodecConfigObj, outputCodecConfigObj);
+ }
+
+ void OnAudioGroupSelectableCodecConf(
+ int group_id,
+ std::vector input_selectable_codec_conf,
+ std::vector output_selectable_codec_conf)
+ override {
+ LOG(INFO) << __func__;
+
+ std::shared_lock lock(callbacks_mutex);
+ CallbackEnv sCallbackEnv(__func__);
+ if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) return;
+
jobject inputSelectableCodecConfigArray = prepareArrayOfCodecConfigs(
sCallbackEnv.get(), input_selectable_codec_conf);
jobject outputSelectableCodecConfigArray = prepareArrayOfCodecConfigs(
sCallbackEnv.get(), output_selectable_codec_conf);
sCallbackEnv->CallVoidMethod(
- mCallbacksObj, method_onAudioGroupCodecConf, (jint)group_id,
- inputCodecConfigObj, outputCodecConfigObj,
+ mCallbacksObj, method_onAudioGroupSelectableCodecConf, (jint)group_id,
inputSelectableCodecConfigArray, outputSelectableCodecConfigArray);
}
+
+ void OnHealthBasedRecommendationAction(
+ const RawAddress& bd_addr,
+ bluetooth::le_audio::LeAudioHealthBasedAction action) override {
+ LOG(INFO) << __func__;
+
+ std::shared_lock lock(callbacks_mutex);
+ CallbackEnv sCallbackEnv(__func__);
+ if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) return;
+
+ ScopedLocalRef addr(
+ sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ if (!addr.get()) {
+ LOG(ERROR) << "Failed to new jbyteArray bd addr for group status";
+ return;
+ }
+
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
+ (jbyte*)&bd_addr);
+ sCallbackEnv->CallVoidMethod(mCallbacksObj,
+ method_onHealthBasedRecommendationAction,
+ addr.get(), (jint)action);
+ }
+
+ void OnHealthBasedGroupRecommendationAction(
+ int group_id,
+ bluetooth::le_audio::LeAudioHealthBasedAction action) override {
+ LOG(INFO) << __func__;
+
+ std::shared_lock lock(callbacks_mutex);
+ CallbackEnv sCallbackEnv(__func__);
+ if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) return;
+
+ sCallbackEnv->CallVoidMethod(mCallbacksObj,
+ method_onHealthBasedGroupRecommendationAction,
+ (jint)group_id, (jint)action);
+ }
+
+ void OnUnicastMonitorModeStatus(uint8_t direction,
+ UnicastMonitorModeStatus status) override {
+ LOG(INFO) << __func__;
+
+ std::shared_lock lock(callbacks_mutex);
+ CallbackEnv sCallbackEnv(__func__);
+ if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) return;
+
+ sCallbackEnv->CallVoidMethod(mCallbacksObj,
+ method_onUnicastMonitorModeStatus,
+ (jint)direction, (jint)status);
+ }
};
static LeAudioClientCallbacksImpl sLeAudioClientCallbacks;
-static void classInitNative(JNIEnv* env, jclass clazz) {
- jclass jniBluetoothLeAudioCodecConfigClass =
- env->FindClass("android/bluetooth/BluetoothLeAudioCodecConfig");
- android_bluetooth_BluetoothLeAudioCodecConfig.constructor = env->GetMethodID(
- jniBluetoothLeAudioCodecConfigClass, "", "(IIIIIIIII)V");
- android_bluetooth_BluetoothLeAudioCodecConfig.getCodecType = env->GetMethodID(
- jniBluetoothLeAudioCodecConfigClass, "getCodecType", "()I");
-
- method_onGroupStatus = env->GetMethodID(clazz, "onGroupStatus", "(II)V");
- method_onGroupNodeStatus =
- env->GetMethodID(clazz, "onGroupNodeStatus", "([BII)V");
- method_onAudioConf = env->GetMethodID(clazz, "onAudioConf", "(IIIII)V");
- method_onSinkAudioLocationAvailable =
- env->GetMethodID(clazz, "onSinkAudioLocationAvailable", "([BI)V");
- method_onInitialized = env->GetMethodID(clazz, "onInitialized", "()V");
- method_onConnectionStateChanged =
- env->GetMethodID(clazz, "onConnectionStateChanged", "(I[B)V");
- method_onAudioLocalCodecCapabilities =
- env->GetMethodID(clazz, "onAudioLocalCodecCapabilities",
- "([Landroid/bluetooth/BluetoothLeAudioCodecConfig;"
- "[Landroid/bluetooth/BluetoothLeAudioCodecConfig;)V");
- method_onAudioGroupCodecConf =
- env->GetMethodID(clazz, "onAudioGroupCodecConf",
- "(ILandroid/bluetooth/BluetoothLeAudioCodecConfig;"
- "Landroid/bluetooth/BluetoothLeAudioCodecConfig;"
- "[Landroid/bluetooth/BluetoothLeAudioCodecConfig;"
- "[Landroid/bluetooth/BluetoothLeAudioCodecConfig;)V");
-}
-
std::vector prepareCodecPreferences(
- JNIEnv* env, jobject object, jobjectArray codecConfigArray) {
+ JNIEnv* env, jobject /* object */, jobjectArray codecConfigArray) {
std::vector codec_preferences;
int numConfigs = env->GetArrayLength(codecConfigArray);
@@ -375,7 +436,7 @@ static void initNative(JNIEnv* env, jobject object,
codec_offloading);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -399,7 +460,7 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static jboolean connectLeAudioNative(JNIEnv* env, jobject object,
+static jboolean connectLeAudioNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
LOG(INFO) << __func__;
std::shared_lock lock(interface_mutex);
@@ -417,7 +478,7 @@ static jboolean connectLeAudioNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static jboolean disconnectLeAudioNative(JNIEnv* env, jobject object,
+static jboolean disconnectLeAudioNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
LOG(INFO) << __func__;
std::shared_lock lock(interface_mutex);
@@ -435,7 +496,7 @@ static jboolean disconnectLeAudioNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static jboolean setEnableStateNative(JNIEnv* env, jobject object,
+static jboolean setEnableStateNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jboolean enabled) {
std::shared_lock lock(interface_mutex);
jbyte* addr = env->GetByteArrayElements(address, nullptr);
@@ -456,8 +517,8 @@ static jboolean setEnableStateNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static jboolean groupAddNodeNative(JNIEnv* env, jobject object, jint group_id,
- jbyteArray address) {
+static jboolean groupAddNodeNative(JNIEnv* env, jobject /* object */,
+ jint group_id, jbyteArray address) {
std::shared_lock lock(interface_mutex);
jbyte* addr = env->GetByteArrayElements(address, nullptr);
@@ -478,7 +539,7 @@ static jboolean groupAddNodeNative(JNIEnv* env, jobject object, jint group_id,
return JNI_TRUE;
}
-static jboolean groupRemoveNodeNative(JNIEnv* env, jobject object,
+static jboolean groupRemoveNodeNative(JNIEnv* env, jobject /* object */,
jint group_id, jbyteArray address) {
std::shared_lock lock(interface_mutex);
if (!sLeAudioClientInterface) {
@@ -498,7 +559,8 @@ static jboolean groupRemoveNodeNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static void groupSetActiveNative(JNIEnv* env, jobject object, jint group_id) {
+static void groupSetActiveNative(JNIEnv* /* env */, jobject /* object */,
+ jint group_id) {
LOG(INFO) << __func__;
std::shared_lock lock(interface_mutex);
@@ -510,7 +572,7 @@ static void groupSetActiveNative(JNIEnv* env, jobject object, jint group_id) {
sLeAudioClientInterface->GroupSetActive(group_id);
}
-static void setCodecConfigPreferenceNative(JNIEnv* env, jobject object,
+static void setCodecConfigPreferenceNative(JNIEnv* env, jobject /* object */,
jint group_id,
jobject inputCodecConfig,
jobject outputCodecConfig) {
@@ -528,22 +590,92 @@ static void setCodecConfigPreferenceNative(JNIEnv* env, jobject object,
inputCodecConfig,
android_bluetooth_BluetoothLeAudioCodecConfig.getCodecType);
+ jint inputSampleRate = env->CallIntMethod(
+ inputCodecConfig,
+ android_bluetooth_BluetoothLeAudioCodecConfig.getSampleRate);
+
+ jint inputBitsPerSample = env->CallIntMethod(
+ inputCodecConfig,
+ android_bluetooth_BluetoothLeAudioCodecConfig.getBitsPerSample);
+
+ jint inputChannelCount = env->CallIntMethod(
+ inputCodecConfig,
+ android_bluetooth_BluetoothLeAudioCodecConfig.getChannelCount);
+
+ jint inputFrameDuration = env->CallIntMethod(
+ inputCodecConfig,
+ android_bluetooth_BluetoothLeAudioCodecConfig.getFrameDuration);
+
+ jint inputOctetsPerFrame = env->CallIntMethod(
+ inputCodecConfig,
+ android_bluetooth_BluetoothLeAudioCodecConfig.getOctetsPerFrame);
+
+ jint inputCodecPriority = env->CallIntMethod(
+ inputCodecConfig,
+ android_bluetooth_BluetoothLeAudioCodecConfig.getCodecPriority);
+
btle_audio_codec_config_t input_codec_config = {
- .codec_type = static_cast(inputCodecType)};
+ .codec_type = static_cast(inputCodecType),
+ .sample_rate =
+ static_cast(inputSampleRate),
+ .bits_per_sample =
+ static_cast(inputBitsPerSample),
+ .channel_count =
+ static_cast(inputChannelCount),
+ .frame_duration =
+ static_cast(inputFrameDuration),
+ .octets_per_frame = static_cast(inputOctetsPerFrame),
+ .codec_priority = static_cast(inputCodecPriority),
+ };
jint outputCodecType = env->CallIntMethod(
outputCodecConfig,
android_bluetooth_BluetoothLeAudioCodecConfig.getCodecType);
+ jint outputSampleRate = env->CallIntMethod(
+ outputCodecConfig,
+ android_bluetooth_BluetoothLeAudioCodecConfig.getSampleRate);
+
+ jint outputBitsPerSample = env->CallIntMethod(
+ outputCodecConfig,
+ android_bluetooth_BluetoothLeAudioCodecConfig.getBitsPerSample);
+
+ jint outputChannelCount = env->CallIntMethod(
+ outputCodecConfig,
+ android_bluetooth_BluetoothLeAudioCodecConfig.getChannelCount);
+
+ jint outputFrameDuration = env->CallIntMethod(
+ outputCodecConfig,
+ android_bluetooth_BluetoothLeAudioCodecConfig.getFrameDuration);
+
+ jint outputOctetsPerFrame = env->CallIntMethod(
+ outputCodecConfig,
+ android_bluetooth_BluetoothLeAudioCodecConfig.getOctetsPerFrame);
+
+ jint outputCodecPriority = env->CallIntMethod(
+ outputCodecConfig,
+ android_bluetooth_BluetoothLeAudioCodecConfig.getCodecPriority);
+
btle_audio_codec_config_t output_codec_config = {
- .codec_type = static_cast(outputCodecType)};
+ .codec_type = static_cast(outputCodecType),
+ .sample_rate =
+ static_cast(outputSampleRate),
+ .bits_per_sample =
+ static_cast(outputBitsPerSample),
+ .channel_count =
+ static_cast(outputChannelCount),
+ .frame_duration =
+ static_cast(outputFrameDuration),
+ .octets_per_frame = static_cast(outputOctetsPerFrame),
+ .codec_priority = static_cast(outputCodecPriority),
+ };
sLeAudioClientInterface->SetCodecConfigPreference(
group_id, input_codec_config, output_codec_config);
}
-static void setCcidInformationNative(JNIEnv* env, jobject object, jint ccid,
- jint contextType) {
+static void setCcidInformationNative(JNIEnv* /* env */, jobject /* object */,
+ jint ccid, jint contextType) {
std::shared_lock lock(interface_mutex);
if (!sLeAudioClientInterface) {
LOG(ERROR) << __func__ << ": Failed to get the Bluetooth LeAudio Interface";
@@ -553,7 +685,8 @@ static void setCcidInformationNative(JNIEnv* env, jobject object, jint ccid,
sLeAudioClientInterface->SetCcidInformation(ccid, contextType);
}
-static void setInCallNative(JNIEnv* env, jobject object, jboolean inCall) {
+static void setInCallNative(JNIEnv* /* env */, jobject /* object */,
+ jboolean inCall) {
std::shared_lock lock(interface_mutex);
if (!sLeAudioClientInterface) {
LOG(ERROR) << __func__ << ": Failed to get the Bluetooth LeAudio Interface";
@@ -563,8 +696,19 @@ static void setInCallNative(JNIEnv* env, jobject object, jboolean inCall) {
sLeAudioClientInterface->SetInCall(inCall);
}
+static void setUnicastMonitorModeNative(JNIEnv* /* env */, jobject /* object */,
+ jint direction, jboolean enable) {
+ std::shared_lock lock(interface_mutex);
+ if (!sLeAudioClientInterface) {
+ LOG(ERROR) << __func__ << ": Failed to get the Bluetooth LeAudio Interface";
+ return;
+ }
+
+ sLeAudioClientInterface->SetUnicastMonitorMode(direction, enable);
+}
+
static void sendAudioProfilePreferencesNative(
- JNIEnv* env, jint groupId, jboolean isOutputPreferenceLeAudio,
+ JNIEnv* /* env */, jint groupId, jboolean isOutputPreferenceLeAudio,
jboolean isDuplexPreferenceLeAudio) {
std::shared_lock lock(interface_mutex);
if (!sLeAudioClientInterface) {
@@ -576,27 +720,6 @@ static void sendAudioProfilePreferencesNative(
groupId, isOutputPreferenceLeAudio, isDuplexPreferenceLeAudio);
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative", "([Landroid/bluetooth/BluetoothLeAudioCodecConfig;)V",
- (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"connectLeAudioNative", "([B)Z", (void*)connectLeAudioNative},
- {"disconnectLeAudioNative", "([B)Z", (void*)disconnectLeAudioNative},
- {"setEnableStateNative", "([BZ)Z", (void*)setEnableStateNative},
- {"groupAddNodeNative", "(I[B)Z", (void*)groupAddNodeNative},
- {"groupRemoveNodeNative", "(I[B)Z", (void*)groupRemoveNodeNative},
- {"groupSetActiveNative", "(I)V", (void*)groupSetActiveNative},
- {"setCodecConfigPreferenceNative",
- "(ILandroid/bluetooth/BluetoothLeAudioCodecConfig;Landroid/bluetooth/"
- "BluetoothLeAudioCodecConfig;)V",
- (void*)setCodecConfigPreferenceNative},
- {"setCcidInformationNative", "(II)V", (void*)setCcidInformationNative},
- {"setInCallNative", "(Z)V", (void*)setInCallNative},
- {"sendAudioProfilePreferencesNative", "(IZZ)V",
- (void*)sendAudioProfilePreferencesNative},
-};
-
/* Le Audio Broadcaster */
static jmethodID method_onBroadcastCreated;
static jmethodID method_onBroadcastDestroyed;
@@ -656,47 +779,43 @@ static jlong getAudioLocationOrDefault(
const std::map>& metadata,
jlong default_location) {
if (metadata.count(
- bluetooth::le_audio::kLeAudioCodecLC3TypeAudioChannelAllocation) == 0)
+ bluetooth::le_audio::kLeAudioLtvTypeAudioChannelAllocation) == 0)
return default_location;
- auto& vec = metadata.at(
- bluetooth::le_audio::kLeAudioCodecLC3TypeAudioChannelAllocation);
+ auto& vec =
+ metadata.at(bluetooth::le_audio::kLeAudioLtvTypeAudioChannelAllocation);
return VEC_UINT8_TO_UINT32(vec);
}
static jint getSamplingFrequencyOrDefault(
const std::map>& metadata,
jint default_sampling_frequency) {
- if (metadata.count(bluetooth::le_audio::kLeAudioCodecLC3TypeSamplingFreq) ==
- 0)
+ if (metadata.count(bluetooth::le_audio::kLeAudioLtvTypeSamplingFreq) == 0)
return default_sampling_frequency;
- auto& vec =
- metadata.at(bluetooth::le_audio::kLeAudioCodecLC3TypeSamplingFreq);
+ auto& vec = metadata.at(bluetooth::le_audio::kLeAudioLtvTypeSamplingFreq);
return (jint)(vec.data()[0]);
}
static jint getFrameDurationOrDefault(
const std::map>& metadata,
jint default_frame_duration) {
- if (metadata.count(bluetooth::le_audio::kLeAudioCodecLC3TypeFrameDuration) ==
- 0)
+ if (metadata.count(bluetooth::le_audio::kLeAudioLtvTypeFrameDuration) == 0)
return default_frame_duration;
- auto& vec =
- metadata.at(bluetooth::le_audio::kLeAudioCodecLC3TypeFrameDuration);
+ auto& vec = metadata.at(bluetooth::le_audio::kLeAudioLtvTypeFrameDuration);
return (jint)(vec.data()[0]);
}
static jint getOctetsPerFrameOrDefault(
const std::map>& metadata,
jint default_octets_per_frame) {
- if (metadata.count(bluetooth::le_audio::kLeAudioCodecLC3TypeOctetPerFrame) ==
+ if (metadata.count(bluetooth::le_audio::kLeAudioLtvTypeOctetsPerCodecFrame) ==
0)
return default_octets_per_frame;
auto& vec =
- metadata.at(bluetooth::le_audio::kLeAudioCodecLC3TypeOctetPerFrame);
+ metadata.at(bluetooth::le_audio::kLeAudioLtvTypeOctetsPerCodecFrame);
return VEC_UINT8_TO_UINT16(vec);
}
@@ -745,11 +864,15 @@ jobject prepareLeAudioContentMetadataObject(
JNIEnv* env, const std::map>& metadata) {
jstring program_info_str = nullptr;
if (metadata.count(bluetooth::le_audio::kLeAudioMetadataTypeProgramInfo)) {
- program_info_str = env->NewStringUTF(
- (const char*)(metadata
- .at(bluetooth::le_audio::
- kLeAudioMetadataTypeProgramInfo)
- .data()));
+ // Convert the metadata vector to string with null terminator
+ std::string p_str(
+ (const char*)metadata
+ .at(bluetooth::le_audio::kLeAudioMetadataTypeProgramInfo)
+ .data(),
+ metadata.at(bluetooth::le_audio::kLeAudioMetadataTypeProgramInfo)
+ .size());
+
+ program_info_str = env->NewStringUTF(p_str.c_str());
if (!program_info_str) {
LOG(ERROR) << "Failed to create new preset name String for preset name";
return nullptr;
@@ -758,10 +881,14 @@ jobject prepareLeAudioContentMetadataObject(
jstring language_str = nullptr;
if (metadata.count(bluetooth::le_audio::kLeAudioMetadataTypeLanguage)) {
- language_str = env->NewStringUTF(
- (const char*)(metadata
- .at(bluetooth::le_audio::kLeAudioMetadataTypeLanguage)
- .data()));
+ // Convert the metadata vector to string with null terminator
+ std::string l_str(
+ (const char*)metadata
+ .at(bluetooth::le_audio::kLeAudioMetadataTypeLanguage)
+ .data(),
+ metadata.at(bluetooth::le_audio::kLeAudioMetadataTypeLanguage).size());
+
+ language_str = env->NewStringUTF(l_str.c_str());
if (!language_str) {
LOG(ERROR) << "Failed to create new preset name String for language";
return nullptr;
@@ -918,16 +1045,14 @@ jobject prepareBluetoothLeBroadcastMetadataObject(
return nullptr;
}
- // Skip the leading null char bytes
+ // Remove the ending null char bytes
int nativeCodeSize = 16;
- int nativeCodeLeadingZeros = 0;
if (broadcast_metadata.broadcast_code) {
auto& nativeCode = broadcast_metadata.broadcast_code.value();
- nativeCodeLeadingZeros =
+ nativeCodeSize =
std::find_if(nativeCode.cbegin(), nativeCode.cend(),
- [](int x) { return x != 0x00; }) -
+ [](int x) { return x == 0x00; }) -
nativeCode.cbegin();
- nativeCodeSize = nativeCode.size() - nativeCodeLeadingZeros;
}
ScopedLocalRef code(env, env->NewByteArray(nativeCodeSize));
@@ -939,8 +1064,7 @@ jobject prepareBluetoothLeBroadcastMetadataObject(
if (broadcast_metadata.broadcast_code) {
env->SetByteArrayRegion(
code.get(), 0, nativeCodeSize,
- (const jbyte*)broadcast_metadata.broadcast_code->data() +
- nativeCodeLeadingZeros);
+ (const jbyte*)broadcast_metadata.broadcast_code->data());
CHECK(!env->ExceptionCheck());
}
@@ -980,8 +1104,9 @@ jobject prepareBluetoothLeBroadcastMetadataObject(
broadcast_metadata.broadcast_code ? true : false,
broadcast_metadata.is_public, broadcast_name.get(),
broadcast_metadata.broadcast_code ? code.get() : nullptr,
- (jint)broadcast_metadata.basic_audio_announcement.presentation_delay,
- audio_cfg_quality, public_meta_obj.get(), subgroup_list_obj.get());
+ (jint)broadcast_metadata.basic_audio_announcement.presentation_delay_us,
+ audio_cfg_quality, (jint)bluetooth::le_audio::kLeAudioSourceRssiUnknown,
+ public_meta_obj.get(), subgroup_list_obj.get());
}
class LeAudioBroadcasterCallbacksImpl : public LeAudioBroadcasterCallbacks {
@@ -1047,63 +1172,6 @@ class LeAudioBroadcasterCallbacksImpl : public LeAudioBroadcasterCallbacks {
static LeAudioBroadcasterCallbacksImpl sLeAudioBroadcasterCallbacks;
-static void BroadcasterClassInitNative(JNIEnv* env, jclass clazz) {
- method_onBroadcastCreated =
- env->GetMethodID(clazz, "onBroadcastCreated", "(IZ)V");
- method_onBroadcastDestroyed =
- env->GetMethodID(clazz, "onBroadcastDestroyed", "(I)V");
- method_onBroadcastStateChanged =
- env->GetMethodID(clazz, "onBroadcastStateChanged", "(II)V");
- method_onBroadcastMetadataChanged =
- env->GetMethodID(clazz, "onBroadcastMetadataChanged",
- "(ILandroid/bluetooth/BluetoothLeBroadcastMetadata;)V");
-
- jclass jniArrayListClass = env->FindClass("java/util/ArrayList");
- java_util_ArrayList.constructor =
- env->GetMethodID(jniArrayListClass, "", "()V");
- java_util_ArrayList.add =
- env->GetMethodID(jniArrayListClass, "add", "(Ljava/lang/Object;)Z");
-
- jclass jniBluetoothLeAudioCodecConfigMetadataClass =
- env->FindClass("android/bluetooth/BluetoothLeAudioCodecConfigMetadata");
- android_bluetooth_BluetoothLeAudioCodecConfigMetadata.constructor =
- env->GetMethodID(jniBluetoothLeAudioCodecConfigMetadataClass, "",
- "(JIII[B)V");
-
- jclass jniBluetoothLeAudioContentMetadataClass =
- env->FindClass("android/bluetooth/BluetoothLeAudioContentMetadata");
- android_bluetooth_BluetoothLeAudioContentMetadata.constructor =
- env->GetMethodID(jniBluetoothLeAudioContentMetadataClass, "",
- "(Ljava/lang/String;Ljava/lang/String;[B)V");
-
- jclass jniBluetoothLeBroadcastChannelClass =
- env->FindClass("android/bluetooth/BluetoothLeBroadcastChannel");
- android_bluetooth_BluetoothLeBroadcastChannel.constructor = env->GetMethodID(
- jniBluetoothLeBroadcastChannelClass, "",
- "(ZILandroid/bluetooth/BluetoothLeAudioCodecConfigMetadata;)V");
-
- jclass jniBluetoothLeBroadcastSubgroupClass =
- env->FindClass("android/bluetooth/BluetoothLeBroadcastSubgroup");
- android_bluetooth_BluetoothLeBroadcastSubgroup.constructor = env->GetMethodID(
- jniBluetoothLeBroadcastSubgroupClass, "",
- "(JLandroid/bluetooth/BluetoothLeAudioCodecConfigMetadata;"
- "Landroid/bluetooth/BluetoothLeAudioContentMetadata;"
- "Ljava/util/List;)V");
-
- jclass jniBluetoothDeviceClass =
- env->FindClass("android/bluetooth/BluetoothDevice");
- android_bluetooth_BluetoothDevice.constructor = env->GetMethodID(
- jniBluetoothDeviceClass, "", "(Ljava/lang/String;I)V");
-
- jclass jniBluetoothLeBroadcastMetadataClass =
- env->FindClass("android/bluetooth/BluetoothLeBroadcastMetadata");
- android_bluetooth_BluetoothLeBroadcastMetadata.constructor = env->GetMethodID(
- jniBluetoothLeBroadcastMetadataClass, "",
- "(ILandroid/bluetooth/BluetoothDevice;IIIZZLjava/lang/String;"
- "[BIILandroid/bluetooth/BluetoothLeAudioContentMetadata;"
- "Ljava/util/List;)V");
-}
-
static void BroadcasterInitNative(JNIEnv* env, jobject object) {
std::unique_lock interface_lock(
sBroadcasterInterfaceMutex);
@@ -1198,7 +1266,7 @@ static void BroadcasterInitNative(JNIEnv* env, jobject object) {
sLeAudioBroadcasterInterface->Initialize(&sLeAudioBroadcasterCallbacks);
}
-static void BroadcasterStopNative(JNIEnv* env, jobject object) {
+static void BroadcasterStopNative(JNIEnv* /* env */, jobject /* object */) {
std::unique_lock interface_lock(
sBroadcasterInterfaceMutex);
@@ -1212,7 +1280,7 @@ static void BroadcasterStopNative(JNIEnv* env, jobject object) {
sLeAudioBroadcasterInterface->Stop();
}
-static void BroadcasterCleanupNative(JNIEnv* env, jobject object) {
+static void BroadcasterCleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock interface_lock(
sBroadcasterInterfaceMutex);
std::unique_lock callbacks_lock(
@@ -1274,7 +1342,7 @@ std::vector> convertToDataVectors(JNIEnv* env,
return res;
}
-static void CreateBroadcastNative(JNIEnv* env, jobject object,
+static void CreateBroadcastNative(JNIEnv* env, jobject /* object */,
jboolean isPublic, jstring broadcastName,
jbyteArray broadcast_code,
jbyteArray publicMetadata,
@@ -1328,8 +1396,8 @@ static void CreateBroadcastNative(JNIEnv* env, jobject object,
if (quality_array) env->ReleaseIntArrayElements(qualityArray, quality_array, 0);
}
-static void UpdateMetadataNative(JNIEnv* env, jobject object, jint broadcast_id,
- jstring broadcastName,
+static void UpdateMetadataNative(JNIEnv* env, jobject /* object */,
+ jint broadcast_id, jstring broadcastName,
jbyteArray publicMetadata,
jobjectArray metadataArray) {
const char* broadcast_name = nullptr;
@@ -1354,7 +1422,7 @@ static void UpdateMetadataNative(JNIEnv* env, jobject object, jint broadcast_id,
if (public_meta) env->ReleaseByteArrayElements(publicMetadata, public_meta, 0);
}
-static void StartBroadcastNative(JNIEnv* env, jobject object,
+static void StartBroadcastNative(JNIEnv* /* env */, jobject /* object */,
jint broadcast_id) {
LOG(INFO) << __func__;
std::shared_lock lock(sBroadcasterInterfaceMutex);
@@ -1362,7 +1430,7 @@ static void StartBroadcastNative(JNIEnv* env, jobject object,
sLeAudioBroadcasterInterface->StartBroadcast(broadcast_id);
}
-static void StopBroadcastNative(JNIEnv* env, jobject object,
+static void StopBroadcastNative(JNIEnv* /* env */, jobject /* object */,
jint broadcast_id) {
LOG(INFO) << __func__;
std::shared_lock lock(sBroadcasterInterfaceMutex);
@@ -1370,7 +1438,7 @@ static void StopBroadcastNative(JNIEnv* env, jobject object,
sLeAudioBroadcasterInterface->StopBroadcast(broadcast_id);
}
-static void PauseBroadcastNative(JNIEnv* env, jobject object,
+static void PauseBroadcastNative(JNIEnv* /* env */, jobject /* object */,
jint broadcast_id) {
LOG(INFO) << __func__;
std::shared_lock lock(sBroadcasterInterfaceMutex);
@@ -1378,7 +1446,7 @@ static void PauseBroadcastNative(JNIEnv* env, jobject object,
sLeAudioBroadcasterInterface->PauseBroadcast(broadcast_id);
}
-static void DestroyBroadcastNative(JNIEnv* env, jobject object,
+static void DestroyBroadcastNative(JNIEnv* /* env */, jobject /* object */,
jint broadcast_id) {
LOG(INFO) << __func__;
std::shared_lock lock(sBroadcasterInterfaceMutex);
@@ -1386,7 +1454,7 @@ static void DestroyBroadcastNative(JNIEnv* env, jobject object,
sLeAudioBroadcasterInterface->DestroyBroadcast(broadcast_id);
}
-static void getBroadcastMetadataNative(JNIEnv* env, jobject object,
+static void getBroadcastMetadataNative(JNIEnv* /* env */, jobject /* object */,
jint broadcast_id) {
LOG(INFO) << __func__;
std::shared_lock lock(sBroadcasterInterfaceMutex);
@@ -1394,30 +1462,178 @@ static void getBroadcastMetadataNative(JNIEnv* env, jobject object,
sLeAudioBroadcasterInterface->GetBroadcastMetadata(broadcast_id);
}
-static JNINativeMethod sBroadcasterMethods[] = {
- {"classInitNative", "()V", (void*)BroadcasterClassInitNative},
- {"initNative", "()V", (void*)BroadcasterInitNative},
- {"stopNative", "()V", (void*)BroadcasterStopNative},
- {"cleanupNative", "()V", (void*)BroadcasterCleanupNative},
- {"createBroadcastNative", "(ZLjava/lang/String;[B[B[I[[B)V",
- (void*)CreateBroadcastNative},
- {"updateMetadataNative", "(ILjava/lang/String;[B[[B)V",
- (void*)UpdateMetadataNative},
- {"startBroadcastNative", "(I)V", (void*)StartBroadcastNative},
- {"stopBroadcastNative", "(I)V", (void*)StopBroadcastNative},
- {"pauseBroadcastNative", "(I)V", (void*)PauseBroadcastNative},
- {"destroyBroadcastNative", "(I)V", (void*)DestroyBroadcastNative},
- {"getBroadcastMetadataNative", "(I)V", (void*)getBroadcastMetadataNative},
-};
+static int register_com_android_bluetooth_le_audio_broadcaster(JNIEnv* env) {
+ const JNINativeMethod methods[] = {
+ {"initNative", "()V", (void*)BroadcasterInitNative},
+ {"stopNative", "()V", (void*)BroadcasterStopNative},
+ {"cleanupNative", "()V", (void*)BroadcasterCleanupNative},
+ {"createBroadcastNative", "(ZLjava/lang/String;[B[B[I[[B)V",
+ (void*)CreateBroadcastNative},
+ {"updateMetadataNative", "(ILjava/lang/String;[B[[B)V",
+ (void*)UpdateMetadataNative},
+ {"startBroadcastNative", "(I)V", (void*)StartBroadcastNative},
+ {"stopBroadcastNative", "(I)V", (void*)StopBroadcastNative},
+ {"pauseBroadcastNative", "(I)V", (void*)PauseBroadcastNative},
+ {"destroyBroadcastNative", "(I)V", (void*)DestroyBroadcastNative},
+ {"getBroadcastMetadataNative", "(I)V", (void*)getBroadcastMetadataNative},
+ };
+
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/le_audio/LeAudioBroadcasterNativeInterface",
+ methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onBroadcastCreated", "(IZ)V", &method_onBroadcastCreated},
+ {"onBroadcastDestroyed", "(I)V", &method_onBroadcastDestroyed},
+ {"onBroadcastStateChanged", "(II)V", &method_onBroadcastStateChanged},
+ {"onBroadcastMetadataChanged",
+ "(ILandroid/bluetooth/BluetoothLeBroadcastMetadata;)V",
+ &method_onBroadcastMetadataChanged},
+ };
+ GET_JAVA_METHODS(
+ env, "com/android/bluetooth/le_audio/LeAudioBroadcasterNativeInterface",
+ javaMethods);
+
+ const JNIJavaMethod javaArrayListMethods[] = {
+ {"", "()V", &java_util_ArrayList.constructor},
+ {"add", "(Ljava/lang/Object;)Z", &java_util_ArrayList.add},
+ };
+ GET_JAVA_METHODS(env, "java/util/ArrayList", javaArrayListMethods);
+
+ const JNIJavaMethod javaLeAudioCodecMethods[] = {
+ {"", "(JIII[B)V",
+ &android_bluetooth_BluetoothLeAudioCodecConfigMetadata.constructor},
+ };
+ GET_JAVA_METHODS(env, "android/bluetooth/BluetoothLeAudioCodecConfigMetadata",
+ javaLeAudioCodecMethods);
+
+ const JNIJavaMethod javaLeAudioContentMethods[] = {
+ {"", "(Ljava/lang/String;Ljava/lang/String;[B)V",
+ &android_bluetooth_BluetoothLeAudioContentMetadata.constructor},
+ };
+ GET_JAVA_METHODS(env, "android/bluetooth/BluetoothLeAudioContentMetadata",
+ javaLeAudioContentMethods);
+
+ const JNIJavaMethod javaLeBroadcastChannelMethods[] = {
+ {"", "(ZILandroid/bluetooth/BluetoothLeAudioCodecConfigMetadata;)V",
+ &android_bluetooth_BluetoothLeBroadcastChannel.constructor},
+ };
+ GET_JAVA_METHODS(env, "android/bluetooth/BluetoothLeBroadcastChannel",
+ javaLeBroadcastChannelMethods);
+
+ const JNIJavaMethod javaLeBroadcastSubgroupMethods[] = {
+ {"",
+ "(JLandroid/bluetooth/BluetoothLeAudioCodecConfigMetadata;"
+ "Landroid/bluetooth/BluetoothLeAudioContentMetadata;"
+ "Ljava/util/List;)V",
+ &android_bluetooth_BluetoothLeBroadcastSubgroup.constructor},
+ };
+ GET_JAVA_METHODS(env, "android/bluetooth/BluetoothLeBroadcastSubgroup",
+ javaLeBroadcastSubgroupMethods);
+
+ const JNIJavaMethod javaBluetoothDevieceMethods[] = {
+ {"", "(Ljava/lang/String;I)V",
+ &android_bluetooth_BluetoothDevice.constructor},
+ };
+ GET_JAVA_METHODS(env, "android/bluetooth/BluetoothDevice",
+ javaBluetoothDevieceMethods);
+
+ const JNIJavaMethod javaLeBroadcastMetadataMethods[] = {
+ {"",
+ "(ILandroid/bluetooth/BluetoothDevice;IIIZZLjava/lang/String;"
+ "[BIIILandroid/bluetooth/BluetoothLeAudioContentMetadata;"
+ "Ljava/util/List;)V",
+ &android_bluetooth_BluetoothLeBroadcastMetadata.constructor},
+ };
+ GET_JAVA_METHODS(env, "android/bluetooth/BluetoothLeBroadcastMetadata",
+ javaLeBroadcastMetadataMethods);
+
+ return 0;
+}
int register_com_android_bluetooth_le_audio(JNIEnv* env) {
- int register_success = jniRegisterNativeMethods(
- env, "com/android/bluetooth/le_audio/LeAudioNativeInterface", sMethods,
- NELEM(sMethods));
- return register_success &
- jniRegisterNativeMethods(
- env,
- "com/android/bluetooth/le_audio/LeAudioBroadcasterNativeInterface",
- sBroadcasterMethods, NELEM(sBroadcasterMethods));
+ const JNINativeMethod methods[] = {
+ {"initNative", "([Landroid/bluetooth/BluetoothLeAudioCodecConfig;)V",
+ (void*)initNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"connectLeAudioNative", "([B)Z", (void*)connectLeAudioNative},
+ {"disconnectLeAudioNative", "([B)Z", (void*)disconnectLeAudioNative},
+ {"setEnableStateNative", "([BZ)Z", (void*)setEnableStateNative},
+ {"groupAddNodeNative", "(I[B)Z", (void*)groupAddNodeNative},
+ {"groupRemoveNodeNative", "(I[B)Z", (void*)groupRemoveNodeNative},
+ {"groupSetActiveNative", "(I)V", (void*)groupSetActiveNative},
+ {"setCodecConfigPreferenceNative",
+ "(ILandroid/bluetooth/BluetoothLeAudioCodecConfig;"
+ "Landroid/bluetooth/BluetoothLeAudioCodecConfig;)V",
+ (void*)setCodecConfigPreferenceNative},
+ {"setCcidInformationNative", "(II)V", (void*)setCcidInformationNative},
+ {"setInCallNative", "(Z)V", (void*)setInCallNative},
+ {"setUnicastMonitorModeNative", "(IZ)V",
+ (void*)setUnicastMonitorModeNative},
+ {"sendAudioProfilePreferencesNative", "(IZZ)V",
+ (void*)sendAudioProfilePreferencesNative},
+ };
+
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/le_audio/LeAudioNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onGroupStatus", "(II)V", &method_onGroupStatus},
+ {"onGroupNodeStatus", "([BII)V", &method_onGroupNodeStatus},
+ {"onAudioConf", "(IIIII)V", &method_onAudioConf},
+ {"onSinkAudioLocationAvailable", "([BI)V",
+ &method_onSinkAudioLocationAvailable},
+ {"onInitialized", "()V", &method_onInitialized},
+ {"onConnectionStateChanged", "(I[B)V", &method_onConnectionStateChanged},
+ {"onAudioLocalCodecCapabilities",
+ "([Landroid/bluetooth/BluetoothLeAudioCodecConfig;"
+ "[Landroid/bluetooth/BluetoothLeAudioCodecConfig;)V",
+ &method_onAudioLocalCodecCapabilities},
+ {"onAudioGroupCurrentCodecConf",
+ "(ILandroid/bluetooth/BluetoothLeAudioCodecConfig;"
+ "Landroid/bluetooth/BluetoothLeAudioCodecConfig;)V",
+ &method_onAudioGroupCurrentCodecConf},
+ {"onAudioGroupSelectableCodecConf",
+ "(I[Landroid/bluetooth/BluetoothLeAudioCodecConfig;"
+ "[Landroid/bluetooth/BluetoothLeAudioCodecConfig;)V",
+ &method_onAudioGroupSelectableCodecConf},
+ {"onHealthBasedRecommendationAction", "([BI)V",
+ &method_onHealthBasedRecommendationAction},
+ {"onHealthBasedGroupRecommendationAction", "(II)V",
+ &method_onHealthBasedGroupRecommendationAction},
+ {"onUnicastMonitorModeStatus", "(II)V",
+ &method_onUnicastMonitorModeStatus},
+ };
+ GET_JAVA_METHODS(env, "com/android/bluetooth/le_audio/LeAudioNativeInterface",
+ javaMethods);
+
+ const JNIJavaMethod javaLeAudioCodecMethods[] = {
+ {"", "(IIIIIIIII)V",
+ &android_bluetooth_BluetoothLeAudioCodecConfig.constructor},
+ {"getCodecType", "()I",
+ &android_bluetooth_BluetoothLeAudioCodecConfig.getCodecType},
+ {"getSampleRate", "()I",
+ &android_bluetooth_BluetoothLeAudioCodecConfig.getSampleRate},
+ {"getBitsPerSample", "()I",
+ &android_bluetooth_BluetoothLeAudioCodecConfig.getBitsPerSample},
+ {"getChannelCount", "()I",
+ &android_bluetooth_BluetoothLeAudioCodecConfig.getChannelCount},
+ {"getFrameDuration", "()I",
+ &android_bluetooth_BluetoothLeAudioCodecConfig.getFrameDuration},
+ {"getOctetsPerFrame", "()I",
+ &android_bluetooth_BluetoothLeAudioCodecConfig.getOctetsPerFrame},
+ {"getCodecPriority", "()I",
+ &android_bluetooth_BluetoothLeAudioCodecConfig.getCodecPriority},
+ };
+ GET_JAVA_METHODS(env, "android/bluetooth/BluetoothLeAudioCodecConfig",
+ javaLeAudioCodecMethods);
+
+ return register_com_android_bluetooth_le_audio_broadcaster(env);
}
} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_pan.cpp b/android/app/jni/com_android_bluetooth_pan.cpp
index 84d7b1c78b07dbe131d963b2f3c2471f90022e5e..a216ebb103458e8959497bbca100339a1aaa22db 100644
--- a/android/app/jni/com_android_bluetooth_pan.cpp
+++ b/android/app/jni/com_android_bluetooth_pan.cpp
@@ -98,19 +98,10 @@ static btpan_callbacks_t sBluetoothPanCallbacks = {
connection_state_callback};
// Define native functions
-
-static void classInitNative(JNIEnv* env, jclass clazz) {
- method_onConnectStateChanged =
- env->GetMethodID(clazz, "onConnectStateChanged", "([BIIII)V");
- method_onControlStateChanged = env->GetMethodID(
- clazz, "onControlStateChanged", "(IIILjava/lang/String;)V");
-
- info("succeeds");
-}
static const bt_interface_t* btIf;
static void initializeNative(JNIEnv* env, jobject object) {
- debug("pan");
+ debug("Initialize pan");
if (btIf) return;
btIf = getBluetoothInterface();
@@ -152,7 +143,8 @@ static void initializeNative(JNIEnv* env, jobject object) {
}
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
+ debug("Cleanup pan");
if (!btIf) return;
if (sPanIf != NULL) {
@@ -169,10 +161,10 @@ static void cleanupNative(JNIEnv* env, jobject object) {
btIf = NULL;
}
-static jboolean connectPanNative(JNIEnv* env, jobject object,
+static jboolean connectPanNative(JNIEnv* env, jobject /* object */,
jbyteArray address, jint src_role,
jint dest_role) {
- debug("in");
+ debug("Connect pan");
if (!sPanIf) return JNI_FALSE;
jbyte* addr = env->GetByteArrayElements(address, NULL);
@@ -192,8 +184,9 @@ static jboolean connectPanNative(JNIEnv* env, jobject object,
return ret;
}
-static jboolean disconnectPanNative(JNIEnv* env, jobject object,
+static jboolean disconnectPanNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
+ debug("Disconnects pan");
if (!sPanIf) return JNI_FALSE;
jbyte* addr = env->GetByteArrayElements(address, NULL);
@@ -213,17 +206,27 @@ static jboolean disconnectPanNative(JNIEnv* env, jobject object,
return ret;
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initializeNative", "()V", (void*)initializeNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"connectPanNative", "([BII)Z", (void*)connectPanNative},
- {"disconnectPanNative", "([B)Z", (void*)disconnectPanNative},
- // TBD cleanup
-};
-
int register_com_android_bluetooth_pan(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/android/bluetooth/pan/PanService",
- sMethods, NELEM(sMethods));
+ const JNINativeMethod methods[] = {
+ {"initializeNative", "()V", (void*)initializeNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"connectPanNative", "([BII)Z", (void*)connectPanNative},
+ {"disconnectPanNative", "([B)Z", (void*)disconnectPanNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/pan/PanNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[]{
+ {"onConnectStateChanged", "([BIIII)V", &method_onConnectStateChanged},
+ {"onControlStateChanged", "(IIILjava/lang/String;)V",
+ &method_onControlStateChanged},
+ };
+ GET_JAVA_METHODS(env, "com/android/bluetooth/pan/PanNativeInterface",
+ javaMethods);
+
+ return 0;
}
}
diff --git a/android/app/jni/com_android_bluetooth_sdp.cpp b/android/app/jni/com_android_bluetooth_sdp.cpp
index ded546a05d85bc6eab7216f7cdac4b3d0c1d9123..62ee16ae3fb19a8bf7d95d491df118c91f28c723 100644
--- a/android/app/jni/com_android_bluetooth_sdp.cpp
+++ b/android/app/jni/com_android_bluetooth_sdp.cpp
@@ -75,34 +75,8 @@ static void initializeNative(JNIEnv* env, jobject object) {
sCallbacksObj = env->NewGlobalRef(object);
}
-static void classInitNative(JNIEnv* env, jclass clazz) {
- /* generic SDP record (raw data)*/
- method_sdpRecordFoundCallback =
- env->GetMethodID(clazz, "sdpRecordFoundCallback", "(I[B[BI[B)V");
-
- /* MAS SDP record*/
- method_sdpMasRecordFoundCallback = env->GetMethodID(
- clazz, "sdpMasRecordFoundCallback", "(I[B[BIIIIIILjava/lang/String;Z)V");
- /* MNS SDP record*/
- method_sdpMnsRecordFoundCallback = env->GetMethodID(
- clazz, "sdpMnsRecordFoundCallback", "(I[B[BIIIILjava/lang/String;Z)V");
- /* PBAP PSE record */
- method_sdpPseRecordFoundCallback = env->GetMethodID(
- clazz, "sdpPseRecordFoundCallback", "(I[B[BIIIIILjava/lang/String;Z)V");
- /* OPP Server record */
- method_sdpOppOpsRecordFoundCallback =
- env->GetMethodID(clazz, "sdpOppOpsRecordFoundCallback",
- "(I[B[BIIILjava/lang/String;[BZ)V");
- /* SAP Server record */
- method_sdpSapsRecordFoundCallback = env->GetMethodID(
- clazz, "sdpSapsRecordFoundCallback", "(I[B[BIILjava/lang/String;Z)V");
- /* DIP record */
- method_sdpDipRecordFoundCallback = env->GetMethodID(
- clazz, "sdpDipRecordFoundCallback", "(I[B[BIIIIIZZ)V");
-}
-
-static jboolean sdpSearchNative(JNIEnv* env, jobject obj, jbyteArray address,
- jbyteArray uuidObj) {
+static jboolean sdpSearchNative(JNIEnv* env, jobject /* obj */,
+ jbyteArray address, jbyteArray uuidObj) {
ALOGD("%s", __func__);
if (!sBluetoothSdpInterface) return JNI_FALSE;
@@ -244,7 +218,7 @@ static void sdp_search_callback(bt_status_t status, const RawAddress& bd_addr,
} // End of for-loop
}
-static jint sdpCreateMapMasRecordNative(JNIEnv* env, jobject obj,
+static jint sdpCreateMapMasRecordNative(JNIEnv* env, jobject /* obj */,
jstring name_str, jint mas_id, jint scn,
jint l2cap_psm, jint version,
jint msg_types, jint features) {
@@ -283,7 +257,7 @@ static jint sdpCreateMapMasRecordNative(JNIEnv* env, jobject obj,
return handle;
}
-static jint sdpCreateMapMnsRecordNative(JNIEnv* env, jobject obj,
+static jint sdpCreateMapMnsRecordNative(JNIEnv* env, jobject /* obj */,
jstring name_str, jint scn,
jint l2cap_psm, jint version,
jint features) {
@@ -320,7 +294,7 @@ static jint sdpCreateMapMnsRecordNative(JNIEnv* env, jobject obj,
return handle;
}
-static jint sdpCreatePbapPceRecordNative(JNIEnv* env, jobject obj,
+static jint sdpCreatePbapPceRecordNative(JNIEnv* env, jobject /* obj */,
jstring name_str, jint version) {
ALOGD("%s", __func__);
if (!sBluetoothSdpInterface) return -1;
@@ -351,7 +325,7 @@ static jint sdpCreatePbapPceRecordNative(JNIEnv* env, jobject obj,
return handle;
}
-static jint sdpCreatePbapPseRecordNative(JNIEnv* env, jobject obj,
+static jint sdpCreatePbapPseRecordNative(JNIEnv* env, jobject /* obj */,
jstring name_str, jint scn,
jint l2cap_psm, jint version,
jint supported_repositories,
@@ -390,7 +364,7 @@ static jint sdpCreatePbapPseRecordNative(JNIEnv* env, jobject obj,
return handle;
}
-static jint sdpCreateOppOpsRecordNative(JNIEnv* env, jobject obj,
+static jint sdpCreateOppOpsRecordNative(JNIEnv* env, jobject /* obj */,
jstring name_str, jint scn,
jint l2cap_psm, jint version,
jbyteArray supported_formats_list) {
@@ -439,7 +413,7 @@ static jint sdpCreateOppOpsRecordNative(JNIEnv* env, jobject obj,
return handle;
}
-static jint sdpCreateSapsRecordNative(JNIEnv* env, jobject obj,
+static jint sdpCreateSapsRecordNative(JNIEnv* env, jobject /* obj */,
jstring name_str, jint scn,
jint version) {
ALOGD("%s", __func__);
@@ -472,7 +446,7 @@ static jint sdpCreateSapsRecordNative(JNIEnv* env, jobject obj,
return handle;
}
-static jboolean sdpRemoveSdpRecordNative(JNIEnv* env, jobject obj,
+static jboolean sdpRemoveSdpRecordNative(JNIEnv* /* env */, jobject /* obj */,
jint record_id) {
ALOGD("%s", __func__);
if (!sBluetoothSdpInterface) return false;
@@ -487,7 +461,7 @@ static jboolean sdpRemoveSdpRecordNative(JNIEnv* env, jobject obj,
return true;
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
const bt_interface_t* btInf = getBluetoothInterface();
if (btInf == NULL) {
@@ -508,28 +482,49 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static JNINativeMethod sMethods[] = {
- /* name, signature, funcPtr */
- {"classInitNative", "()V", (void*)classInitNative},
- {"initializeNative", "()V", (void*)initializeNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"sdpSearchNative", "([B[B)Z", (void*)sdpSearchNative},
- {"sdpCreateMapMasRecordNative", "(Ljava/lang/String;IIIIII)I",
- (void*)sdpCreateMapMasRecordNative},
- {"sdpCreateMapMnsRecordNative", "(Ljava/lang/String;IIII)I",
- (void*)sdpCreateMapMnsRecordNative},
- {"sdpCreatePbapPceRecordNative", "(Ljava/lang/String;I)I",
- (void*)sdpCreatePbapPceRecordNative},
- {"sdpCreatePbapPseRecordNative", "(Ljava/lang/String;IIIII)I",
- (void*)sdpCreatePbapPseRecordNative},
- {"sdpCreateOppOpsRecordNative", "(Ljava/lang/String;III[B)I",
- (void*)sdpCreateOppOpsRecordNative},
- {"sdpCreateSapsRecordNative", "(Ljava/lang/String;II)I",
- (void*)sdpCreateSapsRecordNative},
- {"sdpRemoveSdpRecordNative", "(I)Z", (void*)sdpRemoveSdpRecordNative}};
-
int register_com_android_bluetooth_sdp(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/android/bluetooth/sdp/SdpManager",
- sMethods, NELEM(sMethods));
+ const JNINativeMethod methods[] = {
+ {"initializeNative", "()V", (void*)initializeNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"sdpSearchNative", "([B[B)Z", (void*)sdpSearchNative},
+ {"sdpCreateMapMasRecordNative", "(Ljava/lang/String;IIIIII)I",
+ (void*)sdpCreateMapMasRecordNative},
+ {"sdpCreateMapMnsRecordNative", "(Ljava/lang/String;IIII)I",
+ (void*)sdpCreateMapMnsRecordNative},
+ {"sdpCreatePbapPceRecordNative", "(Ljava/lang/String;I)I",
+ (void*)sdpCreatePbapPceRecordNative},
+ {"sdpCreatePbapPseRecordNative", "(Ljava/lang/String;IIIII)I",
+ (void*)sdpCreatePbapPseRecordNative},
+ {"sdpCreateOppOpsRecordNative", "(Ljava/lang/String;III[B)I",
+ (void*)sdpCreateOppOpsRecordNative},
+ {"sdpCreateSapsRecordNative", "(Ljava/lang/String;II)I",
+ (void*)sdpCreateSapsRecordNative},
+ {"sdpRemoveSdpRecordNative", "(I)Z", (void*)sdpRemoveSdpRecordNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/sdp/SdpManagerNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"sdpRecordFoundCallback", "(I[B[BI[B)V", &method_sdpRecordFoundCallback},
+ {"sdpMasRecordFoundCallback", "(I[B[BIIIIIILjava/lang/String;Z)V",
+ &method_sdpMasRecordFoundCallback},
+ {"sdpMnsRecordFoundCallback", "(I[B[BIIIILjava/lang/String;Z)V",
+ &method_sdpMnsRecordFoundCallback},
+ {"sdpPseRecordFoundCallback", "(I[B[BIIIIILjava/lang/String;Z)V",
+ &method_sdpPseRecordFoundCallback},
+ {"sdpOppOpsRecordFoundCallback", "(I[B[BIIILjava/lang/String;[BZ)V",
+ &method_sdpOppOpsRecordFoundCallback},
+ {"sdpSapsRecordFoundCallback", "(I[B[BIILjava/lang/String;Z)V",
+ &method_sdpSapsRecordFoundCallback},
+ {"sdpDipRecordFoundCallback", "(I[B[BIIIIIZZ)V",
+ &method_sdpDipRecordFoundCallback},
+ };
+ GET_JAVA_METHODS(env, "com/android/bluetooth/sdp/SdpManagerNativeInterface",
+ javaMethods);
+
+ return 0;
}
}
diff --git a/android/app/jni/com_android_bluetooth_vc.cpp b/android/app/jni/com_android_bluetooth_vc.cpp
index 4c4103ef17d03a45ca7a5b9218db77dc7642f22b..60cd30e49b2bb2cee7c88f3a0118f894c19949cf 100644
--- a/android/app/jni/com_android_bluetooth_vc.cpp
+++ b/android/app/jni/com_android_bluetooth_vc.cpp
@@ -48,7 +48,8 @@ class VolumeControlCallbacksImpl : public VolumeControlCallbacks {
~VolumeControlCallbacksImpl() = default;
void OnConnectionState(ConnectionState state,
const RawAddress& bd_addr) override {
- LOG(INFO) << __func__;
+ LOG(INFO) << __func__ << ", state:" << int(state)
+ << ", addr: " << bd_addr.ToRedactedStringForLogging();
std::shared_lock lock(callbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
@@ -198,31 +199,6 @@ class VolumeControlCallbacksImpl : public VolumeControlCallbacks {
static VolumeControlCallbacksImpl sVolumeControlCallbacks;
-static void classInitNative(JNIEnv* env, jclass clazz) {
- method_onConnectionStateChanged =
- env->GetMethodID(clazz, "onConnectionStateChanged", "(I[B)V");
-
- method_onVolumeStateChanged =
- env->GetMethodID(clazz, "onVolumeStateChanged", "(IZ[BZ)V");
-
- method_onGroupVolumeStateChanged =
- env->GetMethodID(clazz, "onGroupVolumeStateChanged", "(IZIZ)V");
-
- method_onDeviceAvailable =
- env->GetMethodID(clazz, "onDeviceAvailable", "(I[B)V");
-
- method_onExtAudioOutVolumeOffsetChanged =
- env->GetMethodID(clazz, "onExtAudioOutVolumeOffsetChanged", "(II[B)V");
-
- method_onExtAudioOutLocationChanged =
- env->GetMethodID(clazz, "onExtAudioOutLocationChanged", "(II[B)V");
-
- method_onExtAudioOutDescriptionChanged = env->GetMethodID(
- clazz, "onExtAudioOutDescriptionChanged", "(ILjava/lang/String;[B)V");
-
- LOG(INFO) << __func__ << ": succeeds";
-}
-
static void initNative(JNIEnv* env, jobject object) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -260,7 +236,7 @@ static void initNative(JNIEnv* env, jobject object) {
sVolumeControlInterface->Init(&sVolumeControlCallbacks);
}
-static void cleanupNative(JNIEnv* env, jobject object) {
+static void cleanupNative(JNIEnv* env, jobject /* object */) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -281,7 +257,7 @@ static void cleanupNative(JNIEnv* env, jobject object) {
}
}
-static jboolean connectVolumeControlNative(JNIEnv* env, jobject object,
+static jboolean connectVolumeControlNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
LOG(INFO) << __func__;
std::shared_lock lock(interface_mutex);
@@ -304,7 +280,7 @@ static jboolean connectVolumeControlNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static jboolean disconnectVolumeControlNative(JNIEnv* env, jobject object,
+static jboolean disconnectVolumeControlNative(JNIEnv* env, jobject /* object */,
jbyteArray address) {
LOG(INFO) << __func__;
std::shared_lock lock(interface_mutex);
@@ -327,8 +303,8 @@ static jboolean disconnectVolumeControlNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static void setVolumeNative(JNIEnv* env, jobject object, jbyteArray address,
- jint volume) {
+static void setVolumeNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jint volume) {
if (!sVolumeControlInterface) {
LOG(ERROR) << __func__
<< ": Failed to get the Bluetooth Volume Control Interface";
@@ -346,8 +322,8 @@ static void setVolumeNative(JNIEnv* env, jobject object, jbyteArray address,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void setGroupVolumeNative(JNIEnv* env, jobject object, jint group_id,
- jint volume) {
+static void setGroupVolumeNative(JNIEnv* /* env */, jobject /* object */,
+ jint group_id, jint volume) {
if (!sVolumeControlInterface) {
LOG(ERROR) << __func__
<< ": Failed to get the Bluetooth Volume Control Interface";
@@ -357,7 +333,7 @@ static void setGroupVolumeNative(JNIEnv* env, jobject object, jint group_id,
sVolumeControlInterface->SetVolume(group_id, volume);
}
-static void muteNative(JNIEnv* env, jobject object, jbyteArray address) {
+static void muteNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
if (!sVolumeControlInterface) {
LOG(ERROR) << __func__
<< ": Failed to get the Bluetooth Volume Control Interface";
@@ -375,7 +351,8 @@ static void muteNative(JNIEnv* env, jobject object, jbyteArray address) {
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void muteGroupNative(JNIEnv* env, jobject object, jint group_id) {
+static void muteGroupNative(JNIEnv* /* env */, jobject /* object */,
+ jint group_id) {
if (!sVolumeControlInterface) {
LOG(ERROR) << __func__
<< ": Failed to get the Bluetooth Volume Control Interface";
@@ -384,7 +361,8 @@ static void muteGroupNative(JNIEnv* env, jobject object, jint group_id) {
sVolumeControlInterface->Mute(group_id);
}
-static void unmuteNative(JNIEnv* env, jobject object, jbyteArray address) {
+static void unmuteNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address) {
if (!sVolumeControlInterface) {
LOG(ERROR) << __func__
<< ": Failed to get the Bluetooth Volume Control Interface";
@@ -402,7 +380,8 @@ static void unmuteNative(JNIEnv* env, jobject object, jbyteArray address) {
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void unmuteGroupNative(JNIEnv* env, jobject object, jint group_id) {
+static void unmuteGroupNative(JNIEnv* /* env */, jobject /* object */,
+ jint group_id) {
if (!sVolumeControlInterface) {
LOG(ERROR) << __func__
<< ": Failed to get the Bluetooth Volume Control Interface";
@@ -412,7 +391,8 @@ static void unmuteGroupNative(JNIEnv* env, jobject object, jint group_id) {
}
/* Native methods for exterbak audio outputs */
-static jboolean getExtAudioOutVolumeOffsetNative(JNIEnv* env, jobject object,
+static jboolean getExtAudioOutVolumeOffsetNative(JNIEnv* env,
+ jobject /* object */,
jbyteArray address,
jint ext_output_id) {
LOG(INFO) << __func__;
@@ -431,7 +411,8 @@ static jboolean getExtAudioOutVolumeOffsetNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static jboolean setExtAudioOutVolumeOffsetNative(JNIEnv* env, jobject object,
+static jboolean setExtAudioOutVolumeOffsetNative(JNIEnv* env,
+ jobject /* object */,
jbyteArray address,
jint ext_output_id,
jint offset) {
@@ -452,7 +433,7 @@ static jboolean setExtAudioOutVolumeOffsetNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static jboolean getExtAudioOutLocationNative(JNIEnv* env, jobject object,
+static jboolean getExtAudioOutLocationNative(JNIEnv* env, jobject /* object */,
jbyteArray address,
jint ext_output_id) {
LOG(INFO) << __func__;
@@ -471,7 +452,7 @@ static jboolean getExtAudioOutLocationNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static jboolean setExtAudioOutLocationNative(JNIEnv* env, jobject object,
+static jboolean setExtAudioOutLocationNative(JNIEnv* env, jobject /* object */,
jbyteArray address,
jint ext_output_id,
jint location) {
@@ -492,7 +473,8 @@ static jboolean setExtAudioOutLocationNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static jboolean getExtAudioOutDescriptionNative(JNIEnv* env, jobject object,
+static jboolean getExtAudioOutDescriptionNative(JNIEnv* env,
+ jobject /* object */,
jbyteArray address,
jint ext_output_id) {
LOG(INFO) << __func__;
@@ -511,7 +493,8 @@ static jboolean getExtAudioOutDescriptionNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static jboolean setExtAudioOutDescriptionNative(JNIEnv* env, jobject object,
+static jboolean setExtAudioOutDescriptionNative(JNIEnv* env,
+ jobject /* object */,
jbyteArray address,
jint ext_output_id,
jstring descr) {
@@ -539,36 +522,55 @@ static jboolean setExtAudioOutDescriptionNative(JNIEnv* env, jobject object,
return JNI_TRUE;
}
-static JNINativeMethod sMethods[] = {
- {"classInitNative", "()V", (void*)classInitNative},
- {"initNative", "()V", (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
- {"connectVolumeControlNative", "([B)Z", (void*)connectVolumeControlNative},
- {"disconnectVolumeControlNative", "([B)Z",
- (void*)disconnectVolumeControlNative},
- {"setVolumeNative", "([BI)V", (void*)setVolumeNative},
- {"setGroupVolumeNative", "(II)V", (void*)setGroupVolumeNative},
- {"muteNative", "([B)V", (void*)muteNative},
- {"muteGroupNative", "(I)V", (void*)muteGroupNative},
- {"unmuteNative", "([B)V", (void*)unmuteNative},
- {"unmuteGroupNative", "(I)V", (void*)unmuteGroupNative},
- {"getExtAudioOutVolumeOffsetNative", "([BI)Z",
- (void*)getExtAudioOutVolumeOffsetNative},
- {"setExtAudioOutVolumeOffsetNative", "([BII)Z",
- (void*)setExtAudioOutVolumeOffsetNative},
- {"getExtAudioOutLocationNative", "([BI)Z",
- (void*)getExtAudioOutLocationNative},
- {"setExtAudioOutLocationNative", "([BII)Z",
- (void*)setExtAudioOutLocationNative},
- {"getExtAudioOutDescriptionNative", "([BI)Z",
- (void*)getExtAudioOutDescriptionNative},
- {"setExtAudioOutDescriptionNative", "([BILjava/lang/String;)Z",
- (void*)setExtAudioOutDescriptionNative},
-};
-
int register_com_android_bluetooth_vc(JNIEnv* env) {
- return jniRegisterNativeMethods(
- env, "com/android/bluetooth/vc/VolumeControlNativeInterface", sMethods,
- NELEM(sMethods));
+ const JNINativeMethod methods[] = {
+ {"initNative", "()V", (void*)initNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
+ {"connectVolumeControlNative", "([B)Z",
+ (void*)connectVolumeControlNative},
+ {"disconnectVolumeControlNative", "([B)Z",
+ (void*)disconnectVolumeControlNative},
+ {"setVolumeNative", "([BI)V", (void*)setVolumeNative},
+ {"setGroupVolumeNative", "(II)V", (void*)setGroupVolumeNative},
+ {"muteNative", "([B)V", (void*)muteNative},
+ {"muteGroupNative", "(I)V", (void*)muteGroupNative},
+ {"unmuteNative", "([B)V", (void*)unmuteNative},
+ {"unmuteGroupNative", "(I)V", (void*)unmuteGroupNative},
+ {"getExtAudioOutVolumeOffsetNative", "([BI)Z",
+ (void*)getExtAudioOutVolumeOffsetNative},
+ {"setExtAudioOutVolumeOffsetNative", "([BII)Z",
+ (void*)setExtAudioOutVolumeOffsetNative},
+ {"getExtAudioOutLocationNative", "([BI)Z",
+ (void*)getExtAudioOutLocationNative},
+ {"setExtAudioOutLocationNative", "([BII)Z",
+ (void*)setExtAudioOutLocationNative},
+ {"getExtAudioOutDescriptionNative", "([BI)Z",
+ (void*)getExtAudioOutDescriptionNative},
+ {"setExtAudioOutDescriptionNative", "([BILjava/lang/String;)Z",
+ (void*)setExtAudioOutDescriptionNative},
+ };
+ const int result = REGISTER_NATIVE_METHODS(
+ env, "com/android/bluetooth/vc/VolumeControlNativeInterface", methods);
+ if (result != 0) {
+ return result;
+ }
+
+ const JNIJavaMethod javaMethods[] = {
+ {"onConnectionStateChanged", "(I[B)V", &method_onConnectionStateChanged},
+ {"onVolumeStateChanged", "(IZ[BZ)V", &method_onVolumeStateChanged},
+ {"onGroupVolumeStateChanged", "(IZIZ)V",
+ &method_onGroupVolumeStateChanged},
+ {"onDeviceAvailable", "(I[B)V", &method_onDeviceAvailable},
+ {"onExtAudioOutVolumeOffsetChanged", "(II[B)V",
+ &method_onExtAudioOutVolumeOffsetChanged},
+ {"onExtAudioOutLocationChanged", "(II[B)V",
+ &method_onExtAudioOutLocationChanged},
+ {"onExtAudioOutDescriptionChanged", "(ILjava/lang/String;[B)V",
+ &method_onExtAudioOutDescriptionChanged},
+ };
+ GET_JAVA_METHODS(env, "com/android/bluetooth/vc/VolumeControlNativeInterface",
+ javaMethods);
+
+ return 0;
}
} // namespace android
diff --git a/android/app/lib/mapapi/com/android/bluetooth/mapapi/BluetoothMapContract.java b/android/app/lib/mapapi/com/android/bluetooth/mapapi/BluetoothMapContract.java
index 5040bdc57eee9b2e610b040ed6fea209fd4e6d39..918aecddc5db118db3dc25dd89a0d227939ddb31 100644
--- a/android/app/lib/mapapi/com/android/bluetooth/mapapi/BluetoothMapContract.java
+++ b/android/app/lib/mapapi/com/android/bluetooth/mapapi/BluetoothMapContract.java
@@ -19,7 +19,6 @@ package com.android.bluetooth.mapapi;
import android.content.ContentResolver;
import android.net.Uri;
-
/**
* This class defines the minimum sets of data needed for a client to
* implement to claim support for the Bluetooth Message Access Profile.
diff --git a/android/app/libbluetooth_jni.map b/android/app/libbluetooth_jni.map
new file mode 100644
index 0000000000000000000000000000000000000000..655a716d9a12d35db7abb1aadf0dbb918cab571b
--- /dev/null
+++ b/android/app/libbluetooth_jni.map
@@ -0,0 +1,4 @@
+{
+ global: JNI_OnLoad;
+ local: *;
+};
diff --git a/android/app/lint-baseline.xml b/android/app/lint-baseline.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3c6ab974d702da194f8827155e8f57c4a132e7a5
--- /dev/null
+++ b/android/app/lint-baseline.xml
@@ -0,0 +1,7146 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/app/proguard.flags b/android/app/proguard.flags
index a9426ad4aa651d94e8e7c0c76abbe0ec43dcfa1a..75da0433f5ea01f55e78f971d3186de43cb20709 100644
--- a/android/app/proguard.flags
+++ b/android/app/proguard.flags
@@ -5,3 +5,6 @@
-keep class android.support.v4.media.MediaMetadataCompat { *; }
-keep class android.support.v4.media.MediaBrowserCompat$MediaItem { *; }
-keep class android.support.v4.media.MediaDescriptionCompat { *; }
+
+# Required for tests that use Mockito's thenThrow with checked exceptions.
+-keepattributes Exceptions
\ No newline at end of file
diff --git a/system/gd/proto/bluetooth/bluetoothKeystore/keystore.proto b/android/app/proto/keystore.proto
similarity index 90%
rename from system/gd/proto/bluetooth/bluetoothKeystore/keystore.proto
rename to android/app/proto/keystore.proto
index d0e418bd28e52ebd68066f1e283f62f7c214554a..f0641ff6fab911f87513b5ae8a9317efb8870c06 100644
--- a/system/gd/proto/bluetooth/bluetoothKeystore/keystore.proto
+++ b/android/app/proto/keystore.proto
@@ -16,9 +16,6 @@
syntax = "proto2";
-// C++ namespace: bluetooth::metrics::BluetoothMetricsProto
-package bluetooth.keystore.BluetoothKeystoreProto;
-
option java_package = "com.android.bluetooth";
option java_outer_classname = "BluetoothKeystoreProto";
diff --git a/android/app/res/layout/bluetooth_map_settings_account_group.xml b/android/app/res/layout/bluetooth_map_settings_account_group.xml
index 7bbfca473ef1b050e937430ffff57302911ac1ca..b82ddeecf37cb569feaa678e5e29993bf235bfd1 100644
--- a/android/app/res/layout/bluetooth_map_settings_account_group.xml
+++ b/android/app/res/layout/bluetooth_map_settings_account_group.xml
@@ -24,22 +24,22 @@
android:id="@+id/bluetooth_map_settings_group_icon"
android:layout_width="64dp"
android:layout_height="64dp"
- android:layout_alignParentLeft="true"
+ android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:maxWidth="64dp"
android:maxHeight="64dp"
- android:layout_marginLeft="30dp"
+ android:layout_marginStart="30dp"
/>
+ android:layout_toEndOf="@id/bluetooth_map_settings_group_icon"/>
diff --git a/android/app/res/layout/bluetooth_map_settings_account_item.xml b/android/app/res/layout/bluetooth_map_settings_account_item.xml
index b6fbf8a77adb6a5e1066cdb5a09ede4fc51757de..5dc63d2bbf15398f51c19cbfba7d0603654fafb2 100644
--- a/android/app/res/layout/bluetooth_map_settings_account_item.xml
+++ b/android/app/res/layout/bluetooth_map_settings_account_item.xml
@@ -22,8 +22,8 @@
android:clickable="true"
android:gravity="fill_vertical"
android:orientation="horizontal"
- android:paddingLeft="51dp"
- android:paddingRight="25dp"
+ android:paddingEnd="51dp"
+ android:paddingStart="25dp"
tools:context=".BluetoothMapSettings" android:baselineAligned="false">
+ android:gravity="start|center_vertical"/>
+ android:gravity="end|center_vertical" />
diff --git a/android/app/res/layout/file_transfer.xml b/android/app/res/layout/file_transfer.xml
index 4dea02d4d8acf719eced666737c85dfde09afee1..d508ee6ab02d969d319a6c74920919dd5a0d8225 100644
--- a/android/app/res/layout/file_transfer.xml
+++ b/android/app/res/layout/file_transfer.xml
@@ -83,15 +83,15 @@
android:id="@+id/progress_percent"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
- android:layout_marginLeft="20dip"
+ android:layout_marginEnd="20dip"
android:textAppearance="?android:attr/textAppearanceSmall"
- android:gravity="left" />
+ android:gravity="start" />
-
-
-
- "com.android.settings"
-
diff --git a/android/app/res/values-af/strings.xml b/android/app/res/values-af/strings.xml
index 4a99bb952f91d86a58e4ae5ba29828e51f8b7b21..425476f69160e4ae0016ca6b22d0e84d12dda3d7 100644
--- a/android/app/res/values-af/strings.xml
+++ b/android/app/res/values-af/strings.xml
@@ -16,6 +16,7 @@
+ "Bluetooth"
"Maak toegang aflaaibestuurder oop."
"Gee aan die program toegang tot die BluetoothShare-bestuurder en om dit te gebruik om lêers oor te dra."
"Voeg Bluetooth-toesteltoegang by aanvaarlys."
diff --git a/android/app/res/values-am/config.xml b/android/app/res/values-am/config.xml
deleted file mode 100644
index 4f96544b67afeaba2c5e363d2f65e01bd9e11263..0000000000000000000000000000000000000000
--- a/android/app/res/values-am/config.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
- "com.android.settings"
-
diff --git a/android/app/res/values-am/strings.xml b/android/app/res/values-am/strings.xml
index ab44be045e7e712926b806097dbdc0bbf37ee82c..4b23792a97ca097baa25ec4e75c99d5aa62dd5f0 100644
--- a/android/app/res/values-am/strings.xml
+++ b/android/app/res/values-am/strings.xml
@@ -16,6 +16,7 @@
+ "ብሉቱá‹"
"አá‹áˆá‹µ አደራጅን ድረስá¢"
"የብሉቱዠአጋራ አስተዳዳሪá‹áŠ• ለመድረስ እና á‹á‹áˆŽá‰½ እንዲያስተላáˆá‰ ለመጠቀሠለመተáŒá‰ ሪያዠá‹áˆá‰…ዳáˆá¢"
"የብሉቱዠመሣሪያ መዳረሻን በመቀበያ á‹áˆá‹áˆ ያስገቡá¢"
diff --git a/android/app/res/values-ar/config.xml b/android/app/res/values-ar/config.xml
deleted file mode 100644
index 4f96544b67afeaba2c5e363d2f65e01bd9e11263..0000000000000000000000000000000000000000
--- a/android/app/res/values-ar/config.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
- "com.android.settings"
-
diff --git a/android/app/res/values-ar/strings.xml b/android/app/res/values-ar/strings.xml
index b8092d046b2a37fb216775363e4234410c215a8f..7106e0638d0bd85c984bffe82df247ea12979881 100644
--- a/android/app/res/values-ar/strings.xml
+++ b/android/app/res/values-ar/strings.xml
@@ -16,6 +16,7 @@
+ "بلوتوث"
"الدخول إلى إدارة التنزيل."
"â€Ù„Ù„Ø³Ù…Ø§Ø Ù„Ù„ØªØ·Ø¨ÙŠÙ‚ بالدخول إلى إدارة BluetoothShare واستخدامها لنقل Ø§Ù„Ù…Ù„ÙØ§Øª."
"Ø¥Ø¶Ø§ÙØ© جهاز يتضمّن بلوتوث إلى القائمة Ø§Ù„Ù…Ø³Ù…ÙˆØ Ø¨Ù‡Ø§."
diff --git a/android/app/res/values-as/config.xml b/android/app/res/values-as/config.xml
deleted file mode 100644
index 4f96544b67afeaba2c5e363d2f65e01bd9e11263..0000000000000000000000000000000000000000
--- a/android/app/res/values-as/config.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
- "com.android.settings"
-
diff --git a/android/app/res/values-as/strings.xml b/android/app/res/values-as/strings.xml
index f87c8aa2cbdf2eb342b1a6c5bb5090953cb0b698..020d1b73a3e4a84f7c5e94b4fee7fc194475f4ae 100644
--- a/android/app/res/values-as/strings.xml
+++ b/android/app/res/values-as/strings.xml
@@ -16,6 +16,7 @@
+ "বà§à¦²à§à¦Ÿà§à¦¥"
"ডাউনল’ড মেনেজাৰ à¦à¦•à§à¦¸à§‡à¦› কৰিব পাৰে।"
"à¦à¦ªà§â€Œà¦Ÿà§‹à¦• BluetoothShare মেনেজাৰ বà§à¦¯à§±à¦¹à¦¾à§° কৰি ফাইল সà§à¦¥à¦¾à¦¨à¦¾à¦¨à§à¦¤à§° কৰিবলৈ অনà§à¦®à¦¤à¦¿ দিয়ে।"
"বà§à¦²à§à¦Ÿà§à¦¥ ডিà¦à¦¾à¦‡à¦š à¦à¦•à§à¦¸à§‡à¦› কৰাৰ সà§à¦¬à§€à¦•ৃতি দিয়ে।"
diff --git a/android/app/res/values-az/config.xml b/android/app/res/values-az/config.xml
deleted file mode 100644
index 4f96544b67afeaba2c5e363d2f65e01bd9e11263..0000000000000000000000000000000000000000
--- a/android/app/res/values-az/config.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
- "com.android.settings"
-
diff --git a/android/app/res/values-az/strings.xml b/android/app/res/values-az/strings.xml
index 0085ccebc342b343ebbc89a5ecd67f99dbdd90ce..5d1599f998663243bbd48efb2e93d048d032784c 100644
--- a/android/app/res/values-az/strings.xml
+++ b/android/app/res/values-az/strings.xml
@@ -16,6 +16,7 @@
+ "Bluetooth"
"EndirmÉ™ menecerinÉ™ daxil olun."
"Tətbiq BluetoothPaylaşım menecerinə daxil ola və faylları ötürmək üçün ondan istifadə edə bilər."
"Bluetooth cihazı girişini qəbul siyahısına daxil edin."
diff --git a/android/app/res/values-b+sr+Latn/config.xml b/android/app/res/values-b+sr+Latn/config.xml
deleted file mode 100644
index 4f96544b67afeaba2c5e363d2f65e01bd9e11263..0000000000000000000000000000000000000000
--- a/android/app/res/values-b+sr+Latn/config.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-