• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 #ifndef CHRE_TEST_SHARED_SEND_MESSAGE_H_
18 #define CHRE_TEST_SHARED_SEND_MESSAGE_H_
19 
20 #include <pb_encode.h>
21 #include <cinttypes>
22 
23 #include "chre/util/system/napp_permissions.h"
24 #include "chre_test_common.nanopb.h"
25 
26 namespace chre {
27 
28 namespace test_shared {
29 
30 chre_test_common_TestResult makeTestResultProtoMessage(
31     bool success, const char *errMessage = nullptr);
32 
33 /**
34  * Same as sendTestResultWithMsgToHost, but doesn't accept an error message and
35  * uses the free callback specified in chre/util/nanoapp/callbacks.h
36  */
37 void sendTestResultToHost(uint16_t hostEndpointId, uint32_t messageType,
38                           bool success, bool abortOnFailure = true);
39 
40 /**
41  * Sends a test result to the host using the chre_test_common.TestResult
42  * message.
43  *
44  * @param hostEndpointId The endpoint ID of the host to send the result to.
45  * @param messageType The message type to associate with the test result.
46  * @param success True if the test succeeded.
47  * @param errMessage Nullable error message to send to the host. Error message
48  *     will only be sent if success is false.
49  * @param abortOnFailure If true, calls chreAbort() if success is false. This
50  *     should only be set to true in legacy tests, as crashing CHRE makes the
51  *     test failure more difficult to understand.
52  */
53 void sendTestResultWithMsgToHost(uint16_t hostEndpointId, uint32_t messageType,
54                                  bool success, const char *errMessage,
55                                  bool abortOnFailure = true);
56 
57 /**
58  * Sends a message to the host with an empty payload.
59  *
60  * @param hostEndpointId The endpoint Id of the host to send the message to.
61  * @param messageType The message type.
62  */
63 void sendEmptyMessageToHost(uint16_t hostEndpointId, uint32_t messageType);
64 
65 /**
66  * Sends a message to the host with default NanoappPermissions (CHRE_PERMS_NONE)
67  *
68  * @param hostEndpointId The endpoint Id of the host to send the message to.
69  * @param message The proto message struct pointer.
70  * @param fields The fields descriptor of the proto message to encode.
71  * @param messageType The message type of the message.
72  */
73 void sendMessageToHost(uint16_t hostEndpointId, const void *message,
74                        const pb_field_t *fields, uint32_t messageType);
75 
76 /**
77  * Sends a message to the host with the provided NanoappPermissions.
78  *
79  * @param hostEndpointId The endpoint Id of the host to send the message to.
80  * @param message The proto message struct pointer.
81  * @param fields The fields descriptor of the proto message to encode.
82  * @param messageType The message type of the message.
83    @param perms The NanoappPermissions associated with the message.
84  */
85 void sendMessageToHostWithPermissions(uint16_t hostEndpointId,
86                                       const void *message,
87                                       const pb_field_t *fields,
88                                       uint32_t messageType,
89                                       chre::NanoappPermissions perms);
90 
91 }  // namespace test_shared
92 
93 }  // namespace chre
94 
95 #endif  // CHRE_TEST_SHARED_SEND_MESSAGE_H_
96