blob: 4f35a4932918b4500d63cb8e99abdaeffdc325b7 [file] [log] [blame]
Michael Bestas3a0209e2023-05-04 01:15:47 +03001/*
2 * Copyright (c) 2017-2018, 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
Michael Bestas222c86c2024-07-18 12:36:55 -040021/* ​​​​​Changes from Qualcomm Innovation Center are provided under the following license:
22 * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
23 * SPDX-License-Identifier: BSD-3-Clause-Clear
24 */
25
Michael Bestas3a0209e2023-05-04 01:15:47 +030026#define LOG_TAG "LocSvc_GnssMeasurementInterface"
27
28#include <log_util.h>
Michael Bestas3a0209e2023-05-04 01:15:47 +030029#include "GnssMeasurement.h"
30
31namespace android {
32namespace hardware {
33namespace gnss {
34namespace V1_1 {
35namespace implementation {
36
37void GnssMeasurement::GnssMeasurementDeathRecipient::serviceDied(
38 uint64_t cookie, const wp<IBase>& who) {
39 LOC_LOGE("%s] service died. cookie: %llu, who: %p",
40 __FUNCTION__, static_cast<unsigned long long>(cookie), &who);
41 if (mGnssMeasurement != nullptr) {
42 mGnssMeasurement->close();
43 }
44}
45
46GnssMeasurement::GnssMeasurement() {
47 mGnssMeasurementDeathRecipient = new GnssMeasurementDeathRecipient(this);
48 mApi = new MeasurementAPIClient();
49}
50
51GnssMeasurement::~GnssMeasurement() {
52 if (mApi) {
53 mApi->destroy();
54 mApi = nullptr;
55 }
56}
57
58// Methods from ::android::hardware::gnss::V1_0::IGnssMeasurement follow.
Michael Bestas222c86c2024-07-18 12:36:55 -040059Return<GnssMeasurement::GnssMeasurementStatus> GnssMeasurement::setCallback(
Michael Bestas3a0209e2023-05-04 01:15:47 +030060 const sp<V1_0::IGnssMeasurementCallback>& callback) {
Michael Bestas222c86c2024-07-18 12:36:55 -040061 return setCallback(callback, mGnssMeasurementCbIface, GNSS_POWER_MODE_INVALID);
62}
Michael Bestas3a0209e2023-05-04 01:15:47 +030063
Michael Bestas222c86c2024-07-18 12:36:55 -040064template <typename T>
65Return<IGnssMeasurement::GnssMeasurementStatus> GnssMeasurement::setCallback(
66 const sp<T>& callback, sp<T>& myCallback, GnssPowerMode powerMode) {
67 Return<GnssMeasurement::GnssMeasurementStatus> ret =
68 IGnssMeasurement::GnssMeasurementStatus::ERROR_GENERIC;
Michael Bestas3a0209e2023-05-04 01:15:47 +030069 if (mApi == nullptr) {
70 LOC_LOGE("%s]: mApi is nullptr", __FUNCTION__);
71 return ret;
72 }
Michael Bestas222c86c2024-07-18 12:36:55 -040073 if (myCallback != callback) {
74 if (nullptr == callback) {
75 LOC_LOGE("%s]: callback is nullptr", __FUNCTION__);
76 mApi->measurementSetCallback(callback);
77 close();
78 } else {
79 if (nullptr != myCallback) {
80 myCallback->unlinkToDeath(mGnssMeasurementDeathRecipient);
81 }
82 myCallback = callback;
83 myCallback->linkToDeath(mGnssMeasurementDeathRecipient, 0);
84 ret = mApi->measurementSetCallback(callback, powerMode);
85 }
86 }
Michael Bestas3a0209e2023-05-04 01:15:47 +030087
Michael Bestas222c86c2024-07-18 12:36:55 -040088 return ret;
Michael Bestas3a0209e2023-05-04 01:15:47 +030089}
90
91Return<void> GnssMeasurement::close() {
Michael Bestas222c86c2024-07-18 12:36:55 -040092 if (mApi != nullptr) {
93 mApi->measurementSetCallback<V1_0::IGnssMeasurementCallback>(nullptr);
94 mApi->measurementSetCallback<V1_1::IGnssMeasurementCallback>(nullptr);
Michael Bestas3a0209e2023-05-04 01:15:47 +030095 }
96
97 if (mGnssMeasurementCbIface != nullptr) {
98 mGnssMeasurementCbIface->unlinkToDeath(mGnssMeasurementDeathRecipient);
99 mGnssMeasurementCbIface = nullptr;
100 }
101 if (mGnssMeasurementCbIface_1_1 != nullptr) {
102 mGnssMeasurementCbIface_1_1->unlinkToDeath(mGnssMeasurementDeathRecipient);
103 mGnssMeasurementCbIface_1_1 = nullptr;
104 }
Michael Bestas3a0209e2023-05-04 01:15:47 +0300105
106 return Void();
107}
108
109// Methods from ::android::hardware::gnss::V1_1::IGnssMeasurement follow.
110Return<GnssMeasurement::GnssMeasurementStatus> GnssMeasurement::setCallback_1_1(
111 const sp<IGnssMeasurementCallback>& callback, bool enableFullTracking) {
Michael Bestas222c86c2024-07-18 12:36:55 -0400112 return setCallback(callback, mGnssMeasurementCbIface_1_1,
113 enableFullTracking ? GNSS_POWER_MODE_M1 : GNSS_POWER_MODE_M2);
Michael Bestas3a0209e2023-05-04 01:15:47 +0300114}
115
116} // namespace implementation
117} // namespace V1_1
118} // namespace gnss
119} // namespace hardware
120} // namespace android