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 "GnssAntennaInfoJni"
19
20 #include "GnssAntennaInfo.h"
21
22 #include "Utils.h"
23
24 using IGnssAntennaInfoAidl = android::hardware::gnss::IGnssAntennaInfo;
25 using IGnssAntennaInfo_V2_1 = android::hardware::gnss::V2_1::IGnssAntennaInfo;
26
27 namespace android::gnss {
28
29 // Implementation of GnssAntennaInfo (AIDL HAL)
30
GnssAntennaInfoAidl(const sp<IGnssAntennaInfoAidl> & iGnssAntennaInfo)31 GnssAntennaInfoAidl::GnssAntennaInfoAidl(const sp<IGnssAntennaInfoAidl>& iGnssAntennaInfo)
32 : mIGnssAntennaInfoAidl(iGnssAntennaInfo) {
33 assert(mIGnssAntennaInfoAidl != nullptr);
34 }
35
setCallback(const std::unique_ptr<GnssAntennaInfoCallback> & callback)36 jboolean GnssAntennaInfoAidl::setCallback(
37 const std::unique_ptr<GnssAntennaInfoCallback>& callback) {
38 auto status = mIGnssAntennaInfoAidl->setCallback(callback->getAidl());
39 return checkAidlStatus(status, "IGnssAntennaInfoAidl setCallback() failed.");
40 }
41
close()42 jboolean GnssAntennaInfoAidl::close() {
43 auto status = mIGnssAntennaInfoAidl->close();
44 return checkAidlStatus(status, "IGnssAntennaInfoAidl close() failed");
45 }
46
47 // Implementation of GnssAntennaInfo_V2_1
48
GnssAntennaInfo_V2_1(const sp<IGnssAntennaInfo_V2_1> & iGnssAntennaInfo)49 GnssAntennaInfo_V2_1::GnssAntennaInfo_V2_1(const sp<IGnssAntennaInfo_V2_1>& iGnssAntennaInfo)
50 : mIGnssAntennaInfo_V2_1(iGnssAntennaInfo) {
51 assert(mIGnssAntennaInfo_V2_1 != nullptr);
52 }
53
setCallback(const std::unique_ptr<GnssAntennaInfoCallback> & callback)54 jboolean GnssAntennaInfo_V2_1::setCallback(
55 const std::unique_ptr<GnssAntennaInfoCallback>& callback) {
56 auto result = mIGnssAntennaInfo_V2_1->setCallback(callback->getV2_1());
57 if (!checkHidlReturn(result, "IGnssAntennaInfo_V2_1 setCallback() failed.")) {
58 return JNI_FALSE;
59 }
60
61 IGnssAntennaInfo_V2_1::GnssAntennaInfoStatus initRet = result;
62 if (initRet != IGnssAntennaInfo_V2_1::GnssAntennaInfoStatus::SUCCESS) {
63 ALOGE("An error has been found on GnssAntennaInfoInterface::init, status=%d",
64 static_cast<int32_t>(initRet));
65 return JNI_FALSE;
66 } else {
67 ALOGD("gnss antenna info v2_1 has been enabled");
68 }
69 return JNI_TRUE;
70 }
71
close()72 jboolean GnssAntennaInfo_V2_1::close() {
73 auto result = mIGnssAntennaInfo_V2_1->close();
74 return checkHidlReturn(result, "IGnssAntennaInfo_V2_1 close() failed.");
75 }
76
77 } // namespace android::gnss
78