Skip to content

Commit

Permalink
Fix JNI type casts in matter jni layer (#26559)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google authored and pull[bot] committed Dec 4, 2023
1 parent 6421711 commit 1036596
Show file tree
Hide file tree
Showing 24 changed files with 197 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ class WildcardFragment : Fragment() {

private suspend fun readCurrentFabricIndex() : UInt {
val context = requireContext()
val endpointId = 0L
val endpointId = 0
val clusterId = 62L // OperationalCredentials
val attributeId = 5L // CurrentFabricIndex
val deviceId = addressUpdateFragment.deviceId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PairOnNetworkLongImInvokeCommand(
tlvWriter.endStructure()

val element: InvokeElement = InvokeElement.newInstance( /* endpointId= */
0L, CLUSTER_ID_IDENTIFY, IDENTIFY_COMMAND, tlvWriter.getEncoded(), null
0, CLUSTER_ID_IDENTIFY, IDENTIFY_COMMAND, tlvWriter.getEncoded(), null
)

currentCommissioner()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ContentAppEndpointManagerImpl(Context context) {
this.context = context;
}

public String sendCommand(int endpointId, int clusterId, int commandId, String commandPayload) {
public String sendCommand(int endpointId, long clusterId, long commandId, String commandPayload) {
Log.d(TAG, "Received a command for endpointId " + endpointId + ". Message " + commandPayload);

ContentApp discoveredApp =
Expand Down Expand Up @@ -54,7 +54,7 @@ public String sendCommand(int endpointId, int clusterId, int commandId, String c
return "Success";
}

public String readAttribute(int endpointId, int clusterId, int attributeId) {
public String readAttribute(int endpointId, long clusterId, long attributeId) {
Log.d(
TAG,
"Received a attribute read request for endpointId "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ public IBinder onBind(final Intent intent) {
}

public static String sendCommand(
Context context, String packageName, int clusterId, int commandId, String payload) {
Context context, String packageName, long clusterId, long commandId, String payload) {
Intent in = new Intent(MatterIntentConstants.ACTION_MATTER_COMMAND);
Bundle extras = new Bundle();
extras.putByteArray(MatterIntentConstants.EXTRA_COMMAND_PAYLOAD, payload.getBytes());
extras.putInt(MatterIntentConstants.EXTRA_COMMAND_ID, commandId);
extras.putInt(MatterIntentConstants.EXTRA_CLUSTER_ID, clusterId);
extras.putLong(MatterIntentConstants.EXTRA_COMMAND_ID, commandId);
extras.putLong(MatterIntentConstants.EXTRA_CLUSTER_ID, clusterId);
in.putExtras(extras);
in.setPackage(packageName);
int flags = Intent.FLAG_INCLUDE_STOPPED_PACKAGES;
Expand All @@ -127,13 +127,13 @@ public static String sendCommand(
}

public static String sendAttributeReadRequest(
Context context, String packageName, int clusterId, int attributeId) {
Context context, String packageName, long clusterId, long attributeId) {
Intent in = new Intent(MatterIntentConstants.ACTION_MATTER_COMMAND);
Bundle extras = new Bundle();
extras.putString(
MatterIntentConstants.EXTRA_ATTRIBUTE_ACTION, MatterIntentConstants.ATTRIBUTE_ACTION_READ);
extras.putInt(MatterIntentConstants.EXTRA_ATTRIBUTE_ID, attributeId);
extras.putInt(MatterIntentConstants.EXTRA_CLUSTER_ID, clusterId);
extras.putLong(MatterIntentConstants.EXTRA_ATTRIBUTE_ID, attributeId);
extras.putLong(MatterIntentConstants.EXTRA_CLUSTER_ID, clusterId);
in.putExtras(extras);
in.setPackage(packageName);
int flags = Intent.FLAG_INCLUDE_STOPPED_PACKAGES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,26 @@ public void init(@NonNull Context context) {
mTvApp =
new TvApp(
(app, clusterId, endpoint) -> {
switch (clusterId) {
case Clusters.ClusterId_KeypadInput:
app.setKeypadInputManager(endpoint, new KeypadInputManagerStub(endpoint));
break;
case Clusters.ClusterId_WakeOnLan:
app.setWakeOnLanManager(endpoint, new WakeOnLanManagerStub(endpoint));
break;
case Clusters.ClusterId_MediaInput:
app.setMediaInputManager(endpoint, new MediaInputManagerStub(endpoint));
break;
case Clusters.ClusterId_ContentLauncher:
app.setContentLaunchManager(endpoint, new ContentLaunchManagerStub(endpoint));
break;
case Clusters.ClusterId_LowPower:
app.setLowPowerManager(endpoint, new LowPowerManagerStub(endpoint));
break;
case Clusters.ClusterId_MediaPlayback:
app.setMediaPlaybackManager(endpoint, new MediaPlaybackManagerStub(endpoint));
break;
case Clusters.ClusterId_Channel:
app.setChannelManager(endpoint, new ChannelManagerStub(endpoint));
break;
case Clusters.ClusterId_OnOff:
mOnOffEndpoint = endpoint;
app.setOnOffManager(endpoint, new OnOffManagerStub(endpoint));
break;
case Clusters.ClusterId_LevelControl:
mLevelEndpoint = endpoint;
app.setLevelManager(endpoint, new LevelManagerStub(endpoint));
break;
if (clusterId == Clusters.ClusterId_KeypadInput) {
app.setKeypadInputManager(endpoint, new KeypadInputManagerStub(endpoint));
} else if (clusterId == Clusters.ClusterId_WakeOnLan) {
app.setWakeOnLanManager(endpoint, new WakeOnLanManagerStub(endpoint));
} else if (clusterId == Clusters.ClusterId_MediaInput) {
app.setMediaInputManager(endpoint, new MediaInputManagerStub(endpoint));
} else if (clusterId == Clusters.ClusterId_ContentLauncher) {
app.setContentLaunchManager(endpoint, new ContentLaunchManagerStub(endpoint));
} else if (clusterId == Clusters.ClusterId_LowPower) {
app.setLowPowerManager(endpoint, new LowPowerManagerStub(endpoint));
} else if (clusterId == Clusters.ClusterId_MediaPlayback) {
app.setMediaPlaybackManager(endpoint, new MediaPlaybackManagerStub(endpoint));
} else if (clusterId == Clusters.ClusterId_Channel) {
app.setChannelManager(endpoint, new ChannelManagerStub(endpoint));
} else if (clusterId == Clusters.ClusterId_OnOff) {
mOnOffEndpoint = endpoint;
app.setOnOffManager(endpoint, new OnOffManagerStub(endpoint));
} else if (clusterId == Clusters.ClusterId_LevelControl) {
mLevelEndpoint = endpoint;
app.setLevelManager(endpoint, new LevelManagerStub(endpoint));
}
});
mTvApp.setDACProvider(new DACProviderStub());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ std::string ContentAppAttributeDelegate::Read(const chip::app::ConcreteReadAttri

jstring resp =
(jstring) env->CallObjectMethod(mContentAppEndpointManager, mReadAttributeMethod, static_cast<jint>(aPath.mEndpointId),
static_cast<jint>(aPath.mClusterId), static_cast<jint>(aPath.mAttributeId));
static_cast<jlong>(aPath.mClusterId), static_cast<jlong>(aPath.mAttributeId));
if (env->ExceptionCheck())
{
ChipLogError(Zcl, "Java exception in ContentAppAttributeDelegate::Read");
Expand Down
2 changes: 1 addition & 1 deletion examples/tv-app/android/java/ContentAppAttributeDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ContentAppAttributeDelegate
VerifyOrReturn(ContentAppEndpointManagerClass != nullptr,
ChipLogError(Zcl, "Failed to get ContentAppEndpointManager Java class"));

mReadAttributeMethod = env->GetMethodID(ContentAppEndpointManagerClass, "readAttribute", "(III)Ljava/lang/String;");
mReadAttributeMethod = env->GetMethodID(ContentAppEndpointManagerClass, "readAttribute", "(IJJ)Ljava/lang/String;");
if (mReadAttributeMethod == nullptr)
{
ChipLogError(Zcl, "Failed to access ContentAppEndpointManager 'readAttribute' method");
Expand Down
4 changes: 2 additions & 2 deletions examples/tv-app/android/java/ContentAppCommandDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void ContentAppCommandDelegate::InvokeCommand(CommandHandlerInterface::HandlerCo

jstring resp = (jstring) env->CallObjectMethod(
mContentAppEndpointManager, mSendCommandMethod, static_cast<jint>(handlerContext.mRequestPath.mEndpointId),
static_cast<jint>(handlerContext.mRequestPath.mClusterId), static_cast<jint>(handlerContext.mRequestPath.mCommandId),
static_cast<jlong>(handlerContext.mRequestPath.mClusterId), static_cast<jlong>(handlerContext.mRequestPath.mCommandId),
jsonString.jniValue());
if (env->ExceptionCheck())
{
Expand Down Expand Up @@ -108,7 +108,7 @@ Status ContentAppCommandDelegate::InvokeCommand(EndpointId epId, ClusterId clust

jstring resp =
(jstring) env->CallObjectMethod(mContentAppEndpointManager, mSendCommandMethod, static_cast<jint>(epId),
static_cast<jint>(clusterId), static_cast<jint>(commandId), jsonString.jniValue());
static_cast<jlong>(clusterId), static_cast<jlong>(commandId), jsonString.jniValue());
if (env->ExceptionCheck())
{
ChipLogError(Zcl, "Java exception in ContentAppCommandDelegate::sendCommand");
Expand Down
2 changes: 1 addition & 1 deletion examples/tv-app/android/java/ContentAppCommandDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ContentAppCommandDelegate : public CommandHandlerInterface
ChipLogError(Zcl, "Failed to get ContentAppEndpointManager Java class"));

mSendCommandMethod =
env->GetMethodID(ContentAppEndpointManagerClass, "sendCommand", "(IIILjava/lang/String;)Ljava/lang/String;");
env->GetMethodID(ContentAppEndpointManagerClass, "sendCommand", "(IJJLjava/lang/String;)Ljava/lang/String;");
if (mSendCommandMethod == nullptr)
{
ChipLogError(Zcl, "Failed to access ContentAppEndpointManager 'sendCommand' method");
Expand Down
4 changes: 2 additions & 2 deletions examples/tv-app/android/java/TVApp-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void TvAppJNI::InitializeWithObjects(jobject app)
jclass managerClass = env->GetObjectClass(mTvAppObject);
VerifyOrReturn(managerClass != nullptr, ChipLogError(Zcl, "Failed to get TvAppJNI Java class"));

mPostClusterInitMethod = env->GetMethodID(managerClass, "postClusterInit", "(II)V");
mPostClusterInitMethod = env->GetMethodID(managerClass, "postClusterInit", "(JI)V");
if (mPostClusterInitMethod == nullptr)
{
ChipLogError(Zcl, "Failed to access ChannelManager 'postClusterInit' method");
Expand All @@ -79,7 +79,7 @@ void TvAppJNI::PostClusterInit(int clusterId, int endpoint)
VerifyOrReturn(mTvAppObject != nullptr, ChipLogError(Zcl, "TvAppJNI::mTvAppObject null"));
VerifyOrReturn(mPostClusterInitMethod != nullptr, ChipLogError(Zcl, "TvAppJNI::mPostClusterInitMethod null"));

env->CallVoidMethod(mTvAppObject, mPostClusterInitMethod, static_cast<jint>(clusterId), static_cast<jint>(endpoint));
env->CallVoidMethod(mTvAppObject, mPostClusterInitMethod, static_cast<jlong>(clusterId), static_cast<jint>(endpoint));
if (env->ExceptionCheck())
{
ChipLogError(Zcl, "Failed to call TvAppJNI 'postClusterInit' method");
Expand Down
Loading

0 comments on commit 1036596

Please sign in to comment.