service.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2017-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 "[email protected]"
  21. #include <android/hardware/gnss/2.1/IGnss.h>
  22. #include <hidl/LegacySupport.h>
  23. #include "loc_cfg.h"
  24. #include "loc_misc_utils.h"
  25. #include <dlfcn.h>
  26. extern "C" {
  27. #include "vndfwk-detect.h"
  28. }
  29. #ifdef ARCH_ARM_32
  30. #define DEFAULT_HW_BINDER_MEM_SIZE 65536
  31. #endif
  32. using android::hardware::gnss::V2_1::IGnss;
  33. using android::hardware::configureRpcThreadpool;
  34. using android::hardware::registerPassthroughServiceImplementation;
  35. using android::hardware::joinRpcThreadpool;
  36. using android::status_t;
  37. using android::OK;
  38. typedef int vendorEnhancedServiceMain(int /* argc */, char* /* argv */ []);
  39. #define GNSS_POWER_LIBNAME "/vendor/lib64/libgnssauto_power.so"
  40. typedef const void* (*gnssAutoPowerHandler)(void);
  41. void initializeGnssPowerHandler() {
  42. void * handle = nullptr;
  43. const char* error = nullptr;
  44. gnssAutoPowerHandler getter = nullptr;
  45. getter = (gnssAutoPowerHandler) dlGetSymFromLib(handle, GNSS_POWER_LIBNAME,
  46. "initGnssAutoPowerHandler");
  47. if (nullptr == getter) {
  48. /*may not be real problem for non-automotive products*/
  49. ALOGW("dlGetSymFromLib for getGnssAutoPowerHandler failed - may not be real problem.");
  50. } else {
  51. /*Initialize GnssAutoPowerHandler if available*/
  52. getter();
  53. ALOGI("GnssAutoPowerHandler Initialized!");
  54. }
  55. }
  56. int main() {
  57. ALOGI("%s", __FUNCTION__);
  58. int vendorInfo = getVendorEnhancedInfo();
  59. /* The magic number 2 points to
  60. #define VND_ENHANCED_SYS_STATUS_BIT 0x02 in vndfwk-detect.c */
  61. bool vendorEnhanced = ( vendorInfo & 2 );
  62. setVendorEnhanced(vendorEnhanced);
  63. #ifdef ARCH_ARM_32
  64. android::hardware::ProcessState::initWithMmapSize((size_t)(DEFAULT_HW_BINDER_MEM_SIZE));
  65. #endif
  66. configureRpcThreadpool(1, true);
  67. status_t status;
  68. status = registerPassthroughServiceImplementation<IGnss>();
  69. if (status == OK) {
  70. initializeGnssPowerHandler();
  71. joinRpcThreadpool();
  72. } else {
  73. ALOGE("Error while registering IGnss 2.1 service: %d", status);
  74. }
  75. return 0;
  76. }