blob: 4e027412a7244d0a43c8083003fb37e88a71dac6 [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
19namespace android {
20namespace frameworks {
21namespace sensorservice {
22namespace V1_0 {
23namespace implementation {
24
25using ::android::Sensor;
26using ::android::hardware::hidl_string;
27using ::android::hardware::sensors::V1_0::SensorInfo;
28
29SensorInfo convertSensor(const Sensor &src) {
30 SensorInfo dst;
31 const String8& name = src.getName();
32 const String8& vendor = src.getVendor();
33 dst.name = hidl_string{name.string(), name.size()};
34 dst.vendor = hidl_string{vendor.string(), vendor.size()};
35 dst.version = src.getVersion();
36 dst.sensorHandle = src.getHandle();
37 dst.type = static_cast<::android::hardware::sensors::V1_0::SensorType>(
38 src.getType());
39 // FIXME maxRange uses maxValue because ::android::Sensor wraps the
40 // internal sensor_t in this way.
41 dst.maxRange = src.getMaxValue();
42 dst.resolution = src.getResolution();
43 dst.power = src.getPowerUsage();
44 dst.minDelay = src.getMinDelay();
45 dst.fifoReservedEventCount = src.getFifoReservedEventCount();
46 dst.fifoMaxEventCount = src.getFifoMaxEventCount();
47 dst.typeAsString = src.getStringType();
48 dst.requiredPermission = src.getRequiredPermission();
49 dst.maxDelay = src.getMaxDelay();
50 dst.flags = src.getFlags();
51 return dst;
52}
53
54Result convertResult(status_t status) {
55 switch (status) {
56 case OK:
57 return Result::OK;
58 case NAME_NOT_FOUND:
59 return Result::NOT_EXIST;
60 case NO_MEMORY:
61 return Result::NO_MEMORY;
62 case NO_INIT:
63 return Result::NO_INIT;
64 case BAD_VALUE:
65 return Result::BAD_VALUE;
66 case INVALID_OPERATION:
67 return Result::INVALID_OPERATION;
68 default:
69 return Result::UNKNOWN_ERROR;
70 }
71}
72
73} // namespace implementation
74} // namespace V1_0
75} // namespace sensorservice
76} // namespace frameworks
77} // namespace android