Skip to content

Commit

Permalink
TV 31718 - update android sample app with TV2 cluster features (#31719)
Browse files Browse the repository at this point in the history
* TV 31718 - android sample app

* Restyle TV 31718 - update android sample app with TV2 cluster features (#31720)

* Restyled by whitespace

* Restyled by google-java-format

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <commits@restyled.io>

* Restyled by google-java-format (#31722)

Co-authored-by: Restyled.io <commits@restyled.io>

* Address comments

---------

Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
3 people authored Jan 30, 2024
1 parent 3e8ef2a commit 20c46c2
Show file tree
Hide file tree
Showing 25 changed files with 897 additions and 101 deletions.
5 changes: 3 additions & 2 deletions examples/tv-app/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ shared_library("jni") {
"include/audio-output/AudioOutputManager.cpp",
"include/audio-output/AudioOutputManager.h",
"include/cluster-init.cpp",
"include/content-app-observer/ContentAppObserver.cpp",
"include/content-app-observer/ContentAppObserver.h",
"include/content-control/ContentController.cpp",
"include/content-control/ContentController.h",
"include/content-launcher/AppContentLauncherManager.cpp",
Expand Down Expand Up @@ -118,6 +116,8 @@ android_library("java") {
"java/src/com/matter/tv/server/tvapp/ChannelLineupInfo.java",
"java/src/com/matter/tv/server/tvapp/ChannelManager.java",
"java/src/com/matter/tv/server/tvapp/ChannelManagerStub.java",
"java/src/com/matter/tv/server/tvapp/ChannelProgramInfo.java",
"java/src/com/matter/tv/server/tvapp/ChannelProgramResponse.java",
"java/src/com/matter/tv/server/tvapp/Clusters.java",
"java/src/com/matter/tv/server/tvapp/ContentAppEndpointManager.java",
"java/src/com/matter/tv/server/tvapp/ContentLaunchBrandingInformation.java",
Expand All @@ -142,6 +142,7 @@ android_library("java") {
"java/src/com/matter/tv/server/tvapp/MediaPlaybackManager.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/OnOffManager.java",
"java/src/com/matter/tv/server/tvapp/OnOffManagerStub.java",
"java/src/com/matter/tv/server/tvapp/TvApp.java",
Expand Down
9 changes: 0 additions & 9 deletions examples/tv-app/android/java/AppImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "../include/account-login/AccountLoginManager.h"
#include "../include/application-basic/ApplicationBasicManager.h"
#include "../include/application-launcher/ApplicationLauncherManager.h"
#include "../include/content-app-observer/ContentAppObserver.h"
#include "../include/content-control/ContentController.h"
#include "../include/content-launcher/AppContentLauncherManager.h"
#include "../include/media-playback/AppMediaPlaybackManager.h"
Expand All @@ -49,7 +48,6 @@
#include <app/clusters/application-basic-server/application-basic-delegate.h>
#include <app/clusters/application-launcher-server/application-launcher-delegate.h>
#include <app/clusters/channel-server/channel-delegate.h>
#include <app/clusters/content-app-observer/content-app-observer-delegate.h>
#include <app/clusters/content-control-server/content-control-delegate.h>
#include <app/clusters/content-launch-server/content-launch-delegate.h>
#include <app/clusters/keypad-input-server/keypad-input-delegate.h>
Expand All @@ -76,7 +74,6 @@ using ApplicationBasicDelegate = app::Clusters::ApplicationBasic::Delegate;
using ApplicationLauncherDelegate = app::Clusters::ApplicationLauncher::Delegate;
using ChannelDelegate = app::Clusters::Channel::Delegate;
using ContentLauncherDelegate = app::Clusters::ContentLauncher::Delegate;
using ContentAppObserverDelegate = app::Clusters::ContentAppObserver::Delegate;
using ContentControlDelegate = app::Clusters::ContentControl::Delegate;
using KeypadInputDelegate = app::Clusters::KeypadInput::Delegate;
using MediaPlaybackDelegate = app::Clusters::MediaPlayback::Delegate;
Expand Down Expand Up @@ -118,11 +115,6 @@ class DLL_EXPORT ContentAppImpl : public ContentApp
mContentLauncherDelegate.SetEndpointId(GetEndpointId());
return &mContentLauncherDelegate;
};
ContentAppObserverDelegate * GetContentAppObserverDelegate() override
{
mContentAppObserverDelegate.SetEndpointId(GetEndpointId());
return &mContentAppObserverDelegate;
};
ContentControlDelegate * GetContentControlDelegate() override
{
mContentControlDelegate.SetEndpointId(GetEndpointId());
Expand All @@ -146,7 +138,6 @@ class DLL_EXPORT ContentAppImpl : public ContentApp
ApplicationLauncherManager mApplicationLauncherDelegate;
ChannelManager mChannelDelegate;
ContentController mContentControlDelegate;
ContentAppObserver mContentAppObserverDelegate;
AppContentLauncherManager mContentLauncherDelegate;
KeypadInputManager mKeypadInputDelegate;
AppMediaPlaybackManager mMediaPlaybackDelegate;
Expand Down
330 changes: 313 additions & 17 deletions examples/tv-app/android/java/ChannelManager.cpp

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions examples/tv-app/android/java/ChannelManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ using ChannelInfoType = chip::app::Clusters::Channel::Structs::Channel
using AdditionalInfoType = chip::app::Clusters::Channel::Structs::AdditionalInfoStruct::Type;
using LineupInfoType = chip::app::Clusters::Channel::Structs::LineupInfoStruct::Type;
using PageTokenType = chip::app::Clusters::Channel::Structs::PageTokenStruct::Type;
using ProgramType = chip::app::Clusters::Channel::Structs::ProgramStruct::Type;
using ChannelPagingType = chip::app::Clusters::Channel::Structs::ChannelPagingStruct::Type;

class ChannelManager : public ChannelDelegate
{
Expand Down Expand Up @@ -73,6 +75,10 @@ class ChannelManager : public ChannelDelegate
jmethodID mChangeChannelByNumberMethod = nullptr;
jmethodID mSkipChannelMethod = nullptr;

jmethodID mGetProgramGuideMethod = nullptr;
jmethodID mRecordProgramMethod = nullptr;
jmethodID mCancelRecordProgramMethod = nullptr;

// TODO: set this based upon meta data from app
uint32_t mDynamicEndpointFeatureMap = 3;
};
12 changes: 8 additions & 4 deletions examples/tv-app/android/java/ContentLauncherManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ void ContentLauncherManager::HandleLaunchContent(CommandResponseHelper<LaunchRes
Commands::LauncherResponse::Type response;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
JniLocalReferenceManager manager(env);

ChipLogProgress(Zcl, "Received ContentLauncherManager::LaunchContent");
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mLaunchContentMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);

{
UtfString jData(env, data);
Expand Down Expand Up @@ -108,11 +109,12 @@ void ContentLauncherManager::HandleLaunchUrl(CommandResponseHelper<LaunchRespons
Commands::LauncherResponse::Type response;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
JniLocalReferenceManager manager(env);

ChipLogProgress(Zcl, "Received ContentLauncherManager::LaunchContentUrl");
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mLaunchUrlMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);

{
UtfString jContentUrl(env, contentUrl);
Expand Down Expand Up @@ -161,11 +163,12 @@ CHIP_ERROR ContentLauncherManager::HandleGetAcceptHeaderList(AttributeValueEncod
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
std::list<std::string> acceptedHeadersList;
VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
JniLocalReferenceManager manager(env);

ChipLogProgress(Zcl, "Received ContentLauncherManager::GetAcceptHeader");
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetAcceptHeaderMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);

return aEncoder.EncodeList([this, env](const auto & encoder) -> CHIP_ERROR {
jobjectArray acceptedHeadersArray =
Expand Down Expand Up @@ -203,11 +206,12 @@ uint32_t ContentLauncherManager::HandleGetSupportedStreamingProtocols()
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
uint32_t supportedStreamingProtocols = 0;
VerifyOrReturnValue(env != nullptr, 0, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
JniLocalReferenceManager manager(env);

ChipLogProgress(Zcl, "Received ContentLauncherManager::GetSupportedStreamingProtocols");
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetSupportedStreamingProtocolsMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);

{
jlong jSupportedStreamingProtocols =
Expand Down
5 changes: 4 additions & 1 deletion examples/tv-app/android/java/KeypadInputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <app/util/config.h>
#include <lib/support/CHIPJNIError.h>
#include <lib/support/JniReferences.h>
#include <lib/support/JniTypeWrappers.h>

using namespace chip;
using namespace chip::app::Clusters::KeypadInput;
Expand All @@ -48,11 +49,12 @@ void KeypadInputManager::HandleSendKey(CommandResponseHelper<SendKeyResponseType
jint ret = -1;
CHIP_ERROR err = CHIP_NO_ERROR;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
JniLocalReferenceManager manager(env);

ChipLogProgress(Zcl, "Received keypadInputClusterSendKey: %c", to_underlying(keyCode));
VerifyOrExit(mKeypadInputManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mSendKeyMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);

env->ExceptionClear();
ret = env->CallIntMethod(mKeypadInputManagerObject, mSendKeyMethod, static_cast<jint>(keyCode));
Expand All @@ -74,6 +76,7 @@ void KeypadInputManager::InitializeWithObjects(jobject managerObject)
{
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for KeypadInputManager"));
JniLocalReferenceManager manager(env);

mKeypadInputManagerObject = env->NewGlobalRef(managerObject);
VerifyOrReturn(mKeypadInputManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef KeypadInputManager"));
Expand Down
5 changes: 4 additions & 1 deletion examples/tv-app/android/java/LevelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ CHIP_ERROR LevelManager::InitializeWithObjects(jobject managerObject)
{
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnLogError(env != nullptr, CHIP_ERROR_INCORRECT_STATE);
JniLocalReferenceManager manager(env);

mLevelManagerObject = env->NewGlobalRef(managerObject);
VerifyOrReturnLogError(mLevelManagerObject != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
Expand All @@ -115,7 +116,9 @@ void LevelManager::HandleLevelChanged(uint8_t value)
ChipLogProgress(Zcl, "LevelManager::HandleLevelChanged");

JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturn(env != NULL, ChipLogProgress(Zcl, "env null"));
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
JniLocalReferenceManager manager(env);

VerifyOrReturn(mLevelManagerObject != nullptr, ChipLogProgress(Zcl, "mLevelManagerObject null"));
VerifyOrReturn(mHandleLevelChangedMethod != nullptr, ChipLogProgress(Zcl, "mHandleLevelChangedMethod null"));

Expand Down
2 changes: 2 additions & 0 deletions examples/tv-app/android/java/LowPowerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void LowPowerManager::InitializeWithObjects(jobject managerObject)
{
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for LowPowerManager"));
JniLocalReferenceManager manager(env);

mLowPowerManagerObject = env->NewGlobalRef(managerObject);
VerifyOrReturn(mLowPowerManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef LowPowerManager"));
Expand All @@ -65,6 +66,7 @@ bool LowPowerManager::HandleSleep()
{
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
JniLocalReferenceManager manager(env);

ChipLogProgress(Zcl, "Received LowPowerManager::Sleep");
VerifyOrExit(mLowPowerManagerObject != nullptr, ChipLogError(Zcl, "mLowPowerManagerObject null"));
Expand Down
17 changes: 12 additions & 5 deletions examples/tv-app/android/java/MediaInputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncode
{
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"));
JniLocalReferenceManager manager(env);

ChipLogProgress(Zcl, "Received MediaInputManager::HandleGetInputList");
VerifyOrExit(mMediaInputManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(mGetInputListMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);

return aEncoder.EncodeList([this, env](const auto & encoder) -> CHIP_ERROR {
jobjectArray inputArray = (jobjectArray) env->CallObjectMethod(mMediaInputManagerObject, mGetInputListMethod);
Expand Down Expand Up @@ -123,6 +124,8 @@ uint8_t MediaInputManager::HandleGetCurrentInput()
CHIP_ERROR err = CHIP_NO_ERROR;
jint index = -1;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnValue(env != nullptr, 0, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
JniLocalReferenceManager manager(env);

ChipLogProgress(Zcl, "Received MediaInputManager::HandleGetCurrentInput");
VerifyOrExit(mMediaInputManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
Expand Down Expand Up @@ -153,11 +156,12 @@ bool MediaInputManager::HandleSelectInput(const uint8_t index)
{
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
JniLocalReferenceManager manager(env);

ChipLogProgress(Zcl, "Received MediaInputManager::HandleSelectInput %d", index);
VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null"));
VerifyOrExit(mSelectInputMethod != nullptr, ChipLogError(Zcl, "mSelectInputMethod null"));
VerifyOrExit(env != NULL, ChipLogError(Zcl, "env null"));

env->ExceptionClear();
ret = env->CallBooleanMethod(mMediaInputManagerObject, mSelectInputMethod, static_cast<jint>(index));
Expand All @@ -177,11 +181,12 @@ bool MediaInputManager::HandleShowInputStatus()
{
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
JniLocalReferenceManager manager(env);

ChipLogProgress(Zcl, "Received MediaInputManager::HandleShowInputStatus");
VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null"));
VerifyOrExit(mShowInputStatusMethod != nullptr, ChipLogError(Zcl, "mShowInputStatusMethod null"));
VerifyOrExit(env != NULL, ChipLogError(Zcl, "env null"));

env->ExceptionClear();
ret = env->CallBooleanMethod(mMediaInputManagerObject, mShowInputStatusMethod);
Expand All @@ -201,11 +206,12 @@ bool MediaInputManager::HandleHideInputStatus()
{
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
JniLocalReferenceManager manager(env);

ChipLogProgress(Zcl, "Received MediaInputManager::HandleHideInputStatus");
VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null"));
VerifyOrExit(mHideInputStatusMethod != nullptr, ChipLogError(Zcl, "mHideInputStatusMethod null"));
VerifyOrExit(env != NULL, ChipLogError(Zcl, "env null"));

env->ExceptionClear();
ret = env->CallBooleanMethod(mMediaInputManagerObject, mHideInputStatusMethod);
Expand All @@ -226,11 +232,12 @@ bool MediaInputManager::HandleRenameInput(const uint8_t index, const chip::CharS
std::string inputname(name.data(), name.size());
jboolean ret = JNI_FALSE;
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
VerifyOrReturnValue(env != nullptr, false, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
JniLocalReferenceManager manager(env);

ChipLogProgress(Zcl, "Received MediaInputManager::HandleRenameInput %d to %s", index, name.data());
VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null"));
VerifyOrExit(mRenameInputMethod != nullptr, ChipLogError(Zcl, "mHideInputStatusMethod null"));
VerifyOrExit(env != NULL, ChipLogError(Zcl, "env null"));

{
UtfString jniInputname(env, inputname.data());
Expand Down
Loading

0 comments on commit 20c46c2

Please sign in to comment.