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 <chre.h>
18 #include <inttypes.h>
19
20 /**
21 * @file
22 * A very basic example nanoapp that just logs activity in its entry points.
23 * Note that code wrapped in #ifdef CHRE_NANOAPP_INTERNAL is only relevant when
24 * a nanoapp is to be statically built into the CHRE system binary, which would
25 * make it a "system nanoapp" rather than a true dynamically loadable nanoapp.
26 */
27
28 #ifdef CHRE_NANOAPP_INTERNAL
29 namespace chre {
30 namespace {
31 #endif // CHRE_NANOAPP_INTERNAL
32
nanoappStart()33 bool nanoappStart() {
34 chreLog(CHRE_LOG_INFO, "Hello, world from version 0x%08" PRIx32,
35 chreGetVersion());
36 return true;
37 }
38
nanoappHandleEvent(uint32_t senderInstanceId,uint16_t eventType,const void *)39 void nanoappHandleEvent(uint32_t senderInstanceId, uint16_t eventType,
40 const void * /*eventData*/) {
41 chreLog(CHRE_LOG_INFO,
42 "Received event 0x%" PRIx16 " from 0x%" PRIx32 " at time %" PRIu64,
43 eventType, senderInstanceId, chreGetTime());
44 }
45
nanoappEnd()46 void nanoappEnd() {
47 chreLog(CHRE_LOG_INFO, "Goodbye, world!");
48 }
49
50 #ifdef CHRE_NANOAPP_INTERNAL
51 } // anonymous namespace
52 } // namespace chre
53
54 #include "chre/platform/static_nanoapp_init.h"
55 #include "chre/util/nanoapp/app_id.h"
56 #include "chre/util/system/napp_permissions.h"
57
58 CHRE_STATIC_NANOAPP_INIT(HelloWorld, chre::kHelloWorldAppId, 0,
59 chre::NanoappPermissions::CHRE_PERMS_NONE);
60 #endif // CHRE_NANOAPP_INTERNAL
61