Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disconnecting from a peripheral then reconnecting it again results in a false connection callback #189

Open
ScottSD777 opened this issue Oct 6, 2023 · 4 comments

Comments

@ScottSD777
Copy link

Connection to a peripheral works well unless it is disconnected then reconnected again. My application allows the user to disconnect from a peripheral then choose from other peripherals seen in the scan. When connecting again to the peripheral previously connected to, this results in the callback BluetoothCentralManagerCallback onConnectedPeripheral saying it was successful. However, this is followed shortly by the callback onDisconnectedPeripheral, saying it disconnected. The peripheral itself doesn't see a connection at this time.

In my debug log, I see that BluetoothPeripheral: reports that it was disconnected 'on request'. This was not requested.

See the log below showing that it connected to the peripheral named 'DDA-D7AF', and shortly after it disconnected.

I/BluetoothHandler: connected to 'DDA-D7AF'
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=5 device=DCBDCC_F
I/BluetoothPeripheral: disconnected 'DDA-D7AF' on request
I/BluetoothHandler: disconnected 'DDA-D7AF' with status SUCCESS

Note that upon the BluetoothHandler disconnect callback, the autoConnectPeripheral() is sent 5 seconds later, which does finally successfully connect to the peripheral correctly.

If I disconnect then reconnect to a DIFFERENT peripheral and not the one previously connected to, this false connection callback does not occur.

I am disconnecting by using cancel connection:
central.cancelConnection(peripheral);

I have also tried calling the peripheral cancel directly:
peripheral.cancelConnection();

Any ideas on this would be appreciated.

@weliem
Copy link
Owner

weliem commented Oct 6, 2023

I think this scenario should work perfectly fine as I am also doing this in my own apps. I have a suspicion you are calling connect again before the peripheral is fully disconnected because that would explain what you are describing.

Can you share a full log that shows this issue?

@ScottSD777
Copy link
Author

I really appreciate the quick reply. I believe you are correct. For a work around, I put in a delay after user disconnects before allowing connection again. This temporarily solves the issue. But the delay I chose is arbitrary and I don't trust it.

I am using the library, and not the Blessed source code, so I don't think I have access to the peripheral disconnect callback (or I am not understanding how to do this). I did check the state of the peripheral in the central callback, and that did say it was disconnected (which must be incorrect).

Attached is the log. As you can see, a reconnection is initially is indicated in the BluetoothHandler callback (line 445). At line 475, BluetoothPeripheral says it is disconnected and the Gatt is closed. Then sometime later, the auto connect occurs. This is not desirable.

Like I said, I believe you are correct. It seems like the peripheral isn't fully connected. I am, however, relying on the BluetoothCentralManagerCallback in BluetoothHandler:
@OverRide
public void onDisconnectedPeripheral(@NotNull final BluetoothPeripheral peripheral, final @NotNull HciStatus status) {
Timber.i("disconnected '%s' with status %s", peripheral.getName(), status);

Is it possible that I need to somehow gain access to the BluetoothPeripheral disconnect callback and rely only on that?
I/ViewRootImpl@2c88c9c[MainActivity]: ViewPostIme pointer 0 V/ViewRootImpl@2c88c9c[MainActivity]: Surface Surface(name=null)/@0x1a4e630 drawing to bitmap w=720, h=1600 V/ViewRootImpl@2c88c9c[MainActivity]: Surface Surface(name=null)/@0x1a4e630 drawing to bitmap w=720, h=1600 I/ViewRootImpl@2c88c9c[MainActivity]: ViewPostIme pointer 1 I/Dialog: mIsDeviceDefault = false, mIsSamsungBasicInteraction = false, isMetaDataInActivity = false I/DecorView: [INFO] isPopOver=false config=false I/DecorView: updateCaptionType: isFloating=true isApplication=true hasWindowDecorCaption=false this=DecorView@a70969b[] D/DecorView: setCaptionType = 0, this = DecorView@a70969b[] I/DecorView: setWindowBackground: isPopOver=false color=fff6f6f6 d=android.graphics.drawable.InsetDrawable@ab91a11 D/ScrollView: initGoToTop I/ViewRootImpl@2bbf168[MainActivity]: setView = com.android.internal.policy.DecorView@a70969b TM=true I/ViewRootImpl@2bbf168[MainActivity]: performTraversals params={(0,0)(wrapxwrap) gr=CENTER sim={adjust=pan forwardNavigation} ty=APPLICATION fmt=TRANSLUCENT wanim=0x7f110002 surfaceInsets=Rect(75, 75 - 75, 75) fl=820002 pfl=42000000 bhv=DEFAULT fitTypes=STATUS_BARS NAVIGATION_BARS CAPTION_BAR dimAmount=0.6 naviIconColor=0 sfl=100000} I/ViewRootImpl@2bbf168[MainActivity]: performTraversals mFirst=true windowShouldResize=false viewVisibilityChanged=false mForceNextWindowRelayout=false params={(0,0)(wrapxwrap) gr=CENTER sim={adjust=pan forwardNavigation} ty=APPLICATION fmt=TRANSLUCENT wanim=0x7f110002 surfaceInsets=Rect(75, 75 - 75, 75) fl=820002 pfl=42000000 bhv=DEFAULT fitTypes=STATUS_BARS NAVIGATION_BARS CAPTION_BAR dimAmount=0.6 naviIconColor=0 sfl=100000} I/ViewRootImpl@2bbf168[MainActivity]: updateBlastSurfaceIfNeeded mBlastBufferQueue=null isSameSurfaceControl=false D/BufferQueueConsumer: [](id:3e9500000017,api:0,p:-1,c:16021) connect: controlledByApp=false I/BLASTBufferQueue: new BLASTBufferQueue, mName= ViewRootImpl@2bbf168[MainActivity] mNativeObject= 0xf4d61240 sc.mNativeObject= 0xeff3a480 caller= android.view.ViewRootImpl.updateBlastSurfaceIfNeeded:2909 android.view.ViewRootImpl.relayoutWindow:9847 android.view.ViewRootImpl.performTraversals:3884 android.view.ViewRootImpl.doTraversal:3116 android.view.ViewRootImpl$TraversalRunnable.run:10885 android.view.Choreographer$CallbackRecord.run:1301 android.view.Choreographer$CallbackRecord.run:1309 android.view.Choreographer.doCallbacks:923 android.view.Choreographer.doFrame:852 android.view.Choreographer$FrameDisplayEventReceiver.run:1283 I/BLASTBufferQueue: update, w= 834 h= 437 mName = ViewRootImpl@2bbf168[MainActivity] mNativeObject= 0xf4d61240 sc.mNativeObject= 0xeff3a480 format= -3 caller= android.graphics.BLASTBufferQueue.<init>:84 android.view.ViewRootImpl.updateBlastSurfaceIfNeeded:2909 android.view.ViewRootImpl.relayoutWindow:9847 android.view.ViewRootImpl.performTraversals:3884 android.view.ViewRootImpl.doTraversal:3116 android.view.ViewRootImpl$TraversalRunnable.run:10885 I/ViewRootImpl@2bbf168[MainActivity]: Relayout returned: old=(0,45,720,1510) new=(18,634,702,921) req=(684,287)0 dur=8 res=0x3 s={true 0xd9357000} ch=true seqId=0 D/ScrollView: onsize change changed I/ViewRootImpl@2bbf168[MainActivity]: reportNextDraw android.view.ViewRootImpl.performTraversals:4438 android.view.ViewRootImpl.doTraversal:3116 android.view.ViewRootImpl$TraversalRunnable.run:10885 android.view.Choreographer$CallbackRecord.run:1301 android.view.Choreographer$CallbackRecord.run:1309 I/ViewRootImpl@2bbf168[MainActivity]: Setup new sync id=0 I/ViewRootImpl@2bbf168[MainActivity]: Setting syncFrameCallback V/ViewRootImpl@2bbf168[MainActivity]: Surface Surface(name=null)/@0xd698580 drawing to bitmap w=834, h=437 I/BLASTBufferQueue: [ViewRootImpl@2bbf168[MainActivity]#23](f:0,a:0) onFrameAvailable the first frame is available D/BLASTBufferQueue: [ViewRootImpl@2bbf168[MainActivity]#23](f:0,a:1) acquireNextBufferLocked size=834x437 mFrameNumber=1 applyTransaction=true mTimestamp=139505989244160(auto) mPendingTransactions.size=0 graphicBufferId=68809671049261 transform=0 I/ViewRootImpl@2bbf168[MainActivity]: onSyncComplete I/ViewRootImpl@2bbf168[MainActivity]: setupSync seqId=0 mSyncId=0 fn=0 caller=android.view.ViewRootImpl$$ExternalSyntheticLambda11.accept:6 android.window.SurfaceSyncer.lambda$setupSync$1$android-window-SurfaceSyncer:128 android.window.SurfaceSyncer$$ExternalSyntheticLambda1.accept:8 android.window.SurfaceSyncer$SyncSet.checkIfSyncIsComplete:382 android.window.SurfaceSyncer$SyncSet.markSyncReady:359 android.window.SurfaceSyncer.markSyncReady:151 android.view.ViewRootImpl.performTraversals:4503 I/ViewRootImpl@2bbf168[MainActivity]: reportDrawFinished seqId=0 mSyncId=-1 fn=0 mSurfaceChangedTransaction=0xf4bb7b00 V/ViewRootImpl@2bbf168[MainActivity]: Surface Surface(name=null)/@0xd698580 drawing to bitmap w=834, h=437 I/ViewRootImpl@2c88c9c[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 0 0 I/ViewRootImpl@2bbf168[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 0 I/ViewRootImpl@2bbf168[MainActivity]: ViewPostIme pointer 0 I/ViewRootImpl@2bbf168[MainActivity]: ViewPostIme pointer 1 V/ViewRootImpl@2bbf168[MainActivity]: Surface Surface(name=null)/@0xd698580 drawing to bitmap w=834, h=437 I/BluetoothHandler: userDisconnect() 'DDA-D7AF' I/BluetoothPeripheral: peripheral 'DC:BD:CC:B1:D7:AF' is disconnecting I/MSHandlerLifeCycle: removeMultiSplitHandler: no exist. decor=DecorView@a70969b[MainActivity] I/ViewRootImpl@2bbf168[MainActivity]: dispatchDetachedFromWindow D/BLASTBufferQueue: [ViewRootImpl@2bbf168[MainActivity]#23](f:0,a:1) destructor() D/BufferQueueConsumer: [ViewRootImpl@2bbf168[MainActivity]#23(BLAST Consumer)23](id:3e9500000017,api:0,p:-1,c:16021) disconnect D/InputTransport: Input channel destroyed: 'c152787', fd=104 D/BluetoothGatt: cancelOpen() - device: DCBDCC_F D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=5 device=DCBDCC_F I/BluetoothPeripheral: force disconnect 'DDA-D7AF' (DC:BD:CC:B1:D7:AF) I/BluetoothPeripheral: disconnected 'DDA-D7AF' on request D/BluetoothGatt: close() D/BluetoothGatt: unregisterApp() - mClientIf=5 I/BluetoothHandler: disconnected 'DDA-D7AF' with status SUCCESS I/System.out: 16:54:43.157 [main] DEBUG MainActivity - Bluetooth disconnected, I/Dialog: mIsDeviceDefault = false, mIsSamsungBasicInteraction = false, isMetaDataInActivity = false I/DecorView: [INFO] isPopOver=false config=false I/DecorView: updateCaptionType: isFloating=true isApplication=true hasWindowDecorCaption=false this=DecorView@2828498[] D/DecorView: setCaptionType = 0, this = DecorView@2828498[] I/DecorView: setWindowBackground: isPopOver=false color=fff6f6f6 d=android.graphics.drawable.InsetDrawable@757e8d6 I/System.out: 16:54:43.171 [Thread-11] DEBUG SendThread - stopping I/DecorView: setWindowBackground: isPopOver=false color=0 d=android.graphics.drawable.ColorDrawable@7af41f3 I/ViewRootImpl@a94eb0[MainActivity]: setView = com.android.internal.policy.DecorView@2828498 TM=true I/ViewRootImpl@a94eb0[MainActivity]: performTraversals params={(0,0)(wrapxwrap) gr=CENTER sim={adjust=pan forwardNavigation} ty=APPLICATION fmt=TRANSPARENT wanim=0x103030a surfaceInsets=Rect(75, 75 - 75, 75) fl=800002 pfl=42000000 bhv=DEFAULT fitTypes=STATUS_BARS NAVIGATION_BARS CAPTION_BAR dimAmount=0.5 naviIconColor=0 sfl=100000} I/ViewRootImpl@a94eb0[MainActivity]: performTraversals mFirst=true windowShouldResize=false viewVisibilityChanged=false mForceNextWindowRelayout=false params={(0,0)(wrapxwrap) gr=CENTER sim={adjust=pan forwardNavigation} ty=APPLICATION fmt=TRANSPARENT wanim=0x103030a surfaceInsets=Rect(75, 75 - 75, 75) fl=800002 pfl=42000000 bhv=DEFAULT fitTypes=STATUS_BARS NAVIGATION_BARS CAPTION_BAR dimAmount=0.5 naviIconColor=0 sfl=100000} I/ViewRootImpl@a94eb0[MainActivity]: updateBlastSurfaceIfNeeded mBlastBufferQueue=null isSameSurfaceControl=false D/BufferQueueConsumer: [](id:3e9500000018,api:0,p:-1,c:16021) connect: controlledByApp=false I/BLASTBufferQueue: new BLASTBufferQueue, mName= ViewRootImpl@a94eb0[MainActivity] mNativeObject= 0xf4d5d340 sc.mNativeObject= 0xf1574c40 caller= android.view.ViewRootImpl.updateBlastSurfaceIfNeeded:2909 android.view.ViewRootImpl.relayoutWindow:9847 android.view.ViewRootImpl.performTraversals:3884 android.view.ViewRootImpl.doTraversal:3116 android.view.ViewRootImpl$TraversalRunnable.run:10885 android.view.Choreographer$CallbackRecord.run:1301 android.view.Choreographer$CallbackRecord.run:1309 android.view.Choreographer.doCallbacks:923 android.view.Choreographer.doFrame:852 android.view.Choreographer$FrameDisplayEventReceiver.run:1283 I/BLASTBufferQueue: update, w= 589 h= 349 mName = ViewRootImpl@a94eb0[MainActivity] mNativeObject= 0xf4d5d340 sc.mNativeObject= 0xf1574c40 format= -2 caller= android.graphics.BLASTBufferQueue.<init>:84 android.view.ViewRootImpl.updateBlastSurfaceIfNeeded:2909 android.view.ViewRootImpl.relayoutWindow:9847 android.view.ViewRootImpl.performTraversals:3884 android.view.ViewRootImpl.doTraversal:3116 android.view.ViewRootImpl$TraversalRunnable.run:10885 I/ViewRootImpl@a94eb0[MainActivity]: Relayout returned: old=(0,45,720,1510) new=(140,678,579,877) req=(439,199)0 dur=8 res=0x3 s={true 0xd9357000} ch=true seqId=0 I/ViewRootImpl@a94eb0[MainActivity]: reportNextDraw android.view.ViewRootImpl.performTraversals:4438 android.view.ViewRootImpl.doTraversal:3116 android.view.ViewRootImpl$TraversalRunnable.run:10885 android.view.Choreographer$CallbackRecord.run:1301 android.view.Choreographer$CallbackRecord.run:1309 I/ViewRootImpl@a94eb0[MainActivity]: Setup new sync id=0 I/ViewRootImpl@a94eb0[MainActivity]: Setting syncFrameCallback V/ViewRootImpl@a94eb0[MainActivity]: Surface Surface(name=null)/@0xeefc6b drawing to bitmap w=589, h=349 I/BLASTBufferQueue: [ViewRootImpl@a94eb0[MainActivity]#24](f:0,a:0) onFrameAvailable the first frame is available D/BLASTBufferQueue: [ViewRootImpl@a94eb0[MainActivity]#24](f:0,a:1) acquireNextBufferLocked size=589x349 mFrameNumber=1 applyTransaction=true mTimestamp=139507308271237(auto) mPendingTransactions.size=0 graphicBufferId=68809671049263 transform=0 I/ViewRootImpl@a94eb0[MainActivity]: onSyncComplete I/ViewRootImpl@a94eb0[MainActivity]: setupSync seqId=0 mSyncId=0 fn=0 caller=android.view.ViewRootImpl$$ExternalSyntheticLambda11.accept:6 android.window.SurfaceSyncer.lambda$setupSync$1$android-window-SurfaceSyncer:128 android.window.SurfaceSyncer$$ExternalSyntheticLambda1.accept:8 android.window.SurfaceSyncer$SyncSet.checkIfSyncIsComplete:382 android.window.SurfaceSyncer$SyncSet.markSyncReady:359 android.window.SurfaceSyncer.markSyncReady:151 android.view.ViewRootImpl.performTraversals:4503 I/ViewRootImpl@a94eb0[MainActivity]: reportDrawFinished seqId=0 mSyncId=-1 fn=0 mSurfaceChangedTransaction=0xf4bb76a0 I/System.out: 16:54:43.235 [main] DEBUG MainActivity - Calling startLeScan I/MSHandlerLifeCycle: removeMultiSplitHandler: no exist. decor=DecorView@2828498[MainActivity] I/ViewRootImpl@a94eb0[MainActivity]: dispatchDetachedFromWindow D/BLASTBufferQueue: [ViewRootImpl@a94eb0[MainActivity]#24](f:0,a:1) destructor() D/BufferQueueConsumer: [ViewRootImpl@a94eb0[MainActivity]#24(BLAST Consumer)24](id:3e9500000018,api:0,p:-1,c:16021) disconnect D/InputTransport: Input channel destroyed: '6be1468', fd=104 D/MaskableFrameLayout: Mode is DST_IN I/System.out: 16:54:43.275 [main] DEBUG MainMenuFragment - screen size: 720.0,1470.0 leftMargin: 281 I/System.out: 16:54:43.293 [main] DEBUG MainActivity - popped to Main Menu I/System.out: 16:54:43.294 [main] DEBUG MainActivity - pushing to NOT SET I/BluetoothCentralManager: no scan to stop because no scan is running I/ViewRootImpl@2c88c9c[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 0 D/InputMethodManager: startInputInner - Id : 0 I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus I/System.out: 16:54:43.350 [main] DEBUG MainMenuFragment - 1 lv:720x1470 mar:281 Y:217.0 normY:-0.70476186-0.14761905 sinY:-0.6478524430857011 X:118.78906 I/System.out: 16:54:43.352 [main] DEBUG MainMenuFragment - 2 lv:720x1470 mar:281 Y:350.0 normY:-0.52380955-0.23809524 sinY:-0.5001825267772194 X:70.37596 I/System.out: 16:54:43.354 [main] DEBUG MainMenuFragment - 3 lv:720x1470 mar:281 Y:483.0 normY:-0.34285712-0.32857144 sinY:-0.3361792928173792 X:40.608234 I/System.out: 16:54:43.356 [main] DEBUG MainMenuFragment - 4 lv:720x1470 mar:281 Y:616.0 normY:-0.16190475-0.41904762 sinY:-0.16119833986128745 X:24.48583 I/System.out: 16:54:43.358 [main] DEBUG MainMenuFragment - 5 lv:720x1470 mar:281 Y:749.0 normY:0.019047618-0.5095238 sinY:0.019046466149927572 X:20.061684 I/System.out: 16:54:43.360 [main] DEBUG MainMenuFragment - 6 lv:720x1470 mar:281 Y:882.0 normY:0.20000005-0.6 sinY:0.19866937752827718 X:26.869398 D/AbsListView: in onLayout changed V/ViewRootImpl@2c88c9c[MainActivity]: Surface Surface(name=null)/@0x1a4e630 drawing to bitmap w=720, h=1600 I/ViewRootImpl@2c88c9c[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 0 I/ViewRootImpl@2c88c9c[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 0 D/AbsListView: in onLayout changed I/BluetoothAdapter: STATE_ON I/BluetoothAdapter: STATE_ON I/BluetoothAdapter: STATE_ON I/BluetoothAdapter: STATE_ON D/BluetoothLeScanner: Start Scan with callback D/BluetoothLeScanner: onScannerRegistered() - status=0 scannerId=8 mScannerId=0 I/BluetoothCentralManager: scan started D/AbsListView: in onLayout changed V/ViewRootImpl@2c88c9c[MainActivity]: Surface Surface(name=null)/@0x1a4e630 drawing to bitmap w=720, h=1600 I/BluetoothHandler: Found peripheral 'DDA-D7AF' I/BluetoothHandler: Found peripheral 'HDX-76C3' I/BluetoothHandler: Found peripheral 'DDA-D7AF' I/BluetoothHandler: Found peripheral 'DDA-D7AF' I/ViewRootImpl@2c88c9c[MainActivity]: ViewPostIme pointer 0 I/ViewRootImpl@2c88c9c[MainActivity]: ViewPostIme pointer 1 D/AbsListView: onTouchUp() mTouchMode : 0 I/Dialog: mIsDeviceDefault = false, mIsSamsungBasicInteraction = false, isMetaDataInActivity = false I/DecorView: [INFO] isPopOver=false config=false I/DecorView: updateCaptionType: isFloating=true isApplication=true hasWindowDecorCaption=false this=DecorView@ca683af[] D/DecorView: setCaptionType = 0, this = DecorView@ca683af[] I/DecorView: setWindowBackground: isPopOver=false color=fff6f6f6 d=android.graphics.drawable.InsetDrawable@21d5f45 I/DecorView: setWindowBackground: isPopOver=false color=0 d=android.graphics.drawable.ColorDrawable@e39aac1 I/ViewRootImpl@2dab266[MainActivity]: setView = com.android.internal.policy.DecorView@ca683af TM=true I/BluetoothHandler: connectPeripheral() 'DDA-D7AF' I/BluetoothAdapter: STATE_ON D/BluetoothLeScanner: Stop Scan with callback I/BluetoothCentralManager: scan stopped V/ViewRootImpl@2c88c9c[MainActivity]: Surface Surface(name=null)/@0x1a4e630 drawing to bitmap w=720, h=1600 I/ViewRootImpl@2dab266[MainActivity]: performTraversals params={(0,0)(wrapxwrap) gr=CENTER sim={adjust=pan forwardNavigation} ty=APPLICATION fmt=TRANSPARENT wanim=0x103030a surfaceInsets=Rect(75, 75 - 75, 75) fl=800002 pfl=42000000 bhv=DEFAULT fitTypes=STATUS_BARS NAVIGATION_BARS CAPTION_BAR dimAmount=0.5 naviIconColor=0 sfl=100000} I/ViewRootImpl@2dab266[MainActivity]: performTraversals mFirst=true windowShouldResize=false viewVisibilityChanged=false mForceNextWindowRelayout=false params={(0,0)(wrapxwrap) gr=CENTER sim={adjust=pan forwardNavigation} ty=APPLICATION fmt=TRANSPARENT wanim=0x103030a surfaceInsets=Rect(75, 75 - 75, 75) fl=800002 pfl=42000000 bhv=DEFAULT fitTypes=STATUS_BARS NAVIGATION_BARS CAPTION_BAR dimAmount=0.5 naviIconColor=0 sfl=100000} I/ViewRootImpl@2dab266[MainActivity]: updateBlastSurfaceIfNeeded mBlastBufferQueue=null isSameSurfaceControl=false D/BufferQueueConsumer: [](id:3e9500000019,api:0,p:-1,c:16021) connect: controlledByApp=false I/BLASTBufferQueue: new BLASTBufferQueue, mName= ViewRootImpl@2dab266[MainActivity] mNativeObject= 0xf4d60b40 sc.mNativeObject= 0xeff3acf0 caller= android.view.ViewRootImpl.updateBlastSurfaceIfNeeded:2909 android.view.ViewRootImpl.relayoutWindow:9847 android.view.ViewRootImpl.performTraversals:3884 android.view.ViewRootImpl.doTraversal:3116 android.view.ViewRootImpl$TraversalRunnable.run:10885 android.view.Choreographer$CallbackRecord.run:1301 android.view.Choreographer$CallbackRecord.run:1309 android.view.Choreographer.doCallbacks:923 android.view.Choreographer.doFrame:852 android.view.Choreographer$FrameDisplayEventReceiver.run:1283 I/BLASTBufferQueue: update, w= 547 h= 349 mName = ViewRootImpl@2dab266[MainActivity] mNativeObject= 0xf4d60b40 sc.mNativeObject= 0xeff3acf0 format= -2 caller= android.graphics.BLASTBufferQueue.<init>:84 android.view.ViewRootImpl.updateBlastSurfaceIfNeeded:2909 android.view.ViewRootImpl.relayoutWindow:9847 android.view.ViewRootImpl.performTraversals:3884 android.view.ViewRootImpl.doTraversal:3116 android.view.ViewRootImpl$TraversalRunnable.run:10885 I/ViewRootImpl@2dab266[MainActivity]: Relayout returned: old=(0,45,720,1510) new=(161,678,558,877) req=(397,199)0 dur=8 res=0x3 s={true 0xf064a000} ch=true seqId=0 I/ViewRootImpl@2dab266[MainActivity]: reportNextDraw android.view.ViewRootImpl.performTraversals:4438 android.view.ViewRootImpl.doTraversal:3116 android.view.ViewRootImpl$TraversalRunnable.run:10885 android.view.Choreographer$CallbackRecord.run:1301 android.view.Choreographer$CallbackRecord.run:1309 I/ViewRootImpl@2dab266[MainActivity]: Setup new sync id=0 I/ViewRootImpl@2dab266[MainActivity]: Setting syncFrameCallback V/ViewRootImpl@2dab266[MainActivity]: Surface Surface(name=null)/@0x8c3a83e drawing to bitmap w=547, h=349 I/BLASTBufferQueue: [ViewRootImpl@2dab266[MainActivity]#25](f:0,a:0) onFrameAvailable the first frame is available D/BLASTBufferQueue: [ViewRootImpl@2dab266[MainActivity]#25](f:0,a:1) acquireNextBufferLocked size=547x349 mFrameNumber=1 applyTransaction=true mTimestamp=139509647799622(auto) mPendingTransactions.size=0 graphicBufferId=68809671049264 transform=0 I/ViewRootImpl@2dab266[MainActivity]: onSyncComplete I/ViewRootImpl@2dab266[MainActivity]: setupSync seqId=0 mSyncId=0 fn=0 caller=android.view.ViewRootImpl$$ExternalSyntheticLambda11.accept:6 android.window.SurfaceSyncer.lambda$setupSync$1$android-window-SurfaceSyncer:128 android.window.SurfaceSyncer$$ExternalSyntheticLambda1.accept:8 android.window.SurfaceSyncer$SyncSet.checkIfSyncIsComplete:382 android.window.SurfaceSyncer$SyncSet.markSyncReady:359 android.window.SurfaceSyncer.markSyncReady:151 android.view.ViewRootImpl.performTraversals:4503 I/ViewRootImpl@2dab266[MainActivity]: reportDrawFinished seqId=0 mSyncId=-1 fn=0 mSurfaceChangedTransaction=0xeff94f20 I/ViewRootImpl@2c88c9c[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 0 0 I/ViewRootImpl@2dab266[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 0 D/InputMethodManager: startInputInner - Id : 0 I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus I/BluetoothPeripheral: connect to 'DDA-D7AF' (DC:BD:CC:B1:D7:AF) using transport LE I/BluetoothAdapter: STATE_ON D/BluetoothGatt: connect() - device: DCBDCC_F, auto: false D/BluetoothGatt: registerApp() D/BluetoothGatt: registerApp() - UUID=82cbebbd-7d4f-4b8c-9999-86ffd6c57ee8 I/BluetoothPeripheral: peripheral 'DC:BD:CC:B1:D7:AF' is connecting D/BluetoothGatt: onClientRegistered() - status=0 clientIf=5 V/ViewRootImpl@2dab266[MainActivity]: Surface Surface(name=null)/@0x8c3a83e drawing to bitmap w=547, h=349 D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=5 device=DCBDCC_F V/ViewRootImpl@2dab266[MainActivity]: Surface Surface(name=null)/@0x8c3a83e drawing to bitmap w=547, h=349 I/BluetoothPeripheral: connected to 'DDA-D7AF' (NONE) in 0.1s D/BluetoothPeripheral: discovering services of 'DDA-D7AF' with delay of 0 ms D/BluetoothGatt: discoverServices() - device: DCBDCC_F D/BluetoothGatt: onSearchComplete() = Device=DCBDCC_F Status=0 I/BluetoothPeripheral: discovered 0 services for 'DDA-D7AF' I/BluetoothHandler: connected to 'DDA-D7AF' I/System.out: 16:54:48.861 [main] DEBUG MainActivity - Bluetooth connect successful I/System.out: 16:54:48.862 [Thread-12] DEBUG SendThread - starting D/MaskableFrameLayout: Mode is DST_IN I/System.out: 16:54:48.927 [main] DEBUG MainMenuFragment - screen size: 720.0,1470.0 leftMargin: 281 I/System.out: 16:54:48.947 [main] DEBUG Dakota - sendMessage RXDO I/System.out: 16:54:48.959 [main] DEBUG MainActivity - popped to Main Menu I/System.out: 16:54:48.971 [Thread-12] DEBUG SendThread - sent RXDO I/System.out: 16:54:49.021 [main] DEBUG MainMenuFragment - 1 lv:720x1470 mar:281 Y:217.0 normY:-0.70476186-0.14761905 sinY:-0.6478524430857011 X:118.78906 I/System.out: 16:54:49.024 [main] DEBUG MainMenuFragment - 2 lv:720x1470 mar:281 Y:350.0 normY:-0.52380955-0.23809524 sinY:-0.5001825267772194 X:70.37596 I/System.out: 16:54:49.025 [main] DEBUG MainMenuFragment - 3 lv:720x1470 mar:281 Y:483.0 normY:-0.34285712-0.32857144 sinY:-0.3361792928173792 X:40.608234 I/System.out: 16:54:49.027 [main] DEBUG MainMenuFragment - 4 lv:720x1470 mar:281 Y:616.0 normY:-0.16190475-0.41904762 sinY:-0.16119833986128745 X:24.48583 I/System.out: 16:54:49.029 [main] DEBUG MainMenuFragment - 5 lv:720x1470 mar:281 Y:749.0 normY:0.019047618-0.5095238 sinY:0.019046466149927572 X:20.061684 I/System.out: 16:54:49.031 [main] DEBUG MainMenuFragment - 6 lv:720x1470 mar:281 Y:882.0 normY:0.20000005-0.6 sinY:0.19866937752827718 X:26.869398 D/AbsListView: in onLayout changed V/ViewRootImpl@2c88c9c[MainActivity]: Surface Surface(name=null)/@0x1a4e630 drawing to bitmap w=720, h=1600 V/ViewRootImpl@2dab266[MainActivity]: Surface Surface(name=null)/@0x8c3a83e drawing to bitmap w=547, h=349 D/BluetoothGatt: configureMTU() - device: DCBDCC_F mtu: 185 I/BluetoothPeripheral: requesting MTU of 185 V/ViewRootImpl@2dab266[MainActivity]: Surface Surface(name=null)/@0x8c3a83e drawing to bitmap w=547, h=349 V/ViewRootImpl@2c88c9c[MainActivity]: Surface Surface(name=null)/@0x1a4e630 drawing to bitmap w=720, h=1600 D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=5 device=DCBDCC_F I/MSHandlerLifeCycle: removeMultiSplitHandler: no exist. decor=DecorView@ca683af[MainActivity] I/ViewRootImpl@2dab266[MainActivity]: dispatchDetachedFromWindow D/BLASTBufferQueue: [ViewRootImpl@2dab266[MainActivity]#25](f:0,a:1) destructor() D/BufferQueueConsumer: [ViewRootImpl@2dab266[MainActivity]#25(BLAST Consumer)25](id:3e9500000019,api:0,p:-1,c:16021) disconnect I/BluetoothPeripheral: disconnected 'DDA-D7AF' on request D/BluetoothGatt: close() D/BluetoothGatt: unregisterApp() - mClientIf=5 D/InputTransport: Input channel destroyed: 'e826361', fd=105 I/System.out: 16:54:49.179 [main] DEBUG Dakota - sendMessage RIM V/ViewRootImpl@2c88c9c[MainActivity]: Surface Surface(name=null)/@0x1a4e630 drawing to bitmap w=720, h=1600 I/BluetoothHandler: disconnected 'DDA-D7AF' with status SUCCESS V/ViewRootImpl@2c88c9c[MainActivity]: Surface Surface(name=null)/@0x1a4e630 drawing to bitmap w=720, h=1600 I/ViewRootImpl@2c88c9c[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 0 D/InputMethodManager: startInputInner - Id : 0 I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus I/System.out: 16:54:49.274 [Thread-12] DEBUG SendThread - stopping I/BluetoothPeripheral: autoConnect to 'DDA-D7AF' (DC:BD:CC:B1:D7:AF) using transport LE I/BluetoothAdapter: STATE_ON D/BluetoothGatt: connect() - device: DCBDCC_F, auto: true D/BluetoothGatt: registerApp() D/BluetoothGatt: registerApp() - UUID=68ff1af7-bd6e-4c39-a878-57d5866834d3 I/BluetoothPeripheral: peripheral 'DC:BD:CC:B1:D7:AF' is connecting D/BluetoothGatt: onClientRegistered() - status=0 clientIf=5 D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=5 device=DCBDCC_F I/BluetoothPeripheral: connected to 'DDA-D7AF' (NONE) in 2.0s D/BluetoothPeripheral: discovering services of 'DDA-D7AF' with delay of 0 ms D/BluetoothGatt: discoverServices() - device: DCBDCC_F D/BluetoothGatt: onConnectionUpdated() - Device=DCBDCC_F interval=6 latency=0 timeout=500 status=0 D/BluetoothPeripheral: connection parameters: interval=7.5ms latency=0 timeout=5s D/BluetoothGatt: onSearchComplete() = Device=DCBDCC_F Status=0 I/BluetoothPeripheral: discovered 3 services for 'DDA-D7AF' I/BluetoothHandler: connected to 'DDA-D7AF' I/System.out: 16:54:57.207 [main] DEBUG MainActivity - Bluetooth connect successful I/System.out: 16:54:57.208 [Thread-13] DEBUG SendThread - starting I/System.out: 16:54:57.221 [Thread-13] DEBUG SendThread - sent RIM I/System.out: 16:54:57.261 [main] DEBUG Dakota - sendMessage SEVF D/BluetoothGatt: onConnectionUpdated() - Device=DCBDCC_F interval=39 latency=0 timeout=500 status=0 D/BluetoothPeripheral: connection parameters: interval=48.8ms latency=0 timeout=5s I/System.out: 16:54:57.269 [main] DEBUG MainActivity - popped to Main Menu D/BluetoothPeripheral: writing <2a52494d0d0a> to characteristic <49535343-8841-43f4-a8d4-ecbe34729bb3> I/System.out: 16:54:57.324 [Thread-13] DEBUG SendThread - sent SEVF V/ViewRootImpl@2c88c9c[MainActivity]: Surface Surface(name=null)/@0x1a4e630 drawing to bitmap w=720, h=1600 I/BluetoothHandler: SUCCESS: Writing <2A 52 49 4D 0D 0A > to <49535343-8841-43f4-a8d4-ecbe34729bb3> D/BluetoothGatt: configureMTU() - device: DCBDCC_F mtu: 185 I/BluetoothPeripheral: requesting MTU of 185 I/System.out: 16:54:57.462 [main] DEBUG Dakota - sendMessage RIM D/BluetoothGatt: onConfigureMTU() - Device=DCBDCC_F mtu=185 status=0 I/BluetoothHandler: new MTU set: 185 D/BluetoothGatt: requestConnectionPriority() - params: 1 D/BluetoothPeripheral: requesting connection priority HIGH I/System.out: 16:54:57.530 [Thread-13] DEBUG SendThread - sent RIM I/BluetoothPeripheral: setting preferred Phy: tx = LE_2M, rx = LE_2M, options = S2 D/BluetoothGatt: onConnectionUpdated() - Device=DCBDCC_F interval=12 latency=0 timeout=500 status=0 D/BluetoothPeripheral: connection parameters: interval=15.0ms latency=0 timeout=5s D/BluetoothGatt: onPhyUpdate() - status=0 address=DCBDCC_F txPhy=2 rxPhy=2 D/BluetoothPeripheral: reading Phy I/BluetoothPeripheral: updated Phy: tx = LE_2M, rx = LE_2M D/BluetoothGatt: onPhyRead() - status=0 address=DCBDCC_F txPhy=2 rxPhy=2 I/BluetoothPeripheral: updated Phy: tx = LE_2M, rx = LE_2M D/BluetoothGatt: setCharacteristicNotification() - uuid: 49535343-1e4d-4bd9-ba61-23c647249616 enable: true I/BluetoothHandler: SUCCESS: Notify set to 'true' for 49535343-1e4d-4bd9-ba61-23c647249616 D/BluetoothPeripheral: writing <2a534556460d0a> to characteristic <49535343-8841-43f4-a8d4-ecbe34729bb3> I/BluetoothHandler: SUCCESS: Writing <2A 53 45 56 46 0D 0A > to <49535343-8841-43f4-a8d4-ecbe34729bb3> D/BluetoothPeripheral: writing <2a52494d0d0a> to characteristic <49535343-8841-43f4-a8d4-ecbe34729bb3> I/BluetoothHandler: SUCCESS: Writing <2A 52 49 4D 0D 0A > to <49535343-8841-43f4-a8d4-ecbe34729bb3>
Regards.

@ScottSD777
Copy link
Author

OK, I see one thing that I was not implementing. I added onConnectionUpdated() to BluetoothPeripheralCallback peripheralCallback. It looks like your Blessed Example wasn't using that either.

Things work better now, but I am getting that callback twice for some reason when connecting. Still looking into it....

I don't think this is an issue with your code, and I appreciate your replies.

@ScottSD777
Copy link
Author

ScottSD777 commented Oct 10, 2023

One thing I notice is that the BluetoothPeripheralCallback onConnectionUpdated() triggers when there is a connection, but does not trigger on a disconnect. Am I to assume that I need to use BluetoothPeripheralCallback onConnectionUpdated() to determine a successful connection and BluetoothCentralManagerCallback onDisconnectedPeripheral() to determine a successful disconnection?

And... on when connecting, I am getting multiple BluetoothPeripheralCallback onConnectionUpdated() callbacks. Why would this be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants