Skip to content

Commit 7891bd3

Browse files
tv-casting-app CDC message CancelPasscode and ErrorCode iOS/Android sample-app UX updates
1 parent bb9363d commit 7891bd3

File tree

8 files changed

+218
-114
lines changed

8 files changed

+218
-114
lines changed

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

+51-27
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ public class ConnectionExampleFragment extends Fragment {
5454
private final CastingPlayer targetCastingPlayer;
5555
private final boolean useCommissionerGeneratedPasscode;
5656
private TextView connectionFragmentStatusTextView;
57+
private TextView commissionerDeclarationErrorTextView;
5758
private Button connectionFragmentNextButton;
59+
private AlertDialog passcodeDialog;
5860

5961
public ConnectionExampleFragment(
6062
CastingPlayer targetCastingPlayer, boolean useCommissionerGeneratedPasscode) {
@@ -100,6 +102,8 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
100102
Log.i(TAG, "onViewCreated()");
101103

102104
connectionFragmentStatusTextView = getView().findViewById(R.id.connectionFragmentStatusText);
105+
commissionerDeclarationErrorTextView =
106+
getView().findViewById(R.id.commissionerDeclarationErrorTextView);
103107
if (useCommissionerGeneratedPasscode) {
104108
connectionFragmentStatusTextView.setText(
105109
"Verifying or establishing connection with Casting Player with device name: "
@@ -190,32 +194,52 @@ public void handle(MatterError err) {
190194
},
191195
null);
192196

193-
// CommissionerDeclaration is only needed for the CastingPlayer/Commissioner-Generated
194-
// passcode commissioning flow.
195-
if (useCommissionerGeneratedPasscode) {
196-
connectionCallbacks.onCommissionerDeclaration =
197-
new MatterCallback<CommissionerDeclaration>() {
198-
@Override
199-
public void handle(CommissionerDeclaration cd) {
200-
Log.i(TAG, "CastingPlayer CommissionerDeclaration message received: ");
201-
cd.logDetail();
202-
203-
getActivity()
204-
.runOnUiThread(
205-
() -> {
206-
connectionFragmentStatusTextView.setText(
207-
"CommissionerDeclaration message received from Casting Player: \n\n");
208-
if (cd.getCommissionerPasscode()) {
209-
210-
displayPasscodeInputDialog(getActivity());
197+
// The CommissionerDeclaration callback is optional and only needed for the
198+
// CastingPlayer/Commissioner-Generated
199+
// passcode commissioning flow. However, if we want to know when the
200+
// CastingPlayer/Commissioner user
201+
// has cancelled the connection attempt when using the Client/Commissionee generated
202+
// passcode flow, then we
203+
// need to implement this callback.
204+
connectionCallbacks.onCommissionerDeclaration =
205+
new MatterCallback<CommissionerDeclaration>() {
206+
@Override
207+
public void handle(CommissionerDeclaration cd) {
208+
Log.i(TAG, "CastingPlayer CommissionerDeclaration message received: ");
209+
cd.logDetail();
210+
211+
getActivity()
212+
.runOnUiThread(
213+
() -> {
214+
connectionFragmentStatusTextView.setText(
215+
"CommissionerDeclaration message received from Casting Player: \n\n");
216+
if (cd.getCommissionerPasscode()) {
217+
218+
displayPasscodeInputDialog(getActivity());
211219

220+
connectionFragmentStatusTextView.setText(
221+
"CommissionerDeclaration message received from Casting Player: A passcode is now displayed for the user by the Casting Player. \n\n");
222+
}
223+
if (cd.getCancelPasscode()) {
224+
if (useCommissionerGeneratedPasscode) {
212225
connectionFragmentStatusTextView.setText(
213-
"CommissionerDeclaration message received from Casting Player: A passcode is now displayed for the user by the Casting Player. \n\n");
226+
"CastingPlayer/Commissioner-Generated passcode connection attempt cancelled by the CastingPlayer/Commissioner user. \n\nRoute back to exit. \n\n");
227+
} else {
228+
connectionFragmentStatusTextView.setText(
229+
"Connection attempt cancelled by the CastingPlayer/Commissioner user. \n\nRoute back to exit. \n\n");
214230
}
215-
});
216-
}
217-
};
218-
}
231+
if (passcodeDialog != null && passcodeDialog.isShowing()) {
232+
passcodeDialog.dismiss();
233+
}
234+
}
235+
if (cd.getErrorCode() != CommissionerDeclaration.CdError.noError) {
236+
commissionerDeclarationErrorTextView.setText(
237+
"CastingPlayer/Commissioner Error: "
238+
+ cd.getErrorCode().toString());
239+
}
240+
});
241+
}
242+
};
219243

220244
MatterError err =
221245
targetCastingPlayer.verifyOrEstablishConnection(
@@ -331,7 +355,7 @@ public void onClick(DialogInterface dialog, int which) {
331355
TAG,
332356
"displayPasscodeInputDialog() user cancelled the CastingPlayer/Commissioner-Generated Passcode input dialog. Calling stopConnecting()");
333357
connectionFragmentStatusTextView.setText(
334-
"Connection attempt with Casting Player cancelled by the user, route back to exit. \n\n");
358+
"Connection attempt with Casting Player cancelled by the Casting Client/Commissionee user. \n\nRoute back to exit. \n\n");
335359
MatterError err = targetCastingPlayer.stopConnecting();
336360
if (err.hasError()) {
337361
MatterError finalErr = err;
@@ -348,9 +372,9 @@ public void onClick(DialogInterface dialog, int which) {
348372
});
349373

350374
builder.setView(dialogView);
351-
AlertDialog alertDialog = builder.create();
352-
alertDialog.show();
353-
alertDialog
375+
passcodeDialog = builder.create(); // Store the dialog instance in the passcodeDialog variable
376+
passcodeDialog.show();
377+
passcodeDialog
354378
.getWindow()
355379
.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
356380
}

examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/CommissionerDeclaration.java

+40-23
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,30 @@
2222
public class CommissionerDeclaration {
2323
static final String TAG = CommissionerDeclaration.class.getSimpleName();
2424

25-
/** The allowed values for the ErrorCode field are the following */
25+
/**
26+
* The allowed values for the ErrorCode field are the following. Indicates errors incurred during
27+
* commissioning.
28+
*/
2629
public enum CdError {
27-
kNoError(0),
28-
kCommissionableDiscoveryFailed(1),
29-
kPaseConnectionFailed(2),
30-
kPaseAuthFailed(3),
31-
kDacValidationFailed(4),
32-
kAlreadyOnFabric(5),
33-
kOperationalDiscoveryFailed(6),
34-
kCaseConnectionFailed(7),
35-
kCaseAuthFailed(8),
36-
kConfigurationFailed(9),
37-
kBindingConfigurationFailed(10),
38-
kCommissionerPasscodeNotSupported(11),
39-
kInvalidIdentificationDeclarationParams(12),
40-
kAppInstallConsentPending(13),
41-
kAppInstalling(14),
42-
kAppInstallFailed(15),
43-
kAppInstalledRetryNeeded(16),
44-
kCommissionerPasscodeDisabled(17),
45-
kUnexpectedCommissionerPasscodeReady(18);
30+
noError(0),
31+
commissionableDiscoveryFailed(1),
32+
paseConnectionFailed(2),
33+
paseAuthFailed(3),
34+
dacValidationFailed(4),
35+
alreadyOnFabric(5),
36+
operationalDiscoveryFailed(6),
37+
caseConnectionFailed(7),
38+
caseAuthFailed(8),
39+
configurationFailed(9),
40+
bindingConfigurationFailed(10),
41+
commissionerPasscodeNotSupported(11),
42+
invalidIdentificationDeclarationParams(12),
43+
appInstallConsentPending(13),
44+
appInstalling(14),
45+
appInstallFailed(15),
46+
appInstalledRetryNeeded(16),
47+
commissionerPasscodeDisabled(17),
48+
unexpectedCommissionerPasscodeReady(18);
4649
private final int value;
4750

4851
CdError(int value) {
@@ -54,7 +57,7 @@ public int getValue() {
5457
}
5558
}
5659
/** Feature: All - Indicates errors incurred during commissioning. */
57-
private CdError errorCode = CdError.kNoError;
60+
private CdError errorCode = CdError.noError;
5861
/**
5962
* Feature: Coordinate PIN Dialogs - When NoPasscode field set to true, and the Commissioner
6063
* determines that a Passcode code will be needed for commissioning.
@@ -81,20 +84,27 @@ public int getValue() {
8184
* also displays a QR code.
8285
*/
8386
private boolean qRCodeDisplayed = false;
87+
/**
88+
* Feature: Commissioner-Generated Passcode - Flag to indicate when the CastingplAYER/Commissioner
89+
* user has decided to exit the commissioning process.
90+
*/
91+
private boolean cancelPasscode = false;
8492

8593
public CommissionerDeclaration(
8694
int errorCode,
8795
boolean needsPasscode,
8896
boolean noAppsFound,
8997
boolean passcodeDialogDisplayed,
9098
boolean commissionerPasscode,
91-
boolean qRCodeDisplayed) {
99+
boolean qRCodeDisplayed,
100+
boolean cancelPasscode) {
92101
this.errorCode = CdError.values()[errorCode];
93102
this.needsPasscode = needsPasscode;
94103
this.noAppsFound = noAppsFound;
95104
this.passcodeDialogDisplayed = passcodeDialogDisplayed;
96105
this.commissionerPasscode = commissionerPasscode;
97106
this.qRCodeDisplayed = qRCodeDisplayed;
107+
this.cancelPasscode = cancelPasscode;
98108
}
99109

100110
public void setErrorCode(CdError errorCode) {
@@ -145,6 +155,10 @@ public boolean getQRCodeDisplayed() {
145155
return this.qRCodeDisplayed;
146156
}
147157

158+
public boolean getCancelPasscode() {
159+
return this.cancelPasscode;
160+
}
161+
148162
@Override
149163
public String toString() {
150164
return "CommissionerDeclaration::errorCode: "
@@ -163,7 +177,10 @@ public String toString() {
163177
+ commissionerPasscode
164178
+ "\n"
165179
+ "CommissionerDeclaration::qRCodeDisplayed: "
166-
+ qRCodeDisplayed;
180+
+ qRCodeDisplayed
181+
+ "\n"
182+
+ "CommissionerDeclaration::cancelPasscode: "
183+
+ cancelPasscode;
167184
}
168185

169186
public void logDetail() {

examples/tv-casting-app/android/App/app/src/main/jni/cpp/support/Converters-JNI.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ convertCommissionerDeclarationFromCppToJava(const chip::Protocols::UserDirectedC
528528
jCommissionerDeclarationClass);
529529
VerifyOrReturnValue(err == CHIP_NO_ERROR, nullptr);
530530

531-
jmethodID jCommissionerDeclarationConstructor = env->GetMethodID(jCommissionerDeclarationClass, "<init>", "(IZZZZZ)V");
531+
jmethodID jCommissionerDeclarationConstructor = env->GetMethodID(jCommissionerDeclarationClass, "<init>", "(IZZZZZZ)V");
532532
if (jCommissionerDeclarationConstructor == nullptr)
533533
{
534534
ChipLogError(AppServer,
@@ -539,7 +539,8 @@ convertCommissionerDeclarationFromCppToJava(const chip::Protocols::UserDirectedC
539539

540540
return env->NewObject(jCommissionerDeclarationClass, jCommissionerDeclarationConstructor,
541541
static_cast<jint>(cppCd.GetErrorCode()), cppCd.GetNeedsPasscode(), cppCd.GetNoAppsFound(),
542-
cppCd.GetPasscodeDialogDisplayed(), cppCd.GetCommissionerPasscode(), cppCd.GetQRCodeDisplayed());
542+
cppCd.GetPasscodeDialogDisplayed(), cppCd.GetCommissionerPasscode(), cppCd.GetQRCodeDisplayed(),
543+
cppCd.GetCancelPasscode());
543544
}
544545

545546
}; // namespace support

examples/tv-casting-app/android/App/app/src/main/res/layout/fragment_matter_connection_example.xml

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@
2828
android:layout_width="match_parent"
2929
android:layout_height="wrap_content"
3030
android:text="@string/matter_connection_next_button_text" />
31+
32+
<!-- TextView for CommissionerDeclaration errors -->
33+
<TextView
34+
android:id="@+id/commissionerDeclarationErrorTextView"
35+
android:layout_width="wrap_content"
36+
android:layout_height="wrap_content"
37+
android:textSize="18sp"
38+
android:textColor="@android:color/holo_red_dark"
39+
android:layout_gravity="center_horizontal"
40+
android:layout_marginTop="20dp"
41+
android:text=""/>
3142

3243
</LinearLayout>
3344

examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCommissionerDeclaration.h

+34-21
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,29 @@
2525
*/
2626
@interface MCCommissionerDeclaration : NSObject
2727

28-
/** The allowed values for the ErrorCode field are the following */
28+
/** The allowed values for the ErrorCode field are the following. Indicates errors incurred
29+
* during commissioning.
30+
*/
2931
typedef NS_ENUM(NSInteger, CdError) {
30-
kNoError = 0,
31-
kCommissionableDiscoveryFailed = 1,
32-
kPaseConnectionFailed = 2,
33-
kPaseAuthFailed = 3,
34-
kDacValidationFailed = 4,
35-
kAlreadyOnFabric = 5,
36-
kOperationalDiscoveryFailed = 6,
37-
kCaseConnectionFailed = 7,
38-
kCaseAuthFailed = 8,
39-
kConfigurationFailed = 9,
40-
kBindingConfigurationFailed = 10,
41-
kCommissionerPasscodeNotSupported = 11,
42-
kInvalidIdentificationDeclarationParams = 12,
43-
kAppInstallConsentPending = 13,
44-
kAppInstalling = 14,
45-
kAppInstallFailed = 15,
46-
kAppInstalledRetryNeeded = 16,
47-
kCommissionerPasscodeDisabled = 17,
48-
kUnexpectedCommissionerPasscodeReady = 18
32+
noError = 0,
33+
commissionableDiscoveryFailed = 1,
34+
paseConnectionFailed = 2,
35+
paseAuthFailed = 3,
36+
dacValidationFailed = 4,
37+
alreadyOnFabric = 5,
38+
operationalDiscoveryFailed = 6,
39+
caseConnectionFailed = 7,
40+
caseAuthFailed = 8,
41+
configurationFailed = 9,
42+
bindingConfigurationFailed = 10,
43+
commissionerPasscodeNotSupported = 11,
44+
invalidIdentificationDeclarationParams = 12,
45+
appInstallConsentPending = 13,
46+
appInstalling = 14,
47+
appInstallFailed = 15,
48+
appInstalledRetryNeeded = 16,
49+
commissionerPasscodeDisabled = 17,
50+
unexpectedCommissionerPasscodeReady = 18
4951
};
5052

5153
/** Feature: All - Indicates errors incurred during commissioning. */
@@ -76,13 +78,24 @@ typedef NS_ENUM(NSInteger, CdError) {
7678
* also displays a QR code.
7779
*/
7880
@property (nonatomic, readonly) BOOL qRCodeDisplayed;
81+
/**
82+
* Feature: Commissioner-Generated Passcode - Flag to indicate when the CastingplAYER/Commissioner
83+
* user has decided to exit the commissioning process.
84+
*/
85+
@property (nonatomic, readonly) BOOL cancelPasscode;
7986

8087
- (instancetype)initWithOptions:(NSInteger)errorCode
8188
needsPasscode:(BOOL)needsPasscode
8289
noAppsFound:(BOOL)noAppsFound
8390
passcodeDialogDisplayed:(BOOL)passcodeDialogDisplayed
8491
commissionerPasscode:(BOOL)commissionerPasscode
85-
qRCodeDisplayed:(BOOL)qRCodeDisplayed;
92+
qRCodeDisplayed:(BOOL)qRCodeDisplayed
93+
cancelPasscode:(BOOL)cancelPasscode;
94+
95+
/**
96+
* Function to return the error code as a string.
97+
*/
98+
- (NSString *)getErrorCodeString;
8699

87100
- (NSString *)description;
88101
- (void)logDetail;

0 commit comments

Comments
 (0)