xref: /aosp_15_r20/external/pigweed/pw_chre/platform_nanoapp.cc (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #include "chre/platform/platform_nanoapp.h"
15 
16 #include "chre/util/system/napp_permissions.h"
17 #include "chre_api/chre/version.h"
18 
19 namespace chre {
20 
~PlatformNanoapp()21 PlatformNanoapp::~PlatformNanoapp() {}
22 
start()23 bool PlatformNanoapp::start() { return app_info_->entryPoints.start(); }
24 
handleEvent(uint32_t SenderInstanceId,uint16_t eventType,const void * eventData)25 void PlatformNanoapp::handleEvent(uint32_t SenderInstanceId,
26                                   uint16_t eventType,
27                                   const void* eventData) {
28   app_info_->entryPoints.handleEvent(SenderInstanceId, eventType, eventData);
29 }
30 
end()31 void PlatformNanoapp::end() { app_info_->entryPoints.end(); }
32 
getAppId() const33 uint64_t PlatformNanoapp::getAppId() const {
34   return (app_info_ == nullptr) ? 0 : app_info_->appId;
35 }
36 
getAppVersion() const37 uint32_t PlatformNanoapp::getAppVersion() const {
38   return app_info_->appVersion;
39 }
40 
getTargetApiVersion() const41 uint32_t PlatformNanoapp::getTargetApiVersion() const {
42   return CHRE_API_VERSION;
43 }
44 
getAppName() const45 const char* PlatformNanoapp::getAppName() const {
46   return (app_info_ != nullptr) ? app_info_->name : "Unknown";
47 }
48 
supportsAppPermissions() const49 bool PlatformNanoapp::supportsAppPermissions() const {
50   return (app_info_ != nullptr) ? (app_info_->structMinorVersion >=
51                                    CHRE_NSL_NANOAPP_INFO_STRUCT_MINOR_VERSION)
52                                 : false;
53 }
54 
getAppPermissions() const55 uint32_t PlatformNanoapp::getAppPermissions() const {
56   return (supportsAppPermissions())
57              ? app_info_->appPermissions
58              : static_cast<uint32_t>(chre::NanoappPermissions::CHRE_PERMS_NONE);
59 }
60 
isSystemNanoapp() const61 bool PlatformNanoapp::isSystemNanoapp() const {
62   return (app_info_ != nullptr && app_info_->isSystemNanoapp);
63 }
64 
logStateToBuffer(DebugDumpWrapper & debugDump) const65 void PlatformNanoapp::logStateToBuffer(DebugDumpWrapper& debugDump) const {
66   if (!app_info_) {
67     return;
68   }
69   debugDump.print("%s: %s", app_info_->name, app_info_->vendor);
70 }
71 
loadStatic(const struct chreNslNanoappInfo * app_info)72 void PlatformNanoappBase::loadStatic(
73     const struct chreNslNanoappInfo* app_info) {
74   app_info_ = app_info;
75 }
76 
77 }  // namespace chre
78