[Android Q&A, Help & Troubleshooting] xlaffer:
I originally posted this question on Stackoverflow, but thought y'all might have some more insight.

I have a BLE device and app that I am developing. When I use my OP3T to connect to the device and then disconnect, the system goes through this cycle of connecting and disconnecting every 5-ish seconds.

This is what I have tried:

Tried testing on other phones, both previous Android versions and the same version, but different hardware. No other phones exhibit this behavior.

Connected to the device through my app, through the nRF Connect app and by pairing to the device through the Bluetooth settings screen. No matter what, the issue appears. When using the apps, I would connect, then disconnect and then immediately kill the app by opening the app switcher and swiping the app away. I confirmed that the app was dead by searching for the pid with adb shell ps | grep and also ensured logcat wasn't showing that pid.

Loaded my own firmware onto the device as well as an example application from the manufacturer with the same results.

Ensured that the UUIDs for the services are different from the ones set aside by the Bluetooth SIG. I am using the company ID of 0xFFFF, btw.

Ensured that the autoconnect flag is false.

Inspected the hci log to ensure that the device was indeed connecting and disconnecting.

I am leaning towards the idea that the Android system believes the device is a headset and therefore connects to it when it can. However, I don't think this explains why it also disconnects. I have this theory due to some log messages referencing Avrcp (Audio/Video Remote Control Profile), HeadsetStateMachine and pbap (Phone Book Access Profile) that surround a connecting or disconnection event.

Here is the logcat log with the filter "connect". I can supply a full log capture from turning Bluetooth on, to a few cycles of the connect/disconnect behavior, if needed.

07-25 16:39:59.435 2896-3336/? V/AlarmManager: Triggering alarm #0: 2 when =859680625 package=com.google.android.gmsoperation =*walarm*:null.CONNECTION_ALARM
07-25 16:40:02.544 2896-3336/? V/AlarmManager: Triggering alarm #0: 2 when =859682773 package=com.google.android.gmsoperation =*walarm*:null.CONNECTION_ALARM
07-25 16:40:04.441 5709-5752/? W/bt_btif: bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0016
07-25 16:40:04.442 5709-5752/? W/bt_btif: bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x0016
07-25 16:40:04.442 5709-5752/? I/bt_btm_sec: btm_sec_disconnected clearing pending flag handle:10 reason:22
07-25 16:40:04.459 5709-5709/? D/AvrcpBipRsp: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:04.460 5709-5709/? D/BluetoothMapService: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:04.472 4077-4077/? I/TrustAgent.Tracker: [BluetoothConnectionTracker] Bluetooth disconnect broadast for Prototype-Device F3:93:9C:88:3B:66
07-25 16:40:05.181 5709-5709/? D/BluetoothPbapReceiver: PbapReceiver onReceive action = android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:05.198 5709-5709/? I/BluetoothPbapReceiver: Exit - onReceive for intent:android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:05.199 5709-5709/? D/BluetoothPbapService: action: android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:05.214 5709-5709/? V/BluetoothFtpService: PARSE INTENT action: android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:05.231 5709-5709/? D/BluetoothDunService: parseIntent: action: android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:05.606 5709-5752/? W/bt_smp: smp_br_connect_callback is called on unexpected transport 2
07-25 16:40:05.651 4077-4077/? I/TrustAgent.Tracker: [BluetoothConnectionTracker] Bluetooth connect broadast for Prototype-Device F3:93:9C:88:3B:66
07-25 16:40:06.640 2896-3336/? V/AlarmManager: Triggering alarm #0: 2 when =859687830 package=com.google.android.gmsoperation =*walarm*:null.CONNECTION_ALARM
07-25 16:40:11.641 5709-5752/? W/bt_btif: bta_gattc_conn_cback() - cif=3 connected=0 conn_id=3 reason=0x0016
07-25 16:40:11.642 5709-5752/? W/bt_btif: bta_gattc_conn_cback() - cif=4 connected=0 conn_id=4 reason=0x0016
07-25 16:40:11.642 5709-5752/? I/bt_btm_sec: btm_sec_disconnected clearing pending flag handle:11 reason:22
07-25 16:40:11.656 5709-5709/? D/AvrcpBipRsp: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:11.657 5709-5709/? D/BluetoothMapService: onReceive: android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:11.666 4077-4077/? I/TrustAgent.Tracker: [BluetoothConnectionTracker] Bluetooth disconnect broadast for Prototype-Device F3:93:9C:88:3B:66
07-25 16:40:12.342 5709-5709/? D/BluetoothPbapReceiver: PbapReceiver onReceive action = android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:12.355 5709-5709/? I/BluetoothPbapReceiver: Exit - onReceive for intent:android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:12.356 5709-5709/? D/BluetoothPbapService: action: android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:12.370 5709-5709/? V/BluetoothFtpService: PARSE INTENT action: android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:12.380 5709-5709/? D/BluetoothDunService: parseIntent: action: android.bluetooth.device.action.ACL_DISCONNECTED
07-25 16:40:12.761 5709-5752/? W/bt_smp: smp_br_connect_callback is called on unexpected transport 2
07-25 16:40:12.800 4077-4077/? I/TrustAgent.Tracker: [BluetoothConnectionTracker] Bluetooth connect broadast for Prototype-Device F3:93:9C:88:3B:66
07-25 16:40:13.790 2896-3336/? V/AlarmManager: Triggering alarm #0: 2 when =859694981 package=com.google.android.gmsoperation =*walarm*:null.CONNECTION_ALARM
07-25 16:40:15.927 2896-3336/? V/AlarmManager: Triggering alarm #0: 2 when =859697117 package=com.google.android.gmsoperation =*walarm*:null.CONNECTION_ALARM

How can I stop the system from automatically connecting and disconnecting?