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 4 commits
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
20 changes: 19 additions & 1 deletion examples/tv-app/android/java/ChannelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void ChannelManager::NewManager(jint endpoint, jobject manager)

CHIP_ERROR ChannelManager::HandleGetChannelList(AttributeValueEncoder & aEncoder)
{
DeviceLayer::StackUnlock unlock;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NULL_OBJECT, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
Expand All @@ -66,6 +67,8 @@ CHIP_ERROR ChannelManager::HandleGetChannelList(AttributeValueEncoder & aEncoder
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetChannelListMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);

env->ExceptionClear();

return aEncoder.EncodeList([this, env](const auto & encoder) -> CHIP_ERROR {
jobjectArray channelInfoList =
(jobjectArray) env->CallObjectMethod(mChannelManagerObject.ObjectRef(), mGetChannelListMethod);
Expand Down Expand Up @@ -134,6 +137,7 @@ CHIP_ERROR ChannelManager::HandleGetChannelList(AttributeValueEncoder & aEncoder

CHIP_ERROR ChannelManager::HandleGetLineup(AttributeValueEncoder & aEncoder)
{
DeviceLayer::StackUnlock unlock;
chip::app::Clusters::Channel::Structs::LineupInfoStruct::Type lineupInfo;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
Expand All @@ -144,6 +148,8 @@ CHIP_ERROR ChannelManager::HandleGetLineup(AttributeValueEncoder & aEncoder)
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetLineupMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);

env->ExceptionClear();

{
jobject channelLineupObject = env->CallObjectMethod(mChannelManagerObject.ObjectRef(), mGetLineupMethod);
if (channelLineupObject != nullptr)
Expand Down Expand Up @@ -197,6 +203,7 @@ CHIP_ERROR ChannelManager::HandleGetLineup(AttributeValueEncoder & aEncoder)

CHIP_ERROR ChannelManager::HandleGetCurrentChannel(AttributeValueEncoder & aEncoder)
{
DeviceLayer::StackUnlock unlock;
chip::app::Clusters::Channel::Structs::ChannelInfoStruct::Type channelInfo;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
Expand All @@ -207,6 +214,8 @@ CHIP_ERROR ChannelManager::HandleGetCurrentChannel(AttributeValueEncoder & aEnco
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetCurrentChannelMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);

env->ExceptionClear();

{
jobject channelInfoObject = env->CallObjectMethod(mChannelManagerObject.ObjectRef(), mGetCurrentChannelMethod);
if (channelInfoObject != nullptr)
Expand Down Expand Up @@ -273,6 +282,7 @@ CHIP_ERROR ChannelManager::HandleGetCurrentChannel(AttributeValueEncoder & aEnco

void ChannelManager::HandleChangeChannel(CommandResponseHelper<ChangeChannelResponseType> & helper, const CharSpan & match)
{
DeviceLayer::StackUnlock unlock;
std::string name(match.data(), match.size());
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
Expand All @@ -282,9 +292,10 @@ void ChannelManager::HandleChangeChannel(CommandResponseHelper<ChangeChannelResp
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), ChipLogError(Zcl, "mChannelManagerObject null"));
VerifyOrExit(mChangeChannelMethod != nullptr, ChipLogError(Zcl, "mChangeChannelMethod null"));

env->ExceptionClear();

{
UtfString jniname(env, name.c_str());
env->ExceptionClear();
jobject channelObject = env->CallObjectMethod(mChannelManagerObject.ObjectRef(), mChangeChannelMethod, jniname.jniValue());
if (env->ExceptionCheck())
{
Expand Down Expand Up @@ -319,6 +330,7 @@ void ChannelManager::HandleChangeChannel(CommandResponseHelper<ChangeChannelResp

bool ChannelManager::HandleChangeChannelByNumber(const uint16_t & majorNumber, const uint16_t & minorNumber)
{
DeviceLayer::StackUnlock unlock;
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
Expand Down Expand Up @@ -347,6 +359,7 @@ bool ChannelManager::HandleChangeChannelByNumber(const uint16_t & majorNumber, c

bool ChannelManager::HandleSkipChannel(const int16_t & count)
{
DeviceLayer::StackUnlock unlock;
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
Expand Down Expand Up @@ -379,6 +392,7 @@ void ChannelManager::HandleGetProgramGuide(
const chip::Optional<chip::app::DataModel::DecodableList<AdditionalInfoType>> & externalIdList,
const chip::Optional<chip::ByteSpan> & data)
{
DeviceLayer::StackUnlock unlock;
ProgramGuideResponseType response;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
Expand All @@ -394,6 +408,8 @@ void ChannelManager::HandleGetProgramGuide(
VerifyOrExit(mChannelManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetProgramGuideMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);

env->ExceptionClear();

{
// NOTE: this example app does not pass the Data, PageToken, ChannelsArray or ExternalIdList through to the Java layer
UtfString jData(env, "");
Expand Down Expand Up @@ -591,6 +607,7 @@ bool ChannelManager::HandleRecordProgram(const chip::CharSpan & programIdentifie
const DataModel::DecodableList<AdditionalInfo> & externalIdList,
const chip::ByteSpan & data)
{
DeviceLayer::StackUnlock unlock;
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
Expand Down Expand Up @@ -628,6 +645,7 @@ bool ChannelManager::HandleCancelRecordProgram(const chip::CharSpan & programIde
const DataModel::DecodableList<AdditionalInfo> & externalIdList,
const chip::ByteSpan & data)
{
DeviceLayer::StackUnlock unlock;
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <lib/support/CHIPJNIError.h>
#include <lib/support/JniReferences.h>
#include <lib/support/JniTypeWrappers.h>
#include <platform/PlatformManager.h>
#include <zap-generated/endpoint_config.h>

namespace chip {
Expand All @@ -43,6 +44,7 @@ std::string ContentAppAttributeDelegate::Read(const chip::app::ConcreteReadAttri
return "";
}

DeviceLayer::StackUnlock unlock;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
ChipLogProgress(Zcl, "ContentAppAttributeDelegate::Read being called for endpoint %d cluster %d attribute %d",
aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId);
Expand Down
2 changes: 2 additions & 0 deletions examples/tv-app/android/java/ContentAppCommandDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <lib/support/JniReferences.h>
#include <lib/support/JniTypeWrappers.h>
#include <lib/support/jsontlv/TlvJson.h>
#include <platform/PlatformManager.h>
#include <zap-generated/endpoint_config.h>

namespace chip {
Expand All @@ -50,6 +51,7 @@ void ContentAppCommandDelegate::InvokeCommand(CommandHandlerInterface::HandlerCo
{
if (handlerContext.mRequestPath.mEndpointId >= FIXED_ENDPOINT_COUNT)
{
DeviceLayer::StackUnlock unlock;
TLV::TLVReader readerForJson;
readerForJson.Init(handlerContext.mPayload);

Expand Down
11 changes: 11 additions & 0 deletions examples/tv-app/android/java/ContentLauncherManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void ContentLauncherManager::HandleLaunchContent(CommandResponseHelper<LaunchRes
const chip::Optional<PlaybackPreferencesType> playbackPreferences,
bool useCurrentContext)
{
DeviceLayer::StackUnlock unlock;
Commands::LauncherResponse::Type response;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
Expand All @@ -61,6 +62,7 @@ void ContentLauncherManager::HandleLaunchContent(CommandResponseHelper<LaunchRes
VerifyOrExit(mContentLauncherManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mLaunchContentMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);

env->ExceptionClear();
{
UtfString jData(env, data);

Expand Down Expand Up @@ -106,6 +108,7 @@ void ContentLauncherManager::HandleLaunchUrl(CommandResponseHelper<LaunchRespons
const chip::CharSpan & displayString,
const BrandingInformationType & brandingInformation)
{
DeviceLayer::StackUnlock unlock;
Commands::LauncherResponse::Type response;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
Expand All @@ -116,6 +119,8 @@ void ContentLauncherManager::HandleLaunchUrl(CommandResponseHelper<LaunchRespons
VerifyOrExit(mContentLauncherManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mLaunchUrlMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);

env->ExceptionClear();

{
UtfString jContentUrl(env, contentUrl);
UtfString jDisplayString(env, displayString);
Expand Down Expand Up @@ -160,6 +165,7 @@ void ContentLauncherManager::HandleLaunchUrl(CommandResponseHelper<LaunchRespons

CHIP_ERROR ContentLauncherManager::HandleGetAcceptHeaderList(AttributeValueEncoder & aEncoder)
{
DeviceLayer::StackUnlock unlock;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
std::list<std::string> acceptedHeadersList;
Expand All @@ -170,6 +176,8 @@ CHIP_ERROR ContentLauncherManager::HandleGetAcceptHeaderList(AttributeValueEncod
VerifyOrExit(mContentLauncherManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetAcceptHeaderMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);

env->ExceptionClear();

return aEncoder.EncodeList([this, env](const auto & encoder) -> CHIP_ERROR {
jobjectArray acceptedHeadersArray =
(jobjectArray) env->CallObjectMethod(mContentLauncherManagerObject.ObjectRef(), mGetAcceptHeaderMethod);
Expand Down Expand Up @@ -203,6 +211,7 @@ CHIP_ERROR ContentLauncherManager::HandleGetAcceptHeaderList(AttributeValueEncod

uint32_t ContentLauncherManager::HandleGetSupportedStreamingProtocols()
{
DeviceLayer::StackUnlock unlock;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
uint32_t supportedStreamingProtocols = 0;
Expand All @@ -213,6 +222,8 @@ uint32_t ContentLauncherManager::HandleGetSupportedStreamingProtocols()
VerifyOrExit(mContentLauncherManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetSupportedStreamingProtocolsMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);

env->ExceptionClear();

{
jlong jSupportedStreamingProtocols =
env->CallLongMethod(mContentLauncherManagerObject.ObjectRef(), mGetSupportedStreamingProtocolsMethod);
Expand Down
1 change: 1 addition & 0 deletions examples/tv-app/android/java/KeypadInputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void KeypadInputManager::NewManager(jint endpoint, jobject manager)

void KeypadInputManager::HandleSendKey(CommandResponseHelper<SendKeyResponseType> & helper, const CECKeyCodeEnum & keyCode)
{
DeviceLayer::StackUnlock unlock;
Commands::SendKeyResponse::Type response;

jint ret = -1;
Expand Down
1 change: 1 addition & 0 deletions examples/tv-app/android/java/LevelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ CHIP_ERROR LevelManager::InitializeWithObjects(jobject managerObject)

void LevelManager::HandleLevelChanged(uint8_t value)
{
DeviceLayer::StackUnlock unlock;
ChipLogProgress(Zcl, "LevelManager::HandleLevelChanged");

JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
Expand Down
1 change: 1 addition & 0 deletions examples/tv-app/android/java/LowPowerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void LowPowerManager::InitializeWithObjects(jobject managerObject)

bool LowPowerManager::HandleSleep()
{
DeviceLayer::StackUnlock unlock;
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
JniLocalReferenceScope scope(env);
Expand Down
14 changes: 12 additions & 2 deletions examples/tv-app/android/java/MediaInputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void MediaInputManager::NewManager(jint endpoint, jobject manager)

CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncoder & aEncoder)
{
DeviceLayer::StackUnlock unlock;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
Expand All @@ -60,6 +61,8 @@ CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncode
VerifyOrExit(mMediaInputManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetInputListMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);

env->ExceptionClear();

return aEncoder.EncodeList([this, env](const auto & encoder) -> CHIP_ERROR {
jobjectArray inputArray = (jobjectArray) env->CallObjectMethod(mMediaInputManagerObject.ObjectRef(), mGetInputListMethod);
if (env->ExceptionCheck())
Expand Down Expand Up @@ -121,6 +124,7 @@ CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncode

uint8_t MediaInputManager::HandleGetCurrentInput()
{
DeviceLayer::StackUnlock unlock;
CHIP_ERROR err = CHIP_NO_ERROR;
jint index = -1;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
Expand All @@ -130,7 +134,8 @@ uint8_t MediaInputManager::HandleGetCurrentInput()
ChipLogProgress(Zcl, "Received MediaInputManager::HandleGetCurrentInput");
VerifyOrExit(mMediaInputManagerObject.HasValidObjectRef(), err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetCurrentInputMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);

env->ExceptionClear();

{
index = env->CallIntMethod(mMediaInputManagerObject.ObjectRef(), mGetCurrentInputMethod);
Expand All @@ -154,6 +159,7 @@ uint8_t MediaInputManager::HandleGetCurrentInput()

bool MediaInputManager::HandleSelectInput(const uint8_t index)
{
DeviceLayer::StackUnlock unlock;
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
Expand All @@ -179,6 +185,7 @@ bool MediaInputManager::HandleSelectInput(const uint8_t index)

bool MediaInputManager::HandleShowInputStatus()
{
DeviceLayer::StackUnlock unlock;
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
Expand All @@ -204,6 +211,7 @@ bool MediaInputManager::HandleShowInputStatus()

bool MediaInputManager::HandleHideInputStatus()
{
DeviceLayer::StackUnlock unlock;
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
Expand All @@ -229,6 +237,7 @@ bool MediaInputManager::HandleHideInputStatus()

bool MediaInputManager::HandleRenameInput(const uint8_t index, const chip::CharSpan & name)
{
DeviceLayer::StackUnlock unlock;
std::string inputname(name.data(), name.size());
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
Expand All @@ -239,9 +248,10 @@ bool MediaInputManager::HandleRenameInput(const uint8_t index, const chip::CharS
VerifyOrExit(mMediaInputManagerObject.HasValidObjectRef(), ChipLogError(Zcl, "mMediaInputManagerObject is not valid"));
VerifyOrExit(mRenameInputMethod != nullptr, ChipLogError(Zcl, "mHideInputStatusMethod null"));

env->ExceptionClear();

{
UtfString jniInputname(env, inputname.data());
env->ExceptionClear();
ret = env->CallBooleanMethod(mMediaInputManagerObject.ObjectRef(), mRenameInputMethod, static_cast<jint>(index),
jniInputname.jniValue());
if (env->ExceptionCheck())
Expand Down
Loading
Loading