1 /*
2  * Copyright (C) 2020 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 "GnssAidl"
18 
19 #include "Gnss.h"
20 #include <log/log.h>
21 #include "GnssConfiguration.h"
22 #include "GnssMeasurementInterface.h"
23 #include "GnssPsds.h"
24 
25 namespace aidl::android::hardware::gnss {
26 
27 std::shared_ptr<IGnssCallback> Gnss::sGnssCallback = nullptr;
28 
setCallback(const std::shared_ptr<IGnssCallback> & callback)29 ndk::ScopedAStatus Gnss::setCallback(const std::shared_ptr<IGnssCallback>& callback) {
30     ALOGD("Gnss::setCallback");
31     if (callback == nullptr) {
32         ALOGE("%s: Null callback ignored", __func__);
33         return ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
34     }
35 
36     sGnssCallback = callback;
37 
38     int capabilities = (int)(IGnssCallback::CAPABILITY_SATELLITE_BLOCKLIST |
39                              IGnssCallback::CAPABILITY_SATELLITE_PVT |
40                              IGnssCallback::CAPABILITY_CORRELATION_VECTOR);
41 
42     auto status = sGnssCallback->gnssSetCapabilitiesCb(capabilities);
43     if (!status.isOk()) {
44         ALOGE("%s: Unable to invoke callback.gnssSetCapabilities", __func__);
45     }
46 
47     return ndk::ScopedAStatus::ok();
48 }
49 
close()50 ndk::ScopedAStatus Gnss::close() {
51     ALOGD("Gnss::close");
52     sGnssCallback = nullptr;
53     return ndk::ScopedAStatus::ok();
54 }
55 
getExtensionPsds(std::shared_ptr<IGnssPsds> * iGnssPsds)56 ndk::ScopedAStatus Gnss::getExtensionPsds(std::shared_ptr<IGnssPsds>* iGnssPsds) {
57     ALOGD("Gnss::getExtensionPsds");
58     *iGnssPsds = SharedRefBase::make<GnssPsds>();
59     return ndk::ScopedAStatus::ok();
60 }
61 
getExtensionGnssConfiguration(std::shared_ptr<IGnssConfiguration> * iGnssConfiguration)62 ndk::ScopedAStatus Gnss::getExtensionGnssConfiguration(
63         std::shared_ptr<IGnssConfiguration>* iGnssConfiguration) {
64     ALOGD("Gnss::getExtensionGnssConfiguration");
65     if (mGnssConfiguration == nullptr) {
66         mGnssConfiguration = SharedRefBase::make<GnssConfiguration>();
67     }
68     *iGnssConfiguration = mGnssConfiguration;
69     return ndk::ScopedAStatus::ok();
70 }
71 
getExtensionGnssPowerIndication(std::shared_ptr<IGnssPowerIndication> * iGnssPowerIndication)72 ndk::ScopedAStatus Gnss::getExtensionGnssPowerIndication(
73         std::shared_ptr<IGnssPowerIndication>* iGnssPowerIndication) {
74     ALOGD("Gnss::getExtensionGnssPowerIndication");
75     if (mGnssPowerIndication == nullptr) {
76         mGnssPowerIndication = SharedRefBase::make<GnssPowerIndication>();
77     }
78 
79     *iGnssPowerIndication = mGnssPowerIndication;
80     return ndk::ScopedAStatus::ok();
81 }
82 
getExtensionGnssMeasurement(std::shared_ptr<IGnssMeasurementInterface> * iGnssMeasurement)83 ndk::ScopedAStatus Gnss::getExtensionGnssMeasurement(
84         std::shared_ptr<IGnssMeasurementInterface>* iGnssMeasurement) {
85     ALOGD("Gnss::getExtensionGnssMeasurement");
86 
87     *iGnssMeasurement = SharedRefBase::make<GnssMeasurementInterface>();
88     return ndk::ScopedAStatus::ok();
89 }
90 
91 }  // namespace aidl::android::hardware::gnss
92