Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messages cluster sample app for android #32162

Merged
merged 7 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.matter.tv.server.tvapp.LowPowerManagerStub;
import com.matter.tv.server.tvapp.MediaInputManagerStub;
import com.matter.tv.server.tvapp.MediaPlaybackManagerStub;
import com.matter.tv.server.tvapp.MessagesManagerStub;
import com.matter.tv.server.tvapp.OnOffManagerStub;
import com.matter.tv.server.tvapp.TvApp;
import com.matter.tv.server.tvapp.WakeOnLanManagerStub;
Expand Down Expand Up @@ -96,6 +97,8 @@ public void init(@NonNull Context context) {
app.setMediaPlaybackManager(endpoint, new MediaPlaybackManagerStub(endpoint));
} else if (clusterId == Clusters.ClusterId_Channel) {
app.setChannelManager(endpoint, new ChannelManagerStub(endpoint));
} else if (clusterId == Clusters.ClusterId_Messaging) {
app.setMessagesManager(endpoint, new MessagesManagerStub(endpoint));
} else if (clusterId == Clusters.ClusterId_OnOff) {
mOnOffEndpoint = endpoint;
app.setOnOffManager(endpoint, new OnOffManagerStub(endpoint));
Expand Down
6 changes: 6 additions & 0 deletions examples/tv-app/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ shared_library("jni") {
"java/MediaInputManager.h",
"java/MediaPlaybackManager.cpp",
"java/MediaPlaybackManager.h",
"java/MessagesManager.cpp",
"java/MessagesManager.h",
"java/MyUserPrompter-JNI.cpp",
"java/MyUserPrompter-JNI.h",
"java/MyUserPrompterResolver-JNI.cpp",
Expand Down Expand Up @@ -143,6 +145,10 @@ android_library("java") {
"java/src/com/matter/tv/server/tvapp/MediaPlaybackManagerStub.java",
"java/src/com/matter/tv/server/tvapp/MediaPlaybackPosition.java",
"java/src/com/matter/tv/server/tvapp/MediaTrack.java",
"java/src/com/matter/tv/server/tvapp/Message.java",
"java/src/com/matter/tv/server/tvapp/MessageResponseOption.java",
"java/src/com/matter/tv/server/tvapp/MessagesManager.java",
"java/src/com/matter/tv/server/tvapp/MessagesManagerStub.java",
"java/src/com/matter/tv/server/tvapp/OnOffManager.java",
"java/src/com/matter/tv/server/tvapp/OnOffManagerStub.java",
"java/src/com/matter/tv/server/tvapp/TvApp.java",
Expand Down
425 changes: 425 additions & 0 deletions examples/tv-app/android/java/MessagesManager.cpp

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions examples/tv-app/android/java/MessagesManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
*
* Copyright (c) 2024 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 <app/clusters/messages-server/messages-server.h>

#include <iostream>
#include <list>

#include <jni.h>
#include <lib/support/JniReferences.h>

class MessagesManager : public chip::app::Clusters::Messages::Delegate
{
public:
static void NewManager(jint endpoint, jobject manager);
void InitializeWithObjects(jobject managerObject);

// Commands
CHIP_ERROR HandlePresentMessagesRequest(
const chip::ByteSpan & messageId, const chip::app::Clusters::Messages::MessagePriorityEnum & priority,
const chip::BitMask<chip::app::Clusters::Messages::MessageControlBitmap> & messageControl,
const chip::app::DataModel::Nullable<uint32_t> & startTime, const chip::app::DataModel::Nullable<uint16_t> & duration,
const chip::CharSpan & messageText,
const chip::Optional<
chip::app::DataModel::DecodableList<chip::app::Clusters::Messages::Structs::MessageResponseOptionStruct::Type>> &
responses) override;
CHIP_ERROR HandleCancelMessagesRequest(const chip::app::DataModel::DecodableList<chip::ByteSpan> & messageIds) override;

// Attributes
CHIP_ERROR HandleGetMessages(chip::app::AttributeValueEncoder & aEncoder) override;
CHIP_ERROR HandleGetActiveMessageIds(chip::app::AttributeValueEncoder & aEncoder) override;

// Global Attributes
uint32_t GetFeatureMap(chip::EndpointId endpoint) override;
// uint16_t GetClusterRevision(chip::EndpointId endpoint) override;

private:
chip::JniGlobalReference mMessagesManagerObject;
jmethodID mGetMessagesMethod = nullptr;

jmethodID mPresentMessagesMethod = nullptr;
jmethodID mCancelMessagesMethod = nullptr;

// TODO: set this based upon meta data from app
static constexpr uint32_t kEndpointFeatureMap = 15;
// static constexpr uint16_t kClusterRevision = 1;
};
6 changes: 6 additions & 0 deletions examples/tv-app/android/java/TVApp-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "LowPowerManager.h"
#include "MediaInputManager.h"
#include "MediaPlaybackManager.h"
#include "MessagesManager.h"
#include "MyUserPrompter-JNI.h"
#include "OnOffManager.h"
#include "WakeOnLanManager.h"
Expand Down Expand Up @@ -137,6 +138,11 @@ JNI_METHOD(void, setMediaPlaybackManager)(JNIEnv *, jobject, jint endpoint, jobj
MediaPlaybackManager::NewManager(endpoint, manager);
}

JNI_METHOD(void, setMessagesManager)(JNIEnv *, jobject, jint endpoint, jobject manager)
{
MessagesManager::NewManager(endpoint, manager);
}

JNI_METHOD(void, setChannelManager)(JNIEnv *, jobject, jint endpoint, jobject manager)
{
ChannelManager::NewManager(endpoint, manager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public class Clusters {
public static final long ClusterId_ApplicationBasic = 0x0000050D;
public static final long ClusterId_AccountLogin = 0x0000050E;
public static final long ClusterId_TestCluster = 0xFFF1FC05;
public static final long ClusterId_Messaging = 0x00000703;
public static final long ClusterId_Messaging = 0x00000097;
public static final long ClusterId_ApplianceIdentification = 0x00000B00;
public static final long ClusterId_MeterIdentification = 0x00000B01;
public static final long ClusterId_ApplianceEventsAndAlert = 0x00000B02;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2024 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.matter.tv.server.tvapp;

import java.util.Vector;

public class Message {

public class PriorityType {
int priority;
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
public PriorityType(int priority)
{
this.priority = priority;
}
}

public String messageId;
public PriorityType priority;
public int messageControl;
public long startTime;
public int duration;
public String messageText;
public Vector<MessageResponseOption> responseOptions;

public Message(String messageId,
PriorityType priority,
int messageControl,
long startTime,
int duration,
String messageText,
Vector<MessageResponseOption> responseOptions)
{
this.messageId = messageId;
this.priority = priority;
this.messageControl = messageControl;
this.startTime = startTime;
this.duration = duration;
this.messageText = messageText;
this.responseOptions = responseOptions;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 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.matter.tv.server.tvapp;

public class MessageResponseOption {
public long id;
yunhanw-google marked this conversation as resolved.
Show resolved Hide resolved
public String label;

public MessageResponseOption(
long id,
String label) {
this.id = id;
this.label = label;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024 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.matter.tv.server.tvapp;

import java.util.Vector;
import com.matter.tv.server.tvapp.Message.PriorityType;

public interface MessagesManager {

Message[] getMessages();

boolean presentMessages(String messageId,
PriorityType priority,
int messageControl,
long startTime,
int duration,
String messageText,
Vector<MessageResponseOption> responseOptions);

boolean cancelMessage(String messageId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2024 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.matter.tv.server.tvapp;

import android.util.Log;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import com.matter.tv.server.tvapp.Message.PriorityType;

public class MessagesManagerStub implements MessagesManager {
private static final String TAG = MessagesManagerStub.class.getSimpleName();

private int endpoint;
chrisdecenzo marked this conversation as resolved.
Show resolved Hide resolved

private Map<String,Message> messages = new HashMap<String,Message>();

public MessagesManagerStub(int endpoint) {
this.endpoint = endpoint;
Log.d(TAG, "MessagesManagerStub: at " + this.endpoint);
}

@Override
public Message[] getMessages() {
Log.d(TAG, "getMessages: at " + this.endpoint);
return messages.values().toArray(new Message[0]);
}

@Override
public boolean presentMessages(String messageId,
PriorityType priority,
int messageControl,
long startTime,
int duration,
String messageText,
Vector<MessageResponseOption> responseOptions) {
Log.d(TAG, "presentMessages: at " + this.endpoint + " id:" + messageId+ " text:"+messageText);
messages.put(messageId, new Message(messageId,
priority,
messageControl,
startTime,
duration,
messageText,
responseOptions));
return true;
}

@Override
public boolean cancelMessage(String messageId)
{
Log.d(TAG, "cancelMessage: at " + this.endpoint + " messageId:"+messageId);
messages.remove(messageId);
return true; // per spec, succeed unless error
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ private void postClusterInit(long clusterId, int endpoint) {

public native void setMediaPlaybackManager(int endpoint, MediaPlaybackManager manager);

public native void setMessagesManager(int endpoint, MessagesManager manager);

public native void setChannelManager(int endpoint, ChannelManager manager);

public native void setOnOffManager(int endpoint, OnOffManager manager);
Expand Down
Loading