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

Add SupportedCluster list to ContentAppPlatform #33827

Merged
merged 15 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -19,6 +19,9 @@
"features": [
"AS"
]
},
{
"identifier": 1294
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
import android.content.IntentFilter;
import android.util.Log;
import androidx.annotation.NonNull;
import com.matter.tv.app.api.SupportedCluster;
import com.matter.tv.server.handlers.ContentAppEndpointManagerImpl;
import com.matter.tv.server.model.ContentApp;
import com.matter.tv.server.receivers.ContentAppDiscoveryService;
import com.matter.tv.server.tvapp.AppPlatform;
import com.matter.tv.server.tvapp.ContentAppSupportedCluster;
import com.matter.tv.server.utils.EndpointsDataStore;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
* This class facilitates the communication with the ContentAppPlatform. It uses the JNI interface
Expand Down Expand Up @@ -168,6 +172,7 @@ public void addContentApp(ContentApp app) {
app.getAppName(),
app.getProductId(),
app.getVersion(),
mapSupportedClusters(app.getSupportedClusters()),
desiredEndpointId,
new ContentAppEndpointManagerImpl(context));
} else {
Expand All @@ -178,6 +183,7 @@ public void addContentApp(ContentApp app) {
app.getAppName(),
app.getProductId(),
app.getVersion(),
mapSupportedClusters(app.getSupportedClusters()),
new ContentAppEndpointManagerImpl(context));
}
if (retEndpointId > 0) {
Expand All @@ -187,4 +193,20 @@ public void addContentApp(ContentApp app) {
Log.e(TAG, "Could not add content app as endpoint. App Name " + app.getAppName());
}
}

private Collection<ContentAppSupportedCluster> mapSupportedClusters(
Collection<SupportedCluster> supportedClusters) {
return supportedClusters
.stream()
.map(AppPlatformService::mapSupportedCluster)
.collect(Collectors.toList());
}

private static ContentAppSupportedCluster mapSupportedCluster(SupportedCluster cluster) {
return new ContentAppSupportedCluster(
cluster.clusterIdentifier,
cluster.features,
cluster.optionalCommandIdentifiers,
cluster.optionalAttributesIdentifiers);
}
}
1 change: 1 addition & 0 deletions examples/tv-app/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ android_library("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/ContentAppSupportedCluster.java",
"java/src/com/matter/tv/server/tvapp/ContentLaunchBrandingInformation.java",
"java/src/com/matter/tv/server/tvapp/ContentLaunchEntry.java",
"java/src/com/matter/tv/server/tvapp/ContentLaunchManager.java",
Expand Down
42 changes: 32 additions & 10 deletions examples/tv-app/android/java/AppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,26 @@ DataVersion gDataVersions[APP_LIBRARY_SIZE][ArraySize(contentAppClusters)];

EmberAfDeviceType gContentAppDeviceType[] = { { DEVICE_TYPE_CONTENT_APP, 1 } };

std::vector<SupportedCluster> make_default_supported_clusters()
{
return std::vector<ContentApp::SupportedCluster>{ { Descriptor::Id }, { ApplicationBasic::Id },
{ KeypadInput::Id }, { ApplicationLauncher::Id },
{ AccountLogin::Id }, { ContentLauncher::Id },
{ TargetNavigator::Id }, { Channel::Id } };
}

} // anonymous namespace

ContentAppFactoryImpl::ContentAppFactoryImpl() {}
ContentAppFactoryImpl::ContentAppFactoryImpl() :
mContentApps{ new ContentAppImpl("Vendor1", 1, "exampleid", 11, "Version1", "20202021", make_default_supported_clusters(),
nullptr, nullptr),
new ContentAppImpl("Vendor2", 65521, "exampleString", 32768, "Version2", "20202021",
make_default_supported_clusters(), nullptr, nullptr),
new ContentAppImpl("Vendor3", 9050, "App3", 22, "Version3", "20202021", make_default_supported_clusters(),
nullptr, nullptr),
new ContentAppImpl("TestSuiteVendor", 1111, "applicationId", 22, "v2", "20202021",
make_default_supported_clusters(), nullptr, nullptr) }
{}

uint16_t ContentAppFactoryImpl::GetPlatformCatalogVendorId()
{
Expand Down Expand Up @@ -339,11 +356,12 @@ ContentApp * ContentAppFactoryImpl::LoadContentApp(const CatalogVendorApp & vend
}

EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName,
uint16_t productId, const char * szApplicationVersion, jobject manager)
uint16_t productId, const char * szApplicationVersion,
std::vector<SupportedCluster> supportedClusters, jobject manager)
{
DataVersion * dataVersionBuf = new DataVersion[ArraySize(contentAppClusters)];
ContentAppImpl * app = new ContentAppImpl(szVendorName, vendorId, szApplicationName, productId, szApplicationVersion, "",
mAttributeDelegate, mCommandDelegate);
std::move(supportedClusters), mAttributeDelegate, mCommandDelegate);
EndpointId epId = ContentAppPlatform::GetInstance().AddContentApp(
app, &contentAppEndpoint, Span<DataVersion>(dataVersionBuf, ArraySize(contentAppClusters)),
Span<const EmberAfDeviceType>(gContentAppDeviceType));
Expand All @@ -355,12 +373,13 @@ EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint1
}

EndpointId ContentAppFactoryImpl::AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName,
uint16_t productId, const char * szApplicationVersion, jobject manager,
EndpointId desiredEndpointId)
uint16_t productId, const char * szApplicationVersion,
std::vector<SupportedCluster> supportedClusters, EndpointId desiredEndpointId,
jobject manager)
{
DataVersion * dataVersionBuf = new DataVersion[ArraySize(contentAppClusters)];
ContentAppImpl * app = new ContentAppImpl(szVendorName, vendorId, szApplicationName, productId, szApplicationVersion, "",
mAttributeDelegate, mCommandDelegate);
std::move(supportedClusters), mAttributeDelegate, mCommandDelegate);
EndpointId epId = ContentAppPlatform::GetInstance().AddContentApp(
app, &contentAppEndpoint, Span<DataVersion>(dataVersionBuf, ArraySize(contentAppClusters)),
Span<const EmberAfDeviceType>(gContentAppDeviceType), desiredEndpointId);
Expand Down Expand Up @@ -480,21 +499,24 @@ CHIP_ERROR InitVideoPlayerPlatform(jobject contentAppEndpointManager)
}

EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
const char * szApplicationVersion, jobject manager)
const char * szApplicationVersion, std::vector<SupportedCluster> supportedClusters, jobject manager)
{
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
ChipLogProgress(DeviceLayer, "AppImpl: AddContentApp vendorId=%d applicationName=%s ", vendorId, szApplicationName);
return gFactory.AddContentApp(szVendorName, vendorId, szApplicationName, productId, szApplicationVersion, manager);
return gFactory.AddContentApp(szVendorName, vendorId, szApplicationName, productId, szApplicationVersion,
std::move(supportedClusters), manager);
#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
return kInvalidEndpointId;
}

EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
const char * szApplicationVersion, EndpointId endpointId, jobject manager)
const char * szApplicationVersion, std::vector<SupportedCluster> supportedClusters, EndpointId endpointId,
jobject manager)
{
#if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
ChipLogProgress(DeviceLayer, "AppImpl: AddContentApp vendorId=%d applicationName=%s ", vendorId, szApplicationName);
return gFactory.AddContentApp(szVendorName, vendorId, szApplicationName, productId, szApplicationVersion, manager, endpointId);
return gFactory.AddContentApp(szVendorName, vendorId, szApplicationName, productId, szApplicationVersion,
std::move(supportedClusters), endpointId, manager);
#endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
return kInvalidEndpointId;
}
Expand Down
28 changes: 15 additions & 13 deletions examples/tv-app/android/java/AppImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <lib/support/JniReferences.h>
#include <stdbool.h>
#include <stdint.h>
#include <vector>

#include "../include/account-login/AccountLoginManager.h"
#include "../include/application-basic/ApplicationBasicManager.h"
Expand All @@ -56,9 +57,12 @@

CHIP_ERROR InitVideoPlayerPlatform(jobject contentAppEndpointManager);
EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
const char * szApplicationVersion, jobject manager);
const char * szApplicationVersion,
std::vector<chip::AppPlatform::ContentApp::SupportedCluster> supportedClusters, jobject manager);
EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
const char * szApplicationVersion, EndpointId endpointId, jobject manager);
const char * szApplicationVersion,
std::vector<chip::AppPlatform::ContentApp::SupportedCluster> supportedClusters, EndpointId endpointId,
jobject manager);
EndpointId RemoveContentApp(EndpointId epId);
void ReportAttributeChange(EndpointId epId, chip::ClusterId clusterId, chip::AttributeId attributeId);

Expand All @@ -81,6 +85,7 @@ using TargetNavigatorDelegate = app::Clusters::TargetNavigator::Delegate;
using SupportedProtocolsBitmap = app::Clusters::ContentLauncher::SupportedProtocolsBitmap;
using ContentAppAttributeDelegate = chip::AppPlatform::ContentAppAttributeDelegate;
using ContentAppCommandDelegate = chip::AppPlatform::ContentAppCommandDelegate;
using SupportedCluster = chip::AppPlatform::ContentApp::SupportedCluster;

static const int kCatalogVendorId = CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID;

Expand All @@ -91,8 +96,9 @@ class DLL_EXPORT ContentAppImpl : public ContentApp
{
public:
ContentAppImpl(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
const char * szApplicationVersion, const char * setupPIN, ContentAppAttributeDelegate * attributeDelegate,
ContentAppCommandDelegate * commandDelegate) :
const char * szApplicationVersion, const char * setupPIN, std::vector<SupportedCluster> supportedClusters,
ContentAppAttributeDelegate * attributeDelegate, ContentAppCommandDelegate * commandDelegate) :
ContentApp{ supportedClusters },
mApplicationBasicDelegate(kCatalogVendorId, BuildAppId(vendorId), szVendorName, vendorId, szApplicationName, productId,
szApplicationVersion),
mAccountLoginDelegate(commandDelegate, setupPIN),
Expand Down Expand Up @@ -160,10 +166,11 @@ class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
ContentApp * LoadContentApp(const CatalogVendorApp & vendorApp) override;

EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
const char * szApplicationVersion, jobject manager);
const char * szApplicationVersion, std::vector<SupportedCluster> supportedClusters, jobject manager);

EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
const char * szApplicationVersion, jobject manager, EndpointId desiredEndpointId);
const char * szApplicationVersion, std::vector<SupportedCluster> supportedClusters,
EndpointId desiredEndpointId, jobject manager);

EndpointId RemoveContentApp(EndpointId epId);

Expand Down Expand Up @@ -192,14 +199,9 @@ class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
void setContentAppCommandDelegate(ContentAppCommandDelegate * commandDelegate);

protected:
std::vector<ContentAppImpl *> mContentApps{
new ContentAppImpl("Vendor1", 1, "exampleid", 11, "Version1", "20202021", nullptr, nullptr),
new ContentAppImpl("Vendor2", 65521, "exampleString", 32768, "Version2", "20202021", nullptr, nullptr),
new ContentAppImpl("Vendor3", 9050, "App3", 22, "Version3", "20202021", nullptr, nullptr),
new ContentAppImpl("TestSuiteVendor", 1111, "applicationId", 22, "v2", "20202021", nullptr, nullptr)
};
// TODO: Update to use unique_ptr instead of raw pointers
std::vector<ContentAppImpl *> mContentApps;
std::vector<DataVersion *> mDataVersions{};

std::vector<uint16_t> mAdminVendorIds{};

private:
Expand Down
Loading
Loading