Skip to content

Commit 4672e1a

Browse files
tv-casting-app updated APIs.md docs with new v1.3 Matter APIs (#34093)
* tv-casting-app updated APIs.md docs with new v1.3 Matter APIs * Fixing spelling error * Addressed comments by sharadb-amazon * Addressed comments by sharadb-amazon2
1 parent a11a9e4 commit 4672e1a

File tree

7 files changed

+572
-143
lines changed

7 files changed

+572
-143
lines changed

examples/tv-casting-app/APIs.md

+412-97
Large diffs are not rendered by default.

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

+18-16
Original file line numberDiff line numberDiff line change
@@ -128,24 +128,26 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
128128
() -> {
129129
Log.d(TAG, "onViewCreated() calling CastingPlayer.verifyOrEstablishConnection()");
130130

131-
IdentificationDeclarationOptions idOptions = new IdentificationDeclarationOptions();
132-
TargetAppInfo targetAppInfo = new TargetAppInfo();
133-
targetAppInfo.vendorId = DESIRED_TARGET_APP_VENDOR_ID;
131+
IdentificationDeclarationOptions idOptions;
132+
TargetAppInfo targetAppInfo = new TargetAppInfo(DESIRED_TARGET_APP_VENDOR_ID);
134133

135134
if (useCommissionerGeneratedPasscode) {
136-
idOptions.commissionerPasscode = true;
137-
targetAppInfo.vendorId = DESIRED_TARGET_APP_VENDOR_ID_FOR_CGP_FLOW;
135+
// Set commissionerPasscode to true for CastingPlayer/Commissioner-Generated
136+
// passcode commissioning.
137+
idOptions = new IdentificationDeclarationOptions(false, false, true, false, false);
138+
targetAppInfo = new TargetAppInfo(DESIRED_TARGET_APP_VENDOR_ID_FOR_CGP_FLOW);
138139
Log.d(
139140
TAG,
140141
"onViewCreated() calling CastingPlayer.verifyOrEstablishConnection() Target Content Application Vendor ID: "
141-
+ targetAppInfo.vendorId
142+
+ targetAppInfo.getVendorId()
142143
+ ", useCommissionerGeneratedPasscode: "
143144
+ useCommissionerGeneratedPasscode);
144145
} else {
146+
idOptions = new IdentificationDeclarationOptions();
145147
Log.d(
146148
TAG,
147149
"onViewCreated() calling CastingPlayer.verifyOrEstablishConnection() Target Content Application Vendor ID: "
148-
+ targetAppInfo.vendorId);
150+
+ targetAppInfo.getVendorId());
149151
}
150152

151153
idOptions.addTargetAppInfo(targetAppInfo);
@@ -242,21 +244,21 @@ private void displayPasscodeInputDialog(Context context) {
242244
new DialogInterface.OnClickListener() {
243245
@Override
244246
public void onClick(DialogInterface dialog, int which) {
245-
String passcode = input.getText().toString();
247+
String userEnteredPasscode = input.getText().toString();
246248
Log.i(
247249
TAG,
248-
"displayPasscodeInputDialog() User entered CastingPlayer/Commissioner-Generated passcode: "
249-
+ passcode);
250+
"displayPasscodeInputDialog() user-entered CastingPlayer/Commissioner-Generated passcode: "
251+
+ userEnteredPasscode);
250252

251253
// Display the user entered passcode on the screen
252254
connectionFragmentStatusTextView.setText(
253-
"Continue Connecting with user entered CastingPlayer/Commissioner-Generated passcode: "
254-
+ passcode
255+
"Continue Connecting with user-entered CastingPlayer/Commissioner-Generated passcode: "
256+
+ userEnteredPasscode
255257
+ "\n\n");
256258

257259
long passcodeLongValue = DEFAULT_COMMISSIONER_GENERATED_PASSCODE;
258260
try {
259-
passcodeLongValue = Long.parseLong(passcode);
261+
passcodeLongValue = Long.parseLong(userEnteredPasscode);
260262
Log.i(
261263
TAG,
262264
"displayPasscodeInputDialog() User entered CastingPlayer/Commissioner-Generated passcode: "
@@ -268,12 +270,12 @@ public void onClick(DialogInterface dialog, int which) {
268270
+ nfe);
269271
connectionFragmentStatusTextView.setText(
270272
"User entered CastingPlayer/Commissioner-Generated passcode is not a valid integer: "
271-
+ passcode
273+
+ userEnteredPasscode
272274
+ "\n\n");
273275
}
274276

275-
// Update the CommissionableData DataProvider with the user entered
276-
// CastingPlayer/Commissioner-Generated setup passcode. This is mandatory for
277+
// Update the CommissionableData DataProvider with the user-entered
278+
// CastingPlayer / Commissioner-Generated setup passcode. This is mandatory for
277279
// Commissioner-Generated passcode commissioning since the commissioning session's PAKE
278280
// verifier needs to be updated with the entered passcode.
279281
InitializationExample.commissionableDataProvider.updateCommissionableDataSetupPasscode(

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828

2929
public class InitializationExample {
3030
private static final String TAG = InitializationExample.class.getSimpleName();
31-
// Dummy values for commissioning demonstration only. These are hard coded in the example tv-app:
32-
// connectedhomeip/examples/tv-app/tv-common/src/AppTv.cpp
33-
private static final long DUMMY_SETUP_PASSCODE = 20202021;
34-
private static final int DUMMY_DISCRIMINATOR = 3874;
3531

3632
/**
3733
* DataProvider implementation for the Unique ID that is used by the SDK to generate the Rotating
@@ -53,6 +49,12 @@ public byte[] get() {
5349
* through commissioning
5450
*/
5551
public static class CommissionableDataProvider implements DataProvider<CommissionableData> {
52+
// Dummy values for commissioning demonstration only. These are hard coded in the example
53+
// tv-app:
54+
// connectedhomeip/examples/tv-app/tv-common/src/AppTv.cpp
55+
private static final long DUMMY_SETUP_PASSCODE = 20202021;
56+
private static final int DUMMY_DISCRIMINATOR = 3874;
57+
5658
CommissionableData commissionableData =
5759
new CommissionableData(DUMMY_SETUP_PASSCODE, DUMMY_DISCRIMINATOR);
5860

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

+37-13
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,29 @@ public class IdentificationDeclarationOptions {
2727
private final short CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS =
2828
getChipDeviceConfigUdcMaxTargetApps();
2929

30+
/** Default constructor. */
3031
public IdentificationDeclarationOptions() {}
3132

33+
/**
34+
* Constructor to set all fields.
35+
*
36+
* @param noPasscode the no passcode flag.
37+
* @param cdUponPasscodeDialog the cd upon passcode dialog flag.
38+
* @param commissionerPasscode the commissioner passcode flag.
39+
* @param commissionerPasscodeReady the commissioner passcode ready flag.
40+
* @param cancelPasscode the cancel passcode flag.
41+
*/
3242
public IdentificationDeclarationOptions(
3343
boolean noPasscode,
3444
boolean cdUponPasscodeDialog,
3545
boolean commissionerPasscode,
3646
boolean commissionerPasscodeReady,
37-
boolean cancelPasscode,
38-
List<TargetAppInfo> targetAppInfos) {
47+
boolean cancelPasscode) {
3948
this.noPasscode = noPasscode;
4049
this.cdUponPasscodeDialog = cdUponPasscodeDialog;
4150
this.commissionerPasscode = commissionerPasscode;
4251
this.commissionerPasscodeReady = commissionerPasscodeReady;
4352
this.cancelPasscode = cancelPasscode;
44-
this.targetAppInfos = targetAppInfos != null ? targetAppInfos : new ArrayList<>();
4553
}
4654

4755
/**
@@ -57,28 +65,28 @@ public IdentificationDeclarationOptions(
5765
* Passcode input dialog, and instead send a CommissionerDeclaration message if a commissioning
5866
* Passcode is needed.
5967
*/
60-
public boolean noPasscode = false;
68+
private boolean noPasscode = false;
6169
/**
6270
* Feature: Coordinate Passcode Dialogs - Flag to instruct the Commissioner to send a
6371
* CommissionerDeclaration message when the Passcode input dialog on the Commissioner has been
6472
* shown to the user.
6573
*/
66-
public boolean cdUponPasscodeDialog = false;
74+
private boolean cdUponPasscodeDialog = false;
6775
/**
6876
* Feature: Commissioner-Generated Passcode - Flag to instruct the Commissioner to use the
6977
* Commissioner-generated Passcode for commissioning.
7078
*/
71-
public boolean commissionerPasscode = false;
79+
private boolean commissionerPasscode = false;
7280
/**
7381
* Feature: Commissioner-Generated Passcode - Flag to indicate whether or not the Commissionee has
7482
* obtained the Commissioner Passcode from the user and is therefore ready for commissioning.
7583
*/
76-
public boolean commissionerPasscodeReady = false;
84+
private boolean commissionerPasscodeReady = false;
7785
/**
7886
* Feature: Coordinate Passcode Dialogs Flag - to indicate when the Commissionee user has decided
7987
* to exit the commissioning process.
8088
*/
81-
public boolean cancelPasscode = false;
89+
private boolean cancelPasscode = false;
8290
/**
8391
* Feature: Target Content Application - The set of content app Vendor IDs (and optionally,
8492
* Product IDs) that can be used for authentication. Also, if TargetAppInfo is passed in,
@@ -104,6 +112,26 @@ public boolean addTargetAppInfo(TargetAppInfo targetAppInfo) {
104112
return true;
105113
}
106114

115+
public boolean isNoPasscode() {
116+
return noPasscode;
117+
}
118+
119+
public boolean isCdUponPasscodeDialog() {
120+
return cdUponPasscodeDialog;
121+
}
122+
123+
public boolean isCommissionerPasscode() {
124+
return commissionerPasscode;
125+
}
126+
127+
public boolean isCommissionerPasscodeReady() {
128+
return commissionerPasscodeReady;
129+
}
130+
131+
public boolean isCancelPasscode() {
132+
return cancelPasscode;
133+
}
134+
107135
public List<TargetAppInfo> getTargetAppInfoList() {
108136
return targetAppInfos;
109137
}
@@ -129,11 +157,7 @@ public String toString() {
129157
sb.append("IdentificationDeclarationOptions::targetAppInfos list: \n");
130158

131159
for (TargetAppInfo targetAppInfo : targetAppInfos) {
132-
sb.append("\t\tTargetAppInfo - Vendor ID: ")
133-
.append(targetAppInfo.vendorId)
134-
.append(", Product ID: ")
135-
.append(targetAppInfo.productId)
136-
.append("\n");
160+
sb.append("\t\t").append(targetAppInfo).append("\n");
137161
}
138162

139163
return sb.toString();

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

+50-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,55 @@
1919
*/
2020
public class TargetAppInfo {
2121
/** Target Target Content Application Vendor ID, null means unspecified */
22-
public Integer vendorId;
22+
private Integer vendorId;
2323
/** Target Target Content Application Product ID, null means unspecified */
24-
public Integer productId;
24+
private Integer productId;
25+
26+
/**
27+
* Constructor to set both vendorId and productId.
28+
*
29+
* @param vendorId the vendor ID, null means unspecified.
30+
* @param productId the product ID, null means unspecified.
31+
*/
32+
public TargetAppInfo(Integer vendorId, Integer productId) {
33+
this.vendorId = vendorId;
34+
this.productId = productId;
35+
}
36+
37+
/**
38+
* Constructor to set only the vendorId.
39+
*
40+
* @param vendorId the vendor ID, null means unspecified.
41+
*/
42+
public TargetAppInfo(Integer vendorId) {
43+
this.vendorId = vendorId;
44+
}
45+
46+
/**
47+
* Getter for vendorId.
48+
*
49+
* @return the vendor ID, null means unspecified.
50+
*/
51+
public Integer getVendorId() {
52+
return vendorId;
53+
}
54+
55+
/**
56+
* Getter for productId.
57+
*
58+
* @return the product ID, null means unspecified.
59+
*/
60+
public Integer getProductId() {
61+
return productId;
62+
}
63+
64+
/**
65+
* Returns a string representation of the object.
66+
*
67+
* @return a string representation of the object.
68+
*/
69+
@Override
70+
public String toString() {
71+
return "TargetAppInfo Vendor ID:" + vendorId + ", Product ID:" + productId;
72+
}
2573
}

examples/tv-casting-app/darwin/TvCasting/TvCasting/MCConnectionExampleViewModel.swift

+24-6
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class MCConnectionExampleViewModel: ObservableObject {
6767
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, calling getTopMostViewController()")
6868
if let topViewController = self.getTopMostViewController() {
6969
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, calling displayPasscodeInputDialog()")
70-
self.displayPasscodeInputDialog(on: topViewController, continueConnecting: { passcode in
71-
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, Continuing to connect with user entered MCCastingPlayer/Commissioner-Generated passcode: \(passcode)")
70+
self.displayPasscodeInputDialog(on: topViewController, continueConnecting: { userEnteredPasscode in
71+
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, Continuing to connect with user entered MCCastingPlayer/Commissioner-Generated passcode: \(userEnteredPasscode)")
7272

7373
// Update the CommissionableData in the client defined MCAppParametersDataSource with the user
7474
// entered CastingPlayer/Commissioner-Generated setup passcode. This is mandatory for the
@@ -79,26 +79,44 @@ class MCConnectionExampleViewModel: ObservableObject {
7979
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback calling MCInitializationExample.getAppParametersDataSource()")
8080
if let dataSource = initializationExample.getAppParametersDataSource() {
8181
let newCommissionableData = MCCommissionableData(
82-
passcode: UInt32(passcode) ?? 0,
82+
passcode: UInt32(userEnteredPasscode) ?? 0,
8383
discriminator: 0,
8484
spake2pIterationCount: 1000,
8585
spake2pVerifier: nil,
8686
spake2pSalt: nil
8787
)
8888
dataSource.update(newCommissionableData)
89-
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, Updated MCAppParametersDataSource instance with new MCCommissionableData.")
89+
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, Updated MCAppParametersDataSource instance with new MCCommissionableData.")
9090
} else {
91-
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, InitializationExample.getAppParametersDataSource() failed")
91+
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, InitializationExample.getAppParametersDataSource() failed, calling stopConnecting()")
9292
self.connectionStatus = "Failed to update the MCAppParametersDataSource with the user entered passcode: \n\nRoute back and try again."
93+
self.connectionSuccess = false
94+
// Since we failed to update the passcode, Attempt to cancel the connection attempt with
95+
// the CastingPlayer/Commissioner.
96+
let err = selectedCastingPlayer?.stopConnecting()
97+
if err == nil {
98+
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, InitializationExample.getAppParametersDataSource() failed, then stopConnecting() succeeded")
99+
} else {
100+
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, InitializationExample.getAppParametersDataSource() failed, then stopConnecting() failed due to: \(err)")
101+
}
102+
return
93103
}
94104

95105
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, calling MCCastingPlayer.continueConnecting()")
96106
let errContinue = selectedCastingPlayer?.continueConnecting()
97107
if errContinue == nil {
98-
self.connectionStatus = "Continuing to connect with user entered passcode: \(passcode)"
108+
self.connectionStatus = "Continuing to connect with user entered passcode: \(userEnteredPasscode)"
99109
} else {
100110
self.connectionStatus = "Continue Connecting to Casting Player failed with: \(String(describing: errContinue)) \n\nRoute back and try again."
101111
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, MCCastingPlayer.continueConnecting() failed due to: \(errContinue)")
112+
// Since continueConnecting() failed, Attempt to cancel the connection attempt with
113+
// the CastingPlayer/Commissioner.
114+
let err = selectedCastingPlayer?.stopConnecting()
115+
if err == nil {
116+
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, MCCastingPlayer.continueConnecting() failed, then stopConnecting() succeeded")
117+
} else {
118+
self.Log.error("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, MCCastingPlayer.continueConnecting() failed, then stopConnecting() failed due to: \(err)")
119+
}
102120
}
103121
}, cancelConnecting: {
104122
self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, Connection attempt cancelled by the user, calling MCCastingPlayer.stopConnecting()")

0 commit comments

Comments
 (0)