GnssConfiguration.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (c) 2017-2018, 2021, 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. #define LOG_TAG "LocSvc_GnssConfigurationInterface"
  21. #include <log_util.h>
  22. #include "Gnss.h"
  23. #include "GnssConfiguration.h"
  24. #include <android/hardware/gnss/1.0/types.h>
  25. namespace android {
  26. namespace hardware {
  27. namespace gnss {
  28. namespace V1_0 {
  29. namespace implementation {
  30. using ::android::hardware::gnss::V1_0::GnssConstellationType;
  31. GnssConfiguration::GnssConfiguration(Gnss* gnss) : mGnss(gnss) {
  32. }
  33. // Methods from ::android::hardware::gps::V1_0::IGnssConfiguration follow.
  34. Return<bool> GnssConfiguration::setSuplEs(bool enabled) {
  35. if (mGnss == nullptr) {
  36. LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
  37. return false;
  38. }
  39. GnssConfig config;
  40. memset(&config, 0, sizeof(GnssConfig));
  41. config.size = sizeof(GnssConfig);
  42. config.flags = GNSS_CONFIG_FLAGS_SUPL_EM_SERVICES_BIT;
  43. config.suplEmergencyServices = (enabled ?
  44. GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_YES :
  45. GNSS_CONFIG_SUPL_EMERGENCY_SERVICES_NO);
  46. return mGnss->updateConfiguration(config);
  47. }
  48. Return<bool> GnssConfiguration::setSuplVersion(uint32_t version) {
  49. if (mGnss == nullptr) {
  50. LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
  51. return false;
  52. }
  53. GnssConfig config;
  54. memset(&config, 0, sizeof(GnssConfig));
  55. config.size = sizeof(GnssConfig);
  56. config.flags = GNSS_CONFIG_FLAGS_SUPL_VERSION_VALID_BIT;
  57. switch (version) {
  58. case 0x00020004:
  59. config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_4;
  60. break;
  61. case 0x00020002:
  62. config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_2;
  63. break;
  64. case 0x00020000:
  65. config.suplVersion = GNSS_CONFIG_SUPL_VERSION_2_0_0;
  66. break;
  67. case 0x00010000:
  68. config.suplVersion = GNSS_CONFIG_SUPL_VERSION_1_0_0;
  69. break;
  70. default:
  71. LOC_LOGE("%s]: invalid version: 0x%x.", __FUNCTION__, version);
  72. return false;
  73. }
  74. return mGnss->updateConfiguration(config);
  75. }
  76. Return<bool> GnssConfiguration::setSuplMode(uint8_t mode) {
  77. if (mGnss == nullptr) {
  78. LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
  79. return false;
  80. }
  81. GnssConfig config;
  82. memset(&config, 0, sizeof(GnssConfig));
  83. config.size = sizeof(GnssConfig);
  84. config.flags = GNSS_CONFIG_FLAGS_SUPL_MODE_BIT;
  85. switch (mode) {
  86. case 0:
  87. config.suplModeMask = 0; // STANDALONE ONLY
  88. break;
  89. case 1:
  90. config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT;
  91. break;
  92. case 2:
  93. config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSA_BIT;
  94. break;
  95. case 3:
  96. config.suplModeMask = GNSS_CONFIG_SUPL_MODE_MSB_BIT | GNSS_CONFIG_SUPL_MODE_MSA_BIT;
  97. break;
  98. default:
  99. LOC_LOGE("%s]: invalid mode: %d.", __FUNCTION__, mode);
  100. return false;
  101. }
  102. return mGnss->updateConfiguration(config);
  103. }
  104. Return<bool> GnssConfiguration::setLppProfile(uint8_t lppProfileMask) {
  105. if (mGnss == nullptr) {
  106. LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
  107. return false;
  108. }
  109. GnssConfig config = {};
  110. config.size = sizeof(GnssConfig);
  111. config.flags = GNSS_CONFIG_FLAGS_LPP_PROFILE_VALID_BIT;
  112. config.lppProfileMask = GNSS_CONFIG_LPP_PROFILE_RRLP_ON_LTE; //default
  113. if (lppProfileMask & (1<<0)) {
  114. config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_BIT;
  115. }
  116. if (lppProfileMask & (1<<1)) {
  117. config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_BIT;
  118. }
  119. if (lppProfileMask & (1<<2)) {
  120. config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_USER_PLANE_OVER_NR5G_SA_BIT;
  121. }
  122. if (lppProfileMask & (1<<3)) {
  123. config.lppProfileMask |= GNSS_CONFIG_LPP_PROFILE_CONTROL_PLANE_OVER_NR5G_SA_BIT;
  124. }
  125. return mGnss->updateConfiguration(config);
  126. }
  127. Return<bool> GnssConfiguration::setGlonassPositioningProtocol(uint8_t protocol) {
  128. if (mGnss == nullptr) {
  129. LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
  130. return false;
  131. }
  132. GnssConfig config;
  133. memset(&config, 0, sizeof(GnssConfig));
  134. config.size = sizeof(GnssConfig);
  135. config.flags = GNSS_CONFIG_FLAGS_AGLONASS_POSITION_PROTOCOL_VALID_BIT;
  136. if (protocol & (1<<0)) {
  137. config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRC_CONTROL_PLANE_BIT;
  138. }
  139. if (protocol & (1<<1)) {
  140. config.aGlonassPositionProtocolMask |= GNSS_CONFIG_RRLP_USER_PLANE_BIT;
  141. }
  142. if (protocol & (1<<2)) {
  143. config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_USER_PLANE_BIT;
  144. }
  145. if (protocol & (1<<3)) {
  146. config.aGlonassPositionProtocolMask |= GNSS_CONFIG_LLP_CONTROL_PLANE_BIT;
  147. }
  148. return mGnss->updateConfiguration(config);
  149. }
  150. Return<bool> GnssConfiguration::setGpsLock(uint8_t lock) {
  151. if (mGnss == nullptr) {
  152. LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
  153. return false;
  154. }
  155. GnssConfig config;
  156. memset(&config, 0, sizeof(GnssConfig));
  157. config.size = sizeof(GnssConfig);
  158. config.flags = GNSS_CONFIG_FLAGS_GPS_LOCK_VALID_BIT;
  159. switch (lock) {
  160. case 0:
  161. config.gpsLock = GNSS_CONFIG_GPS_LOCK_NONE;
  162. break;
  163. case 1:
  164. config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO;
  165. break;
  166. case 2:
  167. config.gpsLock = GNSS_CONFIG_GPS_LOCK_NFW_ALL;
  168. break;
  169. case 3:
  170. config.gpsLock = GNSS_CONFIG_GPS_LOCK_MO_AND_NI;
  171. break;
  172. default:
  173. LOC_LOGE("%s]: invalid lock: %d.", __FUNCTION__, lock);
  174. return false;
  175. }
  176. return mGnss->updateConfiguration(config);
  177. }
  178. Return<bool> GnssConfiguration::setEmergencySuplPdn(bool enabled) {
  179. if (mGnss == nullptr) {
  180. LOC_LOGE("%s]: mGnss is nullptr", __FUNCTION__);
  181. return false;
  182. }
  183. GnssConfig config;
  184. memset(&config, 0, sizeof(GnssConfig));
  185. config.size = sizeof(GnssConfig);
  186. config.flags = GNSS_CONFIG_FLAGS_EM_PDN_FOR_EM_SUPL_VALID_BIT;
  187. config.emergencyPdnForEmergencySupl = (enabled ?
  188. GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_YES :
  189. GNSS_CONFIG_EMERGENCY_PDN_FOR_EMERGENCY_SUPL_NO);
  190. return mGnss->updateConfiguration(config);
  191. }
  192. } // namespace implementation
  193. } // namespace V1_0
  194. } // namespace gnss
  195. } // namespace hardware
  196. } // namespace android