diff options
53 files changed, 127 insertions, 433 deletions
diff --git a/android/app/src/com/android/bluetooth/BluetoothObexTransport.java b/android/app/src/com/android/bluetooth/BluetoothObexTransport.java index 3c57ec1600..d101f1736e 100644 --- a/android/app/src/com/android/bluetooth/BluetoothObexTransport.java +++ b/android/app/src/com/android/bluetooth/BluetoothObexTransport.java @@ -18,7 +18,6 @@ package com.android.bluetooth; import android.annotation.SuppressLint; import android.bluetooth.BluetoothSocket; -import com.android.bluetooth.flags.Flags; import com.android.obex.ObexTransport; import java.io.DataInputStream; @@ -112,10 +111,7 @@ public class BluetoothObexTransport implements ObexTransport { if (mSocket == null) { return null; } - String identityAddress = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(mSocket.getRemoteDevice()) - : mSocket.getRemoteDevice().getIdentityAddress(); + String identityAddress = Utils.getBrEdrAddress(mSocket.getRemoteDevice()); return mSocket.getConnectionType() == BluetoothSocket.TYPE_RFCOMM ? identityAddress : mSocket.getRemoteDevice().getAddress(); diff --git a/android/app/src/com/android/bluetooth/a2dp/A2dpNativeInterface.java b/android/app/src/com/android/bluetooth/a2dp/A2dpNativeInterface.java index fe74b2facd..688f57ce8a 100644 --- a/android/app/src/com/android/bluetooth/a2dp/A2dpNativeInterface.java +++ b/android/app/src/com/android/bluetooth/a2dp/A2dpNativeInterface.java @@ -29,8 +29,6 @@ import android.bluetooth.BluetoothCodecType; import android.bluetooth.BluetoothDevice; import com.android.bluetooth.Utils; -import com.android.bluetooth.btservice.AdapterService; -import com.android.bluetooth.flags.Flags; import com.android.internal.annotations.VisibleForTesting; import java.lang.annotation.Native; @@ -41,15 +39,12 @@ import java.util.List; public class A2dpNativeInterface { private static final String TAG = A2dpNativeInterface.class.getSimpleName(); - private final AdapterService mAdapterService; @Native private final A2dpNativeCallback mNativeCallback; private BluetoothCodecType[] mSupportedCodecTypes; @VisibleForTesting - A2dpNativeInterface( - @NonNull AdapterService adapterService, @NonNull A2dpNativeCallback nativeCallback) { - mAdapterService = requireNonNull(adapterService); + A2dpNativeInterface(@NonNull A2dpNativeCallback nativeCallback) { mNativeCallback = requireNonNull(nativeCallback); } @@ -132,15 +127,11 @@ public class A2dpNativeInterface { return setCodecConfigPreferenceNative(getByteAddress(device), codecConfigArray); } - private byte[] getByteAddress(BluetoothDevice device) { + private static byte[] getByteAddress(BluetoothDevice device) { if (device == null) { return Utils.getBytesFromAddress("00:00:00:00:00:00"); } - if (Flags.identityAddressNullIfNotKnown()) { - return Utils.getByteBrEdrAddress(device); - } else { - return mAdapterService.getByteIdentityAddress(device); - } + return Utils.getByteBrEdrAddress(device); } private native void initNative( diff --git a/android/app/src/com/android/bluetooth/a2dp/A2dpService.java b/android/app/src/com/android/bluetooth/a2dp/A2dpService.java index de37a5b3f4..6633e4e2ea 100644 --- a/android/app/src/com/android/bluetooth/a2dp/A2dpService.java +++ b/android/app/src/com/android/bluetooth/a2dp/A2dpService.java @@ -125,7 +125,6 @@ public class A2dpService extends ProfileService { nativeInterface, () -> new A2dpNativeInterface( - adapterService, new A2dpNativeCallback(adapterService, this))); mDatabaseManager = requireNonNull(mAdapterService.getDatabase()); mAudioManager = requireNonNull(getSystemService(AudioManager.class)); diff --git a/android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface.java b/android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface.java index e3b4c400a3..6822e4e734 100644 --- a/android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface.java +++ b/android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkNativeInterface.java @@ -23,7 +23,6 @@ import android.util.Log; import com.android.bluetooth.Utils; import com.android.bluetooth.btservice.AdapterService; -import com.android.bluetooth.flags.Flags; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; @@ -78,14 +77,6 @@ public class A2dpSinkNativeInterface { return mAdapterService.getDeviceFromByte(address); } - private byte[] getByteAddress(BluetoothDevice device) { - if (Flags.identityAddressNullIfNotKnown()) { - return Utils.getByteBrEdrAddress(device); - } else { - return mAdapterService.getByteIdentityAddress(device); - } - } - /** * Initiates an A2DP connection to a remote device. * @@ -93,7 +84,7 @@ public class A2dpSinkNativeInterface { * @return true on success, otherwise false. */ public boolean connectA2dpSink(BluetoothDevice device) { - return connectA2dpNative(getByteAddress(device)); + return connectA2dpNative(Utils.getByteBrEdrAddress(device)); } /** @@ -103,7 +94,7 @@ public class A2dpSinkNativeInterface { * @return true on success, otherwise false. */ public boolean disconnectA2dpSink(BluetoothDevice device) { - return disconnectA2dpNative(getByteAddress(device)); + return disconnectA2dpNative(Utils.getByteBrEdrAddress(device)); } /** @@ -120,7 +111,7 @@ public class A2dpSinkNativeInterface { // Translate to byte address for JNI. Use an all 0 MAC for no active device byte[] address = null; if (device != null) { - address = getByteAddress(device); + address = Utils.getByteBrEdrAddress(device); } else { address = Utils.getBytesFromAddress("00:00:00:00:00:00"); } diff --git a/android/app/src/com/android/bluetooth/avrcp/AvrcpNativeInterface.java b/android/app/src/com/android/bluetooth/avrcp/AvrcpNativeInterface.java index 720ce84dd8..85d1043023 100644 --- a/android/app/src/com/android/bluetooth/avrcp/AvrcpNativeInterface.java +++ b/android/app/src/com/android/bluetooth/avrcp/AvrcpNativeInterface.java @@ -28,7 +28,6 @@ import com.android.bluetooth.audio_util.PlayStatus; import com.android.bluetooth.audio_util.PlayerInfo; import com.android.bluetooth.audio_util.PlayerSettingsManager.PlayerSettingsValues; import com.android.bluetooth.btservice.AdapterService; -import com.android.bluetooth.flags.Flags; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; @@ -93,10 +92,7 @@ public class AvrcpNativeInterface { } void setBipClientStatus(BluetoothDevice device, boolean connected) { - String identityAddress = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(device) - : mAdapterService.getIdentityAddress(device.getAddress()); + String identityAddress = Utils.getBrEdrAddress(device); setBipClientStatusNative(identityAddress, connected); } @@ -237,10 +233,7 @@ public class AvrcpNativeInterface { } boolean disconnectDevice(BluetoothDevice device) { - String identityAddress = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(device) - : mAdapterService.getIdentityAddress(device.getAddress()); + String identityAddress = Utils.getBrEdrAddress(device); d("disconnectDevice: identityAddress=" + identityAddress); return disconnectDeviceNative(identityAddress); } @@ -278,10 +271,7 @@ public class AvrcpNativeInterface { void sendVolumeChanged(BluetoothDevice device, int volume) { d("sendVolumeChanged: volume=" + volume); - String identityAddress = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(device) - : mAdapterService.getIdentityAddress(device.getAddress()); + String identityAddress = Utils.getBrEdrAddress(device); sendVolumeChangedNative(identityAddress, volume); } diff --git a/android/app/src/com/android/bluetooth/btservice/AdapterProperties.java b/android/app/src/com/android/bluetooth/btservice/AdapterProperties.java index bd483f5925..013c799af7 100644 --- a/android/app/src/com/android/bluetooth/btservice/AdapterProperties.java +++ b/android/app/src/com/android/bluetooth/btservice/AdapterProperties.java @@ -55,7 +55,6 @@ import androidx.annotation.VisibleForTesting; import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.Utils; import com.android.bluetooth.btservice.RemoteDevices.DeviceProperties; -import com.android.bluetooth.flags.Flags; import com.android.modules.utils.build.SdkLevel; import java.io.FileDescriptor; @@ -531,10 +530,7 @@ class AdapterProperties { void cleanupPrevBondRecordsFor(BluetoothDevice device) { String address = device.getAddress(); - String identityAddress = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(device, mService) - : mService.getIdentityAddress(address); + String identityAddress = Utils.getBrEdrAddress(device, mService); int deviceType = mRemoteDevices.getDeviceProperties(device).getDeviceType(); debugLog("cleanupPrevBondRecordsFor: " + device + ", device type: " + deviceType); if (identityAddress == null) { @@ -547,10 +543,7 @@ class AdapterProperties { for (BluetoothDevice existingDevice : mBondedDevices) { String existingAddress = existingDevice.getAddress(); - String existingIdentityAddress = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(existingDevice, mService) - : mService.getIdentityAddress(existingAddress); + String existingIdentityAddress = Utils.getBrEdrAddress(existingDevice, mService); int existingDeviceType = mRemoteDevices.getDeviceProperties(existingDevice).getDeviceType(); @@ -1100,10 +1093,7 @@ class AdapterProperties { StringBuilder sb = new StringBuilder(); for (BluetoothDevice device : mBondedDevices) { String address = device.getAddress(); - String brEdrAddress = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(device) - : mService.getIdentityAddress(address); + String brEdrAddress = Utils.getBrEdrAddress(device); if (brEdrAddress.equals(address)) { writer.println( " " diff --git a/android/app/src/com/android/bluetooth/btservice/AdapterService.java b/android/app/src/com/android/bluetooth/btservice/AdapterService.java index 9bec63769d..e9202c4f6c 100644 --- a/android/app/src/com/android/bluetooth/btservice/AdapterService.java +++ b/android/app/src/com/android/bluetooth/btservice/AdapterService.java @@ -2689,12 +2689,8 @@ public class AdapterService extends Service { return Utils.getBytesFromAddress(deviceProp.getIdentityAddress()); } - if (Flags.identityAddressNullIfNotKnown()) { - // Return null if identity address unknown - return null; - } else { - return Utils.getByteAddress(device); - } + // Return null if identity address unknown + return null; } public BluetoothDevice getDeviceFromByte(byte[] address) { @@ -2712,14 +2708,9 @@ public class AdapterService extends Service { DeviceProperties deviceProp = mRemoteDevices.getDeviceProperties(device); if (deviceProp != null && deviceProp.getIdentityAddress() != null) { return deviceProp.getIdentityAddress(); - } else { - if (Flags.identityAddressNullIfNotKnown()) { - // Return null if identity address unknown - return null; - } else { - return address; - } } + // Return null if identity address unknown + return null; } /** @@ -2745,11 +2736,7 @@ public class AdapterService extends Service { } identityAddressType = deviceProp.getIdentityAddressType(); } else { - if (Flags.identityAddressNullIfNotKnown()) { - identityAddress = null; - } else { - identityAddress = address; - } + identityAddress = null; } return new BluetoothAddress(identityAddress, identityAddressType); diff --git a/android/app/src/com/android/bluetooth/btservice/BluetoothSocketManagerBinder.java b/android/app/src/com/android/bluetooth/btservice/BluetoothSocketManagerBinder.java index f9dcbe8017..0bdebd30e5 100644 --- a/android/app/src/com/android/bluetooth/btservice/BluetoothSocketManagerBinder.java +++ b/android/app/src/com/android/bluetooth/btservice/BluetoothSocketManagerBinder.java @@ -29,7 +29,6 @@ import android.os.ParcelUuid; import android.util.Log; import com.android.bluetooth.Utils; -import com.android.bluetooth.flags.Flags; class BluetoothSocketManagerBinder extends IBluetoothSocketManager.Stub { private static final String TAG = BluetoothSocketManagerBinder.class.getSimpleName(); @@ -58,10 +57,7 @@ class BluetoothSocketManagerBinder extends IBluetoothSocketManager.Stub { return null; } - String brEdrAddress = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(device) - : mService.getIdentityAddress(device.getAddress()); + String brEdrAddress = Utils.getBrEdrAddress(device); Log.i( TAG, @@ -118,10 +114,7 @@ class BluetoothSocketManagerBinder extends IBluetoothSocketManager.Stub { mService.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null); enforceSocketOffloadSupport(type); } - String brEdrAddress = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(device) - : mService.getIdentityAddress(device.getAddress()); + String brEdrAddress = Utils.getBrEdrAddress(device); Log.i( TAG, diff --git a/android/app/src/com/android/bluetooth/hfp/HeadsetNativeInterface.java b/android/app/src/com/android/bluetooth/hfp/HeadsetNativeInterface.java index 5afe78cee5..e3816ed636 100644 --- a/android/app/src/com/android/bluetooth/hfp/HeadsetNativeInterface.java +++ b/android/app/src/com/android/bluetooth/hfp/HeadsetNativeInterface.java @@ -24,7 +24,6 @@ import android.util.Log; import com.android.bluetooth.Utils; import com.android.bluetooth.btservice.AdapterService; -import com.android.bluetooth.flags.Flags; import com.android.internal.annotations.GuardedBy; /** @@ -84,16 +83,12 @@ public class HeadsetNativeInterface { return mAdapterService.getDeviceFromByte(address); } - private byte[] getByteAddress(BluetoothDevice device) { + private static byte[] getByteAddress(BluetoothDevice device) { if (device == null) { // Set bt_stack's active device to default if java layer set active device to null return Utils.getBytesFromAddress("00:00:00:00:00:00"); } - if (Flags.identityAddressNullIfNotKnown()) { - return Utils.getByteBrEdrAddress(device); - } else { - return mAdapterService.getByteIdentityAddress(device); - } + return Utils.getByteBrEdrAddress(device); } void onConnectionStateChanged(int state, byte[] address) { diff --git a/android/app/src/com/android/bluetooth/hfpclient/NativeInterface.java b/android/app/src/com/android/bluetooth/hfpclient/NativeInterface.java index fbb68747fe..bcbb49fba6 100644 --- a/android/app/src/com/android/bluetooth/hfpclient/NativeInterface.java +++ b/android/app/src/com/android/bluetooth/hfpclient/NativeInterface.java @@ -27,7 +27,6 @@ import android.util.Log; import com.android.bluetooth.Utils; import com.android.bluetooth.btservice.AdapterService; -import com.android.bluetooth.flags.Flags; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; @@ -334,12 +333,8 @@ public class NativeInterface { return mAdapterService.getDeviceFromByte(address); } - private byte[] getByteAddress(BluetoothDevice device) { - if (Flags.identityAddressNullIfNotKnown()) { - return Utils.getByteBrEdrAddress(device); - } else { - return mAdapterService.getByteIdentityAddress(device); - } + private static byte[] getByteAddress(BluetoothDevice device) { + return Utils.getByteBrEdrAddress(device); } // Callbacks from the native back into the java framework. All callbacks are routed via the diff --git a/android/app/src/com/android/bluetooth/hid/HidDeviceNativeInterface.java b/android/app/src/com/android/bluetooth/hid/HidDeviceNativeInterface.java index 2ca9078103..dc269b7abf 100644 --- a/android/app/src/com/android/bluetooth/hid/HidDeviceNativeInterface.java +++ b/android/app/src/com/android/bluetooth/hid/HidDeviceNativeInterface.java @@ -29,7 +29,6 @@ import android.util.Log; import com.android.bluetooth.Utils; import com.android.bluetooth.btservice.AdapterService; -import com.android.bluetooth.flags.Flags; import com.android.internal.annotations.VisibleForTesting; /** HID Device Native Interface to/from JNI. */ @@ -123,7 +122,7 @@ public class HidDeviceNativeInterface { * @return the result of the native call */ public boolean connect(BluetoothDevice device) { - return connectNative(getByteAddress(device)); + return connectNative(Utils.getByteBrEdrAddress(device)); } /** @@ -243,14 +242,6 @@ public class HidDeviceNativeInterface { return mAdapterService.getDeviceFromByte(address); } - private byte[] getByteAddress(BluetoothDevice device) { - if (Flags.identityAddressNullIfNotKnown()) { - return Utils.getByteBrEdrAddress(device); - } else { - return mAdapterService.getByteIdentityAddress(device); - } - } - private native void initNative(); private native void cleanupNative(); diff --git a/android/app/src/com/android/bluetooth/hid/HidHostService.java b/android/app/src/com/android/bluetooth/hid/HidHostService.java index 1eac6ed336..68c2be4a8b 100644 --- a/android/app/src/com/android/bluetooth/hid/HidHostService.java +++ b/android/app/src/com/android/bluetooth/hid/HidHostService.java @@ -162,14 +162,6 @@ public class HidHostService extends ProfileService { setHidHostService(null); } - private byte[] getIdentityAddress(BluetoothDevice device) { - if (Flags.identityAddressNullIfNotKnown()) { - return Utils.getByteBrEdrAddress(mAdapterService, device); - } else { - return mAdapterService.getByteIdentityAddress(device); - } - } - private byte[] getByteAddress(BluetoothDevice device, int transport) { final ParcelUuid[] uuids = mAdapterService.getRemoteUuids(device); @@ -177,14 +169,14 @@ public class HidHostService extends ProfileService { // Use pseudo address when HOGP is to be used return Utils.getByteAddress(device); } else if (transport == BluetoothDevice.TRANSPORT_BREDR) { - // Use identity address if HID is to be used - return getIdentityAddress(device); + // Use BR/EDR address if HID is to be used + return Utils.getByteBrEdrAddress(mAdapterService, device); } else { // BluetoothDevice.TRANSPORT_AUTO boolean hidSupported = Utils.arrayContains(uuids, BluetoothUuid.HID); // Prefer HID over HOGP if (hidSupported) { - // Use identity address if HID is available - return getIdentityAddress(device); + // Use BR/EDR address if HID is available + return Utils.getByteBrEdrAddress(mAdapterService, device); } else { // Otherwise use pseudo address return Utils.getByteAddress(device); diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppHandoverReceiver.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppHandoverReceiver.java index 81c59f8ad2..d87bd420fe 100644 --- a/android/app/src/com/android/bluetooth/opp/BluetoothOppHandoverReceiver.java +++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppHandoverReceiver.java @@ -25,7 +25,6 @@ import android.util.Log; import com.android.bluetooth.BluetoothMethodProxy; import com.android.bluetooth.Utils; -import com.android.bluetooth.flags.Flags; import java.util.ArrayList; @@ -82,10 +81,7 @@ public class BluetoothOppHandoverReceiver extends BroadcastReceiver { if (device == null) { return; } - String brEdrAddress = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(device) - : device.getIdentityAddress(); + String brEdrAddress = Utils.getBrEdrAddress(device); Log.d(TAG, "Adding " + brEdrAddress + " to acceptlist"); BluetoothOppManager.getInstance(context).addToAcceptlist(brEdrAddress); } else if (action.equals(Constants.ACTION_STOP_HANDOVER)) { diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppManager.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppManager.java index 730c1e9ce2..c745f243d4 100644 --- a/android/app/src/com/android/bluetooth/opp/BluetoothOppManager.java +++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppManager.java @@ -54,7 +54,6 @@ import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.R; import com.android.bluetooth.Utils; import com.android.bluetooth.content_profiles.ContentProfileErrorReportUtils; -import com.android.bluetooth.flags.Flags; import com.android.internal.annotations.VisibleForTesting; import java.util.ArrayList; @@ -480,11 +479,7 @@ public class BluetoothOppManager { } values.put(BluetoothShare.MIMETYPE, contentType); - values.put( - BluetoothShare.DESTINATION, - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(mRemoteDevice) - : mRemoteDevice.getIdentityAddress()); + values.put(BluetoothShare.DESTINATION, Utils.getBrEdrAddress(mRemoteDevice)); values.put(BluetoothShare.TIMESTAMP, ts); if (mIsHandoverInitiated) { values.put( @@ -512,11 +507,7 @@ public class BluetoothOppManager { ContentValues values = new ContentValues(); values.put(BluetoothShare.URI, mUri); values.put(BluetoothShare.MIMETYPE, mTypeOfSingleFile); - values.put( - BluetoothShare.DESTINATION, - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(mRemoteDevice) - : mRemoteDevice.getIdentityAddress()); + values.put(BluetoothShare.DESTINATION, Utils.getBrEdrAddress(mRemoteDevice)); if (mIsHandoverInitiated) { values.put( BluetoothShare.USER_CONFIRMATION, diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppPreference.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppPreference.java index 6164cb4f58..114adfe631 100644 --- a/android/app/src/com/android/bluetooth/opp/BluetoothOppPreference.java +++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppPreference.java @@ -32,7 +32,6 @@ package com.android.bluetooth.opp; -import android.annotation.SuppressLint; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothUtils; import android.content.Context; @@ -41,7 +40,6 @@ import android.content.SharedPreferences.Editor; import android.util.Log; import com.android.bluetooth.Utils; -import com.android.bluetooth.flags.Flags; import java.util.HashMap; @@ -87,11 +85,11 @@ public class BluetoothOppPreference { } private static String getChannelKey(BluetoothDevice remoteDevice, int uuid) { - return getBrEdrAddress(remoteDevice) + "_" + Integer.toHexString(uuid); + return Utils.getBrEdrAddress(remoteDevice) + "_" + Integer.toHexString(uuid); } public String getName(BluetoothDevice remoteDevice) { - String identityAddress = getBrEdrAddress(remoteDevice); + String identityAddress = Utils.getBrEdrAddress(remoteDevice); if (identityAddress != null && identityAddress.equals("FF:FF:FF:00:00:00")) { return "localhost"; } @@ -113,7 +111,8 @@ public class BluetoothOppPreference { Log.v( TAG, "getChannel for " - + BluetoothUtils.toAnonymizedAddress(getBrEdrAddress(remoteDevice)) + + BluetoothUtils.toAnonymizedAddress( + Utils.getBrEdrAddress(remoteDevice)) + "_" + Integer.toHexString(uuid) + " as " @@ -123,7 +122,7 @@ public class BluetoothOppPreference { } public void setName(BluetoothDevice remoteDevice, String name) { - String brEdrAddress = getBrEdrAddress(remoteDevice); + String brEdrAddress = Utils.getBrEdrAddress(remoteDevice); Log.v( TAG, "setName for " + BluetoothUtils.toAnonymizedAddress(brEdrAddress) + " to " + name); @@ -139,7 +138,7 @@ public class BluetoothOppPreference { Log.v( TAG, "setChannel for " - + BluetoothUtils.toAnonymizedAddress(getBrEdrAddress(remoteDevice)) + + BluetoothUtils.toAnonymizedAddress(Utils.getBrEdrAddress(remoteDevice)) + "_" + Integer.toHexString(uuid) + " to " @@ -163,7 +162,7 @@ public class BluetoothOppPreference { public void removeName(BluetoothDevice remoteDevice) { Editor ed = mNamePreference.edit(); - String key = getBrEdrAddress(remoteDevice); + String key = Utils.getBrEdrAddress(remoteDevice); ed.remove(key); ed.apply(); mNames.remove(key); @@ -175,12 +174,4 @@ public class BluetoothOppPreference { Log.d(TAG, "Dumping Channels: "); Log.d(TAG, mChannels.toString()); } - - @SuppressLint("AndroidFrameworkRequiresPermission") - private static String getBrEdrAddress(BluetoothDevice device) { - if (Flags.identityAddressNullIfNotKnown()) { - return Utils.getBrEdrAddress(device); - } - return device.getIdentityAddress(); - } } diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppReceiver.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppReceiver.java index eb9b7f91c4..77dadd9a65 100644 --- a/android/app/src/com/android/bluetooth/opp/BluetoothOppReceiver.java +++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppReceiver.java @@ -52,7 +52,6 @@ import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.R; import com.android.bluetooth.Utils; import com.android.bluetooth.content_profiles.ContentProfileErrorReportUtils; -import com.android.bluetooth.flags.Flags; /** * Receives and handles: system broadcasts; Intents from other applications; Intents from @@ -81,9 +80,7 @@ public class BluetoothOppReceiver extends BroadcastReceiver { TAG, "Received BT device selected intent, bt device: " + BluetoothUtils.toAnonymizedAddress( - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(remoteDevice) - : remoteDevice.getIdentityAddress())); + Utils.getBrEdrAddress(remoteDevice))); // Insert transfer session record to database mOppManager.startTransfer(remoteDevice); diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppService.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppService.java index 2548b9e45c..f043cbcc53 100644 --- a/android/app/src/com/android/bluetooth/opp/BluetoothOppService.java +++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppService.java @@ -121,7 +121,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti // Since ContentObserver is created with Handler, onChange() can be called // even after the observer is unregistered. - if (Flags.oppIgnoreContentObserverAfterServiceStop() && mObserver != this) { + if (mObserver != this) { Log.d(TAG, "onChange() called after stop() is called."); return; } @@ -1346,9 +1346,7 @@ public class BluetoothOppService extends ProfileService implements IObexConnecti + socket + " \n :device :" + BluetoothUtils.toAnonymizedAddress( - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(device, mAdapterService) - : mAdapterService.getIdentityAddress(device.getAddress()))); + Utils.getBrEdrAddress(device, mAdapterService))); if (!mAcceptNewConnections) { Log.d(TAG, " onConnect BluetoothSocket :" + socket + " rejected"); return false; diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppTransfer.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppTransfer.java index 1ff73d1b48..5e92f1e81e 100644 --- a/android/app/src/com/android/bluetooth/opp/BluetoothOppTransfer.java +++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppTransfer.java @@ -63,7 +63,6 @@ import com.android.bluetooth.BluetoothObexTransport; import com.android.bluetooth.BluetoothStatsLog; import com.android.bluetooth.Utils; import com.android.bluetooth.content_profiles.ContentProfileErrorReportUtils; -import com.android.bluetooth.flags.Flags; import com.android.internal.annotations.VisibleForTesting; import com.android.obex.ObexTransport; @@ -116,7 +115,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch Log.e( TAG, "device : " - + BluetoothUtils.toAnonymizedAddress(getBrEdrAddress(device)) + + BluetoothUtils.toAnonymizedAddress( + Utils.getBrEdrAddress(device)) + " mBatch :" + mBatch + " mCurrentShare :" @@ -133,7 +133,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch Log.v( TAG, "Device :" - + BluetoothUtils.toAnonymizedAddress(getBrEdrAddress(device)) + + BluetoothUtils.toAnonymizedAddress( + Utils.getBrEdrAddress(device)) + "- OPP device: " + mBatch.mDestination + " \n mCurrentShare.mConfirm == " @@ -180,8 +181,8 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch 3); return; } - String deviceIdentityAddress = getBrEdrAddress(device); - String transferDeviceIdentityAddress = getBrEdrAddress(mDevice); + String deviceIdentityAddress = Utils.getBrEdrAddress(device); + String transferDeviceIdentityAddress = Utils.getBrEdrAddress(mDevice); if (deviceIdentityAddress == null || transferDeviceIdentityAddress == null || !deviceIdentityAddress.equalsIgnoreCase( @@ -1008,11 +1009,4 @@ public class BluetoothOppTransfer implements BluetoothOppBatch.BluetoothOppBatch } } } - - private static String getBrEdrAddress(BluetoothDevice device) { - if (Flags.identityAddressNullIfNotKnown()) { - return Utils.getBrEdrAddress(device); - } - return device.getIdentityAddress(); - } } diff --git a/android/app/src/com/android/bluetooth/pan/PanService.java b/android/app/src/com/android/bluetooth/pan/PanService.java index 5c2dfdf2a7..a27724b785 100644 --- a/android/app/src/com/android/bluetooth/pan/PanService.java +++ b/android/app/src/com/android/bluetooth/pan/PanService.java @@ -212,9 +212,7 @@ public class PanService extends ProfileService { case MESSAGE_CONNECT: BluetoothDevice connectDevice = (BluetoothDevice) msg.obj; if (!mNativeInterface.connect( - Flags.identityAddressNullIfNotKnown() - ? Utils.getByteBrEdrAddress(mAdapterService, connectDevice) - : mAdapterService.getByteIdentityAddress(connectDevice))) { + Utils.getByteBrEdrAddress(mAdapterService, connectDevice))) { handlePanDeviceStateChange( connectDevice, null, @@ -232,9 +230,7 @@ public class PanService extends ProfileService { case MESSAGE_DISCONNECT: BluetoothDevice disconnectDevice = (BluetoothDevice) msg.obj; if (!mNativeInterface.disconnect( - Flags.identityAddressNullIfNotKnown() - ? Utils.getByteBrEdrAddress(mAdapterService, disconnectDevice) - : mAdapterService.getByteIdentityAddress(disconnectDevice))) { + Utils.getByteBrEdrAddress(mAdapterService, disconnectDevice))) { handlePanDeviceStateChange( disconnectDevice, mPanIfName, diff --git a/android/app/src/com/android/bluetooth/sdp/SdpManager.java b/android/app/src/com/android/bluetooth/sdp/SdpManager.java index 3a316f8457..de6193aeb2 100644 --- a/android/app/src/com/android/bluetooth/sdp/SdpManager.java +++ b/android/app/src/com/android/bluetooth/sdp/SdpManager.java @@ -35,7 +35,6 @@ import android.util.Log; import com.android.bluetooth.Utils; import com.android.bluetooth.btservice.AbstractionLayer; import com.android.bluetooth.btservice.AdapterService; -import com.android.bluetooth.flags.Flags; import com.android.internal.annotations.GuardedBy; import java.util.ArrayList; @@ -143,16 +142,10 @@ public class SdpManager { SdpSearchInstance getSearchInstance(byte[] address, byte[] uuidBytes) { String addressString = Utils.getAddressStringFromByte(address); - addressString = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(addressString, mAdapterService) - : mAdapterService.getIdentityAddress(addressString); + addressString = Utils.getBrEdrAddress(addressString, mAdapterService); ParcelUuid uuid = Utils.byteArrayToUuid(uuidBytes)[0]; for (SdpSearchInstance inst : mList) { - String instAddressString = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(inst.getDevice(), mAdapterService) - : mAdapterService.getIdentityAddress(inst.getDevice().getAddress()); + String instAddressString = Utils.getBrEdrAddress(inst.getDevice(), mAdapterService); if (instAddressString.equals(addressString) && inst.getUuid().equals(uuid)) { return inst; } @@ -161,15 +154,9 @@ public class SdpManager { } boolean isSearching(BluetoothDevice device, ParcelUuid uuid) { - String addressString = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(device, mAdapterService) - : mAdapterService.getIdentityAddress(device.getAddress()); + String addressString = Utils.getBrEdrAddress(device, mAdapterService); for (SdpSearchInstance inst : mList) { - String instAddressString = - Flags.identityAddressNullIfNotKnown() - ? Utils.getBrEdrAddress(inst.getDevice(), mAdapterService) - : mAdapterService.getIdentityAddress(inst.getDevice().getAddress()); + String instAddressString = Utils.getBrEdrAddress(inst.getDevice(), mAdapterService); if (instAddressString != null && addressString != null && instAddressString.equals(addressString) @@ -473,9 +460,7 @@ public class SdpManager { inst.startSearch(); // Trigger timeout message mNativeInterface.sdpSearch( - Flags.identityAddressNullIfNotKnown() - ? Utils.getByteBrEdrAddress(inst.getDevice()) - : mAdapterService.getByteIdentityAddress(inst.getDevice()), + Utils.getByteBrEdrAddress(inst.getDevice()), Utils.uuidToByteArray(inst.getUuid())); } else { // Else queue is empty. Log.d( diff --git a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java index a9e01b3086..6c7b1ed44e 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/btservice/AdapterServiceTest.java @@ -907,10 +907,6 @@ public class AdapterServiceTest { // Create device properties RemoteDevices remoteDevices = mAdapterService.getRemoteDevices(); remoteDevices.addDeviceProperties(Utils.getBytesFromAddress((TEST_BT_ADDR_1))); - String identityAddress = mAdapterService.getIdentityAddress(TEST_BT_ADDR_1); - if (!Flags.identityAddressNullIfNotKnown()) { - assertThat(identityAddress).isEqualTo(TEST_BT_ADDR_1); - } // Trigger address consolidate callback remoteDevices.addressConsolidateCallback( @@ -918,7 +914,7 @@ public class AdapterServiceTest { Utils.getBytesFromAddress(TEST_BT_ADDR_2)); // Verify we can get correct identity address - identityAddress = mAdapterService.getIdentityAddress(TEST_BT_ADDR_1); + String identityAddress = mAdapterService.getIdentityAddress(TEST_BT_ADDR_1); assertThat(identityAddress).isEqualTo(TEST_BT_ADDR_2); assertThat(mLooper.nextMessage()).isNull(); } @@ -955,7 +951,6 @@ public class AdapterServiceTest { } @Test - @EnableFlags(Flags.FLAG_IDENTITY_ADDRESS_NULL_IF_NOT_KNOWN) public void testIdentityAddressNullIfUnknown() { BluetoothDevice device = getTestDevice(0); diff --git a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java index f6c393909c..3ab02065e3 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/opp/BluetoothOppTransferTest.java @@ -390,7 +390,6 @@ public class BluetoothOppTransferTest { @Test public void oppConnectionReceiver_onReceiveWithActionSdpRecord_withoutSdpRecord() { - mSetFlagRule.enableFlags(Flags.FLAG_IDENTITY_ADDRESS_NULL_IF_NOT_KNOWN); BluetoothDevice device = InstrumentationRegistry.getInstrumentation() .getTargetContext() diff --git a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientObexTransportTest.java b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientObexTransportTest.java index dfcc542467..b594ac70b4 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientObexTransportTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/pbapclient/PbapClientObexTransportTest.java @@ -183,7 +183,6 @@ public class PbapClientObexTransportTest { public void testGetRemoteAddress_transportRfcomm_returnsDeviceIdentityAddress() { doReturn(BluetoothSocket.TYPE_RFCOMM).when(mMockSocket).getConnectionType(); PbapClientObexTransport transport = new PbapClientObexTransport(mMockSocket); - // See "Flags.identityAddressNullIfNotKnown():" // Identity address won't be "known" by the stack for a test device, so it'll return null. // assertThat(transport.getRemoteAddress()).isNull(); assertThat(transport.getRemoteAddress()).isEqualTo(mTestDevice.getAddress()); diff --git a/flags/bta_dm.aconfig b/flags/bta_dm.aconfig index 19e8418785..be510f63cd 100644 --- a/flags/bta_dm.aconfig +++ b/flags/bta_dm.aconfig @@ -9,16 +9,6 @@ flag { } flag { - name: "cancel_open_discovery_client" - namespace: "bluetooth" - description: "Cancel connection from discovery client correctly" - bug: "356168480" - metadata { - purpose: PURPOSE_BUGFIX - } -} - -flag { name: "extend_and_randomize_role_switch_delay" namespace: "bluetooth" description: "Fix the possible conflicts between role switch and authentication" diff --git a/flags/framework.aconfig b/flags/framework.aconfig index dc48541118..0151b46c70 100644 --- a/flags/framework.aconfig +++ b/flags/framework.aconfig @@ -10,16 +10,6 @@ flag { } flag { - name: "identity_address_null_if_not_known" - namespace: "bluetooth" - description: "Return null for identity address if identity address is not known" - bug: "317120534" - metadata { - purpose: PURPOSE_BUGFIX - } -} - -flag { name: "support_bluetooth_quality_report_v6" is_exported: true namespace: "bluetooth" diff --git a/flags/gap.aconfig b/flags/gap.aconfig index edc7874fb5..2b833af69a 100644 --- a/flags/gap.aconfig +++ b/flags/gap.aconfig @@ -57,16 +57,6 @@ flag { } flag { - name: "gatt_fix_multiple_direct_connect" - namespace: "bluetooth" - description: "Do not remove device when multiple clients attempt to connect" - bug: "349232327" - metadata { - purpose: PURPOSE_BUGFIX - } -} - -flag { name: "pan_use_identity_address" namespace: "bluetooth" description: "Use identity address when communicate with native interface" diff --git a/flags/opp.aconfig b/flags/opp.aconfig index 6d1a13bf21..cdba75b756 100644 --- a/flags/opp.aconfig +++ b/flags/opp.aconfig @@ -2,16 +2,6 @@ package: "com.android.bluetooth.flags" container: "com.android.bt" flag { - name: "opp_ignore_content_observer_after_service_stop" - namespace: "bluetooth" - description: "When OppService.stop() is called, previously posted ContentObserver.onChange() should not run" - bug: "346467641" - metadata { - purpose: PURPOSE_BUGFIX - } -} - -flag { name: "opp_set_insets_for_edge_to_edge" namespace: "bluetooth" description: "Set proper insets in BluetoothOppTransferHistory to adapt to edge-to-edge." diff --git a/framework/tests/bumble/src/android/bluetooth/GattClientTest.java b/framework/tests/bumble/src/android/bluetooth/GattClientTest.java index 9b631dce91..29a9668a07 100644 --- a/framework/tests/bumble/src/android/bluetooth/GattClientTest.java +++ b/framework/tests/bumble/src/android/bluetooth/GattClientTest.java @@ -422,7 +422,6 @@ public class GattClientTest { } @Test - @RequiresFlagsEnabled(Flags.FLAG_GATT_FIX_MULTIPLE_DIRECT_CONNECT) public void connectMultiple_closeOne_shouldSuccess() { BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class); BluetoothGattCallback gattCallback2 = mock(BluetoothGattCallback.class); diff --git a/system/bta/dm/bta_dm_disc.cc b/system/bta/dm/bta_dm_disc.cc index b3f010e86e..79d3421361 100644 --- a/system/bta/dm/bta_dm_disc.cc +++ b/system/bta/dm/bta_dm_disc.cc @@ -152,8 +152,7 @@ gatt_interface_t& get_gatt_interface() { return *gatt_interface; } void bta_dm_disc_gatt_cancel_open(const RawAddress& bd_addr) { get_gatt_interface().BTA_GATTC_CancelOpen(0, bd_addr, false); - if (com::android::bluetooth::flags::cancel_open_discovery_client() && - bta_dm_discovery_cb.client_if != BTA_GATTS_INVALID_IF) { + if (bta_dm_discovery_cb.client_if != BTA_GATTS_INVALID_IF) { get_gatt_interface().BTA_GATTC_CancelOpen(bta_dm_discovery_cb.client_if, bd_addr, true); } } @@ -559,11 +558,7 @@ static void bta_dm_gatt_disc_complete(tCONN_ID conn_id, tGATT_STATUS status) { } else { log::info("Discovery complete for invalid conn ID. Will pick up next job"); - if (com::android::bluetooth::flags::cancel_open_discovery_client()) { - bta_dm_close_gatt_conn(bta_dm_discovery_cb.conn_id); - } else { - bta_dm_discovery_cb.conn_id = GATT_INVALID_CONN_ID; - } + bta_dm_close_gatt_conn(bta_dm_discovery_cb.conn_id); if (bta_dm_discovery_cb.transports & BT_TRANSPORT_BR_EDR) { log::info("classic discovery still pending {}", bta_dm_discovery_cb.peer_bdaddr); return; diff --git a/system/gd/common/audit_log.cc b/system/gd/common/audit_log.cc index e83c2894f8..2e112a0c34 100644 --- a/system/gd/common/audit_log.cc +++ b/system/gd/common/audit_log.cc @@ -16,6 +16,8 @@ #include "common/audit_log.h" +#include <format> + #ifdef __ANDROID__ #include <log/log_event_list.h> #endif // __ANDROID__ @@ -43,8 +45,8 @@ void LogConnectionAdminAuditEvent([[maybe_unused]] const char* action, android_log_event_list(SEC_TAG_BLUETOOTH_CONNECTION) << address.ToRedactedStringForLogging() - << /* success */ int32_t(status == hci::ErrorCode::SUCCESS) << action << ": " - << ErrorCodeText(status) << LOG_ID_SECURITY; + << /* success */ int32_t(status == hci::ErrorCode::SUCCESS) + << std::format("{}: {}", action, ErrorCodeText(status)) << LOG_ID_SECURITY; #endif /* defined(__ANDROID__) && !defined (FUZZ_TARGET) */ } diff --git a/system/gd/hal/snoop_logger.h b/system/gd/hal/snoop_logger.h index b009add89c..b0783442b3 100644 --- a/system/gd/hal/snoop_logger.h +++ b/system/gd/hal/snoop_logger.h @@ -17,6 +17,7 @@ #pragma once #include <bluetooth/log.h> +#include <com_android_bluetooth_flags.h> #include <fstream> #include <string> @@ -195,6 +196,13 @@ public: }; SnoopLogger(os::Handler* handler); + ~SnoopLogger() { + if (!com::android::bluetooth::flags::same_handler_for_all_modules()) { + GetHandler()->Clear(); + GetHandler()->WaitUntilStopped(std::chrono::milliseconds(2000)); + delete GetHandler(); + } + } // Returns the maximum number of packets per file // Changes to this value is only effective after restarting Bluetooth diff --git a/system/gd/hci/acl_manager.cc b/system/gd/hci/acl_manager.cc index 26b0ce70eb..280cc237b4 100644 --- a/system/gd/hci/acl_manager.cc +++ b/system/gd/hci/acl_manager.cc @@ -260,16 +260,6 @@ void AclManager::CreateLeConnection(AddressWithType address_with_type, bool is_d CallOn(pimpl_->le_impl_, &le_impl::create_le_connection, address_with_type, true, is_direct); } -void AclManager::SetLeSuggestedDefaultDataParameters(uint16_t octets, uint16_t time) { - CallOn(pimpl_->le_impl_, &le_impl::set_le_suggested_default_data_parameters, octets, time); -} - -void AclManager::LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, - uint16_t max_latency, uint16_t cont_num, uint16_t sup_tout) { - CallOn(pimpl_->le_impl_, &le_impl::LeSetDefaultSubrate, subrate_min, subrate_max, max_latency, - cont_num, sup_tout); -} - void AclManager::SetPrivacyPolicyForInitiatorAddress( LeAddressManager::AddressPolicy address_policy, AddressWithType fixed_address, std::chrono::milliseconds minimum_rotation_time, diff --git a/system/gd/hci/acl_manager.h b/system/gd/hci/acl_manager.h index 2b3d523b1f..f38f1ff689 100644 --- a/system/gd/hci/acl_manager.h +++ b/system/gd/hci/acl_manager.h @@ -86,12 +86,6 @@ public: // Generates OnLeConnectSuccess if connected, or OnLeConnectFail otherwise virtual void CreateLeConnection(AddressWithType address_with_type, bool is_direct); - // Ask the controller for specific data parameters - virtual void SetLeSuggestedDefaultDataParameters(uint16_t octets, uint16_t time); - - virtual void LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, - uint16_t cont_num, uint16_t sup_tout); - virtual void SetPrivacyPolicyForInitiatorAddress(LeAddressManager::AddressPolicy address_policy, AddressWithType fixed_address, std::chrono::milliseconds minimum_rotation_time, diff --git a/system/gd/hci/acl_manager/le_impl.h b/system/gd/hci/acl_manager/le_impl.h index ce93f46e7e..ef5bfb0d7d 100644 --- a/system/gd/hci/acl_manager/le_impl.h +++ b/system/gd/hci/acl_manager/le_impl.h @@ -1149,25 +1149,6 @@ public: remove_device_from_accept_list(address_with_type); } - void set_le_suggested_default_data_parameters(uint16_t length, uint16_t time) { - auto packet = LeWriteSuggestedDefaultDataLengthBuilder::Create(length, time); - le_acl_connection_interface_->EnqueueCommand( - std::move(packet), handler_->BindOnce([](CommandCompleteView /* complete */) {})); - } - - void LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, - uint16_t cont_num, uint16_t sup_tout) { - le_acl_connection_interface_->EnqueueCommand( - LeSetDefaultSubrateBuilder::Create(subrate_min, subrate_max, max_latency, cont_num, - sup_tout), - handler_->BindOnce([](CommandCompleteView complete) { - auto complete_view = LeSetDefaultSubrateCompleteView::Create(complete); - log::assert_that(complete_view.IsValid(), "assert failed: complete_view.IsValid()"); - ErrorCode status = complete_view.GetStatus(); - log::assert_that(status == ErrorCode::SUCCESS, "Status = {}", ErrorCodeText(status)); - })); - } - void clear_resolving_list() { le_address_manager_->ClearResolvingList(); } void set_privacy_policy_for_initiator_address(LeAddressManager::AddressPolicy address_policy, diff --git a/system/gd/hci/acl_manager/le_impl_test.cc b/system/gd/hci/acl_manager/le_impl_test.cc index 66bc16bbd8..274b6827c9 100644 --- a/system/gd/hci/acl_manager/le_impl_test.cc +++ b/system/gd/hci/acl_manager/le_impl_test.cc @@ -1475,29 +1475,6 @@ TEST_F(LeImplTest, cancel_connect) { ASSERT_TRUE(le_impl_->create_connection_timeout_alarms_.empty()); } -TEST_F(LeImplTest, set_le_suggested_default_data_parameters) { - le_impl_->set_le_suggested_default_data_parameters(kLength, kTime); - sync_handler(); - auto view = CreateLeConnectionManagementCommandView<LeWriteSuggestedDefaultDataLengthView>( - hci_layer_->GetCommand()); - ASSERT_TRUE(view.IsValid()); - ASSERT_EQ(kLength, view.GetTxOctets()); - ASSERT_EQ(kTime, view.GetTxTime()); -} - -TEST_F(LeImplTest, LeSetDefaultSubrate) { - le_impl_->LeSetDefaultSubrate(kIntervalMin, kIntervalMax, kLatency, kContinuationNumber, - kTimeout); - sync_handler(); - auto view = CreateAclCommandView<LeSetDefaultSubrateView>(hci_layer_->GetCommand()); - ASSERT_TRUE(view.IsValid()); - ASSERT_EQ(kIntervalMin, view.GetSubrateMin()); - ASSERT_EQ(kIntervalMax, view.GetSubrateMax()); - ASSERT_EQ(kLatency, view.GetMaxLatency()); - ASSERT_EQ(kContinuationNumber, view.GetContinuationNumber()); - ASSERT_EQ(kTimeout, view.GetSupervisionTimeout()); -} - enum class ConnectionCompleteType { CONNECTION_COMPLETE, ENHANCED_CONNECTION_COMPLETE }; class LeImplTestParameterizedByConnectionCompleteEventType diff --git a/system/gd/metrics/counter_metrics.h b/system/gd/metrics/counter_metrics.h index 88c7711f92..2f25f03ed0 100644 --- a/system/gd/metrics/counter_metrics.h +++ b/system/gd/metrics/counter_metrics.h @@ -15,6 +15,8 @@ */ #pragma once +#include <com_android_bluetooth_flags.h> + #include <unordered_map> #include "module.h" @@ -26,6 +28,13 @@ namespace metrics { class CounterMetrics : public bluetooth::Module { public: CounterMetrics(os::Handler* handler) : Module(handler) {} + ~CounterMetrics() { + if (!com::android::bluetooth::flags::same_handler_for_all_modules()) { + GetHandler()->Clear(); + GetHandler()->WaitUntilStopped(std::chrono::milliseconds(2000)); + delete GetHandler(); + } + } bool CacheCount(int32_t key, int64_t value); virtual bool Count(int32_t key, int64_t count); diff --git a/system/gd/storage/storage_module.cc b/system/gd/storage/storage_module.cc index 5e3459e109..5a81a5cf94 100644 --- a/system/gd/storage/storage_module.cc +++ b/system/gd/storage/storage_module.cc @@ -90,6 +90,13 @@ StorageModule::StorageModule(os::Handler* handler, std::string config_file_path, StorageModule::~StorageModule() { std::lock_guard<std::recursive_mutex> lock(mutex_); + + if (!com::android::bluetooth::flags::same_handler_for_all_modules()) { + GetHandler()->Clear(); + GetHandler()->WaitUntilStopped(std::chrono::milliseconds(2000)); + delete GetHandler(); + } + pimpl_.reset(); } diff --git a/system/main/shim/acl.cc b/system/main/shim/acl.cc index b2f0e23975..b01bd1f92d 100644 --- a/system/main/shim/acl.cc +++ b/system/main/shim/acl.cc @@ -969,11 +969,6 @@ struct shim::Acl::impl { maximum_latency, minimum_remote_timeout, minimum_local_timeout); } - void LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, - uint16_t cont_num, uint16_t sup_tout) { - GetAclManager()->LeSetDefaultSubrate(subrate_min, subrate_max, max_latency, cont_num, sup_tout); - } - void LeSubrateRequest(HciHandle handle, uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, uint16_t cont_num, uint16_t sup_tout) { if (IsLeAcl(handle)) { @@ -1573,12 +1568,6 @@ void shim::Acl::UpdateConnectionParameters(uint16_t handle, uint16_t conn_int_mi conn_int_max, conn_latency, conn_timeout, min_ce_len, max_ce_len); } -void shim::Acl::LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, - uint16_t max_latency, uint16_t cont_num, uint16_t sup_tout) { - handler_->CallOn(pimpl_.get(), &Acl::impl::LeSetDefaultSubrate, subrate_min, subrate_max, - max_latency, cont_num, sup_tout); -} - void shim::Acl::LeSubrateRequest(uint16_t hci_handle, uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, uint16_t cont_num, uint16_t sup_tout) { handler_->CallOn(pimpl_.get(), &Acl::impl::LeSubrateRequest, hci_handle, subrate_min, subrate_max, diff --git a/system/main/shim/acl.h b/system/main/shim/acl.h index bbe15d0acf..8253faf013 100644 --- a/system/main/shim/acl.h +++ b/system/main/shim/acl.h @@ -80,8 +80,6 @@ public: void RemoveFromAddressResolution(const hci::AddressWithType& address_with_type); void ClearAddressResolution(); - void LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, - uint16_t cont_num, uint16_t sup_tout); void LeSubrateRequest(uint16_t hci_handle, uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, uint16_t cont_num, uint16_t sup_tout); diff --git a/system/main/shim/acl_api.cc b/system/main/shim/acl_api.cc index 56e63e1977..0868f40f2c 100644 --- a/system/main/shim/acl_api.cc +++ b/system/main/shim/acl_api.cc @@ -166,12 +166,6 @@ void bluetooth::shim::ACL_ClearAddressResolution() { void bluetooth::shim::ACL_ClearFilterAcceptList() { Stack::GetInstance()->GetAcl()->ClearFilterAcceptList(); } -void bluetooth::shim::ACL_LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, - uint16_t max_latency, uint16_t cont_num, - uint16_t sup_tout) { - Stack::GetInstance()->GetAcl()->LeSetDefaultSubrate(subrate_min, subrate_max, max_latency, - cont_num, sup_tout); -} void bluetooth::shim::ACL_LeSubrateRequest(uint16_t hci_handle, uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, diff --git a/system/main/shim/acl_api.h b/system/main/shim/acl_api.h index 6b28988ca6..b0bac16e02 100644 --- a/system/main/shim/acl_api.h +++ b/system/main/shim/acl_api.h @@ -49,8 +49,6 @@ void ACL_AddToAddressResolution(const tBLE_BD_ADDR& legacy_address_with_type, void ACL_RemoveFromAddressResolution(const tBLE_BD_ADDR& legacy_address_with_type); void ACL_ClearAddressResolution(); void ACL_ClearFilterAcceptList(); -void ACL_LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, - uint16_t cont_num, uint16_t sup_tout); void ACL_SendConnectionParameterUpdateRequest(uint16_t handle, uint16_t conn_int_min, uint16_t conn_int_max, uint16_t conn_latency, uint16_t conn_timeout, uint16_t min_ce_len, diff --git a/system/main/shim/stack.cc b/system/main/shim/stack.cc index 4560a6180f..b7b93d3690 100644 --- a/system/main/shim/stack.cc +++ b/system/main/shim/stack.cc @@ -67,9 +67,9 @@ namespace shim { struct Stack::impl { Acl* acl_ = nullptr; - metrics::CounterMetrics* counter_metrics_ = nullptr; - storage::StorageModule* storage_ = nullptr; - hal::SnoopLogger* snoop_logger_ = nullptr; + std::shared_ptr<metrics::CounterMetrics> counter_metrics_ = nullptr; + std::shared_ptr<storage::StorageModule> storage_ = nullptr; + std::shared_ptr<hal::SnoopLogger> snoop_logger_ = nullptr; }; Stack::Stack() { pimpl_ = std::make_shared<Stack::impl>(); } @@ -89,9 +89,16 @@ void Stack::StartEverything() { stack_thread_ = new os::Thread("gd_stack_thread", os::Thread::Priority::REAL_TIME); stack_handler_ = new os::Handler(stack_thread_); - pimpl_->counter_metrics_ = new metrics::CounterMetrics(new Handler(stack_thread_)); - pimpl_->storage_ = new storage::StorageModule(new Handler(stack_thread_)); - pimpl_->snoop_logger_ = new hal::SnoopLogger(new Handler(stack_thread_)); + if (com::android::bluetooth::flags::same_handler_for_all_modules()) { + pimpl_->counter_metrics_ = std::make_shared<metrics::CounterMetrics>(stack_handler_); + pimpl_->storage_ = std::make_shared<storage::StorageModule>(stack_handler_); + pimpl_->snoop_logger_ = std::make_shared<hal::SnoopLogger>(stack_handler_); + } else { + pimpl_->counter_metrics_ = + std::make_shared<metrics::CounterMetrics>(new Handler(stack_thread_)); + pimpl_->storage_ = std::make_shared<storage::StorageModule>(new Handler(stack_thread_)); + pimpl_->snoop_logger_ = std::make_shared<hal::SnoopLogger>(new Handler(stack_thread_)); + } #if TARGET_FLOSS modules.add<sysprops::SyspropsModule>(); @@ -220,19 +227,19 @@ Acl* Stack::GetAcl() const { metrics::CounterMetrics* Stack::GetCounterMetrics() const { std::lock_guard<std::recursive_mutex> lock(mutex_); log::assert_that(is_running_, "assert failed: is_running_"); - return pimpl_->counter_metrics_; + return pimpl_->counter_metrics_.get(); } storage::StorageModule* Stack::GetStorage() const { std::lock_guard<std::recursive_mutex> lock(mutex_); log::assert_that(is_running_, "assert failed: is_running_"); - return pimpl_->storage_; + return pimpl_->storage_.get(); } hal::SnoopLogger* Stack::GetSnoopLogger() const { std::lock_guard<std::recursive_mutex> lock(mutex_); log::assert_that(is_running_, "assert failed: is_running_"); - return pimpl_->snoop_logger_; + return pimpl_->snoop_logger_.get(); } os::Handler* Stack::GetHandler() { @@ -268,9 +275,15 @@ void Stack::handle_start_up(ModuleList* modules, std::promise<void> promise) { void Stack::handle_shut_down(std::promise<void> promise) { registry_.StopAll(); + pimpl_->snoop_logger_->Stop(); pimpl_->storage_->Stop(); pimpl_->counter_metrics_->Stop(); + + pimpl_->snoop_logger_.reset(); + pimpl_->storage_.reset(); + pimpl_->counter_metrics_.reset(); + promise.set_value(); } diff --git a/system/stack/btm/btm_ble_sec.cc b/system/stack/btm/btm_ble_sec.cc index cef553c79e..679e937eef 100644 --- a/system/stack/btm/btm_ble_sec.cc +++ b/system/stack/btm/btm_ble_sec.cc @@ -1662,6 +1662,13 @@ static bool btm_ble_complete_evt_ignore(const tBTM_SEC_DEV_REC* p_dev_rec, p_dev_rec->bd_addr); l2cu_start_post_bond_timer(p_dev_rec->ble_hci_handle); return true; + } else if (com::android::bluetooth::flags::le_peripheral_enc_failure() && + !p_dev_rec->role_central) { + log::warn("Peripheral encryption request failed for the bonded device {} with reason {}", + p_dev_rec->bd_addr, smp_status_text(p_data->complt.reason)); + btm_sec_disconnect(p_dev_rec->ble_hci_handle, HCI_ERR_AUTH_FAILURE, + smp_status_text(p_data->complt.reason)); + return true; } } @@ -1702,6 +1709,11 @@ static void btm_ble_complete_evt(const RawAddress& bd_addr, tBTM_SEC_DEV_REC* p_ } BTM_BLE_SEC_CALLBACK(BTM_LE_COMPLT_EVT, bd_addr, p_data); + p_dev_rec = btm_find_dev(bd_addr); // BTM_LE_COMPLT_EVT event may have removed the device + if (p_dev_rec == nullptr) { + log::warn("Device record removed {}", bd_addr); + return; + } log::verbose("before update sec_level=0x{:x} sec_flags=0x{:x}", p_data->complt.sec_level, p_dev_rec->sec_rec.sec_flags); diff --git a/system/stack/btm/btm_sec.cc b/system/stack/btm/btm_sec.cc index 3c07ce8a58..4595794cab 100644 --- a/system/stack/btm/btm_sec.cc +++ b/system/stack/btm/btm_sec.cc @@ -3129,12 +3129,12 @@ void btm_sec_auth_complete(uint16_t handle, tHCI_STATUS status) { p_dev_rec->sec_rec.security_required &= ~BTM_SEC_OUT_AUTHENTICATE; if (status != HCI_SUCCESS) { - if ((status != HCI_ERR_PEER_USER) && (status != HCI_ERR_CONN_CAUSE_LOCAL_HOST)) { + if (status != HCI_ERR_PEER_USER && status != HCI_ERR_CONN_CAUSE_LOCAL_HOST) { btm_sec_send_hci_disconnect( p_dev_rec, HCI_ERR_PEER_USER, p_dev_rec->hci_handle, "stack::btm::btm_sec::btm_sec_auth_retry Auth fail while bonding"); } - } else { + } else if (!com::android::bluetooth::flags::immediate_encryption_after_pairing()) { BTM_LogHistory(kBtmLogTag, p_dev_rec->bd_addr, "Bonding completed", hci_error_code_text(status)); @@ -3159,6 +3159,11 @@ void btm_sec_auth_complete(uint16_t handle, tHCI_STATUS status) { } l2cu_start_post_bond_timer(p_dev_rec->hci_handle); + } else { + BTM_LogHistory(kBtmLogTag, p_dev_rec->bd_addr, "Bonding completed", + hci_error_code_text(status)); + BTM_SetEncryption(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR, NULL, NULL, BTM_BLE_SEC_NONE); + l2cu_start_post_bond_timer(p_dev_rec->hci_handle); } return; diff --git a/system/stack/include/l2cap_interface.h b/system/stack/include/l2cap_interface.h index b1551d2a80..19f85d4d2e 100644 --- a/system/stack/include/l2cap_interface.h +++ b/system/stack/include/l2cap_interface.h @@ -871,21 +871,6 @@ public: virtual void L2CA_SetEcosystemBaseInterval(uint32_t base_interval) = 0; /******************************************************************************* - * - * Function L2CA_SetDefaultSubrate - * - * Description BLE Set Default Subrate. - * - * Parameters: Subrate parameters - * - * Return value: void - * - ******************************************************************************/ - virtual void L2CA_SetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, - uint16_t max_latency, uint16_t cont_num, - uint16_t timeout) = 0; - - /******************************************************************************* ** ** Function L2CA_SetMediaStreamChannel ** diff --git a/system/stack/l2cap/internal/l2c_api.h b/system/stack/l2cap/internal/l2c_api.h index dd1dbf52e6..989eccf50e 100644 --- a/system/stack/l2cap/internal/l2c_api.h +++ b/system/stack/l2cap/internal/l2c_api.h @@ -719,20 +719,6 @@ void L2CA_SetEcosystemBaseInterval(uint32_t base_interval); /******************************************************************************* * - * Function L2CA_SetDefaultSubrate - * - * Description BLE Set Default Subrate. - * - * Parameters: Subrate parameters - * - * Return value: void - * - ******************************************************************************/ -void L2CA_SetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, - uint16_t cont_num, uint16_t timeout); - -/******************************************************************************* - * * Function L2CA_SubrateRequest * * Description BLE Subrate request. diff --git a/system/stack/l2cap/l2c_api.h b/system/stack/l2cap/l2c_api.h index 1ff09ffaf5..f9eab67d55 100644 --- a/system/stack/l2cap/l2c_api.h +++ b/system/stack/l2cap/l2c_api.h @@ -73,8 +73,6 @@ public: uint8_t* p_chnl_mask) override; [[nodiscard]] bool L2CA_SetAclPriority(const RawAddress& bd_addr, tL2CAP_PRIORITY priority) override; - void L2CA_SetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, - uint16_t cont_num, uint16_t timeout) override; void L2CA_AdjustConnectionIntervals(uint16_t* min_interval, uint16_t* max_interval, uint16_t floor_interval) override; void L2CA_SetEcosystemBaseInterval(uint32_t base_interval) override; diff --git a/system/stack/l2cap/l2c_ble_conn_params.cc b/system/stack/l2cap/l2c_ble_conn_params.cc index 49eeb06155..392b1f5a74 100644 --- a/system/stack/l2cap/l2c_ble_conn_params.cc +++ b/system/stack/l2cap/l2c_ble_conn_params.cc @@ -510,26 +510,6 @@ static void l2cble_start_subrate_change(tL2C_LCB* p_lcb) { /******************************************************************************* * - * Function L2CA_SetDefaultSubrate - * - * Description BLE Set Default Subrate - * - * Parameters: Subrate parameters - * - * Return value: void - * - ******************************************************************************/ -void L2CA_SetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, - uint16_t cont_num, uint16_t timeout) { - log::verbose("subrate_min={}, subrate_max={}, max_latency={}, cont_num={}, timeout={}", - subrate_min, subrate_max, max_latency, cont_num, timeout); - - bluetooth::shim::ACL_LeSetDefaultSubrate(subrate_min, subrate_max, max_latency, cont_num, - timeout); -} - -/******************************************************************************* - * * Function L2CA_SubrateRequest * * Description BLE Subrate request. diff --git a/system/stack/l2cap/l2cap_api.cc b/system/stack/l2cap/l2cap_api.cc index 0752c995c0..e9ccaeaf2a 100644 --- a/system/stack/l2cap/l2cap_api.cc +++ b/system/stack/l2cap/l2cap_api.cc @@ -234,13 +234,6 @@ void bluetooth::stack::l2cap::Impl::L2CA_SetEcosystemBaseInterval(uint32_t base_ return ::L2CA_IsLinkEstablished(bd_addr, transport); } -void bluetooth::stack::l2cap::Impl::L2CA_SetDefaultSubrate(uint16_t subrate_min, - uint16_t subrate_max, - uint16_t max_latency, uint16_t cont_num, - uint16_t timeout) { - ::L2CA_SetDefaultSubrate(subrate_min, subrate_max, max_latency, cont_num, timeout); -} - [[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_SubrateRequest( const RawAddress& rem_bda, uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, uint16_t cont_num, uint16_t timeout) { diff --git a/system/test/mock/mock_main_shim_acl.cc b/system/test/mock/mock_main_shim_acl.cc index a98e809ad0..5f58860347 100644 --- a/system/test/mock/mock_main_shim_acl.cc +++ b/system/test/mock/mock_main_shim_acl.cc @@ -129,12 +129,6 @@ void shim::Acl::DisconnectLe(uint16_t /* handle */, tHCI_STATUS /* reason */, inc_func_call_count(__func__); } -void shim::Acl::LeSetDefaultSubrate(uint16_t /* subrate_min */, uint16_t /* subrate_max */, - uint16_t /* max_latency */, uint16_t /* cont_num */, - uint16_t /* sup_tout */) { - inc_func_call_count(__func__); -} - void shim::Acl::LeSubrateRequest(uint16_t /* hci_handle */, uint16_t /* subrate_min */, uint16_t /* subrate_max */, uint16_t /* max_latency */, uint16_t /* cont_num */, uint16_t /* sup_tout */) { diff --git a/system/test/mock/mock_main_shim_acl_api.cc b/system/test/mock/mock_main_shim_acl_api.cc index 3d257f1a5a..e3a3c9d63b 100644 --- a/system/test/mock/mock_main_shim_acl_api.cc +++ b/system/test/mock/mock_main_shim_acl_api.cc @@ -73,12 +73,6 @@ void bluetooth::shim::ACL_RemoveFromAddressResolution( inc_func_call_count(__func__); } void bluetooth::shim::ACL_ClearAddressResolution() { inc_func_call_count(__func__); } -void bluetooth::shim::ACL_LeSetDefaultSubrate(uint16_t /* subrate_min */, - uint16_t /* subrate_max */, - uint16_t /* max_latency */, uint16_t /* cont_num */, - uint16_t /* sup_tout */) { - inc_func_call_count(__func__); -} void bluetooth::shim::ACL_LeSubrateRequest(uint16_t /* hci_handle */, uint16_t /* subrate_min */, uint16_t /* subrate_max */, uint16_t /* max_latency */, uint16_t /* cont_num */, uint16_t /* sup_tout */) { diff --git a/system/test/mock/mock_main_shim_acl_api.h b/system/test/mock/mock_main_shim_acl_api.h index ab891673e3..29e27dbad3 100644 --- a/system/test/mock/mock_main_shim_acl_api.h +++ b/system/test/mock/mock_main_shim_acl_api.h @@ -84,21 +84,6 @@ struct ACL_ClearFilterAcceptList { }; extern struct ACL_ClearFilterAcceptList ACL_ClearFilterAcceptList; -// Name: ACL_LeSetDefaultSubrate -// Params: -// Return: void -struct ACL_LeSetDefaultSubrate { - std::function<void(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, - uint16_t cont_num, uint16_t sup_tout)> - body{[](uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, - uint16_t cont_num, uint16_t sup_tout) {}}; - void operator()(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, - uint16_t cont_num, uint16_t sup_tout) { - body(subrate_min, subrate_max, max_latency, cont_num, sup_tout); - } -}; -extern struct ACL_LeSetDefaultSubrate ACL_LeSetDefaultSubrate; - // Name: ACL_LeSubrateRequest // Params: // Return: void diff --git a/system/test/mock/mock_stack_l2cap_interface.h b/system/test/mock/mock_stack_l2cap_interface.h index a5cd536777..b2fc3e0ae9 100644 --- a/system/test/mock/mock_stack_l2cap_interface.h +++ b/system/test/mock/mock_stack_l2cap_interface.h @@ -64,9 +64,6 @@ public: MOCK_METHOD(bool, L2CA_GetPeerFeatures, (const RawAddress& bd_addr, uint32_t* p_ext_feat, uint8_t* p_chnl_mask)); MOCK_METHOD(bool, L2CA_SetAclPriority, (const RawAddress& bd_addr, tL2CAP_PRIORITY priority)); - MOCK_METHOD(void, L2CA_SetDefaultSubrate, - (uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, uint16_t cont_num, - uint16_t timeout)); MOCK_METHOD(void, L2CA_AdjustConnectionIntervals, (uint16_t* min_interval, uint16_t* max_interval, uint16_t floor_interval)); MOCK_METHOD(void, L2CA_SetEcosystemBaseInterval, (uint32_t base_interval)); |