1 /* 2 * Copyright (C) 2021 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 before <log/log.h> to overwrite the default value. 18 #define LOG_TAG "GnssNavigationMessageJni" 19 20 #include "GnssNavigationMessage.h" 21 22 #include "Utils.h" 23 24 namespace android::gnss { 25 26 using hardware::gnss::IGnssNavigationMessageInterface; 27 using IGnssNavigationMessageHidl = hardware::gnss::V1_0::IGnssNavigationMessage; 28 29 // Implementation of GnssNavigationMessage (AIDL HAL) 30 GnssNavigationMessageAidl(const sp<IGnssNavigationMessageInterface> & iGnssNavigationMessage)31GnssNavigationMessageAidl::GnssNavigationMessageAidl( 32 const sp<IGnssNavigationMessageInterface>& iGnssNavigationMessage) 33 : mIGnssNavigationMessage(iGnssNavigationMessage) { 34 assert(mIGnssNavigationMessage != nullptr); 35 } 36 setCallback(const std::unique_ptr<GnssNavigationMessageCallback> & callback)37jboolean GnssNavigationMessageAidl::setCallback( 38 const std::unique_ptr<GnssNavigationMessageCallback>& callback) { 39 auto status = mIGnssNavigationMessage->setCallback(callback->getAidl()); 40 return checkAidlStatus(status, "IGnssNavigationMessageAidl setCallback() failed."); 41 } 42 close()43jboolean GnssNavigationMessageAidl::close() { 44 auto status = mIGnssNavigationMessage->close(); 45 return checkAidlStatus(status, "IGnssNavigationMessageAidl close() failed"); 46 } 47 48 // Implementation of GnssNavigationMessageHidl 49 GnssNavigationMessageHidl(const sp<IGnssNavigationMessageHidl> & iGnssNavigationMessage)50GnssNavigationMessageHidl::GnssNavigationMessageHidl( 51 const sp<IGnssNavigationMessageHidl>& iGnssNavigationMessage) 52 : mIGnssNavigationMessageHidl(iGnssNavigationMessage) { 53 assert(mIGnssNavigationMessageHidl != nullptr); 54 } 55 setCallback(const std::unique_ptr<GnssNavigationMessageCallback> & callback)56jboolean GnssNavigationMessageHidl::setCallback( 57 const std::unique_ptr<GnssNavigationMessageCallback>& callback) { 58 auto result = mIGnssNavigationMessageHidl->setCallback(callback->getHidl()); 59 60 IGnssNavigationMessageHidl::GnssNavigationMessageStatus initRet = result; 61 if (initRet != IGnssNavigationMessageHidl::GnssNavigationMessageStatus::SUCCESS) { 62 ALOGE("An error has been found in %s: %d", __FUNCTION__, static_cast<int32_t>(initRet)); 63 return JNI_FALSE; 64 } 65 return JNI_TRUE; 66 } 67 close()68jboolean GnssNavigationMessageHidl::close() { 69 auto result = mIGnssNavigationMessageHidl->close(); 70 return checkHidlReturn(result, "IGnssNavigationMessage close() failed."); 71 } 72 73 } // namespace android::gnss 74