AppImpl.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. *
  3. * Copyright (c) 2021 Project CHIP Authors
  4. * All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /**
  19. * @brief Manages Content Apps
  20. */
  21. #pragma once
  22. #include <app-common/zap-generated/enums.h>
  23. #include <app/app-platform/ContentApp.h>
  24. #include <app/app-platform/ContentAppPlatform.h>
  25. #include <app/util/attribute-storage.h>
  26. #include <functional>
  27. #include <jni.h>
  28. #include <lib/core/DataModelTypes.h>
  29. #include <lib/support/JniReferences.h>
  30. #include <stdbool.h>
  31. #include <stdint.h>
  32. #include "../include/account-login/AccountLoginManager.h"
  33. #include "../include/application-basic/ApplicationBasicManager.h"
  34. #include "../include/application-launcher/ApplicationLauncherManager.h"
  35. #include "../include/content-launcher/AppContentLauncherManager.h"
  36. #include "../include/media-playback/AppMediaPlaybackManager.h"
  37. #include "../include/target-navigator/TargetNavigatorManager.h"
  38. #include "ChannelManager.h"
  39. #include "CommissionerMain.h"
  40. #include "ContentAppAttributeDelegate.h"
  41. #include "ContentAppCommandDelegate.h"
  42. #include "KeypadInputManager.h"
  43. #include <app/clusters/account-login-server/account-login-delegate.h>
  44. #include <app/clusters/application-basic-server/application-basic-delegate.h>
  45. #include <app/clusters/application-launcher-server/application-launcher-delegate.h>
  46. #include <app/clusters/channel-server/channel-delegate.h>
  47. #include <app/clusters/content-launch-server/content-launch-delegate.h>
  48. #include <app/clusters/keypad-input-server/keypad-input-delegate.h>
  49. #include <app/clusters/media-playback-server/media-playback-delegate.h>
  50. #include <app/clusters/target-navigator-server/target-navigator-delegate.h>
  51. CHIP_ERROR InitVideoPlayerPlatform(jobject contentAppEndpointManager);
  52. EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
  53. const char * szApplicationVersion, jobject manager);
  54. EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
  55. const char * szApplicationVersion, EndpointId endpointId, jobject manager);
  56. EndpointId RemoveContentApp(EndpointId epId);
  57. void ReportAttributeChange(EndpointId epId, chip::ClusterId clusterId, chip::AttributeId attributeId);
  58. void AddSelfVendorAsAdmin();
  59. #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
  60. namespace chip {
  61. namespace AppPlatform {
  62. using AccountLoginDelegate = app::Clusters::AccountLogin::Delegate;
  63. using ApplicationBasicDelegate = app::Clusters::ApplicationBasic::Delegate;
  64. using ApplicationLauncherDelegate = app::Clusters::ApplicationLauncher::Delegate;
  65. using ChannelDelegate = app::Clusters::Channel::Delegate;
  66. using ContentLauncherDelegate = app::Clusters::ContentLauncher::Delegate;
  67. using KeypadInputDelegate = app::Clusters::KeypadInput::Delegate;
  68. using MediaPlaybackDelegate = app::Clusters::MediaPlayback::Delegate;
  69. using TargetNavigatorDelegate = app::Clusters::TargetNavigator::Delegate;
  70. using SupportedStreamingProtocol = app::Clusters::ContentLauncher::SupportedStreamingProtocol;
  71. using ContentAppAttributeDelegate = chip::AppPlatform::ContentAppAttributeDelegate;
  72. using ContentAppCommandDelegate = chip::AppPlatform::ContentAppCommandDelegate;
  73. static const int kCatalogVendorId = CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID;
  74. // for this platform, appid is just vendor id
  75. #define BuildAppId(vid) std::to_string(vid).c_str()
  76. class DLL_EXPORT ContentAppImpl : public ContentApp
  77. {
  78. public:
  79. ContentAppImpl(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
  80. const char * szApplicationVersion, const char * setupPIN, ContentAppAttributeDelegate * attributeDelegate,
  81. ContentAppCommandDelegate * commandDelegate) :
  82. mApplicationBasicDelegate(kCatalogVendorId, BuildAppId(vendorId), szVendorName, vendorId, szApplicationName, productId,
  83. szApplicationVersion),
  84. mAccountLoginDelegate(commandDelegate, setupPIN),
  85. mContentLauncherDelegate(attributeDelegate, { "image/*", "video/*" },
  86. to_underlying(SupportedStreamingProtocol::kDash) |
  87. to_underlying(SupportedStreamingProtocol::kHls)),
  88. mMediaPlaybackDelegate(attributeDelegate),
  89. mTargetNavigatorDelegate(attributeDelegate, { "home", "search", "info", "guide", "menu" }, 0){};
  90. virtual ~ContentAppImpl() {}
  91. AccountLoginDelegate * GetAccountLoginDelegate() override
  92. {
  93. mAccountLoginDelegate.SetEndpointId(GetEndpointId());
  94. return &mAccountLoginDelegate;
  95. };
  96. ApplicationBasicDelegate * GetApplicationBasicDelegate() override { return &mApplicationBasicDelegate; };
  97. ApplicationLauncherDelegate * GetApplicationLauncherDelegate() override { return &mApplicationLauncherDelegate; };
  98. ChannelDelegate * GetChannelDelegate() override { return &mChannelDelegate; };
  99. ContentLauncherDelegate * GetContentLauncherDelegate() override
  100. {
  101. mContentLauncherDelegate.SetEndpointId(GetEndpointId());
  102. return &mContentLauncherDelegate;
  103. };
  104. KeypadInputDelegate * GetKeypadInputDelegate() override { return &mKeypadInputDelegate; };
  105. MediaPlaybackDelegate * GetMediaPlaybackDelegate() override
  106. {
  107. mMediaPlaybackDelegate.SetEndpointId(GetEndpointId());
  108. return &mMediaPlaybackDelegate;
  109. };
  110. TargetNavigatorDelegate * GetTargetNavigatorDelegate() override
  111. {
  112. mTargetNavigatorDelegate.SetEndpointId(GetEndpointId());
  113. return &mTargetNavigatorDelegate;
  114. };
  115. protected:
  116. ApplicationBasicManager mApplicationBasicDelegate;
  117. AccountLoginManager mAccountLoginDelegate;
  118. ApplicationLauncherManager mApplicationLauncherDelegate;
  119. ChannelManager mChannelDelegate;
  120. AppContentLauncherManager mContentLauncherDelegate;
  121. KeypadInputManager mKeypadInputDelegate;
  122. AppMediaPlaybackManager mMediaPlaybackDelegate;
  123. TargetNavigatorManager mTargetNavigatorDelegate;
  124. };
  125. class DLL_EXPORT ContentAppFactoryImpl : public ContentAppFactory
  126. {
  127. #define APP_LIBRARY_SIZE 4
  128. public:
  129. ContentAppFactoryImpl();
  130. virtual ~ContentAppFactoryImpl() {}
  131. // Lookup CatalogVendor App for this client (vendor id/product id client)
  132. // and then write it to destinationApp
  133. // return error if not found
  134. CHIP_ERROR LookupCatalogVendorApp(uint16_t vendorId, uint16_t productId, CatalogVendorApp * destinationApp) override;
  135. // Lookup ContentApp for this catalog id / app id and load it
  136. ContentApp * LoadContentApp(const CatalogVendorApp & vendorApp) override;
  137. EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
  138. const char * szApplicationVersion, jobject manager);
  139. EndpointId AddContentApp(const char * szVendorName, uint16_t vendorId, const char * szApplicationName, uint16_t productId,
  140. const char * szApplicationVersion, jobject manager, EndpointId desiredEndpointId);
  141. EndpointId RemoveContentApp(EndpointId epId);
  142. // Gets the catalog vendor ID used by this platform
  143. uint16_t GetPlatformCatalogVendorId() override;
  144. // Converts application (any catalog) into the platform's catalog Vendor
  145. // and then writes it to destinationApp
  146. CHIP_ERROR ConvertToPlatformCatalogVendorApp(const CatalogVendorApp & sourceApp, CatalogVendorApp * destinationApp) override;
  147. // Get the privilege this vendorId should have on endpoints 1, 2, and content app endpoints
  148. // In the case of casting video clients, this should usually be Access::Privilege::kOperate
  149. // and for voice agents, this may be Access::Privilege::kAdminister
  150. // When a vendor has admin privileges, it will get access to all clusters on ep1
  151. Access::Privilege GetVendorPrivilege(uint16_t vendorId) override;
  152. // Get the cluster list this vendorId/productId should have on static endpoints such as ep1 for casting video clients.
  153. // When a vendor has admin privileges, it will get access to all clusters on ep1
  154. std::list<ClusterId> GetAllowedClusterListForStaticEndpoint(EndpointId endpointId, uint16_t vendorId,
  155. uint16_t productId) override;
  156. void AddAdminVendorId(uint16_t vendorId);
  157. void setContentAppAttributeDelegate(ContentAppAttributeDelegate * attributeDelegate);
  158. void setContentAppCommandDelegate(ContentAppCommandDelegate * commandDelegate);
  159. protected:
  160. std::vector<ContentAppImpl *> mContentApps{
  161. new ContentAppImpl("Vendor1", 1, "exampleid", 11, "Version1", "20202021", nullptr, nullptr),
  162. new ContentAppImpl("Vendor2", 65521, "exampleString", 32768, "Version2", "20202021", nullptr, nullptr),
  163. new ContentAppImpl("Vendor3", 9050, "App3", 22, "Version3", "20202021", nullptr, nullptr),
  164. new ContentAppImpl("TestSuiteVendor", 1111, "applicationId", 22, "v2", "20202021", nullptr, nullptr)
  165. };
  166. std::vector<DataVersion *> mDataVersions{};
  167. std::vector<uint16_t> mAdminVendorIds{};
  168. private:
  169. ContentAppAttributeDelegate * mAttributeDelegate;
  170. ContentAppCommandDelegate * mCommandDelegate;
  171. };
  172. } // namespace AppPlatform
  173. } // namespace chip
  174. chip::AppPlatform::ContentAppFactoryImpl * GetContentAppFactoryImpl();
  175. #endif // CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED