Skip to content

Commit 8158442

Browse files
Android tv-casting-app: Endpoint API
1 parent d87e006 commit 8158442

30 files changed

+1225
-384
lines changed

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MainActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
import com.chip.casting.DiscoveredNodeData;
1111
import com.chip.casting.TvCastingApp;
1212
import com.chip.casting.util.GlobalCastingConstants;
13-
import com.chip.casting.util.PreferencesConfigurationManager;
1413
import com.matter.casting.ConnectionExampleFragment;
1514
import com.matter.casting.DiscoveryExampleFragment;
1615
import com.matter.casting.InitializationExample;
16+
import com.matter.casting.PreferencesConfigurationManager;
1717
import com.matter.casting.core.CastingPlayer;
1818
import java.util.Random;
1919

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/GlobalCastingConstants.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ public class GlobalCastingConstants {
66
public static final int SetupPasscode = 20202021;
77
public static final int Discriminator = 0xF00;
88
public static final boolean ChipCastingSimplified =
9-
false; // set this flag to true to demo simplified casting APIs
9+
true; // set this flag to true to demo simplified casting APIs
1010
}

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

+51-40
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
import androidx.fragment.app.Fragment;
2828
import com.R;
2929
import com.matter.casting.core.CastingPlayer;
30-
import com.matter.casting.support.DeviceTypeStruct;
3130
import com.matter.casting.support.EndpointFilter;
31+
import com.matter.casting.support.FailureCallback;
32+
import com.matter.casting.support.MatterError;
33+
import com.matter.casting.support.SuccessCallback;
3234
import java.util.ArrayList;
33-
import java.util.concurrent.CompletableFuture;
3435
import java.util.concurrent.Executors;
3536

3637
/** A {@link Fragment} to Verify or establish a connection with a selected Casting Player. */
@@ -39,6 +40,7 @@ public class ConnectionExampleFragment extends Fragment {
3940
// Time (in sec) to keep the commissioning window open, if commissioning is required.
4041
// Must be >= 3 minutes.
4142
private static final long MIN_CONNECTION_TIMEOUT_SEC = 3 * 60;
43+
private static final Integer DESIRED_ENDPOINT_VENDOR_ID = 65521;
4244
private final CastingPlayer targetCastingPlayer;
4345
private TextView connectionFragmentStatusTextView;
4446
private Button connectionFragmentNextButton;
@@ -81,7 +83,11 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
8183
connectionFragmentStatusTextView = getView().findViewById(R.id.connectionFragmentStatusText);
8284
connectionFragmentStatusTextView.setText(
8385
"Verifying or establishing connection with Casting Player with device name: "
84-
+ targetCastingPlayer.getDeviceName());
86+
+ targetCastingPlayer.getDeviceName()
87+
+ "\nSetup Passcode: "
88+
+ InitializationExample.commissionableDataProvider.get().getSetupPasscode()
89+
+ "\nDiscriminator: "
90+
+ InitializationExample.commissionableDataProvider.get().getDiscriminator());
8591

8692
connectionFragmentNextButton = getView().findViewById(R.id.connectionFragmentNextButton);
8793
Callback callback = (ConnectionExampleFragment.Callback) this.getActivity();
@@ -97,45 +103,50 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
97103
Log.d(TAG, "onViewCreated() calling verifyOrEstablishConnection()");
98104

99105
EndpointFilter desiredEndpointFilter =
100-
new EndpointFilter(null, 65521, new ArrayList<DeviceTypeStruct>());
101-
// The desired commissioning window timeout and EndpointFilter are optional.
102-
CompletableFuture<Void> completableFuture =
103-
targetCastingPlayer.VerifyOrEstablishConnection(
104-
MIN_CONNECTION_TIMEOUT_SEC, desiredEndpointFilter);
106+
new EndpointFilter(null, DESIRED_ENDPOINT_VENDOR_ID, new ArrayList<>());
105107

106-
Log.d(TAG, "onViewCreated() verifyOrEstablishConnection() called");
107-
108-
completableFuture
109-
.thenRun(
110-
() -> {
111-
Log.i(
112-
TAG,
113-
"CompletableFuture.thenRun(), connected to CastingPlayer with deviceId: "
114-
+ targetCastingPlayer.getDeviceId());
115-
getActivity()
116-
.runOnUiThread(
117-
() -> {
118-
connectionFragmentStatusTextView.setText(
119-
"Connected to Casting Player with device name: "
120-
+ targetCastingPlayer.getDeviceName());
121-
connectionFragmentNextButton.setEnabled(true);
122-
});
123-
})
124-
.exceptionally(
125-
exc -> {
126-
Log.e(
127-
TAG,
128-
"CompletableFuture.exceptionally(), CastingPLayer connection failed: "
129-
+ exc.getMessage());
130-
getActivity()
131-
.runOnUiThread(
132-
() -> {
133-
connectionFragmentStatusTextView.setText(
134-
"Casting Player connection failed due to: "
135-
+ exc.getMessage());
136-
});
137-
return null;
108+
MatterError err =
109+
targetCastingPlayer.verifyOrEstablishConnection(
110+
MIN_CONNECTION_TIMEOUT_SEC,
111+
desiredEndpointFilter,
112+
new SuccessCallback<Void>() {
113+
@Override
114+
public void handle(Void v) {
115+
Log.i(
116+
TAG,
117+
"Connected to CastingPlayer with deviceId: "
118+
+ targetCastingPlayer.getDeviceId());
119+
getActivity()
120+
.runOnUiThread(
121+
() -> {
122+
connectionFragmentStatusTextView.setText(
123+
"Connected to Casting Player with device name: "
124+
+ targetCastingPlayer.getDeviceName());
125+
connectionFragmentNextButton.setEnabled(true);
126+
});
127+
}
128+
},
129+
new FailureCallback() {
130+
@Override
131+
public void handle(MatterError err) {
132+
Log.e(TAG, "CastingPLayer connection failed: " + err);
133+
getActivity()
134+
.runOnUiThread(
135+
() -> {
136+
connectionFragmentStatusTextView.setText(
137+
"Casting Player connection failed due to: " + err);
138+
});
139+
}
138140
});
141+
142+
if (err.hasError()) {
143+
getActivity()
144+
.runOnUiThread(
145+
() -> {
146+
connectionFragmentStatusTextView.setText(
147+
"Casting Player connection failed due to: " + err);
148+
});
149+
}
139150
});
140151
}
141152

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import android.content.Context;
2020
import android.util.Log;
2121
import chip.platform.ConfigurationManager;
22-
import com.chip.casting.util.PreferencesConfigurationManager;
2322
import com.matter.casting.core.CastingApp;
2423
import com.matter.casting.support.AppParameters;
2524
import com.matter.casting.support.CommissionableData;
@@ -49,7 +48,7 @@ public byte[] get() {
4948
* DataProvider implementation for the Commissioning Data used by the SDK when the CastingApp goes
5049
* through commissioning
5150
*/
52-
private static final DataProvider<CommissionableData> commissionableDataProvider =
51+
static final DataProvider<CommissionableData> commissionableDataProvider =
5352
new DataProvider<CommissionableData>() {
5453
@Override
5554
public CommissionableData get() {

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/PreferencesConfigurationManager.java examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/PreferencesConfigurationManager.java

+109-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*
1717
*/
18-
package com.chip.casting.util;
18+
package com.matter.casting;
1919

2020
import android.content.Context;
2121
import android.content.SharedPreferences;
@@ -53,6 +53,41 @@ public PreferencesConfigurationManager(Context context, String preferenceFileKey
5353
public long readConfigValueLong(String namespace, String name)
5454
throws AndroidChipPlatformException {
5555
String key = getKey(namespace, name);
56+
switch (key) {
57+
/**
58+
* The unique id assigned by the device vendor to identify the product or device type. This
59+
* number is scoped to the device vendor id. return a different value than
60+
* src/include/platform/CHIPDeviceConfig.h for debug
61+
*/
62+
case kConfigNamespace_ChipFactory + ":" + kConfigKey_ProductId:
63+
return 0x8003;
64+
65+
/**
66+
* The default hardware version number assigned to the device or product by the device
67+
* vendor.
68+
*
69+
* <p>Hardware versions are specific to a particular device vendor and product id, and
70+
* typically correspond to a revision of the physical device, a change to its packaging,
71+
* and/or a change to its marketing presentation. This value is generally *not* incremented
72+
* for device software revisions.
73+
*
74+
* <p>This is a default value which is used when a hardware version has not been stored in
75+
* device persistent storage (e.g. by a factory provisioning process).
76+
*
77+
* <p>return a different value than src/include/platform/CHIPDeviceConfig.h for debug
78+
*/
79+
case kConfigNamespace_ChipFactory + ":" + kConfigKey_HardwareVersion:
80+
return 1;
81+
82+
/**
83+
* A monothonic number identifying the software version running on the device.
84+
*
85+
* <p>return a different value than src/include/platform/CHIPDeviceConfig.h for debug
86+
*/
87+
case kConfigNamespace_ChipFactory + ":" + kConfigKey_SoftwareVersion:
88+
return 1;
89+
}
90+
5691
if (preferences.contains(key)) {
5792
long value = preferences.getLong(key, Long.MAX_VALUE);
5893
return value;
@@ -66,6 +101,79 @@ public long readConfigValueLong(String namespace, String name)
66101
public String readConfigValueStr(String namespace, String name)
67102
throws AndroidChipPlatformException {
68103
String key = getKey(namespace, name);
104+
105+
switch (key) {
106+
/**
107+
* Human readable name of the device model. return a different value than
108+
* src/include/platform/CHIPDeviceConfig.h for debug
109+
*/
110+
case kConfigNamespace_ChipFactory + ":" + kConfigKey_ProductName:
111+
return "TEST_ANDROID_PRODUCT";
112+
113+
/**
114+
* Human readable string identifying version of the product assigned by the device vendor.
115+
*
116+
* <p>return a different value than src/include/platform/CHIPDeviceConfig.h for debug
117+
*/
118+
case kConfigNamespace_ChipFactory + ":" + kConfigKey_HardwareVersionString:
119+
return "TEST_ANDROID_VERSION";
120+
121+
/**
122+
* A string identifying the software version running on the device.
123+
*
124+
* <p>return a different value than src/include/platform/CHIPDeviceConfig.h for debug
125+
*/
126+
case kConfigNamespace_ChipFactory + ":" + kConfigKey_SoftwareVersionString:
127+
return "prerelease(android)";
128+
129+
/**
130+
* The ManufacturingDate attribute SHALL specify the date that the Node was manufactured.
131+
* The first 8 characters SHALL specify the date of manufacture of the Node in international
132+
* date notation according to ISO 8601, i.e., YYYYMMDD, e.g., 20060814. The final 8
133+
* characters MAY include country, factory, line, shift or other related information at the
134+
* option of the vendor. The format of this information is vendor defined.
135+
*/
136+
case kConfigNamespace_ChipFactory + ":" + kConfigKey_ManufacturingDate:
137+
return "2021-12-06";
138+
139+
/**
140+
* Enables the use of a hard-coded default serial number if none * is found in Chip NV
141+
* storage.
142+
*
143+
* <p>return a different value than src/include/platform/CHIPDeviceConfig.h for debug
144+
*/
145+
case kConfigNamespace_ChipFactory + ":" + kConfigKey_SerialNum:
146+
return "TEST_ANDROID_SN";
147+
148+
/**
149+
* The PartNumber attribute SHALL specify a human-readable (displayable) vendor assigned
150+
* part number for the Node whose meaning and numbering scheme is vendor defined. Multiple
151+
* products (and hence PartNumbers) can share a ProductID. For instance, there may be
152+
* different packaging (with different PartNumbers) for different regions; also different
153+
* colors of a product might share the ProductID but may have a different PartNumber.
154+
*/
155+
case kConfigNamespace_ChipFactory + ":" + kConfigKey_PartNumber:
156+
return "TEST_ANDROID_PRODUCT_BLUE";
157+
158+
/**
159+
* The ProductURL attribute SHALL specify a link to a product specific web page. The syntax
160+
* of the ProductURL attribute SHALL follow the syntax as specified in RFC 3986. The
161+
* specified URL SHOULD resolve to a maintained web page available for the lifetime of the
162+
* product. The maximum length of the ProductUrl attribute is 256 ASCII characters.
163+
*/
164+
case kConfigNamespace_ChipFactory + ":" + kConfigKey_ProductURL:
165+
return "https://buildwithmatter.com/";
166+
167+
/**
168+
* The ProductLabel attribute SHALL specify a vendor specific human readable (displayable)
169+
* product label. The ProductLabel attribute MAY be used to provide a more user-friendly
170+
* value than that represented by the ProductName attribute. The ProductLabel attribute
171+
* SHOULD NOT include the name of the vendor as defined within the VendorName attribute.
172+
*/
173+
case kConfigNamespace_ChipFactory + ":" + kConfigKey_ProductLabel:
174+
return "X10";
175+
}
176+
69177
if (preferences.contains(key)) {
70178
String value = preferences.getString(key, null);
71179
return value;

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

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2020-2024 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
117
package com.matter.casting.core;
218

319
/** Represents the state of the CastingApp */

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

+15-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
package com.matter.casting.core;
1818

1919
import com.matter.casting.support.EndpointFilter;
20+
import com.matter.casting.support.FailureCallback;
21+
import com.matter.casting.support.MatterError;
22+
import com.matter.casting.support.SuccessCallback;
2023
import java.net.InetAddress;
2124
import java.util.List;
22-
import java.util.concurrent.CompletableFuture;
2325

2426
/**
2527
* The CastingPlayer interface defines a Matter commissioner that is able to play media to a
@@ -48,6 +50,8 @@ public interface CastingPlayer {
4850

4951
long getDeviceType();
5052

53+
List<Endpoint> getEndpoints();
54+
5155
@Override
5256
String toString();
5357

@@ -75,8 +79,11 @@ public interface CastingPlayer {
7579
* com.matter.casting.core.CastingException. If the VerifyOrEstablishConnection fails, the
7680
* CastingException will contain the error code and message from the CastingApp.
7781
*/
78-
CompletableFuture<Void> VerifyOrEstablishConnection(
79-
long commissioningWindowTimeoutSec, EndpointFilter desiredEndpointFilter);
82+
MatterError verifyOrEstablishConnection(
83+
long commissioningWindowTimeoutSec,
84+
EndpointFilter desiredEndpointFilter,
85+
SuccessCallback<Void> successCallback,
86+
FailureCallback failureCallback);
8087

8188
/**
8289
* Verifies that a connection exists with this CastingPlayer, or triggers a new session request.
@@ -90,5 +97,9 @@ CompletableFuture<Void> VerifyOrEstablishConnection(
9097
* com.matter.casting.core.CastingException. If the VerifyOrEstablishConnection fails, the
9198
* CastingException will contain the error code and message from the CastingApp.
9299
*/
93-
CompletableFuture<Void> VerifyOrEstablishConnection();
100+
MatterError verifyOrEstablishConnection(
101+
SuccessCallback<Void> successCallback, FailureCallback failureCallback);
102+
103+
/** @brief Sets the internal connection state of this CastingPlayer to "disconnected" */
104+
void disconnect();
94105
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2020-24 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.matter.casting.core;
19+
20+
import com.matter.casting.support.DeviceTypeStruct;
21+
import java.util.List;
22+
23+
public interface Endpoint {
24+
int getId();
25+
26+
int getVendorId();
27+
28+
int getProductId();
29+
30+
List<DeviceTypeStruct> getDeviceTypeList();
31+
32+
CastingPlayer getCastingPlayer();
33+
}

0 commit comments

Comments
 (0)