blob: b5405254d929f6bb137ae748e034205fdf9cab8e [file] [log] [blame]
Yifan Hongc34f57f2017-03-10 14:12:00 -08001/*
2 * Copyright (C) 2017 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 "utils.h"
18
Yifan Hong95c7a062017-03-28 19:07:17 -070019#include <sensors/convert.h>
20
Yifan Hongc34f57f2017-03-10 14:12:00 -080021namespace android {
22namespace frameworks {
23namespace sensorservice {
24namespace V1_0 {
25namespace implementation {
26
27using ::android::Sensor;
28using ::android::hardware::hidl_string;
29using ::android::hardware::sensors::V1_0::SensorInfo;
30
Yifan Hong95c7a062017-03-28 19:07:17 -070031SensorInfo convertSensor(const Sensor& src) {
Yifan Hongc34f57f2017-03-10 14:12:00 -080032 SensorInfo dst;
33 const String8& name = src.getName();
34 const String8& vendor = src.getVendor();
35 dst.name = hidl_string{name.string(), name.size()};
36 dst.vendor = hidl_string{vendor.string(), vendor.size()};
37 dst.version = src.getVersion();
38 dst.sensorHandle = src.getHandle();
39 dst.type = static_cast<::android::hardware::sensors::V1_0::SensorType>(
40 src.getType());
Yifan Hong95c7a062017-03-28 19:07:17 -070041 // maxRange uses maxValue because ::android::Sensor wraps the
Yifan Hongc34f57f2017-03-10 14:12:00 -080042 // internal sensor_t in this way.
43 dst.maxRange = src.getMaxValue();
44 dst.resolution = src.getResolution();
45 dst.power = src.getPowerUsage();
46 dst.minDelay = src.getMinDelay();
47 dst.fifoReservedEventCount = src.getFifoReservedEventCount();
48 dst.fifoMaxEventCount = src.getFifoMaxEventCount();
49 dst.typeAsString = src.getStringType();
50 dst.requiredPermission = src.getRequiredPermission();
51 dst.maxDelay = src.getMaxDelay();
52 dst.flags = src.getFlags();
53 return dst;
54}
55
56Result convertResult(status_t status) {
57 switch (status) {
58 case OK:
59 return Result::OK;
60 case NAME_NOT_FOUND:
61 return Result::NOT_EXIST;
62 case NO_MEMORY:
63 return Result::NO_MEMORY;
64 case NO_INIT:
65 return Result::NO_INIT;
66 case BAD_VALUE:
67 return Result::BAD_VALUE;
68 case INVALID_OPERATION:
69 return Result::INVALID_OPERATION;
70 default:
71 return Result::UNKNOWN_ERROR;
72 }
73}
74
Yifan Hong95c7a062017-03-28 19:07:17 -070075::android::hardware::sensors::V1_0::Event convertEvent(const ::ASensorEvent& src) {
76 ::android::hardware::sensors::V1_0::Event dst;
77 ::android::hardware::sensors::V1_0::implementation::convertFromSensorEvent(
78 reinterpret_cast<const sensors_event_t&>(src), &dst);
79 return dst;
80}
81
Yifan Hongc34f57f2017-03-10 14:12:00 -080082} // namespace implementation
83} // namespace V1_0
84} // namespace sensorservice
85} // namespace frameworks
86} // namespace android