xref: /aosp_15_r20/system/chre/apps/hello_world/hello_world.cc (revision 84e339476a462649f82315436d70fd732297a399)
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <inttypes.h>
18 
19 #include "chre/util/nanoapp/log.h"
20 #include "chre_api/chre.h"
21 
22 #define LOG_TAG "[HelloWorld]"
23 
24 /**
25  * @file
26  * A very basic example nanoapp that just logs activity in its entry points.
27  * Note that code wrapped in #ifdef CHRE_NANOAPP_INTERNAL is only relevant when
28  * a nanoapp is to be statically built into the CHRE system binary, which would
29  * make it a "system nanoapp" rather than a true dynamically loadable nanoapp.
30  */
31 
32 #ifdef CHRE_NANOAPP_INTERNAL
33 namespace chre {
34 namespace {
35 #endif  // CHRE_NANOAPP_INTERNAL
36 
nanoappStart()37 bool nanoappStart() {
38   LOGI("Hello, world from version 0x%08" PRIx32, chreGetVersion());
39   return true;
40 }
41 
nanoappHandleEvent(uint32_t senderInstanceId,uint16_t eventType,const void *)42 void nanoappHandleEvent(uint32_t senderInstanceId, uint16_t eventType,
43                         const void * /*eventData*/) {
44   LOGI("Received event 0x%" PRIx16 " from 0x%" PRIx32 " at time %" PRIu64,
45        eventType, senderInstanceId, chreGetTime());
46 }
47 
nanoappEnd()48 void nanoappEnd() {
49   LOGI("Goodbye, world!");
50 }
51 
52 #ifdef CHRE_NANOAPP_INTERNAL
53 }  // anonymous namespace
54 }  // namespace chre
55 
56 #include "chre/platform/static_nanoapp_init.h"
57 #include "chre/util/nanoapp/app_id.h"
58 #include "chre/util/system/napp_permissions.h"
59 
60 CHRE_STATIC_NANOAPP_INIT(HelloWorld, chre::kHelloWorldAppId, 0,
61                          chre::NanoappPermissions::CHRE_PERMS_NONE);
62 #endif  // CHRE_NANOAPP_INTERNAL
63