Skip to content

Commit 20c46c2

Browse files
chrisdecenzorestyled-io[bot]restyled-commits
authored
TV 31718 - update android sample app with TV2 cluster features (project-chip#31719)
* TV 31718 - android sample app * Restyle TV 31718 - update android sample app with TV2 cluster features (project-chip#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 (project-chip#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>
1 parent 3e8ef2a commit 20c46c2

25 files changed

+897
-101
lines changed

examples/tv-app/android/BUILD.gn

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ shared_library("jni") {
3333
"include/audio-output/AudioOutputManager.cpp",
3434
"include/audio-output/AudioOutputManager.h",
3535
"include/cluster-init.cpp",
36-
"include/content-app-observer/ContentAppObserver.cpp",
37-
"include/content-app-observer/ContentAppObserver.h",
3836
"include/content-control/ContentController.cpp",
3937
"include/content-control/ContentController.h",
4038
"include/content-launcher/AppContentLauncherManager.cpp",
@@ -118,6 +116,8 @@ android_library("java") {
118116
"java/src/com/matter/tv/server/tvapp/ChannelLineupInfo.java",
119117
"java/src/com/matter/tv/server/tvapp/ChannelManager.java",
120118
"java/src/com/matter/tv/server/tvapp/ChannelManagerStub.java",
119+
"java/src/com/matter/tv/server/tvapp/ChannelProgramInfo.java",
120+
"java/src/com/matter/tv/server/tvapp/ChannelProgramResponse.java",
121121
"java/src/com/matter/tv/server/tvapp/Clusters.java",
122122
"java/src/com/matter/tv/server/tvapp/ContentAppEndpointManager.java",
123123
"java/src/com/matter/tv/server/tvapp/ContentLaunchBrandingInformation.java",
@@ -142,6 +142,7 @@ android_library("java") {
142142
"java/src/com/matter/tv/server/tvapp/MediaPlaybackManager.java",
143143
"java/src/com/matter/tv/server/tvapp/MediaPlaybackManagerStub.java",
144144
"java/src/com/matter/tv/server/tvapp/MediaPlaybackPosition.java",
145+
"java/src/com/matter/tv/server/tvapp/MediaTrack.java",
145146
"java/src/com/matter/tv/server/tvapp/OnOffManager.java",
146147
"java/src/com/matter/tv/server/tvapp/OnOffManagerStub.java",
147148
"java/src/com/matter/tv/server/tvapp/TvApp.java",

examples/tv-app/android/java/AppImpl.h

-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "../include/account-login/AccountLoginManager.h"
3636
#include "../include/application-basic/ApplicationBasicManager.h"
3737
#include "../include/application-launcher/ApplicationLauncherManager.h"
38-
#include "../include/content-app-observer/ContentAppObserver.h"
3938
#include "../include/content-control/ContentController.h"
4039
#include "../include/content-launcher/AppContentLauncherManager.h"
4140
#include "../include/media-playback/AppMediaPlaybackManager.h"
@@ -49,7 +48,6 @@
4948
#include <app/clusters/application-basic-server/application-basic-delegate.h>
5049
#include <app/clusters/application-launcher-server/application-launcher-delegate.h>
5150
#include <app/clusters/channel-server/channel-delegate.h>
52-
#include <app/clusters/content-app-observer/content-app-observer-delegate.h>
5351
#include <app/clusters/content-control-server/content-control-delegate.h>
5452
#include <app/clusters/content-launch-server/content-launch-delegate.h>
5553
#include <app/clusters/keypad-input-server/keypad-input-delegate.h>
@@ -76,7 +74,6 @@ using ApplicationBasicDelegate = app::Clusters::ApplicationBasic::Delegate;
7674
using ApplicationLauncherDelegate = app::Clusters::ApplicationLauncher::Delegate;
7775
using ChannelDelegate = app::Clusters::Channel::Delegate;
7876
using ContentLauncherDelegate = app::Clusters::ContentLauncher::Delegate;
79-
using ContentAppObserverDelegate = app::Clusters::ContentAppObserver::Delegate;
8077
using ContentControlDelegate = app::Clusters::ContentControl::Delegate;
8178
using KeypadInputDelegate = app::Clusters::KeypadInput::Delegate;
8279
using MediaPlaybackDelegate = app::Clusters::MediaPlayback::Delegate;
@@ -118,11 +115,6 @@ class DLL_EXPORT ContentAppImpl : public ContentApp
118115
mContentLauncherDelegate.SetEndpointId(GetEndpointId());
119116
return &mContentLauncherDelegate;
120117
};
121-
ContentAppObserverDelegate * GetContentAppObserverDelegate() override
122-
{
123-
mContentAppObserverDelegate.SetEndpointId(GetEndpointId());
124-
return &mContentAppObserverDelegate;
125-
};
126118
ContentControlDelegate * GetContentControlDelegate() override
127119
{
128120
mContentControlDelegate.SetEndpointId(GetEndpointId());
@@ -146,7 +138,6 @@ class DLL_EXPORT ContentAppImpl : public ContentApp
146138
ApplicationLauncherManager mApplicationLauncherDelegate;
147139
ChannelManager mChannelDelegate;
148140
ContentController mContentControlDelegate;
149-
ContentAppObserver mContentAppObserverDelegate;
150141
AppContentLauncherManager mContentLauncherDelegate;
151142
KeypadInputManager mKeypadInputDelegate;
152143
AppMediaPlaybackManager mMediaPlaybackDelegate;

examples/tv-app/android/java/ChannelManager.cpp

+313-17
Large diffs are not rendered by default.

examples/tv-app/android/java/ChannelManager.h

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ using ChannelInfoType = chip::app::Clusters::Channel::Structs::Channel
3131
using AdditionalInfoType = chip::app::Clusters::Channel::Structs::AdditionalInfoStruct::Type;
3232
using LineupInfoType = chip::app::Clusters::Channel::Structs::LineupInfoStruct::Type;
3333
using PageTokenType = chip::app::Clusters::Channel::Structs::PageTokenStruct::Type;
34+
using ProgramType = chip::app::Clusters::Channel::Structs::ProgramStruct::Type;
35+
using ChannelPagingType = chip::app::Clusters::Channel::Structs::ChannelPagingStruct::Type;
3436

3537
class ChannelManager : public ChannelDelegate
3638
{
@@ -73,6 +75,10 @@ class ChannelManager : public ChannelDelegate
7375
jmethodID mChangeChannelByNumberMethod = nullptr;
7476
jmethodID mSkipChannelMethod = nullptr;
7577

78+
jmethodID mGetProgramGuideMethod = nullptr;
79+
jmethodID mRecordProgramMethod = nullptr;
80+
jmethodID mCancelRecordProgramMethod = nullptr;
81+
7682
// TODO: set this based upon meta data from app
7783
uint32_t mDynamicEndpointFeatureMap = 3;
7884
};

examples/tv-app/android/java/ContentLauncherManager.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ void ContentLauncherManager::HandleLaunchContent(CommandResponseHelper<LaunchRes
5454
Commands::LauncherResponse::Type response;
5555
CHIP_ERROR err = CHIP_NO_ERROR;
5656
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
57+
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
58+
JniLocalReferenceManager manager(env);
5759

5860
ChipLogProgress(Zcl, "Received ContentLauncherManager::LaunchContent");
5961
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
6062
VerifyOrExit(mLaunchContentMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
61-
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);
6263

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

112115
ChipLogProgress(Zcl, "Received ContentLauncherManager::LaunchContentUrl");
113116
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
114117
VerifyOrExit(mLaunchUrlMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
115-
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);
116118

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

165169
ChipLogProgress(Zcl, "Received ContentLauncherManager::GetAcceptHeader");
166170
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
167171
VerifyOrExit(mGetAcceptHeaderMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
168-
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);
169172

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

207212
ChipLogProgress(Zcl, "Received ContentLauncherManager::GetSupportedStreamingProtocols");
208213
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
209214
VerifyOrExit(mGetSupportedStreamingProtocolsMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
210-
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);
211215

212216
{
213217
jlong jSupportedStreamingProtocols =

examples/tv-app/android/java/KeypadInputManager.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <app/util/config.h>
2424
#include <lib/support/CHIPJNIError.h>
2525
#include <lib/support/JniReferences.h>
26+
#include <lib/support/JniTypeWrappers.h>
2627

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

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

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

7881
mKeypadInputManagerObject = env->NewGlobalRef(managerObject);
7982
VerifyOrReturn(mKeypadInputManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef KeypadInputManager"));

examples/tv-app/android/java/LevelManager.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ CHIP_ERROR LevelManager::InitializeWithObjects(jobject managerObject)
9292
{
9393
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
9494
VerifyOrReturnLogError(env != nullptr, CHIP_ERROR_INCORRECT_STATE);
95+
JniLocalReferenceManager manager(env);
9596

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

117118
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
118-
VerifyOrReturn(env != NULL, ChipLogProgress(Zcl, "env null"));
119+
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
120+
JniLocalReferenceManager manager(env);
121+
119122
VerifyOrReturn(mLevelManagerObject != nullptr, ChipLogProgress(Zcl, "mLevelManagerObject null"));
120123
VerifyOrReturn(mHandleLevelChangedMethod != nullptr, ChipLogProgress(Zcl, "mHandleLevelChangedMethod null"));
121124

examples/tv-app/android/java/LowPowerManager.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void LowPowerManager::InitializeWithObjects(jobject managerObject)
4646
{
4747
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
4848
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for LowPowerManager"));
49+
JniLocalReferenceManager manager(env);
4950

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

6971
ChipLogProgress(Zcl, "Received LowPowerManager::Sleep");
7072
VerifyOrExit(mLowPowerManagerObject != nullptr, ChipLogError(Zcl, "mLowPowerManagerObject null"));

examples/tv-app/android/java/MediaInputManager.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ CHIP_ERROR MediaInputManager::HandleGetInputList(chip::app::AttributeValueEncode
5353
{
5454
CHIP_ERROR err = CHIP_NO_ERROR;
5555
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
56+
VerifyOrReturnError(env != nullptr, CHIP_JNI_ERROR_NO_ENV, ChipLogError(Zcl, "Could not get JNIEnv for current thread"));
57+
JniLocalReferenceManager manager(env);
5658

5759
ChipLogProgress(Zcl, "Received MediaInputManager::HandleGetInputList");
5860
VerifyOrExit(mMediaInputManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
5961
VerifyOrExit(mGetInputListMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
60-
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);
6162

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

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

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

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

181187
ChipLogProgress(Zcl, "Received MediaInputManager::HandleShowInputStatus");
182188
VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null"));
183189
VerifyOrExit(mShowInputStatusMethod != nullptr, ChipLogError(Zcl, "mShowInputStatusMethod null"));
184-
VerifyOrExit(env != NULL, ChipLogError(Zcl, "env null"));
185190

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

205212
ChipLogProgress(Zcl, "Received MediaInputManager::HandleHideInputStatus");
206213
VerifyOrExit(mMediaInputManagerObject != nullptr, ChipLogError(Zcl, "mMediaInputManagerObject null"));
207214
VerifyOrExit(mHideInputStatusMethod != nullptr, ChipLogError(Zcl, "mHideInputStatusMethod null"));
208-
VerifyOrExit(env != NULL, ChipLogError(Zcl, "env null"));
209215

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

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

235242
{
236243
UtfString jniInputname(env, inputname.data());

0 commit comments

Comments
 (0)