1 /* 2 * Copyright (c) 2017, The Linux Foundation. All rights reserved. 3 * Not a Contribution 4 */ 5 /* 6 * Copyright (C) 2016 The Android Open Source Project 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 #define LOG_TAG "LocSvc_GnssNiInterface" 22 23 #include <log_util.h> 24 #include "Gnss.h" 25 #include "GnssNi.h" 26 27 namespace android { 28 namespace hardware { 29 namespace gnss { 30 namespace V1_0 { 31 namespace implementation { 32 33 void GnssNi::GnssNiDeathRecipient::serviceDied(uint64_t cookie, const wp<IBase>& who) { 34 LOC_LOGE("%s] service died. cookie: %llu, who: %p", 35 __FUNCTION__, static_cast<unsigned long long>(cookie), &who); 36 // we do nothing here 37 // Gnss::GnssDeathRecipient will stop the session 38 } 39 40 GnssNi::GnssNi(Gnss* gnss) : mGnss(gnss) { 41 mGnssNiDeathRecipient = new GnssNiDeathRecipient(this); 42 } 43 44 // Methods from ::android::hardware::gnss::V1_0::IGnssNi follow. 45 Return<void> GnssNi::setCallback(const sp<IGnssNiCallback>& callback) { 46 if (mGnss == nullptr) { 47 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); 48 return Void(); 49 } 50 51 mGnss->setGnssNiCb(callback); 52 53 if (mGnssNiCbIface != nullptr) { 54 mGnssNiCbIface->unlinkToDeath(mGnssNiDeathRecipient); 55 } 56 mGnssNiCbIface = callback; 57 if (mGnssNiCbIface != nullptr) { 58 mGnssNiCbIface->linkToDeath(mGnssNiDeathRecipient, 0 /*cookie*/); 59 } 60 61 return Void(); 62 } 63 64 Return<void> GnssNi::respond(int32_t notifId, IGnssNiCallback::GnssUserResponseType userResponse) { 65 if (mGnss == nullptr) { 66 LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__); 67 return Void(); 68 } 69 70 GnssAPIClient* api = mGnss->getApi(); 71 if (api == nullptr) { 72 LOC_LOGE("%s]: api is nullptr", __FUNCTION__); 73 return Void(); 74 } 75 76 api->gnssNiRespond(notifId, userResponse); 77 78 return Void(); 79 } 80 81 } // namespace implementation 82 } // namespace V1_0 83 } // namespace gnss 84 } // namespace hardware 85 } // namespace android 86