Yifan Hong | c34f57f | 2017-03-10 14:12:00 -0800 | [diff] [blame] | 1 | /* |
| 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 Hong | 95c7a06 | 2017-03-28 19:07:17 -0700 | [diff] [blame] | 19 | #include <sensors/convert.h> |
| 20 | |
Yifan Hong | c34f57f | 2017-03-10 14:12:00 -0800 | [diff] [blame] | 21 | namespace android { |
| 22 | namespace frameworks { |
| 23 | namespace sensorservice { |
| 24 | namespace V1_0 { |
| 25 | namespace implementation { |
| 26 | |
| 27 | using ::android::Sensor; |
| 28 | using ::android::hardware::hidl_string; |
| 29 | using ::android::hardware::sensors::V1_0::SensorInfo; |
| 30 | |
Yifan Hong | 95c7a06 | 2017-03-28 19:07:17 -0700 | [diff] [blame] | 31 | SensorInfo convertSensor(const Sensor& src) { |
Yifan Hong | c34f57f | 2017-03-10 14:12:00 -0800 | [diff] [blame] | 32 | 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 Hong | 95c7a06 | 2017-03-28 19:07:17 -0700 | [diff] [blame] | 41 | // maxRange uses maxValue because ::android::Sensor wraps the |
Yifan Hong | c34f57f | 2017-03-10 14:12:00 -0800 | [diff] [blame] | 42 | // 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 | |
| 56 | Result 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 Hong | 95c7a06 | 2017-03-28 19:07:17 -0700 | [diff] [blame] | 75 | ::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 Hong | c34f57f | 2017-03-10 14:12:00 -0800 | [diff] [blame] | 82 | } // namespace implementation |
| 83 | } // namespace V1_0 |
| 84 | } // namespace sensorservice |
| 85 | } // namespace frameworks |
| 86 | } // namespace android |