service.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 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. #include <aidl/android/hardware/gnss/IGnss.h>
  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 <android/binder_manager.h>
  26. #include <android/binder_process.h>
  27. #include "Gnss.h"
  28. #include <pthread.h>
  29. #include <log_util.h>
  30. extern "C" {
  31. #include "vndfwk-detect.h"
  32. }
  33. #ifdef LOG_TAG
  34. #undef LOG_TAG
  35. #endif
  36. #define LOG_TAG "android.hardware.gnss-aidl-impl-qti"
  37. #ifdef ARCH_ARM_32
  38. #define DEFAULT_HW_BINDER_MEM_SIZE 65536
  39. #endif
  40. using android::hardware::configureRpcThreadpool;
  41. using android::hardware::registerPassthroughServiceImplementation;
  42. using android::hardware::joinRpcThreadpool;
  43. using ::android::sp;
  44. using android::status_t;
  45. using android::OK;
  46. typedef int vendorEnhancedServiceMain(int /* argc */, char* /* argv */ []);
  47. using GnssAidl = ::android::hardware::gnss::aidl::implementation::Gnss;
  48. using ::android::hardware::gnss::V1_0::GnssLocation;
  49. using android::hardware::gnss::V2_1::IGnss;
  50. int main() {
  51. ABinderProcess_setThreadPoolMaxThreadCount(1);
  52. ABinderProcess_startThreadPool();
  53. ALOGI("%s, start Gnss HAL process", __FUNCTION__);
  54. std::shared_ptr<GnssAidl> gnssAidl = ndk::SharedRefBase::make<GnssAidl>();
  55. const std::string instance = std::string() + GnssAidl::descriptor + "/default";
  56. if (gnssAidl != nullptr) {
  57. binder_status_t status =
  58. AServiceManager_addService(gnssAidl->asBinder().get(), instance.c_str());
  59. if (STATUS_OK == status) {
  60. ALOGD("register IGnss AIDL service success");
  61. } else {
  62. ALOGD("Error while register IGnss AIDL service, status: %d", status);
  63. }
  64. }
  65. int vendorInfo = getVendorEnhancedInfo();
  66. // The magic number 2 points to
  67. // #define VND_ENHANCED_SYS_STATUS_BIT 0x02 in vndfwk-detect.c
  68. bool vendorEnhanced = ( vendorInfo & 2 );
  69. setVendorEnhanced(vendorEnhanced);
  70. #ifdef ARCH_ARM_32
  71. android::hardware::ProcessState::initWithMmapSize((size_t)(DEFAULT_HW_BINDER_MEM_SIZE));
  72. #endif
  73. configureRpcThreadpool(1, true);
  74. status_t ret;
  75. ret = registerPassthroughServiceImplementation<IGnss>();
  76. if (ret == OK) {
  77. // Loc AIDL service
  78. #define VENDOR_AIDL_LIB "vendor.qti.gnss-service.so"
  79. void* libAidlHandle = NULL;
  80. vendorEnhancedServiceMain* aidlMainMethod = (vendorEnhancedServiceMain*)
  81. dlGetSymFromLib(libAidlHandle, VENDOR_AIDL_LIB, "main");
  82. if (NULL != aidlMainMethod) {
  83. ALOGI("start LocAidl service");
  84. (*aidlMainMethod)(0, NULL);
  85. }
  86. // Loc AIDL service end
  87. joinRpcThreadpool();
  88. ABinderProcess_joinThreadPool();
  89. } else {
  90. ALOGE("Error while registering IGnss HIDL 2.1 service: %d", ret);
  91. }
  92. return EXIT_FAILURE; // should not reach
  93. }