diff --git a/.clang-format b/.clang-format
index 0b4b45a62c10bf56e4cc6a8f85b1d5cbea5915e1..d49e3528a1dca86b3af435811afca8bdeaa4a7a2 100644
--- a/.clang-format
+++ b/.clang-format
@@ -19,6 +19,28 @@
# accommodate for handling of the large legacy code base.
#
+# AOSP is based on google style with some modification commented below
BasedOnStyle: Google
-CommentPragmas: NOLINT:.*
-DerivePointerAlignment: false
+
+---
+Language: Cpp
+# AOSP ask for 4, but we are not ready to touch every single line
+# IndentWidth: 4 # vs 2
+ColumnLimit: 100 # vs 80
+ContinuationIndentWidth: 8 # vs 4
+AccessModifierOffset: -2 # vs -1 Should be -4 when updating IndentWidth to 4
+Standard: c++20 # vs Auto
+AllowShortIfStatementsOnASingleLine: Never # vs WithoutElse
+AllowShortLoopsOnASingleLine: false # vs true
+# AOSP suggest 1, but ask to follow clang-format settings. CppLint ask for 2
+# SpacesBeforeTrailingComments: 1 # vs 2
+
+# Allow clang-format to automatically fix more things
+RemoveSemicolon: true
+InsertBraces: true
+RemoveParentheses: ReturnStatement
+
+---
+Language: Java
+# Java format is handled by google-java-format
+DisableFormat: true
diff --git a/Android.bp b/Android.bp
index e403ac4334374d7e62d3fba7c91ce3251ac0ebb5..e88d6ab550663c690b388f625f84d7c4374146f1 100644
--- a/Android.bp
+++ b/Android.bp
@@ -57,7 +57,7 @@ filegroup {
// 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,
+// - Try avoiding adding option that would not fit "future" targets, for example 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 {
@@ -73,3 +73,112 @@ cc_defaults {
c_std: "c99",
cpp_std: "c++20",
}
+
+java_defaults {
+ name: "bluetooth_errorprone_rules",
+ errorprone: {
+ enabled: true,
+ javacflags: [
+ "-Xep:AlmostJavadoc:ERROR",
+ "-Xep:AlreadyChecked:ERROR",
+ "-Xep:BadImport:ERROR",
+ "-Xep:CatchAndPrintStackTrace:ERROR",
+ "-Xep:CatchFail:ERROR",
+ "-Xep:CheckReturnValue:ERROR",
+ "-Xep:ClassCanBeStatic:ERROR",
+ "-Xep:DateFormatConstant:ERROR",
+ "-Xep:DirectInvocationOnMock:ERROR",
+ "-Xep:EmptyBlockTag:ERROR",
+ "-Xep:EmptyCatch:ERROR",
+ "-Xep:EqualsGetClass:ERROR",
+ "-Xep:EqualsHashCode:ERROR",
+ "-Xep:EqualsIncompatibleType:ERROR",
+ "-Xep:FallThrough:ERROR",
+ "-Xep:Finalize:ERROR",
+ "-Xep:FutureReturnValueIgnored:ERROR",
+ "-Xep:GuardedBy:ERROR",
+ "-Xep:HidingField:ERROR",
+ "-Xep:InconsistentHashCode:ERROR",
+ "-Xep:InlineFormatString:ERROR",
+ "-Xep:InlineMeInliner:ERROR",
+ "-Xep:InvalidBlockTag:ERROR",
+ "-Xep:InvalidInlineTag:ERROR",
+ "-Xep:InvalidParam:ERROR",
+ "-Xep:JavaUtilDate:ERROR",
+ "-Xep:JdkObsolete:ERROR",
+ "-Xep:LockOnNonEnclosingClassLiteral:ERROR",
+ "-Xep:LongFloatConversion:ERROR",
+ "-Xep:LoopOverCharArray:ERROR",
+ "-Xep:MissingCasesInEnumSwitch:ERROR",
+ "-Xep:MixedMutabilityReturnType:ERROR",
+ "-Xep:MockNotUsedInProduction:ERROR",
+ "-Xep:ModifiedButNotUsed:ERROR",
+ "-Xep:ModifyCollectionInEnhancedForLoop:ERROR",
+ "-Xep:NarrowCalculation:ERROR",
+ "-Xep:NarrowingCompoundAssignment:ERROR",
+ "-Xep:NonApiType:ERROR",
+ "-Xep:NonAtomicVolatileUpdate:ERROR",
+ "-Xep:NonCanonicalType:ERROR",
+ "-Xep:NotJavadoc:ERROR",
+ "-Xep:ObjectEqualsForPrimitives:ERROR",
+ "-Xep:OperatorPrecedence:ERROR",
+ "-Xep:ReferenceEquality:ERROR",
+ "-Xep:ReturnAtTheEndOfVoidFunction:ERROR",
+ "-Xep:StaticAssignmentInConstructor:ERROR",
+ "-Xep:StaticGuardedByInstance:ERROR",
+ "-Xep:StringCaseLocaleUsage:ERROR",
+ "-Xep:StringCharset:ERROR",
+ "-Xep:SynchronizeOnNonFinalField:ERROR",
+ "-Xep:ToStringReturnsNull:ERROR",
+ "-Xep:TruthConstantAsserts:ERROR",
+ "-Xep:TruthIncompatibleType:ERROR",
+ "-Xep:UndefinedEquals:ERROR",
+ "-Xep:UnnecessaryAssignment:ERROR",
+ "-Xep:UnnecessaryAsync:ERROR",
+ "-Xep:UnnecessaryStringBuilder:ERROR",
+ "-Xep:UnrecognisedJavadocTag:ERROR",
+ "-Xep:UnusedMethod:ERROR",
+ "-Xep:UnusedNestedClass:ERROR",
+ "-Xep:UnusedVariable:ERROR",
+ "-Xep:WaitNotInLoop:ERROR",
+ "-Xep:WakelockReleasedDangerously:ERROR",
+
+ // Exclude generated files
+ "-XepExcludedPaths:.*/srcjars/.*",
+
+ // The @InlineMe annotation is not available
+ // "-Xep:InlineMeSuggester:OFF",
+ ],
+ },
+}
+
+java_defaults {
+ name: "bluetooth_framework_errorprone_rules",
+ defaults: ["bluetooth_errorprone_rules"],
+ plugins: [
+ "error_prone_android_framework",
+ ],
+ errorprone: {
+ javacflags: [
+ "-Xep:AndroidFrameworkBinderIdentity:ERROR",
+ "-Xep:AndroidFrameworkBluetoothPermission:ERROR",
+ "-Xep:AndroidFrameworkCompatChange:ERROR",
+ "-Xep:AndroidFrameworkEfficientParcelable:ERROR",
+ "-Xep:AndroidFrameworkEfficientStrings:ERROR",
+ "-Xep:AndroidFrameworkPendingIntentMutability:ERROR",
+ "-Xep:AndroidFrameworkRequiresPermission:ERROR",
+ "-Xep:AndroidFrameworkRethrowFromSystem:ERROR",
+ "-Xep:AndroidFrameworkTargetSdk:ERROR",
+ "-Xep:AndroidHideInComments:ERROR",
+
+ // After fixing this errorprone, we decided to not merge the change.
+ // It is not very readable and the benefits are minimal when looking
+ // at the size of the maps used in the Bluetooth application.
+ // See https://r.android.com/3200511
+ "-Xep:AndroidFrameworkEfficientCollections:OFF",
+
+ // Does not look pertinent in our situation
+ "-Xep:AndroidFrameworkEfficientXml:OFF",
+ ],
+ },
+}
diff --git a/CPPLINT.cfg b/CPPLINT.cfg
new file mode 100644
index 0000000000000000000000000000000000000000..cc062661c71c86524b7e04325cfa758571dfe361
--- /dev/null
+++ b/CPPLINT.cfg
@@ -0,0 +1,44 @@
+set noparent
+linelength=100
+# Do not check access modifier indentation.
+# CPPLint enforces +1, but our rule is no indentation.
+filter=-whitespace/indent
+
+# TODO: b/364967694 re-enable the warning
+filter=-whitespace/newline
+# TODO: b/364967694 re-enable the warning
+filter=-whitespace/blank_line
+# TODO: b/364967694 re-enable the warning
+filter=-whitespace/ending_newline
+# TODO: b/364967694 re-enable the warning
+filter=-readability/check
+# TODO: b/364967694 re-enable the warning
+filter=-runtime/int
+# TODO: b/364967694 re-enable the warning
+filter=-runtime/string
+# TODO: b/364967694 re-enable the warning
+filter=-runtime/explicit
+# TODO: b/364967694 re-enable the warning
+filter=-readability/braces
+# TODO: b/364967694 re-enable the warning
+filter=-whitespace/braces
+# TODO: b/364967694 re-enable the warning
+filter=-build/c++11
+# TODO: b/364967694 re-enable the warning
+filter=-readability/todo
+# TODO: b/364967694 re-enable the warning
+filter=-readability/multiline_comment
+# TODO: b/364967694 re-enable the warning
+filter=-build/namespaces
+# TODO: b/364967694 re-enable the warning
+filter=-readability/inheritance
+# TODO: b/364967694 re-enable the warning
+filter=-build/header_guard
+# TODO: b/364967694 re-enable the warning
+filter=-runtime/references
+# TODO: b/364967694 re-enable the warning
+filter=-build/include_what_you_use
+# TODO: b/364967694 re-enable the warning
+filter=-build/include_subdir
+# TODO: b/364967694 re-enable the warning
+filter=-readability/casting
diff --git a/OWNERS_build b/OWNERS_build
index 263e0532b6ba983665554ebbeb49c3c0540039df..5b3f4bad26bb6d12a5b76f2f028bde581286585c 100644
--- a/OWNERS_build
+++ b/OWNERS_build
@@ -1,2 +1 @@
-licorne@google.com
wescande@google.com
diff --git a/OWNERS_chromeos b/OWNERS_chromeos
index 0280ec47df9af042be2674c2d55beaeb5ceb43cc..075a04e5e3c80b043790f920a8dbeebb1d79ef51 100644
--- a/OWNERS_chromeos
+++ b/OWNERS_chromeos
@@ -1,6 +1,5 @@
# Project owners
abhishekpandit@google.com
-sonnysasaka@google.com
# Audio
enshuo@google.com
@@ -12,3 +11,12 @@ whalechang@google.com
michaelfsun@google.com
laikatherine@google.com
yinghsu@google.com
+apusaka@google.com
+deanliao@google.com
+chharry@google.com
+melhuishj@google.com
+johnlai@google.com
+mmandlik@google.com
+sarveshkalwit@google.com
+howardchung@google.com
+jiangzp@google.com
diff --git a/OWNERS_hearingaid b/OWNERS_hearingaid
index 09f245c2fcca2b51b7bb92e2f0d95d318f0ace8f..e70772a9527eb199cb115399b3cf6bab7bae263a 100644
--- a/OWNERS_hearingaid
+++ b/OWNERS_hearingaid
@@ -1,2 +1 @@
charliebout@google.com
-licorne@google.com
diff --git a/TEST_MAPPING b/TEST_MAPPING
index d63ee4014153169c47c779131d2978f6ecddb053..5f21a9b8008fcf89ae41382b075e80d0a67004f6 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -25,9 +25,6 @@
//{
// "name": "bluetooth-test-audio-hal-interface"
//},
- {
- "name": "net_test_audio_a2dp_hw"
- },
{
"name": "net_test_audio_hearing_aid_hw"
},
@@ -110,9 +107,6 @@
{
"name": "bluetooth_test_common"
},
- {
- "name": "bluetooth_test_gd_unit"
- },
{
"name": "bluetooth_test_sdp"
},
@@ -226,9 +220,6 @@
//{
// "name": "bluetooth-test-audio-hal-interface"
//},
- {
- "name": "net_test_audio_a2dp_hw"
- },
{
"name": "net_test_audio_hearing_aid_hw"
},
diff --git a/android/ChannelSoundingTestApp/app/build.gradle.kts b/android/ChannelSoundingTestApp/app/build.gradle.kts
index 76749335f57db90e07352b04ac82771c3347c234..cfc03a1247c0da78faec718937f3e1955f805743 100644
--- a/android/ChannelSoundingTestApp/app/build.gradle.kts
+++ b/android/ChannelSoundingTestApp/app/build.gradle.kts
@@ -10,8 +10,8 @@ android {
applicationId = "com.android.bluetooth.channelsoundingtestapp"
minSdk = 34
targetSdk = 34
- versionCode = 1
- versionName = "1.0"
+ versionCode = 2
+ versionName = "2.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
@@ -38,7 +38,10 @@ dependencies {
implementation(libs.constraintlayout)
implementation(libs.navigation.fragment)
implementation(libs.navigation.ui)
+ implementation(libs.legacy.support.v4)
+ implementation(libs.lifecycle.livedata.ktx)
+ implementation(libs.lifecycle.viewmodel.ktx)
testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core)
-}
\ No newline at end of file
+}
diff --git a/android/ChannelSoundingTestApp/app/src/main/AndroidManifest.xml b/android/ChannelSoundingTestApp/app/src/main/AndroidManifest.xml
index 9be650fdc5dffd6cf661ab59c1fade81b692a5c6..a949fa7cc24fb27aa7b7ed43bd1d6354063bc9a6 100644
--- a/android/ChannelSoundingTestApp/app/src/main/AndroidManifest.xml
+++ b/android/ChannelSoundingTestApp/app/src/main/AndroidManifest.xml
@@ -4,9 +4,12 @@
package="com.android.bluetooth.channelsoundingtestapp">
+
+
-
+
+
+ tools:targetApi="34">
mBondedBtDevicesArrayAdapter;
+ private Button mButtonUpdate;
+ private Button mButtonGatt;
+ private Button mButtonScanConnect;
+ private Spinner mSpinnerBtAddress;
+
+ public static BleConnectionFragment newInstance() {
+ return new BleConnectionFragment();
+ }
+
+ @Override
+ public View onCreateView(
+ @NonNull LayoutInflater inflater,
+ @Nullable ViewGroup container,
+ @Nullable Bundle savedInstanceState) {
+
+ View root = inflater.inflate(R.layout.fragment_ble_connection, container, false);
+ mBtnAdvertising = root.findViewById(R.id.btn_advertising);
+ mButtonUpdate = (Button) root.findViewById(R.id.btn_update_devices);
+ mButtonGatt = (Button) root.findViewById(R.id.btn_connect_gatt);
+ mButtonScanConnect = (Button) root.findViewById(R.id.btn_scan_connect);
+ mSpinnerBtAddress = (Spinner) root.findViewById(R.id.spinner_bt_address);
+ return root;
+ }
+
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+
+ mBondedBtDevicesArrayAdapter =
+ new ArrayAdapter(
+ getContext(), android.R.layout.simple_spinner_item, new ArrayList<>());
+ mBondedBtDevicesArrayAdapter.setDropDownViewResource(
+ android.R.layout.simple_spinner_dropdown_item);
+ mSpinnerBtAddress.setAdapter(mBondedBtDevicesArrayAdapter);
+
+ mViewModel =
+ new ViewModelProvider(requireParentFragment()).get(BleConnectionViewModel.class);
+ mViewModel
+ .getGattState()
+ .observe(
+ getActivity(),
+ gattSate -> {
+ switch (gattSate) {
+ case CONNECTED_DIRECT:
+ mButtonGatt.setText("Disconnect Gatt");
+ break;
+ case SCANNING:
+ mButtonScanConnect.setText("Stop Scan");
+ break;
+ case CONNECTED_SCAN:
+ mButtonScanConnect.setText("Disconnect Gatt");
+ break;
+ case DISCONNECTED:
+ default:
+ mButtonGatt.setText("Connect Gatt");
+ mButtonScanConnect.setText("Scan and Connect");
+ }
+ });
+ mButtonUpdate.setOnClickListener(
+ v -> {
+ mViewModel.updateBondedDevices();
+ });
+ mViewModel
+ .getBondedBtDeviceAddresses()
+ .observe(
+ getActivity(),
+ deviceList -> {
+ mBondedBtDevicesArrayAdapter.clear();
+ mBondedBtDevicesArrayAdapter.addAll(deviceList);
+ if (mSpinnerBtAddress.getSelectedItem() != null) {
+ String selectedBtAddress =
+ mSpinnerBtAddress.getSelectedItem().toString();
+ mViewModel.setCsTargetAddress(selectedBtAddress);
+ }
+ });
+ mSpinnerBtAddress.setOnItemSelectedListener(
+ new OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(
+ AdapterView> adapterView, View view, int i, long l) {
+ String btAddress = mSpinnerBtAddress.getSelectedItem().toString();
+ mViewModel.setCsTargetAddress(btAddress);
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView> adapterView) {
+ mViewModel.setCsTargetAddress("");
+ }
+ });
+ mButtonGatt.setOnClickListener(
+ v -> {
+ mViewModel.toggleGattConnection();
+ });
+ mButtonScanConnect.setOnClickListener(
+ v -> {
+ mViewModel.toggleScanConnect();
+ });
+ mViewModel
+ .getIsAdvertising()
+ .observe(
+ getActivity(),
+ isAdvertising -> {
+ if (isAdvertising) {
+ mBtnAdvertising.setText("Stop Advertising");
+ } else {
+ mBtnAdvertising.setText("Start Advertising");
+ }
+ });
+
+ mBtnAdvertising.setOnClickListener(
+ new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ mViewModel.toggleAdvertising();
+ }
+ });
+ }
+}
diff --git a/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/BleConnectionViewModel.java b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/BleConnectionViewModel.java
new file mode 100644
index 0000000000000000000000000000000000000000..c5f25cff1f2d36fe37e04668edf53df91a92ef11
--- /dev/null
+++ b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/BleConnectionViewModel.java
@@ -0,0 +1,342 @@
+/*
+ * Copyright 2024 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.
+ */
+
+package com.android.bluetooth.channelsoundingtestapp;
+
+import android.annotation.SuppressLint;
+import android.app.Application;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothGatt;
+import android.bluetooth.BluetoothGattCallback;
+import android.bluetooth.BluetoothGattServer;
+import android.bluetooth.BluetoothGattServerCallback;
+import android.bluetooth.BluetoothManager;
+import android.bluetooth.BluetoothProfile;
+import android.bluetooth.le.AdvertiseData;
+import android.bluetooth.le.AdvertisingSet;
+import android.bluetooth.le.AdvertisingSetCallback;
+import android.bluetooth.le.AdvertisingSetParameters;
+import android.bluetooth.le.BluetoothLeAdvertiser;
+import android.bluetooth.le.BluetoothLeScanner;
+import android.bluetooth.le.ScanCallback;
+import android.bluetooth.le.ScanFilter;
+import android.bluetooth.le.ScanResult;
+import android.bluetooth.le.ScanSettings;
+import android.os.ParcelUuid;
+import android.text.TextUtils;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.lifecycle.AndroidViewModel;
+import androidx.lifecycle.LiveData;
+import androidx.lifecycle.MutableLiveData;
+
+import com.android.bluetooth.channelsoundingtestapp.Constants.GattState;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+/** The ViewModel for the BLE GATT connection. */
+@SuppressLint("MissingPermission") // permissions are checked upfront
+public class BleConnectionViewModel extends AndroidViewModel {
+ private static final int GATT_MTU_SIZE = 512;
+
+ private final BluetoothAdapter mBluetoothAdapter;
+ private final BluetoothManager mBluetoothManager;
+ @Nullable private BluetoothGatt mBluetoothGatt = null;
+ private MutableLiveData mIsAdvertising = new MutableLiveData<>(false);
+ private MutableLiveData mLogText = new MutableLiveData<>();
+ private MutableLiveData mTargetDevice = new MutableLiveData<>();
+ // scanner
+ private final MutableLiveData> mBondedBtDeviceAddresses = new MutableLiveData<>();
+ private final MutableLiveData mGattState =
+ new MutableLiveData<>(GattState.DISCONNECTED);
+ private String mTargetBtAddress = "";
+
+ private GattState mExpectedGattState = GattState.DISCONNECTED;
+
+ /** Constructor */
+ public BleConnectionViewModel(@NonNull Application application) {
+ super(application);
+ mBluetoothManager = application.getSystemService(BluetoothManager.class);
+ mBluetoothAdapter = mBluetoothManager.getAdapter();
+ }
+
+ LiveData getIsAdvertising() {
+ return mIsAdvertising;
+ }
+
+ LiveData getLogText() {
+ return mLogText;
+ }
+
+ LiveData getGattState() {
+ return mGattState;
+ }
+
+ LiveData> getBondedBtDeviceAddresses() {
+ return mBondedBtDeviceAddresses;
+ }
+
+ LiveData getTargetDevice() {
+ return mTargetDevice;
+ }
+
+ void toggleAdvertising() {
+ if (mIsAdvertising.getValue()) {
+ stopAdvertising();
+ } else {
+ startConnectableAdvertising();
+ }
+ }
+
+ AdvertisingSetCallback mAdvertisingSetCallback =
+ new AdvertisingSetCallback() {
+ @Override
+ public void onAdvertisingSetStarted(
+ AdvertisingSet advertisingSet, int txPower, int status) {
+ printLog(
+ "onAdvertisingSetStarted(): txPower:"
+ + txPower
+ + " , status: "
+ + status);
+ if (status == 0) {
+ mIsAdvertising.postValue(true);
+ }
+ }
+
+ @Override
+ public void onAdvertisingDataSet(AdvertisingSet advertisingSet, int status) {
+ printLog("onAdvertisingDataSet() :status:" + status);
+ }
+
+ @Override
+ public void onScanResponseDataSet(AdvertisingSet advertisingSet, int status) {
+ printLog("onScanResponseDataSet(): status:" + status);
+ }
+
+ @Override
+ public void onAdvertisingSetStopped(AdvertisingSet advertisingSet) {
+ printLog("onAdvertisingSetStopped():");
+ mIsAdvertising.postValue(false);
+ }
+ };
+
+ private void startConnectableAdvertising() {
+ if (mIsAdvertising.getValue()) {
+ return;
+ }
+ BluetoothLeAdvertiser advertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();
+ AdvertisingSetParameters parameters =
+ new AdvertisingSetParameters.Builder()
+ .setLegacyMode(false) // True by default, but set here as a reminder.
+ .setConnectable(true)
+ .setInterval(AdvertisingSetParameters.INTERVAL_LOW)
+ .setTxPowerLevel(AdvertisingSetParameters.TX_POWER_MEDIUM)
+ .build();
+
+ BluetoothGattServerCallback gattServerCallback =
+ new BluetoothGattServerCallback() {
+ @Override
+ public void onConnectionStateChange(
+ BluetoothDevice device, int status, int newState) {
+ super.onConnectionStateChange(device, status, newState);
+ if (newState == BluetoothProfile.STATE_CONNECTED) {
+ printLog("Device connected: " + device.getName());
+ mTargetDevice.postValue(device);
+ } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
+ printLog("Device disconnected: " + device.getName());
+ mTargetDevice.postValue(null);
+ }
+ }
+ };
+
+ BluetoothGattServer bluetoothGattServer =
+ mBluetoothManager.openGattServer(
+ getApplication().getApplicationContext(), gattServerCallback);
+ AdvertiseData advertiseData =
+ new AdvertiseData.Builder()
+ .setIncludeDeviceName(true)
+ .addServiceUuid(new ParcelUuid(Constants.CS_TEST_SERVICE_UUID))
+ .build();
+
+ printLog("Start connectable advertising");
+
+ advertiser.startAdvertisingSet(
+ parameters, advertiseData, null, null, null, 0, 0, mAdvertisingSetCallback);
+ }
+
+ private void stopAdvertising() {
+ BluetoothLeAdvertiser advertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();
+ advertiser.stopAdvertisingSet(mAdvertisingSetCallback);
+ printLog("stop advertising");
+ }
+
+ void updateBondedDevices() {
+ List addresses = new ArrayList<>();
+ Set bonded_devices = mBluetoothAdapter.getBondedDevices();
+ for (BluetoothDevice device : bonded_devices) {
+ addresses.add(device.getAddress());
+ }
+ mBondedBtDeviceAddresses.setValue(addresses);
+ }
+
+ void setCsTargetAddress(String btAddress) {
+ printLog("set target address: " + btAddress);
+ mTargetBtAddress = btAddress;
+ }
+
+ void toggleGattConnection() {
+ if (mGattState.getValue() == GattState.DISCONNECTED) {
+ if (TextUtils.isEmpty(mTargetBtAddress)) {
+ printLog("Pair and select a target device first!");
+ return;
+ }
+ connectGatt();
+ } else if (mGattState.getValue() == GattState.CONNECTED_DIRECT) {
+ disconnectGatt();
+ }
+ }
+
+ private BluetoothGattCallback mGattCallback =
+ new BluetoothGattCallback() {
+ @Override
+ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
+ printLog("onConnectionStateChange status:" + status + ", newState:" + newState);
+ if (newState == BluetoothProfile.STATE_CONNECTED) {
+ printLog(gatt.getDevice().getName() + " is connected");
+ gatt.requestMtu(GATT_MTU_SIZE);
+ mBluetoothGatt = gatt;
+ mGattState.postValue(mExpectedGattState);
+ mTargetDevice.postValue(gatt.getDevice());
+ } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
+ printLog("disconnected from " + gatt.getDevice().getName());
+ mExpectedGattState = GattState.DISCONNECTED;
+ mGattState.postValue(mExpectedGattState);
+ mBluetoothGatt.close();
+ mBluetoothGatt = null;
+ mTargetDevice.postValue(null);
+ }
+ }
+
+ public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
+ if (status == BluetoothGatt.GATT_SUCCESS) {
+ printLog("MTU changed to: " + mtu);
+ } else {
+ printLog("MTU change failed: " + status);
+ }
+ }
+ };
+
+ private void connectGatt() {
+ BluetoothDevice btDevice = mBluetoothAdapter.getRemoteDevice(mTargetBtAddress);
+ printLog("Connect gatt to " + btDevice.getName());
+ mExpectedGattState = GattState.CONNECTED_DIRECT;
+ btDevice.connectGatt(
+ getApplication().getApplicationContext(),
+ false,
+ mGattCallback,
+ BluetoothDevice.TRANSPORT_LE);
+ }
+
+ private void disconnectGatt() {
+ if (mBluetoothGatt != null) {
+ printLog("disconnect from " + mBluetoothGatt.getDevice().getName());
+ mBluetoothGatt.disconnect();
+ }
+ }
+
+ void toggleScanConnect() {
+ if (mGattState.getValue() == GattState.DISCONNECTED) {
+ connectGattByScanning();
+ } else if (mGattState.getValue() == GattState.SCANNING) {
+ stopScanning();
+ } else if (mGattState.getValue() == GattState.CONNECTED_SCAN) {
+ disconnectGatt();
+ }
+ }
+
+ private ScanCallback mScanCallback =
+ new ScanCallback() {
+ @Override
+ public void onScanResult(int callbackType, ScanResult result) {
+ List serviceUuids = result.getScanRecord().getServiceUuids();
+ if (serviceUuids != null) {
+ for (ParcelUuid parcelUuid : serviceUuids) {
+ BluetoothDevice btDevice = result.getDevice();
+ printLog("found device - " + btDevice.getName());
+ if (parcelUuid.getUuid().equals(Constants.CS_TEST_SERVICE_UUID)) {
+ mExpectedGattState = GattState.CONNECTED_SCAN;
+ stopScanning();
+ printLog("connect GATT to: " + btDevice.getName());
+ // Connect to the GATT server
+ mBluetoothGatt =
+ btDevice.connectGatt(
+ getApplication().getApplicationContext(),
+ false,
+ mGattCallback,
+ BluetoothDevice.TRANSPORT_LE);
+ }
+ }
+ }
+ }
+ };
+
+ private void connectGattByScanning() {
+ BluetoothLeScanner bluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
+
+ List filters = new ArrayList<>();
+ ScanFilter filter =
+ new ScanFilter.Builder()
+ .setServiceUuid(
+ new ParcelUuid(
+ Constants.CS_TEST_SERVICE_UUID)) // Filter by service UUID
+ .build();
+ filters.add(filter);
+
+ ScanSettings settings =
+ new ScanSettings.Builder()
+ .setLegacy(false)
+ .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
+ .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
+ .setReportDelay(0)
+ .build();
+
+ printLog("start scanning...");
+
+ // Start scanning
+ bluetoothLeScanner.startScan(filters, settings, mScanCallback);
+ mExpectedGattState = GattState.SCANNING;
+ mGattState.setValue(mExpectedGattState);
+ }
+
+ private void stopScanning() {
+ BluetoothLeScanner bluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
+ if (bluetoothLeScanner != null) {
+ bluetoothLeScanner.stopScan(mScanCallback);
+ if (mExpectedGattState == GattState.SCANNING) {
+ mExpectedGattState = GattState.DISCONNECTED;
+ mGattState.setValue(mExpectedGattState);
+ }
+ }
+ }
+
+ private void printLog(@NonNull String logMsg) {
+ mLogText.postValue("BT Log: " + logMsg);
+ }
+}
diff --git a/system/gd/l2cap/le/dynamic_channel.cc b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/Constants.java
similarity index 59%
rename from system/gd/l2cap/le/dynamic_channel.cc
rename to android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/Constants.java
index 108b65f97e0790a21a6a7d89ec140061772c754f..a672811c6f170fb4bd365168da3fc2aa723f5af0 100644
--- a/system/gd/l2cap/le/dynamic_channel.cc
+++ b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/Constants.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 The Android Open Source Project
+ * Copyright 2024 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.
@@ -14,20 +14,18 @@
* limitations under the License.
*/
-#include "l2cap/le/dynamic_channel.h"
-#include "l2cap/le/internal/link.h"
+package com.android.bluetooth.channelsoundingtestapp;
-namespace bluetooth {
-namespace l2cap {
-namespace le {
-LinkOptions* DynamicChannel::GetLinkOptions() {
- return link_->GetLinkOptions();
-}
+import java.util.UUID;
-Mtu DynamicChannel::GetMtu() const {
- return mtu_;
-}
+abstract class Constants {
+ static final UUID CS_TEST_SERVICE_UUID =
+ UUID.fromString("f81d4fae-7ccc-eeee-a765-00aaaaaaaaaa");
-} // namespace le
-} // namespace l2cap
-} // namespace bluetooth
+ enum GattState {
+ DISCONNECTED,
+ SCANNING,
+ CONNECTED_DIRECT,
+ CONNECTED_SCAN,
+ }
+}
diff --git a/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/DistanceMeasurementInitiator.java b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/DistanceMeasurementInitiator.java
index 44e7cff79408a7383c6e2675cd31305dd2761eaa..9d39dcb10f633e92e60c9e76c6666dcb424db8a3 100644
--- a/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/DistanceMeasurementInitiator.java
+++ b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/DistanceMeasurementInitiator.java
@@ -19,10 +19,7 @@ package com.android.bluetooth.channelsoundingtestapp;
import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothGatt;
-import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothManager;
-import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothStatusCodes;
import android.bluetooth.le.DistanceMeasurementManager;
import android.bluetooth.le.DistanceMeasurementMethod;
@@ -36,14 +33,12 @@ import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
class DistanceMeasurementInitiator {
private static final int DISTANCE_MEASUREMENT_DURATION_SEC = 3600;
- private static final int GATT_MTU_SIZE = 512;
private static final List> mDistanceMeasurementMethodMapping =
List.of(
new Pair<>(DistanceMeasurementMethod.DISTANCE_MEASUREMENT_METHOD_AUTO, "AUTO"),
@@ -58,9 +53,8 @@ class DistanceMeasurementInitiator {
private final Context mApplicationContext;
private final Executor mBtExecutor;
private final BtDistanceMeasurementCallback mBtDistanceMeasurementCallback;
- private String mTargetBtAddress = "";
- @Nullable private BluetoothGatt mBluetoothGatt = null;
@Nullable private DistanceMeasurementSession mSession = null;
+ @Nullable private BluetoothDevice mTargetDevice = null;
DistanceMeasurementInitiator(
Context applicationContext,
@@ -77,70 +71,8 @@ class DistanceMeasurementInitiator {
mBtExecutor = Executors.newSingleThreadExecutor();
}
- void setTargetBtAddress(String btAddress) {
- mTargetBtAddress = btAddress;
- }
-
- @SuppressLint("MissingPermission") // permissions are checked upfront
- List updatePairedDevice() {
- List arrayList = new ArrayList<>();
- Set bonded_devices = mBluetoothAdapter.getBondedDevices();
- for (BluetoothDevice device : bonded_devices) {
- arrayList.add(device.getAddress());
- }
- printLog("Num of paired Devices: " + arrayList.size());
- return arrayList;
- }
-
- @SuppressLint("MissingPermission") // permissions are checked upfront
- void connectGatt() {
- if (mTargetBtAddress == null) {
- printLog("A paired device must be selected first.");
- return;
- }
- BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(mTargetBtAddress);
- BluetoothGattCallback gattCallback =
- new BluetoothGattCallback() {
- @Override
- public void onConnectionStateChange(
- BluetoothGatt gatt, int status, int newState) {
- printLog(
- "onConnectionStateChange status:"
- + status
- + ", newState:"
- + newState);
- if (newState == BluetoothProfile.STATE_CONNECTED) {
- printLog(gatt.getDevice().getName() + " is connected");
- gatt.requestMtu(GATT_MTU_SIZE);
- mBluetoothGatt = gatt;
- mBtDistanceMeasurementCallback.onGattConnected();
- } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
- printLog("disconnected from " + gatt.getDevice().getName());
- mBtDistanceMeasurementCallback.onGattDisconnected();
- mBluetoothGatt.close();
- mBluetoothGatt = null;
- }
- }
-
- public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
- if (status == BluetoothGatt.GATT_SUCCESS) {
- printLog("MTU changed to: " + mtu);
- } else {
- printLog("MTU change failed: " + status);
- }
- }
- };
- printLog("Connect gatt to " + device.getAddress());
-
- device.connectGatt(mApplicationContext, false, gattCallback, BluetoothDevice.TRANSPORT_LE);
- }
-
- @SuppressLint("MissingPermission") // permissions are checked upfront
- void disconnectGatt() {
- if (mBluetoothGatt != null) {
- printLog("disconnect from " + mBluetoothGatt.getDevice().getName());
- mBluetoothGatt.disconnect();
- }
+ void setTargetDevice(BluetoothDevice targetDevice) {
+ mTargetDevice = targetDevice;
}
private void printLog(String log) {
@@ -190,16 +122,15 @@ class DistanceMeasurementInitiator {
@SuppressLint("MissingPermission") // permissions are checked upfront
void startDistanceMeasurement(String distanceMeasurementMethodName) {
- if (mTargetBtAddress == null) {
- printLog("pair and select a valid address.");
+ if (mTargetDevice == null) {
+ printLog("do Gatt connect first");
return;
}
- printLog("start CS with address: " + mTargetBtAddress);
+ printLog("start CS with device: " + mTargetDevice.getName());
- BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(mTargetBtAddress);
DistanceMeasurementParams params =
- new DistanceMeasurementParams.Builder(device)
+ new DistanceMeasurementParams.Builder(mTargetDevice)
.setDurationSeconds(DISTANCE_MEASUREMENT_DURATION_SEC)
.setFrequency(DistanceMeasurementParams.REPORT_FREQUENCY_LOW)
.setMethodId(getDistanceMeasurementMethodId(distanceMeasurementMethodName))
@@ -255,9 +186,5 @@ class DistanceMeasurementInitiator {
void onStop();
void onDistanceResult(double distanceMeters);
-
- void onGattConnected();
-
- void onGattDisconnected();
}
}
diff --git a/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/InitiatorFragment.java b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/InitiatorFragment.java
index 010ef3b9881959a95bca2d551e703f47abccf37f..fe3a211f9f7965d6df3fb5f2b3c0c10a1c174d60 100644
--- a/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/InitiatorFragment.java
+++ b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/InitiatorFragment.java
@@ -22,8 +22,6 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
@@ -32,37 +30,38 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
-import androidx.lifecycle.ViewModelProviders;
+import androidx.fragment.app.FragmentTransaction;
+import androidx.lifecycle.ViewModelProvider;
import java.text.DecimalFormat;
import java.util.ArrayList;
-/** d The fragment holds the initiator of channel sounding. */
+/** The fragment holds the initiator of channel sounding. */
@SuppressWarnings("SetTextI18n")
public class InitiatorFragment extends Fragment {
private static final DecimalFormat DISTANCE_DECIMAL_FMT = new DecimalFormat("0.00");
private ArrayAdapter mDmMethodArrayAdapter;
- private ArrayAdapter mBondedBtDevicesArrayAdapter;
private TextView mDistanceText;
private CanvasView mDistanceCanvasView;
private Spinner mSpinnerDmMethod;
- private Button mButtonUpdate;
private Button mButtonCs;
- private Button mButtonGatt;
- private Spinner mSpinnerBtAddress;
private LinearLayout mDistanceViewLayout;
private TextView mLogText;
+ private BleConnectionViewModel mBleConnectionViewModel;
+ private InitiatorViewModel mInitiatorViewModel;
+
@Override
public View onCreateView(
@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_initiator, container, false);
- mButtonUpdate = (Button) root.findViewById(R.id.btn_update_devices);
+ Fragment bleConnectionFragment = new BleConnectionFragment();
+ FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
+ transaction.replace(R.id.init_ble_connection_container, bleConnectionFragment).commit();
+
mButtonCs = (Button) root.findViewById(R.id.btn_cs);
- mButtonGatt = (Button) root.findViewById(R.id.btn_connect_gatt);
- mSpinnerBtAddress = (Spinner) root.findViewById(R.id.spinner_bt_address);
mSpinnerDmMethod = (Spinner) root.findViewById(R.id.spinner_dm_method);
mDistanceViewLayout = (LinearLayout) root.findViewById(R.id.layout_distance_view);
mDistanceText = new TextView(getContext());
@@ -87,28 +86,24 @@ public class InitiatorFragment extends Fragment {
android.R.layout.simple_spinner_dropdown_item);
mSpinnerDmMethod.setAdapter(mDmMethodArrayAdapter);
- mBondedBtDevicesArrayAdapter =
- new ArrayAdapter(
- getContext(), android.R.layout.simple_spinner_item, new ArrayList<>());
- mBondedBtDevicesArrayAdapter.setDropDownViewResource(
- android.R.layout.simple_spinner_dropdown_item);
- mSpinnerBtAddress.setAdapter(mBondedBtDevicesArrayAdapter);
-
- InitiatorViewModel initiatorViewModel =
- ViewModelProviders.of(getActivity()).get(InitiatorViewModel.class);
-
- initiatorViewModel
- .getGattConnected()
+ mInitiatorViewModel = new ViewModelProvider(this).get(InitiatorViewModel.class);
+ mBleConnectionViewModel = new ViewModelProvider(this).get(BleConnectionViewModel.class);
+ mBleConnectionViewModel
+ .getLogText()
.observe(
getActivity(),
- connected -> {
- if (connected) {
- mButtonGatt.setText("Disconnect Gatt");
- } else {
- mButtonGatt.setText("Connect Gatt");
- }
+ log -> {
+ mLogText.setText(log);
+ });
+ mBleConnectionViewModel
+ .getTargetDevice()
+ .observe(
+ getActivity(),
+ targetDevice -> {
+ mInitiatorViewModel.setTargetDevice(targetDevice);
});
- initiatorViewModel
+
+ mInitiatorViewModel
.getCsStarted()
.observe(
getActivity(),
@@ -120,36 +115,7 @@ public class InitiatorFragment extends Fragment {
mButtonCs.setText("Start Distance Measurement");
}
});
- initiatorViewModel
- .getBondedBtDeviceAddresses()
- .observe(
- getActivity(),
- deviceList -> {
- mBondedBtDevicesArrayAdapter.clear();
- mBondedBtDevicesArrayAdapter.addAll(deviceList);
- if (mSpinnerBtAddress.getSelectedItem() != null) {
- String selectedBtAddress =
- mSpinnerBtAddress.getSelectedItem().toString();
- printLog("set target address: ");
- initiatorViewModel.setCsTargetAddress(selectedBtAddress);
- }
- });
- mSpinnerBtAddress.setOnItemSelectedListener(
- new OnItemSelectedListener() {
- @Override
- public void onItemSelected(
- AdapterView> adapterView, View view, int i, long l) {
- String btAddress = mSpinnerBtAddress.getSelectedItem().toString();
- printLog("Target Address: " + btAddress);
- initiatorViewModel.setCsTargetAddress(btAddress);
- }
-
- @Override
- public void onNothingSelected(AdapterView> adapterView) {
- initiatorViewModel.setCsTargetAddress("");
- }
- });
- initiatorViewModel
+ mInitiatorViewModel
.getLogText()
.observe(
getActivity(),
@@ -157,7 +123,7 @@ public class InitiatorFragment extends Fragment {
mLogText.setText(log);
});
- initiatorViewModel
+ mInitiatorViewModel
.getDistanceResult()
.observe(
getActivity(),
@@ -167,41 +133,18 @@ public class InitiatorFragment extends Fragment {
DISTANCE_DECIMAL_FMT.format(distanceMeters) + " m");
});
- mDmMethodArrayAdapter.addAll(initiatorViewModel.getSupportedDmMethods());
+ mDmMethodArrayAdapter.addAll(mInitiatorViewModel.getSupportedDmMethods());
- mButtonUpdate.setOnClickListener(
- v -> {
- printLog("click update Bonded Devices.");
- initiatorViewModel.updateBondedDevices();
- });
- mButtonGatt.setOnClickListener(
- v -> {
- if (!hasValidTarget()) return;
- initiatorViewModel.toggleGattConnection();
- });
mButtonCs.setOnClickListener(
v -> {
- if (!hasValidTarget()) return;
String methodName = mSpinnerDmMethod.getSelectedItem().toString();
if (TextUtils.isEmpty(methodName)) {
printLog("the device doesn't support any distance measurement methods.");
}
- initiatorViewModel.toggleCsStartStop(methodName);
+ mInitiatorViewModel.toggleCsStartStop(methodName);
});
}
- private boolean hasValidTarget() {
- String btAddress = "";
- if (mSpinnerBtAddress.getSelectedItem() != null) {
- btAddress = mSpinnerBtAddress.getSelectedItem().toString();
- }
- if (TextUtils.isEmpty(btAddress)) {
- printLog("Pair and select a target device first!");
- return false;
- }
- return true;
- }
-
private void printLog(String logMessage) {
mLogText.setText("LOG: " + logMessage);
}
diff --git a/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/InitiatorViewModel.java b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/InitiatorViewModel.java
index ae6459976306d0ea9c8ba2bdf689e0b0da7547a7..f54ec7b94a6b859b91fe46e8b4aa84787a5008e4 100644
--- a/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/InitiatorViewModel.java
+++ b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/InitiatorViewModel.java
@@ -17,6 +17,7 @@
package com.android.bluetooth.channelsoundingtestapp;
import android.app.Application;
+import android.bluetooth.BluetoothDevice;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
@@ -32,9 +33,8 @@ public class InitiatorViewModel extends AndroidViewModel {
private final MutableLiveData mLogText = new MutableLiveData<>();
private final MutableLiveData mCsStarted = new MutableLiveData<>(false);
- private final MutableLiveData> mBondedBtDeviceAddresses = new MutableLiveData<>();
+
private final MutableLiveData mDistanceResult = new MutableLiveData<>();
- private final MutableLiveData mGattConnected = new MutableLiveData<>(false);
private final DistanceMeasurementInitiator
mDistanceMeasurementInitiator; // mDistanceMeasurementInitiator;
@@ -51,42 +51,22 @@ public class InitiatorViewModel extends AndroidViewModel {
});
}
- LiveData getLogText() {
- return mLogText;
+ void setTargetDevice(BluetoothDevice targetDevice) {
+ mDistanceMeasurementInitiator.setTargetDevice(targetDevice);
}
- LiveData getGattConnected() {
- return mGattConnected;
+ LiveData getLogText() {
+ return mLogText;
}
LiveData getCsStarted() {
return mCsStarted;
}
- LiveData> getBondedBtDeviceAddresses() {
- return mBondedBtDeviceAddresses;
- }
-
LiveData getDistanceResult() {
return mDistanceResult;
}
- void setCsTargetAddress(String btAddress) {
- mDistanceMeasurementInitiator.setTargetBtAddress(btAddress);
- }
-
- void updateBondedDevices() {
- mBondedBtDeviceAddresses.setValue(mDistanceMeasurementInitiator.updatePairedDevice());
- }
-
- void toggleGattConnection() {
- if (!mGattConnected.getValue()) {
- mDistanceMeasurementInitiator.connectGatt();
- } else {
- mDistanceMeasurementInitiator.disconnectGatt();
- }
- }
-
List getSupportedDmMethods() {
return mDistanceMeasurementInitiator.getDistanceMeasurementMethods();
}
@@ -118,15 +98,5 @@ public class InitiatorViewModel extends AndroidViewModel {
public void onDistanceResult(double distanceMeters) {
mDistanceResult.postValue(distanceMeters);
}
-
- @Override
- public void onGattConnected() {
- mGattConnected.postValue(true);
- }
-
- @Override
- public void onGattDisconnected() {
- mGattConnected.postValue(false);
- }
};
}
diff --git a/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/MainActivity.java b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/MainActivity.java
index 7162f12a3c489113e202054c856a4062d9ea79e3..a78067c012ffb40d321fb2ef163a69c68c0b9212 100644
--- a/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/MainActivity.java
+++ b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/MainActivity.java
@@ -16,7 +16,7 @@
package com.android.bluetooth.channelsoundingtestapp;
-import android.Manifest;
+import android.Manifest.permission;
import android.content.pm.PackageManager;
import android.os.Bundle;
@@ -55,12 +55,16 @@ public class MainActivity extends AppCompatActivity {
private void requestBtPermissions() {
String[] requiredPermissions =
new String[] {
- android.Manifest.permission.BLUETOOTH_ADVERTISE,
- android.Manifest.permission.BLUETOOTH_CONNECT,
+ permission.ACCESS_COARSE_LOCATION,
+ permission.ACCESS_FINE_LOCATION,
+ permission.BLUETOOTH_ADVERTISE,
+ permission.BLUETOOTH_CONNECT,
+ permission.BLUETOOTH_SCAN,
};
List permissionsToRequest = new ArrayList<>();
+
for (String permission : requiredPermissions) {
- if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT)
+ if (ActivityCompat.checkSelfPermission(this, permission)
!= PackageManager.PERMISSION_GRANTED) {
permissionsToRequest.add(permission);
}
diff --git a/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/ReflectorFragment.java b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/ReflectorFragment.java
index 240529bdc0a6397954c4ef03c34ded91e67baea2..13a8981682533548322d9c231fb8b6fc5cc03ff9 100644
--- a/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/ReflectorFragment.java
+++ b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/ReflectorFragment.java
@@ -19,21 +19,18 @@ package com.android.bluetooth.channelsoundingtestapp;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.View.OnClickListener;
import android.view.ViewGroup;
-import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
-import androidx.lifecycle.ViewModelProviders;
+import androidx.fragment.app.FragmentTransaction;
+import androidx.lifecycle.ViewModelProvider;
/** The fragment holds the reflector of channel sounding. */
@SuppressWarnings("SetTextI18n")
public class ReflectorFragment extends Fragment {
-
- private ReflectorViewModel mReflectorViewModel;
- private Button mBtnAdvertising;
+ private BleConnectionViewModel mBleConnectionViewModel;
private TextView mLogText;
@Override
@@ -41,40 +38,24 @@ public class ReflectorFragment extends Fragment {
@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_reflector, container, false);
- mBtnAdvertising = (Button) root.findViewById(R.id.btn_advertising);
+ Fragment bleConnectionFragment = new BleConnectionFragment();
+ FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
+ transaction.replace(R.id.ref_ble_connection_container, bleConnectionFragment).commit();
mLogText = (TextView) root.findViewById(R.id.text_log);
return root;
}
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
- mReflectorViewModel = ViewModelProviders.of(getActivity()).get(ReflectorViewModel.class);
- mReflectorViewModel
- .getIsAdvertising()
- .observe(
- getActivity(),
- isAdvertising -> {
- if (isAdvertising) {
- mBtnAdvertising.setText("Stop Advertising");
- } else {
- mBtnAdvertising.setText("Start Advertising");
- }
- });
- mReflectorViewModel
+
+ mBleConnectionViewModel = new ViewModelProvider(this).get(BleConnectionViewModel.class);
+ mBleConnectionViewModel
.getLogText()
.observe(
getActivity(),
log -> {
mLogText.setText(log);
});
-
- mBtnAdvertising.setOnClickListener(
- new OnClickListener() {
- @Override
- public void onClick(View view) {
- mReflectorViewModel.toggleAdvertising();
- }
- });
}
@Override
diff --git a/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/ReflectorViewModel.java b/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/ReflectorViewModel.java
deleted file mode 100644
index 98cd4816aee428f4104bb3af432961bf1e964dc5..0000000000000000000000000000000000000000
--- a/android/ChannelSoundingTestApp/app/src/main/java/com/android/bluetooth/channelsoundingtestapp/ReflectorViewModel.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright 2024 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.
- */
-
-package com.android.bluetooth.channelsoundingtestapp;
-
-import android.annotation.SuppressLint;
-import android.app.Application;
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothManager;
-import android.bluetooth.le.AdvertiseData;
-import android.bluetooth.le.AdvertisingSet;
-import android.bluetooth.le.AdvertisingSetCallback;
-import android.bluetooth.le.AdvertisingSetParameters;
-import android.bluetooth.le.BluetoothLeAdvertiser;
-
-import androidx.annotation.NonNull;
-import androidx.lifecycle.AndroidViewModel;
-import androidx.lifecycle.LiveData;
-import androidx.lifecycle.MutableLiveData;
-
-/** ViewModel for the Reflector. */
-@SuppressLint("MissingPermission")
-public class ReflectorViewModel extends AndroidViewModel {
-
- private final BluetoothAdapter mBluetoothAdapter;
- private MutableLiveData mIsAdvertising = new MutableLiveData<>(false);
- private MutableLiveData mLogText = new MutableLiveData<>();
- private AdvertisingSet mAdvertisingSet = null;
-
- /** Constructor */
- public ReflectorViewModel(@NonNull Application application) {
- super(application);
- BluetoothManager bluetoothManager = application.getSystemService(BluetoothManager.class);
- mBluetoothAdapter = bluetoothManager.getAdapter();
- }
-
- LiveData getIsAdvertising() {
- return mIsAdvertising;
- }
-
- LiveData getLogText() {
- return mLogText;
- }
-
- void toggleAdvertising() {
- if (mIsAdvertising.getValue()) {
- stopAdvertising();
- } else {
- startConnectableAdvertising();
- }
- }
-
- private void startConnectableAdvertising() {
- if (mAdvertisingSet != null) {
- mAdvertisingSet.enableAdvertising(!mIsAdvertising.getValue(), 0, 0);
- return;
- }
-
- BluetoothLeAdvertiser advertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();
- AdvertisingSetParameters parameters =
- (new AdvertisingSetParameters.Builder())
- .setLegacyMode(false) // True by default, but set here as a reminder.
- .setConnectable(true)
- .setScannable(false)
- .setInterval(AdvertisingSetParameters.INTERVAL_LOW)
- .setTxPowerLevel(AdvertisingSetParameters.TX_POWER_MEDIUM)
- .build();
-
- AdvertiseData response = (new AdvertiseData.Builder()).setIncludeDeviceName(true).build();
-
- AdvertisingSetCallback callback =
- new AdvertisingSetCallback() {
- @Override
- public void onAdvertisingSetStarted(
- AdvertisingSet advertisingSet, int txPower, int status) {
- printLog(
- "onAdvertisingSetStarted(): txPower:"
- + txPower
- + " , status: "
- + status);
- mAdvertisingSet = advertisingSet;
- if (status == 0) {
- mIsAdvertising.setValue(true);
- }
- }
-
- @Override
- public void onAdvertisingEnabled(
- AdvertisingSet advertisingSet, boolean enable, int status) {
- printLog("enable: " + enable + ", status:" + status);
- if (enable == false) {
- mIsAdvertising.setValue(false);
- } else {
- mIsAdvertising.setValue(true);
- }
- }
-
- @Override
- public void onAdvertisingDataSet(AdvertisingSet advertisingSet, int status) {
- printLog("onAdvertisingDataSet() :status:" + status);
- }
-
- @Override
- public void onScanResponseDataSet(AdvertisingSet advertisingSet, int status) {
- printLog("onScanResponseDataSet(): status:" + status);
- }
-
- @Override
- public void onAdvertisingSetStopped(AdvertisingSet advertisingSet) {
- printLog("onAdvertisingSetStopped():");
- }
- };
-
- printLog("Start connectable advertising");
- advertiser.startAdvertisingSet(parameters, response, null, null, null, 0, 0, callback);
- }
-
- private void stopAdvertising() {
- if (mAdvertisingSet != null) {
- printLog("advertising is stopped.");
- mAdvertisingSet.enableAdvertising(false, 0, 0);
- }
- }
-
- private void printLog(@NonNull String logMsg) {
- mLogText.setValue("BT Log: " + logMsg);
- }
-}
diff --git a/android/ChannelSoundingTestApp/app/src/main/res/layout/fragment_ble_connection.xml b/android/ChannelSoundingTestApp/app/src/main/res/layout/fragment_ble_connection.xml
new file mode 100644
index 0000000000000000000000000000000000000000..5c70cec470d7bec5b9f77e712352d0a03fb4bea4
--- /dev/null
+++ b/android/ChannelSoundingTestApp/app/src/main/res/layout/fragment_ble_connection.xml
@@ -0,0 +1,114 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/ChannelSoundingTestApp/app/src/main/res/layout/fragment_initiator.xml b/android/ChannelSoundingTestApp/app/src/main/res/layout/fragment_initiator.xml
index 66c0c4e4136537e342c19664214fede7ce4681cb..f5f57f2c273979fb10115bf3335b89833957e581 100644
--- a/android/ChannelSoundingTestApp/app/src/main/res/layout/fragment_initiator.xml
+++ b/android/ChannelSoundingTestApp/app/src/main/res/layout/fragment_initiator.xml
@@ -11,38 +11,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
-
-
-
-
+ app:layout_constraintTop_toTopOf="parent" />
+
+ app:layout_constraintTop_toBottomOf="@id/init_ble_connection_container" />
+ app:layout_constraintTop_toBottomOf="@id/init_ble_connection_container" />
-
+ app:layout_constraintTop_toTopOf="parent" />
-
+ app:layout_constraintTop_toBottomOf="@id/ref_ble_connection_container" />
diff --git a/android/ChannelSoundingTestApp/app/src/main/res/navigation/nav_graph.xml b/android/ChannelSoundingTestApp/app/src/main/res/navigation/nav_graph.xml
index d39cc3eaa5e1acb3174cd0207177855f73a3ad2c..66f5ad9d4a8bfc3e5130a0893940da631ee2a2b6 100644
--- a/android/ChannelSoundingTestApp/app/src/main/res/navigation/nav_graph.xml
+++ b/android/ChannelSoundingTestApp/app/src/main/res/navigation/nav_graph.xml
@@ -3,40 +3,40 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
- app:startDestination="@id/RoleSelectionFragment">
+ app:startDestination="@id/role_selection_fragment">
+ app:destination="@id/initiator_fragment" />
+ app:destination="@id/reflector_fragment" />
+ app:destination="@id/role_selection_fragment" />
+ app:destination="@id/role_selection_fragment" />
diff --git a/android/ChannelSoundingTestApp/gradle/libs.versions.toml b/android/ChannelSoundingTestApp/gradle/libs.versions.toml
index 406664134397d5dfdf1ff2c4e70e8627c10d829f..c4350a40e3b759de30b6bd9f99a1d51fad16e857 100644
--- a/android/ChannelSoundingTestApp/gradle/libs.versions.toml
+++ b/android/ChannelSoundingTestApp/gradle/libs.versions.toml
@@ -8,6 +8,9 @@ material = "1.11.0"
constraintlayout = "2.1.4"
navigationFragment = "2.7.7"
navigationUi = "2.7.7"
+legacySupportV4 = "1.0.0"
+lifecycleLivedataKtx = "2.7.0"
+lifecycleViewmodelKtx = "2.7.0"
[libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" }
@@ -18,6 +21,9 @@ material = { group = "com.google.android.material", name = "material", version.r
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
navigation-fragment = { group = "androidx.navigation", name = "navigation-fragment", version.ref = "navigationFragment" }
navigation-ui = { group = "androidx.navigation", name = "navigation-ui", version.ref = "navigationUi" }
+legacy-support-v4 = { group = "androidx.legacy", name = "legacy-support-v4", version.ref = "legacySupportV4" }
+lifecycle-livedata-ktx = { group = "androidx.lifecycle", name = "lifecycle-livedata-ktx", version.ref = "lifecycleLivedataKtx" }
+lifecycle-viewmodel-ktx = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version.ref = "lifecycleViewmodelKtx" }
[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
diff --git a/android/apishim/Android.bp b/android/apishim/Android.bp
index 5febd3261ddab12d00069bae1d112823d18674d2..9d980b24980099efaea9b240bd1dd80eedc296c9 100644
--- a/android/apishim/Android.bp
+++ b/android/apishim/Android.bp
@@ -21,9 +21,7 @@ java_defaults {
name: "BluetoothShimsDefaults",
libs: [
"androidx.annotation_annotation",
- ],
- static_libs : [
- "modules-utils-build_system"
+ "modules-utils-build",
],
apex_available: [
"com.android.btservices",
@@ -40,7 +38,7 @@ java_library {
"BluetoothShimsDefaults",
],
srcs: ["common/**/*.java"],
- sdk_version: "system_current",
+ sdk_version: "module_current",
visibility: ["//visibility:private"],
}
@@ -70,10 +68,10 @@ java_library {
"34/**/*.java",
],
libs: [
- "BluetoothShimsCommon",
"BluetoothApi33Shims",
+ "BluetoothShimsCommon",
],
- sdk_version: "module_current",
+ sdk_version: "module_34",
visibility: ["//visibility:private"],
}
@@ -83,12 +81,12 @@ java_library {
"BluetoothShimsDefaults",
],
static_libs: [
- "BluetoothShimsCommon",
"BluetoothApi33Shims",
"BluetoothApi34Shims",
+ "BluetoothShimsCommon",
],
visibility: [
"//packages/modules/Bluetooth/android/app",
],
sdk_version: "module_33",
-}
\ No newline at end of file
+}
diff --git a/android/apishim/OWNERS b/android/apishim/OWNERS
index a70b577d30f4fda4bb487de3d85565c86ad08053..586d2866f18936c4d8c62907f9a0ac5135f463aa 100644
--- a/android/apishim/OWNERS
+++ b/android/apishim/OWNERS
@@ -1,8 +1,6 @@
# Reviewers for /android/apishim
-cmanton@google.com
eruffieux@google.com
jpawlowski@google.com
-mylesgw@google.com
siyuanh@google.com
-wescande@google.com
\ No newline at end of file
+wescande@google.com
diff --git a/android/app/.clang-format b/android/app/.clang-format
deleted file mode 100644
index 85098f2a60c122814316bf6b34ebf23851ba373a..0000000000000000000000000000000000000000
--- a/android/app/.clang-format
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# Copyright (C) 2016 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.
-#
-
-#
-# Below are some minor deviations from the default Google style to
-# accommodate for handling of the large legacy code base.
-#
-
-BasedOnStyle: Google
-CommentPragmas: NOLINT:.*
-DerivePointerAlignment: false
-
----
-Language: Java
-# Java format is handled by check_style hook
-DisableFormat: true
-SortIncludes: false
diff --git a/android/app/Android.bp b/android/app/Android.bp
index b11a7ecea78b42bdc7d06b5fbd355e5a8a09f028..e6fc97bfc011e853d47fe9e3a2995717ed5336c9 100644
--- a/android/app/Android.bp
+++ b/android/app/Android.bp
@@ -98,11 +98,11 @@ cc_library_shared {
"android.system.suspend-V1-ndk",
"android.system.suspend.control-V1-ndk",
"avrcp-target-service",
+ "bluetooth_flags_c_lib",
"lib-bt-packets-avrcp",
"lib-bt-packets-base",
"libFraunhoferAAC",
"libaconfig_storage_read_api_cc",
- "libaudio-a2dp-hw-utils",
"libbase",
"libbluetooth",
"libbluetooth-dumpsys",
@@ -134,6 +134,8 @@ cc_library_shared {
"libchrome",
"libcutils",
"libevent",
+ "libexpresslog",
+ "libflags_rust_cpp_bridge",
"libflatbuffers-cpp",
"libfmq",
"libg722codec",
@@ -144,6 +146,8 @@ cc_library_shared {
"libosi",
"libprotobuf-cpp-lite",
"libstatslog_bt",
+ "libstatslog_express",
+ "libtextclassifier_hash_static",
"libudrv-uipc",
"libutils",
"server_configurable_flags",
@@ -164,7 +168,6 @@ cc_library_shared {
"com.android.btservices",
],
min_sdk_version: "Tiramisu",
- ldflags: ["-Wl,--allow-multiple-definition"],
// TODO(b/346919576) Workaround LTO build breakage.
lto_O0: true,
@@ -217,6 +220,7 @@ cc_library {
android_app {
name: "Bluetooth",
+ defaults: ["bluetooth_framework_errorprone_rules"],
srcs: [
":statslog-bluetooth-java-gen",
@@ -244,21 +248,22 @@ android_app {
"error_prone_annotations",
"framework-annotations-lib",
"framework-bluetooth-pre-jarjar",
- "framework-configinfrastructure",
+ "framework-configinfrastructure.stubs.module_lib",
"framework-connectivity.stubs.module_lib",
"framework-location.stubs.module_lib",
- "framework-mediaprovider",
+ "framework-mediaprovider.stubs.module_lib",
"framework-statsd.stubs.module_lib",
"framework-tethering.stubs.module_lib",
"unsupportedappusage",
// Need to link the class at runtime
- "framework-bluetooth",
+ "framework-bluetooth.stubs.module_lib",
],
static_libs: [
"BluetoothApiShims",
"android.hardware.radio-V1.0-java",
"android.hardware.radio.sap-V1-java",
+ "android.os.flags-aconfig-java-export",
"androidx.annotation_annotation",
"androidx.core_core",
"androidx.lifecycle_lifecycle-livedata",
@@ -283,6 +288,7 @@ android_app {
plugins: [
"androidx.room_room-compiler-plugin",
+ "error_prone_android_framework",
],
// Export schemas to the test directory so that we have an history
@@ -317,25 +323,6 @@ android_app {
apex_available: [
"com.android.btservices",
],
- errorprone: {
- enabled: true,
- javacflags: [
- // "-Xep:AndroidFrameworkRequiresPermission:ERROR",
- "-Xep:AlmostJavadoc:ERROR",
- "-Xep:BadImport:ERROR",
- "-Xep:ClassCanBeStatic:ERROR",
- "-Xep:EmptyBlockTag:ERROR",
- "-Xep:InlineMeInliner:ERROR",
- "-Xep:InvalidBlockTag:ERROR",
- "-Xep:InvalidParam:ERROR",
- "-Xep:MockNotUsedInProduction:ERROR",
- "-Xep:NonCanonicalType:ERROR",
- "-Xep:ReturnAtTheEndOfVoidFunction:ERROR",
- "-Xep:UnusedMethod:ERROR",
- "-Xep:UnusedVariable:ERROR",
- "-XepExcludedPaths:.*/srcjars/.*", // Exclude generated files
- ],
- },
min_sdk_version: "Tiramisu",
sdk_version: "module_current",
}
diff --git a/android/app/AndroidManifest.xml b/android/app/AndroidManifest.xml
index eeb4719d28755325093123f359cb2df58d50dd5a..c77602c8a7f52658262d5a1d57652e1440edf531 100644
--- a/android/app/AndroidManifest.xml
+++ b/android/app/AndroidManifest.xml
@@ -161,13 +161,6 @@
-
-
getUuids(in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
@@ -71,12 +69,12 @@ interface IBluetooth
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN)")
int getScanMode(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_SCAN,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int setScanMode(int mode, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN)")
long getDiscoverableTimeout(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_SCAN,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int setDiscoverableTimeout(long timeout, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN)")
@@ -117,13 +115,13 @@ interface IBluetooth
int getRemoteType(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
String getRemoteAlias(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT})")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED}, conditional=true)")
int setRemoteAlias(in BluetoothDevice device, in String name, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
int getRemoteClass(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
List getRemoteUuids(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED}, conditional=true)")
boolean fetchRemoteUuids(in BluetoothDevice device, in int transport, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
boolean sdpSearch(in BluetoothDevice device, in ParcelUuid uuid, in AttributionSource attributionSource);
@@ -210,7 +208,7 @@ interface IBluetooth
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean registerMetadataListener(in IBluetoothMetadataListener listener, in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- boolean unregisterMetadataListener(in BluetoothDevice device, in AttributionSource attributionSource);
+ boolean unregisterMetadataListener(in IBluetoothMetadataListener listener, in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean setMetadata(in BluetoothDevice device, in int key, in byte[] value, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
@@ -226,10 +224,10 @@ interface IBluetooth
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
oneway void requestActivityInfo(in IBluetoothActivityEnergyInfoListener listener, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- oneway void startBrEdr(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- oneway void stopBle(in AttributionSource attributionSource);
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ oneway void bleOnToOn(in AttributionSource attributionSource);
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ oneway void bleOnToOff(in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED,android.Manifest.permission.MODIFY_PHONE_STATE})")
int connectAllEnabledProfiles(in BluetoothDevice device, in AttributionSource attributionSource);
@@ -253,18 +251,18 @@ interface IBluetooth
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean canBondWithoutDialog(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- String getPackageNameOfBondingApplication(in BluetoothDevice device);
+ String getPackageNameOfBondingApplication(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void generateLocalOobData(in int transport, IBluetoothOobDataCallback callback, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean allowLowLatencyAudio(in boolean allowed, in BluetoothDevice device);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int isRequestAudioPolicyAsSinkSupported(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int requestAudioPolicyAsSink(in BluetoothDevice device, in BluetoothSinkAudioPolicy policies, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
BluetoothSinkAudioPolicy getRequestedAudioPolicyAsSink(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
@@ -282,6 +280,8 @@ interface IBluetooth
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
Bundle getPreferredAudioProfiles(in BluetoothDevice device, in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
+ int isDualModeAudioEnabled(in AttributionSource attributionSource);
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int registerPreferredAudioProfilesChangedCallback(in IBluetoothPreferredAudioProfilesCallback callback, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int unregisterPreferredAudioProfilesChangedCallback(in IBluetoothPreferredAudioProfilesCallback callback, in AttributionSource attributionSource);
@@ -305,7 +305,7 @@ interface IBluetooth
@JavaPassthrough(annotation="@android.annotation.RequiresNoPermission")
IBinder getBluetoothScan();
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
oneway void unregAllGattClient(in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresNoPermission")
diff --git a/android/app/aidl/android/bluetooth/IBluetoothA2dp.aidl b/android/app/aidl/android/bluetooth/IBluetoothA2dp.aidl
index a70edc2872a4a123034be356b0b34ac27e2109d6..bcfc95585da9917faa0bfd0a6be756b0958c4d62 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothA2dp.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothA2dp.aidl
@@ -52,10 +52,10 @@ interface IBluetoothA2dp {
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
boolean isA2dpPlaying(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
- List getSupportedCodecTypes(in AttributionSource attributionSource);
+ List getSupportedCodecTypes();
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
BluetoothCodecStatus getCodecStatus(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED}, conditional=true)")
oneway void setCodecConfigPreference(in BluetoothDevice device, in BluetoothCodecConfig codecConfig, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
oneway void enableOptionalCodecs(in BluetoothDevice device, in AttributionSource attributionSource);
diff --git a/android/app/aidl/android/bluetooth/IBluetoothAvrcpTarget.aidl b/android/app/aidl/android/bluetooth/IBluetoothAvrcpTarget.aidl
deleted file mode 100644
index 64fbb7c518c66092064d938610df1c95ce730fc2..0000000000000000000000000000000000000000
--- a/android/app/aidl/android/bluetooth/IBluetoothAvrcpTarget.aidl
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2018 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.
- */
-
-package android.bluetooth;
-
-/**
- * API for Bluetooth AVRCP Target Interface
- *
- * @hide
- */
-interface IBluetoothAvrcpTarget {
- /**
- * @hide
- */
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
- void sendVolumeChanged(in int volume);
-}
diff --git a/android/app/aidl/android/bluetooth/IBluetoothBattery.aidl b/android/app/aidl/android/bluetooth/IBluetoothBattery.aidl
deleted file mode 100644
index 167bac88cf4d395f4326d135381415ecd7704755..0000000000000000000000000000000000000000
--- a/android/app/aidl/android/bluetooth/IBluetoothBattery.aidl
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2022, 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.
- */
-
-package android.bluetooth;
-
-import android.bluetooth.BluetoothDevice;
-import android.content.AttributionSource;
-
-/**
- * APIs for Bluetooth Battery service
- *
- * @hide
- */
-interface IBluetoothBattery {
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
- boolean connect(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
- boolean disconnect(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
- List getConnectedDevices(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
- List getDevicesMatchingConnectionStates(in int[] states, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
- int getConnectionState(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- boolean setConnectionPolicy(in BluetoothDevice device, int connectionPolicy, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- int getConnectionPolicy(in BluetoothDevice device, in AttributionSource attributionSource);
-}
diff --git a/android/app/aidl/android/bluetooth/IBluetoothCallback.aidl b/android/app/aidl/android/bluetooth/IBluetoothCallback.aidl
index 3c0680f08040e4b7272641a5bdc6d0549fe92e24..9b2888eadbf156735b824d9de31b8bc54f86dca9 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothCallback.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothCallback.aidl
@@ -23,6 +23,7 @@ package android.bluetooth;
*/
interface IBluetoothCallback
{
- //void onRfcommChannelFound(int channel);
void onBluetoothStateChange(int prevState, int newState);
+ void onAdapterNameChange(String name);
+ void onAdapterAddressChange(String address);
}
diff --git a/android/app/aidl/android/bluetooth/IBluetoothCsipSetCoordinator.aidl b/android/app/aidl/android/bluetooth/IBluetoothCsipSetCoordinator.aidl
index b4ba5300c7f2c95b55080e1d9182f1ae01fbaabf..6e95453e141569ee5f2a3481b7680ca7e19bcd73 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothCsipSetCoordinator.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothCsipSetCoordinator.aidl
@@ -30,55 +30,25 @@ import java.util.Map;
* @hide
*/
interface IBluetoothCsipSetCoordinator {
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
- boolean connect(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
- boolean disconnect(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
List getConnectedDevices(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
List getDevicesMatchingConnectionStates(in int[] states, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getConnectionState(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean setConnectionPolicy(in BluetoothDevice device, int connectionPolicy, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getConnectionPolicy(in BluetoothDevice device, in AttributionSource attributionSource);
-
- /**
- * Get the list of group identifiers for the given context {@var uuid}.
- * @return group identifiers as List
- */
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
List getAllGroupIds(in ParcelUuid uuid, in AttributionSource attributionSource);
-
- /**
- * Get all groups that {@var device} belongs to.
- * @return group identifiers and their context uuids as Map
- */
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
Map getGroupUuidMapByDevice(in BluetoothDevice device, in AttributionSource attributionSource);
-
- /**
- * Get the number of known group members or
- * {@link android.bluetooth.IBluetoothCsipSetCoordinator.CSIS_GROUP_SIZE_UNKNOWN} if unknown.
- * @return group size
- */
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getDesiredGroupSize(in int group_id, in AttributionSource attributionSource);
-
- /**
- * Lock group identified with {@var groupId}.
- * @return unique lock identifier required for unlocking
- */
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
ParcelUuid lockGroup(int groupId, in IBluetoothCsipSetCoordinatorLockCallback callback, in AttributionSource attributionSource);
-
- /**
- * Unlock group using {@var lockUuid} acquired through
- * {@link android.bluetooth.IBluetoothCsipSetCoordinator.lockGroup}.
- */
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void unlockGroup(in ParcelUuid lockUuid, in AttributionSource attributionSource);
const int CSIS_GROUP_ID_INVALID = -1;
diff --git a/android/app/aidl/android/bluetooth/IBluetoothGatt.aidl b/android/app/aidl/android/bluetooth/IBluetoothGatt.aidl
index 4d72cfb6b39b02bb0142f693c27b86fd211cb695..e09f6e9d037480d2c6befe7d0d66ef2aa41fcbf5 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothGatt.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothGatt.aidl
@@ -65,7 +65,7 @@ interface IBluetoothGatt {
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN)")
void flushPendingBatchResults(in int scannerId, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_ADVERTISE)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_ADVERTISE,android.Manifest.permission.BLUETOOTH_PRIVILEGED}, conditional=true)")
void startAdvertisingSet(in AdvertisingSetParameters parameters, in AdvertiseData advertiseData,
in AdvertiseData scanResponse, in PeriodicAdvertisingParameters periodicParameters,
in AdvertiseData periodicData, in int duration, in int maxExtAdvEvents, in int gattServerIf,
@@ -174,7 +174,7 @@ interface IBluetoothGatt {
in boolean confirm, in byte[] value, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
void disconnectAll(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN)")
int numHwTrackFiltersAvailable(in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
void leSubrateRequest(in int clientIf, in String address, in int subrateMin, in int subrateMax, in int maxLatency,
diff --git a/android/app/aidl/android/bluetooth/IBluetoothHapClient.aidl b/android/app/aidl/android/bluetooth/IBluetoothHapClient.aidl
index e7b1863f3e91f1018cfb40d4fee884daad2a751b..12440e4f2c6c841d2aa7a7f3dffb9d89010adcab 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothHapClient.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothHapClient.aidl
@@ -28,21 +28,21 @@ import android.content.AttributionSource;
* @hide
*/
interface IBluetoothHapClient {
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
List getConnectedDevices(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
List getDevicesMatchingConnectionStates(in int[] states, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getConnectionState(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean setConnectionPolicy(in BluetoothDevice device, int connectionPolicy, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getConnectionPolicy(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getHapGroup(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getActivePresetIndex(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
BluetoothHapPresetInfo getActivePresetInfo(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
oneway void selectPreset(in BluetoothDevice device, int presetIndex, in AttributionSource attributionSource);
@@ -56,11 +56,11 @@ interface IBluetoothHapClient {
oneway void switchToPreviousPreset(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
oneway void switchToPreviousPresetForGroup(int groupId, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
BluetoothHapPresetInfo getPresetInfo(in BluetoothDevice device, int presetIndex, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
List getAllPresetInfo(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getFeatures(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
oneway void setPresetName(in BluetoothDevice device, int presetIndex, in String name, in AttributionSource attributionSource);
diff --git a/android/app/aidl/android/bluetooth/IBluetoothHeadset.aidl b/android/app/aidl/android/bluetooth/IBluetoothHeadset.aidl
index 15c353064d3c3e906ca10d6528cfd25fa0d59f3a..9f63f37dc0ca9c190d335c2b52b51e746905f5da 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothHeadset.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothHeadset.aidl
@@ -35,7 +35,7 @@ interface IBluetoothHeadset {
List getDevicesMatchingConnectionStates(in int[] states, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
int getConnectionState(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.MODIFY_PHONE_STATE})")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
boolean startVoiceRecognition(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
boolean stopVoiceRecognition(in BluetoothDevice device, in AttributionSource attributionSource);
@@ -55,20 +55,18 @@ interface IBluetoothHeadset {
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getAudioState(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- boolean isAudioOn(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int connectAudio(in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int disconnectAudio(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void setAudioRouteAllowed(boolean allowed, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean getAudioRouteAllowed(in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
void setForceScoAudio(boolean forced, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.MODIFY_PHONE_STATE})")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.MODIFY_PHONE_STATE,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean startScoUsingVirtualVoiceCall(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.MODIFY_PHONE_STATE})")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.MODIFY_PHONE_STATE,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean stopScoUsingVirtualVoiceCall(in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.MODIFY_PHONE_STATE})")
void phoneStateChanged(int numActive, int numHeld, int callState, String number, int type, String name, in AttributionSource attributionSource);
@@ -78,7 +76,7 @@ interface IBluetoothHeadset {
boolean setActiveDevice(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
BluetoothDevice getActiveDevice(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean isInbandRingingEnabled(in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
diff --git a/android/app/aidl/android/bluetooth/IBluetoothHeadsetClient.aidl b/android/app/aidl/android/bluetooth/IBluetoothHeadsetClient.aidl
index eef7d80e6c0e5eb9f7a6448781f4b20eef3beebf..59c5f98bfb9989e7be2408b799e862cc15954650 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothHeadsetClient.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothHeadsetClient.aidl
@@ -33,15 +33,15 @@ interface IBluetoothHeadsetClient {
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
boolean disconnect(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
List getConnectedDevices(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
List getDevicesMatchingConnectionStates(in int[] states, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getConnectionState(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean setConnectionPolicy(in BluetoothDevice device, int connectionPolicy, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getConnectionPolicy(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
@@ -51,7 +51,7 @@ interface IBluetoothHeadsetClient {
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
List getCurrentCalls(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
Bundle getCurrentAgEvents(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
diff --git a/android/app/aidl/android/bluetooth/IBluetoothHearingAid.aidl b/android/app/aidl/android/bluetooth/IBluetoothHearingAid.aidl
index 7a89ef23952dc01115257e2893fea0f3ce23432d..29e5a1f792d182c333e34507a85284e722bad0dd 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothHearingAid.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothHearingAid.aidl
@@ -45,7 +45,7 @@ interface IBluetoothHearingAid {
boolean setConnectionPolicy(in BluetoothDevice device, int connectionPolicy, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getConnectionPolicy(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void setVolume(int volume, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
diff --git a/android/app/aidl/android/bluetooth/IBluetoothLeAudio.aidl b/android/app/aidl/android/bluetooth/IBluetoothLeAudio.aidl
index 0461df8904f3cca42a9accf0c1f4e17389dc3030..f026d2c1a0c95908e37b4d4bc102f984f5e58670 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothLeAudio.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothLeAudio.aidl
@@ -51,18 +51,18 @@ interface IBluetoothLeAudio {
List getActiveDevices(in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean setConnectionPolicy(in BluetoothDevice device, int connectionPolicy, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getConnectionPolicy(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
BluetoothDevice getConnectedGroupLeadDevice(int groupId, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
BluetoothLeAudioCodecStatus getCodecStatus(in int groupId, in AttributionSource source);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void setCodecConfigPreference(in int groupId, in BluetoothLeAudioCodecConfig inputCodecConfig, in BluetoothLeAudioCodecConfig outputCodecConfig, in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- void registerCallback(in IBluetoothLeAudioCallback callback, in AttributionSource attributionSource);
+ oneway void registerCallback(in IBluetoothLeAudioCallback callback, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- void unregisterCallback(in IBluetoothLeAudioCallback callback, in AttributionSource attributionSource);
+ oneway void unregisterCallback(in IBluetoothLeAudioCallback callback, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void setCcidInformation(in ParcelUuid userUuid, in int ccid, in int contextType, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
@@ -111,16 +111,16 @@ interface IBluetoothLeAudio {
void stopBroadcast(int broadcastId, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void updateBroadcast(int broadcastId, in BluetoothLeBroadcastSettings broadcastSettings, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT})")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean isPlaying(int broadcastId, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
List getAllBroadcastMetadata(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT})")
- int getMaximumNumberOfBroadcasts(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT})")
- int getMaximumStreamsPerBroadcast(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT})")
- int getMaximumSubgroupsPerBroadcast(in AttributionSource attributionSource);
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
+ int getMaximumNumberOfBroadcasts();
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
+ int getMaximumStreamsPerBroadcast();
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
+ int getMaximumSubgroupsPerBroadcast();
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean isBroadcastActive(in AttributionSource attributionSource);
}
diff --git a/android/app/aidl/android/bluetooth/IBluetoothLeBroadcastAssistant.aidl b/android/app/aidl/android/bluetooth/IBluetoothLeBroadcastAssistant.aidl
index 789868544ae81d92099c45160fabc8127318df63..bf95bb5ceec7c3171b65400a83d3d954c4d8cb3a 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothLeBroadcastAssistant.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothLeBroadcastAssistant.aidl
@@ -21,6 +21,7 @@ import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
import android.bluetooth.IBluetoothLeBroadcastAssistantCallback;
import android.bluetooth.le.ScanFilter;
+import android.content.AttributionSource;
/**
* APIs for Bluetooth LE Audio Broadcast Assistant service
@@ -30,32 +31,33 @@ import android.bluetooth.le.ScanFilter;
interface IBluetoothLeBroadcastAssistant {
// Public API
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- int getConnectionState(in BluetoothDevice sink);
+ int getConnectionState(in BluetoothDevice sink, in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- List getDevicesMatchingConnectionStates(in int[] states);
+ List getDevicesMatchingConnectionStates(in int[] states, in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- List getConnectedDevices();
+ List getConnectedDevices(in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- boolean setConnectionPolicy(in BluetoothDevice device, int connectionPolicy);
+ boolean setConnectionPolicy(in BluetoothDevice device, int connectionPolicy, in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- int getConnectionPolicy(in BluetoothDevice device);
+ int getConnectionPolicy(in BluetoothDevice device, in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- void registerCallback(in IBluetoothLeBroadcastAssistantCallback cb);
+ void registerCallback(in IBluetoothLeBroadcastAssistantCallback cb, in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- void unregisterCallback(in IBluetoothLeBroadcastAssistantCallback cb);
+ void unregisterCallback(in IBluetoothLeBroadcastAssistantCallback cb, in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_SCAN,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- void startSearchingForSources(in List filters);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- void stopSearchingForSources();
+ void startSearchingForSources(in List filters, in AttributionSource source);
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_SCAN,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
+ void stopSearchingForSources(in AttributionSource source);
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_SCAN,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
+ boolean isSearchInProgress(in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- boolean isSearchInProgress();
+ void addSource(in BluetoothDevice sink, in BluetoothLeBroadcastMetadata sourceMetadata, in boolean isGroupOp, in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- void addSource(in BluetoothDevice sink, in BluetoothLeBroadcastMetadata sourceMetadata, in boolean isGroupOp);
+ void modifySource(in BluetoothDevice sink, in int sourceId, in BluetoothLeBroadcastMetadata updatedMetadata, in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- void modifySource(in BluetoothDevice sink, in int sourceId, in BluetoothLeBroadcastMetadata updatedMetadata);
+ void removeSource(in BluetoothDevice sink, in int sourceId, in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- void removeSource(in BluetoothDevice sink, in int sourceId);
+ List getAllSources(in BluetoothDevice sink, in AttributionSource source);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
- List getAllSources(in BluetoothDevice sink);
- int getMaximumSourceCapacity(in BluetoothDevice sink);
+ int getMaximumSourceCapacity(in BluetoothDevice sink, in AttributionSource source);
}
diff --git a/android/app/aidl/android/bluetooth/IBluetoothLeBroadcastCallback.aidl b/android/app/aidl/android/bluetooth/IBluetoothLeBroadcastCallback.aidl
index d4df7c8dd5b3a6f1834402bf998df34814d6d247..aa9f3925cc6f7b474c577ad11fac9bc4779efd6e 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothLeBroadcastCallback.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothLeBroadcastCallback.aidl
@@ -23,22 +23,13 @@ import android.bluetooth.BluetoothLeBroadcastMetadata;
* @hide
*/
oneway interface IBluetoothLeBroadcastCallback {
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onBroadcastStarted(in int reason, in int broadcastId);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onBroadcastStartFailed(in int reason);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onBroadcastStopped(in int reason, in int broadcastId);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onBroadcastStopFailed(in int reason);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onPlaybackStarted(in int reason, in int broadcastId);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onPlaybackStopped(in int reason, in int broadcastId);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onBroadcastUpdated(in int reason, in int broadcastId);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onBroadcastUpdateFailed(in int reason, in int broadcastId);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onBroadcastMetadataChanged(in int broadcastId, in BluetoothLeBroadcastMetadata metadata);
}
diff --git a/android/app/aidl/android/bluetooth/IBluetoothLeCallControl.aidl b/android/app/aidl/android/bluetooth/IBluetoothLeCallControl.aidl
index a0939f4a5eed48f94cdba378269e2a5e008cb370..b023b785355eb78387228f314bdda1147c8bebaa 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothLeCallControl.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothLeCallControl.aidl
@@ -26,21 +26,21 @@ import android.os.ParcelUuid;
* @hide
*/
oneway interface IBluetoothLeCallControl {
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void registerBearer(in String token, in IBluetoothLeCallControlCallback callback, in String uci, in List uriSchemes,
in int capabilities, in String provider, in int technology, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void unregisterBearer(in String token, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void requestResult(in int ccid, in int requestId, in int result, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void callAdded(in int ccid, in BluetoothLeCall call, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void callRemoved(in int ccid, in ParcelUuid callId, in int reason, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void callStateChanged(in int ccid, in ParcelUuid callId, in int state, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void currentCallsList(in int ccid, in List calls, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
void networkStateChanged(in int ccid, in String provider, in int technology, in AttributionSource attributionSource);
}
diff --git a/android/app/aidl/android/bluetooth/IBluetoothLeCallControlCallback.aidl b/android/app/aidl/android/bluetooth/IBluetoothLeCallControlCallback.aidl
index 715fa7626b6eff1cf6f7f6b22eb77374e1bf104c..94125de8f8285f2857ee7a63466dbc3d7fddf403 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothLeCallControlCallback.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothLeCallControlCallback.aidl
@@ -26,18 +26,11 @@ import android.os.ParcelUuid;
* @hide
*/
oneway interface IBluetoothLeCallControlCallback {
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onBearerRegistered(in int ccid);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onAcceptCall(in int requestId, in ParcelUuid uuid);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onTerminateCall(in int requestId, in ParcelUuid uuid);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onHoldCall(in int requestId, in ParcelUuid uuid);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onUnholdCall(in int requestId, in ParcelUuid uuid);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onPlaceCall(in int requestId, in ParcelUuid uuid, in String uri);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
void onJoinCalls(in int requestId, in List uuids);
}
diff --git a/android/app/aidl/android/bluetooth/IBluetoothMapClient.aidl b/android/app/aidl/android/bluetooth/IBluetoothMapClient.aidl
index 38aa2c4bd3458fced85d73ddc5572427a97f40c8..a06a7fc0dcdafdd6cf324e13ac864af99800ff7b 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothMapClient.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothMapClient.aidl
@@ -31,24 +31,17 @@ interface IBluetoothMapClient {
boolean connect(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED })")
boolean disconnect(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
- boolean isConnected(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED })")
List getConnectedDevices(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED })")
List getDevicesMatchingConnectionStates(in int[] states, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED })")
int getConnectionState(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED })")
boolean setConnectionPolicy(in BluetoothDevice device,in int connectionPolicy, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED })")
int getConnectionPolicy(in BluetoothDevice device, in AttributionSource attributionSource);
+
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.SEND_SMS })")
boolean sendMessage(in BluetoothDevice device, in Uri[] contacts, in String message, in PendingIntent sentIntent, in PendingIntent deliveryIntent, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.READ_SMS })")
- boolean getUnreadMessages(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
- int getSupportedFeatures(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf = { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.READ_SMS })")
- boolean setMessageStatus(in BluetoothDevice device, in String handle, in int status, in AttributionSource attributionSource);
}
diff --git a/android/app/aidl/android/bluetooth/IBluetoothPbapClient.aidl b/android/app/aidl/android/bluetooth/IBluetoothPbapClient.aidl
index 1512e44a64ace6f8319db1e1ccfb418411f020ea..7cc66d08ac0a95a1eb9f77b8b47a57d1b78d3411 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothPbapClient.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothPbapClient.aidl
@@ -29,11 +29,11 @@ interface IBluetoothPbapClient {
boolean connect(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean disconnect(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
List getConnectedDevices(in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
List getDevicesMatchingConnectionStates(in int[] states, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
int getConnectionState(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean setConnectionPolicy(in BluetoothDevice device, int connectionPolicy, in AttributionSource attributionSource);
diff --git a/android/app/aidl/android/bluetooth/IBluetoothScan.aidl b/android/app/aidl/android/bluetooth/IBluetoothScan.aidl
index 636e149fe409676516c15e11fefe715330b15285..de597d292b4c91e2466401d2fb51ff1875877192 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothScan.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothScan.aidl
@@ -58,6 +58,6 @@ interface IBluetoothScan {
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN)")
void transferSetInfo(in BluetoothDevice bda, in int serviceData, in int advertisingHandle, in IPeriodicAdvertisingCallback callback, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_SCAN)")
int numHwTrackFiltersAvailable(in AttributionSource attributionSource);
}
diff --git a/android/app/aidl/android/bluetooth/IBluetoothVolumeControl.aidl b/android/app/aidl/android/bluetooth/IBluetoothVolumeControl.aidl
index c535ef75cfc44d3affc1c43fc0da7713968807b3..e4509661c875b15680a7426fd2557cc388b96b2e 100644
--- a/android/app/aidl/android/bluetooth/IBluetoothVolumeControl.aidl
+++ b/android/app/aidl/android/bluetooth/IBluetoothVolumeControl.aidl
@@ -30,16 +30,11 @@ interface IBluetoothVolumeControl {
const int VOLUME_CONTROL_UNKNOWN_VOLUME = -1;
- /* Public API */
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
- boolean connect(in BluetoothDevice device, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
- boolean disconnect(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
List getConnectedDevices(in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
List getDevicesMatchingConnectionStates(in int[] states, in AttributionSource attributionSource);
- @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
+ @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
int getConnectionState(in BluetoothDevice device, in AttributionSource attributionSource);
@JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
boolean setConnectionPolicy(in BluetoothDevice device, int connectionPolicy, in AttributionSource attributionSource);
diff --git a/android/app/jni/com_android_bluetooth.h b/android/app/jni/com_android_bluetooth.h
index 3723a239282c0943877e0b6a31308cf9398ee791..c473b50ac699b73a28bf1917e0e4882b63154fc8 100644
--- a/android/app/jni/com_android_bluetooth.h
+++ b/android/app/jni/com_android_bluetooth.h
@@ -33,99 +33,93 @@ bool isCallbackThread();
class CallbackEnv {
public:
- CallbackEnv(const char *methodName) : mName(methodName) {
- mCallbackEnv = getCallbackEnv();
- }
+ CallbackEnv(const char* methodName) : mName(methodName) { mCallbackEnv = getCallbackEnv(); }
- ~CallbackEnv() {
- if (mCallbackEnv && mCallbackEnv->ExceptionCheck()) {
- log::error("An exception was thrown by callback '{}'.", mName);
- jniLogException(mCallbackEnv, ANDROID_LOG_ERROR, LOG_TAG);
- mCallbackEnv->ExceptionClear();
- }
+ ~CallbackEnv() {
+ if (mCallbackEnv && mCallbackEnv->ExceptionCheck()) {
+ log::error("An exception was thrown by callback '{}'.", mName);
+ jniLogException(mCallbackEnv, ANDROID_LOG_ERROR, LOG_TAG);
+ mCallbackEnv->ExceptionClear();
}
+ }
- bool valid() const {
- if (!mCallbackEnv || !isCallbackThread()) {
- log::error("{}: Callback env fail", mName);
- return false;
- }
- return true;
+ bool valid() const {
+ if (!mCallbackEnv || !isCallbackThread()) {
+ log::error("{}: Callback env fail", mName);
+ return false;
}
-
- // stolen from art/runtime/jni/check_jni.cc
- bool isValidUtf(const char* bytes) const {
- while (*bytes != '\0') {
- const uint8_t* utf8 = reinterpret_cast(bytes++);
- // Switch on the high four bits.
- switch (*utf8 >> 4) {
- case 0x00:
- case 0x01:
- case 0x02:
- case 0x03:
- case 0x04:
- case 0x05:
- case 0x06:
- case 0x07:
- // Bit pattern 0xxx. No need for any extra bytes.
- break;
- case 0x08:
- case 0x09:
- case 0x0a:
- case 0x0b:
- // Bit patterns 10xx, which are illegal start bytes.
- return false;
- case 0x0f:
- // Bit pattern 1111, which might be the start of a 4 byte sequence.
- if ((*utf8 & 0x08) == 0) {
- // Bit pattern 1111 0xxx, which is the start of a 4 byte sequence.
- // We consume one continuation byte here, and fall through to
- // consume two more.
- utf8 = reinterpret_cast(bytes++);
- if ((*utf8 & 0xc0) != 0x80) {
- return false;
- }
- } else {
- return false;
- }
- // Fall through to the cases below to consume two more continuation
- // bytes.
- FALLTHROUGH_INTENDED;
- case 0x0e:
- // Bit pattern 1110, so there are two additional bytes.
- utf8 = reinterpret_cast(bytes++);
- if ((*utf8 & 0xc0) != 0x80) {
- return false;
- }
- // Fall through to consume one more continuation byte.
- FALLTHROUGH_INTENDED;
- case 0x0c:
- case 0x0d:
- // Bit pattern 110x, so there is one additional byte.
+ return true;
+ }
+
+ // stolen from art/runtime/jni/check_jni.cc
+ bool isValidUtf(const char* bytes) const {
+ while (*bytes != '\0') {
+ const uint8_t* utf8 = reinterpret_cast(bytes++);
+ // Switch on the high four bits.
+ switch (*utf8 >> 4) {
+ case 0x00:
+ case 0x01:
+ case 0x02:
+ case 0x03:
+ case 0x04:
+ case 0x05:
+ case 0x06:
+ case 0x07:
+ // Bit pattern 0xxx. No need for any extra bytes.
+ break;
+ case 0x08:
+ case 0x09:
+ case 0x0a:
+ case 0x0b:
+ // Bit patterns 10xx, which are illegal start bytes.
+ return false;
+ case 0x0f:
+ // Bit pattern 1111, which might be the start of a 4 byte sequence.
+ if ((*utf8 & 0x08) == 0) {
+ // Bit pattern 1111 0xxx, which is the start of a 4 byte sequence.
+ // We consume one continuation byte here, and fall through to
+ // consume two more.
utf8 = reinterpret_cast(bytes++);
if ((*utf8 & 0xc0) != 0x80) {
return false;
}
- break;
- }
+ } else {
+ return false;
+ }
+ // Fall through to the cases below to consume two more continuation
+ // bytes.
+ [[fallthrough]];
+ case 0x0e:
+ // Bit pattern 1110, so there are two additional bytes.
+ utf8 = reinterpret_cast(bytes++);
+ if ((*utf8 & 0xc0) != 0x80) {
+ return false;
+ }
+ // Fall through to consume one more continuation byte.
+ [[fallthrough]];
+ case 0x0c:
+ case 0x0d:
+ // Bit pattern 110x, so there is one additional byte.
+ utf8 = reinterpret_cast(bytes++);
+ if ((*utf8 & 0xc0) != 0x80) {
+ return false;
+ }
+ break;
}
- return true;
}
+ return true;
+ }
- JNIEnv *operator-> () const {
- return mCallbackEnv;
- }
+ JNIEnv* operator->() const { return mCallbackEnv; }
- JNIEnv *get() const {
- return mCallbackEnv;
- }
+ JNIEnv* get() const { return mCallbackEnv; }
private:
- JNIEnv *mCallbackEnv;
- const char *mName;
+ JNIEnv* mCallbackEnv;
+ const char* mName;
- CallbackEnv(const CallbackEnv&) = delete;
- void operator=(const CallbackEnv&) = delete;
+ CallbackEnv(const CallbackEnv&) = delete;
+ void operator=(const CallbackEnv&) = delete;
};
const bt_interface_t* getBluetoothInterface();
@@ -166,23 +160,22 @@ int register_com_android_bluetooth_vc(JNIEnv* env);
int register_com_android_bluetooth_csip_set_coordinator(JNIEnv* env);
-int register_com_android_bluetooth_btservice_BluetoothQualityReport(
- JNIEnv* env);
+int register_com_android_bluetooth_btservice_BluetoothQualityReport(JNIEnv* env);
struct JNIJavaMethod {
- const char* name;
- const char* signature;
- jmethodID* id;
- bool is_static{false};
+ const char* name;
+ const char* signature;
+ jmethodID* id;
+ bool is_static{false};
};
-void jniGetMethodsOrDie(JNIEnv* env, const char* className,
- const JNIJavaMethod* methods, int nMethods);
+void jniGetMethodsOrDie(JNIEnv* env, const char* className, const JNIJavaMethod* methods,
+ int nMethods);
#define REGISTER_NATIVE_METHODS(env, classname, methodsArray) \
- jniRegisterNativeMethods(env, classname, methodsArray, NELEM(methodsArray))
+ jniRegisterNativeMethods(env, classname, methodsArray, NELEM(methodsArray))
#define GET_JAVA_METHODS(env, classname, methodsArray) \
- jniGetMethodsOrDie(env, classname, methodsArray, NELEM(methodsArray))
+ jniGetMethodsOrDie(env, classname, methodsArray, NELEM(methodsArray))
} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_BluetoothQualityReport.cpp b/android/app/jni/com_android_bluetooth_BluetoothQualityReport.cpp
index 4af4130c592693c25fa9682bfd79d1c9f218bba4..d1d48e93b721b123b5976a9a0004305934e9a7be 100644
--- a/android/app/jni/com_android_bluetooth_BluetoothQualityReport.cpp
+++ b/android/app/jni/com_android_bluetooth_BluetoothQualityReport.cpp
@@ -21,7 +21,6 @@
#include
#include "com_android_bluetooth.h"
-#include "common/init_flags.h"
#include "hardware/bt_bqr.h"
using bluetooth::bqr::BluetoothQualityReportCallbacks;
@@ -30,41 +29,43 @@ using bluetooth::bqr::BluetoothQualityReportInterface;
namespace android {
static jmethodID method_bqrDeliver;
-static BluetoothQualityReportInterface* sBluetoothQualityReportInterface =
- nullptr;
+static BluetoothQualityReportInterface* sBluetoothQualityReportInterface = nullptr;
static std::shared_timed_mutex interface_mutex;
static jobject mCallbacksObj = nullptr;
static std::shared_timed_mutex callbacks_mutex;
-class BluetoothQualityReportCallbacksImpl
- : public bluetooth::bqr::BluetoothQualityReportCallbacks {
- public:
+class BluetoothQualityReportCallbacksImpl : public bluetooth::bqr::BluetoothQualityReportCallbacks {
+public:
~BluetoothQualityReportCallbacksImpl() = default;
- void bqr_delivery_callback(const RawAddress bd_addr, uint8_t lmp_ver,
- uint16_t lmp_subver, uint16_t manufacturer_id,
- std::vector bqr_raw_data) override {
+ void bqr_delivery_callback(const RawAddress bd_addr, uint8_t lmp_ver, uint16_t lmp_subver,
+ uint16_t manufacturer_id, std::vector bqr_raw_data) override {
log::info("");
std::shared_lock lock(callbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
- if (method_bqrDeliver == NULL) return;
- if (mCallbacksObj == nullptr) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
+ if (method_bqrDeliver == NULL) {
+ return;
+ }
+ if (mCallbacksObj == nullptr) {
+ return;
+ }
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Error while allocation byte array for addr");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)bd_addr.address);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)bd_addr.address);
- ScopedLocalRef raw_data(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(bqr_raw_data.size()));
+ ScopedLocalRef raw_data(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(bqr_raw_data.size()));
if (!raw_data.get()) {
log::error("Error while allocation byte array for bqr raw data");
return;
@@ -72,9 +73,8 @@ class BluetoothQualityReportCallbacksImpl
sCallbackEnv->SetByteArrayRegion(raw_data.get(), 0, bqr_raw_data.size(),
(jbyte*)bqr_raw_data.data());
- sCallbackEnv->CallVoidMethod(mCallbacksObj, method_bqrDeliver, addr.get(),
- (jint)lmp_ver, (jint)lmp_subver,
- (jint)manufacturer_id, raw_data.get());
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_bqrDeliver, addr.get(), (jint)lmp_ver,
+ (jint)lmp_subver, (jint)manufacturer_id, raw_data.get());
}
};
@@ -91,8 +91,7 @@ static void initNative(JNIEnv* env, jobject object) {
}
if (sBluetoothQualityReportInterface != nullptr) {
- log::info(
- "Cleaning up BluetoothQualityReport Interface before initializing...");
+ log::info("Cleaning up BluetoothQualityReport Interface before initializing...");
sBluetoothQualityReportInterface = nullptr;
}
@@ -103,13 +102,12 @@ static void initNative(JNIEnv* env, jobject object) {
}
if ((mCallbacksObj = env->NewGlobalRef(object)) == nullptr) {
- log::error(
- "Failed to allocate Global Ref for BluetoothQualityReport Callbacks");
+ log::error("Failed to allocate Global Ref for BluetoothQualityReport Callbacks");
return;
}
sBluetoothQualityReportInterface =
- (BluetoothQualityReportInterface*)btInf->get_profile_interface(BT_BQR_ID);
+ (BluetoothQualityReportInterface*)btInf->get_profile_interface(BT_BQR_ID);
if (sBluetoothQualityReportInterface == nullptr) {
log::error("Failed to get BluetoothQualityReport Interface");
return;
@@ -138,27 +136,22 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {
}
}
-int register_com_android_bluetooth_btservice_BluetoothQualityReport(
- JNIEnv* env) {
+int register_com_android_bluetooth_btservice_BluetoothQualityReport(JNIEnv* env) {
const JNINativeMethod methods[] = {
- {"initNative", "()V", (void*)initNative},
- {"cleanupNative", "()V", (void*)cleanupNative},
+ {"initNative", "()V", (void*)initNative},
+ {"cleanupNative", "()V", (void*)cleanupNative},
};
const int result = REGISTER_NATIVE_METHODS(
- env,
- "com/android/bluetooth/btservice/BluetoothQualityReportNativeInterface",
- methods);
+ env, "com/android/bluetooth/btservice/BluetoothQualityReportNativeInterface", methods);
if (result != 0) {
return result;
}
const JNIJavaMethod javaMethods[] = {
- {"bqrDeliver", "([BIII[B)V", &method_bqrDeliver},
+ {"bqrDeliver", "([BIII[B)V", &method_bqrDeliver},
};
- GET_JAVA_METHODS(
- env,
- "com/android/bluetooth/btservice/BluetoothQualityReportNativeInterface",
- javaMethods);
+ GET_JAVA_METHODS(env, "com/android/bluetooth/btservice/BluetoothQualityReportNativeInterface",
+ javaMethods);
return 0;
}
diff --git a/android/app/jni/com_android_bluetooth_a2dp.cpp b/android/app/jni/com_android_bluetooth_a2dp.cpp
index 6d73056c2236b393b1aa33e4f1ebf25df2705c32..f8a6f5480ac52b339ce0a448f7aac2d4c8b7cb7b 100644
--- a/android/app/jni/com_android_bluetooth_a2dp.cpp
+++ b/android/app/jni/com_android_bluetooth_a2dp.cpp
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-#define LOG_TAG "BluetoothA2dpServiceJni"
-
-#include
+#define LOG_TAG "bluetooth-a2dp"
+#include
#include
+#include "btif/include/btif_av.h"
#include "btif/include/btif_util.h"
#include "com_android_bluetooth.h"
#include "hardware/bt_av.h"
@@ -44,7 +44,6 @@ static struct {
jmethodID getCodecSpecific4;
} android_bluetooth_BluetoothCodecConfig;
-static const btav_source_interface_t* sBluetoothA2dpInterface = nullptr;
static std::vector supported_codecs;
static std::shared_timed_mutex interface_mutex;
@@ -58,200 +57,191 @@ static void bta2dp_connection_state_callback(const RawAddress& bd_addr,
std::shared_lock lock(callbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) return;
+ if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) {
+ return;
+ }
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Fail to new jbyteArray bd addr");
return;
}
- sCallbackEnv->SetByteArrayRegion(
- addr.get(), 0, sizeof(RawAddress),
- reinterpret_cast(bd_addr.address));
- sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectionStateChanged,
- addr.get(), (jint)state);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
+ reinterpret_cast(bd_addr.address));
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectionStateChanged, addr.get(),
+ (jint)state);
}
-static void bta2dp_audio_state_callback(const RawAddress& bd_addr,
- btav_audio_state_t state) {
+static void bta2dp_audio_state_callback(const RawAddress& bd_addr, btav_audio_state_t state) {
log::info("{}: state: {}", bd_addr, dump_av_audio_state(state));
std::shared_lock lock(callbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) return;
+ if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) {
+ return;
+ }
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Fail to new jbyteArray bd addr");
return;
}
- sCallbackEnv->SetByteArrayRegion(
- addr.get(), 0, sizeof(RawAddress),
- reinterpret_cast(bd_addr.address));
- sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged,
- addr.get(), (jint)state);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
+ reinterpret_cast(bd_addr.address));
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged, addr.get(), (jint)state);
}
static void bta2dp_audio_config_callback(
- const RawAddress& bd_addr, btav_a2dp_codec_config_t codec_config,
- std::vector codecs_local_capabilities,
- std::vector codecs_selectable_capabilities) {
- log::info(
- "{}: codec: {}, local codecs: {}, selectable codecs: {}", bd_addr,
- codec_config.CodecNameStr(),
- btav_a2dp_codec_config_t::PrintCodecs(codecs_local_capabilities),
- btav_a2dp_codec_config_t::PrintCodecs(codecs_selectable_capabilities));
+ const RawAddress& bd_addr, btav_a2dp_codec_config_t codec_config,
+ std::vector codecs_local_capabilities,
+ std::vector codecs_selectable_capabilities) {
+ log::info("{}: codec: {}, local codecs: {}, selectable codecs: {}", bd_addr,
+ codec_config.CodecNameStr(),
+ btav_a2dp_codec_config_t::PrintCodecs(codecs_local_capabilities),
+ btav_a2dp_codec_config_t::PrintCodecs(codecs_selectable_capabilities));
std::shared_lock lock(callbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) return;
+ if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) {
+ return;
+ }
jobject codecConfigObj = sCallbackEnv->NewObject(
- android_bluetooth_BluetoothCodecConfig.clazz,
- android_bluetooth_BluetoothCodecConfig.constructor,
- (jint)codec_config.codec_type, (jint)codec_config.codec_priority,
- (jint)codec_config.sample_rate, (jint)codec_config.bits_per_sample,
- (jint)codec_config.channel_mode, (jlong)codec_config.codec_specific_1,
- (jlong)codec_config.codec_specific_2,
- (jlong)codec_config.codec_specific_3,
- (jlong)codec_config.codec_specific_4);
+ android_bluetooth_BluetoothCodecConfig.clazz,
+ android_bluetooth_BluetoothCodecConfig.constructor, (jint)codec_config.codec_type,
+ (jint)codec_config.codec_priority, (jint)codec_config.sample_rate,
+ (jint)codec_config.bits_per_sample, (jint)codec_config.channel_mode,
+ (jlong)codec_config.codec_specific_1, (jlong)codec_config.codec_specific_2,
+ (jlong)codec_config.codec_specific_3, (jlong)codec_config.codec_specific_4);
jsize i = 0;
- jobjectArray local_capabilities_array = sCallbackEnv->NewObjectArray(
- (jsize)codecs_local_capabilities.size(),
- android_bluetooth_BluetoothCodecConfig.clazz, nullptr);
+ jobjectArray local_capabilities_array =
+ sCallbackEnv->NewObjectArray((jsize)codecs_local_capabilities.size(),
+ android_bluetooth_BluetoothCodecConfig.clazz, nullptr);
for (auto const& cap : codecs_local_capabilities) {
jobject capObj = sCallbackEnv->NewObject(
- android_bluetooth_BluetoothCodecConfig.clazz,
- android_bluetooth_BluetoothCodecConfig.constructor,
- (jint)cap.codec_type, (jint)cap.codec_priority, (jint)cap.sample_rate,
- (jint)cap.bits_per_sample, (jint)cap.channel_mode,
- (jlong)cap.codec_specific_1, (jlong)cap.codec_specific_2,
- (jlong)cap.codec_specific_3, (jlong)cap.codec_specific_4);
+ android_bluetooth_BluetoothCodecConfig.clazz,
+ android_bluetooth_BluetoothCodecConfig.constructor, (jint)cap.codec_type,
+ (jint)cap.codec_priority, (jint)cap.sample_rate, (jint)cap.bits_per_sample,
+ (jint)cap.channel_mode, (jlong)cap.codec_specific_1, (jlong)cap.codec_specific_2,
+ (jlong)cap.codec_specific_3, (jlong)cap.codec_specific_4);
sCallbackEnv->SetObjectArrayElement(local_capabilities_array, i++, capObj);
sCallbackEnv->DeleteLocalRef(capObj);
}
i = 0;
- jobjectArray selectable_capabilities_array = sCallbackEnv->NewObjectArray(
- (jsize)codecs_selectable_capabilities.size(),
- android_bluetooth_BluetoothCodecConfig.clazz, nullptr);
+ jobjectArray selectable_capabilities_array =
+ sCallbackEnv->NewObjectArray((jsize)codecs_selectable_capabilities.size(),
+ android_bluetooth_BluetoothCodecConfig.clazz, nullptr);
for (auto const& cap : codecs_selectable_capabilities) {
jobject capObj = sCallbackEnv->NewObject(
- android_bluetooth_BluetoothCodecConfig.clazz,
- android_bluetooth_BluetoothCodecConfig.constructor,
- (jint)cap.codec_type, (jint)cap.codec_priority, (jint)cap.sample_rate,
- (jint)cap.bits_per_sample, (jint)cap.channel_mode,
- (jlong)cap.codec_specific_1, (jlong)cap.codec_specific_2,
- (jlong)cap.codec_specific_3, (jlong)cap.codec_specific_4);
- sCallbackEnv->SetObjectArrayElement(selectable_capabilities_array, i++,
- capObj);
+ android_bluetooth_BluetoothCodecConfig.clazz,
+ android_bluetooth_BluetoothCodecConfig.constructor, (jint)cap.codec_type,
+ (jint)cap.codec_priority, (jint)cap.sample_rate, (jint)cap.bits_per_sample,
+ (jint)cap.channel_mode, (jlong)cap.codec_specific_1, (jlong)cap.codec_specific_2,
+ (jlong)cap.codec_specific_3, (jlong)cap.codec_specific_4);
+ sCallbackEnv->SetObjectArrayElement(selectable_capabilities_array, i++, capObj);
sCallbackEnv->DeleteLocalRef(capObj);
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(RawAddress::kLength));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(RawAddress::kLength));
if (!addr.get()) {
log::error("Fail to new jbyteArray bd addr");
return;
}
- sCallbackEnv->SetByteArrayRegion(
- addr.get(), 0, RawAddress::kLength,
- reinterpret_cast(bd_addr.address));
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, RawAddress::kLength,
+ reinterpret_cast(bd_addr.address));
- sCallbackEnv->CallVoidMethod(
- mCallbacksObj, method_onCodecConfigChanged, addr.get(), codecConfigObj,
- local_capabilities_array, selectable_capabilities_array);
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onCodecConfigChanged, addr.get(),
+ codecConfigObj, local_capabilities_array,
+ selectable_capabilities_array);
}
-static bool bta2dp_mandatory_codec_preferred_callback(
- const RawAddress& bd_addr) {
+static bool bta2dp_mandatory_codec_preferred_callback(const RawAddress& bd_addr) {
log::info("{}", bd_addr);
std::shared_lock lock(callbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) return false;
+ if (!sCallbackEnv.valid() || mCallbacksObj == nullptr) {
+ return false;
+ }
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(RawAddress::kLength));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(RawAddress::kLength));
if (!addr.get()) {
log::error("Fail to new jbyteArray bd addr");
return false;
}
- sCallbackEnv->SetByteArrayRegion(
- addr.get(), 0, RawAddress::kLength,
- reinterpret_cast(bd_addr.address));
- return sCallbackEnv->CallBooleanMethod(
- mCallbacksObj, method_isMandatoryCodecPreferred, addr.get());
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, RawAddress::kLength,
+ reinterpret_cast(bd_addr.address));
+ return sCallbackEnv->CallBooleanMethod(mCallbacksObj, method_isMandatoryCodecPreferred,
+ addr.get());
}
static btav_source_callbacks_t sBluetoothA2dpCallbacks = {
- sizeof(sBluetoothA2dpCallbacks),
- bta2dp_connection_state_callback,
- bta2dp_audio_state_callback,
- bta2dp_audio_config_callback,
- bta2dp_mandatory_codec_preferred_callback,
+ sizeof(sBluetoothA2dpCallbacks),
+ bta2dp_connection_state_callback,
+ bta2dp_audio_state_callback,
+ bta2dp_audio_config_callback,
+ bta2dp_mandatory_codec_preferred_callback,
};
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);
for (int i = 0; i < numConfigs; i++) {
jobject jcodecConfig = env->GetObjectArrayElement(codecConfigArray, i);
- if (jcodecConfig == nullptr) continue;
- if (!env->IsInstanceOf(jcodecConfig,
- android_bluetooth_BluetoothCodecConfig.clazz)) {
+ if (jcodecConfig == nullptr) {
+ continue;
+ }
+ if (!env->IsInstanceOf(jcodecConfig, android_bluetooth_BluetoothCodecConfig.clazz)) {
log::error("Invalid BluetoothCodecConfig instance");
continue;
}
- jint codecType = env->CallIntMethod(
- jcodecConfig, android_bluetooth_BluetoothCodecConfig.getCodecType);
+ jint codecType =
+ env->CallIntMethod(jcodecConfig, android_bluetooth_BluetoothCodecConfig.getCodecType);
jint codecPriority = env->CallIntMethod(
- jcodecConfig, android_bluetooth_BluetoothCodecConfig.getCodecPriority);
- jint sampleRate = env->CallIntMethod(
- jcodecConfig, android_bluetooth_BluetoothCodecConfig.getSampleRate);
+ jcodecConfig, android_bluetooth_BluetoothCodecConfig.getCodecPriority);
+ jint sampleRate =
+ env->CallIntMethod(jcodecConfig, android_bluetooth_BluetoothCodecConfig.getSampleRate);
jint bitsPerSample = env->CallIntMethod(
- jcodecConfig, android_bluetooth_BluetoothCodecConfig.getBitsPerSample);
- jint channelMode = env->CallIntMethod(
- jcodecConfig, android_bluetooth_BluetoothCodecConfig.getChannelMode);
+ jcodecConfig, android_bluetooth_BluetoothCodecConfig.getBitsPerSample);
+ jint channelMode =
+ env->CallIntMethod(jcodecConfig, android_bluetooth_BluetoothCodecConfig.getChannelMode);
jlong codecSpecific1 = env->CallLongMethod(
- jcodecConfig, android_bluetooth_BluetoothCodecConfig.getCodecSpecific1);
+ jcodecConfig, android_bluetooth_BluetoothCodecConfig.getCodecSpecific1);
jlong codecSpecific2 = env->CallLongMethod(
- jcodecConfig, android_bluetooth_BluetoothCodecConfig.getCodecSpecific2);
+ jcodecConfig, android_bluetooth_BluetoothCodecConfig.getCodecSpecific2);
jlong codecSpecific3 = env->CallLongMethod(
- jcodecConfig, android_bluetooth_BluetoothCodecConfig.getCodecSpecific3);
+ jcodecConfig, android_bluetooth_BluetoothCodecConfig.getCodecSpecific3);
jlong codecSpecific4 = env->CallLongMethod(
- jcodecConfig, android_bluetooth_BluetoothCodecConfig.getCodecSpecific4);
+ jcodecConfig, android_bluetooth_BluetoothCodecConfig.getCodecSpecific4);
btav_a2dp_codec_config_t codec_config = {
- .codec_type = static_cast(codecType),
- .codec_priority =
- static_cast(codecPriority),
- .sample_rate = static_cast(sampleRate),
- .bits_per_sample =
- static_cast(bitsPerSample),
- .channel_mode =
- static_cast(channelMode),
- .codec_specific_1 = codecSpecific1,
- .codec_specific_2 = codecSpecific2,
- .codec_specific_3 = codecSpecific3,
- .codec_specific_4 = codecSpecific4};
+ .codec_type = static_cast(codecType),
+ .codec_priority = static_cast(codecPriority),
+ .sample_rate = static_cast(sampleRate),
+ .bits_per_sample = static_cast(bitsPerSample),
+ .channel_mode = static_cast(channelMode),
+ .codec_specific_1 = codecSpecific1,
+ .codec_specific_2 = codecSpecific2,
+ .codec_specific_3 = codecSpecific3,
+ .codec_specific_4 = codecSpecific4};
codec_preferences.push_back(codec_config);
}
return codec_preferences;
}
-static void initNative(JNIEnv* env, jobject object,
- jint maxConnectedAudioDevices,
- jobjectArray codecConfigArray,
- jobjectArray codecOffloadingArray) {
+static void initNative(JNIEnv* env, jobject object, jint maxConnectedAudioDevices,
+ jobjectArray codecConfigArray, jobjectArray codecOffloadingArray) {
std::unique_lock interface_lock(interface_mutex);
std::unique_lock callbacks_lock(callbacks_mutex);
@@ -261,12 +251,6 @@ static void initNative(JNIEnv* env, jobject object,
return;
}
- if (sBluetoothA2dpInterface != nullptr) {
- log::warn("Cleaning up A2DP Interface before initializing...");
- sBluetoothA2dpInterface->cleanup();
- sBluetoothA2dpInterface = nullptr;
- }
-
if (mCallbacksObj != nullptr) {
log::warn("Cleaning up A2DP callback object");
env->DeleteGlobalRef(mCallbacksObj);
@@ -278,34 +262,23 @@ static void initNative(JNIEnv* env, jobject object,
return;
}
- android_bluetooth_BluetoothCodecConfig.clazz = (jclass)env->NewGlobalRef(
- env->FindClass("android/bluetooth/BluetoothCodecConfig"));
+ android_bluetooth_BluetoothCodecConfig.clazz =
+ (jclass)env->NewGlobalRef(env->FindClass("android/bluetooth/BluetoothCodecConfig"));
if (android_bluetooth_BluetoothCodecConfig.clazz == nullptr) {
log::error("Failed to allocate Global Ref for BluetoothCodecConfig class");
return;
}
- sBluetoothA2dpInterface =
- (btav_source_interface_t*)btInf->get_profile_interface(
- BT_PROFILE_ADVANCED_AUDIO_ID);
- if (sBluetoothA2dpInterface == nullptr) {
- log::error("Failed to get Bluetooth A2DP Interface");
- return;
- }
-
std::vector codec_priorities =
- prepareCodecPreferences(env, object, codecConfigArray);
+ prepareCodecPreferences(env, object, codecConfigArray);
std::vector codec_offloading =
- prepareCodecPreferences(env, object, codecOffloadingArray);
+ prepareCodecPreferences(env, object, codecOffloadingArray);
- bt_status_t status = sBluetoothA2dpInterface->init(
- &sBluetoothA2dpCallbacks, maxConnectedAudioDevices, codec_priorities,
- codec_offloading, &supported_codecs);
+ bt_status_t status = btif_av_source_init(&sBluetoothA2dpCallbacks, maxConnectedAudioDevices,
+ codec_priorities, codec_offloading, &supported_codecs);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed to initialize Bluetooth A2DP, status: {}",
- bt_status_text(status));
- sBluetoothA2dpInterface = nullptr;
+ log::error("Failed to initialize Bluetooth A2DP, status: {}", bt_status_text(status));
return;
}
}
@@ -320,10 +293,7 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {
return;
}
- if (sBluetoothA2dpInterface != nullptr) {
- sBluetoothA2dpInterface->cleanup();
- sBluetoothA2dpInterface = nullptr;
- }
+ btif_av_source_cleanup();
env->DeleteGlobalRef(android_bluetooth_BluetoothCodecConfig.clazz);
android_bluetooth_BluetoothCodecConfig.clazz = nullptr;
@@ -335,26 +305,23 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {
}
static jobjectArray getSupportedCodecTypesNative(JNIEnv* env) {
- log::info("{}", fmt::ptr(sBluetoothA2dpInterface));
-
- jclass android_bluetooth_BluetoothCodecType_clazz = (jclass)env->NewGlobalRef(
- env->FindClass("android/bluetooth/BluetoothCodecType"));
+ jclass android_bluetooth_BluetoothCodecType_clazz =
+ (jclass)env->NewGlobalRef(env->FindClass("android/bluetooth/BluetoothCodecType"));
if (android_bluetooth_BluetoothCodecType_clazz == nullptr) {
log::error("Failed to allocate Global Ref for BluetoothCodecType class");
return nullptr;
}
- jmethodID init = env->GetMethodID(android_bluetooth_BluetoothCodecType_clazz,
- "", "(IJLjava/lang/String;)V");
+ jmethodID init = env->GetMethodID(android_bluetooth_BluetoothCodecType_clazz, "",
+ "(IJLjava/lang/String;)V");
if (init == nullptr) {
log::error("Failed to find method of BluetoothCodecType class");
return nullptr;
}
- jobjectArray result =
- env->NewObjectArray(supported_codecs.size(),
- android_bluetooth_BluetoothCodecType_clazz, nullptr);
+ jobjectArray result = env->NewObjectArray(supported_codecs.size(),
+ android_bluetooth_BluetoothCodecType_clazz, nullptr);
if (result == nullptr) {
log::error("Failed to allocate result array of BluetoothCodecType");
@@ -363,24 +330,17 @@ static jobjectArray getSupportedCodecTypesNative(JNIEnv* env) {
for (size_t index = 0; index < supported_codecs.size(); index++) {
jobject codec_type = env->NewObject(
- android_bluetooth_BluetoothCodecType_clazz, init,
- (jint)supported_codecs[index].codec_type,
- (jlong)supported_codecs[index].codec_id,
- env->NewStringUTF(supported_codecs[index].codec_name.c_str()));
+ android_bluetooth_BluetoothCodecType_clazz, init,
+ (jint)supported_codecs[index].codec_type, (jlong)supported_codecs[index].codec_id,
+ env->NewStringUTF(supported_codecs[index].codec_name.c_str()));
env->SetObjectArrayElement(result, index, codec_type);
}
return result;
}
-static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
- jbyteArray address) {
+static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
std::shared_lock lock(interface_mutex);
- if (!sBluetoothA2dpInterface) {
- log::error("Failed to get the Bluetooth A2DP Interface");
- return JNI_FALSE;
- }
-
jbyte* addr = env->GetByteArrayElements(address, nullptr);
if (!addr) {
jniThrowIOException(env, EINVAL);
@@ -389,9 +349,9 @@ static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
RawAddress bd_addr;
bd_addr.FromOctets(reinterpret_cast(addr));
- log::info("sBluetoothA2dpInterface: {}, {}",
- fmt::ptr(sBluetoothA2dpInterface), bd_addr);
- bt_status_t status = sBluetoothA2dpInterface->connect(bd_addr);
+
+ log::info("{}", bd_addr);
+ bt_status_t status = btif_av_source_connect(bd_addr);
if (status != BT_STATUS_SUCCESS) {
log::error("Failed A2DP connection, status: {}", bt_status_text(status));
}
@@ -399,14 +359,8 @@ static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
- jbyteArray address) {
+static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
std::shared_lock lock(interface_mutex);
- if (!sBluetoothA2dpInterface) {
- log::error("Failed to get the Bluetooth A2DP Interface");
- return JNI_FALSE;
- }
-
jbyte* addr = env->GetByteArrayElements(address, nullptr);
if (!addr) {
jniThrowIOException(env, EINVAL);
@@ -415,9 +369,9 @@ static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
RawAddress bd_addr;
bd_addr.FromOctets(reinterpret_cast(addr));
- log::info("sBluetoothA2dpInterface: {}, {}",
- fmt::ptr(sBluetoothA2dpInterface), bd_addr);
- bt_status_t status = sBluetoothA2dpInterface->disconnect(bd_addr);
+
+ log::info("{}", bd_addr);
+ bt_status_t status = btif_av_source_disconnect(bd_addr);
if (status != BT_STATUS_SUCCESS) {
log::error("Failed A2DP disconnection, status: {}", bt_status_text(status));
}
@@ -425,16 +379,11 @@ static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean setSilenceDeviceNative(JNIEnv* env, jobject /* object */,
- jbyteArray address, jboolean silence) {
+static jboolean setSilenceDeviceNative(JNIEnv* env, jobject /* object */, jbyteArray address,
+ jboolean silence) {
std::shared_lock lock(interface_mutex);
- if (!sBluetoothA2dpInterface) {
- log::error("Failed to get the Bluetooth A2DP Interface");
- return JNI_FALSE;
- }
jbyte* addr = env->GetByteArrayElements(address, nullptr);
-
RawAddress bd_addr = RawAddress::kEmpty;
if (addr) {
bd_addr.FromOctets(reinterpret_cast(addr));
@@ -442,53 +391,37 @@ static jboolean setSilenceDeviceNative(JNIEnv* env, jobject /* object */,
if (bd_addr == RawAddress::kEmpty) {
return JNI_FALSE;
}
- log::info("sBluetoothA2dpInterface: {}, {}: silence: {}",
- fmt::ptr(sBluetoothA2dpInterface), bd_addr,
- static_cast(silence));
- bt_status_t status =
- sBluetoothA2dpInterface->set_silence_device(bd_addr, silence);
+
+ log::info("{}: silence={}", bd_addr, silence);
+ bt_status_t status = btif_av_source_set_silence_device(bd_addr, silence);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed A2DP set_silence_device, status: {}",
- bt_status_text(status));
+ log::error("Failed A2DP set_silence_device, status: {}", bt_status_text(status));
}
env->ReleaseByteArrayElements(address, addr, 0);
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
- jbyteArray address) {
+static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
std::shared_lock lock(interface_mutex);
- if (!sBluetoothA2dpInterface) {
- log::error("Failed to get the Bluetooth A2DP Interface");
- return JNI_FALSE;
- }
jbyte* addr = env->GetByteArrayElements(address, nullptr);
-
RawAddress bd_addr = RawAddress::kEmpty;
if (addr) {
bd_addr.FromOctets(reinterpret_cast(addr));
}
- log::info("sBluetoothA2dpInterface: {}, {}",
- fmt::ptr(sBluetoothA2dpInterface), bd_addr);
- bt_status_t status = sBluetoothA2dpInterface->set_active_device(bd_addr);
+
+ log::info("{}", bd_addr);
+ bt_status_t status = btif_av_source_set_active_device(bd_addr);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed A2DP set_active_device, status: {}",
- bt_status_text(status));
+ log::error("Failed A2DP set_active_device, status: {}", bt_status_text(status));
}
env->ReleaseByteArrayElements(address, addr, 0);
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean setCodecConfigPreferenceNative(JNIEnv* env, jobject object,
- jbyteArray address,
+static jboolean setCodecConfigPreferenceNative(JNIEnv* env, jobject object, jbyteArray address,
jobjectArray codecConfigArray) {
std::shared_lock lock(interface_mutex);
- if (!sBluetoothA2dpInterface) {
- log::error("Failed to get the Bluetooth A2DP Interface");
- return JNI_FALSE;
- }
-
jbyte* addr = env->GetByteArrayElements(address, nullptr);
if (!addr) {
jniThrowIOException(env, EINVAL);
@@ -498,15 +431,11 @@ static jboolean setCodecConfigPreferenceNative(JNIEnv* env, jobject object,
RawAddress bd_addr;
bd_addr.FromOctets(reinterpret_cast(addr));
std::vector codec_preferences =
- prepareCodecPreferences(env, object, codecConfigArray);
- log::info("sBluetoothA2dpInterface: {}, {}: {}",
- fmt::ptr(sBluetoothA2dpInterface), bd_addr,
- btav_a2dp_codec_config_t::PrintCodecs(codec_preferences));
- bt_status_t status =
- sBluetoothA2dpInterface->config_codec(bd_addr, codec_preferences);
+ prepareCodecPreferences(env, object, codecConfigArray);
+ log::info("{}: {}", bd_addr, btav_a2dp_codec_config_t::PrintCodecs(codec_preferences));
+ bt_status_t status = btif_av_source_set_codec_config_preference(bd_addr, codec_preferences);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed codec configuration, status: {}",
- bt_status_text(status));
+ log::error("Failed codec configuration, status: {}", bt_status_text(status));
}
env->ReleaseByteArrayElements(address, addr, 0);
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
@@ -514,66 +443,52 @@ static jboolean setCodecConfigPreferenceNative(JNIEnv* env, jobject object,
int register_com_android_bluetooth_a2dp(JNIEnv* env) {
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},
+ {"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);
+ 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},
+ {"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);
+ 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},
+ {"", "(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);
+ GET_JAVA_METHODS(env, "android/bluetooth/BluetoothCodecConfig", codecConfigCallbacksMethods);
return 0;
}
-}
+} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_a2dp_sink.cpp b/android/app/jni/com_android_bluetooth_a2dp_sink.cpp
index abd8e20ed778de4eb70da9ad8efabb7817e1dd45..44f1fee6cc9b5df8bdc691a228e0a40fe345196e 100644
--- a/android/app/jni/com_android_bluetooth_a2dp_sink.cpp
+++ b/android/app/jni/com_android_bluetooth_a2dp_sink.cpp
@@ -16,11 +16,13 @@
#define LOG_TAG "BluetoothA2dpSinkServiceJni"
-#include
+#include
+#include
#include
#include
+#include "btif/include/btif_av.h"
#include "com_android_bluetooth.h"
#include "hardware/bt_av.h"
@@ -29,22 +31,25 @@ static jmethodID method_onConnectionStateChanged;
static jmethodID method_onAudioStateChanged;
static jmethodID method_onAudioConfigChanged;
-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 */) {
log::info("");
std::shared_lock lock(callbacks_mutex);
- if (!mCallbacksObj) return;
+ if (!mCallbacksObj) {
+ return;
+ }
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Fail to new jbyteArray bd addr for connection state");
return;
@@ -52,21 +57,24 @@ static void a2dp_sink_connection_state_callback(
sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
(const jbyte*)bd_addr.address);
- sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectionStateChanged,
- addr.get(), (jint)state);
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onConnectionStateChanged, addr.get(),
+ (jint)state);
}
-static void a2dp_sink_audio_state_callback(const RawAddress& bd_addr,
- btav_audio_state_t state) {
+static void a2dp_sink_audio_state_callback(const RawAddress& bd_addr, btav_audio_state_t state) {
log::info("");
std::shared_lock lock(callbacks_mutex);
- if (!mCallbacksObj) return;
+ if (!mCallbacksObj) {
+ return;
+ }
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Fail to new jbyteArray bd addr for connection state");
return;
@@ -74,22 +82,24 @@ static void a2dp_sink_audio_state_callback(const RawAddress& bd_addr,
sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
(const jbyte*)bd_addr.address);
- sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged,
- addr.get(), (jint)state);
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioStateChanged, addr.get(), (jint)state);
}
-static void a2dp_sink_audio_config_callback(const RawAddress& bd_addr,
- uint32_t sample_rate,
+static void a2dp_sink_audio_config_callback(const RawAddress& bd_addr, uint32_t sample_rate,
uint8_t channel_count) {
log::info("");
std::shared_lock lock(callbacks_mutex);
- if (!mCallbacksObj) return;
+ if (!mCallbacksObj) {
+ return;
+ }
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Fail to new jbyteArray bd addr for connection state");
return;
@@ -97,20 +107,18 @@ static void a2dp_sink_audio_config_callback(const RawAddress& bd_addr,
sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
(const jbyte*)bd_addr.address);
- sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioConfigChanged,
- addr.get(), (jint)sample_rate,
- (jint)channel_count);
+ sCallbackEnv->CallVoidMethod(mCallbacksObj, method_onAudioConfigChanged, addr.get(),
+ (jint)sample_rate, (jint)channel_count);
}
static btav_sink_callbacks_t sBluetoothA2dpCallbacks = {
- sizeof(sBluetoothA2dpCallbacks),
- a2dp_sink_connection_state_callback,
- a2dp_sink_audio_state_callback,
- a2dp_sink_audio_config_callback,
+ sizeof(sBluetoothA2dpCallbacks),
+ a2dp_sink_connection_state_callback,
+ a2dp_sink_audio_state_callback,
+ a2dp_sink_audio_config_callback,
};
-static void initNative(JNIEnv* env, jobject object,
- jint maxConnectedAudioDevices) {
+static void initNative(JNIEnv* env, jobject object, jint maxConnectedAudioDevices) {
std::unique_lock lock(callbacks_mutex);
const bt_interface_t* btInf = getBluetoothInterface();
@@ -119,32 +127,15 @@ static void initNative(JNIEnv* env, jobject object,
return;
}
- if (sBluetoothA2dpInterface != NULL) {
- log::warn("Cleaning up A2DP Interface before initializing...");
- sBluetoothA2dpInterface->cleanup();
- sBluetoothA2dpInterface = NULL;
- }
-
if (mCallbacksObj != NULL) {
log::warn("Cleaning up A2DP callback object");
env->DeleteGlobalRef(mCallbacksObj);
mCallbacksObj = NULL;
}
- sBluetoothA2dpInterface =
- (btav_sink_interface_t*)btInf->get_profile_interface(
- BT_PROFILE_ADVANCED_AUDIO_SINK_ID);
- if (sBluetoothA2dpInterface == NULL) {
- log::error("Failed to get Bluetooth A2DP Sink Interface");
- return;
- }
-
- bt_status_t status = sBluetoothA2dpInterface->init(&sBluetoothA2dpCallbacks,
- maxConnectedAudioDevices);
+ bt_status_t status = btif_av_sink_init(&sBluetoothA2dpCallbacks, maxConnectedAudioDevices);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed to initialize Bluetooth A2DP Sink, status: {}",
- bt_status_text(status));
- sBluetoothA2dpInterface = NULL;
+ log::error("Failed to initialize Bluetooth A2DP Sink, status: {}", bt_status_text(status));
return;
}
@@ -160,10 +151,7 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {
return;
}
- if (sBluetoothA2dpInterface != NULL) {
- sBluetoothA2dpInterface->cleanup();
- sBluetoothA2dpInterface = NULL;
- }
+ btif_av_sink_cleanup();
if (mCallbacksObj != NULL) {
env->DeleteGlobalRef(mCallbacksObj);
@@ -171,11 +159,7 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {
}
}
-static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
- jbyteArray address) {
- log::info("sBluetoothA2dpInterface: {}", fmt::ptr(sBluetoothA2dpInterface));
- if (!sBluetoothA2dpInterface) return JNI_FALSE;
-
+static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
jniThrowIOException(env, EINVAL);
@@ -184,18 +168,18 @@ static jboolean connectA2dpNative(JNIEnv* env, jobject /* object */,
RawAddress bd_addr;
bd_addr.FromOctets(reinterpret_cast(addr));
- bt_status_t status = sBluetoothA2dpInterface->connect(bd_addr);
+
+ log::info("{}", bd_addr);
+ bt_status_t status = btif_av_sink_connect(bd_addr);
if (status != BT_STATUS_SUCCESS) {
log::error("Failed HF connection, status: {}", bt_status_text(status));
}
+
env->ReleaseByteArrayElements(address, addr, 0);
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
- jbyteArray address) {
- if (!sBluetoothA2dpInterface) return JNI_FALSE;
-
+static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
jniThrowIOException(env, EINVAL);
@@ -204,32 +188,26 @@ static jboolean disconnectA2dpNative(JNIEnv* env, jobject /* object */,
RawAddress bd_addr;
bd_addr.FromOctets(reinterpret_cast(addr));
- bt_status_t status = sBluetoothA2dpInterface->disconnect(bd_addr);
+
+ log::info("{}", bd_addr);
+ bt_status_t status = btif_av_sink_disconnect(bd_addr);
if (status != BT_STATUS_SUCCESS) {
log::error("Failed HF disconnection, status: {}", bt_status_text(status));
}
+
env->ReleaseByteArrayElements(address, addr, 0);
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static void informAudioFocusStateNative(JNIEnv* /* env */, jobject /* object */,
- jint focus_state) {
- if (!sBluetoothA2dpInterface) return;
- sBluetoothA2dpInterface->set_audio_focus_state((uint8_t)focus_state);
+static void informAudioFocusStateNative(JNIEnv* /* env */, jobject /* object */, jint focus_state) {
+ btif_av_sink_set_audio_focus_state(static_cast(focus_state));
}
-static void informAudioTrackGainNative(JNIEnv* /* env */, jobject /* object */,
- jfloat gain) {
- if (!sBluetoothA2dpInterface) return;
- sBluetoothA2dpInterface->set_audio_track_gain((float)gain);
+static void informAudioTrackGainNative(JNIEnv* /* env */, jobject /* object */, jfloat gain) {
+ btif_av_sink_set_audio_track_gain(static_cast(gain));
}
-static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
- jbyteArray address) {
- if (!sBluetoothA2dpInterface) return JNI_FALSE;
-
- log::info("sBluetoothA2dpInterface: {}", fmt::ptr(sBluetoothA2dpInterface));
-
+static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
jniThrowIOException(env, EINVAL);
@@ -237,43 +215,43 @@ static jboolean setActiveDeviceNative(JNIEnv* env, jobject /* object */,
}
RawAddress rawAddress;
- rawAddress.FromOctets((uint8_t*)addr);
- bt_status_t status = sBluetoothA2dpInterface->set_active_device(rawAddress);
+ rawAddress.FromOctets(reinterpret_cast(addr));
+
+ log::info("{}", rawAddress);
+ bt_status_t status = btif_av_sink_set_active_device(rawAddress);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed sending passthru command, status: {}",
- bt_status_text(status));
+ log::error("Failed sending passthru command, status: {}", bt_status_text(status));
}
- env->ReleaseByteArrayElements(address, addr, 0);
+ env->ReleaseByteArrayElements(address, addr, 0);
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
int register_com_android_bluetooth_a2dp_sink(JNIEnv* env) {
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},
+ {"initNative", "(I)V", reinterpret_cast(initNative)},
+ {"cleanupNative", "()V", reinterpret_cast(cleanupNative)},
+ {"connectA2dpNative", "([B)Z", reinterpret_cast(connectA2dpNative)},
+ {"disconnectA2dpNative", "([B)Z", reinterpret_cast(disconnectA2dpNative)},
+ {"informAudioFocusStateNative", "(I)V",
+ reinterpret_cast(informAudioFocusStateNative)},
+ {"informAudioTrackGainNative", "(F)V",
+ reinterpret_cast(informAudioTrackGainNative)},
+ {"setActiveDeviceNative", "([B)Z", reinterpret_cast(setActiveDeviceNative)},
};
const int result = REGISTER_NATIVE_METHODS(
- env, "com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface", 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},
+ {"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);
+ GET_JAVA_METHODS(env, "com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface", javaMethods);
return 0;
}
-}
+} // namespace android
diff --git a/android/app/jni/com_android_bluetooth_avrcp_controller.cpp b/android/app/jni/com_android_bluetooth_avrcp_controller.cpp
index 57a80bb87de2ae05850829530259a3cce43adc75..0d29848e8191bd72d27aec9ee8c2fd95ee6ebbcf 100644
--- a/android/app/jni/com_android_bluetooth_avrcp_controller.cpp
+++ b/android/app/jni/com_android_bluetooth_avrcp_controller.cpp
@@ -53,8 +53,8 @@ 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) {
+static void btavrcp_passthrough_response_callback(const RawAddress& /* bd_addr */, int id,
+ int pressed) {
log::verbose("id: {}, pressed: {} --- Not implemented", id, pressed);
}
@@ -67,56 +67,56 @@ static void btavrcp_connection_state_callback(bool rc_connect, bool br_connect,
log::info("conn state: rc: {} br: {}", rc_connect, br_connect);
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
if (!sCallbacksObj) {
log::error("sCallbacksObj is null");
return;
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)bd_addr.address);
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_onConnectionStateChanged,
- (jboolean)rc_connect, (jboolean)br_connect,
- addr.get());
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)bd_addr.address);
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_onConnectionStateChanged, (jboolean)rc_connect,
+ (jboolean)br_connect, addr.get());
}
-static void btavrcp_get_rcfeatures_callback(const RawAddress& /* bd_addr */,
- int /* features */) {
+static void btavrcp_get_rcfeatures_callback(const RawAddress& /* bd_addr */, int /* features */) {
log::verbose("--- Not implemented");
}
-static void btavrcp_setplayerapplicationsetting_rsp_callback(
- const RawAddress& /* bd_addr */, uint8_t /* accepted */) {
+static void btavrcp_setplayerapplicationsetting_rsp_callback(const RawAddress& /* bd_addr */,
+ uint8_t /* accepted */) {
log::verbose("--- Not implemented");
}
-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 */) {
+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 */) {
log::info("");
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
if (!sCallbacksObj) {
log::error("sCallbacksObj is null");
return;
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
/* TODO ext attrs
* Flattening defined attributes:
*/
@@ -127,52 +127,50 @@ static void btavrcp_playerapplicationsetting_callback(
}
log::verbose("arraylen {}", arraylen);
- ScopedLocalRef playerattribs(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(arraylen));
+ ScopedLocalRef playerattribs(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(arraylen));
if (!playerattribs.get()) {
log::error("Failed to allocate a new byte array");
return;
}
for (int i = 0, k = 0; (i < num_attr) && (k < arraylen); i++) {
- sCallbackEnv->SetByteArrayRegion(playerattribs.get(), k, 1,
- (jbyte*)&(app_attrs[i].attr_id));
+ sCallbackEnv->SetByteArrayRegion(playerattribs.get(), k, 1, (jbyte*)&(app_attrs[i].attr_id));
k++;
- sCallbackEnv->SetByteArrayRegion(playerattribs.get(), k, 1,
- (jbyte*)&(app_attrs[i].num_val));
+ sCallbackEnv->SetByteArrayRegion(playerattribs.get(), k, 1, (jbyte*)&(app_attrs[i].num_val));
k++;
- sCallbackEnv->SetByteArrayRegion(playerattribs.get(), k,
- app_attrs[i].num_val,
+ sCallbackEnv->SetByteArrayRegion(playerattribs.get(), k, app_attrs[i].num_val,
(jbyte*)(app_attrs[i].attr_val));
k = k + app_attrs[i].num_val;
}
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleplayerappsetting,
- addr.get(), playerattribs.get(), (jint)arraylen);
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleplayerappsetting, addr.get(),
+ playerattribs.get(), (jint)arraylen);
}
-static void btavrcp_playerapplicationsetting_changed_callback(
- const RawAddress& bd_addr, const btrc_player_settings_t& vals) {
+static void btavrcp_playerapplicationsetting_changed_callback(const RawAddress& bd_addr,
+ const btrc_player_settings_t& vals) {
log::info("");
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
if (!sCallbacksObj) {
log::error("sCallbacksObj is null");
return;
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
int arraylen = vals.num_attr * 2;
- ScopedLocalRef playerattribs(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(arraylen));
+ ScopedLocalRef playerattribs(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(arraylen));
if (!playerattribs.get()) {
log::error("Fail to new jbyteArray playerattribs");
return;
@@ -181,69 +179,66 @@ static void btavrcp_playerapplicationsetting_changed_callback(
* Flatening format:
*/
for (int i = 0, k = 0; (i < vals.num_attr) && (k < arraylen); i++) {
- sCallbackEnv->SetByteArrayRegion(playerattribs.get(), k, 1,
- (jbyte*)&(vals.attr_ids[i]));
+ sCallbackEnv->SetByteArrayRegion(playerattribs.get(), k, 1, (jbyte*)&(vals.attr_ids[i]));
k++;
- sCallbackEnv->SetByteArrayRegion(playerattribs.get(), k, 1,
- (jbyte*)&(vals.attr_values[i]));
+ sCallbackEnv->SetByteArrayRegion(playerattribs.get(), k, 1, (jbyte*)&(vals.attr_values[i]));
k++;
}
- sCallbackEnv->CallVoidMethod(sCallbacksObj,
- method_handleplayerappsettingchanged, addr.get(),
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleplayerappsettingchanged, addr.get(),
playerattribs.get(), (jint)arraylen);
}
-static void btavrcp_set_abs_vol_cmd_callback(const RawAddress& bd_addr,
- uint8_t abs_vol, uint8_t label) {
+static void btavrcp_set_abs_vol_cmd_callback(const RawAddress& bd_addr, uint8_t abs_vol,
+ uint8_t label) {
log::info("");
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
if (!sCallbacksObj) {
log::error("sCallbacksObj is null");
return;
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleSetAbsVolume,
- addr.get(), (jbyte)abs_vol, (jbyte)label);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleSetAbsVolume, addr.get(), (jbyte)abs_vol,
+ (jbyte)label);
}
-static void btavrcp_register_notification_absvol_callback(
- const RawAddress& bd_addr, uint8_t label) {
+static void btavrcp_register_notification_absvol_callback(const RawAddress& bd_addr,
+ uint8_t label) {
log::info("");
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
if (!sCallbacksObj) {
log::error("sCallbacksObj is null");
return;
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
- sCallbackEnv->CallVoidMethod(sCallbacksObj,
- method_handleRegisterNotificationAbsVol,
- addr.get(), (jbyte)label);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleRegisterNotificationAbsVol, addr.get(),
+ (jbyte)label);
}
-static void btavrcp_track_changed_callback(const RawAddress& bd_addr,
- uint8_t num_attr,
+static void btavrcp_track_changed_callback(const RawAddress& bd_addr, uint8_t num_attr,
btrc_element_attr_val_t* p_attrs) {
/*
* byteArray will be formatted like this: id,len,string
@@ -252,105 +247,102 @@ static void btavrcp_track_changed_callback(const RawAddress& bd_addr,
log::info("");
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
if (!sCallbacksObj) {
log::error("sCallbacksObj is null");
return;
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- ScopedLocalRef attribIds(sCallbackEnv.get(),
- sCallbackEnv->NewIntArray(num_attr));
+ ScopedLocalRef attribIds(sCallbackEnv.get(), sCallbackEnv->NewIntArray(num_attr));
if (!attribIds.get()) {
log::error("failed to set new array for attribIds");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
jclass strclazz = sCallbackEnv->FindClass("java/lang/String");
ScopedLocalRef stringArray(
- sCallbackEnv.get(),
- sCallbackEnv->NewObjectArray((jint)num_attr, strclazz, 0));
+ sCallbackEnv.get(), sCallbackEnv->NewObjectArray((jint)num_attr, strclazz, 0));
if (!stringArray.get()) {
log::error("failed to get String array");
return;
}
for (jint i = 0; i < num_attr; i++) {
- ScopedLocalRef str(
- sCallbackEnv.get(),
- sCallbackEnv->NewStringUTF((char*)(p_attrs[i].text)));
+ ScopedLocalRef str(sCallbackEnv.get(),
+ sCallbackEnv->NewStringUTF((char*)(p_attrs[i].text)));
if (!str.get()) {
log::error("Unable to get str");
return;
}
- sCallbackEnv->SetIntArrayRegion(attribIds.get(), i, 1,
- (jint*)&(p_attrs[i].attr_id));
+ sCallbackEnv->SetIntArrayRegion(attribIds.get(), i, 1, (jint*)&(p_attrs[i].attr_id));
sCallbackEnv->SetObjectArrayElement(stringArray.get(), i, str.get());
}
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handletrackchanged,
- addr.get(), (jbyte)(num_attr), attribIds.get(),
- stringArray.get());
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handletrackchanged, addr.get(),
+ (jbyte)(num_attr), attribIds.get(), stringArray.get());
}
-static void btavrcp_play_position_changed_callback(const RawAddress& bd_addr,
- uint32_t song_len,
+static void btavrcp_play_position_changed_callback(const RawAddress& bd_addr, uint32_t song_len,
uint32_t song_pos) {
log::info("");
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
if (!sCallbacksObj) {
log::error("sCallbacksObj is null");
return;
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleplaypositionchanged,
- addr.get(), (jint)(song_len), (jint)song_pos);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleplaypositionchanged, addr.get(),
+ (jint)(song_len), (jint)song_pos);
}
-static void btavrcp_play_status_changed_callback(
- const RawAddress& bd_addr, btrc_play_status_t play_status) {
+static void btavrcp_play_status_changed_callback(const RawAddress& bd_addr,
+ btrc_play_status_t play_status) {
log::info("");
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
if (!sCallbacksObj) {
log::error("sCallbacksObj is null");
return;
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleplaystatuschanged,
- addr.get(), (jbyte)play_status);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleplaystatuschanged, addr.get(),
+ (jbyte)play_status);
}
-static void btavrcp_get_folder_items_callback(
- const RawAddress& bd_addr, btrc_status_t status,
- const btrc_folder_items_t* folder_items, uint8_t count) {
+static void btavrcp_get_folder_items_callback(const RawAddress& bd_addr, btrc_status_t status,
+ const btrc_folder_items_t* folder_items,
+ uint8_t count) {
/* Folder items are list of items that can be either BTRC_ITEM_PLAYER
* BTRC_ITEM_MEDIA, BTRC_ITEM_FOLDER. Here we translate them to their java
* counterparts by calling the java constructor for each of the items.
@@ -358,35 +350,33 @@ static void btavrcp_get_folder_items_callback(
log::verbose("count {}", count);
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
if (!sCallbacksObj) {
log::error("sCallbacksObj is null");
return;
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
// Inspect if the first element is a folder/item or player listing. They are
// always exclusive.
- bool isPlayerListing =
- count > 0 && (folder_items[0].item_type == BTRC_ITEM_PLAYER);
+ bool isPlayerListing = count > 0 && (folder_items[0].item_type == BTRC_ITEM_PLAYER);
// Initialize arrays for Folder OR Player listing.
ScopedLocalRef itemArray(sCallbackEnv.get(), NULL);
if (isPlayerListing) {
- itemArray.reset(
- sCallbackEnv->NewObjectArray((jint)count, class_AvrcpPlayer, 0));
+ itemArray.reset(sCallbackEnv->NewObjectArray((jint)count, class_AvrcpPlayer, 0));
} else {
- itemArray.reset(sCallbackEnv->NewObjectArray(
- (jint)count, class_AvrcpItem, 0));
+ itemArray.reset(sCallbackEnv->NewObjectArray((jint)count, class_AvrcpItem, 0));
}
if (!itemArray.get()) {
log::error("itemArray allocation failed.");
@@ -399,8 +389,7 @@ static void btavrcp_get_folder_items_callback(
case BTRC_ITEM_MEDIA: {
// Parse name
ScopedLocalRef mediaName(
- sCallbackEnv.get(),
- sCallbackEnv->NewStringUTF((const char*)item->media.name));
+ sCallbackEnv.get(), sCallbackEnv->NewStringUTF((const char*)item->media.name));
if (!mediaName.get()) {
log::error("can't allocate media name string!");
return;
@@ -408,41 +397,36 @@ static void btavrcp_get_folder_items_callback(
// Parse UID
long long uid = *(long long*)item->media.uid;
// Parse Attrs
- ScopedLocalRef attrIdArray(
- sCallbackEnv.get(),
- sCallbackEnv->NewIntArray(item->media.num_attrs));
+ ScopedLocalRef attrIdArray(sCallbackEnv.get(),
+ sCallbackEnv->NewIntArray(item->media.num_attrs));
if (!attrIdArray.get()) {
log::error("can't allocate attr id array!");
return;
}
ScopedLocalRef attrValArray(
- sCallbackEnv.get(),
- sCallbackEnv->NewObjectArray(
- item->media.num_attrs,
- sCallbackEnv->FindClass("java/lang/String"), 0));
+ sCallbackEnv.get(),
+ sCallbackEnv->NewObjectArray(item->media.num_attrs,
+ sCallbackEnv->FindClass("java/lang/String"), 0));
if (!attrValArray.get()) {
log::error("can't allocate attr val array!");
return;
}
for (int j = 0; j < item->media.num_attrs; j++) {
- sCallbackEnv->SetIntArrayRegion(
- attrIdArray.get(), j, 1,
- (jint*)&(item->media.p_attrs[j].attr_id));
+ sCallbackEnv->SetIntArrayRegion(attrIdArray.get(), j, 1,
+ (jint*)&(item->media.p_attrs[j].attr_id));
ScopedLocalRef attrValStr(
- sCallbackEnv.get(),
- sCallbackEnv->NewStringUTF((char*)(item->media.p_attrs[j].text)));
- sCallbackEnv->SetObjectArrayElement(attrValArray.get(), j,
- attrValStr.get());
+ sCallbackEnv.get(),
+ sCallbackEnv->NewStringUTF((char*)(item->media.p_attrs[j].text)));
+ sCallbackEnv->SetObjectArrayElement(attrValArray.get(), j, attrValStr.get());
}
ScopedLocalRef mediaObj(
- sCallbackEnv.get(),
- (jobject)sCallbackEnv->CallStaticObjectMethod(
- class_AvrcpControllerNativeInterface,
- method_createFromNativeMediaItem, addr.get(), uid,
- (jint)item->media.type, mediaName.get(), attrIdArray.get(),
- attrValArray.get()));
+ sCallbackEnv.get(),
+ (jobject)sCallbackEnv->CallStaticObjectMethod(
+ class_AvrcpControllerNativeInterface, method_createFromNativeMediaItem,
+ addr.get(), uid, (jint)item->media.type, mediaName.get(), attrIdArray.get(),
+ attrValArray.get()));
if (!mediaObj.get()) {
log::error("failed to create AvrcpItem for type ITEM_MEDIA");
return;
@@ -454,8 +438,7 @@ static void btavrcp_get_folder_items_callback(
case BTRC_ITEM_FOLDER: {
// Parse name
ScopedLocalRef folderName(
- sCallbackEnv.get(),
- sCallbackEnv->NewStringUTF((const char*)item->folder.name));
+ sCallbackEnv.get(), sCallbackEnv->NewStringUTF((const char*)item->folder.name));
if (!folderName.get()) {
log::error("can't allocate folder name string!");
return;
@@ -463,18 +446,16 @@ static void btavrcp_get_folder_items_callback(
// Parse UID
long long uid = *(long long*)item->folder.uid;
ScopedLocalRef folderObj(
- sCallbackEnv.get(),
- (jobject)sCallbackEnv->CallStaticObjectMethod(
- class_AvrcpControllerNativeInterface,
- method_createFromNativeFolderItem, addr.get(), uid,
- (jint)item->folder.type, folderName.get(),
- (jint)item->folder.playable));
+ sCallbackEnv.get(),
+ (jobject)sCallbackEnv->CallStaticObjectMethod(
+ class_AvrcpControllerNativeInterface, method_createFromNativeFolderItem,
+ addr.get(), uid, (jint)item->folder.type, folderName.get(),
+ (jint)item->folder.playable));
if (!folderObj.get()) {
log::error("failed to create AvrcpItem for type ITEM_FOLDER");
return;
}
- sCallbackEnv->SetObjectArrayElement(itemArray.get(), i,
- folderObj.get());
+ sCallbackEnv->SetObjectArrayElement(itemArray.get(), i, folderObj.get());
break;
}
@@ -485,37 +466,32 @@ static void btavrcp_get_folder_items_callback(
jint playerType = (jint)item->player.major_type;
jint playStatus = (jint)item->player.play_status;
ScopedLocalRef featureBitArray(
- sCallbackEnv.get(),
- sCallbackEnv->NewByteArray(BTRC_FEATURE_BIT_MASK_SIZE *
- sizeof(uint8_t)));
+ sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(BTRC_FEATURE_BIT_MASK_SIZE * sizeof(uint8_t)));
if (!featureBitArray.get()) {
log::error("failed to allocate featureBitArray");
return;
}
- sCallbackEnv->SetByteArrayRegion(
- featureBitArray.get(), 0,
- sizeof(uint8_t) * BTRC_FEATURE_BIT_MASK_SIZE,
- (jbyte*)item->player.features);
+ sCallbackEnv->SetByteArrayRegion(featureBitArray.get(), 0,
+ sizeof(uint8_t) * BTRC_FEATURE_BIT_MASK_SIZE,
+ (jbyte*)item->player.features);
ScopedLocalRef playerName(
- sCallbackEnv.get(),
- sCallbackEnv->NewStringUTF((const char*)item->player.name));
+ sCallbackEnv.get(), sCallbackEnv->NewStringUTF((const char*)item->player.name));
if (!playerName.get()) {
log::error("can't allocate player name string!");
return;
}
ScopedLocalRef playerObj(
- sCallbackEnv.get(),
- (jobject)sCallbackEnv->CallStaticObjectMethod(
- class_AvrcpControllerNativeInterface,
- method_createFromNativePlayerItem, addr.get(), id,
- playerName.get(), featureBitArray.get(), playStatus,
- playerType));
+ sCallbackEnv.get(),
+ (jobject)sCallbackEnv->CallStaticObjectMethod(
+ class_AvrcpControllerNativeInterface, method_createFromNativePlayerItem,
+ addr.get(), id, playerName.get(), featureBitArray.get(), playStatus,
+ playerType));
if (!playerObj.get()) {
log::error("failed to create AvrcpPlayer from ITEM_PLAYER");
return;
}
- sCallbackEnv->SetObjectArrayElement(itemArray.get(), i,
- playerObj.get());
+ sCallbackEnv->SetObjectArrayElement(itemArray.get(), i, playerObj.get());
break;
}
@@ -525,134 +501,131 @@ static void btavrcp_get_folder_items_callback(
}
if (isPlayerListing) {
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleGetPlayerItemsRsp,
- addr.get(), itemArray.get());
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleGetPlayerItemsRsp, addr.get(),
+ itemArray.get());
} else {
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleGetFolderItemsRsp,
- addr.get(), status, itemArray.get());
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleGetFolderItemsRsp, addr.get(), status,
+ itemArray.get());
}
}
-static void btavrcp_change_path_callback(const RawAddress& bd_addr,
- uint32_t count) {
+static void btavrcp_change_path_callback(const RawAddress& bd_addr, uint32_t count) {
log::info("count {}", count);
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
if (!sCallbacksObj) {
log::error("sCallbacksObj is null");
return;
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleChangeFolderRsp,
- addr.get(), (jint)count);
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleChangeFolderRsp, addr.get(),
+ (jint)count);
}
-static void btavrcp_set_browsed_player_callback(const RawAddress& bd_addr,
- uint8_t num_items,
+static void btavrcp_set_browsed_player_callback(const RawAddress& bd_addr, uint8_t num_items,
uint8_t depth) {
log::info("items {} depth {}", num_items, depth);
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
if (!sCallbacksObj) {
log::error("sCallbacksObj is null");
return;
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleSetBrowsedPlayerRsp,
- addr.get(), (jint)num_items, (jint)depth);
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleSetBrowsedPlayerRsp, addr.get(),
+ (jint)num_items, (jint)depth);
}
-static void btavrcp_set_addressed_player_callback(const RawAddress& bd_addr,
- uint8_t status) {
+static void btavrcp_set_addressed_player_callback(const RawAddress& bd_addr, uint8_t status) {
log::info("status {}", status);
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
if (!sCallbacksObj) {
log::error("sCallbacksObj is null");
return;
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
- sCallbackEnv->CallVoidMethod(sCallbacksObj,
- method_handleSetAddressedPlayerRsp, addr.get(),
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleSetAddressedPlayerRsp, addr.get(),
(jint)status);
}
-static void btavrcp_addressed_player_changed_callback(const RawAddress& bd_addr,
- uint16_t id) {
+static void btavrcp_addressed_player_changed_callback(const RawAddress& bd_addr, uint16_t id) {
log::info("status {}", id);
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
if (!sCallbacksObj) {
log::error("sCallbacksObj is null");
return;
}
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
- sCallbackEnv->CallVoidMethod(
- sCallbacksObj, method_handleAddressedPlayerChanged, addr.get(), (jint)id);
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleAddressedPlayerChanged, addr.get(),
+ (jint)id);
}
-static void btavrcp_now_playing_content_changed_callback(
- const RawAddress& bd_addr) {
+static void btavrcp_now_playing_content_changed_callback(const RawAddress& bd_addr) {
log::info("");
CallbackEnv sCallbackEnv(__func__);
- if (!sCallbackEnv.valid()) return;
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
- sCallbackEnv->CallVoidMethod(
- sCallbacksObj, method_handleNowPlayingContentChanged, addr.get());
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_handleNowPlayingContentChanged, addr.get());
}
-static void btavrcp_available_player_changed_callback (
- const RawAddress& bd_addr) {
+static void btavrcp_available_player_changed_callback(const RawAddress& bd_addr) {
log::info("");
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
@@ -660,23 +633,22 @@ static void btavrcp_available_player_changed_callback (
log::error("sCallbacksObj is null");
return;
}
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr);
- sCallbackEnv->CallVoidMethod(
- sCallbacksObj, method_onAvailablePlayerChanged, addr.get());
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr);
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_onAvailablePlayerChanged, addr.get());
}
-static void btavrcp_get_rcpsm_callback(const RawAddress& bd_addr,
- uint16_t psm) {
+static void btavrcp_get_rcpsm_callback(const RawAddress& bd_addr, uint16_t psm) {
log::error("-> psm received of {}", psm);
std::shared_lock lock(sCallbacks_mutex);
CallbackEnv sCallbackEnv(__func__);
@@ -684,60 +656,57 @@ static void btavrcp_get_rcpsm_callback(const RawAddress& bd_addr,
log::error("sCallbacksObj is null");
return;
}
- if (!sCallbackEnv.valid()) return;
+ if (!sCallbackEnv.valid()) {
+ return;
+ }
- ScopedLocalRef addr(
- sCallbackEnv.get(), sCallbackEnv->NewByteArray(sizeof(RawAddress)));
+ ScopedLocalRef addr(sCallbackEnv.get(),
+ sCallbackEnv->NewByteArray(sizeof(RawAddress)));
if (!addr.get()) {
log::error("Failed to allocate a new byte array");
return;
}
- sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress),
- (jbyte*)&bd_addr.address);
- sCallbackEnv->CallVoidMethod(sCallbacksObj, method_getRcPsm, addr.get(),
- (jint)psm);
+ sCallbackEnv->SetByteArrayRegion(addr.get(), 0, sizeof(RawAddress), (jbyte*)&bd_addr.address);
+ sCallbackEnv->CallVoidMethod(sCallbacksObj, method_getRcPsm, addr.get(), (jint)psm);
}
static btrc_ctrl_callbacks_t sBluetoothAvrcpCallbacks = {
- sizeof(sBluetoothAvrcpCallbacks),
- btavrcp_passthrough_response_callback,
- btavrcp_groupnavigation_response_callback,
- btavrcp_connection_state_callback,
- btavrcp_get_rcfeatures_callback,
- btavrcp_setplayerapplicationsetting_rsp_callback,
- btavrcp_playerapplicationsetting_callback,
- btavrcp_playerapplicationsetting_changed_callback,
- btavrcp_set_abs_vol_cmd_callback,
- btavrcp_register_notification_absvol_callback,
- btavrcp_track_changed_callback,
- btavrcp_play_position_changed_callback,
- btavrcp_play_status_changed_callback,
- btavrcp_get_folder_items_callback,
- btavrcp_change_path_callback,
- btavrcp_set_browsed_player_callback,
- btavrcp_set_addressed_player_callback,
- btavrcp_addressed_player_changed_callback,
- btavrcp_now_playing_content_changed_callback,
- btavrcp_available_player_changed_callback,
- btavrcp_get_rcpsm_callback,
+ sizeof(sBluetoothAvrcpCallbacks),
+ btavrcp_passthrough_response_callback,
+ btavrcp_groupnavigation_response_callback,
+ btavrcp_connection_state_callback,
+ btavrcp_get_rcfeatures_callback,
+ btavrcp_setplayerapplicationsetting_rsp_callback,
+ btavrcp_playerapplicationsetting_callback,
+ btavrcp_playerapplicationsetting_changed_callback,
+ btavrcp_set_abs_vol_cmd_callback,
+ btavrcp_register_notification_absvol_callback,
+ btavrcp_track_changed_callback,
+ btavrcp_play_position_changed_callback,
+ btavrcp_play_status_changed_callback,
+ btavrcp_get_folder_items_callback,
+ btavrcp_change_path_callback,
+ btavrcp_set_browsed_player_callback,
+ btavrcp_set_addressed_player_callback,
+ btavrcp_addressed_player_changed_callback,
+ btavrcp_now_playing_content_changed_callback,
+ btavrcp_available_player_changed_callback,
+ btavrcp_get_rcpsm_callback,
};
static void initNative(JNIEnv* env, jobject object) {
std::unique_lock lock(sCallbacks_mutex);
- jclass tmpAvrcpItem =
- env->FindClass("com/android/bluetooth/avrcpcontroller/AvrcpItem");
+ jclass tmpAvrcpItem = env->FindClass("com/android/bluetooth/avrcpcontroller/AvrcpItem");
class_AvrcpItem = (jclass)env->NewGlobalRef(tmpAvrcpItem);
- jclass tmpBtPlayer =
- env->FindClass("com/android/bluetooth/avrcpcontroller/AvrcpPlayer");
+ jclass tmpBtPlayer = 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);
+ jclass tmpControllerInterface =
+ env->FindClass("com/android/bluetooth/avrcpcontroller/AvrcpControllerNativeInterface");
+ class_AvrcpControllerNativeInterface = (jclass)env->NewGlobalRef(tmpControllerInterface);
const bt_interface_t* btInf = getBluetoothInterface();
if (btInf == NULL) {
@@ -758,15 +727,13 @@ static void initNative(JNIEnv* env, jobject object) {
}
sBluetoothAvrcpInterface =
- (btrc_ctrl_interface_t*)btInf->get_profile_interface(
- BT_PROFILE_AV_RC_CTRL_ID);
+ (btrc_ctrl_interface_t*)btInf->get_profile_interface(BT_PROFILE_AV_RC_CTRL_ID);
if (sBluetoothAvrcpInterface == NULL) {
log::error("Failed to get Bluetooth Avrcp Controller Interface");
return;
}
- bt_status_t status =
- sBluetoothAvrcpInterface->init(&sBluetoothAvrcpCallbacks);
+ bt_status_t status = sBluetoothAvrcpInterface->init(&sBluetoothAvrcpCallbacks);
if (status != BT_STATUS_SUCCESS) {
log::error("Failed to initialize Bluetooth Avrcp Controller, status: {}",
bt_status_text(status));
@@ -797,10 +764,11 @@ static void cleanupNative(JNIEnv* env, jobject /* object */) {
}
}
-static jboolean sendPassThroughCommandNative(JNIEnv* env, jobject /* object */,
- jbyteArray address, jint key_code,
- jint key_state) {
- if (!sBluetoothAvrcpInterface) return JNI_FALSE;
+static jboolean sendPassThroughCommandNative(JNIEnv* env, jobject /* object */, jbyteArray address,
+ jint key_code, jint key_state) {
+ if (!sBluetoothAvrcpInterface) {
+ return JNI_FALSE;
+ }
log::info("sBluetoothAvrcpInterface: {}", fmt::ptr(sBluetoothAvrcpInterface));
@@ -815,22 +783,21 @@ static jboolean sendPassThroughCommandNative(JNIEnv* env, jobject /* object */,
RawAddress rawAddress;
rawAddress.FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->send_pass_through_cmd(
- rawAddress, (uint8_t)key_code, (uint8_t)key_state);
+ rawAddress, (uint8_t)key_code, (uint8_t)key_state);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed sending passthru command, status: {}",
- bt_status_text(status));
+ log::error("Failed sending passthru command, status: {}", bt_status_text(status));
}
env->ReleaseByteArrayElements(address, addr, 0);
return (status == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
-static jboolean sendGroupNavigationCommandNative(JNIEnv* env,
- jobject /* object */,
- jbyteArray address,
- jint key_code,
+static jboolean sendGroupNavigationCommandNative(JNIEnv* env, jobject /* object */,
+ jbyteArray address, jint key_code,
jint key_state) {
- if (!sBluetoothAvrcpInterface) return JNI_FALSE;
+ if (!sBluetoothAvrcpInterface) {
+ return JNI_FALSE;
+ }
log::info("sBluetoothAvrcpInterface: {}", fmt::ptr(sBluetoothAvrcpInterface));
@@ -845,21 +812,22 @@ static jboolean sendGroupNavigationCommandNative(JNIEnv* env,
rawAddress.FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->send_group_navigation_cmd(
- rawAddress, (uint8_t)key_code, (uint8_t)key_state);
+ rawAddress, (uint8_t)key_code, (uint8_t)key_state);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed sending Grp Navigation command, status: {}",
- bt_status_text(status));
+ log::error("Failed sending Grp Navigation command, status: {}", bt_status_text(status));
}
env->ReleaseByteArrayElements(address, addr, 0);
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) {
log::info("sBluetoothAvrcpInterface: {}", fmt::ptr(sBluetoothAvrcpInterface));
- if (!sBluetoothAvrcpInterface) return;
+ if (!sBluetoothAvrcpInterface) {
+ return;
+ }
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
@@ -871,8 +839,7 @@ static void setPlayerApplicationSettingValuesNative(
uint8_t* pAttrsVal = new uint8_t[num_attrib];
if ((!pAttrs) || (!pAttrsVal)) {
delete[] pAttrs;
- log::error(
- "setPlayerApplicationSettingValuesNative: not have enough memory");
+ log::error("setPlayerApplicationSettingValuesNative: not have enough memory");
return;
}
@@ -894,10 +861,9 @@ static void setPlayerApplicationSettingValuesNative(
rawAddress.FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->set_player_app_setting_cmd(
- rawAddress, (uint8_t)num_attrib, pAttrs, pAttrsVal);
+ rawAddress, (uint8_t)num_attrib, pAttrs, pAttrsVal);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed sending setPlAppSettValNative command, status: {}",
- bt_status_text(status));
+ log::error("Failed sending setPlAppSettValNative command, status: {}", bt_status_text(status));
}
delete[] pAttrs;
delete[] pAttrsVal;
@@ -906,9 +872,11 @@ static void setPlayerApplicationSettingValuesNative(
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void sendAbsVolRspNative(JNIEnv* env, jobject /* object */,
- jbyteArray address, jint abs_vol, jint label) {
- if (!sBluetoothAvrcpInterface) return;
+static void sendAbsVolRspNative(JNIEnv* env, jobject /* object */, jbyteArray address, jint abs_vol,
+ jint label) {
+ if (!sBluetoothAvrcpInterface) {
+ return;
+ }
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
@@ -920,19 +888,19 @@ static void sendAbsVolRspNative(JNIEnv* env, jobject /* object */,
RawAddress rawAddress;
rawAddress.FromOctets((uint8_t*)addr);
- bt_status_t status = sBluetoothAvrcpInterface->set_volume_rsp(
- rawAddress, (uint8_t)abs_vol, (uint8_t)label);
+ bt_status_t status =
+ sBluetoothAvrcpInterface->set_volume_rsp(rawAddress, (uint8_t)abs_vol, (uint8_t)label);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed sending sendAbsVolRspNative command, status: {}",
- bt_status_text(status));
+ log::error("Failed sending sendAbsVolRspNative command, status: {}", bt_status_text(status));
}
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void sendRegisterAbsVolRspNative(JNIEnv* env, jobject /* object */,
- jbyteArray address, jbyte rsp_type,
- jint abs_vol, jint label) {
- if (!sBluetoothAvrcpInterface) return;
+static void sendRegisterAbsVolRspNative(JNIEnv* env, jobject /* object */, jbyteArray address,
+ jbyte rsp_type, jint abs_vol, jint label) {
+ if (!sBluetoothAvrcpInterface) {
+ return;
+ }
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
@@ -944,8 +912,7 @@ static void sendRegisterAbsVolRspNative(JNIEnv* env, jobject /* object */,
rawAddress.FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->register_abs_vol_rsp(
- rawAddress, (btrc_notification_type_t)rsp_type, (uint8_t)abs_vol,
- (uint8_t)label);
+ rawAddress, (btrc_notification_type_t)rsp_type, (uint8_t)abs_vol, (uint8_t)label);
if (status != BT_STATUS_SUCCESS) {
log::error("Failed sending sendRegisterAbsVolRspNative command, status: {}",
bt_status_text(status));
@@ -953,22 +920,21 @@ static void sendRegisterAbsVolRspNative(JNIEnv* env, jobject /* object */,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void getCurrentMetadataNative(JNIEnv* env, jobject /* object */,
- jbyteArray address) {
- if (!sBluetoothAvrcpInterface) return;
+static void getCurrentMetadataNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
+ if (!sBluetoothAvrcpInterface) {
+ return;
+ }
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
jniThrowIOException(env, EINVAL);
return;
}
- log::verbose("sBluetoothAvrcpInterface: {}",
- fmt::ptr(sBluetoothAvrcpInterface));
+ log::verbose("sBluetoothAvrcpInterface: {}", fmt::ptr(sBluetoothAvrcpInterface));
RawAddress rawAddress;
rawAddress.FromOctets((uint8_t*)addr);
- bt_status_t status =
- sBluetoothAvrcpInterface->get_current_metadata_cmd(rawAddress);
+ bt_status_t status = sBluetoothAvrcpInterface->get_current_metadata_cmd(rawAddress);
if (status != BT_STATUS_SUCCESS) {
log::error("Failed sending getCurrentMetadataNative command, status: {}",
bt_status_text(status));
@@ -976,44 +942,42 @@ static void getCurrentMetadataNative(JNIEnv* env, jobject /* object */,
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void getPlaybackStateNative(JNIEnv* env, jobject /* object */,
- jbyteArray address) {
- if (!sBluetoothAvrcpInterface) return;
+static void getPlaybackStateNative(JNIEnv* env, jobject /* object */, jbyteArray address) {
+ if (!sBluetoothAvrcpInterface) {
+ return;
+ }
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
jniThrowIOException(env, EINVAL);
return;
}
- log::verbose("sBluetoothAvrcpInterface: {}",
- fmt::ptr(sBluetoothAvrcpInterface));
+ log::verbose("sBluetoothAvrcpInterface: {}", fmt::ptr(sBluetoothAvrcpInterface));
RawAddress rawAddress;
rawAddress.FromOctets((uint8_t*)addr);
- bt_status_t status =
- sBluetoothAvrcpInterface->get_playback_state_cmd(rawAddress);
+ bt_status_t status = sBluetoothAvrcpInterface->get_playback_state_cmd(rawAddress);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed sending getPlaybackStateNative command, status: {}",
- bt_status_text(status));
+ log::error("Failed sending getPlaybackStateNative command, status: {}", bt_status_text(status));
}
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void getNowPlayingListNative(JNIEnv* env, jobject /* object */,
- jbyteArray address, jint start, jint end) {
- if (!sBluetoothAvrcpInterface) return;
+static void getNowPlayingListNative(JNIEnv* env, jobject /* object */, jbyteArray address,
+ jint start, jint end) {
+ if (!sBluetoothAvrcpInterface) {
+ return;
+ }
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
jniThrowIOException(env, EINVAL);
return;
}
- log::verbose("sBluetoothAvrcpInterface: {}",
- fmt::ptr(sBluetoothAvrcpInterface));
+ log::verbose("sBluetoothAvrcpInterface: {}", fmt::ptr(sBluetoothAvrcpInterface));
RawAddress rawAddress;
rawAddress.FromOctets((uint8_t*)addr);
- bt_status_t status = sBluetoothAvrcpInterface->get_now_playing_list_cmd(
- rawAddress, start, end);
+ bt_status_t status = sBluetoothAvrcpInterface->get_now_playing_list_cmd(rawAddress, start, end);
if (status != BT_STATUS_SUCCESS) {
log::error("Failed sending getNowPlayingListNative command, status: {}",
bt_status_text(status));
@@ -1021,31 +985,32 @@ 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) {
- if (!sBluetoothAvrcpInterface) return;
+static void getFolderListNative(JNIEnv* env, jobject /* object */, jbyteArray address, jint start,
+ jint end) {
+ if (!sBluetoothAvrcpInterface) {
+ return;
+ }
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
jniThrowIOException(env, EINVAL);
return;
}
- log::verbose("sBluetoothAvrcpInterface: {}",
- fmt::ptr(sBluetoothAvrcpInterface));
+ log::verbose("sBluetoothAvrcpInterface: {}", fmt::ptr(sBluetoothAvrcpInterface));
RawAddress rawAddress;
rawAddress.FromOctets((uint8_t*)addr);
- bt_status_t status =
- sBluetoothAvrcpInterface->get_folder_list_cmd(rawAddress, start, end);
+ bt_status_t status = sBluetoothAvrcpInterface->get_folder_list_cmd(rawAddress, start, end);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed sending getFolderListNative command, status: {}",
- bt_status_text(status));
+ log::error("Failed sending getFolderListNative command, status: {}", bt_status_text(status));
}
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void getPlayerListNative(JNIEnv* env, jobject /* object */,
- jbyteArray address, jint start, jint end) {
- if (!sBluetoothAvrcpInterface) return;
+static void getPlayerListNative(JNIEnv* env, jobject /* object */, jbyteArray address, jint start,
+ jint end) {
+ if (!sBluetoothAvrcpInterface) {
+ return;
+ }
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
jniThrowIOException(env, EINVAL);
@@ -1055,19 +1020,18 @@ static void getPlayerListNative(JNIEnv* env, jobject /* object */,
RawAddress rawAddress;
rawAddress.FromOctets((uint8_t*)addr);
- bt_status_t status =
- sBluetoothAvrcpInterface->get_player_list_cmd(rawAddress, start, end);
+ bt_status_t status = sBluetoothAvrcpInterface->get_player_list_cmd(rawAddress, start, end);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed sending getPlayerListNative command, status: {}",
- bt_status_text(status));
+ log::error("Failed sending getPlayerListNative command, status: {}", bt_status_text(status));
}
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void changeFolderPathNative(JNIEnv* env, jobject /* object */,
- jbyteArray address, jbyte direction,
- jlong uid) {
- if (!sBluetoothAvrcpInterface) return;
+static void changeFolderPathNative(JNIEnv* env, jobject /* object */, jbyteArray address,
+ jbyte direction, jlong uid) {
+ if (!sBluetoothAvrcpInterface) {
+ return;
+ }
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
jniThrowIOException(env, EINVAL);
@@ -1085,17 +1049,17 @@ static void changeFolderPathNative(JNIEnv* env, jobject /* object */,
rawAddress.FromOctets((uint8_t*)addr);
bt_status_t status = sBluetoothAvrcpInterface->change_folder_path_cmd(
- rawAddress, (uint8_t)direction, (uint8_t*)&uid);
+ rawAddress, (uint8_t)direction, (uint8_t*)&uid);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed sending changeFolderPathNative command, status: {}",
- bt_status_text(status));
+ log::error("Failed sending changeFolderPathNative command, status: {}", bt_status_text(status));
}
// env->ReleaseByteArrayElements(address, addr, 0);
}
-static void setBrowsedPlayerNative(JNIEnv* env, jobject /* object */,
- jbyteArray address, jint id) {
- if (!sBluetoothAvrcpInterface) return;
+static void setBrowsedPlayerNative(JNIEnv* env, jobject /* object */, jbyteArray address, jint id) {
+ if (!sBluetoothAvrcpInterface) {
+ return;
+ }
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
jniThrowIOException(env, EINVAL);
@@ -1105,18 +1069,18 @@ static void setBrowsedPlayerNative(JNIEnv* env, jobject /* object */,
rawAddress.FromOctets((uint8_t*)addr);
log::info("sBluetoothAvrcpInterface: {}", fmt::ptr(sBluetoothAvrcpInterface));
- bt_status_t status = sBluetoothAvrcpInterface->set_browsed_player_cmd(
- rawAddress, (uint16_t)id);
+ bt_status_t status = sBluetoothAvrcpInterface->set_browsed_player_cmd(rawAddress, (uint16_t)id);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed sending setBrowsedPlayerNative command, status: {}",
- bt_status_text(status));
+ log::error("Failed sending setBrowsedPlayerNative command, status: {}", bt_status_text(status));
}
env->ReleaseByteArrayElements(address, addr, 0);
}
-static void setAddressedPlayerNative(JNIEnv* env, jobject /* object */,
- jbyteArray address, jint id) {
- if (!sBluetoothAvrcpInterface) return;
+static void setAddressedPlayerNative(JNIEnv* env, jobject /* object */, jbyteArray address,
+ jint id) {
+ if (!sBluetoothAvrcpInterface) {
+ return;
+ }
jbyte* addr = env->GetByteArrayElements(address, NULL);
if (!addr) {
jniThrowIOException(env, EINVAL);
@@ -1126,8 +1090,7 @@ static void setAddressedPlayerNative(JNIEnv* env, jobject /* object */,
rawAddress.FromOctets((uint8_t*)addr);
log::info("sBluetoothAvrcpInterface: {}", fmt::ptr(sBluetoothAvrcpInterface));
- bt_status_t status = sBluetoothAvrcpInterface->set_addressed_player_cmd(
- rawAddress, (uint16_t)id);
+ bt_status_t status = sBluetoothAvrcpInterface->set_addressed_player_cmd(rawAddress, (uint16_t)id);
if (status != BT_STATUS_SUCCESS) {
log::error("Failed sending setAddressedPlayerNative command, status: {}",
bt_status_text(status));
@@ -1135,10 +1098,11 @@ 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) {
- if (!sBluetoothAvrcpInterface) return;
+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) {
jniThrowIOException(env, EINVAL);
@@ -1155,92 +1119,75 @@ static void playItemNative(JNIEnv* env, jobject /* object */,
log::info("sBluetoothAvrcpInterface: {}", fmt::ptr(sBluetoothAvrcpInterface));
bt_status_t status = sBluetoothAvrcpInterface->play_item_cmd(
- rawAddress, (uint8_t)scope, (uint8_t*)&uid, (uint16_t)uidCounter);
+ rawAddress, (uint8_t)scope, (uint8_t*)&uid, (uint16_t)uidCounter);
if (status != BT_STATUS_SUCCESS) {
- log::error("Failed sending playItemNative command, status: {}",
- bt_status_text(status));
+ log::error("Failed sending playItemNative command, status: {}", bt_status_text(status));
}
env->ReleaseByteArrayElements(address, addr, 0);
}
int register_com_android_bluetooth_avrcp_controller(JNIEnv* env) {
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},
+ {"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);
+ 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},
+ {"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);
+ 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 671be3933857dbfd9b0350cf79d3a096f5588ddc..d717ad0d8dfc00d742b28d9f1928e002d6b6e9d4 100644
--- a/android/app/jni/com_android_bluetooth_avrcp_target.cpp
+++ b/android/app/jni/com_android_bluetooth_avrcp_target.cpp
@@ -18,16 +18,30 @@
#include
#include
+#include
#include