diff options
author | 2024-12-26 16:41:40 +0000 | |
---|---|---|
committer | 2025-01-02 16:08:20 -0800 | |
commit | e33515649e7e85cf540a0f5e6afd8f9d5dbf7ec3 (patch) | |
tree | 4f6b6ae9a00ec395c0f86b011c09330d51076d4a | |
parent | a69c2fea130b5bf25320bed1443f311e651a2ea3 (diff) |
Remove flag allow_switching_hid_and_hogp
Change-Id: I1f6a0a2cfedb80e729326c6bb6ad33dab0c5eb2b
Test: mmm packages/modules/Bluetooth
Flag: com.android.bluetooth.flags.allow_switching_hid_and_hogp
Bug: 320762367
11 files changed, 154 insertions, 314 deletions
diff --git a/android/app/src/com/android/bluetooth/hid/HidHostService.java b/android/app/src/com/android/bluetooth/hid/HidHostService.java index 70d69c8c80..2dda64f4b3 100644 --- a/android/app/src/com/android/bluetooth/hid/HidHostService.java +++ b/android/app/src/com/android/bluetooth/hid/HidHostService.java @@ -87,10 +87,6 @@ public class HidHostService extends ProfileService { } } - void setState(int state) { - setState(mSelectedTransport, state); - } - @Override public String toString() { return ("Selected transport=" + mSelectedTransport) @@ -198,20 +194,6 @@ public class HidHostService extends ProfileService { private byte[] getByteAddress(BluetoothDevice device, int transport) { final ParcelUuid[] uuids = mAdapterService.getRemoteUuids(device); - if (!Flags.allowSwitchingHidAndHogp()) { - boolean hogpSupported = Utils.arrayContains(uuids, BluetoothUuid.HOGP); - boolean headtrackerSupported = - Utils.arrayContains(uuids, HidHostService.ANDROID_HEADTRACKER_UUID); - - if (hogpSupported || headtrackerSupported) { - // Use pseudo address when HOGP is available - return Utils.getByteAddress(device); - } else { - // Otherwise use identity address - return getIdentityAddress(device); - } - } - if (transport == BluetoothDevice.TRANSPORT_LE) { // Use pseudo address when HOGP is to be used return Utils.getByteAddress(device); @@ -331,11 +313,6 @@ public class HidHostService extends ProfileService { "nativeConnect: Connection attempt failed." + (" device=" + device) + (" transport=" + transport)); - - if (!Flags.allowSwitchingHidAndHogp()) { - updateConnectionState(device, transport, BluetoothProfile.STATE_DISCONNECTING); - updateConnectionState(device, transport, BluetoothProfile.STATE_DISCONNECTED); - } return false; } return true; @@ -362,10 +339,6 @@ public class HidHostService extends ProfileService { "nativeDisconnect: Disconnection attempt failed." + (" device=" + device) + (" transport=" + transport)); - if (!Flags.allowSwitchingHidAndHogp()) { - updateConnectionState(device, transport, BluetoothProfile.STATE_DISCONNECTING); - updateConnectionState(device, transport, BluetoothProfile.STATE_DISCONNECTED); - } return false; } return true; @@ -434,9 +407,6 @@ public class HidHostService extends ProfileService { }; private void handleMessageSendData(Message msg) { - if (!Flags.allowSwitchingHidAndHogp()) { - return; - } BluetoothDevice device = mAdapterService.getDeviceFromByte((byte[]) msg.obj); Bundle data = msg.getData(); @@ -630,43 +600,37 @@ public class HidHostService extends ProfileService { int state = msg.arg2; int prevState = getState(device, transport); - if (Flags.allowSwitchingHidAndHogp()) { - InputDevice inputDevice = mInputDevices.get(device); - if (inputDevice != null) { - // Update transport if it was not resolved already - if (inputDevice.mSelectedTransport == BluetoothDevice.TRANSPORT_AUTO) { - inputDevice.mSelectedTransport = transport; - setTransport(device, transport); - } - } else { - // ACCEPTING state for unknown device indicates that this device - // was loaded from storage. Add it in the record. - if (state == STATE_ACCEPTING) { - setTransport(device, transport); - } else { - Log.e( - TAG, - "handleMessageConnectStateChanged: Disconnect and unknown inputDevice" - + (" device=" + device) - + (" state=" + state)); - nativeDisconnect(device, transport, false); - return; - } + InputDevice inputDevice = mInputDevices.get(device); + if (inputDevice != null) { + // Update transport if it was not resolved already + if (inputDevice.mSelectedTransport == BluetoothDevice.TRANSPORT_AUTO) { + inputDevice.mSelectedTransport = transport; + setTransport(device, transport); } - - if (transport != getTransport(device)) { - Log.w( + } else { + // ACCEPTING state for unknown device indicates that this device + // was loaded from storage. Add it in the record. + if (state == STATE_ACCEPTING) { + setTransport(device, transport); + } else { + Log.e( TAG, - "handleMessageConnectStateChanged: Not preferred transport in message" + "handleMessageConnectStateChanged: Disconnect and unknown inputDevice" + (" device=" + device) - + (" transport=" + transport) - + (" newState=" + state) - + (" prevState=" + prevState)); + + (" state=" + state)); + nativeDisconnect(device, transport, false); + return; } - } else { - // Only TRANSPORT_AUTO should be used when allowSwitchingHidAndHogp is disabled - transport = BluetoothDevice.TRANSPORT_AUTO; - setTransport(device, BluetoothDevice.TRANSPORT_AUTO); + } + + if (transport != getTransport(device)) { + Log.w( + TAG, + "handleMessageConnectStateChanged: Not preferred transport in message" + + (" device=" + device) + + (" transport=" + transport) + + (" newState=" + state) + + (" prevState=" + prevState)); } Log.d( @@ -676,11 +640,10 @@ public class HidHostService extends ProfileService { + (" newState=" + state) + (" prevState=" + prevState)); - boolean connectionAllowed = true; // Process connection if (prevState == BluetoothProfile.STATE_DISCONNECTED && state == BluetoothProfile.STATE_CONNECTED) { - connectionAllowed = processConnection(device, transport); + processConnection(device, transport); } // ACCEPTING state has to be treated as DISCONNECTED state @@ -688,10 +651,7 @@ public class HidHostService extends ProfileService { if (state == STATE_ACCEPTING) { reportedState = BluetoothProfile.STATE_DISCONNECTED; } - - if (Flags.allowSwitchingHidAndHogp() || connectionAllowed) { - updateConnectionState(device, transport, reportedState); - } + updateConnectionState(device, transport, reportedState); } private void handleMessageDisconnect(Message msg) { @@ -699,12 +659,9 @@ public class HidHostService extends ProfileService { int connectionPolicy = msg.arg1; boolean reconnectAllowed = true; - if (Flags.allowSwitchingHidAndHogp()) { - if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) { - reconnectAllowed = false; - } + if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) { + reconnectAllowed = false; } - nativeDisconnect(device, getTransport(device), reconnectAllowed); } @@ -712,19 +669,16 @@ public class HidHostService extends ProfileService { BluetoothDevice device = (BluetoothDevice) msg.obj; InputDevice inputDevice = getOrCreateInputDevice(device); - if (Flags.allowSwitchingHidAndHogp()) { - int connectionPolicy = getConnectionPolicy(device); - if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) { - Log.e( - TAG, - "handleMessageConnect: Connection not allowed." - + (" device=" + device) - + (" connectionPolicy=" + connectionPolicy)); + int connectionPolicy = getConnectionPolicy(device); + if (connectionPolicy != BluetoothProfile.CONNECTION_POLICY_ALLOWED) { + Log.e( + TAG, + "handleMessageConnect: Connection not allowed." + + (" device=" + device) + + (" connectionPolicy=" + connectionPolicy)); - return; - } + return; } - nativeConnect(device, inputDevice.mSelectedTransport); } @@ -737,7 +691,7 @@ public class HidHostService extends ProfileService { * @return true if transport matches, otherwise false */ private boolean checkTransport(BluetoothDevice device, int transport, int message) { - if (Flags.allowSwitchingHidAndHogp() && getTransport(device) != transport) { + if (getTransport(device) != transport) { Log.w( TAG, "checkTransport:" @@ -763,12 +717,7 @@ public class HidHostService extends ProfileService { + (" device=" + device) + (" connectionPolicy=" + getConnectionPolicy(device))); - if (Flags.allowSwitchingHidAndHogp()) { - nativeDisconnect(device, transport, false); - } else { - mNativeInterface.virtualUnPlug( - getByteAddress(device), getAddressType(device), getTransport(device)); - } + nativeDisconnect(device, transport, false); return false; } return true; @@ -1217,11 +1166,6 @@ public class HidHostService extends ProfileService { return false; } - if (!Flags.allowSwitchingHidAndHogp()) { - return mNativeInterface.sendData( - getByteAddress(device), getAddressType(device), getTransport(device), report); - } - Message msg = mHandler.obtainMessage(MESSAGE_SEND_DATA, device); Bundle data = new Bundle(); data.putString(BluetoothHidHost.EXTRA_REPORT, report); @@ -1321,39 +1265,29 @@ public class HidHostService extends ProfileService { */ private void updateConnectionState(BluetoothDevice device, int transport, int newState) { InputDevice inputDevice = mInputDevices.get(device); - int prevState = BluetoothProfile.STATE_DISCONNECTED; - if (Flags.allowSwitchingHidAndHogp()) { - if (inputDevice == null) { - Log.w( - TAG, - "updateConnectionState: requested on unknown inputDevice" - + (" device=" + device) - + (" newState=" + newState) - + (" transport=" + transport)); - return; - } - - if (transport == BluetoothDevice.TRANSPORT_AUTO) { - Log.w( - TAG, - "updateConnectionState: requested with AUTO transport" - + (" device=" + device) - + (" newState=" + newState)); - return; - } + if (inputDevice == null) { + Log.w( + TAG, + "updateConnectionState: requested on unknown inputDevice" + + (" device=" + device) + + (" newState=" + newState) + + (" transport=" + transport)); + return; + } - prevState = inputDevice.getState(transport); - inputDevice.setState(transport, newState); - } else { - if (inputDevice == null) { - inputDevice = getOrCreateInputDevice(device); - } - prevState = inputDevice.getState(); - setTransport(device, transport); - inputDevice.setState(newState); + if (transport == BluetoothDevice.TRANSPORT_AUTO) { + Log.w( + TAG, + "updateConnectionState: requested with AUTO transport" + + (" device=" + device) + + (" newState=" + newState)); + return; } + int prevState = inputDevice.getState(transport); + inputDevice.setState(transport, newState); + if (prevState == newState) { Log.d( TAG, @@ -1393,9 +1327,7 @@ public class HidHostService extends ProfileService { intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothProfile.EXTRA_STATE, newState); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); - if (Flags.allowSwitchingHidAndHogp()) { - intent.putExtra(BluetoothDevice.EXTRA_TRANSPORT, transport); - } + intent.putExtra(BluetoothDevice.EXTRA_TRANSPORT, transport); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); sendBroadcastAsUser( intent, diff --git a/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceBinderTest.java b/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceBinderTest.java index 39de9c8e0f..bf519011bb 100644 --- a/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceBinderTest.java +++ b/android/app/tests/unit/src/com/android/bluetooth/hid/HidHostServiceBinderTest.java @@ -110,7 +110,6 @@ public class HidHostServiceBinderTest { @Test public void setPreferredTransport_callsServiceMethod() { - mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP); int preferredTransport = BluetoothDevice.TRANSPORT_AUTO; mBinder.setPreferredTransport(mRemoteDevice, preferredTransport, null); @@ -119,7 +118,6 @@ public class HidHostServiceBinderTest { @Test public void getPreferredTransport_callsServiceMethod() { - mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP); mBinder.getPreferredTransport(mRemoteDevice, null); verify(mService).getPreferredTransport(mRemoteDevice); diff --git a/framework/api/system-current.txt b/framework/api/system-current.txt index 8368f676b8..62b4aa6062 100644 --- a/framework/api/system-current.txt +++ b/framework/api/system-current.txt @@ -514,9 +514,9 @@ package android.bluetooth { method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public int getConnectionState(@NonNull android.bluetooth.BluetoothDevice); method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public java.util.List<android.bluetooth.BluetoothDevice> getDevicesMatchingConnectionStates(int[]); - method @FlaggedApi("com.android.bluetooth.flags.allow_switching_hid_and_hogp") @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getPreferredTransport(@NonNull android.bluetooth.BluetoothDevice); + method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getPreferredTransport(@NonNull android.bluetooth.BluetoothDevice); method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setConnectionPolicy(@NonNull android.bluetooth.BluetoothDevice, int); - method @FlaggedApi("com.android.bluetooth.flags.allow_switching_hid_and_hogp") @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setPreferredTransport(@NonNull android.bluetooth.BluetoothDevice, int); + method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean setPreferredTransport(@NonNull android.bluetooth.BluetoothDevice, int); field @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public static final String ACTION_CONNECTION_STATE_CHANGED = "android.bluetooth.input.profile.action.CONNECTION_STATE_CHANGED"; } diff --git a/framework/java/android/bluetooth/BluetoothHidHost.java b/framework/java/android/bluetooth/BluetoothHidHost.java index b9d3d0f158..b1e4de56a0 100644 --- a/framework/java/android/bluetooth/BluetoothHidHost.java +++ b/framework/java/android/bluetooth/BluetoothHidHost.java @@ -465,7 +465,6 @@ public final class BluetoothHidHost implements BluetoothProfile { * @throws IllegalArgumentException if the {@code device} invalid. * @hide */ - @FlaggedApi(Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP) @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( @@ -569,7 +568,6 @@ public final class BluetoothHidHost implements BluetoothProfile { * @throws IllegalArgumentException if the {@code device} invalid. * @hide */ - @FlaggedApi(Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP) @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( diff --git a/framework/tests/bumble/src/android/bluetooth/hid/HidHeadTrackerTest.java b/framework/tests/bumble/src/android/bluetooth/hid/HidHeadTrackerTest.java index f8324d9592..faf79ef23f 100644 --- a/framework/tests/bumble/src/android/bluetooth/hid/HidHeadTrackerTest.java +++ b/framework/tests/bumble/src/android/bluetooth/hid/HidHeadTrackerTest.java @@ -55,7 +55,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.ParcelUuid; -import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.util.Log; @@ -63,7 +62,6 @@ import android.util.Log; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.platform.app.InstrumentationRegistry; -import com.android.bluetooth.flags.Flags; import com.android.compatibility.common.util.AdoptShellPermissionsRule; import org.hamcrest.CustomTypeSafeMatcher; @@ -292,9 +290,7 @@ public class HidHeadTrackerTest { */ @SuppressLint("MissingPermission") @Test - @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP}) public void connectWithoutHidServiceTest() { - registerIntentActions( BluetoothDevice.ACTION_ACL_CONNECTED, BluetoothDevice.ACTION_ACL_DISCONNECTED, @@ -385,9 +381,7 @@ public class HidHeadTrackerTest { */ @SuppressLint("MissingPermission") @Test - @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP}) public void connectWithHidServiceTest() { - registerIntentActions( BluetoothDevice.ACTION_ACL_CONNECTED, BluetoothDevice.ACTION_UUID, diff --git a/framework/tests/bumble/src/android/bluetooth/hid/HidHostDualModeTest.java b/framework/tests/bumble/src/android/bluetooth/hid/HidHostDualModeTest.java index 167e583d7d..2a8d9a2787 100644 --- a/framework/tests/bumble/src/android/bluetooth/hid/HidHostDualModeTest.java +++ b/framework/tests/bumble/src/android/bluetooth/hid/HidHostDualModeTest.java @@ -57,7 +57,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.os.ParcelUuid; import android.os.Parcelable; -import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.util.Log; @@ -392,7 +391,6 @@ public class HidHostDualModeTest { * </ol> */ @Test - @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP}) public void setPreferredTransportTest() { // BR/EDR transport mHidService.setPreferredTransport(mDevice, TRANSPORT_BREDR); @@ -410,7 +408,6 @@ public class HidHostDualModeTest { * </ol> */ @Test - @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP}) public void hogpGetReportTest() throws Exception { // Keyboard report mReportData = new byte[0]; @@ -444,7 +441,6 @@ public class HidHostDualModeTest { * </ol> */ @Test - @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP}) public void hogpGetProtocolModeTest() { mHidService.getProtocolMode(mDevice); verifyIntentReceived( @@ -463,7 +459,6 @@ public class HidHostDualModeTest { * </ol> */ @Test - @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP}) public void hogpSetProtocolModeTest() throws Exception { mHidService.setProtocolMode(mDevice, BluetoothHidHost.PROTOCOL_BOOT_MODE); // Must cast ERROR_RSP_SUCCESS, otherwise, it won't match with the int extra @@ -482,7 +477,6 @@ public class HidHostDualModeTest { * </ol> */ @Test - @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP}) public void hogpSetReportTest() throws Exception { // Keyboard report mHidService.setReport(mDevice, BluetoothHidHost.REPORT_TYPE_INPUT, "010203040506070809"); @@ -509,7 +503,6 @@ public class HidHostDualModeTest { * </ol> */ @Test - @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP}) public void hogpVirtualUnplugFromHidHostTest() throws Exception { mHidService.virtualUnplug(mDevice); verifyIntentReceived( diff --git a/framework/tests/bumble/src/android/bluetooth/hid/HidHostTest.java b/framework/tests/bumble/src/android/bluetooth/hid/HidHostTest.java index 1cb9e083fb..c7a3d48c8b 100644 --- a/framework/tests/bumble/src/android/bluetooth/hid/HidHostTest.java +++ b/framework/tests/bumble/src/android/bluetooth/hid/HidHostTest.java @@ -16,7 +16,6 @@ package android.bluetooth.hid; -import static android.bluetooth.BluetoothDevice.TRANSPORT_AUTO; import static android.bluetooth.BluetoothDevice.TRANSPORT_BREDR; import static android.bluetooth.BluetoothProfile.STATE_CONNECTED; import static android.bluetooth.BluetoothProfile.STATE_CONNECTING; @@ -323,15 +322,9 @@ public class HidHostTest { mDevice, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN)) .isTrue(); } - if (Flags.allowSwitchingHidAndHogp()) { - verifyConnectionState(mDevice, equalTo(TRANSPORT_BREDR), equalTo(STATE_CONNECTING)); - verifyConnectionState(mDevice, equalTo(TRANSPORT_BREDR), equalTo(STATE_CONNECTED)); - assertThat(mHidService.getPreferredTransport(mDevice)).isEqualTo(TRANSPORT_BREDR); - } else { - // Without allowSwitchingHidAndHogp, transport will be AUTO - verifyConnectionState(mDevice, equalTo(TRANSPORT_AUTO), equalTo(STATE_CONNECTING)); - verifyConnectionState(mDevice, equalTo(TRANSPORT_AUTO), equalTo(STATE_CONNECTED)); - } + verifyConnectionState(mDevice, equalTo(TRANSPORT_BREDR), equalTo(STATE_CONNECTING)); + verifyConnectionState(mDevice, equalTo(TRANSPORT_BREDR), equalTo(STATE_CONNECTED)); + assertThat(mHidService.getPreferredTransport(mDevice)).isEqualTo(TRANSPORT_BREDR); } @SuppressLint("MissingPermission") @@ -381,7 +374,6 @@ public class HidHostTest { */ @SuppressLint("MissingPermission") @Test - @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP}) public void hidReconnectionWhenConnectionPolicyChangeTest() throws Exception { assertThat(mHidService.getConnectionPolicy(mDevice)) @@ -437,7 +429,6 @@ public class HidHostTest { */ @SuppressLint("MissingPermission") @Test - @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP}) public void hidReconnectionAfterBTrestartWithConnectionPolicyAllowedTest() throws Exception { assertThat(mHidService.getConnectionPolicy(mDevice)) @@ -462,7 +453,6 @@ public class HidHostTest { */ @SuppressLint("MissingPermission") @Test - @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP}) public void hidReconnectionAfterBTrestartWithConnectionPolicyiDisallowedTest() throws Exception { @@ -490,7 +480,6 @@ public class HidHostTest { */ @SuppressLint("MissingPermission") @Test - @RequiresFlagsEnabled({Flags.FLAG_ALLOW_SWITCHING_HID_AND_HOGP}) public void hidReconnectionAfterDeviceRemovedTest() throws Exception { assertThat(mHidService.getConnectionPolicy(mDevice)) @@ -731,62 +720,34 @@ public class HidHostTest { private void verifyConnectionState( BluetoothDevice device, Matcher<Integer> transport, Matcher<Integer> state) { - if (Flags.allowSwitchingHidAndHogp()) { - verifyIntentReceived( - hasAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED), - hasExtra(BluetoothDevice.EXTRA_DEVICE, device), - hasExtra(BluetoothDevice.EXTRA_TRANSPORT, transport), - hasExtra(BluetoothProfile.EXTRA_STATE, state)); - } else { - // skip transport verification - verifyIntentReceived( - hasAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED), - hasExtra(BluetoothDevice.EXTRA_DEVICE, device), - hasExtra(BluetoothProfile.EXTRA_STATE, state)); - } + verifyIntentReceived( + hasAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED), + hasExtra(BluetoothDevice.EXTRA_DEVICE, device), + hasExtra(BluetoothDevice.EXTRA_TRANSPORT, transport), + hasExtra(BluetoothProfile.EXTRA_STATE, state)); } private void verifyIncomingProfileConnectionState() { // for incoming connection, connection state transit // from STATE_ACCEPTING -->STATE_CONNECTED - if (Flags.allowSwitchingHidAndHogp()) { - verifyIntentReceived( - hasAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED), - hasExtra(BluetoothDevice.EXTRA_DEVICE, mDevice), - hasExtra(BluetoothDevice.EXTRA_TRANSPORT, TRANSPORT_BREDR), - hasExtra(BluetoothProfile.EXTRA_STATE, STATE_CONNECTED)); - } else { - // skip transport verification - verifyIntentReceived( - hasAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED), - hasExtra(BluetoothDevice.EXTRA_DEVICE, mDevice), - hasExtra(BluetoothProfile.EXTRA_STATE, STATE_CONNECTED)); - } + verifyIntentReceived( + hasAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED), + hasExtra(BluetoothDevice.EXTRA_DEVICE, mDevice), + hasExtra(BluetoothDevice.EXTRA_TRANSPORT, TRANSPORT_BREDR), + hasExtra(BluetoothProfile.EXTRA_STATE, STATE_CONNECTED)); } private void verifyProfileDisconnectionState() { - if (Flags.allowSwitchingHidAndHogp()) { - verifyIntentReceived( - hasAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED), - hasExtra(BluetoothDevice.EXTRA_DEVICE, mDevice), - hasExtra(BluetoothDevice.EXTRA_TRANSPORT, TRANSPORT_BREDR), - hasExtra(BluetoothProfile.EXTRA_STATE, STATE_DISCONNECTING)); - verifyIntentReceived( - hasAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED), - hasExtra(BluetoothDevice.EXTRA_DEVICE, mDevice), - hasExtra(BluetoothDevice.EXTRA_TRANSPORT, TRANSPORT_BREDR), - hasExtra(BluetoothProfile.EXTRA_STATE, STATE_DISCONNECTED)); - } else { - // skip transport verification - verifyIntentReceived( - hasAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED), - hasExtra(BluetoothDevice.EXTRA_DEVICE, mDevice), - hasExtra(BluetoothProfile.EXTRA_STATE, STATE_DISCONNECTING)); - verifyIntentReceived( - hasAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED), - hasExtra(BluetoothDevice.EXTRA_DEVICE, mDevice), - hasExtra(BluetoothProfile.EXTRA_STATE, STATE_DISCONNECTED)); - } + verifyIntentReceived( + hasAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED), + hasExtra(BluetoothDevice.EXTRA_DEVICE, mDevice), + hasExtra(BluetoothDevice.EXTRA_TRANSPORT, TRANSPORT_BREDR), + hasExtra(BluetoothProfile.EXTRA_STATE, STATE_DISCONNECTING)); + verifyIntentReceived( + hasAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED), + hasExtra(BluetoothDevice.EXTRA_DEVICE, mDevice), + hasExtra(BluetoothDevice.EXTRA_TRANSPORT, TRANSPORT_BREDR), + hasExtra(BluetoothProfile.EXTRA_STATE, STATE_DISCONNECTED)); } private void reconnectionFromRemoteAndVerifyDisconnectedState() throws Exception { diff --git a/system/bta/hh/bta_hh_act.cc b/system/bta/hh/bta_hh_act.cc index 4e685a5b8e..7c19f91c17 100644 --- a/system/bta/hh/bta_hh_act.cc +++ b/system/bta/hh/bta_hh_act.cc @@ -926,12 +926,6 @@ void bta_hh_maint_dev_act(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) { /* initialize callback data */ if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE) { tBT_TRANSPORT transport = p_data->api_maintdev.link_spec.transport; - if (!com::android::bluetooth::flags::allow_switching_hid_and_hogp()) { - transport = get_btm_client_interface().ble.BTM_UseLeLink( - p_data->api_maintdev.link_spec.addrt.bda) - ? BT_TRANSPORT_LE - : BT_TRANSPORT_BR_EDR; - } if (transport == BT_TRANSPORT_LE) { p_cb->link_spec.transport = BT_TRANSPORT_LE; dev_info.handle = bta_hh_le_add_device(p_cb, p_dev_info); diff --git a/system/btif/src/btif_dm.cc b/system/btif/src/btif_dm.cc index a130b3d134..e2469242c4 100644 --- a/system/btif/src/btif_dm.cc +++ b/system/btif/src/btif_dm.cc @@ -1522,8 +1522,7 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* static bool btif_is_interesting_le_service(bluetooth::Uuid uuid) { return uuid.As16Bit() == UUID_SERVCLASS_LE_HID || uuid == UUID_HEARING_AID || uuid == UUID_VC || uuid == UUID_CSIS || uuid == UUID_LE_AUDIO || uuid == UUID_LE_MIDI || uuid == UUID_HAS || - uuid == UUID_BASS || uuid == UUID_BATTERY || - uuid == ANDROID_HEADTRACKER_SERVICE_UUID; + uuid == UUID_BASS || uuid == UUID_BATTERY || uuid == ANDROID_HEADTRACKER_SERVICE_UUID; } static bt_status_t btif_get_existing_uuids(RawAddress* bd_addr, Uuid* existing_uuids) { diff --git a/system/btif/src/btif_hh.cc b/system/btif/src/btif_hh.cc index e733855233..5e4d2077cb 100644 --- a/system/btif/src/btif_hh.cc +++ b/system/btif/src/btif_hh.cc @@ -455,10 +455,6 @@ static void btif_hh_start_vup_timer(const tAclLinkSpec& link_spec) { } static bthh_connection_state_t hh_get_state_on_disconnect(tAclLinkSpec& link_spec) { - if (!com::android::bluetooth::flags::allow_switching_hid_and_hogp()) { - return BTHH_CONN_STATE_ACCEPTING; - } - btif_hh_added_device_t* added_dev = btif_hh_find_added_dev(link_spec); if (added_dev != nullptr) { return added_dev->reconnect_allowed ? BTHH_CONN_STATE_ACCEPTING : BTHH_CONN_STATE_DISCONNECTED; @@ -559,55 +555,48 @@ static void hh_disable_handler(tBTA_HH_STATUS& status) { static void hh_open_handler(tBTA_HH_CONN& conn) { log::debug("link spec = {}, status = {}, handle = {}", conn.link_spec, conn.status, conn.handle); - if (com::android::bluetooth::flags::allow_switching_hid_and_hogp()) { - // Initialize with disconnected/accepting state based on reconnection policy - bthh_connection_state_t dev_status = hh_get_state_on_disconnect(conn.link_spec); + // Initialize with disconnected/accepting state based on reconnection policy + bthh_connection_state_t dev_status = hh_get_state_on_disconnect(conn.link_spec); - // Use current state if the device instance already exists - btif_hh_device_t* p_dev = btif_hh_find_dev_by_link_spec(conn.link_spec); - if (p_dev != nullptr) { - log::debug("Device instance found: {}, state: {}", p_dev->link_spec, - bthh_connection_state_text(p_dev->dev_status)); - dev_status = p_dev->dev_status; - } + // Use current state if the device instance already exists + btif_hh_device_t* p_dev = btif_hh_find_dev_by_link_spec(conn.link_spec); + if (p_dev != nullptr) { + log::debug("Device instance found: {}, state: {}", p_dev->link_spec, + bthh_connection_state_text(p_dev->dev_status)); + dev_status = p_dev->dev_status; + } - if (std::find(btif_hh_cb.new_connection_requests.begin(), - btif_hh_cb.new_connection_requests.end(), - conn.link_spec) != btif_hh_cb.new_connection_requests.end()) { - log::verbose("Device connection was pending for: {}, status: {}", conn.link_spec, - btif_hh_status_text(btif_hh_cb.status)); - dev_status = BTHH_CONN_STATE_CONNECTING; - } + if (std::find(btif_hh_cb.new_connection_requests.begin(), + btif_hh_cb.new_connection_requests.end(), + conn.link_spec) != btif_hh_cb.new_connection_requests.end()) { + log::verbose("Device connection was pending for: {}, status: {}", conn.link_spec, + btif_hh_status_text(btif_hh_cb.status)); + dev_status = BTHH_CONN_STATE_CONNECTING; + } - if (dev_status != BTHH_CONN_STATE_ACCEPTING && dev_status != BTHH_CONN_STATE_CONNECTING) { - log::warn("Reject Incoming HID Connection, device: {}, state: {}", conn.link_spec, - bthh_connection_state_text(dev_status)); - log_counter_metrics_btif( - android::bluetooth::CodePathCounterKeyEnum::HIDH_COUNT_INCOMING_CONNECTION_REJECTED, - 1); + if (dev_status != BTHH_CONN_STATE_ACCEPTING && dev_status != BTHH_CONN_STATE_CONNECTING) { + log::warn("Reject Incoming HID Connection, device: {}, state: {}", conn.link_spec, + bthh_connection_state_text(dev_status)); + log_counter_metrics_btif( + android::bluetooth::CodePathCounterKeyEnum::HIDH_COUNT_INCOMING_CONNECTION_REJECTED, 1); - if (p_dev != nullptr) { - p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED; - } + if (p_dev != nullptr) { + p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED; + } - if (!com::android::bluetooth::flags::suppress_hid_rejection_broadcast()) { - hh_connect_complete(conn, BTHH_CONN_STATE_DISCONNECTED); - return; - } - BTA_HhClose(conn.handle); + if (!com::android::bluetooth::flags::suppress_hid_rejection_broadcast()) { + hh_connect_complete(conn, BTHH_CONN_STATE_DISCONNECTED); return; } - } - - if (!com::android::bluetooth::flags::allow_switching_hid_and_hogp()) { - BTHH_STATE_UPDATE(conn.link_spec, BTHH_CONN_STATE_CONNECTING); + BTA_HhClose(conn.handle); + return; } btif_hh_cb.new_connection_requests.remove(conn.link_spec); if (conn.status != BTA_HH_OK) { btif_dm_hh_open_failed(&conn.link_spec.addrt.bda); - btif_hh_device_t* p_dev = btif_hh_find_dev_by_link_spec(conn.link_spec); + p_dev = btif_hh_find_dev_by_link_spec(conn.link_spec); if (p_dev != nullptr) { btif_hh_stop_vup_timer(p_dev->link_spec); @@ -624,7 +613,7 @@ static void hh_open_handler(tBTA_HH_CONN& conn) { return; } - btif_hh_device_t* p_dev = btif_hh_find_connected_dev_by_handle(conn.handle); + p_dev = btif_hh_find_connected_dev_by_handle(conn.handle); if (p_dev == nullptr) { /* The connect request must have come from device side and exceeded the * connected HID device number. */ @@ -819,9 +808,7 @@ static void hh_get_dscp_handler(tBTA_HH_DEV_DSCP_INFO& dscp_info) { dscp_info.descriptor.dsc_list); // Allow incoming connections - if (com::android::bluetooth::flags::allow_switching_hid_and_hogp()) { - btif_storage_set_hid_connection_policy(p_dev->link_spec, true); - } + btif_storage_set_hid_connection_policy(p_dev->link_spec, true); ASSERTC(ret == BT_STATUS_SUCCESS, "storing hid info failed", ret); log::info("Added device {}", p_dev->link_spec); @@ -909,8 +896,7 @@ void btif_hh_load_bonded_dev(const tAclLinkSpec& link_spec_ref, tBTA_HH_ATTR_MAS uint8_t i; tAclLinkSpec link_spec = link_spec_ref; - if (com::android::bluetooth::flags::allow_switching_hid_and_hogp() && - link_spec.transport == BT_TRANSPORT_AUTO) { + if (link_spec.transport == BT_TRANSPORT_AUTO) { log::warn("Resolving link spec {} transport to BREDR/LE", link_spec); btif_hh_transport_select(link_spec); reconnect_allowed = true; @@ -925,7 +911,7 @@ void btif_hh_load_bonded_dev(const tAclLinkSpec& link_spec_ref, tBTA_HH_ATTR_MAS } if (hh_add_device(link_spec, attr_mask, reconnect_allowed)) { - if (com::android::bluetooth::flags::allow_switching_hid_and_hogp() && reconnect_allowed) { + if (reconnect_allowed) { BTHH_STATE_UPDATE(link_spec, BTHH_CONN_STATE_ACCEPTING); } BTA_HhAddDev(link_spec, attr_mask, sub_class, app_id, dscp_info); @@ -1135,10 +1121,8 @@ bt_status_t btif_hh_connect(const tAclLinkSpec& link_spec) { } // Reset the connection policy to allow incoming reconnections - if (com::android::bluetooth::flags::allow_switching_hid_and_hogp()) { - added_dev->reconnect_allowed = true; - btif_storage_set_hid_connection_policy(link_spec, true); - } + added_dev->reconnect_allowed = true; + btif_storage_set_hid_connection_policy(link_spec, true); } if (p_dev && p_dev->dev_status == BTHH_CONN_STATE_CONNECTED) { @@ -1660,7 +1644,7 @@ static bt_status_t disconnect(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type, return BT_STATUS_UNHANDLED; } - if (com::android::bluetooth::flags::allow_switching_hid_and_hogp() && !reconnect_allowed) { + if (!reconnect_allowed) { log::info("Incoming reconnections disabled for device {}", link_spec); btif_hh_added_device_t* added_dev = btif_hh_find_added_dev(link_spec); if (added_dev != nullptr) { @@ -1671,27 +1655,25 @@ static bt_status_t disconnect(RawAddress* bd_addr, tBLE_ADDR_TYPE addr_type, btif_hh_device_t* p_dev = btif_hh_find_connected_dev_by_link_spec(link_spec); if (p_dev == nullptr) { - if (com::android::bluetooth::flags::allow_switching_hid_and_hogp()) { - // Conclude the request if the device is already disconnected - p_dev = btif_hh_find_dev_by_link_spec(link_spec); - if (p_dev != nullptr && (p_dev->dev_status == BTHH_CONN_STATE_ACCEPTING || - p_dev->dev_status == BTHH_CONN_STATE_CONNECTING)) { - log::warn("Device {} already not connected, state: {}", p_dev->link_spec, - bthh_connection_state_text(p_dev->dev_status)); - p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED; - - if (com::android::bluetooth::flags::pending_hid_connection_cancellation()) { - btif_hh_cb.new_connection_requests.remove(link_spec); - } - return BT_STATUS_DONE; - } else if (com::android::bluetooth::flags::initiate_multiple_hid_connections() && - std::find(btif_hh_cb.new_connection_requests.begin(), - btif_hh_cb.new_connection_requests.end(), - link_spec) != btif_hh_cb.new_connection_requests.end()) { + // Conclude the request if the device is already disconnected + p_dev = btif_hh_find_dev_by_link_spec(link_spec); + if (p_dev != nullptr && (p_dev->dev_status == BTHH_CONN_STATE_ACCEPTING || + p_dev->dev_status == BTHH_CONN_STATE_CONNECTING)) { + log::warn("Device {} already not connected, state: {}", p_dev->link_spec, + bthh_connection_state_text(p_dev->dev_status)); + p_dev->dev_status = BTHH_CONN_STATE_DISCONNECTED; + + if (com::android::bluetooth::flags::pending_hid_connection_cancellation()) { btif_hh_cb.new_connection_requests.remove(link_spec); - log::info("Pending connection cancelled {}", link_spec); - return BT_STATUS_SUCCESS; } + return BT_STATUS_DONE; + } else if (com::android::bluetooth::flags::initiate_multiple_hid_connections() && + std::find(btif_hh_cb.new_connection_requests.begin(), + btif_hh_cb.new_connection_requests.end(), + link_spec) != btif_hh_cb.new_connection_requests.end()) { + btif_hh_cb.new_connection_requests.remove(link_spec); + log::info("Pending connection cancelled {}", link_spec); + return BT_STATUS_SUCCESS; } BTHH_LOG_UNKNOWN_LINK(link_spec); diff --git a/system/btif/src/btif_profile_storage.cc b/system/btif/src/btif_profile_storage.cc index f4ac16352c..e6d671a369 100644 --- a/system/btif/src/btif_profile_storage.cc +++ b/system/btif/src/btif_profile_storage.cc @@ -145,13 +145,6 @@ bt_status_t btif_storage_add_hid_device_info(const tAclLinkSpec& link_spec, uint log::verbose("link spec: {}", link_spec.ToRedactedStringForLogging()); std::string bdstr = link_spec.addrt.bda.ToString(); - if (!com::android::bluetooth::flags::allow_switching_hid_and_hogp()) { - btif_storage_hid_device_info(bdstr, attr_mask, sub_class, app_id, vendor_id, product_id, - version, ctry_code, ssr_max_latency, ssr_min_tout, dl_len, - dsc_list); - return BT_STATUS_SUCCESS; - } - if (link_spec.transport == BT_TRANSPORT_AUTO) { log::error("Unexpected transport!"); return BT_STATUS_UNHANDLED; @@ -291,9 +284,7 @@ bt_status_t btif_storage_load_bonded_hid_info(void) { link_spec.transport = BT_TRANSPORT_AUTO; int db_version = 0; - if (com::android::bluetooth::flags::allow_switching_hid_and_hogp()) { - btif_config_get_int(name, BTIF_STORAGE_KEY_HID_DB_VERSION, &db_version); - } + btif_config_get_int(name, BTIF_STORAGE_KEY_HID_DB_VERSION, &db_version); log::info("link spec: {}; db version: {}", link_spec, db_version); @@ -338,22 +329,20 @@ bt_status_t btif_storage_remove_hid_info(const tAclLinkSpec& link_spec) { btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_REPORT); btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_REPORT_VERSION); - if (com::android::bluetooth::flags::allow_switching_hid_and_hogp()) { - int db_version = 0; - btif_config_get_int(bdstr, BTIF_STORAGE_KEY_HID_DB_VERSION, &db_version); - if (db_version == STORAGE_HID_DB_VERSION) { - btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_ATTR_MASK); - btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_SUB_CLASS); - btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_APP_ID); - btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_VENDOR_ID); - btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_PRODUCT_ID); - btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_VERSION); - btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_COUNTRY_CODE); - btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_DESCRIPTOR); - btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_RECONNECT_ALLOWED); - } - btif_config_remove(bdstr, BTIF_STORAGE_KEY_HID_DB_VERSION); + int db_version = 0; + btif_config_get_int(bdstr, BTIF_STORAGE_KEY_HID_DB_VERSION, &db_version); + if (db_version == STORAGE_HID_DB_VERSION) { + btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_ATTR_MASK); + btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_SUB_CLASS); + btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_APP_ID); + btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_VENDOR_ID); + btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_PRODUCT_ID); + btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_VERSION); + btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_COUNTRY_CODE); + btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_DESCRIPTOR); + btif_config_remove(bdstr, BTIF_STORAGE_KEY_HOGP_RECONNECT_ALLOWED); } + btif_config_remove(bdstr, BTIF_STORAGE_KEY_HID_DB_VERSION); return BT_STATUS_SUCCESS; } |