Skip to content

Commit 5988375

Browse files
authored
Enable content launcher test for tv app (project-chip#12961)
* Enable test and connect the logic * Zap generate files * Enabled List of Strings in java template * Run zap regen tool * Added delegate methods for attributes, updated linux and android tv app * Updated code per comments * Run zap regen * Restyle fix
1 parent 00ec330 commit 5988375

File tree

55 files changed

+4351
-549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4351
-549
lines changed

examples/all-clusters-app/all-clusters-common/all-clusters-app.zap

+1-1
Original file line numberDiff line numberDiff line change
@@ -14460,7 +14460,7 @@
1446014460
],
1446114461
"attributes": [
1446214462
{
14463-
"name": "accepts header list",
14463+
"name": "accept header list",
1446414464
"code": 0,
1446514465
"mfgCode": null,
1446614466
"side": "server",

examples/all-clusters-app/linux/include/tv-callbacks.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
*******************************************************************************
2323
******************************************************************************/
2424

25+
#include <list>
26+
#include <string>
27+
2528
bool lowPowerClusterSleep()
2629
{
2730
return true;

examples/chip-tool/templates/tests.js

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ function getTests()
173173
'TV_MediaPlaybackCluster',
174174
'TV_TvChannelCluster',
175175
'TV_LowPowerCluster',
176+
'TV_ContentLauncherCluster',
176177
'TV_MediaInputCluster',
177178
];
178179

examples/thermostat/thermostat-common/thermostat.zap

+1-1
Original file line numberDiff line numberDiff line change
@@ -13120,7 +13120,7 @@
1312013120
],
1312113121
"attributes": [
1312213122
{
13123-
"name": "accepts header list",
13123+
"name": "accept header list",
1312413124
"code": 0,
1312513125
"mfgCode": null,
1312613126
"side": "server",

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

+127-202
Original file line numberDiff line numberDiff line change
@@ -45,206 +45,9 @@ using namespace chip;
4545

4646
ContentLauncherManager ContentLauncherManager::sInstance;
4747

48-
namespace {
49-
50-
class ContentLauncherAttrAccess : public app::AttributeAccessInterface
51-
{
52-
public:
53-
ContentLauncherAttrAccess() : app::AttributeAccessInterface(Optional<EndpointId>::Missing(), app::Clusters::ContentLauncher::Id)
54-
{}
55-
56-
CHIP_ERROR Read(const app::ConcreteReadAttributePath & aPath, app::AttributeValueEncoder & aEncoder) override
57-
{
58-
if (aPath.mAttributeId == app::Clusters::ContentLauncher::Attributes::AcceptsHeaderList::Id)
59-
{
60-
return ContentLauncherMgr().GetAcceptsHeader(aEncoder);
61-
}
62-
else if (aPath.mAttributeId == app::Clusters::ContentLauncher::Attributes::SupportedStreamingProtocols::Id)
63-
{
64-
return ContentLauncherMgr().GetSupportedStreamingTypes(aEncoder);
65-
}
66-
67-
return CHIP_NO_ERROR;
68-
}
69-
};
70-
71-
ContentLauncherAttrAccess gContentLauncherAttrAccess;
72-
73-
} // anonymous namespace
74-
75-
/** @brief Content Launch Cluster Init
76-
*
77-
* This function is called when a specific cluster is initialized. It gives the
78-
* application an opportunity to take care of cluster initialization procedures.
79-
* It is called exactly once for each endpoint where cluster is present.
80-
*
81-
* @param endpoint Ver.: always
82-
*
83-
*/
84-
void emberAfContentLauncherClusterInitCallback(EndpointId endpoint)
85-
{
86-
static bool attrAccessRegistered = false;
87-
if (!attrAccessRegistered)
88-
{
89-
registerAttributeAccessOverride(&gContentLauncherAttrAccess);
90-
attrAccessRegistered = true;
91-
}
92-
}
93-
94-
ContentLaunchResponse contentLauncherClusterLaunchContent(chip::EndpointId endpointId,
95-
std::list<ContentLaunchParamater> parameterList, bool autoplay,
96-
const chip::CharSpan & data)
97-
{
98-
return ContentLauncherMgr().LaunchContent(endpointId, parameterList, autoplay, data);
99-
}
100-
101-
ContentLaunchResponse contentLauncherClusterLaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString,
102-
ContentLaunchBrandingInformation & brandingInformation)
103-
{
104-
return ContentLauncherMgr().LaunchUrl(contentUrl, displayString, brandingInformation);
105-
}
106-
107-
void ContentLauncherManager::InitializeWithObjects(jobject managerObject)
108-
{
109-
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
110-
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for ContentLauncherManager"));
111-
112-
mContentLauncherManagerObject = env->NewGlobalRef(managerObject);
113-
VerifyOrReturn(mContentLauncherManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef ContentLauncherManager"));
114-
115-
jclass ContentLauncherClass = env->GetObjectClass(managerObject);
116-
VerifyOrReturn(ContentLauncherClass != nullptr, ChipLogError(Zcl, "Failed to get ContentLauncherManager Java class"));
117-
118-
mGetAcceptsHeaderMethod = env->GetMethodID(ContentLauncherClass, "getAcceptsHeader", "()[Ljava/lang/String;");
119-
if (mGetAcceptsHeaderMethod == nullptr)
120-
{
121-
ChipLogError(Zcl, "Failed to access MediaInputManager 'getInputList' method");
122-
env->ExceptionClear();
123-
}
124-
125-
mGetSupportedStreamingTypesMethod = env->GetMethodID(ContentLauncherClass, "getSupportedStreamingTypes", "()[I");
126-
if (mGetSupportedStreamingTypesMethod == nullptr)
127-
{
128-
ChipLogError(Zcl, "Failed to access MediaInputManager 'getSupportedStreamingTypes' method");
129-
env->ExceptionClear();
130-
}
131-
132-
mLaunchContentMethod = env->GetMethodID(
133-
ContentLauncherClass, "launchContent",
134-
"([Lcom/tcl/chip/tvapp/ContentLaunchSearchParameter;ZLjava/lang/String;)Lcom/tcl/chip/tvapp/ContentLaunchResponse;");
135-
if (mLaunchContentMethod == nullptr)
136-
{
137-
ChipLogError(Zcl, "Failed to access MediaInputManager 'launchContent' method");
138-
env->ExceptionClear();
139-
}
140-
141-
mLaunchUrlMethod = env->GetMethodID(ContentLauncherClass, "launchUrl",
142-
"(Ljava/lang/String;Ljava/lang/String;Lcom/tcl/chip/tvapp/"
143-
"ContentLaunchBrandingInformation;)Lcom/tcl/chip/tvapp/ContentLaunchResponse;");
144-
if (mLaunchUrlMethod == nullptr)
145-
{
146-
ChipLogError(AppServer, "Failed to access 'launchUrl' method");
147-
env->ExceptionClear();
148-
}
149-
}
150-
151-
CHIP_ERROR ContentLauncherManager::GetAcceptsHeader(chip::app::AttributeValueEncoder & aEncoder)
152-
{
153-
CHIP_ERROR err = CHIP_NO_ERROR;
154-
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
155-
156-
ChipLogProgress(Zcl, "Received ContentLauncherManager::GetAcceptsHeader");
157-
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
158-
VerifyOrExit(mGetAcceptsHeaderMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
159-
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);
160-
161-
return aEncoder.EncodeList([this, env](const auto & encoder) -> CHIP_ERROR {
162-
jobjectArray headersArray = (jobjectArray) env->CallObjectMethod(mContentLauncherManagerObject, mGetAcceptsHeaderMethod);
163-
if (env->ExceptionCheck())
164-
{
165-
ChipLogError(Zcl, "Java exception in ContentLauncherManager::GetAcceptsHeader");
166-
env->ExceptionDescribe();
167-
env->ExceptionClear();
168-
return CHIP_ERROR_INCORRECT_STATE;
169-
}
170-
171-
jint size = env->GetArrayLength(headersArray);
172-
for (int i = 0; i < size; i++)
173-
{
174-
jstring acceptsheader = (jstring) env->GetObjectArrayElement(headersArray, i);
175-
if (acceptsheader != nullptr)
176-
{
177-
JniUtfString header(env, acceptsheader);
178-
179-
chip::ByteSpan bHeader((const uint8_t *) (header.c_str()), (size_t)(header.size()));
180-
ReturnErrorOnFailure(encoder.Encode(bHeader));
181-
182-
// Todo: should be chanSpan?
183-
// ReturnErrorOnFailure(encoder.Encode(header.charSpan()));
184-
}
185-
}
186-
187-
return CHIP_NO_ERROR;
188-
});
189-
190-
exit:
191-
if (err != CHIP_NO_ERROR)
192-
{
193-
ChipLogError(Zcl, "ContentLauncherManager::GetAcceptsHeader status error: %s", err.AsString());
194-
}
195-
196-
return err;
197-
}
198-
199-
CHIP_ERROR ContentLauncherManager::GetSupportedStreamingTypes(chip::app::AttributeValueEncoder & aEncoder)
200-
{
201-
CHIP_ERROR err = CHIP_NO_ERROR;
202-
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
203-
204-
ChipLogProgress(Zcl, "Received ContentLauncherManager::GetSupportedStreamingTypes");
205-
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
206-
VerifyOrExit(mGetSupportedStreamingTypesMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
207-
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);
208-
209-
return aEncoder.EncodeList([this, env](const auto & encoder) -> CHIP_ERROR {
210-
jintArray typesArray = (jintArray) env->CallObjectMethod(mContentLauncherManagerObject, mGetSupportedStreamingTypesMethod);
211-
if (env->ExceptionCheck())
212-
{
213-
ChipLogError(Zcl, "Java exception in ContentLauncherManager::GetSupportedStreamingTypes");
214-
env->ExceptionDescribe();
215-
env->ExceptionClear();
216-
return CHIP_ERROR_INCORRECT_STATE;
217-
}
218-
219-
jboolean isCopy = JNI_FALSE;
220-
jint * ptypes = env->GetIntArrayElements(typesArray, &isCopy);
221-
jint size = env->GetArrayLength(typesArray);
222-
223-
CHIP_ERROR err = CHIP_NO_ERROR;
224-
for (int i = 0; i < size; i++)
225-
{
226-
err = encoder.Encode(static_cast<uint8_t>(ptypes[i]));
227-
if (err != CHIP_NO_ERROR)
228-
{
229-
break;
230-
}
231-
}
232-
env->ReleaseIntArrayElements(typesArray, ptypes, 0);
233-
return err;
234-
});
235-
236-
exit:
237-
if (err != CHIP_NO_ERROR)
238-
{
239-
ChipLogError(Zcl, "ContentLauncherManager::GetAcceptsHeader status error: %s", err.AsString());
240-
}
241-
242-
return err;
243-
}
244-
245-
ContentLaunchResponse ContentLauncherManager::LaunchContent(chip::EndpointId endpointId,
246-
std::list<ContentLaunchParamater> parameterList, bool autoplay,
247-
const chip::CharSpan & data)
48+
ContentLaunchResponse ContentLauncherManager::HandleLaunchContent(chip::EndpointId endpointId,
49+
const std::list<ContentLaunchParamater> & parameterList,
50+
bool autoplay, const chip::CharSpan & data)
24851
{
24952
ContentLaunchResponse response;
25053
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -297,8 +100,9 @@ ContentLaunchResponse ContentLauncherManager::LaunchContent(chip::EndpointId end
297100
return response;
298101
}
299102

300-
ContentLaunchResponse ContentLauncherManager::LaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString,
301-
ContentLaunchBrandingInformation & brandingInformation)
103+
ContentLaunchResponse
104+
ContentLauncherManager::HandleLaunchUrl(const chip::CharSpan & contentUrl, const chip::CharSpan & displayString,
105+
const std::list<ContentLaunchBrandingInformation> & brandingInformation)
302106
{
303107
ContentLaunchResponse response;
304108
CHIP_ERROR err = CHIP_NO_ERROR;
@@ -351,3 +155,124 @@ ContentLaunchResponse ContentLauncherManager::LaunchUrl(const chip::CharSpan & c
351155

352156
return response;
353157
}
158+
159+
std::list<std::string> ContentLauncherManager::HandleGetAcceptHeaderList()
160+
{
161+
CHIP_ERROR err = CHIP_NO_ERROR;
162+
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
163+
std::list<std::string> acceptedHeadersList;
164+
165+
ChipLogProgress(Zcl, "Received ContentLauncherManager::GetAcceptHeader");
166+
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
167+
VerifyOrExit(mGetAcceptHeaderMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
168+
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);
169+
170+
{
171+
jobjectArray acceptedHeadersArray =
172+
(jobjectArray) env->CallObjectMethod(mContentLauncherManagerObject, mGetAcceptHeaderMethod);
173+
if (env->ExceptionCheck())
174+
{
175+
ChipLogError(Zcl, "Java exception in ContentLauncherManager::GetAcceptHeader");
176+
env->ExceptionDescribe();
177+
env->ExceptionClear();
178+
err = CHIP_ERROR_INCORRECT_STATE;
179+
goto exit;
180+
}
181+
182+
jint size = env->GetArrayLength(acceptedHeadersArray);
183+
for (int i = 0; i < size; i++)
184+
{
185+
186+
jstring jAcceptedHeader = (jstring) env->GetObjectArrayElement(acceptedHeadersArray, i);
187+
const char * convertedValue = (env)->GetStringUTFChars(jAcceptedHeader, JNI_FALSE);
188+
std::string acceptedHeader = std::string(convertedValue, strlen(convertedValue));
189+
acceptedHeadersList.push_front(acceptedHeader);
190+
}
191+
}
192+
193+
exit:
194+
if (err != CHIP_NO_ERROR)
195+
{
196+
ChipLogError(Zcl, "ContentLauncherManager::GetAcceptHeader status error: %s", err.AsString());
197+
}
198+
199+
return acceptedHeadersList;
200+
}
201+
202+
uint32_t ContentLauncherManager::HandleGetSupportedStreamingProtocols()
203+
{
204+
CHIP_ERROR err = CHIP_NO_ERROR;
205+
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
206+
uint32_t supportedStreamingProtocols = 0;
207+
208+
ChipLogProgress(Zcl, "Received ContentLauncherManager::GetSupportedStreamingProtocols");
209+
VerifyOrExit(mContentLauncherManagerObject != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
210+
VerifyOrExit(mGetSupportedStreamingProtocolsMethod != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
211+
VerifyOrExit(env != NULL, err = CHIP_JNI_ERROR_NO_ENV);
212+
213+
{
214+
jint jSupportedStreamingProtocols =
215+
env->CallIntMethod(mContentLauncherManagerObject, mGetSupportedStreamingProtocolsMethod);
216+
supportedStreamingProtocols = (uint32_t) jSupportedStreamingProtocols;
217+
if (env->ExceptionCheck())
218+
{
219+
ChipLogError(Zcl, "Java exception in ContentLauncherManager::GetAcceptHeader");
220+
env->ExceptionDescribe();
221+
env->ExceptionClear();
222+
err = CHIP_ERROR_INCORRECT_STATE;
223+
goto exit;
224+
}
225+
}
226+
227+
exit:
228+
if (err != CHIP_NO_ERROR)
229+
{
230+
ChipLogError(Zcl, "ContentLauncherManager::GetSupportedStreamingProtocols status error: %s", err.AsString());
231+
}
232+
233+
return supportedStreamingProtocols;
234+
}
235+
236+
void ContentLauncherManager::InitializeWithObjects(jobject managerObject)
237+
{
238+
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();
239+
VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Failed to GetEnvForCurrentThread for ContentLauncherManager"));
240+
241+
mContentLauncherManagerObject = env->NewGlobalRef(managerObject);
242+
VerifyOrReturn(mContentLauncherManagerObject != nullptr, ChipLogError(Zcl, "Failed to NewGlobalRef ContentLauncherManager"));
243+
244+
jclass ContentLauncherClass = env->GetObjectClass(managerObject);
245+
VerifyOrReturn(ContentLauncherClass != nullptr, ChipLogError(Zcl, "Failed to get ContentLauncherManager Java class"));
246+
247+
mGetAcceptHeaderMethod = env->GetMethodID(ContentLauncherClass, "getAcceptHeader", "()[Ljava/lang/String;");
248+
if (mGetAcceptHeaderMethod == nullptr)
249+
{
250+
ChipLogError(Zcl, "Failed to access MediaInputManager 'getInputList' method");
251+
env->ExceptionClear();
252+
}
253+
254+
mGetSupportedStreamingProtocolsMethod = env->GetMethodID(ContentLauncherClass, "getSupportedStreamingProtocols", "()[I");
255+
if (mGetSupportedStreamingProtocolsMethod == nullptr)
256+
{
257+
ChipLogError(Zcl, "Failed to access MediaInputManager 'getSupportedStreamingProtocols' method");
258+
env->ExceptionClear();
259+
}
260+
261+
mLaunchContentMethod = env->GetMethodID(
262+
ContentLauncherClass, "launchContent",
263+
"([Lcom/tcl/chip/tvapp/ContentLaunchSearchParameter;ZLjava/lang/String;)Lcom/tcl/chip/tvapp/ContentLaunchResponse;");
264+
if (mLaunchContentMethod == nullptr)
265+
{
266+
ChipLogError(Zcl, "Failed to access MediaInputManager 'launchContent' method");
267+
env->ExceptionClear();
268+
}
269+
270+
mLaunchUrlMethod = env->GetMethodID(ContentLauncherClass, "launchUrl",
271+
"(Ljava/lang/String;Ljava/lang/String;Lcom/tcl/chip/tvapp/"
272+
"ContentLaunchBrandingInformation;)Lcom/tcl/chip/tvapp/ContentLaunchResponse;");
273+
if (mLaunchUrlMethod == nullptr)
274+
{
275+
ChipLogError(AppServer, "Failed to access 'launchUrl' method");
276+
env->ExceptionClear();
277+
}
278+
}

0 commit comments

Comments
 (0)