blob: 2f9e922b59655dd259cd19c7d4ec20838ad22eb0 [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;
Yifan Hongecf10802017-04-10 13:37:25 -070066 case PERMISSION_DENIED:
67 return Result::PERMISSION_DENIED;
Yifan Hongc34f57f2017-03-10 14:12:00 -080068 case BAD_VALUE:
69 return Result::BAD_VALUE;
70 case INVALID_OPERATION:
71 return Result::INVALID_OPERATION;
72 default:
73 return Result::UNKNOWN_ERROR;
74 }
75}
76
Yifan Hong95c7a062017-03-28 19:07:17 -070077::android::hardware::sensors::V1_0::Event convertEvent(const ::ASensorEvent& src) {
78 ::android::hardware::sensors::V1_0::Event dst;
79 ::android::hardware::sensors::V1_0::implementation::convertFromSensorEvent(
80 reinterpret_cast<const sensors_event_t&>(src), &dst);
81 return dst;
82}
83
Yifan Hongc34f57f2017-03-10 14:12:00 -080084} // namespace implementation
85} // namespace V1_0
86} // namespace sensorservice
87} // namespace frameworks
88} // namespace android