From dd8b002e7e65d3f6b1f1a95ef8a740607202ea38 Mon Sep 17 00:00:00 2001
From: Sharad Binjola <31142146+sharadb-amazon@users.noreply.github.com>
Date: Wed, 21 Aug 2024 17:01:20 -0700
Subject: [PATCH] Re-route deprecated android casting APIs to new ones (#35136)
---
.../android/App/app/build.gradle | 4 +-
.../com/chip/casting/app/CastingContext.java | 2 +
.../chip/casting/app/CertTestFragment.java | 12 +-
.../app/CommissionerDiscoveryFragment.java | 6 +-
.../chip/casting/app/ConnectionFragment.java | 10 +-
.../casting/app/ContentLauncherFragment.java | 6 +-
.../casting/app/MediaPlaybackFragment.java | 6 +-
.../casting/app/SelectClusterFragment.java | 6 +-
.../chip/casting/util/DACProviderStub.java | 2 +
.../casting/util/GlobalCastingConstants.java | 11 +
.../jni/com/chip/casting/AppParameters.java | 2 +
.../chip/casting/CommissioningCallbacks.java | 2 +
.../jni/com/chip/casting/ContentApp.java | 37 +
.../chip/casting/ContentLauncherTypes.java | 2 +
.../jni/com/chip/casting/DACProvider.java | 2 +
.../com/chip/casting/DiscoveredNodeData.java | 26 +-
.../jni/com/chip/casting/FailureCallback.java | 6 +-
.../chip/casting/MatterCallbackHandler.java | 6 +-
.../jni/com/chip/casting/MatterError.java | 9 +
.../com/chip/casting/MediaPlaybackTypes.java | 2 +
.../SubscriptionEstablishedCallback.java | 2 +
.../jni/com/chip/casting/SuccessCallback.java | 2 +
.../chip/casting/TargetNavigatorTypes.java | 2 +
.../jni/com/chip/casting/TvCastingApp.java | 1327 ++++++++++
.../jni/com/chip/casting/VideoPlayer.java | 62 +-
.../App/app/src/main/AndroidManifest.xml | 4 +-
.../casting/util/GlobalCastingConstants.java | 11 -
.../casting}/ChipTvCastingApplication.java | 2 +-
.../app => matter/casting}/MainActivity.java | 16 +-
.../chip/casting/NsdDiscoveryListener.java | 128 -
.../com/chip/casting/NsdResolveListener.java | 165 --
.../jni/com/chip/casting/TvCastingApp.java | 608 -----
.../matter/casting/support/DataProvider.java | 4 +-
.../App/app/src/main/jni/cpp/Constants.h | 74 -
.../app/src/main/jni/cpp/ConversionUtils.cpp | 410 ----
.../app/src/main/jni/cpp/ConversionUtils.h | 36 -
.../jni/cpp/MatterCallbackHandler-JNI.cpp | 419 ----
.../main/jni/cpp/MatterCallbackHandler-JNI.h | 293 ---
.../app/src/main/jni/cpp/TvCastingApp-JNI.cpp | 2129 -----------------
.../app/src/main/jni/cpp/TvCastingApp-JNI.h | 162 --
.../src/main/jni/cpp/core/CastingApp-JNI.cpp | 15 +-
.../cpp/core/CastingPlayerDiscovery-JNI.cpp | 1 -
.../jni/cpp/core/MatterCastingPlayer-JNI.cpp | 1 -
.../main/jni/cpp/core/MatterEndpoint-JNI.cpp | 1 -
.../jni/cpp/{ => support}/JNIDACProvider.cpp | 8 +
.../jni/cpp/{ => support}/JNIDACProvider.h | 8 +
.../app/src/main/res/layout/activity_main.xml | 2 +-
.../CommissionerDiscoveryListenerTest.java | 68 -
examples/tv-casting-app/android/BUILD.gn | 46 +-
.../tv-casting-common/core/CastingApp.cpp | 2 -
50 files changed, 1566 insertions(+), 4601 deletions(-)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/java/com/chip/casting/app/CastingContext.java (87%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/java/com/chip/casting/app/CertTestFragment.java (97%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/java/com/chip/casting/app/CommissionerDiscoveryFragment.java (98%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/java/com/chip/casting/app/ConnectionFragment.java (96%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/java/com/chip/casting/app/ContentLauncherFragment.java (94%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/java/com/chip/casting/app/MediaPlaybackFragment.java (97%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/java/com/chip/casting/app/SelectClusterFragment.java (95%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/java/com/chip/casting/util/DACProviderStub.java (98%)
create mode 100644 examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/util/GlobalCastingConstants.java
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/AppParameters.java (97%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/CommissioningCallbacks.java (97%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/ContentApp.java (51%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/ContentLauncherTypes.java (96%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/DACProvider.java (92%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/DiscoveredNodeData.java (88%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/FailureCallback.java (85%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/MatterCallbackHandler.java (85%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/MatterError.java (84%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/MediaPlaybackTypes.java (93%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/SubscriptionEstablishedCallback.java (91%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/SuccessCallback.java (91%)
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/TargetNavigatorTypes.java (93%)
create mode 100644 examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/TvCastingApp.java
rename examples/tv-casting-app/android/App/app/src/{main => compat}/jni/com/chip/casting/VideoPlayer.java (81%)
delete mode 100644 examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/GlobalCastingConstants.java
rename examples/tv-casting-app/android/App/app/src/main/java/com/{chip/casting/app => matter/casting}/ChipTvCastingApplication.java (84%)
rename examples/tv-casting-app/android/App/app/src/main/java/com/{chip/casting/app => matter/casting}/MainActivity.java (92%)
delete mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdDiscoveryListener.java
delete mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdResolveListener.java
delete mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java
delete mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/cpp/Constants.h
delete mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp
delete mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.h
delete mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp
delete mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.h
delete mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp
delete mode 100644 examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.h
rename examples/tv-casting-app/android/App/app/src/main/jni/cpp/{ => support}/JNIDACProvider.cpp (98%)
rename examples/tv-casting-app/android/App/app/src/main/jni/cpp/{ => support}/JNIDACProvider.h (94%)
delete mode 100644 examples/tv-casting-app/android/App/app/src/test/java/com/chip/casting/dnssd/CommissionerDiscoveryListenerTest.java
diff --git a/examples/tv-casting-app/android/App/app/build.gradle b/examples/tv-casting-app/android/App/app/build.gradle
index 3dcdad715e6393..757e6a6522f5da 100644
--- a/examples/tv-casting-app/android/App/app/build.gradle
+++ b/examples/tv-casting-app/android/App/app/build.gradle
@@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "com.chip.casting"
- minSdk 24
+ minSdk 26
targetSdk 30
versionCode 1
versionName "1.0"
@@ -47,6 +47,8 @@ android {
java.srcDirs = [
'src/main/java',
'src/main/jni',
+ 'src/compat/java',
+ 'src/compat/jni',
]
// uncomment this code to debug
diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CastingContext.java b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/CastingContext.java
similarity index 87%
rename from examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CastingContext.java
rename to examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/CastingContext.java
index acab829034bd56..b089e92b8faf0f 100644
--- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CastingContext.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/CastingContext.java
@@ -5,6 +5,8 @@
import androidx.fragment.app.FragmentActivity;
import com.R;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public class CastingContext {
private FragmentActivity fragmentActivity;
diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CertTestFragment.java b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/CertTestFragment.java
similarity index 97%
rename from examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CertTestFragment.java
rename to examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/CertTestFragment.java
index 7ee9fa3c46a0ae..27f00aab8e9325 100644
--- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CertTestFragment.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/CertTestFragment.java
@@ -313,7 +313,17 @@ private void runCertTests(Activity activity) {
"messages_presentMessages",
successFailureCallback,
() -> {
- tvCastingApp.messages_presentMessages(kTVApp, "CastingAppTestMessage", callback);
+ final byte[] messageID = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5};
+ tvCastingApp.messages_presentMessages(
+ kTVApp,
+ messageID,
+ 0,
+ 0,
+ (long) 0,
+ (long) 60 * 1000,
+ "CastingAppTestMessage",
+ Optional.empty(),
+ callback);
});
runAndWait(
diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CommissionerDiscoveryFragment.java b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/CommissionerDiscoveryFragment.java
similarity index 98%
rename from examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CommissionerDiscoveryFragment.java
rename to examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/CommissionerDiscoveryFragment.java
index 3a119940b64839..c7aa931d9f00a1 100644
--- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CommissionerDiscoveryFragment.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/CommissionerDiscoveryFragment.java
@@ -28,7 +28,11 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
-/** A {@link Fragment} to discover commissioners on the network */
+/**
+ * @deprecated Refer to com.matter.casting.DiscoveryExampleFragment.
+ *
A {@link Fragment} to discover commissioners on the network
+ */
+@Deprecated
public class CommissionerDiscoveryFragment extends Fragment {
private static final String TAG = CommissionerDiscoveryFragment.class.getSimpleName();
private static final long DISCOVERY_POLL_INTERVAL_MS = 15000;
diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ConnectionFragment.java b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/ConnectionFragment.java
similarity index 96%
rename from examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ConnectionFragment.java
rename to examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/ConnectionFragment.java
index 09ba31b2c8776c..dcd681d7cbc70d 100644
--- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ConnectionFragment.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/ConnectionFragment.java
@@ -21,9 +21,14 @@
import com.chip.casting.util.GlobalCastingConstants;
import java.util.concurrent.Executors;
-/** A {@link Fragment} to get the TV Casting App commissioned / connected. */
+/**
+ * @deprecated Refer to com.matter.casting.ConnectionExampleFragment.
+ *
A {@link Fragment} to get the TV Casting App commissioned / connected
+ */
+@Deprecated
public class ConnectionFragment extends Fragment {
private static final String TAG = ConnectionFragment.class.getSimpleName();
+ private static final Integer targetContentAppVendorId = 65521;
private final TvCastingApp tvCastingApp;
private final DiscoveredNodeData selectedCommissioner;
@@ -189,7 +194,8 @@ public void handle(MatterError error) {
+ " port: "
+ selectedCommissioner.getPort());
- this.sendUdcSuccess = tvCastingApp.sendCommissioningRequest(selectedCommissioner);
+ this.sendUdcSuccess =
+ tvCastingApp.sendCommissioningRequest(selectedCommissioner, targetContentAppVendorId);
updateUiOnConnectionSuccess();
}
} else {
diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ContentLauncherFragment.java b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/ContentLauncherFragment.java
similarity index 94%
rename from examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ContentLauncherFragment.java
rename to examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/ContentLauncherFragment.java
index d1c3c9f957f394..14bcfcae1568f8 100644
--- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ContentLauncherFragment.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/ContentLauncherFragment.java
@@ -15,7 +15,11 @@
import com.chip.casting.MatterError;
import com.chip.casting.TvCastingApp;
-/** A {@link Fragment} to send Content Launcher commands from the TV Casting App. */
+/**
+ * @deprecated Refer to com.matter.casting.ContentLauncherLaunchURLExampleFragment.
+ *
A {@link Fragment} to send Content Launcher commands from the TV Casting App.
+ */
+@Deprecated
public class ContentLauncherFragment extends Fragment {
private static final String TAG = ContentLauncherFragment.class.getSimpleName();
diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MediaPlaybackFragment.java b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/MediaPlaybackFragment.java
similarity index 97%
rename from examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MediaPlaybackFragment.java
rename to examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/MediaPlaybackFragment.java
index a9c38443a7d91e..b48dcd277122a4 100644
--- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MediaPlaybackFragment.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/MediaPlaybackFragment.java
@@ -18,7 +18,11 @@
import com.chip.casting.SuccessCallback;
import com.chip.casting.TvCastingApp;
-/** A {@link Fragment} for the Media Playback cluster */
+/**
+ * @deprecated Refer to com.matter.casting.MediaPlaybackSubscribeToCurrentStateExampleFragment.
+ *
A {@link Fragment} for the Media Playback cluster
+ */
+@Deprecated
public class MediaPlaybackFragment extends Fragment {
private static final String TAG = MediaPlaybackFragment.class.getSimpleName();
diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/SelectClusterFragment.java b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/SelectClusterFragment.java
similarity index 95%
rename from examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/SelectClusterFragment.java
rename to examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/SelectClusterFragment.java
index f89fc36009e404..47cc4728f96cfb 100644
--- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/SelectClusterFragment.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/SelectClusterFragment.java
@@ -10,7 +10,11 @@
import com.R;
import com.chip.casting.TvCastingApp;
-/** An interstitial {@link Fragment} to select one of the supported media actions to perform */
+/**
+ * @deprecated Refer to com.matter.casting.ActionSelectorFragment.
+ *
An interstitial {@link Fragment} to select one of the supported media actions to perform
+ */
+@Deprecated
public class SelectClusterFragment extends Fragment {
private static final String TAG = SelectClusterFragment.class.getSimpleName();
diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/DACProviderStub.java b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/util/DACProviderStub.java
similarity index 98%
rename from examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/DACProviderStub.java
rename to examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/util/DACProviderStub.java
index 9dbae27c6e5982..2a91c055dcb47a 100644
--- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/DACProviderStub.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/util/DACProviderStub.java
@@ -11,6 +11,8 @@
import java.security.spec.ECParameterSpec;
import java.security.spec.ECPrivateKeySpec;
+/** @deprecated Refer to com.matter.casting.DACProviderStub. */
+@Deprecated
public class DACProviderStub implements DACProvider {
private String kDevelopmentDAC_Cert_FFF1_8001 =
diff --git a/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/util/GlobalCastingConstants.java b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/util/GlobalCastingConstants.java
new file mode 100644
index 00000000000000..526bbb07401845
--- /dev/null
+++ b/examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/util/GlobalCastingConstants.java
@@ -0,0 +1,11 @@
+package com.chip.casting.util;
+
+public class GlobalCastingConstants {
+ public static final int CommissioningWindowDurationSecs = 3 * 60;
+ public static final int SetupPasscode = 20202021;
+ public static final int Discriminator = 0xF00;
+
+ // set to true, to demo the simplified casting APIs.
+ // Otherwise, the deprecated casting APIs are invoked
+ public static final boolean ChipCastingSimplified = true;
+}
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/AppParameters.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/AppParameters.java
similarity index 97%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/AppParameters.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/AppParameters.java
index 18c9a351f0e41a..3d72b38f72eb84 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/AppParameters.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/AppParameters.java
@@ -22,6 +22,8 @@
import java.math.BigInteger;
import java.util.Arrays;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public class AppParameters {
private static final String TAG = AppParameters.class.getSimpleName();
public static final int MIN_ROTATING_DEVICE_ID_UNIQUE_ID_LENGTH = 16;
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/CommissioningCallbacks.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/CommissioningCallbacks.java
similarity index 97%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/CommissioningCallbacks.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/CommissioningCallbacks.java
index 9a44aba792f18b..20599a4f07352a 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/CommissioningCallbacks.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/CommissioningCallbacks.java
@@ -17,6 +17,8 @@
*/
package com.chip.casting;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public class CommissioningCallbacks {
/**
* This is called when the PBKDFParamRequest is received and indicates the start of the session
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/ContentApp.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/ContentApp.java
similarity index 51%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/ContentApp.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/ContentApp.java
index 80efc22ef52024..1c20a40b66251a 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/ContentApp.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/ContentApp.java
@@ -17,10 +17,16 @@
*/
package com.chip.casting;
+import chip.devicecontroller.ChipClusters;
+import com.matter.casting.core.Endpoint;
+import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public class ContentApp {
+ private Endpoint endpoint;
private short endpointId;
private List clusterIds;
@@ -32,6 +38,33 @@ public ContentApp(short endpointId, List clusterIds) {
this.isInitialized = true;
}
+ ContentApp(Endpoint endpoint) {
+ this.endpoint = endpoint;
+ this.endpointId = (short) endpoint.getId();
+ this.clusterIds = new ArrayList<>();
+ if (endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class) != null) {
+ this.clusterIds.add((int) ChipClusters.ApplicationBasicCluster.CLUSTER_ID);
+ }
+ if (endpoint.getCluster(ChipClusters.ApplicationLauncherCluster.class) != null) {
+ this.clusterIds.add((int) ChipClusters.ApplicationLauncherCluster.CLUSTER_ID);
+ }
+ if (endpoint.getCluster(ChipClusters.ContentLauncherCluster.class) != null) {
+ this.clusterIds.add((int) ChipClusters.ContentLauncherCluster.CLUSTER_ID);
+ }
+ if (endpoint.getCluster(ChipClusters.KeypadInputCluster.class) != null) {
+ this.clusterIds.add((int) ChipClusters.KeypadInputCluster.CLUSTER_ID);
+ }
+ if (endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) != null) {
+ this.clusterIds.add((int) ChipClusters.MediaPlaybackCluster.CLUSTER_ID);
+ }
+ if (endpoint.getCluster(ChipClusters.OnOffCluster.class) != null) {
+ this.clusterIds.add((int) ChipClusters.OnOffCluster.CLUSTER_ID);
+ }
+ if (endpoint.getCluster(ChipClusters.TargetNavigatorCluster.class) != null) {
+ this.clusterIds.add((int) ChipClusters.TargetNavigatorCluster.CLUSTER_ID);
+ }
+ }
+
public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
@@ -49,6 +82,10 @@ public java.lang.String toString() {
return "endpointId=" + endpointId;
}
+ Endpoint getEndpoint() {
+ return endpoint;
+ }
+
public short getEndpointId() {
return endpointId;
}
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/ContentLauncherTypes.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/ContentLauncherTypes.java
similarity index 96%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/ContentLauncherTypes.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/ContentLauncherTypes.java
index bc4ee6a6a24bdf..b6d7c3402989d9 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/ContentLauncherTypes.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/ContentLauncherTypes.java
@@ -20,6 +20,8 @@
import java.util.ArrayList;
import java.util.Optional;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public class ContentLauncherTypes {
public static class AdditionalInfo {
public String name;
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/DACProvider.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/DACProvider.java
similarity index 92%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/DACProvider.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/DACProvider.java
index c49d73ab98c86e..7c6ac281e61568 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/DACProvider.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/DACProvider.java
@@ -17,6 +17,8 @@
*/
package com.chip.casting;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public interface DACProvider {
byte[] GetCertificationDeclaration();
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/DiscoveredNodeData.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/DiscoveredNodeData.java
similarity index 88%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/DiscoveredNodeData.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/DiscoveredNodeData.java
index a66d48a57c0e2a..39b9113c94a836 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/DiscoveredNodeData.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/DiscoveredNodeData.java
@@ -19,6 +19,7 @@
import android.net.nsd.NsdServiceInfo;
import android.util.Log;
+import com.matter.casting.core.CastingPlayer;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
@@ -26,15 +27,18 @@
import java.util.Map;
import java.util.Objects;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public class DiscoveredNodeData {
private static final String TAG = DiscoveredNodeData.class.getSimpleName();
- private static final int MAX_IP_ADDRESSES = 5;
private static final int MAX_ROTATING_ID_LEN = 50;
private static final String KEY_DEVICE_NAME = "DN";
private static final String KEY_DEVICE_TYPE = "DT";
private static final String KEY_VENDOR_PRODUCT = "VP";
+ private CastingPlayer castingPlayer;
+
private String hostName;
private String instanceName;
private long longDiscriminator;
@@ -119,10 +123,30 @@ public DiscoveredNodeData(VideoPlayer player) {
this.port = player.getPort();
}
+ DiscoveredNodeData(CastingPlayer castingPlayer) {
+ this.castingPlayer = castingPlayer;
+ this.deviceName = castingPlayer.getDeviceName();
+ this.ipAddresses = castingPlayer.getIpAddresses();
+ this.numIPs =
+ castingPlayer.getIpAddresses() != null ? castingPlayer.getIpAddresses().size() : 0;
+ this.deviceType = castingPlayer.getDeviceType();
+ this.hostName = castingPlayer.getHostName();
+ this.vendorId = castingPlayer.getVendorId();
+ this.productId = castingPlayer.getProductId();
+ this.instanceName = castingPlayer.getInstanceName();
+ if (castingPlayer.isConnected()) {
+ this.connectableVideoPlayer = new VideoPlayer(castingPlayer);
+ }
+ }
+
void setConnectableVideoPlayer(VideoPlayer videoPlayer) {
this.connectableVideoPlayer = videoPlayer;
}
+ CastingPlayer getCastingPlayer() {
+ return castingPlayer;
+ }
+
public boolean isPreCommissioned() {
return connectableVideoPlayer != null;
}
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/FailureCallback.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/FailureCallback.java
similarity index 85%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/FailureCallback.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/FailureCallback.java
index 2ad3b9fc7222fe..5e07e9d526b1c4 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/FailureCallback.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/FailureCallback.java
@@ -19,14 +19,16 @@
import android.util.Log;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public abstract class FailureCallback {
private static final String TAG = FailureCallback.class.getSimpleName();
public abstract void handle(MatterError err);
- protected final void handleInternal(int errorCode, String errorMessage) {
+ protected final void handleInternal(MatterError err) {
try {
- handle(new MatterError(errorCode, errorMessage));
+ handle(err);
} catch (Throwable t) {
Log.e(TAG, "FailureCallback::Caught an unhandled Throwable from the client: " + t);
}
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MatterCallbackHandler.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/MatterCallbackHandler.java
similarity index 85%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MatterCallbackHandler.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/MatterCallbackHandler.java
index 493635beb692f1..7f1efd056e2e23 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MatterCallbackHandler.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/MatterCallbackHandler.java
@@ -19,14 +19,16 @@
import android.util.Log;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public abstract class MatterCallbackHandler {
private static final String TAG = MatterCallbackHandler.class.getSimpleName();
public abstract void handle(MatterError err);
- protected final void handleInternal(int errorCode, String errorMessage) {
+ protected final void handleInternal(MatterError err) {
try {
- handle(new MatterError(errorCode, errorMessage));
+ handle(err);
} catch (Throwable t) {
Log.e(TAG, "MatterCallbackHandler::Caught an unhandled Throwable from the client: " + t);
}
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MatterError.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/MatterError.java
similarity index 84%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MatterError.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/MatterError.java
index ac12eaccd28977..e281bdd8b63735 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MatterError.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/MatterError.java
@@ -19,6 +19,8 @@
import java.util.Objects;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public class MatterError {
private long errorCode;
private String errorMessage;
@@ -26,8 +28,15 @@ public class MatterError {
public static final MatterError DISCOVERY_SERVICE_LOST =
new MatterError(4L, "Discovery service was lost.");
+ public static final MatterError MATTER_INTERNAL_ERROR = new MatterError(0xac, "Internal error.");
+
public static final MatterError NO_ERROR = new MatterError(0, null);
+ MatterError(com.matter.casting.support.MatterError err) {
+ this.errorCode = err.getErrorCode();
+ this.errorMessage = err.getErrorMessage();
+ }
+
public MatterError(long errorCode, String errorMessage) {
this.errorCode = errorCode;
this.errorMessage = errorMessage;
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MediaPlaybackTypes.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/MediaPlaybackTypes.java
similarity index 93%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MediaPlaybackTypes.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/MediaPlaybackTypes.java
index 7bf37b5d1cd8e4..fc01b02dea23da 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MediaPlaybackTypes.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/MediaPlaybackTypes.java
@@ -17,6 +17,8 @@
*/
package com.chip.casting;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public class MediaPlaybackTypes {
public enum PlaybackStateEnum {
Playing,
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/SubscriptionEstablishedCallback.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/SubscriptionEstablishedCallback.java
similarity index 91%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/SubscriptionEstablishedCallback.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/SubscriptionEstablishedCallback.java
index aab9dcd9306fd7..dd5eab2ec66556 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/SubscriptionEstablishedCallback.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/SubscriptionEstablishedCallback.java
@@ -19,6 +19,8 @@
import android.util.Log;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public abstract class SubscriptionEstablishedCallback {
private static final String TAG = SubscriptionEstablishedCallback.class.getSimpleName();
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/SuccessCallback.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/SuccessCallback.java
similarity index 91%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/SuccessCallback.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/SuccessCallback.java
index b82845567d8276..d1194d46f3eef0 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/SuccessCallback.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/SuccessCallback.java
@@ -19,6 +19,8 @@
import android.util.Log;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public abstract class SuccessCallback {
private static final String TAG = SuccessCallback.class.getSimpleName();
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TargetNavigatorTypes.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/TargetNavigatorTypes.java
similarity index 93%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TargetNavigatorTypes.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/TargetNavigatorTypes.java
index 88f71bb796ceaf..832101c9564fe7 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TargetNavigatorTypes.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/TargetNavigatorTypes.java
@@ -17,6 +17,8 @@
*/
package com.chip.casting;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public class TargetNavigatorTypes {
public static class TargetInfo {
public Integer identifier;
diff --git a/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/TvCastingApp.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/TvCastingApp.java
new file mode 100644
index 00000000000000..cd965905065bee
--- /dev/null
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/TvCastingApp.java
@@ -0,0 +1,1327 @@
+/*
+ * Copyright (c) 2022 Project CHIP Authors
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.chip.casting;
+
+import android.content.Context;
+import android.util.Log;
+import androidx.annotation.Nullable;
+import chip.devicecontroller.ChipClusters;
+import chip.devicecontroller.ChipStructs;
+import com.matter.casting.core.CastingApp;
+import com.matter.casting.core.CastingPlayer;
+import com.matter.casting.core.CastingPlayerDiscovery;
+import com.matter.casting.core.Endpoint;
+import com.matter.casting.core.MatterCastingPlayerDiscovery;
+import com.matter.casting.support.AppParameters;
+import com.matter.casting.support.CommissionableData;
+import com.matter.casting.support.ConnectionCallbacks;
+import com.matter.casting.support.DACProvider;
+import com.matter.casting.support.IdentificationDeclarationOptions;
+import com.matter.casting.support.MatterCallback;
+import com.matter.casting.support.MatterError;
+import com.matter.casting.support.TargetAppInfo;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
+public class TvCastingApp {
+ private static final String TAG = TvCastingApp.class.getSimpleName();
+
+ private com.chip.casting.AppParameters appParametersCompat;
+ private int commissioningWindowTimeout;
+ private CommissioningCallbacks commissioningCallbacks;
+ private SuccessCallback onConnectionSuccess;
+ private FailureCallback onConnectionFailure;
+ private SuccessCallback onNewOrUpdatedEndpointCallback;
+ private CastingPlayer targetCastingPlayer;
+
+ private abstract class CastingPlayerChangeListenerAdapter
+ extends CastingPlayerDiscovery.CastingPlayerChangeListener {
+ public abstract void initialize(SuccessCallback discoverySuccessCallback);
+ }
+
+ private CastingPlayerChangeListenerAdapter castingPlayerDiscoveryChangeListener =
+ new CastingPlayerChangeListenerAdapter() {
+ private SuccessCallback discoverySuccessCallbackCompat;
+
+ @Override
+ public void initialize(SuccessCallback discoverySuccessCallback) {
+ this.discoverySuccessCallbackCompat = discoverySuccessCallback;
+ }
+
+ @Override
+ public void onAdded(CastingPlayer castingPlayer) {
+ if (discoverySuccessCallbackCompat == null) {
+ Log.e(TAG, "discoverySuccessCallbackCompat not set");
+ return;
+ }
+ discoverySuccessCallbackCompat.handleInternal(new DiscoveredNodeData((castingPlayer)));
+ }
+
+ @Override
+ public void onChanged(CastingPlayer castingPlayer) {
+ if (discoverySuccessCallbackCompat == null) {
+ Log.e(TAG, "discoverySuccessCallbackCompat not set");
+ return;
+ }
+ discoverySuccessCallbackCompat.handleInternal(new DiscoveredNodeData((castingPlayer)));
+ }
+
+ @Override
+ public void onRemoved(CastingPlayer castingPlayer) {
+ Log.e(TAG, "CastingPlayerChangeListener.onRemoved() not implemented");
+ }
+ };
+
+ private interface DACProviderAdapter extends DACProvider {
+ void initialize(com.chip.casting.DACProvider dacProviderCompat);
+ }
+
+ private DACProviderAdapter dacProvider =
+ new DACProviderAdapter() {
+ private com.chip.casting.DACProvider dacProviderCompat;
+
+ public void initialize(com.chip.casting.DACProvider dacProviderCompat) {
+ this.dacProviderCompat = dacProviderCompat;
+ }
+
+ @Override
+ public byte[] GetCertificationDeclaration() {
+ if (dacProviderCompat == null) {
+ Log.e(TAG, "dacProviderCompat not set");
+ return null;
+ }
+ return dacProviderCompat.GetCertificationDeclaration();
+ }
+
+ @Override
+ public byte[] GetFirmwareInformation() {
+ if (dacProviderCompat == null) {
+ Log.e(TAG, "dacProviderCompat not set");
+ return null;
+ }
+ return dacProviderCompat.GetFirmwareInformation();
+ }
+
+ @Override
+ public byte[] GetDeviceAttestationCert() {
+ if (dacProviderCompat == null) {
+ Log.e(TAG, "dacProviderCompat not set");
+ return null;
+ }
+ return dacProviderCompat.GetDeviceAttestationCert();
+ }
+
+ @Override
+ public byte[] GetProductAttestationIntermediateCert() {
+ if (dacProviderCompat == null) {
+ Log.e(TAG, "dacProviderCompat not set");
+ return null;
+ }
+ return dacProviderCompat.GetProductAttestationIntermediateCert();
+ }
+
+ @Override
+ public byte[] SignWithDeviceAttestationKey(byte[] message) {
+ if (dacProviderCompat == null) {
+ Log.e(TAG, "dacProviderCompat not set");
+ return null;
+ }
+ return dacProviderCompat.SignWithDeviceAttestationKey(message);
+ }
+ };
+
+ private static final List DISCOVERY_TARGET_DEVICE_TYPE_FILTER =
+ Arrays.asList(35L); // Matter Casting Video player = 35;
+
+ private static TvCastingApp sInstance;
+
+ private TvCastingApp() {}
+
+ public static TvCastingApp getInstance() {
+ if (sInstance == null) {
+ sInstance = new TvCastingApp();
+ }
+ return sInstance;
+ }
+
+ public boolean initApp(
+ Context applicationContext, com.chip.casting.AppParameters appParametersCompat) {
+ if (applicationContext == null
+ || appParametersCompat == null
+ || appParametersCompat.getConfigurationManager() == null) {
+ return false;
+ }
+
+ this.appParametersCompat = appParametersCompat;
+
+ AppParameters appParameters =
+ new AppParameters(
+ applicationContext,
+ () -> appParametersCompat.getConfigurationManager(),
+ () -> appParametersCompat.getRotatingDeviceIdUniqueId(),
+ () -> {
+ CommissionableData commissionableData =
+ new CommissionableData(
+ appParametersCompat.getSetupPasscode(),
+ appParametersCompat.getDiscriminator());
+ commissionableData.setSpake2pIterationCount(
+ appParametersCompat.getSpake2pIterationCount());
+ commissionableData.setSpake2pSaltBase64(appParametersCompat.getSpake2pSaltBase64());
+ commissionableData.setSpake2pVerifierBase64(
+ appParametersCompat.getSpake2pVerifierBase64());
+ return commissionableData;
+ },
+ this.dacProvider);
+
+ // Initialize the SDK using the appParameters and check if it returns successfully
+ MatterError err = CastingApp.getInstance().initialize(appParameters);
+ if (err.hasError()) {
+ Log.e(TAG, "Failed to initialize Matter CastingApp. Err: " + err);
+ return false;
+ }
+
+ err = CastingApp.getInstance().start();
+ if (err.hasError()) {
+ Log.e(TAG, "Failed to start Matter CastingApp. Err: " + err);
+ return false;
+ }
+ return true;
+ }
+
+ public void setDACProvider(com.chip.casting.DACProvider dacProviderCompat) {
+ this.dacProvider.initialize(dacProviderCompat);
+ }
+
+ public void discoverVideoPlayerCommissioners(
+ SuccessCallback discoverySuccessCallback,
+ FailureCallback discoveryFailureCallback) {
+
+ // stop before starting another discovery session
+ stopVideoPlayerDiscovery();
+
+ castingPlayerDiscoveryChangeListener.initialize(discoverySuccessCallback);
+ MatterError err =
+ MatterCastingPlayerDiscovery.getInstance()
+ .addCastingPlayerChangeListener(castingPlayerDiscoveryChangeListener);
+ if (err.hasError()) {
+ Log.e(TAG, "addCastingPlayerChangeListener before starting discovery failed. Err: " + err);
+ discoveryFailureCallback.handleInternal(new com.chip.casting.MatterError(err));
+ return;
+ }
+
+ err =
+ MatterCastingPlayerDiscovery.getInstance()
+ .startDiscovery(DISCOVERY_TARGET_DEVICE_TYPE_FILTER.get(0));
+ if (err.hasError()) {
+ Log.e(TAG, "startDiscovery failed. Err: " + err);
+ discoveryFailureCallback.handleInternal(new com.chip.casting.MatterError(err));
+ }
+ }
+
+ public void stopVideoPlayerDiscovery() {
+ MatterError err = MatterCastingPlayerDiscovery.getInstance().stopDiscovery();
+ if (err.hasError()) {
+ Log.e(TAG, "stopDiscovery failed. Err: " + err);
+ return;
+ }
+
+ err =
+ MatterCastingPlayerDiscovery.getInstance()
+ .removeCastingPlayerChangeListener(castingPlayerDiscoveryChangeListener);
+ if (err.hasError()) {
+ Log.e(TAG, "removeCastingPlayerChangeListener failed. Err: " + err);
+ }
+ }
+
+ public boolean openBasicCommissioningWindow(
+ int commissioningWindowTimeout,
+ CommissioningCallbacks commissioningCallbacks,
+ SuccessCallback onConnectionSuccess,
+ FailureCallback onConnectionFailure,
+ SuccessCallback onNewOrUpdatedEndpointCallback) {
+ this.commissioningWindowTimeout = commissioningWindowTimeout;
+ this.commissioningCallbacks = commissioningCallbacks;
+ this.onConnectionSuccess = onConnectionSuccess;
+ this.onConnectionFailure = onConnectionFailure;
+ this.onNewOrUpdatedEndpointCallback = onNewOrUpdatedEndpointCallback;
+ return true;
+ }
+
+ public boolean sendCommissioningRequest(DiscoveredNodeData commissioner, Integer vendorId) {
+ if (commissioningCallbacks == null
+ || onConnectionSuccess == null
+ || onConnectionFailure == null
+ || onNewOrUpdatedEndpointCallback == null) {
+ Log.e(TAG, "Commissioning/connection callbacks not set");
+ return false;
+ }
+
+ this.targetCastingPlayer = commissioner.getCastingPlayer();
+
+ IdentificationDeclarationOptions idOptions = new IdentificationDeclarationOptions();
+ idOptions.addTargetAppInfo(new TargetAppInfo(vendorId, null));
+
+ MatterError err =
+ targetCastingPlayer.verifyOrEstablishConnection(
+ new ConnectionCallbacks(
+ new MatterCallback() {
+ @Override
+ public void handle(Void response) {
+ ((MatterCallbackHandler) commissioningCallbacks.getCommissioningComplete())
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ onConnectionSuccess.handleInternal(new VideoPlayer(targetCastingPlayer));
+
+ List endpoints = targetCastingPlayer.getEndpoints();
+ if (endpoints != null) {
+ for (Endpoint endpoint : endpoints) {
+ onNewOrUpdatedEndpointCallback.handleInternal(new ContentApp(endpoint));
+ }
+ }
+ }
+ },
+ new MatterCallback() {
+ @Override
+ public void handle(MatterError err) {
+ onConnectionFailure.handleInternal(new com.chip.casting.MatterError(err));
+ }
+ },
+ null),
+ (short) this.commissioningWindowTimeout,
+ idOptions);
+
+ if (err.hasError()) {
+ Log.e(
+ TAG, "sendCommissioningRequest failed to call verifyOrEstablishConnection. Err: " + err);
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean verifyOrEstablishConnection(
+ VideoPlayer targetVideoPlayer,
+ SuccessCallback onConnectionSuccess,
+ FailureCallback onConnectionFailure,
+ SuccessCallback onNewOrUpdatedEndpointCallback) {
+ Log.e(TAG, "verifyOrEstablishConnection is unsupported");
+ return false;
+ }
+
+ public void shutdownAllSubscriptions() {
+ MatterError err = CastingApp.getInstance().shutdownAllSubscriptions();
+ if (err.hasError()) {
+ Log.e(TAG, "shutdownAllSubscriptions failed. Err: " + err);
+ }
+ }
+
+ public void disconnect() {
+ if (targetCastingPlayer != null) {
+ targetCastingPlayer.disconnect();
+ }
+ }
+
+ public boolean purgeCache() {
+ MatterError err = CastingApp.getInstance().clearCache();
+ if (err.hasError()) {
+ Log.e(TAG, "purgeCache failed. Err: " + err);
+ return false;
+ }
+ return true;
+ }
+
+ private Endpoint getTargetEndpoint(ContentApp contentApp) {
+ if (targetCastingPlayer == null || targetCastingPlayer.getEndpoints() == null) {
+ return null;
+ }
+
+ for (Endpoint endpoint : targetCastingPlayer.getEndpoints()) {
+ if (endpoint.getId() == contentApp.getEndpointId()) {
+ return endpoint;
+ }
+ }
+
+ return null;
+ }
+
+ public boolean contentLauncherLaunchURL(
+ ContentApp contentApp, String contentUrl, String contentDisplayStr, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.ContentLauncherCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.ContentLauncherCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.launchURL(
+ new ChipClusters.ContentLauncherCluster.LauncherResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "LauncherResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ },
+ contentUrl,
+ Optional.of(contentDisplayStr),
+ Optional.empty());
+
+ return true;
+ }
+
+ public boolean contentLauncher_launchContent(
+ ContentApp contentApp,
+ ContentLauncherTypes.ContentSearch searchCompat,
+ boolean autoPlay,
+ String data,
+ Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.ContentLauncherCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.ContentLauncherCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ // translate searchCompat
+ ArrayList parameterList = null;
+ if (searchCompat.parameterList != null) {
+ parameterList = new ArrayList<>();
+ for (ContentLauncherTypes.Parameter parameterCompat : searchCompat.parameterList) {
+ ArrayList externalIDList = null;
+ if (parameterCompat.externalIDList != null && parameterCompat.externalIDList.isPresent()) {
+ externalIDList = new ArrayList<>();
+ for (ContentLauncherTypes.AdditionalInfo additionalInfoCompat :
+ parameterCompat.externalIDList.get()) {
+ externalIDList.add(
+ new ChipStructs.ContentLauncherClusterAdditionalInfoStruct(
+ additionalInfoCompat.name, additionalInfoCompat.value));
+ }
+ }
+ parameterList.add(
+ new ChipStructs.ContentLauncherClusterParameterStruct(
+ parameterCompat.type,
+ parameterCompat.value,
+ externalIDList != null ? Optional.of(externalIDList) : Optional.empty()));
+ }
+ }
+ ChipStructs.ContentLauncherClusterContentSearchStruct search =
+ new ChipStructs.ContentLauncherClusterContentSearchStruct(parameterList);
+
+ cluster.launchContent(
+ new ChipClusters.ContentLauncherCluster.LauncherResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "LauncherResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ },
+ search,
+ autoPlay,
+ data != null ? Optional.of(data) : Optional.empty(),
+ Optional.empty(),
+ Optional.empty());
+ return true;
+ }
+
+ public boolean mediaPlayback_play(ContentApp contentApp, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.MediaPlaybackCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.play(
+ new ChipClusters.MediaPlaybackCluster.PlaybackResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "PlaybackResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean mediaPlayback_pause(ContentApp contentApp, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.MediaPlaybackCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.pause(
+ new ChipClusters.MediaPlaybackCluster.PlaybackResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "PlaybackResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean mediaPlayback_stopPlayback(ContentApp contentApp, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.MediaPlaybackCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.stop(
+ new ChipClusters.MediaPlaybackCluster.PlaybackResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "PlaybackResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean mediaPlayback_next(ContentApp contentApp, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.MediaPlaybackCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.next(
+ new ChipClusters.MediaPlaybackCluster.PlaybackResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "PlaybackResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean mediaPlayback_previous(ContentApp contentApp, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.MediaPlaybackCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
+
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.previous(
+ new ChipClusters.MediaPlaybackCluster.PlaybackResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "PlaybackResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean mediaPlayback_rewind(ContentApp contentApp, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.MediaPlaybackCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.rewind(
+ new ChipClusters.MediaPlaybackCluster.PlaybackResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "PlaybackResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ },
+ Optional.empty());
+ return true;
+ }
+
+ public boolean mediaPlayback_fastForward(ContentApp contentApp, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.MediaPlaybackCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.fastForward(
+ new ChipClusters.MediaPlaybackCluster.PlaybackResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "PlaybackResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ },
+ Optional.empty());
+ return true;
+ }
+
+ public boolean mediaPlayback_startOver(ContentApp contentApp, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.MediaPlaybackCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.startOver(
+ new ChipClusters.MediaPlaybackCluster.PlaybackResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "PlaybackResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean mediaPlayback_seek(ContentApp contentApp, long position, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.MediaPlaybackCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.seek(
+ new ChipClusters.MediaPlaybackCluster.PlaybackResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "PlaybackResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ },
+ position);
+ return true;
+ }
+
+ public boolean mediaPlayback_skipForward(
+ ContentApp contentApp, long deltaPositionMilliseconds, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.MediaPlaybackCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.skipForward(
+ new ChipClusters.MediaPlaybackCluster.PlaybackResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "PlaybackResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ },
+ deltaPositionMilliseconds);
+ return true;
+ }
+
+ public boolean mediaPlayback_skipBackward(
+ ContentApp contentApp, long deltaPositionMilliseconds, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.MediaPlaybackCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.skipBackward(
+ new ChipClusters.MediaPlaybackCluster.PlaybackResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "PlaybackResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ },
+ deltaPositionMilliseconds);
+ return true;
+ }
+
+ public boolean mediaPlayback_subscribeToCurrentState(
+ ContentApp contentApp,
+ SuccessCallback readSuccessHandler,
+ FailureCallback readFailureHandler,
+ int minInterval,
+ int maxInterval,
+ SubscriptionEstablishedCallback subscriptionEstablishedHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.MediaPlaybackCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.subscribeCurrentStateAttribute(
+ new ChipClusters.IntegerAttributeCallback() {
+ @Override
+ public void onSuccess(int value) {
+ readSuccessHandler.handleInternal(MediaPlaybackTypes.PlaybackStateEnum.values()[value]);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "IntegerAttributeCallback.onError: " + error);
+ readFailureHandler.handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+
+ @Override
+ public void onSubscriptionEstablished(long subscriptionId) {
+ subscriptionEstablishedHandler.handleInternal();
+ }
+ },
+ minInterval,
+ maxInterval);
+ return true;
+ }
+
+ public boolean applicationLauncher_launchApp(
+ ContentApp contentApp,
+ short catalogVendorId,
+ String applicationId,
+ byte[] data,
+ Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.ApplicationLauncherCluster cluster =
+ endpoint != null
+ ? endpoint.getCluster(ChipClusters.ApplicationLauncherCluster.class)
+ : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ // translate to application
+ Optional application =
+ Optional.empty();
+ if (applicationId != null) {
+ application =
+ Optional.of(
+ new ChipStructs.ApplicationLauncherClusterApplicationStruct(
+ (int) catalogVendorId, applicationId));
+ }
+
+ cluster.launchApp(
+ new ChipClusters.ApplicationLauncherCluster.LauncherResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "LauncherResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ },
+ application,
+ data != null ? Optional.of(data) : Optional.empty());
+ return true;
+ }
+
+ public boolean applicationLauncher_stopApp(
+ ContentApp contentApp, short catalogVendorId, String applicationId, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.ApplicationLauncherCluster cluster =
+ endpoint != null
+ ? endpoint.getCluster(ChipClusters.ApplicationLauncherCluster.class)
+ : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ // translate to application
+ Optional application =
+ Optional.empty();
+ if (applicationId != null) {
+ application =
+ Optional.of(
+ new ChipStructs.ApplicationLauncherClusterApplicationStruct(
+ (int) catalogVendorId, applicationId));
+ }
+
+ cluster.stopApp(
+ new ChipClusters.ApplicationLauncherCluster.LauncherResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "LauncherResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ },
+ application);
+ return true;
+ }
+
+ public boolean applicationLauncher_hideApp(
+ ContentApp contentApp, short catalogVendorId, String applicationId, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.ApplicationLauncherCluster cluster =
+ endpoint != null
+ ? endpoint.getCluster(ChipClusters.ApplicationLauncherCluster.class)
+ : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ // translate to application
+ Optional application =
+ Optional.empty();
+ if (applicationId != null) {
+ application =
+ Optional.of(
+ new ChipStructs.ApplicationLauncherClusterApplicationStruct(
+ (int) catalogVendorId, applicationId));
+ }
+
+ cluster.hideApp(
+ new ChipClusters.ApplicationLauncherCluster.LauncherResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "LauncherResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ },
+ application);
+ return true;
+ }
+
+ public boolean targetNavigator_navigateTarget(
+ ContentApp contentApp, byte target, String data, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.TargetNavigatorCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.TargetNavigatorCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.navigateTarget(
+ new ChipClusters.TargetNavigatorCluster.NavigateTargetResponseCallback() {
+ @Override
+ public void onSuccess(Integer status, Optional data) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "NavigateTargetResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ },
+ (int) target,
+ data != null ? Optional.of(data) : Optional.empty());
+ return true;
+ }
+
+ public boolean targetNavigator_subscribeToTargetList(
+ ContentApp contentApp,
+ SuccessCallback readSuccessHandler,
+ FailureCallback readFailureHandler,
+ int minInterval,
+ int maxInterval,
+ SubscriptionEstablishedCallback subscriptionEstablishedHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.TargetNavigatorCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.TargetNavigatorCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.subscribeTargetListAttribute(
+ new ChipClusters.TargetNavigatorCluster.TargetListAttributeCallback() {
+ @Override
+ public void onSuccess(
+ List targetInfoList) {
+ List targetInfoListCompat = null;
+ if (targetInfoList != null) {
+ targetInfoListCompat = new ArrayList<>();
+ for (ChipStructs.TargetNavigatorClusterTargetInfoStruct targetInfo : targetInfoList) {
+ targetInfoListCompat.add(
+ new TargetNavigatorTypes.TargetInfo(targetInfo.identifier, targetInfo.name));
+ }
+ }
+ readSuccessHandler.handleInternal(targetInfoListCompat);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "TargetListAttributeCallback.onError: " + error);
+ readFailureHandler.handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+
+ @Override
+ public void onSubscriptionEstablished(long subscriptionId) {
+ subscriptionEstablishedHandler.handleInternal();
+ }
+ },
+ minInterval,
+ maxInterval);
+ return true;
+ }
+
+ public boolean keypadInput_sendKey(ContentApp contentApp, byte keyCode, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.KeypadInputCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.KeypadInputCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.sendKey(
+ new ChipClusters.KeypadInputCluster.SendKeyResponseCallback() {
+ @Override
+ public void onSuccess(Integer status) {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "LauncherResponseCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ },
+ (int) keyCode);
+ return true;
+ }
+
+ public boolean applicationBasic_readVendorName(
+ ContentApp contentApp,
+ SuccessCallback readSuccessHandler,
+ FailureCallback readFailureHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.ApplicationBasicCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.readVendorNameAttribute(
+ new ChipClusters.CharStringAttributeCallback() {
+ @Override
+ public void onSuccess(String value) {
+ readSuccessHandler.handleInternal(value);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "CharStringAttributeCallback.onError: " + error);
+ readFailureHandler.handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean applicationBasic_readVendorID(
+ ContentApp contentApp,
+ SuccessCallback readSuccessHandler,
+ FailureCallback readFailureHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.ApplicationBasicCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.readVendorIDAttribute(
+ new ChipClusters.IntegerAttributeCallback() {
+ @Override
+ public void onSuccess(int value) {
+ readSuccessHandler.handleInternal(value);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "IntegerAttributeCallback.onError: " + error);
+ readFailureHandler.handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean applicationBasic_readApplicationName(
+ ContentApp contentApp,
+ SuccessCallback readSuccessHandler,
+ FailureCallback readFailureHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.ApplicationBasicCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.readApplicationNameAttribute(
+ new ChipClusters.CharStringAttributeCallback() {
+ @Override
+ public void onSuccess(String value) {
+ readSuccessHandler.handleInternal(value);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "CharStringAttributeCallback.onError: " + error);
+ readFailureHandler.handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean applicationBasic_readProductID(
+ ContentApp contentApp,
+ SuccessCallback readSuccessHandler,
+ FailureCallback readFailureHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.ApplicationBasicCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.readProductIDAttribute(
+ new ChipClusters.IntegerAttributeCallback() {
+ @Override
+ public void onSuccess(int value) {
+ readSuccessHandler.handleInternal(value);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "IntegerAttributeCallback.onError: " + error);
+ readFailureHandler.handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean applicationBasic_readApplicationVersion(
+ ContentApp contentApp,
+ SuccessCallback readSuccessHandler,
+ FailureCallback readFailureHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.ApplicationBasicCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.readApplicationVersionAttribute(
+ new ChipClusters.CharStringAttributeCallback() {
+ @Override
+ public void onSuccess(String value) {
+ readSuccessHandler.handleInternal(value);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "CharStringAttributeCallback.onError: " + error);
+ readFailureHandler.handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean onOff_on(ContentApp contentApp, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.OnOffCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.OnOffCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.on(
+ new ChipClusters.DefaultClusterCallback() {
+ @Override
+ public void onSuccess() {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "DefaultClusterCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean onOff_off(ContentApp contentApp, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.OnOffCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.OnOffCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.off(
+ new ChipClusters.DefaultClusterCallback() {
+ @Override
+ public void onSuccess() {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "DefaultClusterCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean onOff_toggle(ContentApp contentApp, Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.OnOffCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.OnOffCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.toggle(
+ new ChipClusters.DefaultClusterCallback() {
+ @Override
+ public void onSuccess() {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "DefaultClusterCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ });
+ return true;
+ }
+
+ public boolean messages_presentMessages(
+ ContentApp contentApp,
+ byte[] messageID,
+ Integer priority,
+ Integer messageControl,
+ @Nullable Long startTime,
+ @Nullable Long duration,
+ String messageText,
+ Optional> responses,
+ Object responseHandler) {
+
+ Endpoint endpoint = getTargetEndpoint(contentApp);
+ ChipClusters.MessagesCluster cluster =
+ endpoint != null ? endpoint.getCluster(ChipClusters.MessagesCluster.class) : null;
+ if (cluster == null) {
+ Log.e(TAG, "Cluster not found");
+ return false;
+ }
+
+ cluster.presentMessagesRequest(
+ new ChipClusters.DefaultClusterCallback() {
+ @Override
+ public void onSuccess() {
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.NO_ERROR);
+ }
+
+ @Override
+ public void onError(Exception error) {
+ Log.e(TAG, "DefaultClusterCallback.onError: " + error);
+ ((MatterCallbackHandler) responseHandler)
+ .handleInternal(com.chip.casting.MatterError.MATTER_INTERNAL_ERROR);
+ }
+ },
+ messageID,
+ priority,
+ messageControl,
+ startTime,
+ duration,
+ messageText,
+ responses);
+ return true;
+ }
+}
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/VideoPlayer.java b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/VideoPlayer.java
similarity index 81%
rename from examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/VideoPlayer.java
rename to examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/VideoPlayer.java
index fab9b027a78cc4..1933e28979f8a6 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/VideoPlayer.java
+++ b/examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/VideoPlayer.java
@@ -17,15 +17,19 @@
*/
package com.chip.casting;
+import com.matter.casting.core.CastingPlayer;
+import com.matter.casting.core.Endpoint;
import java.net.InetAddress;
-import java.util.HashSet;
+import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
-import java.util.Set;
+/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
+@Deprecated
public class VideoPlayer {
private static final String TAG = VideoPlayer.class.getSimpleName();
+ private CastingPlayer castingPlayer;
private long nodeId;
private byte fabricIndex;
private String deviceName;
@@ -82,41 +86,25 @@ public VideoPlayer(
this.isInitialized = true;
}
- public boolean isSameAs(DiscoveredNodeData discoveredNodeData) {
- // return false because 'this' VideoPlayer is not null
- if (discoveredNodeData == null) {
- return false;
- }
-
- // return true if hostNames match
- if (Objects.equals(hostName, discoveredNodeData.getHostName())) {
- return true;
- }
-
- // return false because deviceNames are different
- if (Objects.equals(deviceName, discoveredNodeData.getDeviceName()) == false) {
- return false;
- }
-
- // return false because not even a single IP Address matches
- if (ipAddresses != null) {
- boolean matchFound = false;
- Set discoveredNodeDataIpAddressSet =
- new HashSet(discoveredNodeData.getIpAddresses());
- for (InetAddress videoPlayerIpAddress : ipAddresses) {
- if (discoveredNodeDataIpAddressSet.contains(videoPlayerIpAddress)) {
- matchFound = true;
- break;
- }
- }
-
- if (!matchFound) {
- return false;
+ public VideoPlayer(CastingPlayer castingPlayer) {
+ this.castingPlayer = castingPlayer;
+ this.deviceType = (int) castingPlayer.getDeviceType();
+ this.deviceName = castingPlayer.getDeviceName();
+ this.hostName = castingPlayer.getHostName();
+ this.ipAddresses = castingPlayer.getIpAddresses();
+ this.numIPs =
+ castingPlayer.getIpAddresses() != null ? castingPlayer.getIpAddresses().size() : 0;
+ this.isConnected = castingPlayer.isConnected();
+ this.productId = castingPlayer.getProductId();
+ this.vendorId = castingPlayer.getVendorId();
+ List endpoints = castingPlayer.getEndpoints();
+ if (endpoints != null) {
+ this.contentApps = new ArrayList<>();
+ for (Endpoint endpoint : endpoints) {
+ contentApps.add(new ContentApp(endpoint));
}
}
-
- // otherwise, return true
- return true;
+ this.isInitialized = true;
}
public boolean equals(Object object) {
@@ -175,6 +163,10 @@ public String toString() {
+ '}';
}
+ CastingPlayer getCastingPlayer() {
+ return castingPlayer;
+ }
+
public long getNodeId() {
return nodeId;
}
diff --git a/examples/tv-casting-app/android/App/app/src/main/AndroidManifest.xml b/examples/tv-casting-app/android/App/app/src/main/AndroidManifest.xml
index e551de818eb5b0..b47ec80a86b0d9 100644
--- a/examples/tv-casting-app/android/App/app/src/main/AndroidManifest.xml
+++ b/examples/tv-casting-app/android/App/app/src/main/AndroidManifest.xml
@@ -18,9 +18,9 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
- android:name=".chip.casting.app.ChipTvCastingApplication"
+ android:name=".matter.casting.ChipTvCastingApplication"
android:theme="@style/Theme.CHIPTVCastingApp">
-
diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/GlobalCastingConstants.java b/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/GlobalCastingConstants.java
deleted file mode 100644
index 483f1efedb1b46..00000000000000
--- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/GlobalCastingConstants.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.chip.casting.util;
-
-public class GlobalCastingConstants {
- public static final String CommissionerServiceType = "_matterd._udp.";
- public static final int CommissioningWindowDurationSecs = 3 * 60;
- public static final int SetupPasscode = 20202021;
- public static final int Discriminator = 0xF00;
- public static final boolean ChipCastingSimplified =
- true; // set to true, to demo the simplified casting APIs. Otherwise, the older deprecated
- // APIs are invoked
-}
diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ChipTvCastingApplication.java b/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/ChipTvCastingApplication.java
similarity index 84%
rename from examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ChipTvCastingApplication.java
rename to examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/ChipTvCastingApplication.java
index 4986cc28e49c01..bea5b88a310158 100644
--- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ChipTvCastingApplication.java
+++ b/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/ChipTvCastingApplication.java
@@ -1,4 +1,4 @@
-package com.chip.casting.app;
+package com.matter.casting;
import android.app.Application;
diff --git a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MainActivity.java b/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/MainActivity.java
similarity index 92%
rename from examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MainActivity.java
rename to examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/MainActivity.java
index 685dbf2fb6426e..53908322d10155 100644
--- a/examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MainActivity.java
+++ b/examples/tv-casting-app/android/App/app/src/main/java/com/matter/casting/MainActivity.java
@@ -1,4 +1,4 @@
-package com.chip.casting.app;
+package com.matter.casting;
import android.os.Bundle;
import android.util.Log;
@@ -9,15 +9,13 @@
import com.chip.casting.AppParameters;
import com.chip.casting.DiscoveredNodeData;
import com.chip.casting.TvCastingApp;
+import com.chip.casting.app.CertTestFragment;
+import com.chip.casting.app.CommissionerDiscoveryFragment;
+import com.chip.casting.app.ConnectionFragment;
+import com.chip.casting.app.ContentLauncherFragment;
+import com.chip.casting.app.MediaPlaybackFragment;
+import com.chip.casting.app.SelectClusterFragment;
import com.chip.casting.util.GlobalCastingConstants;
-import com.matter.casting.ActionSelectorFragment;
-import com.matter.casting.ApplicationBasicReadVendorIDExampleFragment;
-import com.matter.casting.ConnectionExampleFragment;
-import com.matter.casting.ContentLauncherLaunchURLExampleFragment;
-import com.matter.casting.DiscoveryExampleFragment;
-import com.matter.casting.InitializationExample;
-import com.matter.casting.MediaPlaybackSubscribeToCurrentStateExampleFragment;
-import com.matter.casting.PreferencesConfigurationManager;
import com.matter.casting.core.CastingPlayer;
import java.util.Random;
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdDiscoveryListener.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdDiscoveryListener.java
deleted file mode 100644
index 1a9556e5fdb6d2..00000000000000
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdDiscoveryListener.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright (c) 2022 Project CHIP Authors
- * All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package com.chip.casting;
-
-import android.net.nsd.NsdManager;
-import android.net.nsd.NsdServiceInfo;
-import android.util.Log;
-import chip.platform.NsdManagerServiceResolver;
-import java.util.List;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-public class NsdDiscoveryListener implements NsdManager.DiscoveryListener {
- private static final String TAG = NsdDiscoveryListener.class.getSimpleName();
-
- private final NsdManager nsdManager;
- private final String targetServiceType;
- private final List deviceTypeFilter;
- private final List preCommissionedVideoPlayers;
- private final SuccessCallback successCallback;
- private final FailureCallback failureCallback;
- private final NsdManagerServiceResolver.NsdManagerResolverAvailState nsdManagerResolverAvailState;
- private final ExecutorService resolutionExecutor;
-
- public NsdDiscoveryListener(
- NsdManager nsdManager,
- String targetServiceType,
- List deviceTypeFilter,
- List preCommissionedVideoPlayers,
- SuccessCallback successCallback,
- FailureCallback failureCallback,
- NsdManagerServiceResolver.NsdManagerResolverAvailState nsdManagerResolverAvailState) {
- this.nsdManager = nsdManager;
- this.targetServiceType = targetServiceType;
- this.deviceTypeFilter = deviceTypeFilter;
- this.preCommissionedVideoPlayers = preCommissionedVideoPlayers;
- this.successCallback = successCallback;
- this.failureCallback = failureCallback;
- this.nsdManagerResolverAvailState = nsdManagerResolverAvailState;
- this.resolutionExecutor = Executors.newSingleThreadExecutor();
- }
-
- @Override
- public void onDiscoveryStarted(String regType) {
- Log.d(TAG, "Service discovery started. regType: " + regType);
- }
-
- @Override
- public void onServiceFound(NsdServiceInfo service) {
- this.resolutionExecutor.execute(
- new Runnable() {
- @Override
- public void run() {
- Log.d(TAG, "Service discovery success. " + service);
- if (service.getServiceType().equals(targetServiceType)) {
- if (nsdManagerResolverAvailState != null) {
- nsdManagerResolverAvailState.acquireResolver();
- }
-
- Log.d(TAG, "Calling NsdManager.resolveService for " + service);
- nsdManager.resolveService(
- service,
- new NsdResolveListener(
- nsdManager,
- deviceTypeFilter,
- preCommissionedVideoPlayers,
- successCallback,
- failureCallback,
- nsdManagerResolverAvailState,
- 1));
- } else {
- Log.d(TAG, "Ignoring discovered service: " + service.toString());
- }
- }
- });
- }
-
- @Override
- public void onServiceLost(NsdServiceInfo service) {
- // When the network service is no longer available.
- // Internal bookkeeping code goes here.
- Log.e(TAG, "Service lost: " + service);
- failureCallback.handle(MatterError.DISCOVERY_SERVICE_LOST);
- }
-
- @Override
- public void onDiscoveryStopped(String serviceType) {
- Log.i(TAG, "Discovery stopped: " + serviceType);
- if (nsdManagerResolverAvailState != null) {
- nsdManagerResolverAvailState.signalFree();
- }
- }
-
- @Override
- public void onStartDiscoveryFailed(String serviceType, int errorCode) {
- Log.e(TAG, "Discovery failed to start: Error code:" + errorCode);
- TvCastingApp.getInstance().resetDiscoveryState();
- failureCallback.handle(
- new MatterError(
- 3, "NsdDiscoveryListener Discovery failed to start: Nsd Error code:" + errorCode));
- }
-
- @Override
- public void onStopDiscoveryFailed(String serviceType, int errorCode) {
- Log.e(TAG, "Discovery failed to stop: Error code:" + errorCode);
- if (nsdManagerResolverAvailState != null) {
- nsdManagerResolverAvailState.signalFree();
- }
- failureCallback.handle(
- new MatterError(
- 3, "NsdDiscoveryListener Discovery failed to stop: Nsd Error code:" + errorCode));
- }
-}
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdResolveListener.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdResolveListener.java
deleted file mode 100644
index 638425675dc99b..00000000000000
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/NsdResolveListener.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright (c) 2022 Project CHIP Authors
- * All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package com.chip.casting;
-
-import android.net.nsd.NsdManager;
-import android.net.nsd.NsdServiceInfo;
-import android.util.Log;
-import chip.platform.NsdManagerServiceResolver;
-import java.util.List;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-
-public class NsdResolveListener implements NsdManager.ResolveListener {
-
- private static final String TAG = NsdResolveListener.class.getSimpleName();
-
- private static final int MAX_RESOLUTION_ATTEMPTS = 5;
- private static final int RESOLUTION_ATTEMPT_DELAY_SECS = 1;
-
- private final NsdManager nsdManager;
- private final List deviceTypeFilter;
- private final List preCommissionedVideoPlayers;
- private final SuccessCallback successCallback;
- private final FailureCallback failureCallback;
- private final NsdManagerServiceResolver.NsdManagerResolverAvailState nsdManagerResolverAvailState;
- private final int resolutionAttemptNumber;
-
- public NsdResolveListener(
- NsdManager nsdManager,
- List deviceTypeFilter,
- List preCommissionedVideoPlayers,
- SuccessCallback successCallback,
- FailureCallback failureCallback,
- NsdManagerServiceResolver.NsdManagerResolverAvailState nsdManagerResolverAvailState,
- int resolutionAttemptNumber) {
- this.nsdManager = nsdManager;
- this.deviceTypeFilter = deviceTypeFilter;
- this.preCommissionedVideoPlayers = preCommissionedVideoPlayers;
- if (preCommissionedVideoPlayers != null) {
- for (VideoPlayer videoPlayer : preCommissionedVideoPlayers) {
- Log.d(TAG, "Precommissioned video player: " + videoPlayer);
- }
- }
- this.successCallback = successCallback;
- this.failureCallback = failureCallback;
- this.nsdManagerResolverAvailState = nsdManagerResolverAvailState;
- this.resolutionAttemptNumber = resolutionAttemptNumber;
- }
-
- @Override
- public void onServiceResolved(NsdServiceInfo serviceInfo) {
- DiscoveredNodeData discoveredNodeData = new DiscoveredNodeData(serviceInfo);
- Log.d(TAG, "DiscoveredNodeData resolved: " + discoveredNodeData);
-
- if (nsdManagerResolverAvailState != null) {
- nsdManagerResolverAvailState.signalFree();
- }
-
- if (isPassingDeviceTypeFilter(discoveredNodeData)) {
- addCommissioningInfo(discoveredNodeData);
- successCallback.handle(discoveredNodeData);
- } else {
- Log.d(
- TAG,
- "DiscoveredNodeData ignored because it did not pass the device type filter "
- + discoveredNodeData);
- }
- }
-
- @Override
- public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
- if (nsdManagerResolverAvailState != null) {
- if (errorCode != NsdManager.FAILURE_ALREADY_ACTIVE
- || resolutionAttemptNumber >= MAX_RESOLUTION_ATTEMPTS) {
- nsdManagerResolverAvailState.signalFree();
- }
- }
-
- switch (errorCode) {
- case NsdManager.FAILURE_ALREADY_ACTIVE:
- Log.e(TAG, "NsdResolveListener FAILURE_ALREADY_ACTIVE - Service: " + serviceInfo);
- if (resolutionAttemptNumber < MAX_RESOLUTION_ATTEMPTS) {
- Log.d(TAG, "NsdResolveListener Scheduling a retry to resolve service " + serviceInfo);
- Executors.newSingleThreadScheduledExecutor()
- .schedule(
- new Runnable() {
- @Override
- public void run() {
- nsdManager.resolveService(
- serviceInfo,
- new NsdResolveListener(
- nsdManager,
- deviceTypeFilter,
- preCommissionedVideoPlayers,
- successCallback,
- failureCallback,
- nsdManagerResolverAvailState,
- resolutionAttemptNumber + 1));
- }
- },
- RESOLUTION_ATTEMPT_DELAY_SECS,
- TimeUnit.SECONDS);
- } else { // giving up
- failureCallback.handle(
- new MatterError(
- 3, "NsdResolveListener FAILURE_ALREADY_ACTIVE - Service: " + serviceInfo));
- }
- break;
- case NsdManager.FAILURE_INTERNAL_ERROR:
- Log.e(TAG, "NsdResolveListener FAILURE_INTERNAL_ERROR - Service: " + serviceInfo);
- failureCallback.handle(
- new MatterError(
- 3, "NsdResolveListener FAILURE_INTERNAL_ERROR - Service: " + serviceInfo));
- break;
- case NsdManager.FAILURE_MAX_LIMIT:
- Log.e(TAG, "NsdResolveListener FAILURE_MAX_LIMIT - Service: " + serviceInfo);
- failureCallback.handle(
- new MatterError(19, "NsdResolveListener FAILURE_MAX_LIMIT - Service: " + serviceInfo));
- break;
- }
- }
-
- private boolean isPassingDeviceTypeFilter(DiscoveredNodeData discoveredNodeData) {
- return deviceTypeFilter == null
- || deviceTypeFilter.isEmpty()
- || deviceTypeFilter.contains(discoveredNodeData.getDeviceType());
- }
-
- private void addCommissioningInfo(DiscoveredNodeData discoveredNodeData) {
- if (preCommissionedVideoPlayers != null) {
- long currentUnixTimeMS = System.currentTimeMillis();
- for (VideoPlayer videoPlayer : preCommissionedVideoPlayers) {
- if (videoPlayer.isSameAs(discoveredNodeData)) {
- Log.d(
- TAG,
- "Matching Video Player with the following information found for DiscoveredNodeData"
- + videoPlayer);
- Log.d(TAG, "Updating discovery timestamp for VideoPlayer to " + currentUnixTimeMS);
- videoPlayer.setLastDiscoveredMs(currentUnixTimeMS);
- discoveredNodeData.setConnectableVideoPlayer(videoPlayer);
- return;
- }
- }
- }
- Log.d(
- TAG,
- "No matching VideoPlayers found from the cache for new DiscoveredNodeData: "
- + discoveredNodeData);
- }
-}
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java
deleted file mode 100644
index 9dd0fa500d9e2b..00000000000000
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/TvCastingApp.java
+++ /dev/null
@@ -1,608 +0,0 @@
-/*
- * Copyright (c) 2022 Project CHIP Authors
- * All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package com.chip.casting;
-
-import android.content.Context;
-import android.net.nsd.NsdManager;
-import android.net.wifi.WifiManager;
-import android.util.Log;
-import chip.appserver.ChipAppServer;
-import chip.platform.AndroidBleManager;
-import chip.platform.AndroidChipPlatform;
-import chip.platform.ChipMdnsCallbackImpl;
-import chip.platform.DiagnosticDataProviderImpl;
-import chip.platform.NsdManagerServiceBrowser;
-import chip.platform.NsdManagerServiceResolver;
-import chip.platform.PreferencesKeyValueStoreManager;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-import java.util.function.Predicate;
-
-public class TvCastingApp {
- private static final String TAG = TvCastingApp.class.getSimpleName();
- private static final String DISCOVERY_TARGET_SERVICE_TYPE = "_matterd._udp.";
- private static final List DISCOVERY_TARGET_DEVICE_TYPE_FILTER =
- Arrays.asList(35L); // Video player = 35;
-
- // delay before which we assume undiscovered cached players may be in STR mode
- private static final long CHIP_DEVICE_CONFIG_STR_DISCOVERY_DELAY_SEC = 5;
-
- private static TvCastingApp sInstance;
- private Context applicationContext;
- private ChipAppServer chipAppServer;
- private NsdManagerServiceResolver.NsdManagerResolverAvailState nsdManagerResolverAvailState;
- private boolean discoveryStarted = false;
- private Object discoveryLock = new Object();
-
- private List discoveredPlayers;
- private ScheduledFuture> reportSleepingVideoPlayerCommissionersFuture;
-
- private WifiManager.MulticastLock multicastLock;
- private NsdManager nsdManager;
- private NsdDiscoveryListener nsdDiscoveryListener;
-
- private TvCastingApp() {}
-
- public static TvCastingApp getInstance() {
- if (sInstance == null) {
- sInstance = new TvCastingApp();
- }
- return sInstance;
- }
-
- public boolean initApp(Context applicationContext, AppParameters appParameters) {
- if (applicationContext == null
- || appParameters == null
- || appParameters.getConfigurationManager() == null) {
- return false;
- }
-
- this.applicationContext = applicationContext;
- nsdManagerResolverAvailState = new NsdManagerServiceResolver.NsdManagerResolverAvailState();
- NsdManagerServiceResolver nsdManagerServiceResolver =
- new NsdManagerServiceResolver(applicationContext, nsdManagerResolverAvailState);
-
- AndroidChipPlatform chipPlatform =
- new AndroidChipPlatform(
- new AndroidBleManager(),
- new PreferencesKeyValueStoreManager(applicationContext),
- appParameters.getConfigurationManager(),
- nsdManagerServiceResolver,
- new NsdManagerServiceBrowser(applicationContext),
- new ChipMdnsCallbackImpl(),
- new DiagnosticDataProviderImpl(applicationContext));
-
- boolean ret =
- chipPlatform.updateCommissionableDataProviderData(
- appParameters.getSpake2pVerifierBase64(),
- appParameters.getSpake2pSaltBase64(),
- appParameters.getSpake2pIterationCount(),
- appParameters.getSetupPasscode(),
- appParameters.getDiscriminator());
- if (!ret) {
- Log.e(
- TAG,
- "TvCastingApp.initApp failed to updateCommissionableDataProviderData on chipPlatform");
- return ret;
- }
-
- ret = preInitJni(appParameters);
- if (!ret) {
- Log.e(TAG, "TvCastingApp.initApp failed in preInitJni");
- return ret;
- }
-
- chipAppServer = new ChipAppServer();
- ret = chipAppServer.startApp();
- if (!ret) {
- Log.e(TAG, "TvCastingApp.initApp failed in start chipAppServer");
- return ret;
- }
-
- return initJni(appParameters);
- }
-
- public native void setDACProvider(DACProvider provider);
-
- private native boolean preInitJni(AppParameters appParameters);
-
- private native boolean initJni(AppParameters appParameters);
-
- public void discoverVideoPlayerCommissioners(
- SuccessCallback discoverySuccessCallback,
- FailureCallback discoveryFailureCallback) {
- synchronized (discoveryLock) {
- Log.d(TAG, "TvCastingApp.discoverVideoPlayerCommissioners called");
-
- if (this.discoveryStarted) {
- Log.d(TAG, "Discovery already started, stopping before starting again");
- stopVideoPlayerDiscovery();
- }
-
- List preCommissionedVideoPlayers = readCachedVideoPlayers();
-
- WifiManager wifiManager =
- (WifiManager) applicationContext.getSystemService(Context.WIFI_SERVICE);
- multicastLock = wifiManager.createMulticastLock("multicastLock");
- multicastLock.setReferenceCounted(true);
- multicastLock.acquire();
-
- nsdManager = (NsdManager) applicationContext.getSystemService(Context.NSD_SERVICE);
- discoveredPlayers = new ArrayList<>();
- nsdDiscoveryListener =
- new NsdDiscoveryListener(
- nsdManager,
- DISCOVERY_TARGET_SERVICE_TYPE,
- DISCOVERY_TARGET_DEVICE_TYPE_FILTER,
- preCommissionedVideoPlayers,
- new SuccessCallback() {
- @Override
- public void handle(DiscoveredNodeData commissioner) {
- Log.d(TAG, "Discovered commissioner added " + commissioner);
- discoveredPlayers.add(commissioner);
- discoverySuccessCallback.handle(commissioner);
- }
- },
- discoveryFailureCallback,
- nsdManagerResolverAvailState);
-
- nsdManager.discoverServices(
- DISCOVERY_TARGET_SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, nsdDiscoveryListener);
- Log.d(TAG, "TvCastingApp.discoverVideoPlayerCommissioners started");
-
- /**
- * Surface players (as DiscoveredNodeData objects on discoverySuccessCallback) that we
- * previously connected to and received their WakeOnLAN MACAddress, but could not discover
- * over DNS-SD this time in CHIP_DEVICE_CONFIG_STR_DISCOVERY_DELAY_SEC. This API will also
- * ensure that the reported players were previously discoverable within
- * CHIP_DEVICE_CONFIG_STR_CACHE_LAST_DISCOVERED_HOURS.
- *
- * The DiscoveredNodeData object for such players will have the IsAsleep attribute set to
- * true, which can optionally be used for any special UX treatment when displaying them.
- *
- *
Surfacing such players as discovered will allow displaying them to the user, who may
- * want to cast to them. In such a case, the VerifyOrEstablishConnection API will turn them on
- * over WakeOnLan.
- */
- this.reportSleepingVideoPlayerCommissionersFuture =
- Executors.newScheduledThreadPool(1)
- .schedule(
- () -> {
- Log.d(
- TAG,
- "Scheduling reportSleepingCommissioners with commissioner count "
- + (preCommissionedVideoPlayers != null
- ? preCommissionedVideoPlayers.size()
- : 0));
- reportSleepingVideoPlayerCommissioners(
- preCommissionedVideoPlayers, discoverySuccessCallback);
- },
- CHIP_DEVICE_CONFIG_STR_DISCOVERY_DELAY_SEC * 1000,
- TimeUnit.MILLISECONDS);
-
- this.discoveryStarted = true;
- }
- }
-
- private void reportSleepingVideoPlayerCommissioners(
- List cachedVideoPlayers,
- SuccessCallback discoverySuccessCallback) {
- Log.d(
- TAG,
- "TvCastingApp.reportSleepingVideoPlayerCommissioners called with commissioner count "
- + (cachedVideoPlayers != null ? cachedVideoPlayers.size() : 0));
- if (cachedVideoPlayers == null) {
- Log.d(TAG, "No cached video players available.");
- return;
- }
-
- for (VideoPlayer player : cachedVideoPlayers) {
- Log.d(TAG, "Cached Video Player: " + player);
- // do NOT surface this cached Player if we don't have its MACAddress
- if (player.getMACAddress() == null) {
- Log.d(
- TAG,
- "TvCastingApp.reportSleepingVideoPlayerCommissioners Skipping Player with hostName"
- + player.getHostName()
- + " but no MACAddress");
- continue;
- }
-
- // do NOT surface this cached Player if it has not been discoverable recently (in
- // CHIP_DEVICE_CONFIG_STR_CACHE_LAST_DISCOVERED_HOURS)
- if (!WasRecentlyDiscoverable(player)) {
- Log.d(
- TAG,
- "TvCastingApp.reportSleepingVideoPlayerCommissioners Skipping Player with hostName"
- + player.getHostName()
- + " that has not been discovered recently");
- continue;
- }
-
- // do NOT surface this cached Player if it was just discovered right now (in this discovery
- // call)
- boolean justDiscovered =
- discoveredPlayers
- .stream()
- .anyMatch(
- new Predicate() {
- @Override
- public boolean test(DiscoveredNodeData discoveredNodeData) {
- return player.getHostName().equals(discoveredNodeData.getHostName());
- }
- });
- if (justDiscovered) {
- Log.d(
- TAG,
- "TvCastingApp.reportSleepingVideoPlayerCommissioners Skipping Player with hostName"
- + player.getHostName()
- + " that was just discovered");
- continue;
- }
-
- // DO surface this cached Player (as asleep)
- Log.d(TAG, "Reporting sleeping player with hostName " + player.getHostName());
- player.setIsAsleep(true);
- discoverySuccessCallback.handle(new DiscoveredNodeData(player));
- }
- }
-
- private native boolean WasRecentlyDiscoverable(VideoPlayer player);
-
- public void stopVideoPlayerDiscovery() {
- synchronized (discoveryLock) {
- Log.d(TAG, "TvCastingApp trying to stop video player discovery");
- if (this.discoveryStarted
- && nsdManager != null
- && multicastLock != null
- && nsdDiscoveryListener != null) {
- Log.d(TAG, "TvCastingApp stopping Video Player commissioner discovery");
- try {
- nsdManager.stopServiceDiscovery(nsdDiscoveryListener);
- } catch (IllegalArgumentException e) {
- Log.w(
- TAG,
- "TvCastingApp received exception on calling nsdManager.stopServiceDiscovery() "
- + e.getMessage());
- }
-
- if (multicastLock.isHeld()) {
- multicastLock.release();
- }
-
- if (reportSleepingVideoPlayerCommissionersFuture != null) {
- reportSleepingVideoPlayerCommissionersFuture.cancel(false);
- }
- this.discoveryStarted = false;
- }
- }
- }
-
- void resetDiscoveryState() {
- synchronized (discoveryLock) {
- Log.d(TAG, "TvCastingApp resetting discovery state");
- this.discoveryStarted = false;
- this.nsdDiscoveryListener = null;
- if (multicastLock != null && multicastLock.isHeld()) {
- multicastLock.release();
- }
- }
- }
-
- public native boolean openBasicCommissioningWindow(
- int duration,
- CommissioningCallbacks commissioningCallbacks,
- SuccessCallback onConnectionSuccess,
- FailureCallback onConnectionFailure,
- SuccessCallback onNewOrUpdatedEndpointCallback);
-
- public native boolean sendCommissioningRequest(DiscoveredNodeData commissioner);
-
- /** @Deprecated Use sendCommissioningRequest(DiscoveredNodeData) instead */
- private native boolean sendUserDirectedCommissioningRequest(String address, int port);
-
- public native List readCachedVideoPlayers();
-
- public native boolean verifyOrEstablishConnection(
- VideoPlayer targetVideoPlayer,
- SuccessCallback onConnectionSuccess,
- FailureCallback onConnectionFailure,
- SuccessCallback onNewOrUpdatedEndpointCallback);
-
- public native void shutdownAllSubscriptions();
-
- public native void disconnect();
-
- public native List getActiveTargetVideoPlayers();
-
- public native boolean purgeCache();
-
- /*
- * CONTENT LAUNCHER CLUSTER
- *
- * TODO: Add API to subscribe to AcceptHeader
- */
- public native boolean contentLauncherLaunchURL(
- ContentApp contentApp, String contentUrl, String contentDisplayStr, Object launchURLHandler);
-
- public native boolean contentLauncher_launchContent(
- ContentApp contentApp,
- ContentLauncherTypes.ContentSearch search,
- boolean autoPlay,
- String data,
- Object responseHandler);
-
- public native boolean contentLauncher_subscribeToSupportedStreamingProtocols(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- /*
- * LEVEL CONTROL CLUSTER
- */
- public native boolean levelControl_step(
- ContentApp contentApp,
- byte stepMode,
- byte stepSize,
- short transitionTime,
- byte optionMask,
- byte optionOverridem,
- Object responseHandler);
-
- public native boolean levelControl_moveToLevel(
- ContentApp contentApp,
- byte level,
- short transitionTime,
- byte optionMask,
- byte optionOverridem,
- Object responseHandler);
-
- public native boolean levelControl_subscribeToCurrentLevel(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- public native boolean levelControl_subscribeToMinLevel(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- public native boolean levelControl_subscribeToMaxLevel(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- /*
- * MEDIA PLAYBACK CLUSTER
- */
- public native boolean mediaPlayback_play(ContentApp contentApp, Object responseHandler);
-
- public native boolean mediaPlayback_pause(ContentApp contentApp, Object responseHandler);
-
- public native boolean mediaPlayback_stopPlayback(ContentApp contentApp, Object responseHandler);
-
- public native boolean mediaPlayback_next(ContentApp contentApp, Object responseHandler);
-
- public native boolean mediaPlayback_previous(ContentApp contentApp, Object responseHandler);
-
- public native boolean mediaPlayback_rewind(ContentApp contentApp, Object responseHandler);
-
- public native boolean mediaPlayback_fastForward(ContentApp contentApp, Object responseHandler);
-
- public native boolean mediaPlayback_startOver(ContentApp contentApp, Object responseHandler);
-
- public native boolean mediaPlayback_seek(
- ContentApp contentApp, long position, Object responseHandler);
-
- public native boolean mediaPlayback_skipForward(
- ContentApp contentApp, long deltaPositionMilliseconds, Object responseHandler);
-
- public native boolean mediaPlayback_skipBackward(
- ContentApp contentApp, long deltaPositionMilliseconds, Object responseHandler);
-
- public native boolean mediaPlayback_subscribeToCurrentState(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- public native boolean mediaPlayback_subscribeToDuration(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- public native boolean mediaPlayback_subscribeToSampledPosition(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- public native boolean mediaPlayback_subscribeToPlaybackSpeed(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- public native boolean mediaPlayback_subscribeToSeekRangeEnd(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- public native boolean mediaPlayback_subscribeToSeekRangeStart(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- /*
- * APPLICATION LAUNCHER CLUSTER
- */
- public native boolean applicationLauncher_launchApp(
- ContentApp contentApp,
- short catalogVendorId,
- String applicationId,
- byte[] data,
- Object responseHandler);
-
- public native boolean applicationLauncher_stopApp(
- ContentApp contentApp, short catalogVendorId, String applicationId, Object responseHandler);
-
- public native boolean applicationLauncher_hideApp(
- ContentApp contentApp, short catalogVendorId, String applicationId, Object responseHandler);
-
- /*
- * TARGET NAVIGATOR CLUSTER
- */
- public native boolean targetNavigator_navigateTarget(
- ContentApp contentApp, byte target, String data, Object responseHandler);
-
- public native boolean targetNavigator_subscribeToCurrentTarget(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- public native boolean targetNavigator_subscribeToTargetList(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- /*
- * KEYPAD INPUT CLUSTER
- */
- public native boolean keypadInput_sendKey(
- ContentApp contentApp, byte keyCode, Object responseHandler);
-
- /**
- * APPLICATION BASIC
- *
- * TODO: Add APIs to subscribe to & read Application, Status and AllowedVendorList
- */
- public native boolean applicationBasic_subscribeToVendorName(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- public native boolean applicationBasic_subscribeToVendorID(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- public native boolean applicationBasic_subscribeToApplicationName(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- public native boolean applicationBasic_subscribeToProductID(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- public native boolean applicationBasic_subscribeToApplicationVersion(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler,
- int minInterval,
- int maxInterval,
- SubscriptionEstablishedCallback subscriptionEstablishedHandler);
-
- public native boolean applicationBasic_readVendorName(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler);
-
- public native boolean applicationBasic_readVendorID(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler);
-
- public native boolean applicationBasic_readApplicationName(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler);
-
- public native boolean applicationBasic_readProductID(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler);
-
- public native boolean applicationBasic_readApplicationVersion(
- ContentApp contentApp,
- SuccessCallback readSuccessHandler,
- FailureCallback readFailureHandler);
-
- public native boolean onOff_on(ContentApp contentApp, Object responseHandler);
-
- public native boolean onOff_off(ContentApp contentApp, Object responseHandler);
-
- public native boolean onOff_toggle(ContentApp contentApp, Object responseHandler);
-
- public native boolean messages_presentMessages(
- ContentApp contentApp, String messageText, Object responseHandler);
-
- static {
- System.loadLibrary("TvCastingApp");
- }
-}
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/DataProvider.java b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/DataProvider.java
index 854cf76ce8aca8..63e8da3d31b609 100644
--- a/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/DataProvider.java
+++ b/examples/tv-casting-app/android/App/app/src/main/jni/com/matter/casting/support/DataProvider.java
@@ -20,7 +20,7 @@
import android.util.Log;
public interface DataProvider {
- public static final String TAG = DataProvider.class.getSimpleName();
+ String TAG = DataProvider.class.getSimpleName();
default T _get() {
T val = null;
@@ -32,5 +32,5 @@ default T _get() {
return val;
}
- public abstract T get();
+ T get();
}
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/Constants.h b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/Constants.h
deleted file mode 100644
index 735cabf2375f51..00000000000000
--- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/Constants.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2022 Project CHIP Authors
- * All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#pragma once
-
-enum MediaCommandName
-{
- ContentLauncher_LaunchURL,
- ContentLauncher_LaunchContent,
- LevelControl_Step,
- LevelControl_MoveToLevel,
- OnOff_On,
- OnOff_Off,
- OnOff_Toggle,
- MediaPlayback_Play,
- MediaPlayback_Pause,
- MediaPlayback_StopPlayback,
- MediaPlayback_Next,
- MediaPlayback_Previous,
- MediaPlayback_Rewind,
- MediaPlayback_FastForward,
- MediaPlayback_StartOver,
- MediaPlayback_Seek,
- MediaPlayback_SkipForward,
- MediaPlayback_SkipBackward,
- Messages_PresentMessagesRequest,
- ApplicationLauncher_LaunchApp,
- ApplicationLauncher_StopApp,
- ApplicationLauncher_HideApp,
- TargetNavigator_NavigateTarget,
- KeypadInput_SendKey,
-
- MEDIA_COMMAND_COUNT
-};
-
-enum MediaAttributeName
-{
- ContentLauncher_SupportedStreamingProtocols,
- ContentLauncher_AcceptHeader,
- LevelControl_CurrentLevel,
- LevelControl_MinLevel,
- LevelControl_MaxLevel,
- MediaPlayback_CurrentState,
- MediaPlayback_StartTime,
- MediaPlayback_Duration,
- MediaPlayback_SampledPosition,
- MediaPlayback_PlaybackSpeed,
- MediaPlayback_SeekRangeEnd,
- MediaPlayback_SeekRangeStart,
- ApplicationLauncher_CurrentApp,
- TargetNavigator_TargetList,
- TargetNavigator_CurrentTarget,
- ApplicationBasic_VendorName,
- ApplicationBasic_VendorID,
- ApplicationBasic_ApplicationName,
- ApplicationBasic_ProductID,
- ApplicationBasic_ApplicationVersion,
-
- MEDIA_ATTRIBUTE_COUNT
-};
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp
deleted file mode 100644
index c8a38942e60234..00000000000000
--- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.cpp
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- *
- * Copyright (c) 2021 Project CHIP Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "ConversionUtils.h"
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-CHIP_ERROR convertJAppParametersToCppAppParams(jobject appParameters, AppParams & outAppParams)
-{
- ChipLogProgress(AppServer, "convertJAppParametersToCppAppParams called");
- JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
- VerifyOrReturnError(appParameters != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
-
- jclass jAppParametersClass;
- ReturnErrorOnFailure(
- chip::JniReferences::GetInstance().GetLocalClassRef(env, "com/chip/casting/AppParameters", jAppParametersClass));
-
- jmethodID getRotatingDeviceIdUniqueIdMethod = env->GetMethodID(jAppParametersClass, "getRotatingDeviceIdUniqueId", "()[B");
- if (getRotatingDeviceIdUniqueIdMethod == nullptr)
- {
- ChipLogError(Zcl, "Failed to access AppParameters 'getRotatingDeviceIdUniqueId' method");
- env->ExceptionClear();
- }
-
- jobject jRotatingDeviceIdUniqueId = (jobject) env->CallObjectMethod(appParameters, getRotatingDeviceIdUniqueIdMethod);
- if (env->ExceptionCheck())
- {
- ChipLogError(Zcl, "Java exception in AppParameters::getRotatingDeviceIdUniqueId");
- env->ExceptionDescribe();
- env->ExceptionClear();
- return CHIP_ERROR_INCORRECT_STATE;
- }
-
- if (jRotatingDeviceIdUniqueId != nullptr)
- {
- chip::JniByteArray * jniRotatingDeviceIdUniqueIdByteArray =
- new chip::JniByteArray(env, static_cast(jRotatingDeviceIdUniqueId));
- outAppParams.SetRotatingDeviceIdUniqueId(MakeOptional(jniRotatingDeviceIdUniqueIdByteArray->byteSpan()));
- }
-
- return CHIP_NO_ERROR;
-}
-
-CHIP_ERROR convertJContentAppToTargetEndpointInfo(jobject contentApp, TargetEndpointInfo & outTargetEndpointInfo)
-{
- ChipLogProgress(AppServer, "convertJContentAppToTargetEndpointInfo called");
- VerifyOrReturnError(contentApp != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
- JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
-
- jclass jContentAppClass;
- ReturnErrorOnFailure(chip::JniReferences::GetInstance().GetLocalClassRef(env, "com/chip/casting/ContentApp", jContentAppClass));
-
- jfieldID jEndpointIdField = env->GetFieldID(jContentAppClass, "endpointId", "S");
- jshort jEndpointId = env->GetShortField(contentApp, jEndpointIdField);
- outTargetEndpointInfo.Initialize(static_cast(jEndpointId));
-
- jfieldID jclusterIdsField = env->GetFieldID(jContentAppClass, "clusterIds", "Ljava/util/List;");
- jobject jClusterIds = env->GetObjectField(contentApp, jclusterIdsField);
- if (jClusterIds == nullptr)
- {
- return CHIP_NO_ERROR;
- }
-
- jobject jIterator = env->CallObjectMethod(
- jClusterIds, env->GetMethodID(env->GetObjectClass(jClusterIds), "iterator", "()Ljava/util/Iterator;"));
- jmethodID jNextMid = env->GetMethodID(env->GetObjectClass(jIterator), "next", "()Ljava/lang/Object;");
- jmethodID jHasNextMid = env->GetMethodID(env->GetObjectClass(jIterator), "hasNext", "()Z");
-
- while (env->CallBooleanMethod(jIterator, jHasNextMid))
- {
- jobject jClusterId = env->CallObjectMethod(jIterator, jNextMid);
- jclass jIntegerClass = env->FindClass("java/lang/Integer");
- jmethodID jIntValueMid = env->GetMethodID(jIntegerClass, "intValue", "()I");
- outTargetEndpointInfo.AddCluster(static_cast(env->CallIntMethod(jClusterId, jIntValueMid)));
- }
-
- return CHIP_NO_ERROR;
-}
-
-CHIP_ERROR convertTargetEndpointInfoToJContentApp(TargetEndpointInfo * targetEndpointInfo, jobject & outContentApp)
-{
- ChipLogProgress(AppServer, "convertTargetEndpointInfoToJContentApp called");
- if (targetEndpointInfo != nullptr && targetEndpointInfo->IsInitialized())
- {
- JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
-
- jclass jContentAppClass;
- ReturnErrorOnFailure(
- chip::JniReferences::GetInstance().GetLocalClassRef(env, "com/chip/casting/ContentApp", jContentAppClass));
- jmethodID jContentAppConstructor = env->GetMethodID(jContentAppClass, "", "(SLjava/util/List;)V");
- chip::ClusterId * clusters = targetEndpointInfo->GetClusters();
- jobject jClustersArrayList = nullptr;
- if (clusters != nullptr)
- {
- chip::JniReferences::GetInstance().CreateArrayList(jClustersArrayList);
- for (size_t i = 0; i < kMaxNumberOfClustersPerEndpoint && clusters[i] != chip::kInvalidClusterId; i++)
- {
- jobject jCluster = nullptr;
- jint jniclusterId = static_cast(clusters[i]);
- chip::JniReferences::GetInstance().CreateBoxedObject("java/lang/Integer", "(I)V", jniclusterId, jCluster);
- chip::JniReferences::GetInstance().AddToList(jClustersArrayList, jCluster);
- }
- }
- outContentApp =
- env->NewObject(jContentAppClass, jContentAppConstructor, targetEndpointInfo->GetEndpointId(), jClustersArrayList);
- }
- return CHIP_NO_ERROR;
-}
-
-CHIP_ERROR convertJVideoPlayerToTargetVideoPlayerInfo(jobject videoPlayer, TargetVideoPlayerInfo & outTargetVideoPlayerInfo)
-{
- ChipLogProgress(AppServer, "convertJVideoPlayerToTargetVideoPlayerInfo called");
- VerifyOrReturnError(videoPlayer != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
- JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
-
- jclass jVideoPlayerClass;
- ReturnErrorOnFailure(
- chip::JniReferences::GetInstance().GetLocalClassRef(env, "com/chip/casting/VideoPlayer", jVideoPlayerClass));
-
- jfieldID jNodeIdField = env->GetFieldID(jVideoPlayerClass, "nodeId", "J");
- chip::NodeId nodeId = static_cast(env->GetLongField(videoPlayer, jNodeIdField));
-
- jfieldID jFabricIndexField = env->GetFieldID(jVideoPlayerClass, "fabricIndex", "B");
- chip::FabricIndex fabricIndex = static_cast(env->GetByteField(videoPlayer, jFabricIndexField));
-
- jfieldID jVendorIdField = env->GetFieldID(jVideoPlayerClass, "vendorId", "I");
- uint16_t vendorId = static_cast(env->GetIntField(videoPlayer, jVendorIdField));
-
- jfieldID jProductIdField = env->GetFieldID(jVideoPlayerClass, "productId", "I");
- uint16_t productId = static_cast(env->GetIntField(videoPlayer, jProductIdField));
-
- jfieldID jDeviceType = env->GetFieldID(jVideoPlayerClass, "deviceType", "I");
- uint16_t deviceType = static_cast(env->GetIntField(videoPlayer, jDeviceType));
-
- jfieldID getDeviceNameField = env->GetFieldID(jVideoPlayerClass, "deviceName", "Ljava/lang/String;");
- jstring jDeviceName = static_cast(env->GetObjectField(videoPlayer, getDeviceNameField));
- const char * deviceName = env->GetStringUTFChars(jDeviceName, 0);
-
- jfieldID getHostNameField = env->GetFieldID(jVideoPlayerClass, "hostName", "Ljava/lang/String;");
- jstring jHostName = static_cast(env->GetObjectField(videoPlayer, getHostNameField));
- const char * hostName = env->GetStringUTFChars(jHostName, 0);
-
- jfieldID jPort = env->GetFieldID(jVideoPlayerClass, "port", "I");
- uint16_t port = static_cast(env->GetIntField(videoPlayer, jPort));
-
- jfieldID getInstanceNameField = env->GetFieldID(jVideoPlayerClass, "instanceName", "Ljava/lang/String;");
- jstring jInstanceName = static_cast(env->GetObjectField(videoPlayer, getInstanceNameField));
- const char * instanceName = {};
- if (jInstanceName != nullptr)
- {
- instanceName = env->GetStringUTFChars(jInstanceName, 0);
- }
-
- jfieldID jLastDiscoveredMs = env->GetFieldID(jVideoPlayerClass, "lastDiscoveredMs", "J");
- long lastDiscoveredMs = static_cast(env->GetLongField(videoPlayer, jLastDiscoveredMs));
-
- jfieldID getMACAddressField = env->GetFieldID(jVideoPlayerClass, "MACAddress", "Ljava/lang/String;");
- jstring jMACAddress = static_cast(env->GetObjectField(videoPlayer, getMACAddressField));
- const char * MACAddress = jMACAddress == nullptr ? nullptr : env->GetStringUTFChars(jMACAddress, 0);
-
- jfieldID jIsAsleep = env->GetFieldID(jVideoPlayerClass, "isAsleep", "Z");
- bool isAsleep = static_cast(env->GetBooleanField(videoPlayer, jIsAsleep));
-
- outTargetVideoPlayerInfo.Initialize(nodeId, fabricIndex, nullptr, nullptr, vendorId, productId, deviceType, deviceName,
- hostName, 0, nullptr, port, instanceName, chip::System::Clock::Timestamp(lastDiscoveredMs));
-
- if (MACAddress != nullptr)
- {
- chip::CharSpan MACAddressSpan(MACAddress, 2 * 2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength);
- outTargetVideoPlayerInfo.SetMACAddress(MACAddressSpan);
- }
-
- outTargetVideoPlayerInfo.SetIsAsleep(isAsleep);
-
- jfieldID jContentAppsField = env->GetFieldID(jVideoPlayerClass, "contentApps", "Ljava/util/List;");
- jobject jContentApps = env->GetObjectField(videoPlayer, jContentAppsField);
- if (jContentApps == nullptr)
- {
- return CHIP_NO_ERROR;
- }
-
- jobject jIterator = env->CallObjectMethod(
- jContentApps, env->GetMethodID(env->GetObjectClass(jContentApps), "iterator", "()Ljava/util/Iterator;"));
- jmethodID jNextMid = env->GetMethodID(env->GetObjectClass(jIterator), "next", "()Ljava/lang/Object;");
- jmethodID jHasNextMid = env->GetMethodID(env->GetObjectClass(jIterator), "hasNext", "()Z");
-
- while (env->CallBooleanMethod(jIterator, jHasNextMid))
- {
- jobject jContentApp = env->CallObjectMethod(jIterator, jNextMid);
-
- jclass jContentAppClass;
- ReturnErrorOnFailure(
- chip::JniReferences::GetInstance().GetLocalClassRef(env, "com/chip/casting/ContentApp", jContentAppClass));
- jfieldID jEndpointIdField = env->GetFieldID(jContentAppClass, "endpointId", "S");
- chip::EndpointId endpointId = static_cast(env->GetShortField(jContentApp, jEndpointIdField));
- TargetEndpointInfo * endpoint = outTargetVideoPlayerInfo.GetOrAddEndpoint(endpointId);
-
- ReturnErrorOnFailure(convertJContentAppToTargetEndpointInfo(jContentApp, *endpoint));
- }
-
- return CHIP_NO_ERROR;
-}
-
-CHIP_ERROR convertTargetVideoPlayerInfoToJVideoPlayer(TargetVideoPlayerInfo * targetVideoPlayerInfo, jobject & outVideoPlayer)
-{
- ChipLogProgress(AppServer, "convertTargetVideoPlayerInfoToJVideoPlayer called");
- if (targetVideoPlayerInfo != nullptr && targetVideoPlayerInfo->IsInitialized())
- {
- JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
-
- jclass jVideoPlayerClass;
- ReturnErrorOnFailure(
- chip::JniReferences::GetInstance().GetLocalClassRef(env, "com/chip/casting/VideoPlayer", jVideoPlayerClass));
- jmethodID jVideoPlayerConstructor = env->GetMethodID(jVideoPlayerClass, "",
- "(JBLjava/lang/String;IIILjava/util/List;ILjava/util/List;Ljava/lang/"
- "String;Ljava/lang/String;IJLjava/lang/String;ZZ)V");
-
- jobject jContentAppList = nullptr;
- TargetEndpointInfo * endpoints = targetVideoPlayerInfo->GetEndpoints();
- if (endpoints != nullptr)
- {
- chip::JniReferences::GetInstance().CreateArrayList(jContentAppList);
- for (size_t i = 0; i < kMaxNumberOfEndpoints && endpoints[i].IsInitialized(); i++)
- {
- jobject contentApp = nullptr;
- ReturnErrorOnFailure(convertTargetEndpointInfoToJContentApp(&endpoints[i], contentApp));
- chip::JniReferences::GetInstance().AddToList(jContentAppList, contentApp);
- }
- }
-
- jstring deviceName =
- targetVideoPlayerInfo->GetDeviceName() == nullptr ? nullptr : env->NewStringUTF(targetVideoPlayerInfo->GetDeviceName());
-
- jstring hostName =
- targetVideoPlayerInfo->GetHostName() == nullptr ? nullptr : env->NewStringUTF(targetVideoPlayerInfo->GetHostName());
-
- jstring instanceName = targetVideoPlayerInfo->GetInstanceName() == nullptr
- ? nullptr
- : env->NewStringUTF(targetVideoPlayerInfo->GetInstanceName());
-
- jstring MACAddress = nullptr;
- if (targetVideoPlayerInfo->GetMACAddress() != nullptr && targetVideoPlayerInfo->GetMACAddress()->data() != nullptr)
- {
- char MACAddressWithNil[2 * chip::DeviceLayer::ConfigurationManager::kPrimaryMACAddressLength + 1];
- memcpy(MACAddressWithNil, targetVideoPlayerInfo->GetMACAddress()->data(),
- targetVideoPlayerInfo->GetMACAddress()->size());
- MACAddressWithNil[targetVideoPlayerInfo->GetMACAddress()->size()] = '\0';
- MACAddress = env->NewStringUTF(MACAddressWithNil);
- }
-
- jobject jIPAddressList = nullptr;
- const chip::Inet::IPAddress * ipAddresses = targetVideoPlayerInfo->GetIpAddresses();
- if (ipAddresses != nullptr)
- {
- chip::JniReferences::GetInstance().CreateArrayList(jIPAddressList);
- for (size_t i = 0; i < targetVideoPlayerInfo->GetNumIPs() && i < chip::Dnssd::CommonResolutionData::kMaxIPAddresses;
- i++)
- {
- char addrCString[chip::Inet::IPAddress::kMaxStringLength];
- ipAddresses[i].ToString(addrCString, chip::Inet::IPAddress::kMaxStringLength);
- jstring jIPAddressStr = env->NewStringUTF(addrCString);
-
- jclass jIPAddressClass;
- ReturnErrorOnFailure(
- chip::JniReferences::GetInstance().GetLocalClassRef(env, "java/net/InetAddress", jIPAddressClass));
- jmethodID jGetByNameMid =
- env->GetStaticMethodID(jIPAddressClass, "getByName", "(Ljava/lang/String;)Ljava/net/InetAddress;");
- jobject jIPAddress = env->CallStaticObjectMethod(jIPAddressClass, jGetByNameMid, jIPAddressStr);
-
- chip::JniReferences::GetInstance().AddToList(jIPAddressList, jIPAddress);
- }
- }
-
- outVideoPlayer = env->NewObject(
- jVideoPlayerClass, jVideoPlayerConstructor, targetVideoPlayerInfo->GetNodeId(), targetVideoPlayerInfo->GetFabricIndex(),
- deviceName, targetVideoPlayerInfo->GetVendorId(), targetVideoPlayerInfo->GetProductId(),
- targetVideoPlayerInfo->GetDeviceType(), jContentAppList, targetVideoPlayerInfo->GetNumIPs(), jIPAddressList, hostName,
- instanceName, targetVideoPlayerInfo->GetPort(), targetVideoPlayerInfo->GetLastDiscovered().count(), MACAddress,
- targetVideoPlayerInfo->IsAsleep(), targetVideoPlayerInfo->GetOperationalDeviceProxy() != nullptr);
- }
- return CHIP_NO_ERROR;
-}
-
-CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscoveredNodeData,
- chip::Dnssd::CommissionNodeData & outCppDiscoveredNodeData)
-{
- ChipLogProgress(AppServer, "convertJDiscoveredNodeDataToCppDiscoveredNodeData called");
- VerifyOrReturnError(jDiscoveredNodeData != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
-
- JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
-
- jclass jDiscoveredNodeDataClass;
- ReturnErrorOnFailure(
- chip::JniReferences::GetInstance().GetLocalClassRef(env, "com/chip/casting/DiscoveredNodeData", jDiscoveredNodeDataClass));
-
- jfieldID getHostNameField = env->GetFieldID(jDiscoveredNodeDataClass, "hostName", "Ljava/lang/String;");
- jstring jHostName = static_cast(env->GetObjectField(jDiscoveredNodeData, getHostNameField));
- if (jHostName != nullptr)
- {
- chip::Platform::CopyString(outCppDiscoveredNodeData.hostName, chip::Dnssd::kHostNameMaxLength + 1,
- env->GetStringUTFChars(jHostName, 0));
- }
-
- jfieldID getInstanceNameField = env->GetFieldID(jDiscoveredNodeDataClass, "instanceName", "Ljava/lang/String;");
- jstring jInstanceName = static_cast(env->GetObjectField(jDiscoveredNodeData, getInstanceNameField));
- if (jInstanceName != nullptr)
- {
- chip::Platform::CopyString(outCppDiscoveredNodeData.instanceName, chip::Dnssd::Commission::kInstanceNameMaxLength + 1,
- env->GetStringUTFChars(jInstanceName, 0));
- }
-
- jfieldID jLongDiscriminatorField = env->GetFieldID(jDiscoveredNodeDataClass, "longDiscriminator", "J");
- outCppDiscoveredNodeData.vendorId = static_cast(env->GetLongField(jDiscoveredNodeData, jLongDiscriminatorField));
-
- jfieldID jVendorIdField = env->GetFieldID(jDiscoveredNodeDataClass, "vendorId", "J");
- outCppDiscoveredNodeData.vendorId = static_cast(env->GetLongField(jDiscoveredNodeData, jVendorIdField));
-
- jfieldID jProductIdField = env->GetFieldID(jDiscoveredNodeDataClass, "productId", "J");
- outCppDiscoveredNodeData.productId = static_cast(env->GetLongField(jDiscoveredNodeData, jProductIdField));
-
- jfieldID jCommissioningModeField = env->GetFieldID(jDiscoveredNodeDataClass, "commissioningMode", "B");
- outCppDiscoveredNodeData.commissioningMode =
- static_cast(env->GetByteField(jDiscoveredNodeData, jCommissioningModeField));
-
- jfieldID jDeviceTypeField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceType", "J");
- outCppDiscoveredNodeData.deviceType = static_cast(env->GetLongField(jDiscoveredNodeData, jDeviceTypeField));
-
- jfieldID getDeviceNameField = env->GetFieldID(jDiscoveredNodeDataClass, "deviceName", "Ljava/lang/String;");
- jstring jDeviceName = static_cast(env->GetObjectField(jDiscoveredNodeData, getDeviceNameField));
- if (jDeviceName != nullptr)
- {
- chip::Platform::CopyString(outCppDiscoveredNodeData.deviceName, chip::Dnssd::kMaxDeviceNameLen + 1,
- env->GetStringUTFChars(jDeviceName, 0));
- }
-
- // TODO: map rotating ID
- jfieldID jRotatingIdLenField = env->GetFieldID(jDiscoveredNodeDataClass, "rotatingIdLen", "I");
- outCppDiscoveredNodeData.rotatingIdLen = static_cast(env->GetIntField(jDiscoveredNodeData, jRotatingIdLenField));
-
- jfieldID jPairingHintField = env->GetFieldID(jDiscoveredNodeDataClass, "pairingHint", "S");
- outCppDiscoveredNodeData.pairingHint = static_cast(env->GetShortField(jDiscoveredNodeData, jPairingHintField));
-
- jfieldID getPairingInstructionField = env->GetFieldID(jDiscoveredNodeDataClass, "pairingInstruction", "Ljava/lang/String;");
- jstring jPairingInstruction = static_cast(env->GetObjectField(jDiscoveredNodeData, getPairingInstructionField));
- if (jPairingInstruction != nullptr)
- {
- chip::Platform::CopyString(outCppDiscoveredNodeData.pairingInstruction, chip::Dnssd::kMaxPairingInstructionLen + 1,
- env->GetStringUTFChars(jPairingInstruction, 0));
- }
-
- jfieldID jPortField = env->GetFieldID(jDiscoveredNodeDataClass, "port", "I");
- outCppDiscoveredNodeData.port = static_cast(env->GetIntField(jDiscoveredNodeData, jPortField));
-
- jfieldID jNumIpsField = env->GetFieldID(jDiscoveredNodeDataClass, "numIPs", "I");
- outCppDiscoveredNodeData.numIPs = static_cast(env->GetIntField(jDiscoveredNodeData, jNumIpsField));
-
- jfieldID jIPAddressesField = env->GetFieldID(jDiscoveredNodeDataClass, "ipAddresses", "Ljava/util/List;");
- jobject jIPAddresses = env->GetObjectField(jDiscoveredNodeData, jIPAddressesField);
- if (jIPAddresses == nullptr && outCppDiscoveredNodeData.numIPs > 0)
- {
- return CHIP_ERROR_INVALID_ARGUMENT;
- }
-
- jobject jIterator = env->CallObjectMethod(
- jIPAddresses, env->GetMethodID(env->GetObjectClass(jIPAddresses), "iterator", "()Ljava/util/Iterator;"));
- jmethodID jNextMid = env->GetMethodID(env->GetObjectClass(jIterator), "next", "()Ljava/lang/Object;");
- jmethodID jHasNextMid = env->GetMethodID(env->GetObjectClass(jIterator), "hasNext", "()Z");
-
- size_t ipAddressCount = 0;
- while (env->CallBooleanMethod(jIterator, jHasNextMid))
- {
- jobject jIPAddress = env->CallObjectMethod(jIterator, jNextMid);
- jclass jIPAddressClass;
- ReturnErrorOnFailure(chip::JniReferences::GetInstance().GetLocalClassRef(env, "java/net/InetAddress", jIPAddressClass));
- jmethodID jGetHostAddressMid = env->GetMethodID(jIPAddressClass, "getHostAddress", "()Ljava/lang/String;");
- jstring jIPAddressStr = static_cast(env->CallObjectMethod(jIPAddress, jGetHostAddressMid));
-
- chip::Inet::IPAddress addressInet;
- chip::JniUtfString addressJniString(env, jIPAddressStr);
- VerifyOrReturnError(chip::Inet::IPAddress::FromString(addressJniString.c_str(), addressInet), CHIP_ERROR_INVALID_ARGUMENT);
- outCppDiscoveredNodeData.ipAddress[ipAddressCount] = addressInet;
-
- if (ipAddressCount == 0)
- {
- outCppDiscoveredNodeData.interfaceId = chip::Inet::InterfaceId::FromIPAddress(addressInet);
- }
- ipAddressCount++;
- }
-
- return CHIP_NO_ERROR;
-}
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.h b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.h
deleted file mode 100644
index 28f5a1abd28c5a..00000000000000
--- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/ConversionUtils.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- *
- * Copyright (c) 2021 Project CHIP Authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include "AppParams.h"
-#include "TargetEndpointInfo.h"
-#include "TargetVideoPlayerInfo.h"
-
-#include
-
-CHIP_ERROR convertJAppParametersToCppAppParams(jobject appParameters, AppParams & outAppParams);
-
-CHIP_ERROR convertJContentAppToTargetEndpointInfo(jobject contentApp, TargetEndpointInfo & outTargetEndpointInfo);
-
-CHIP_ERROR convertTargetEndpointInfoToJContentApp(TargetEndpointInfo * targetEndpointInfo, jobject & outContentApp);
-
-CHIP_ERROR convertJVideoPlayerToTargetVideoPlayerInfo(jobject videoPlayer, TargetVideoPlayerInfo & targetVideoPlayerInfo);
-
-CHIP_ERROR convertTargetVideoPlayerInfoToJVideoPlayer(TargetVideoPlayerInfo * targetVideoPlayerInfo, jobject & outVideoPlayer);
-
-CHIP_ERROR convertJDiscoveredNodeDataToCppDiscoveredNodeData(jobject jDiscoveredNodeData,
- chip::Dnssd::CommissionNodeData & cppDiscoveredNodeData);
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp
deleted file mode 100644
index ca62ba5f37ee22..00000000000000
--- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.cpp
+++ /dev/null
@@ -1,419 +0,0 @@
-/*
- *
- * Copyright (c) 2022 Project CHIP Authors
- * All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "MatterCallbackHandler-JNI.h"
-
-#include
-
-using namespace chip;
-
-CHIP_ERROR CallbackBaseJNI::SetUp(JNIEnv * env, jobject inHandler)
-{
- ChipLogProgress(AppServer, "CallbackBaseJNI::SetUp called");
- CHIP_ERROR err = CHIP_NO_ERROR;
-
- VerifyOrExit(mObject.Init(inHandler) == CHIP_NO_ERROR, ChipLogError(AppServer, "Failed to Init mObject"));
-
- mClazz = env->GetObjectClass(mObject.ObjectRef());
- VerifyOrExit(mClazz != nullptr, ChipLogError(AppServer, "Failed to get handler Java class"));
-
- mSuperClazz = env->GetSuperclass(mClazz);
- VerifyOrExit(mSuperClazz != nullptr, ChipLogError(AppServer, "Failed to get handler's parent's Java class"));
-
- mMethod = env->GetMethodID(mSuperClazz, "handleInternal", mMethodSignature);
- if (mMethod == nullptr)
- {
- ChipLogError(AppServer, "Failed to access 'handleInternal' method with signature %s", mMethodSignature);
- env->ExceptionClear();
- }
-
-exit:
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer, "CallbackBaseJNI::SetUp error: %s", err.AsString());
- return err;
- }
-
- return err;
-}
-
-void FailureHandlerJNI::Handle(CHIP_ERROR callbackErr)
-{
- ChipLogProgress(AppServer, "Handle(CHIP_ERROR) called");
-
- JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
- UtfString jniCallbackErrString(env, callbackErr.AsString());
-
- chip::DeviceLayer::StackUnlock unlock;
- CHIP_ERROR err = CHIP_NO_ERROR;
- VerifyOrExit(mObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
- VerifyOrExit(mMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
- env->CallVoidMethod(mObject.ObjectRef(), mMethod, static_cast(callbackErr.AsInteger()), jniCallbackErrString.jniValue());
-exit:
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer, "Handle(CHIP_ERROR) status error: %s", err.AsString());
- }
-}
-
-void SubscriptionEstablishedHandlerJNI::Handle()
-{
- ChipLogProgress(AppServer, "SubscriptionEstablishedHandlerJNI::Handle called");
-
- JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
-
- chip::DeviceLayer::StackUnlock unlock;
- CHIP_ERROR err = CHIP_NO_ERROR;
- VerifyOrExit(mObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
- VerifyOrExit(mMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
-
- env->CallVoidMethod(mObject.ObjectRef(), mMethod);
-exit:
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer, "SubscriptionEstablishedHandlerJNI::Handle status error: %s", err.AsString());
- }
-}
-
-jobject ConvertToLongJObject(uint64_t responseData)
-{
- JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
-
- jclass responseTypeClass = env->FindClass("java/lang/Long");
- if (responseTypeClass == nullptr)
- {
- ChipLogError(AppServer, "ConvertToJObject: Class for Response Type not found!");
- return nullptr;
- }
-
- jmethodID constructor = env->GetMethodID(responseTypeClass, "", "(J)V");
- return env->NewObject(responseTypeClass, constructor, responseData);
-}
-
-jobject ConvertToFloatJObject(float responseData)
-{
- JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
-
- jclass responseTypeClass = env->FindClass("java/lang/Float");
- if (responseTypeClass == nullptr)
- {
- ChipLogError(AppServer, "ConvertToJObject: Class for Response Type not found!");
- return nullptr;
- }
-
- jmethodID constructor = env->GetMethodID(responseTypeClass, "", "(F)V");
- return env->NewObject(responseTypeClass, constructor, responseData);
-}
-
-jobject ConvertToShortJObject(uint16_t responseData)
-{
- JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
-
- jclass responseTypeClass = env->FindClass("java/lang/Short");
- if (responseTypeClass == nullptr)
- {
- ChipLogError(AppServer, "ConvertToJObject: Class for Response Type not found!");
- return nullptr;
- }
-
- jmethodID constructor = env->GetMethodID(responseTypeClass, "", "(S)V");
- return env->NewObject(responseTypeClass, constructor, responseData);
-}
-
-jobject ConvertToByteJObject(uint8_t responseData)
-{
- JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
-
- jclass responseTypeClass = env->FindClass("java/lang/Byte");
- if (responseTypeClass == nullptr)
- {
- ChipLogError(AppServer, "ConvertToJObject: Class for Response Type not found!");
- return nullptr;
- }
-
- jmethodID constructor = env->GetMethodID(responseTypeClass, "", "(B)V");
- return env->NewObject(responseTypeClass, constructor, responseData);
-}
-
-jstring ConvertToJString(chip::CharSpan responseData)
-{
- JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
-
- return env->NewStringUTF(std::string(responseData.data(), responseData.size()).c_str());
-}
-
-jobject ConvertToIntegerJObject(uint32_t responseData)
-{
- JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
-
- jclass responseTypeClass = env->FindClass("java/lang/Integer");
- if (responseTypeClass == nullptr)
- {
- ChipLogError(AppServer, "ConvertToJObject: Class for Response Type not found!");
- return nullptr;
- }
-
- jmethodID constructor = env->GetMethodID(responseTypeClass, "", "(I)V");
- return env->NewObject(responseTypeClass, constructor, responseData);
-}
-
-// COMMISSIONING AND CONNECTION
-jobject OnConnectionSuccessHandlerJNI::ConvertToJObject(TargetVideoPlayerInfo * targetVideoPlayerInfo)
-{
- ChipLogProgress(AppServer, "OnConnectionSuccessHandlerJNI::ConvertToJObject called");
- jobject videoPlayer = nullptr;
- CHIP_ERROR err = convertTargetVideoPlayerInfoToJVideoPlayer(targetVideoPlayerInfo, videoPlayer);
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer, "OnConnectionSuccessHandlerJNI::ConvertToJObject failed with %" CHIP_ERROR_FORMAT, err.Format());
- }
- return videoPlayer;
-}
-
-jobject OnNewOrUpdatedEndpointHandlerJNI::ConvertToJObject(TargetEndpointInfo * targetEndpointInfo)
-{
- ChipLogProgress(AppServer, "OnNewOrUpdatedEndpointHandlerJNI::ConvertToJObject called");
- jobject contentApp = nullptr;
- CHIP_ERROR err = convertTargetEndpointInfoToJContentApp(targetEndpointInfo, contentApp);
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer, "OnNewOrUpdatedEndpointHandlerJNI::ConvertToJObject failed with %" CHIP_ERROR_FORMAT, err.Format());
- }
- return contentApp;
-}
-
-// MEDIA PLAYBACK
-jobject CurrentStateSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::MediaPlayback::Attributes::CurrentState::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "CurrentStateSuccessHandlerJNI::ConvertToJObject called");
- JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
- VerifyOrReturnValue(env != nullptr, nullptr);
- JniLocalReferenceScope scope(env);
-
- jclass enumClass = nullptr;
- CHIP_ERROR err =
- JniReferences::GetInstance().GetLocalClassRef(env, "com/chip/casting/MediaPlaybackTypes$PlaybackStateEnum", enumClass);
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer, "ConvertToJObject: Class for Response Type not found!");
- return nullptr;
- }
-
- jfieldID enumType = nullptr;
- switch (responseData)
- {
- case chip::app::Clusters::MediaPlayback::PlaybackStateEnum::kPlaying:
- enumType = env->GetStaticFieldID(enumClass, "Playing", "Lcom/chip/casting/MediaPlaybackTypes$PlaybackStateEnum;");
- break;
- case chip::app::Clusters::MediaPlayback::PlaybackStateEnum::kPaused:
- enumType = env->GetStaticFieldID(enumClass, "Paused", "Lcom/chip/casting/MediaPlaybackTypes$PlaybackStateEnum;");
- break;
- case chip::app::Clusters::MediaPlayback::PlaybackStateEnum::kNotPlaying:
- enumType = env->GetStaticFieldID(enumClass, "NotPlaying", "Lcom/chip/casting/MediaPlaybackTypes$PlaybackStateEnum;");
- break;
- case chip::app::Clusters::MediaPlayback::PlaybackStateEnum::kBuffering:
- enumType = env->GetStaticFieldID(enumClass, "Buffering", "Lcom/chip/casting/MediaPlaybackTypes$PlaybackStateEnum;");
- break;
- default:
- enumType = env->GetStaticFieldID(enumClass, "Unknown", "Lcom/chip/casting/MediaPlaybackTypes$PlaybackStateEnum;");
- break;
- }
-
- if (enumType != nullptr)
- {
- return env->GetStaticObjectField(enumClass, enumType);
- }
- return nullptr;
-}
-
-jobject DurationSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::MediaPlayback::Attributes::Duration::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "DurationSuccessHandlerJNI::ConvertToJObject called");
- return responseData.IsNull() ? nullptr : ConvertToLongJObject(responseData.Value());
-}
-
-jobject SampledPositionSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::MediaPlayback::Attributes::SampledPosition::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "SampledPositionSuccessHandlerJNI::ConvertToJObject called");
- JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
- VerifyOrReturnValue(env != nullptr, nullptr);
- JniLocalReferenceScope scope(env);
-
- jobject jSampledPosition = nullptr;
- if (!responseData.IsNull())
- {
- const chip::app::Clusters::MediaPlayback::Structs::PlaybackPositionStruct::DecodableType & playbackPosition =
- responseData.Value();
-
- jclass responseTypeClass = nullptr;
- CHIP_ERROR err = JniReferences::GetInstance().GetLocalClassRef(
- env, "com/chip/casting/MediaPlaybackTypes$PlaybackPositionStruct", responseTypeClass);
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer, "ConvertToJObject: Class for Response Type not found!");
- return nullptr;
- }
-
- if (playbackPosition.position.IsNull())
- {
- jmethodID constructor = env->GetMethodID(responseTypeClass, "", "(Ljava/lang/Long;)V");
- jSampledPosition = env->NewObject(responseTypeClass, constructor, playbackPosition.updatedAt);
- }
- else
- {
- jmethodID constructor = env->GetMethodID(responseTypeClass, "", "(Ljava/lang/Long;java/lang/Long;)V");
- jSampledPosition =
- env->NewObject(responseTypeClass, constructor, playbackPosition.updatedAt, playbackPosition.position.Value());
- }
- }
-
- return jSampledPosition;
-}
-
-jobject PlaybackSpeedSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::MediaPlayback::Attributes::PlaybackSpeed::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "PlaybackSpeedSuccessHandlerJNI::ConvertToJObject called");
- return ConvertToFloatJObject(responseData);
-}
-
-jobject SeekRangeEndSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::MediaPlayback::Attributes::SeekRangeEnd::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "SeekRangeEndSuccessHandlerJNI::ConvertToJObject called");
- return responseData.IsNull() ? nullptr : ConvertToLongJObject(responseData.Value());
-}
-
-jobject SeekRangeStartSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::MediaPlayback::Attributes::SeekRangeStart::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "SeekRangeStartSuccessHandlerJNI::ConvertToJObject called");
- return responseData.IsNull() ? nullptr : ConvertToLongJObject(responseData.Value());
-}
-
-// TARGET NAVIGATOR
-jobject CurrentTargetSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::TargetNavigator::Attributes::CurrentTarget::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "CurrentTargetSuccessHandlerJNI::ConvertToJObject called");
- return ConvertToByteJObject(responseData);
-}
-
-jobject TargetListSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::TargetNavigator::Attributes::TargetList::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "TargetListSuccessHandlerJNI::ConvertToJObject called");
-
- JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
- VerifyOrReturnValue(env != nullptr, nullptr);
- JniLocalReferenceScope scope(env);
-
- jobject jArrayList;
- chip::JniReferences::GetInstance().CreateArrayList(jArrayList);
- auto iter = responseData.begin();
- while (iter.Next())
- {
- const chip::app::Clusters::TargetNavigator::Structs::TargetInfoStruct::DecodableType & targetInfo = iter.GetValue();
-
- jclass responseTypeClass = nullptr;
- CHIP_ERROR err = JniReferences::GetInstance().GetLocalClassRef(env, "com/chip/casting/TargetNavigatorTypes$TargetInfo",
- responseTypeClass);
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer, "ConvertToJObject: Class for Response Type not found!");
- return nullptr;
- }
-
- jmethodID constructor = env->GetMethodID(responseTypeClass, "", "(Ljava/lang/Integer;Ljava/lang/String;)V");
- chip::UtfString targetInfoName(env, targetInfo.name);
- jobject jTargetInfo = env->NewObject(responseTypeClass, constructor, ConvertToIntegerJObject(targetInfo.identifier),
- targetInfoName.jniValue());
-
- chip::JniReferences::GetInstance().AddToList(jArrayList, jTargetInfo);
- }
- return jArrayList;
-}
-
-// LEVEL CONTROL
-jobject CurrentLevelSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::LevelControl::Attributes::CurrentLevel::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "CurrentLevelSuccessHandlerJNI::ConvertToJObject called");
- return responseData.IsNull() ? nullptr : ConvertToByteJObject(responseData.Value());
-}
-
-jobject MinLevelSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::LevelControl::Attributes::MinLevel::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "MinLevelSuccessHandlerJNI::ConvertToJObject called");
- return ConvertToByteJObject(responseData);
-}
-
-jobject MaxLevelSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::LevelControl::Attributes::MaxLevel::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "MaxLevelSuccessHandlerJNI::ConvertToJObject called");
- return ConvertToByteJObject(responseData);
-}
-
-// CONTENT LAUNCHER
-jobject SupportedStreamingProtocolsSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::ContentLauncher::Attributes::SupportedStreamingProtocols::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "SupportedStreamingProtocolsSuccessHandlerJNI::ConvertToJObject called");
- return ConvertToIntegerJObject(responseData.Raw());
-}
-
-// APPLICATION BASIC
-jobject VendorNameSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::ApplicationBasic::Attributes::VendorName::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "VendorNameSuccessHandlerJNI::ConvertToJObject called");
- return ConvertToJString(responseData);
-}
-
-jobject VendorIDSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::ApplicationBasic::Attributes::VendorID::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "VendorIDSuccessHandlerJNI::ConvertToJObject called");
- return ConvertToIntegerJObject(responseData);
-}
-
-jobject ApplicationNameSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::ApplicationBasic::Attributes::ApplicationName::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "ApplicationNameSuccessHandlerJNI::ConvertToJObject called");
- return ConvertToJString(responseData);
-}
-
-jobject ProductIDSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::ApplicationBasic::Attributes::ProductID::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "ProductIDSuccessHandlerJNI::ConvertToJObject called");
- return ConvertToIntegerJObject(responseData);
-}
-
-jobject ApplicationVersionSuccessHandlerJNI::ConvertToJObject(
- chip::app::Clusters::ApplicationBasic::Attributes::ApplicationVersion::TypeInfo::DecodableArgType responseData)
-{
- ChipLogProgress(AppServer, "ApplicationVersionSuccessHandlerJNI::ConvertToJObject called");
- return ConvertToJString(responseData);
-}
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.h b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.h
deleted file mode 100644
index 152dac59737532..00000000000000
--- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/MatterCallbackHandler-JNI.h
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- *
- * Copyright (c) 2022 Project CHIP Authors
- * All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include "ConversionUtils.h"
-#include "TargetEndpointInfo.h"
-#include "TargetVideoPlayerInfo.h"
-
-#include
-#include
-#include
-#include
-#include
-
-#include
-
-class CallbackBaseJNI
-{
-public:
- CallbackBaseJNI(const char * methodSignature) { mMethodSignature = methodSignature; }
- CHIP_ERROR SetUp(JNIEnv * env, jobject inHandler);
-
-protected:
- chip::JniGlobalReference mObject;
- jclass mClazz = nullptr;
- jclass mSuperClazz = nullptr;
- jmethodID mMethod = nullptr;
- const char * mMethodSignature = nullptr;
-};
-
-class FailureHandlerJNI : public CallbackBaseJNI
-{
-public:
- FailureHandlerJNI() : CallbackBaseJNI("(ILjava/lang/String;)V") {}
- void Handle(CHIP_ERROR err);
-};
-
-class MatterCallbackHandlerJNI : public FailureHandlerJNI
-{
-};
-
-class SubscriptionEstablishedHandlerJNI : public CallbackBaseJNI
-{
-public:
- SubscriptionEstablishedHandlerJNI() : CallbackBaseJNI("()V") {}
- void Handle();
-};
-
-// helper functions for conversions
-jobject ConvertToLongJObject(uint64_t responseData);
-jobject ConvertToFloatJObject(float responseData);
-jobject ConvertToShortJObject(uint8_t responseData);
-jobject ConvertToByteJObject(uint8_t responseData);
-jobject ConvertToIntegerJObject(uint32_t responseData);
-jstring ConvertToJString(chip::CharSpan responseData);
-
-template
-class SuccessHandlerJNI : public CallbackBaseJNI
-{
-public:
- SuccessHandlerJNI(const char * methodSignature) : CallbackBaseJNI(methodSignature) {}
-
- virtual ~SuccessHandlerJNI() = 0;
-
- virtual jobject ConvertToJObject(T responseData) = 0;
-
- void Handle(T responseData)
- {
- ChipLogProgress(AppServer, "SuccessHandlerJNI::Handle called");
-
- JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread();
- jobject jResponseData = ConvertToJObject(responseData);
-
- chip::DeviceLayer::StackUnlock unlock;
- CHIP_ERROR err = CHIP_NO_ERROR;
- VerifyOrExit(mObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
- VerifyOrExit(mMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
- env->CallVoidMethod(mObject.ObjectRef(), mMethod, jResponseData);
- exit:
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer, "SuccessHandlerJNI::Handle status error: %s", err.AsString());
- }
- }
-};
-
-template
-SuccessHandlerJNI::~SuccessHandlerJNI(){};
-
-// COMMISSIONING AND CONNECTION
-class SessionEstablishmentStartedHandlerJNI : public SuccessHandlerJNI
-{
-public:
- SessionEstablishmentStartedHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Object;)V") {}
- jobject ConvertToJObject(void * responseData)
- {
- // return nullptr because the Java callback extends SuccessCallback and its handle() expects a Void param.
- // It expects a Void becauase no value is passed as part of this callback.
- return nullptr;
- }
-};
-
-class SessionEstablishedHandlerJNI : public SuccessHandlerJNI
-{
-public:
- SessionEstablishedHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Object;)V") {}
- jobject ConvertToJObject(void * responseData)
- {
- // return nullptr because the Java callback extends SuccessCallback and its handle() expects a Void param.
- // It expects a Void becauase no value is passed as part of this callback.
- return nullptr;
- }
-};
-
-class OnConnectionSuccessHandlerJNI : public SuccessHandlerJNI
-{
-public:
- OnConnectionSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Object;)V") {}
- jobject ConvertToJObject(TargetVideoPlayerInfo * responseData);
-};
-
-class OnNewOrUpdatedEndpointHandlerJNI : public SuccessHandlerJNI
-{
-public:
- OnNewOrUpdatedEndpointHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Object;)V") {}
- jobject ConvertToJObject(TargetEndpointInfo * responseData);
-};
-
-// MEDIA PLAYBACK
-class CurrentStateSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- CurrentStateSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Object;)V") {}
- jobject ConvertToJObject(chip::app::Clusters::MediaPlayback::Attributes::CurrentState::TypeInfo::DecodableArgType responseData);
-};
-
-class DurationSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- DurationSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Long;)V") {}
- jobject ConvertToJObject(chip::app::Clusters::MediaPlayback::Attributes::Duration::TypeInfo::DecodableArgType responseData);
-};
-
-class SampledPositionSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- SampledPositionSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Object;)V") {}
- jobject
- ConvertToJObject(chip::app::Clusters::MediaPlayback::Attributes::SampledPosition::TypeInfo::DecodableArgType responseData);
-};
-
-class PlaybackSpeedSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- PlaybackSpeedSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Float;)V") {}
- jobject
- ConvertToJObject(chip::app::Clusters::MediaPlayback::Attributes::PlaybackSpeed::TypeInfo::DecodableArgType responseData);
-};
-
-class SeekRangeEndSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- SeekRangeEndSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Long;)V") {}
- jobject ConvertToJObject(chip::app::Clusters::MediaPlayback::Attributes::SeekRangeEnd::TypeInfo::DecodableArgType responseData);
-};
-
-class SeekRangeStartSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- SeekRangeStartSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Long;)V") {}
- jobject
- ConvertToJObject(chip::app::Clusters::MediaPlayback::Attributes::SeekRangeStart::TypeInfo::DecodableArgType responseData);
-};
-
-// TARGET NAVIGATOR
-class CurrentTargetSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- CurrentTargetSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Byte;)V") {}
- jobject
- ConvertToJObject(chip::app::Clusters::TargetNavigator::Attributes::CurrentTarget::TypeInfo::DecodableArgType responseData);
-};
-
-class TargetListSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- TargetListSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Object;)V") {}
- jobject ConvertToJObject(chip::app::Clusters::TargetNavigator::Attributes::TargetList::TypeInfo::DecodableArgType responseData);
-};
-
-// LEVEL CONTROL
-class CurrentLevelSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- CurrentLevelSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Byte;)V") {}
- jobject ConvertToJObject(chip::app::Clusters::LevelControl::Attributes::CurrentLevel::TypeInfo::DecodableArgType responseData);
-};
-
-class MinLevelSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- MinLevelSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Byte;)V") {}
- jobject ConvertToJObject(chip::app::Clusters::LevelControl::Attributes::MinLevel::TypeInfo::DecodableArgType responseData);
-};
-
-class MaxLevelSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- MaxLevelSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Byte;)V") {}
- jobject ConvertToJObject(chip::app::Clusters::LevelControl::Attributes::MaxLevel::TypeInfo::DecodableArgType responseData);
-};
-
-// CONTENT LAUNCHER
-class SupportedStreamingProtocolsSuccessHandlerJNI
- : public SuccessHandlerJNI<
- chip::app::Clusters::ContentLauncher::Attributes::SupportedStreamingProtocols::TypeInfo::DecodableArgType>
-{
-public:
- SupportedStreamingProtocolsSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Integer;)V") {}
- jobject ConvertToJObject(
- chip::app::Clusters::ContentLauncher::Attributes::SupportedStreamingProtocols::TypeInfo::DecodableArgType responseData);
-};
-
-// APPLICATION BASIC
-class VendorNameSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- VendorNameSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/String;)V") {}
- jobject
- ConvertToJObject(chip::app::Clusters::ApplicationBasic::Attributes::VendorName::TypeInfo::DecodableArgType responseData);
-};
-
-class VendorIDSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- VendorIDSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Integer;)V") {}
- jobject ConvertToJObject(chip::app::Clusters::ApplicationBasic::Attributes::VendorID::TypeInfo::DecodableArgType responseData);
-};
-
-class ApplicationNameSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- ApplicationNameSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/String;)V") {}
- jobject
- ConvertToJObject(chip::app::Clusters::ApplicationBasic::Attributes::ApplicationName::TypeInfo::DecodableArgType responseData);
-};
-
-class ProductIDSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- ProductIDSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/Integer;)V") {}
- jobject ConvertToJObject(chip::app::Clusters::ApplicationBasic::Attributes::ProductID::TypeInfo::DecodableArgType responseData);
-};
-
-class ApplicationVersionSuccessHandlerJNI
- : public SuccessHandlerJNI
-{
-public:
- ApplicationVersionSuccessHandlerJNI() : SuccessHandlerJNI("(Ljava/lang/String;)V") {}
- jobject ConvertToJObject(
- chip::app::Clusters::ApplicationBasic::Attributes::ApplicationVersion::TypeInfo::DecodableArgType responseData);
-};
diff --git a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp b/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp
deleted file mode 100644
index f2e0d5b79fc53c..00000000000000
--- a/examples/tv-casting-app/android/App/app/src/main/jni/cpp/TvCastingApp-JNI.cpp
+++ /dev/null
@@ -1,2129 +0,0 @@
-/*
- * Copyright (c) 2022 Project CHIP Authors
- * All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "TvCastingApp-JNI.h"
-#include "CastingServer.h"
-#include "Constants.h"
-#include "ConversionUtils.h"
-#include "JNIDACProvider.h"
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-using namespace chip;
-
-#define JNI_METHOD(RETURN, METHOD_NAME) extern "C" JNIEXPORT RETURN JNICALL Java_com_chip_casting_TvCastingApp_##METHOD_NAME
-
-TvCastingAppJNI TvCastingAppJNI::sInstance;
-
-jint JNI_OnLoad(JavaVM * jvm, void * reserved)
-{
- return AndroidAppServerJNI_OnLoad(jvm, reserved);
-}
-
-void JNI_OnUnload(JavaVM * jvm, void * reserved)
-{
- return AndroidAppServerJNI_OnUnload(jvm, reserved);
-}
-
-JNI_METHOD(jboolean, preInitJni)(JNIEnv *, jobject, jobject jAppParameters)
-{
- chip::DeviceLayer::StackLock lock;
- ChipLogProgress(AppServer, "JNI_METHOD preInitJni called");
-
- CHIP_ERROR err = CHIP_NO_ERROR;
- if (jAppParameters == nullptr)
- {
- err = CastingServer::GetInstance()->PreInit();
- }
- else
- {
- AppParams appParams;
- err = convertJAppParametersToCppAppParams(jAppParameters, appParams);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion of AppParameters from jobject to Cpp type failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
- err = CastingServer::GetInstance()->PreInit(&appParams);
- }
- VerifyOrExit(
- err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Call to CastingServer::GetInstance()->PreInit() failed: %" CHIP_ERROR_FORMAT, err.Format()));
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, initJni)(JNIEnv *, jobject, jobject jAppParameters)
-{
- chip::DeviceLayer::StackLock lock;
- ChipLogProgress(AppServer, "JNI_METHOD initJni called");
-
- CHIP_ERROR err = CHIP_NO_ERROR;
- if (jAppParameters == nullptr)
- {
- err = CastingServer::GetInstance()->Init();
- }
- else
- {
- AppParams appParams;
- err = convertJAppParametersToCppAppParams(jAppParameters, appParams);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion of AppParameters from jobject to Cpp type failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
- err = CastingServer::GetInstance()->Init(&appParams);
- }
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Call to CastingServer::GetInstance()->Init() failed: %" CHIP_ERROR_FORMAT, err.Format()));
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(void, setDACProvider)(JNIEnv *, jobject, jobject provider)
-{
- chip::DeviceLayer::StackLock lock;
- ChipLogProgress(AppServer, "JNI_METHOD setDACProvider called");
-
- JNIDACProvider * p = new JNIDACProvider(provider);
- chip::Credentials::SetDeviceAttestationCredentialsProvider(p);
-}
-
-JNI_METHOD(jboolean, openBasicCommissioningWindow)
-(JNIEnv * env, jobject, jint duration, jobject jCommissioningCallbacks, jobject jOnConnectionSuccessHandler,
- jobject jOnConnectionFailureHandler, jobject jOnNewOrUpdatedEndpointHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD openBasicCommissioningWindow called with duration %d", duration);
-
- CHIP_ERROR err = CHIP_NO_ERROR;
-
- CommissioningCallbacks commissioningCallbacks;
- jclass jCommissioningCallbacksClass;
- chip::JniReferences::GetInstance().GetLocalClassRef(env, "com/chip/casting/CommissioningCallbacks",
- jCommissioningCallbacksClass);
-
- jfieldID jCommissioningCompleteField =
- env->GetFieldID(jCommissioningCallbacksClass, "commissioningComplete", "Ljava/lang/Object;");
- jobject jCommissioningComplete = env->GetObjectField(jCommissioningCallbacks, jCommissioningCompleteField);
- if (jCommissioningComplete != nullptr)
- {
- err = TvCastingAppJNIMgr().getCommissioningCompleteHandler().SetUp(env, jCommissioningComplete);
- VerifyOrReturnValue(err == CHIP_NO_ERROR, false,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI::SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
- commissioningCallbacks.commissioningComplete = [](CHIP_ERROR err) {
- TvCastingAppJNIMgr().getCommissioningCompleteHandler().Handle(err);
- };
- }
-
- jfieldID jSessionEstablishmentStartedField =
- env->GetFieldID(jCommissioningCallbacksClass, "sessionEstablishmentStarted", "Lcom/chip/casting/SuccessCallback;");
- jobject jSessionEstablishmentStarted = env->GetObjectField(jCommissioningCallbacks, jSessionEstablishmentStartedField);
- if (jSessionEstablishmentStarted != nullptr)
- {
- err = TvCastingAppJNIMgr().getSessionEstablishmentStartedHandler().SetUp(env, jSessionEstablishmentStarted);
- VerifyOrReturnValue(
- err == CHIP_NO_ERROR, false,
- ChipLogError(AppServer, "SessionEstablishmentStartedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
- commissioningCallbacks.sessionEstablishmentStarted = []() {
- TvCastingAppJNIMgr().getSessionEstablishmentStartedHandler().Handle(nullptr);
- };
- }
-
- jfieldID jSessionEstablishedField =
- env->GetFieldID(jCommissioningCallbacksClass, "sessionEstablished", "Lcom/chip/casting/SuccessCallback;");
- jobject jSessionEstablished = env->GetObjectField(jCommissioningCallbacks, jSessionEstablishedField);
- if (jSessionEstablished != nullptr)
- {
- err = TvCastingAppJNIMgr().getSessionEstablishedHandler().SetUp(env, jSessionEstablished);
- VerifyOrReturnValue(err == CHIP_NO_ERROR, false,
- ChipLogError(AppServer, "SessionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
- commissioningCallbacks.sessionEstablished = []() { TvCastingAppJNIMgr().getSessionEstablishedHandler().Handle(nullptr); };
- }
-
- jfieldID jSessionEstablishmentErrorField =
- env->GetFieldID(jCommissioningCallbacksClass, "sessionEstablishmentError", "Lcom/chip/casting/FailureCallback;");
- jobject jSessionEstablishmentError = env->GetObjectField(jCommissioningCallbacks, jSessionEstablishmentErrorField);
- if (jSessionEstablishmentError != nullptr)
- {
- err = TvCastingAppJNIMgr().getSessionEstablishmentErrorHandler().SetUp(env, jSessionEstablishmentError);
- VerifyOrReturnValue(err == CHIP_NO_ERROR, false);
- commissioningCallbacks.sessionEstablishmentError = [](CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSessionEstablishmentErrorHandler().Handle(err);
- };
- }
-
- jfieldID jSessionEstablishmentStoppedField =
- env->GetFieldID(jCommissioningCallbacksClass, "sessionEstablishmentStopped", "Lcom/chip/casting/FailureCallback;");
- jobject jSessionEstablishmentStopped = env->GetObjectField(jCommissioningCallbacks, jSessionEstablishmentStoppedField);
- if (jSessionEstablishmentStopped != nullptr)
- {
- err = TvCastingAppJNIMgr().getSessionEstablishmentStoppedHandler().SetUp(env, jSessionEstablishmentStopped);
- VerifyOrReturnValue(
- err == CHIP_NO_ERROR, false,
- ChipLogError(AppServer, "SessionEstablishmentStoppedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
- commissioningCallbacks.sessionEstablishmentStopped = []() {
- TvCastingAppJNIMgr().getSessionEstablishmentStoppedHandler().Handle(CHIP_NO_ERROR);
- };
- }
-
- err = TvCastingAppJNIMgr().getOnConnectionSuccessHandler(false).SetUp(env, jOnConnectionSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "OnConnectionSuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getOnConnectionFailureHandler(false).SetUp(env, jOnConnectionFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "OnConnectionFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getOnNewOrUpdatedEndpointHandler(false).SetUp(env, jOnNewOrUpdatedEndpointHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "OnNewOrUpdatedEndpointHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->OpenBasicCommissioningWindow(
- commissioningCallbacks,
- [](TargetVideoPlayerInfo * videoPlayer) { TvCastingAppJNIMgr().getOnConnectionSuccessHandler(false).Handle(videoPlayer); },
- [](CHIP_ERROR err) { TvCastingAppJNIMgr().getOnConnectionFailureHandler(false).Handle(err); },
- [](TargetEndpointInfo * endpoint) { TvCastingAppJNIMgr().getOnNewOrUpdatedEndpointHandler(false).Handle(endpoint); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer::OpenBasicCommissioningWindow failed: %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jobject, readCachedVideoPlayers)(JNIEnv * env, jobject)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD readCachedVideoPlayers called");
-
- jobject jVideoPlayerList = nullptr;
- TargetVideoPlayerInfo * targetVideoPlayerInfoList = CastingServer::GetInstance()->ReadCachedTargetVideoPlayerInfos();
- if (targetVideoPlayerInfoList != nullptr)
- {
- chip::JniReferences::GetInstance().CreateArrayList(jVideoPlayerList);
- for (size_t i = 0; targetVideoPlayerInfoList[i].IsInitialized(); i++)
- {
- jobject jVideoPlayer = nullptr;
- CHIP_ERROR err = convertTargetVideoPlayerInfoToJVideoPlayer(&targetVideoPlayerInfoList[i], jVideoPlayer);
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer,
- "Conversion from TargetVideoPlayerInfo * to jobject VideoPlayer failed: %" CHIP_ERROR_FORMAT,
- err.Format());
- continue;
- }
- chip::JniReferences::GetInstance().AddToList(jVideoPlayerList, jVideoPlayer);
- }
- }
-
- return jVideoPlayerList;
-}
-
-JNI_METHOD(jboolean, verifyOrEstablishConnection)
-(JNIEnv * env, jobject, jobject videoPlayer, jobject jOnConnectionSuccessHandler, jobject jOnConnectionFailureHandler,
- jobject jOnNewOrUpdatedEndpointHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD verifyOrEstablishConnection called");
-
- TargetVideoPlayerInfo targetVideoPlayerInfo;
- CHIP_ERROR err = convertJVideoPlayerToTargetVideoPlayerInfo(videoPlayer, targetVideoPlayerInfo);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer,
- "Conversion from jobject VideoPlayer to TargetVideoPlayerInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getOnConnectionSuccessHandler(true).SetUp(env, jOnConnectionSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "OnConnectionSuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getOnConnectionFailureHandler(true).SetUp(env, jOnConnectionFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "OnConnectionFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getOnNewOrUpdatedEndpointHandler(true).SetUp(env, jOnNewOrUpdatedEndpointHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "OnNewOrUpdatedEndpointHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->VerifyOrEstablishConnection(
- targetVideoPlayerInfo,
- [](TargetVideoPlayerInfo * videoPlayer) { TvCastingAppJNIMgr().getOnConnectionSuccessHandler(true).Handle(videoPlayer); },
- [](CHIP_ERROR err) { TvCastingAppJNIMgr().getOnConnectionFailureHandler(true).Handle(err); },
- [](TargetEndpointInfo * endpoint) { TvCastingAppJNIMgr().getOnNewOrUpdatedEndpointHandler(true).Handle(endpoint); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer::verifyOrEstablishConnection failed: %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, WasRecentlyDiscoverable)
-(JNIEnv * env, jobject, jobject videoPlayer)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD WasRecentlyDiscoverable called");
-
- TargetVideoPlayerInfo targetVideoPlayerInfo;
- CHIP_ERROR err = convertJVideoPlayerToTargetVideoPlayerInfo(videoPlayer, targetVideoPlayerInfo);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer,
- "Conversion from jobject VideoPlayer to TargetVideoPlayerInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
- return targetVideoPlayerInfo.WasRecentlyDiscoverable();
-
-exit:
- return false; // default to false
-}
-
-JNI_METHOD(void, shutdownAllSubscriptions)(JNIEnv * env, jobject)
-{
- chip::DeviceLayer::StackLock lock;
- ChipLogProgress(AppServer, "JNI_METHOD shutdownAllSubscriptions called");
-
- CastingServer::GetInstance()->ShutdownAllSubscriptions();
-}
-
-JNI_METHOD(void, disconnect)(JNIEnv * env, jobject)
-{
- chip::DeviceLayer::StackLock lock;
- ChipLogProgress(AppServer, "JNI_METHOD disconnect called");
- CastingServer::GetInstance()->Disconnect();
-}
-
-JNI_METHOD(jobject, getActiveTargetVideoPlayers)(JNIEnv * env, jobject)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD getActiveTargetVideoPlayers called");
-
- jobject jVideoPlayerList = nullptr;
- TargetVideoPlayerInfo * targetVideoPlayerInfo = CastingServer::GetInstance()->GetActiveTargetVideoPlayer();
- if (targetVideoPlayerInfo != nullptr)
- {
- chip::JniReferences::GetInstance().CreateArrayList(jVideoPlayerList);
- jobject jVideoPlayer = nullptr;
- CHIP_ERROR err = convertTargetVideoPlayerInfoToJVideoPlayer(targetVideoPlayerInfo, jVideoPlayer);
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer, "Conversion from TargetVideoPlayerInfo * to jobject VideoPlayer failed: %" CHIP_ERROR_FORMAT,
- err.Format());
- }
- else
- {
- chip::JniReferences::GetInstance().AddToList(jVideoPlayerList, jVideoPlayer);
- }
- }
- return jVideoPlayerList;
-}
-
-JNI_METHOD(jboolean, sendUserDirectedCommissioningRequest)(JNIEnv * env, jobject, jstring addressJStr, jint port)
-{
- chip::DeviceLayer::StackLock lock;
- ChipLogProgress(AppServer, "JNI_METHOD sendUserDirectedCommissioningRequest called with port %d", port);
- Inet::IPAddress addressInet;
- JniUtfString addressJniString(env, addressJStr);
- if (Inet::IPAddress::FromString(addressJniString.c_str(), addressInet) == false)
- {
- ChipLogError(AppServer, "Failed to parse IP address");
- return false;
- }
-
- chip::Inet::InterfaceId interfaceId = chip::Inet::InterfaceId::FromIPAddress(addressInet);
- chip::Transport::PeerAddress peerAddress =
- chip::Transport::PeerAddress::UDP(addressInet, static_cast(port), interfaceId);
- CHIP_ERROR err = CastingServer::GetInstance()->SendUserDirectedCommissioningRequest(peerAddress);
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer, "TVCastingApp-JNI::sendUserDirectedCommissioningRequest failed: %" CHIP_ERROR_FORMAT, err.Format());
- return false;
- }
- return true;
-}
-
-JNI_METHOD(jboolean, sendCommissioningRequest)(JNIEnv * env, jobject, jobject jDiscoveredNodeData)
-{
- chip::DeviceLayer::StackLock lock;
- ChipLogProgress(AppServer, "JNI_METHOD sendCommissioningRequest called");
-
- chip::Dnssd::CommissionNodeData commissioner;
- CHIP_ERROR err = convertJDiscoveredNodeDataToCppDiscoveredNodeData(jDiscoveredNodeData, commissioner);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer,
- "Conversion from jobject DiscoveredNodeData to Cpp DiscoveredNodeData failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = CastingServer::GetInstance()->SendUserDirectedCommissioningRequest(&commissioner);
-
-exit:
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer, "TVCastingApp-JNI::sendCommissioningRequest failed: %" CHIP_ERROR_FORMAT, err.Format());
- return false;
- }
- return true;
-}
-
-JNI_METHOD(jboolean, purgeCache)(JNIEnv * env, jobject)
-{
- chip::DeviceLayer::StackLock lock;
- ChipLogProgress(AppServer, "JNI_METHOD purgeCache called");
-
- CHIP_ERROR err = CastingServer::GetInstance()->PurgeCache();
- if (err != CHIP_NO_ERROR)
- {
- ChipLogError(AppServer, "TVCastingApp-JNI::purgeCache failed: %" CHIP_ERROR_FORMAT, err.Format());
- return false;
- }
- return true;
-}
-
-JNI_METHOD(jboolean, contentLauncherLaunchURL)
-(JNIEnv * env, jobject, jobject contentApp, jstring contentUrl, jstring contentDisplayStr, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD contentLauncherLaunchURL called");
- const char * nativeContentUrl = env->GetStringUTFChars(contentUrl, 0);
- const char * nativeContentDisplayStr = env->GetStringUTFChars(contentDisplayStr, 0);
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(ContentLauncher_LaunchURL).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI::SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->ContentLauncherLaunchURL(
- &endpoint, nativeContentUrl, nativeContentDisplayStr,
- [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(ContentLauncher_LaunchURL).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer::ContentLauncherLaunchURL failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- env->ReleaseStringUTFChars(contentUrl, nativeContentUrl);
- env->ReleaseStringUTFChars(contentDisplayStr, nativeContentDisplayStr);
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-CHIP_ERROR CreateParameter(JNIEnv * env, jobject jParameter,
- chip::app::Clusters::ContentLauncher::Structs::ParameterStruct::Type & parameter)
-{
- jclass jParameterClass = env->GetObjectClass(jParameter);
-
- jfieldID jTypeField = env->GetFieldID(jParameterClass, "type", "Ljava/lang/Integer;");
- jobject jTypeObj = env->GetObjectField(jParameter, jTypeField);
- jclass jIntegerClass = env->FindClass("java/lang/Integer");
- jmethodID jIntValueMid = env->GetMethodID(jIntegerClass, "intValue", "()I");
- parameter.type = static_cast(env->CallIntMethod(jTypeObj, jIntValueMid));
-
- jfieldID jValueField = env->GetFieldID(jParameterClass, "value", "Ljava/lang/String;");
- jstring jValueObj = (jstring) env->GetObjectField(jParameter, jValueField);
- const char * nativeValue = env->GetStringUTFChars(jValueObj, 0);
- parameter.value = CharSpan::fromCharString(nativeValue);
- return CHIP_NO_ERROR;
-}
-
-CHIP_ERROR CreateContentSearch(JNIEnv * env, jobject jSearch,
- chip::app::Clusters::ContentLauncher::Structs::ContentSearchStruct::Type & search,
- ListFreer & listFreer)
-{
- jclass jContentSearchClass;
- ReturnErrorOnFailure(JniReferences::GetInstance().GetLocalClassRef(env, "com/chip/casting/ContentLauncherTypes$ContentSearch",
- jContentSearchClass));
-
- jfieldID jParameterListField = env->GetFieldID(jContentSearchClass, "parameterList", "Ljava/util/ArrayList;");
- jobject jParameterList = env->GetObjectField(jSearch, jParameterListField);
- ReturnErrorOnFailure(jParameterList != nullptr ? CHIP_NO_ERROR : CHIP_ERROR_INVALID_ARGUMENT);
-
- jclass jArrayListClass = env->FindClass("java/util/ArrayList");
- jmethodID sizeMid = env->GetMethodID(jArrayListClass, "size", "()I");
- size_t parameterListSize = static_cast(env->CallIntMethod(jParameterList, sizeMid));
-
- jobject jIterator = env->CallObjectMethod(
- jParameterList, env->GetMethodID(env->GetObjectClass(jParameterList), "iterator", "()Ljava/util/Iterator;"));
- jmethodID jNextMid = env->GetMethodID(env->GetObjectClass(jIterator), "next", "()Ljava/lang/Object;");
- jmethodID jHasNextMid = env->GetMethodID(env->GetObjectClass(jIterator), "hasNext", "()Z");
-
- auto * parameterListHolder =
- new ListHolder(parameterListSize);
- listFreer.add(parameterListHolder);
- int parameterIndex = 0;
- while (env->CallBooleanMethod(jIterator, jHasNextMid))
- {
- jobject jParameter = env->CallObjectMethod(jIterator, jNextMid);
- chip::app::Clusters::ContentLauncher::Structs::ParameterStruct::Type parameter;
- ReturnErrorOnFailure(CreateParameter(env, jParameter, parameter));
- parameterListHolder->mList[parameterIndex].type = parameter.type;
- parameterListHolder->mList[parameterIndex].value = parameter.value;
- parameterListHolder->mList[parameterIndex].externalIDList = parameter.externalIDList;
- parameterIndex++;
- }
- search.parameterList = chip::app::DataModel::List(
- parameterListHolder->mList, parameterListSize);
-
- return CHIP_NO_ERROR;
-}
-
-JNI_METHOD(jboolean, contentLauncher_1launchContent)
-(JNIEnv * env, jobject, jobject contentApp, jobject jSearch, jboolean jAutoplay, jstring jData, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD contentLauncher_1launchContent called");
-
- // prepare arguments
- bool autoplay = static_cast(jAutoplay);
-
- const char * nativeData = env->GetStringUTFChars(jData, 0);
- chip::Optional data = MakeOptional(CharSpan::fromCharString(nativeData));
-
- ListFreer listFreer;
- chip::app::Clusters::ContentLauncher::Structs::ContentSearchStruct::Type search;
- CHIP_ERROR err = CreateContentSearch(env, jSearch, search, listFreer);
-
- TargetEndpointInfo endpoint;
- err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer,
- "contentLauncher_1launchContent::Could not create ContentSearch object %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(ContentLauncher_LaunchContent).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI::SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->ContentLauncher_LaunchContent(&endpoint, search, autoplay, data, [](CHIP_ERROR err) {
- TvCastingAppJNIMgr().getMediaCommandResponseHandler(ContentLauncher_LaunchContent).Handle(err);
- });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer::ContentLauncher_LaunchContent failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- env->ReleaseStringUTFChars(jData, nativeData);
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, contentLauncher_1subscribeToSupportedStreamingProtocols)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD ContentLauncher_subscribeToSupportedStreamingProtocols called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getSupportedStreamingProtocolsSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr()
- .getSubscriptionReadFailureHandler(ContentLauncher_SupportedStreamingProtocols)
- .SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr()
- .getSubscriptionEstablishedHandler(ContentLauncher_SupportedStreamingProtocols)
- .SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->ContentLauncher_SubscribeToSupportedStreamingProtocols(
- &endpoint, nullptr,
- [](void * context,
- chip::app::Clusters::ContentLauncher::Attributes::SupportedStreamingProtocols::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getSupportedStreamingProtocolsSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(ContentLauncher_SupportedStreamingProtocols).Handle(err);
- },
- static_cast(minInterval), static_cast(maxInterval),
- [](void * context, chip::SubscriptionId) {
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(ContentLauncher_SupportedStreamingProtocols).Handle();
- });
-
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer,
- "CastingServer.ContentLauncher_SubscribeToSupportedStreamingProtocols failed %" CHIP_ERROR_FORMAT,
- err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, levelControl_1step)
-(JNIEnv * env, jobject, jobject contentApp, jbyte stepMode, jbyte stepSize, jshort transitionTime, jbyte optionMask,
- jbyte optionOverride, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD levelControl_step called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(LevelControl_Step).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->LevelControl_Step(
- &endpoint, static_cast(stepMode), static_cast(stepSize),
- static_cast(transitionTime), static_cast(optionMask), static_cast(optionOverride),
- [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(LevelControl_Step).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.LevelControl_Step failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, levelControl_1moveToLevel)
-(JNIEnv * env, jobject, jobject contentApp, jbyte level, jshort transitionTime, jbyte optionMask, jbyte optionOverride,
- jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD levelControl_moveToLevel called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(LevelControl_MoveToLevel).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->LevelControl_MoveToLevel(
- &endpoint, static_cast(level), static_cast(transitionTime), static_cast(optionMask),
- static_cast(optionOverride),
- [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(LevelControl_MoveToLevel).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.LevelControl_MoveToLevel failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, levelControl_1subscribeToCurrentLevel)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD levelControl_subscribeToCurrentLevel called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getCurrentLevelSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(LevelControl_CurrentLevel).SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr()
- .getSubscriptionEstablishedHandler(LevelControl_CurrentLevel)
- .SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->LevelControl_SubscribeToCurrentLevel(
- &endpoint, nullptr,
- [](void * context, chip::app::Clusters::LevelControl::Attributes::CurrentLevel::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getCurrentLevelSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(LevelControl_CurrentLevel).Handle(err);
- },
- static_cast(minInterval), static_cast(maxInterval),
- [](void * context, chip::SubscriptionId) {
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(LevelControl_CurrentLevel).Handle();
- });
-
- VerifyOrExit(
- CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.LevelControl_SubscribeToCurrentLevel failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, levelControl_1subscribeToMinLevel)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD levelControl_subscribeToMinLevel called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMinLevelSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(LevelControl_MinLevel).SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(LevelControl_MinLevel).SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->LevelControl_SubscribeToMinLevel(
- &endpoint, nullptr,
- [](void * context, chip::app::Clusters::LevelControl::Attributes::MinLevel::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getMinLevelSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(LevelControl_MinLevel).Handle(err);
- },
- static_cast(minInterval), static_cast(maxInterval),
- [](void * context, chip::SubscriptionId) {
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(LevelControl_MinLevel).Handle();
- });
-
- VerifyOrExit(
- CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.LevelControl_SubscribeToMinLevel failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, levelControl_1subscribeToMaxLevel)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD levelControl_subscribeToMaxLevel called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMaxLevelSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(LevelControl_MaxLevel).SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(LevelControl_MaxLevel).SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->LevelControl_SubscribeToMaxLevel(
- &endpoint, nullptr,
- [](void * context, chip::app::Clusters::LevelControl::Attributes::MaxLevel::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getMaxLevelSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(LevelControl_MaxLevel).Handle(err);
- },
- static_cast(minInterval), static_cast(maxInterval),
- [](void * context, chip::SubscriptionId) {
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(LevelControl_MaxLevel).Handle();
- });
-
- VerifyOrExit(
- CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.LevelControl_SubscribeToMaxLevel failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, onOff_1on)
-(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD onOff_on called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(OnOff_On).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->OnOff_On(
- &endpoint, [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(OnOff_On).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "CastingServer.OnOff_On failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, onOff_1off)
-(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD onOff_off called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(OnOff_Off).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->OnOff_Off(
- &endpoint, [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(OnOff_Off).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "CastingServer.OnOff_Off failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, onOff_1toggle)
-(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD onOff_toggle called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(OnOff_Toggle).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->OnOff_Toggle(
- &endpoint, [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(OnOff_Toggle).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.OnOff_Toggle failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, messages_1presentMessages)
-(JNIEnv * env, jobject, jobject contentApp, jstring messageText, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD messages_presentMessages called");
- const char * nativeMessageText = env->GetStringUTFChars(messageText, 0);
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(Messages_PresentMessagesRequest).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->Messages_PresentMessagesRequest(&endpoint, nativeMessageText, [](CHIP_ERROR err) {
- TvCastingAppJNIMgr().getMediaCommandResponseHandler(Messages_PresentMessagesRequest).Handle(err);
- });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.Messages_PresentMessagesRequest failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- env->ReleaseStringUTFChars(messageText, nativeMessageText);
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1play)
-(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD mediaPlayback_play called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Play).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->MediaPlayback_Play(
- &endpoint, [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Play).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.MediaPlayback_Play failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1pause)
-(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD mediaPlayback_pause called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Pause).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->MediaPlayback_Pause(
- &endpoint, [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Pause).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.MediaPlayback_Pause failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1stopPlayback)
-(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD mediaPlayback_stopPlayback called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_StopPlayback).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->MediaPlayback_StopPlayback(&endpoint, [](CHIP_ERROR err) {
- TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_StopPlayback).Handle(err);
- });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.MediaPlayback_StopPlayback failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1next)
-(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD mediaPlayback_next called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Next).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->MediaPlayback_Next(
- &endpoint, [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Next).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.MediaPlayback_Next failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1seek)
-(JNIEnv * env, jobject, jobject contentApp, jlong position, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD mediaPlayback_seek called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Seek).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->MediaPlayback_Seek(&endpoint, static_cast(position), [](CHIP_ERROR err) {
- TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Seek).Handle(err);
- });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.MediaPlayback_Seek failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1skipForward)
-(JNIEnv * env, jobject, jobject contentApp, jlong deltaPositionMilliseconds, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD mediaPlayback_skipForward called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_SkipForward).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->MediaPlayback_SkipForward(
- &endpoint, static_cast(deltaPositionMilliseconds),
- [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_SkipForward).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.MediaPlayback_SkipForward failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1skipBackward)
-(JNIEnv * env, jobject, jobject contentApp, jlong deltaPositionMilliseconds, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD mediaPlayback_skipBackward called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_SkipBackward).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->MediaPlayback_SkipBackward(
- &endpoint, static_cast(deltaPositionMilliseconds),
- [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_SkipBackward).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.MediaPlayback_SkipBackward failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1previous)
-(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
-{
- return TvCastingAppJNIMgr().runCastingServerCommand(
- env, contentApp, jResponseHandler, "MediaPlayback_Previous", MediaPlayback_Previous,
- [](TargetEndpointInfo endpoint) -> CHIP_ERROR {
- return CastingServer::GetInstance()->MediaPlayback_Previous(&endpoint, [](CHIP_ERROR err) {
- TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Previous).Handle(err);
- });
- });
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1rewind)
-(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
-{
- return TvCastingAppJNIMgr().runCastingServerCommand(
- env, contentApp, jResponseHandler, "MediaPlayback_Rewind", MediaPlayback_Rewind,
- [](TargetEndpointInfo endpoint) -> CHIP_ERROR {
- return CastingServer::GetInstance()->MediaPlayback_Rewind(&endpoint, [](CHIP_ERROR err) {
- TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_Rewind).Handle(err);
- });
- });
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1fastForward)
-(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
-{
- return TvCastingAppJNIMgr().runCastingServerCommand(
- env, contentApp, jResponseHandler, "MediaPlayback_FastForward", MediaPlayback_FastForward,
- [](TargetEndpointInfo endpoint) -> CHIP_ERROR {
- return CastingServer::GetInstance()->MediaPlayback_FastForward(&endpoint, [](CHIP_ERROR err) {
- TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_FastForward).Handle(err);
- });
- });
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1startOver)
-(JNIEnv * env, jobject, jobject contentApp, jobject jResponseHandler)
-{
- return TvCastingAppJNIMgr().runCastingServerCommand(
- env, contentApp, jResponseHandler, "MediaPlayback_StartOver", MediaPlayback_StartOver,
- [](TargetEndpointInfo endpoint) -> CHIP_ERROR {
- return CastingServer::GetInstance()->MediaPlayback_StartOver(&endpoint, [](CHIP_ERROR err) {
- TvCastingAppJNIMgr().getMediaCommandResponseHandler(MediaPlayback_StartOver).Handle(err);
- });
- });
-}
-
-jboolean TvCastingAppJNI::runCastingServerCommand(JNIEnv * env, jobject contentApp, jobject jResponseHandler,
- const char * commandName, MediaCommandName command,
- const std::function & commandRunner)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD %s called", commandName);
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(command).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = commandRunner(endpoint);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.%s failed %" CHIP_ERROR_FORMAT, commandName, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1subscribeToCurrentState)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD mediaPlayback_subscribeToCurrentState called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getCurrentStateSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_CurrentState).SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr()
- .getSubscriptionEstablishedHandler(MediaPlayback_CurrentState)
- .SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->MediaPlayback_SubscribeToCurrentState(
- &endpoint, nullptr,
- [](void * context, chip::app::Clusters::MediaPlayback::Attributes::CurrentState::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getCurrentStateSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_CurrentState).Handle(err);
- },
- static_cast(minInterval), static_cast(maxInterval),
- [](void * context, chip::SubscriptionId) {
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_CurrentState).Handle();
- });
-
- VerifyOrExit(
- CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.MediaPlayback_SubscribeToCurrentState failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1subscribeToDuration)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD mediaPlayback_1subscribeToDuration called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getDurationSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_Duration).SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err =
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_Duration).SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->MediaPlayback_SubscribeToDuration(
- &endpoint, nullptr,
- [](void * context, chip::app::Clusters::MediaPlayback::Attributes::Duration::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getDurationSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_Duration).Handle(err);
- },
- static_cast(minInterval), static_cast(maxInterval),
- [](void * context, chip::SubscriptionId) {
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_Duration).Handle();
- });
-
- VerifyOrExit(
- CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.mediaPlayback_subscribeToDuration failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1subscribeToSampledPosition)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD mediaPlayback_1subscribeToSampledPosition called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getSampledPositionSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_SampledPosition).SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr()
- .getSubscriptionEstablishedHandler(MediaPlayback_SampledPosition)
- .SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->MediaPlayback_SubscribeToSampledPosition(
- &endpoint, nullptr,
- [](void * context,
- chip::app::Clusters::MediaPlayback::Attributes::SampledPosition::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getSampledPositionSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_SampledPosition).Handle(err);
- },
- static_cast(minInterval), static_cast(maxInterval),
- [](void * context, chip::SubscriptionId) {
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_SampledPosition).Handle();
- });
-
- VerifyOrExit(
- CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.mediaPlayback_subscribeToSampledPosition failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1subscribeToPlaybackSpeed)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD mediaPlayback_1subscribeToPlaybackSpeed called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getPlaybackSpeedSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_PlaybackSpeed).SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr()
- .getSubscriptionEstablishedHandler(MediaPlayback_PlaybackSpeed)
- .SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->MediaPlayback_SubscribeToPlaybackSpeed(
- &endpoint, nullptr,
- [](void * context, chip::app::Clusters::MediaPlayback::Attributes::PlaybackSpeed::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getPlaybackSpeedSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_PlaybackSpeed).Handle(err);
- },
- static_cast(minInterval), static_cast(maxInterval),
- [](void * context, chip::SubscriptionId) {
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_PlaybackSpeed).Handle();
- });
-
- VerifyOrExit(
- CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.mediaPlayback_subscribeToPlaybackSpeed failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1subscribeToSeekRangeEnd)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD mediaPlayback_1subscribeToSeekRangeEnd called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getSeekRangeEndSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_SeekRangeEnd).SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr()
- .getSubscriptionEstablishedHandler(MediaPlayback_SeekRangeEnd)
- .SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->MediaPlayback_SubscribeToSeekRangeEnd(
- &endpoint, nullptr,
- [](void * context, chip::app::Clusters::MediaPlayback::Attributes::SeekRangeEnd::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getSeekRangeEndSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_SeekRangeEnd).Handle(err);
- },
- static_cast(minInterval), static_cast(maxInterval),
- [](void * context, chip::SubscriptionId) {
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_SeekRangeEnd).Handle();
- });
-
- VerifyOrExit(
- CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.mediaPlayback_subscribeToSeekRangeEnd failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, mediaPlayback_1subscribeToSeekRangeStart)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD mediaPlayback_1subscribeToSeekRangeStart called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getSeekRangeStartSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_SeekRangeStart).SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr()
- .getSubscriptionEstablishedHandler(MediaPlayback_SeekRangeStart)
- .SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->MediaPlayback_SubscribeToSeekRangeStart(
- &endpoint, nullptr,
- [](void * context,
- chip::app::Clusters::MediaPlayback::Attributes::SeekRangeStart::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getSeekRangeStartSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(MediaPlayback_SeekRangeStart).Handle(err);
- },
- static_cast(minInterval), static_cast(maxInterval),
- [](void * context, chip::SubscriptionId) {
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(MediaPlayback_SeekRangeStart).Handle();
- });
-
- VerifyOrExit(
- CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.mediaPlayback_subscribeToSeekRangeStart failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, applicationLauncher_1launchApp)
-(JNIEnv * env, jobject, jobject contentApp, jshort catalogVendorId, jstring applicationId, jbyteArray data,
- jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD applicationLauncher_launchApp called");
-
- chip::app::Clusters::ApplicationLauncher::Structs::ApplicationStruct::Type application;
- application.catalogVendorID = static_cast(catalogVendorId);
- const char * nativeApplicationId = env->GetStringUTFChars(applicationId, 0);
- application.applicationID = CharSpan::fromCharString(nativeApplicationId);
- JniByteArray dataByteArray(env, data);
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(ApplicationLauncher_LaunchApp).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->ApplicationLauncher_LaunchApp(
- &endpoint, application, chip::MakeOptional(dataByteArray.byteSpan()),
- [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(ApplicationLauncher_LaunchApp).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.ApplicationLauncher_LaunchApp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- env->ReleaseStringUTFChars(applicationId, nativeApplicationId);
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, applicationLauncher_1stopApp)
-(JNIEnv * env, jobject, jobject contentApp, jshort catalogVendorId, jstring applicationId, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD applicationLauncher_stopApp called");
-
- chip::app::Clusters::ApplicationLauncher::Structs::ApplicationStruct::Type application;
- application.catalogVendorID = static_cast(catalogVendorId);
- const char * nativeApplicationId = env->GetStringUTFChars(applicationId, 0);
- application.applicationID = CharSpan::fromCharString(nativeApplicationId);
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(ApplicationLauncher_StopApp).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->ApplicationLauncher_StopApp(&endpoint, application, [&](CHIP_ERROR err) {
- TvCastingAppJNIMgr().getMediaCommandResponseHandler(ApplicationLauncher_StopApp).Handle(err);
- });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.ApplicationLauncher_StopApp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- env->ReleaseStringUTFChars(applicationId, nativeApplicationId);
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, applicationLauncher_1hideApp)
-(JNIEnv * env, jobject, jobject contentApp, jshort catalogVendorId, jstring applicationId, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD applicationLauncher_hideApp called");
-
- chip::app::Clusters::ApplicationLauncher::Structs::ApplicationStruct::Type application;
- application.catalogVendorID = static_cast(catalogVendorId);
- const char * nativeApplicationId = env->GetStringUTFChars(applicationId, 0);
- application.applicationID = CharSpan::fromCharString(nativeApplicationId);
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(ApplicationLauncher_HideApp).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->ApplicationLauncher_HideApp(&endpoint, application, [](CHIP_ERROR err) {
- TvCastingAppJNIMgr().getMediaCommandResponseHandler(ApplicationLauncher_HideApp).Handle(err);
- });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.ApplicationLauncher_HideApp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- env->ReleaseStringUTFChars(applicationId, nativeApplicationId);
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, targetNavigator_1navigateTarget)
-(JNIEnv * env, jobject, jobject contentApp, jbyte target, jstring data, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD targetNavigator_navigateTarget called");
-
- const char * nativeData = (data != nullptr ? env->GetStringUTFChars(data, 0) : nullptr);
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(TargetNavigator_NavigateTarget).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->TargetNavigator_NavigateTarget(
- &endpoint, static_cast(target),
- (nativeData != nullptr ? chip::MakeOptional(CharSpan::fromCharString(nativeData)) : chip::NullOptional),
- [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(TargetNavigator_NavigateTarget).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.TargetNavigator_NavigateTarget failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- if (nativeData != nullptr)
- {
- env->ReleaseStringUTFChars(data, nativeData);
- }
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, targetNavigator_1subscribeToCurrentTarget)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD targetNavigator_1subscribeToCurrentTarget called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getCurrentTargetSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(TargetNavigator_CurrentTarget).SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr()
- .getSubscriptionEstablishedHandler(TargetNavigator_CurrentTarget)
- .SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->TargetNavigator_SubscribeToCurrentTarget(
- &endpoint, nullptr,
- [](void * context,
- chip::app::Clusters::TargetNavigator::Attributes::CurrentTarget::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getCurrentTargetSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(TargetNavigator_CurrentTarget).Handle(err);
- },
- static_cast(minInterval), static_cast(maxInterval),
- [](void * context, chip::SubscriptionId) {
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(TargetNavigator_CurrentTarget).Handle();
- });
-
- VerifyOrExit(
- CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.targetNavigator_subscribeToCurrentTarget failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, targetNavigator_1subscribeToTargetList)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD targetNavigator_1subscribeToTargetList called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getTargetListSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(TargetNavigator_TargetList).SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr()
- .getSubscriptionEstablishedHandler(TargetNavigator_TargetList)
- .SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->TargetNavigator_SubscribeToTargetList(
- &endpoint, nullptr,
- [](void * context, chip::app::Clusters::TargetNavigator::Attributes::TargetList::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getTargetListSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(TargetNavigator_TargetList).Handle(err);
- },
- static_cast(minInterval), static_cast(maxInterval),
- [](void * context, chip::SubscriptionId) {
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(TargetNavigator_TargetList).Handle();
- });
-
- VerifyOrExit(
- CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.targetNavigator_subscribeToTargetList failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, keypadInput_1sendKey)
-(JNIEnv * env, jobject, jobject contentApp, jbyte keyCode, jobject jResponseHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD keypadInput_sendKey called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getMediaCommandResponseHandler(KeypadInput_SendKey).SetUp(env, jResponseHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "MatterCallbackHandlerJNI.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->KeypadInput_SendKey(
- &endpoint, static_cast(keyCode),
- [](CHIP_ERROR err) { TvCastingAppJNIMgr().getMediaCommandResponseHandler(KeypadInput_SendKey).Handle(err); });
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.KeypadInput_SendKey failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-// APPLICATION BASIC
-JNI_METHOD(jboolean, applicationBasic_1subscribeToVendorName)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD applicationBasic_1subscribeToVendorName called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getVendorNameSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(ApplicationBasic_VendorName).SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr()
- .getSubscriptionEstablishedHandler(ApplicationBasic_VendorName)
- .SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->ApplicationBasic_SubscribeToVendorName(
- &endpoint, nullptr,
- [](void * context, chip::app::Clusters::ApplicationBasic::Attributes::VendorName::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getVendorNameSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(ApplicationBasic_VendorName).Handle(err);
- },
- static_cast(minInterval), static_cast(maxInterval),
- [](void * context, chip::SubscriptionId) {
- TvCastingAppJNIMgr().getSubscriptionEstablishedHandler(ApplicationBasic_VendorName).Handle();
- });
-
- VerifyOrExit(
- CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "CastingServer.applicationBasic_subscribeToVendorName failed %" CHIP_ERROR_FORMAT, err.Format()));
-
-exit:
- return (err == CHIP_NO_ERROR);
-}
-
-JNI_METHOD(jboolean, applicationBasic_1subscribeToVendorID)
-(JNIEnv * env, jobject, jobject contentApp, jobject jReadSuccessHandler, jobject jReadFailureHandler, jint minInterval,
- jint maxInterval, jobject jSubscriptionEstablishedHandler)
-{
- chip::DeviceLayer::StackLock lock;
-
- ChipLogProgress(AppServer, "JNI_METHOD applicationBasic_1subscribeToVendorID called");
-
- TargetEndpointInfo endpoint;
- CHIP_ERROR err = convertJContentAppToTargetEndpointInfo(contentApp, endpoint);
- VerifyOrExit(err == CHIP_NO_ERROR,
- ChipLogError(AppServer, "Conversion from jobject contentApp to TargetEndpointInfo * failed: %" CHIP_ERROR_FORMAT,
- err.Format()));
-
- err = TvCastingAppJNIMgr().getVendorIDSuccessHandler().SetUp(env, jReadSuccessHandler);
- VerifyOrExit(CHIP_NO_ERROR == err, ChipLogError(AppServer, "SuccessHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(ApplicationBasic_VendorID).SetUp(env, jReadFailureHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionReadFailureHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = TvCastingAppJNIMgr()
- .getSubscriptionEstablishedHandler(ApplicationBasic_VendorID)
- .SetUp(env, jSubscriptionEstablishedHandler);
- VerifyOrExit(CHIP_NO_ERROR == err,
- ChipLogError(AppServer, "SubscriptionEstablishedHandler.SetUp failed %" CHIP_ERROR_FORMAT, err.Format()));
-
- err = CastingServer::GetInstance()->ApplicationBasic_SubscribeToVendorID(
- &endpoint, nullptr,
- [](void * context, chip::app::Clusters::ApplicationBasic::Attributes::VendorID::TypeInfo::DecodableArgType responseData) {
- TvCastingAppJNIMgr().getVendorIDSuccessHandler().Handle(responseData);
- },
- [](void * context, CHIP_ERROR err) {
- TvCastingAppJNIMgr().getSubscriptionReadFailureHandler(ApplicationBasic_VendorID).Handle(err);
- },
- static_cast