Skip to content

Commit d179e92

Browse files
[Amazon] StopConnect for UDC in Android tv-casting-app
Updated JNI and Android tv-casting-app to use CharToStringUTF util function to create jstring and handle NULL JNIEnv interface Changes * JNI to use CharToStringUTF util function to create jstring * Updated documentation for new JNI functions 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 e1c6340 commit d179e92

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@
3030
*/
3131
public interface CastingPlayer {
3232

33+
/** @brief CastingPlayer's Conenction State */
3334
public enum ConnectionState {
35+
/** State when CastingPlayer is not connected */
3436
NOT_CONNECTED,
37+
38+
/** State when CastingPlayer is attempting to connect */
3539
CONNECTING,
40+
41+
/** State when CastingPlayer is connnected */
3642
CONNECTED,
3743
}
3844

@@ -161,10 +167,14 @@ MatterError verifyOrEstablishConnection(
161167
void disconnect();
162168

163169
/**
164-
* @return true if this CastingPlayer is still pending pass code from user and therefore is not
165-
* ready
170+
* @brief Get CastingPlayer's current ConnectionState.
171+
* @return Current ConnectionState.
166172
*/
167173
ConnectionState getConnectionState();
168174

175+
/**
176+
* @brief Get the Current ConnectionState of a CastingPlayer from the native layer.
177+
* @returns A String representation of the CastingPlayer's current connectation.
178+
*/
169179
String getConnectionStateNative();
170180
}

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

+17
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,27 @@ public MatterError continueConnecting() {
269269
@Override
270270
public native void disconnect();
271271

272+
/**
273+
* @brief Get CastingPlayer's current ConnectionState.
274+
* @throws IllegalArgumentException or NullPointerException when native layer returns invalid
275+
* state.
276+
* @return Current ConnectionState.
277+
*/
272278
@Override
273279
public ConnectionState getConnectionState() {
274280
return ConnectionState.valueOf(getConnectionStateNative());
275281
}
276282

283+
/*
284+
* @brief Get the Current ConnectionState of a CastingPlayer from the native layer.
285+
*
286+
* @returns A String representation of the CastingPlayer's current connectation.
287+
* Possible return values are
288+
* - "NOT_CONNECTED"
289+
* - "CONNECTING"
290+
* - "CONNECTED"
291+
* - Error message or NULL on error
292+
*/
293+
@Override
277294
public native String getConnectionStateNative();
278295
}

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ JNI_METHOD(void, disconnect)
168168
JNI_METHOD(jstring, getConnectionStateNative)
169169
(JNIEnv * env, jobject thiz)
170170
{
171+
if (NULL == env)
172+
{
173+
jobject err_jstr = nullptr;
174+
LogErrorOnFailure(
175+
chip::JniReferences::GetInstance().CharToStringUTF(CharSpan::fromCharString("JNIEnv interface is NULL"), err_jstr));
176+
return static_cast<jstring>(err_jstr);
177+
}
178+
171179
chip::DeviceLayer::StackLock lock;
172180
ChipLogProgress(AppServer, "MatterCastingPlayer-JNI::getConnectionState()");
173181

@@ -186,7 +194,10 @@ JNI_METHOD(jstring, getConnectionStateNative)
186194
default: {
187195
char error_str[50];
188196
snprintf(error_str, sizeof(error_str), "Unsupported Connection State: %d", state);
189-
return env->NewStringUTF(error_str);
197+
198+
jobject err_jstr = nullptr;
199+
LogErrorOnFailure(chip::JniReferences::GetInstance().CharToStringUTF(CharSpan::fromCharString(error_str), err_jstr));
200+
return static_cast<jstring>(err_jstr);
190201
}
191202
}
192203
}

0 commit comments

Comments
 (0)