rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #define LOG_TAG "VzwDebugInterface" |
| 18 | |
| 19 | #include <log/log.h> |
| 20 | |
| 21 | #include "VzwDebug.h" |
| 22 | |
| 23 | namespace vendor { |
| 24 | namespace mediatek { |
| 25 | namespace hardware { |
| 26 | namespace gnss { |
| 27 | namespace V1_1 { |
| 28 | namespace implementation { |
| 29 | |
| 30 | sp<IVzwDebugCallback> VzwDebug::sVzwDebugCbIface = nullptr; |
| 31 | VzwDebugCallbacks VzwDebug::sHalVzwDeubgCb = { |
| 32 | .vzw_debug_cb = vzwDebugMessageCb, |
| 33 | }; |
| 34 | |
| 35 | |
| 36 | VzwDebug::VzwDebug(const VzwDebugInterface* vzwDebugIface) : mHalVzwDebugIface(vzwDebugIface) {} |
| 37 | |
| 38 | |
| 39 | // Methods from ::vendor::mediatek::hardware::gnss::V1_1::IVzwDebug follow. |
| 40 | Return<bool> VzwDebug::init(const sp<IVzwDebugCallback>& callback) { |
| 41 | ALOGE("%s: Vzw debug init, to set callback", __func__); |
| 42 | if (mHalVzwDebugIface == nullptr) { |
| 43 | ALOGE("%s: Vzw debug HAL interface is unavailable", __func__); |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | sVzwDebugCbIface = callback; |
| 48 | |
| 49 | return (mHalVzwDebugIface->init(&sHalVzwDeubgCb) == 0); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | void VzwDebug::vzwDebugMessageCb(VzwDebugData* vzw_message) { |
| 54 | if (sVzwDebugCbIface == nullptr) { |
| 55 | ALOGE("%s: Vzw Debug Callback Interface configured incorrectly", __func__); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | IVzwDebugCallback::VzwDebugData* pMsg = new IVzwDebugCallback::VzwDebugData(); |
| 60 | pMsg->size = strlen(vzw_message->vzw_msg_data); |
| 61 | if (pMsg->size >= VZW_DEBUG_STRING_MAXLEN) { |
| 62 | pMsg->size = VZW_DEBUG_STRING_MAXLEN - 1; |
| 63 | } |
| 64 | |
| 65 | uint8_t *dst = reinterpret_cast<uint8_t *>(&pMsg->vzw_msg_data[0]); |
| 66 | const uint8_t *src = reinterpret_cast<uint8_t *>(&vzw_message->vzw_msg_data[0]); |
| 67 | memcpy(dst, src, pMsg->size + 1); |
| 68 | |
| 69 | auto ret = sVzwDebugCbIface->vzwDebugCb(*pMsg); |
| 70 | if (!ret.isOk()) { |
| 71 | ALOGE("%s: Unable to invoke callback", __func__); |
| 72 | } |
| 73 | delete pMsg; |
| 74 | } |
| 75 | |
| 76 | |
| 77 | |
| 78 | // Methods from ::android::hardware::gnss::V1_0::IGnssDebug follow. |
| 79 | Return<void> VzwDebug::setVzwDebugScreen(bool enabled) { |
| 80 | if (mHalVzwDebugIface == nullptr) { |
| 81 | ALOGE("%s: Vzw debug HAL interface is unavailable", __func__); |
| 82 | return Void(); |
| 83 | } |
| 84 | |
| 85 | mHalVzwDebugIface->set_vzw_debug_screen(enabled); |
| 86 | return Void(); |
| 87 | } |
| 88 | |
| 89 | } // namespace implementation |
| 90 | } // namespace V1_1 |
| 91 | } // namespace gnss |
| 92 | } // namespace hardware |
| 93 | } // namespace mediatek |
| 94 | } // namespace vendor |