Skip to content

Commit

Permalink
Fixed JNI loading issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed Aug 21, 2024
1 parent 510b82d commit 9dc0ad0
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 32 deletions.
1 change: 1 addition & 0 deletions examples/tv-casting-app/android/App/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ android {
'src/main/java',
'src/main/jni',
'src/compat/java',
'src/compat/jni',
]

// uncomment this code to debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,26 @@ public boolean purgeCache() {
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 =
contentApp.getEndpoint().getCluster(ChipClusters.ContentLauncherCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.ContentLauncherCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down Expand Up @@ -387,8 +402,9 @@ public boolean contentLauncher_launchContent(
String data,
Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.ContentLauncherCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.ContentLauncherCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.ContentLauncherCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down Expand Up @@ -444,8 +460,9 @@ public void onError(Exception error) {

public boolean mediaPlayback_play(ContentApp contentApp, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.MediaPlaybackCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.MediaPlaybackCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -471,8 +488,9 @@ public void onError(Exception error) {

public boolean mediaPlayback_pause(ContentApp contentApp, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.MediaPlaybackCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.MediaPlaybackCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -498,8 +516,9 @@ public void onError(Exception error) {

public boolean mediaPlayback_stopPlayback(ContentApp contentApp, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.MediaPlaybackCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.MediaPlaybackCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -525,8 +544,9 @@ public void onError(Exception error) {

public boolean mediaPlayback_next(ContentApp contentApp, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.MediaPlaybackCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.MediaPlaybackCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -552,8 +572,10 @@ public void onError(Exception error) {

public boolean mediaPlayback_previous(ContentApp contentApp, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.MediaPlaybackCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.MediaPlaybackCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;

if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -579,8 +601,9 @@ public void onError(Exception error) {

public boolean mediaPlayback_rewind(ContentApp contentApp, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.MediaPlaybackCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.MediaPlaybackCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -607,8 +630,9 @@ public void onError(Exception error) {

public boolean mediaPlayback_fastForward(ContentApp contentApp, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.MediaPlaybackCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.MediaPlaybackCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -635,8 +659,9 @@ public void onError(Exception error) {

public boolean mediaPlayback_startOver(ContentApp contentApp, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.MediaPlaybackCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.MediaPlaybackCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -662,8 +687,9 @@ public void onError(Exception error) {

public boolean mediaPlayback_seek(ContentApp contentApp, long position, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.MediaPlaybackCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.MediaPlaybackCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down Expand Up @@ -691,8 +717,9 @@ public void onError(Exception error) {
public boolean mediaPlayback_skipForward(
ContentApp contentApp, long deltaPositionMilliseconds, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.MediaPlaybackCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.MediaPlaybackCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down Expand Up @@ -720,8 +747,9 @@ public void onError(Exception error) {
public boolean mediaPlayback_skipBackward(
ContentApp contentApp, long deltaPositionMilliseconds, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.MediaPlaybackCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.MediaPlaybackCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down Expand Up @@ -754,8 +782,9 @@ public boolean mediaPlayback_subscribeToCurrentState(
int maxInterval,
SubscriptionEstablishedCallback subscriptionEstablishedHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.MediaPlaybackCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.MediaPlaybackCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down Expand Up @@ -791,8 +820,11 @@ public boolean applicationLauncher_launchApp(
byte[] data,
Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.ApplicationLauncherCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.ApplicationLauncherCluster.class);
endpoint != null
? endpoint.getCluster(ChipClusters.ApplicationLauncherCluster.class)
: null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down Expand Up @@ -831,8 +863,11 @@ public void onError(Exception error) {
public boolean applicationLauncher_stopApp(
ContentApp contentApp, short catalogVendorId, String applicationId, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.ApplicationLauncherCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.ApplicationLauncherCluster.class);
endpoint != null
? endpoint.getCluster(ChipClusters.ApplicationLauncherCluster.class)
: null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down Expand Up @@ -870,8 +905,11 @@ public void onError(Exception error) {
public boolean applicationLauncher_hideApp(
ContentApp contentApp, short catalogVendorId, String applicationId, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.ApplicationLauncherCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.ApplicationLauncherCluster.class);
endpoint != null
? endpoint.getCluster(ChipClusters.ApplicationLauncherCluster.class)
: null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down Expand Up @@ -909,8 +947,9 @@ public void onError(Exception error) {
public boolean targetNavigator_navigateTarget(
ContentApp contentApp, byte target, String data, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.TargetNavigatorCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.TargetNavigatorCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.TargetNavigatorCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down Expand Up @@ -944,8 +983,9 @@ public boolean targetNavigator_subscribeToTargetList(
int maxInterval,
SubscriptionEstablishedCallback subscriptionEstablishedHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.TargetNavigatorCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.TargetNavigatorCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.TargetNavigatorCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down Expand Up @@ -985,8 +1025,9 @@ public void onSubscriptionEstablished(long subscriptionId) {

public boolean keypadInput_sendKey(ContentApp contentApp, byte keyCode, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.KeypadInputCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.KeypadInputCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.KeypadInputCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down Expand Up @@ -1016,8 +1057,9 @@ public boolean applicationBasic_readVendorName(
SuccessCallback<String> readSuccessHandler,
FailureCallback readFailureHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.ApplicationBasicCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.ApplicationBasicCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -1044,8 +1086,9 @@ public boolean applicationBasic_readVendorID(
SuccessCallback<Integer> readSuccessHandler,
FailureCallback readFailureHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.ApplicationBasicCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.ApplicationBasicCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -1072,8 +1115,9 @@ public boolean applicationBasic_readApplicationName(
SuccessCallback<String> readSuccessHandler,
FailureCallback readFailureHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.ApplicationBasicCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.ApplicationBasicCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -1100,8 +1144,9 @@ public boolean applicationBasic_readProductID(
SuccessCallback<Integer> readSuccessHandler,
FailureCallback readFailureHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.ApplicationBasicCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.ApplicationBasicCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -1128,8 +1173,9 @@ public boolean applicationBasic_readApplicationVersion(
SuccessCallback<String> readSuccessHandler,
FailureCallback readFailureHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.ApplicationBasicCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.ApplicationBasicCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -1153,8 +1199,9 @@ public void onError(Exception error) {

public boolean onOff_on(ContentApp contentApp, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.OnOffCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.OnOffCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.OnOffCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -1180,8 +1227,9 @@ public void onError(Exception error) {

public boolean onOff_off(ContentApp contentApp, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.OnOffCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.OnOffCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.OnOffCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand All @@ -1207,8 +1255,9 @@ public void onError(Exception error) {

public boolean onOff_toggle(ContentApp contentApp, Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.OnOffCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.OnOffCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.OnOffCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down Expand Up @@ -1242,8 +1291,10 @@ public boolean messages_presentMessages(
String messageText,
Optional<ArrayList<ChipStructs.MessagesClusterMessageResponseOptionStruct>> responses,
Object responseHandler) {

Endpoint endpoint = getTargetEndpoint(contentApp);
ChipClusters.MessagesCluster cluster =
contentApp.getEndpoint().getCluster(ChipClusters.MessagesCluster.class);
endpoint != null ? endpoint.getCluster(ChipClusters.MessagesCluster.class) : null;
if (cluster == null) {
Log.e(TAG, "Cluster not found");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import com.R;
import com.chip.casting.AppParameters;
import com.chip.casting.DiscoveredNodeData;
Expand All @@ -19,7 +17,6 @@
import com.chip.casting.app.SelectClusterFragment;
import com.chip.casting.util.GlobalCastingConstants;
import com.matter.casting.core.CastingPlayer;

import java.util.Random;

public class MainActivity extends AppCompatActivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <app/clusters/bindings/BindingManager.h>
#include <app/server/Server.h>
#include <app/server/java/AndroidAppServerWrapper.h>
#include <jni.h>
#include <lib/support/JniReferences.h>
#include <lib/support/JniTypeWrappers.h>
Expand All @@ -37,6 +38,16 @@ using namespace chip;

#define JNI_METHOD(RETURN, METHOD_NAME) extern "C" JNIEXPORT RETURN JNICALL Java_com_matter_casting_core_CastingApp_##METHOD_NAME

jint JNI_OnLoad(JavaVM * jvm, void * reserved)
{
return AndroidAppServerJNI_OnLoad(jvm, reserved);
}

void JNI_OnUnload(JavaVM * jvm, void * reserved)
{
return AndroidAppServerJNI_OnUnload(jvm, reserved);
}

namespace matter {
namespace casting {
namespace core {
Expand Down

0 comments on commit 9dc0ad0

Please sign in to comment.