@@ -262,6 +262,21 @@ public void handle(CommissionerDeclaration cd) {
262
262
});
263
263
}
264
264
265
+ @ Override
266
+ public void onStop () {
267
+ super .onStop ();
268
+ // Only stop connection if we are still connecting to the device
269
+ if (targetCastingPlayer .getConnectionState () == CastingPlayer .ConnectionState .CONNECTING ) {
270
+ // NOTE, once stopConnecting() is called, the targetCastingPlayer's native object is freed
271
+ MatterError err = targetCastingPlayer .stopConnecting ();
272
+ if (err .hasError ()) {
273
+ Log .e (
274
+ TAG ,
275
+ "Going back before connection finishes but stopConnecting() failed due to: " + err );
276
+ }
277
+ }
278
+ }
279
+
265
280
private void displayPasscodeInputDialog (Context context ) {
266
281
AlertDialog .Builder builder = new AlertDialog .Builder (context );
267
282
@@ -336,18 +351,9 @@ public void onClick(DialogInterface dialog, int which) {
336
351
connectionFragmentStatusTextView .setText (
337
352
"Casting Player CONTINUE CONNECTING failed due to: "
338
353
+ finalErr
339
- + "\n \n " );
354
+ + ". Route back to disconnect & try again. \n \n " );
340
355
});
341
- Log .e (
342
- TAG ,
343
- "displayPasscodeInputDialog() continueConnecting() failed, calling stopConnecting() due to: "
344
- + err );
345
- // Since continueConnecting() failed, Attempt to cancel the connection attempt with
346
- // the CastingPlayer/Commissioner.
347
- err = targetCastingPlayer .stopConnecting ();
348
- if (err .hasError ()) {
349
- Log .e (TAG , "displayPasscodeInputDialog() stopConnecting() failed due to: " + err );
350
- }
356
+ Log .e (TAG , "displayPasscodeInputDialog() continueConnecting() failed due to: " + err );
351
357
}
352
358
}
353
359
});
@@ -359,20 +365,9 @@ public void onClick(DialogInterface dialog, int which) {
359
365
public void onClick (DialogInterface dialog , int which ) {
360
366
Log .i (
361
367
TAG ,
362
- "displayPasscodeInputDialog() user cancelled the CastingPlayer/Commissioner-Generated Passcode input dialog. Calling stopConnecting() " );
368
+ "displayPasscodeInputDialog() user cancelled the CastingPlayer/Commissioner-Generated Passcode input dialog" );
363
369
connectionFragmentStatusTextView .setText (
364
- "Connection attempt with Casting Player cancelled by the Casting Client/Commissionee user. \n \n Route back to exit. \n \n " );
365
- MatterError err = targetCastingPlayer .stopConnecting ();
366
- if (err .hasError ()) {
367
- MatterError finalErr = err ;
368
- getActivity ()
369
- .runOnUiThread (
370
- () -> {
371
- connectionFragmentStatusTextView .setText (
372
- "Casting Player CANCEL failed due to: " + finalErr + "\n \n " );
373
- });
374
- Log .e (TAG , "displayPasscodeInputDialog() stopConnecting() failed due to: " + err );
375
- }
370
+ "Connection attempt with Casting Player cancelled by the Casting Client/Commissionee user. \n \n Route back to disconnect & exit. \n \n " );
376
371
dialog .cancel ();
377
372
}
378
373
});
0 commit comments