blob: 27de32c26f04bd78389c2e694cc43bb9ed3e07f3 [file] [log] [blame]
Devin Moore160d7a42022-12-01 23:17:17 +00001/*
2 * Copyright (C) 2022 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 <sensors/common_convert.h>
18#include <cstring>
19
20namespace android {
21namespace hardware {
22namespace sensors {
23namespace implementation {
24namespace common {
25
26sensors_event_t convertASensorEvent(const ASensorEvent& src) {
27 // Attempt to ensure these types are compatible.
28 static_assert(sizeof(sensors_event_t) == sizeof(ASensorEvent));
29 static_assert(offsetof(sensors_event_t, timestamp) == offsetof(ASensorEvent, timestamp));
30 static_assert(offsetof(sensors_event_t, flags) == offsetof(ASensorEvent, flags));
31
32 // TODO(b/259711109) Follow up work to handle this in a safer way.
33 return *reinterpret_cast<const sensors_event_t*>(&src);
34}
35
36} // namespace common
37} // namespace implementation
38} // namespace sensors
39} // namespace hardware
40} // namespace android