| Devin Moore | 0b59781 | 2022-11-04 20:43:35 +0000 | [diff] [blame] | 1 | /* | 
 | 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 "utils.h" | 
 | 18 |  | 
 | 19 | #include <aidl/android/frameworks/sensorservice/ISensorManager.h> | 
 | 20 | #include <aidl/sensors/convert.h> | 
 | 21 |  | 
 | 22 | namespace android { | 
 | 23 | namespace frameworks { | 
 | 24 | namespace sensorservice { | 
 | 25 | namespace implementation { | 
 | 26 |  | 
 | 27 | ndk::ScopedAStatus convertResult(status_t src) { | 
 | 28 |     using ::aidl::android::frameworks::sensorservice::ISensorManager; | 
 | 29 |  | 
 | 30 |     int err = 0; | 
 | 31 |     switch (src) { | 
 | 32 |         case OK: | 
 | 33 |             return ndk::ScopedAStatus::ok(); | 
 | 34 |         case NAME_NOT_FOUND: | 
 | 35 |             err = ISensorManager::RESULT_NOT_EXIST; | 
 | 36 |             break; | 
 | 37 |         case NO_MEMORY: | 
 | 38 |             err = ISensorManager::RESULT_NO_MEMORY; | 
 | 39 |             break; | 
 | 40 |         case NO_INIT: | 
 | 41 |             err = ISensorManager::RESULT_NO_INIT; | 
 | 42 |             break; | 
 | 43 |         case PERMISSION_DENIED: | 
 | 44 |             err = ISensorManager::RESULT_PERMISSION_DENIED; | 
 | 45 |             break; | 
 | 46 |         case BAD_VALUE: | 
 | 47 |             err = ISensorManager::RESULT_BAD_VALUE; | 
 | 48 |             break; | 
 | 49 |         case INVALID_OPERATION: | 
 | 50 |             err = ISensorManager::RESULT_INVALID_OPERATION; | 
 | 51 |             break; | 
 | 52 |         default: | 
 | 53 |             err = ISensorManager::RESULT_UNKNOWN_ERROR; | 
 | 54 |     } | 
 | 55 |     return ndk::ScopedAStatus::fromServiceSpecificError(err); | 
 | 56 | } | 
 | 57 |  | 
 | 58 | ::aidl::android::hardware::sensors::Event convertEvent(const ::ASensorEvent& src) { | 
 | 59 |     ::aidl::android::hardware::sensors::Event dst; | 
 | 60 |     ::android::hardware::sensors::implementation:: | 
| Devin Moore | 826ca96 | 2022-12-01 23:17:17 +0000 | [diff] [blame] | 61 |             convertFromASensorEvent(src, &dst); | 
| Devin Moore | 0b59781 | 2022-11-04 20:43:35 +0000 | [diff] [blame] | 62 |     return dst; | 
 | 63 | } | 
 | 64 |  | 
 | 65 | } // namespace implementation | 
 | 66 | } // namespace sensorservice | 
 | 67 | } // namespace frameworks | 
 | 68 | } // namespace android |