upload android base code part6
This commit is contained in:
parent
421e214c7d
commit
4e516ec6ed
35396 changed files with 9188716 additions and 0 deletions
26
android/system/chre/apps/message_world/Makefile
Normal file
26
android/system/chre/apps/message_world/Makefile
Normal file
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# Message World Nanoapp Makefile
|
||||
#
|
||||
|
||||
# Environment Checks ###########################################################
|
||||
|
||||
ifeq ($(CHRE_PREFIX),)
|
||||
$(error "The CHRE_PREFIX environment variable must be set to a path to the \
|
||||
CHRE project root. Example: export CHRE_PREFIX=$$HOME/chre")
|
||||
endif
|
||||
|
||||
# Nanoapp Configuration ########################################################
|
||||
|
||||
NANOAPP_NAME = message_world
|
||||
|
||||
# Common Compiler Flags ########################################################
|
||||
|
||||
COMMON_CFLAGS += -I.
|
||||
|
||||
# Common Source Files ##########################################################
|
||||
|
||||
COMMON_SRCS += message_world.cc
|
||||
|
||||
# Makefile Includes ############################################################
|
||||
|
||||
include $(CHRE_PREFIX)/build/nanoapp/app.mk
|
89
android/system/chre/apps/message_world/message_world.cc
Normal file
89
android/system/chre/apps/message_world/message_world.cc
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <chre.h>
|
||||
#include <cinttypes>
|
||||
|
||||
#include "chre/util/nanoapp/log.h"
|
||||
|
||||
#define LOG_TAG "[MsgWorld]"
|
||||
|
||||
#ifdef CHRE_NANOAPP_INTERNAL
|
||||
namespace chre {
|
||||
namespace {
|
||||
#endif // CHRE_NANOAPP_INTERNAL
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr uint32_t kMessageType = 1234;
|
||||
uint8_t gMessageData[CHRE_MESSAGE_TO_HOST_MAX_SIZE] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
|
||||
void messageFreeCallback(void *message, size_t messageSize) {
|
||||
LOGI("Got message free callback for message @"
|
||||
" %p (match? %d) size %zu (match? %d)",
|
||||
message, (message == gMessageData),
|
||||
messageSize, (messageSize == sizeof(gMessageData)));
|
||||
if (!chreSendEvent(CHRE_EVENT_FIRST_USER_VALUE, nullptr, nullptr,
|
||||
chreGetInstanceId())) {
|
||||
LOGE("Failed to send event");
|
||||
}
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
bool nanoappStart() {
|
||||
LOGI("App started as instance %" PRIu32, chreGetInstanceId());
|
||||
|
||||
bool success = chreSendMessageToHostEndpoint(
|
||||
gMessageData, sizeof(gMessageData), kMessageType,
|
||||
CHRE_HOST_ENDPOINT_BROADCAST, messageFreeCallback);
|
||||
LOGI("Sent message to host from start callback, result %d", success);
|
||||
return true;
|
||||
}
|
||||
|
||||
void nanoappHandleEvent(uint32_t senderInstanceId,
|
||||
uint16_t eventType,
|
||||
const void *eventData) {
|
||||
if (eventType == CHRE_EVENT_MESSAGE_FROM_HOST) {
|
||||
auto *msg = static_cast<const chreMessageFromHostData *>(eventData);
|
||||
LOGI("Got message from host with type %" PRIu32 " size %" PRIu32
|
||||
" data @ %p hostEndpoint 0x%" PRIx16,
|
||||
msg->messageType, msg->messageSize, msg->message, msg->hostEndpoint);
|
||||
if (senderInstanceId != CHRE_INSTANCE_ID) {
|
||||
LOGE("Message from host came from unexpected instance ID %" PRIu32,
|
||||
senderInstanceId);
|
||||
}
|
||||
|
||||
bool success = chreSendMessageToHostEndpoint(
|
||||
gMessageData, sizeof(gMessageData), kMessageType,
|
||||
CHRE_HOST_ENDPOINT_BROADCAST, messageFreeCallback);
|
||||
LOGI("Result of sending reply: %d", success);
|
||||
}
|
||||
}
|
||||
|
||||
void nanoappEnd() {
|
||||
LOGI("Stopped");
|
||||
}
|
||||
|
||||
#ifdef CHRE_NANOAPP_INTERNAL
|
||||
} // anonymous namespace
|
||||
} // namespace chre
|
||||
|
||||
#include "chre/util/nanoapp/app_id.h"
|
||||
#include "chre/platform/static_nanoapp_init.h"
|
||||
|
||||
CHRE_STATIC_NANOAPP_INIT(MessageWorld, chre::kMessageWorldAppId, 0);
|
||||
#endif // CHRE_NANOAPP_INTERNAL
|
12
android/system/chre/apps/message_world/message_world.mk
Normal file
12
android/system/chre/apps/message_world/message_world.mk
Normal file
|
@ -0,0 +1,12 @@
|
|||
#
|
||||
# Message World Makefile
|
||||
#
|
||||
|
||||
# Common Compiler Flags ########################################################
|
||||
|
||||
# Include paths.
|
||||
COMMON_CFLAGS += -Iapps/message_world/include
|
||||
|
||||
# Common Source Files ##########################################################
|
||||
|
||||
COMMON_SRCS += apps/message_world/message_world.cc
|
Loading…
Add table
Add a link
Reference in a new issue