1 /*
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_GnssConfigurationInterface"
18
19 #include <log/log.h>
20
21 #include "GnssConfiguration.h"
22
23 namespace android {
24 namespace hardware {
25 namespace gnss {
26 namespace V1_0 {
27 namespace implementation {
28
GnssConfiguration(const GnssConfigurationInterface * gnssConfigInfc)29 GnssConfiguration::GnssConfiguration(const GnssConfigurationInterface* gnssConfigInfc)
30 : mGnssConfigIface(gnssConfigInfc) {}
31
32 // Methods from ::android::hardware::gps::V1_0::IGnssConfiguration follow.
setSuplEs(bool enabled)33 Return<bool> GnssConfiguration::setSuplEs(bool enabled) {
34 if (mGnssConfigIface == nullptr) {
35 ALOGE("%s: GNSS Configuration interface is not available.", __func__);
36 return false;
37 }
38
39 std::string config = "SUPL_ES=" + std::to_string(enabled ? 1 : 0) + "\n";
40 mGnssConfigIface->configuration_update(config.c_str(), config.size());
41 return true;
42 }
43
setSuplVersion(uint32_t version)44 Return<bool> GnssConfiguration::setSuplVersion(uint32_t version) {
45 if (mGnssConfigIface == nullptr) {
46 ALOGE("%s: GNSS Configuration interface is not available.", __func__);
47 return false;
48 }
49
50 std::string config = "SUPL_VER=" + std::to_string(version) + "\n";
51 mGnssConfigIface->configuration_update(config.c_str(), config.size());
52
53 return true;
54 }
55
setSuplMode(uint8_t mode)56 Return<bool> GnssConfiguration::setSuplMode(uint8_t mode) {
57 if (mGnssConfigIface == nullptr) {
58 ALOGE("%s: GNSS Configuration interface is not available.", __func__);
59 return false;
60 }
61
62 std::string config = "SUPL_MODE=" + std::to_string(mode) + "\n";
63 mGnssConfigIface->configuration_update(config.c_str(), config.size());
64 return true;
65 }
66
setLppProfile(uint8_t lppProfile)67 Return<bool> GnssConfiguration::setLppProfile(uint8_t lppProfile) {
68 if (mGnssConfigIface == nullptr) {
69 ALOGE("%s: GNSS Configuration interface is not available.", __func__);
70 return false;
71 }
72
73 std::string config = "LPP_PROFILE=" + std::to_string(lppProfile) + "\n";
74 mGnssConfigIface->configuration_update(config.c_str(), config.size());
75 return true;
76 }
77
setGlonassPositioningProtocol(uint8_t protocol)78 Return<bool> GnssConfiguration::setGlonassPositioningProtocol(uint8_t protocol) {
79 if (mGnssConfigIface == nullptr) {
80 ALOGE("%s: GNSS Configuration interface is not available.", __func__);
81 return false;
82 }
83
84 std::string config = "A_GLONASS_POS_PROTOCOL_SELECT=" +
85 std::to_string(protocol) + "\n";
86 mGnssConfigIface->configuration_update(config.c_str(), config.size());
87 return true;
88 }
89
setGpsLock(uint8_t lock)90 Return<bool> GnssConfiguration::setGpsLock(uint8_t lock) {
91 if (mGnssConfigIface == nullptr) {
92 ALOGE("%s: GNSS Configuration interface is not available.", __func__);
93 return false;
94 }
95
96 std::string config = "GPS_LOCK=" + std::to_string(lock) + "\n";
97 mGnssConfigIface->configuration_update(config.c_str(), config.size());
98 return true;
99 }
100
setEmergencySuplPdn(bool enabled)101 Return<bool> GnssConfiguration::setEmergencySuplPdn(bool enabled) {
102 if (mGnssConfigIface == nullptr) {
103 ALOGE("%s: GNSS Configuration interface is not available.", __func__);
104 return false;
105 }
106
107 std::string config = "USE_EMERGENCY_PDN_FOR_EMERGENCY_SUPL=" + std::to_string(enabled ? 1 : 0)
108 + "\n";
109 mGnssConfigIface->configuration_update(config.c_str(), config.size());
110 return true;
111 }
112
113 } // namespace implementation
114 } // namespace V1_0
115 } // namespace gnss
116 } // namespace hardware
117 } // namespace android
118