Skip to content

Commit ac97dce

Browse files
[Amazon] StopConnect for UDC in Android tv-casting-app
Updated JNI and Android tv-casting-app to use native layer ConnectionState instead of a pendingPasscode customer check. Changes * Expose native layer ConnectionState to Android tv-casting-app * Update Android tv-casting-app to use ConnectionState to determine if we should call stopConnect() * Only call stopConnect() on navigate back from ConnectionExampleFragmnet Test 1. Manually verified UDC attempt is successful both Android iOS for following 1. Attempt UDC attempt (both commissionee & commissioner generated passcode) 2. Navigate back to discovery page 3. Start new UDC attempt (both commissionee & commissioner generated passcode) 2. Manually verified UDC attempt is successful both Android iOS for following. UDC will finish in the background. 1. Attempt UDC attempt (both commissionee & commissioner generated passcode) 2. Confirm passcode on TV app or casting app depending on who generated passcode 3. Navigate back before commission fnishes. 3. Manual regression test following * UDC attempt happy path (no navigate back) for both commissinee & commissioner generated passcode
1 parent 8cc626a commit ac97dce

File tree

5 files changed

+43
-41
lines changed

5 files changed

+43
-41
lines changed

examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/ConnectionExampleFragment.java

+9-27
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,11 @@ public void handle(CommissionerDeclaration cd) {
263263
}
264264

265265
@Override
266-
public void onDestroy() {
267-
super.onDestroy();
268-
269-
// Only stop connection if we are pending passcode confirmation
270-
// We cannot stop connection once continueConnecting() is called
271-
if (targetCastingPlayer.isPendingPasscodeFromUser()) {
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
272271
MatterError err = targetCastingPlayer.stopConnecting();
273272
if (err.hasError()) {
274273
Log.e(
@@ -352,18 +351,12 @@ public void onClick(DialogInterface dialog, int which) {
352351
connectionFragmentStatusTextView.setText(
353352
"Casting Player CONTINUE CONNECTING failed due to: "
354353
+ finalErr
355-
+ "\n\n");
354+
+ ". Route back to disconnect & try again. \n\n");
356355
});
357356
Log.e(
358357
TAG,
359-
"displayPasscodeInputDialog() continueConnecting() failed, calling stopConnecting() due to: "
358+
"displayPasscodeInputDialog() continueConnecting() failed due to: "
360359
+ err);
361-
// Since continueConnecting() failed, Attempt to cancel the connection attempt with
362-
// the CastingPlayer/Commissioner.
363-
err = targetCastingPlayer.stopConnecting();
364-
if (err.hasError()) {
365-
Log.e(TAG, "displayPasscodeInputDialog() stopConnecting() failed due to: " + err);
366-
}
367360
}
368361
}
369362
});
@@ -375,20 +368,9 @@ public void onClick(DialogInterface dialog, int which) {
375368
public void onClick(DialogInterface dialog, int which) {
376369
Log.i(
377370
TAG,
378-
"displayPasscodeInputDialog() user cancelled the CastingPlayer/Commissioner-Generated Passcode input dialog. Calling stopConnecting()");
371+
"displayPasscodeInputDialog() user cancelled the CastingPlayer/Commissioner-Generated Passcode input dialog");
379372
connectionFragmentStatusTextView.setText(
380-
"Connection attempt with Casting Player cancelled by the Casting Client/Commissionee user. \n\nRoute back to exit. \n\n");
381-
MatterError err = targetCastingPlayer.stopConnecting();
382-
if (err.hasError()) {
383-
MatterError finalErr = err;
384-
getActivity()
385-
.runOnUiThread(
386-
() -> {
387-
connectionFragmentStatusTextView.setText(
388-
"Casting Player CANCEL failed due to: " + finalErr + "\n\n");
389-
});
390-
Log.e(TAG, "displayPasscodeInputDialog() stopConnecting() failed due to: " + err);
391-
}
373+
"Connection attempt with Casting Player cancelled by the Casting Client/Commissionee user. \n\nRoute back to disconnect & exit. \n\n");
392374
dialog.cancel();
393375
}
394376
});

examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/CastingPlayer.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
* about the service discovered/resolved.
3030
*/
3131
public interface CastingPlayer {
32+
33+
public enum ConnectionState {
34+
NOT_CONNECTED,
35+
CONNECTING,
36+
CONNECTED,
37+
}
38+
3239
boolean isConnected();
3340

3441
String getDeviceId();
@@ -157,5 +164,7 @@ MatterError verifyOrEstablishConnection(
157164
* @return true if this CastingPlayer is still pending pass code from user and therefore is not
158165
* ready
159166
*/
160-
boolean isPendingPasscodeFromUser();
167+
ConnectionState getConnectionState();
168+
169+
String getConnectionStateNative();
161170
}

examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/core/MatterCastingPlayer.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333
public class MatterCastingPlayer implements CastingPlayer {
3434
private static final String TAG = MatterCastingPlayer.class.getSimpleName();
35+
3536
/**
3637
* Time (in sec) to keep the commissioning window open, if commissioning is required. Must be >= 3
3738
* minutes.
@@ -269,5 +270,9 @@ public MatterError continueConnecting() {
269270
public native void disconnect();
270271

271272
@Override
272-
public native boolean isPendingPasscodeFromUser();
273+
public ConnectionState getConnectionState() {
274+
return ConnectionState.valueOf(getConnectionStateNative());
275+
}
276+
277+
public native String getConnectionStateNative();
273278
}

examples/tv-casting-app/android/App/app/src/main/jni/cpp/core/MatterCastingPlayer-JNI.cpp

+18-4
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,30 @@ JNI_METHOD(void, disconnect)
165165
castingPlayer->Disconnect();
166166
}
167167

168-
JNI_METHOD(bool, isPendingPasscodeFromUser)
168+
JNI_METHOD(jstring, getConnectionStateNative)
169169
(JNIEnv * env, jobject thiz)
170170
{
171171
chip::DeviceLayer::StackLock lock;
172-
ChipLogProgress(AppServer, "MatterCastingPlayer-JNI::isPendingPasscodeFromUser()");
172+
ChipLogProgress(AppServer, "MatterCastingPlayer-JNI::getConnectionState()");
173173

174174
CastingPlayer * castingPlayer = support::convertCastingPlayerFromJavaToCpp(thiz);
175-
VerifyOrReturnValue(castingPlayer != nullptr, support::convertMatterErrorFromCppToJava(CHIP_ERROR_INVALID_ARGUMENT));
175+
VerifyOrReturnValue(castingPlayer != nullptr, env->NewStringUTF("Cast Player is nullptr"));
176176

177-
return castingPlayer->IsPendingPasscodeFromUser();
177+
matter::casting::core::ConnectionState state = castingPlayer->GetConnectionState();
178+
switch (state)
179+
{
180+
case matter::casting::core::ConnectionState::CASTING_PLAYER_NOT_CONNECTED:
181+
return env->NewStringUTF("NOT_CONNECTED");
182+
case matter::casting::core::ConnectionState::CASTING_PLAYER_CONNECTING:
183+
return env->NewStringUTF("CONNECTING");
184+
case matter::casting::core::ConnectionState::CASTING_PLAYER_CONNECTED:
185+
return env->NewStringUTF("CONNECTED");
186+
default: {
187+
char error_str[50];
188+
snprintf(error_str, sizeof(error_str), "Unsupported Connection State: %d", state);
189+
return env->NewStringUTF(error_str);
190+
}
191+
}
178192
}
179193

180194
JNI_METHOD(jobject, getEndpoints)

examples/tv-casting-app/tv-casting-common/core/CastingPlayer.h

-8
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,6 @@ class CastingPlayer : public std::enable_shared_from_this<CastingPlayer>
142142
*/
143143
bool IsConnected() const { return mConnectionState == CASTING_PLAYER_CONNECTED; }
144144

145-
/**
146-
* @return true if this CastingPlayer is still pending pass code from user and therefore is not ready
147-
*/
148-
bool IsPendingPasscodeFromUser() const
149-
{
150-
return mConnectionState == CASTING_PLAYER_CONNECTING && !mIdOptions.mCommissionerPasscodeReady;
151-
}
152-
153145
/**
154146
* @brief Verifies that a connection exists with this CastingPlayer, or triggers a new commissioning session request. If the
155147
* CastingApp does not have the nodeId and fabricIndex of this CastingPlayer cached on disk, this will execute the User Directed

0 commit comments

Comments
 (0)