blob: 87abad72e9d55a63cd396a624437f9cafd4fa5fb [file] [log] [blame]
Hridya Valsaraju29dc1e02016-10-21 14:41:12 -07001/*
2 * Copyright (C) 2016 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 "GnssHAL_AGnssRilInterface"
18
19#include "AGnssRil.h"
20
21namespace android {
22namespace hardware {
23namespace gnss {
24namespace V1_0 {
25namespace implementation {
26
27std::vector<std::unique_ptr<ThreadFuncArgs>> AGnssRil::sThreadFuncArgsList;
28sp<IAGnssRilCallback> AGnssRil::sAGnssRilCbIface = nullptr;
29bool AGnssRil::sInterfaceExists = false;
30
31AGpsRilCallbacks AGnssRil::sAGnssRilCb = {
32 .request_setid = AGnssRil::requestSetId,
33 .request_refloc = AGnssRil::requestRefLoc,
34 .create_thread_cb = AGnssRil::createThreadCb
35};
36
37AGnssRil::AGnssRil(const AGpsRilInterface* aGpsRilIface) : mAGnssRilIface(aGpsRilIface) {
38 /* Error out if an instance of the interface already exists. */
39 LOG_ALWAYS_FATAL_IF(sInterfaceExists);
40 sInterfaceExists = true;
41}
42
43AGnssRil::~AGnssRil() {
44 sThreadFuncArgsList.clear();
45}
46
47void AGnssRil::requestSetId(uint32_t flags) {
48 if (sAGnssRilCbIface == nullptr) {
49 ALOGE("%s: AGNSSRil Callback Interface configured incorrectly", __func__);
50 return;
51 }
52
53 sAGnssRilCbIface->requestSetIdCb(static_cast<IAGnssRilCallback::ID>(flags));
54}
55
56void AGnssRil::requestRefLoc(uint32_t /*flags*/) {
57 if (sAGnssRilCbIface == nullptr) {
58 ALOGE("%s: AGNSSRil Callback Interface configured incorrectly", __func__);
59 return;
60 }
61
62 sAGnssRilCbIface->requestRefLocCb();
63}
64
65pthread_t AGnssRil::createThreadCb(const char* name, void (*start)(void*), void* arg) {
66 return createPthread(name, start, arg, &sThreadFuncArgsList);
67}
68
69// Methods from ::android::hardware::gnss::V1_0::IAGnssRil follow.
70Return<void> AGnssRil::setCallback(const sp<IAGnssRilCallback>& callback) {
71 if (mAGnssRilIface == nullptr) {
72 ALOGE("%s: AGnssRil interface is unavailable", __func__);
73 return Void();
74 }
75
76 sAGnssRilCbIface = callback;
77
78 mAGnssRilIface->init(&sAGnssRilCb);
79 return Void();
80}
81
82Return<void> AGnssRil::setRefLocation(const IAGnssRil::AGnssRefLocation& aGnssRefLocation) {
83 if (mAGnssRilIface == nullptr) {
84 ALOGE("%s: AGnssRil interface is unavailable", __func__);
85 return Void();
86 }
87
88 AGpsRefLocation aGnssRefloc;
89 aGnssRefloc.type = static_cast<uint16_t>(aGnssRefLocation.type);
90
91 auto& cellID = aGnssRefLocation.cellID;
92 aGnssRefloc.u.cellID = {
93 .type = static_cast<uint16_t>(cellID.type),
94 .mcc = cellID.mcc,
95 .mnc = cellID.mnc,
96 .lac = cellID.lac,
97 .cid = cellID.cid,
98 .tac = cellID.tac,
99 .pcid = cellID.pcid
100 };
101
102 mAGnssRilIface->set_ref_location(&aGnssRefloc, sizeof(aGnssRefloc));
103 return Void();
104}
105
106Return<bool> AGnssRil::setSetId(IAGnssRil::SetIDType type, const hidl_string& setid) {
107 if (mAGnssRilIface == nullptr) {
108 ALOGE("%s: AGnssRil interface is unavailable", __func__);
109 return false;
110 }
111
112 mAGnssRilIface->set_set_id(static_cast<uint16_t>(type), setid.c_str());
113 return true;
114}
115
116Return<bool> AGnssRil::updateNetworkState(bool connected,
117 IAGnssRil::NetworkType type,
118 bool roaming) {
119 if (mAGnssRilIface == nullptr) {
120 ALOGE("%s: AGnssRil interface is unavailable", __func__);
121 return false;
122 }
123
124 mAGnssRilIface->update_network_state(connected,
125 static_cast<int>(type),
126 roaming,
127 nullptr /* extra_info */);
128 return true;
129}
130
131Return<bool> AGnssRil::updateNetworkAvailability(bool available, const hidl_string& apn) {
132 if (mAGnssRilIface == nullptr) {
133 ALOGE("%s: AGnssRil interface is unavailable", __func__);
134 return false;
135 }
136
137 mAGnssRilIface->update_network_availability(available, apn.c_str());
138 return true;
139}
140
141} // namespace implementation
142} // namespace V1_0
143} // namespace gnss
144} // namespace hardware
145} // namespace android