GnssAutoPowerHandler.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2021 The Linux Foundation. All rights reserved.
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are
  5. * met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above
  9. * copyright notice, this list of conditions and the following
  10. * disclaimer in the documentation and/or other materials provided
  11. * with the distribution.
  12. * * Neither the name of The Linux Foundation nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  20. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  23. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  24. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  25. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  26. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #ifndef GNSSAUTOPOWERHANDLER_H
  29. #define GNSSAUTOPOWERHANDLER_H
  30. #include <utils/StrongPointer.h>
  31. #include <utils/RefBase.h>
  32. #include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
  33. #include <unordered_map>
  34. #include <dlfcn.h>
  35. #include <LocationAPI.h>
  36. using ::android::hardware::Return;
  37. using ::android::hardware::Void;
  38. using ::android::hardware::hidl_death_recipient;
  39. using ::android::sp;
  40. using ::android::wp;
  41. using ::android::hidl::base::V1_0::IBase;
  42. using ::android::hardware::automotive::vehicle::V2_0::IVehicleCallback;
  43. using ::android::hardware::hidl_vec;
  44. using ::android::hardware::automotive::vehicle::V2_0::VehiclePropValue;
  45. using ::android::hardware::automotive::vehicle::V2_0::StatusCode;
  46. using ::android::hardware::automotive::vehicle::V2_0::IVehicle;
  47. using ::android::hardware::automotive::vehicle::V2_0::SubscribeFlags;
  48. using ::android::hardware::automotive::vehicle::V2_0::SubscribeOptions;
  49. using ::android::hardware::automotive::vehicle::V2_0::VehicleApPowerStateReport;
  50. using ::android::hardware::automotive::vehicle::V2_0::VehiclePropConfig;
  51. using ::android::hardware::automotive::vehicle::V2_0::VehicleProperty;
  52. using ::android::hardware::automotive::vehicle::V2_0::VehiclePropValue;
  53. class GnssAutoPowerHandler : public IVehicleCallback {
  54. public:
  55. GnssAutoPowerHandler();
  56. ~GnssAutoPowerHandler();
  57. /* Overrides */
  58. Return<void> onPropertyEvent(const hidl_vec<VehiclePropValue>& propValues) override;
  59. Return<void> onPropertySet(const VehiclePropValue& propValue) override;
  60. Return<void> onPropertySetError(StatusCode errorCode, int32_t propId,
  61. int32_t areaId) override;
  62. void handleVHidlDeath(uint64_t cookie, const wp<IBase>& who);
  63. static GnssAutoPowerHandler* getGnssAutoPowerHandler();
  64. void sendPowerEventToLocCtrlApi(PowerStateType intPowerState);
  65. bool connectToVhal();
  66. void initializeGnssAutoPower();
  67. void handleGnssAutoPowerEvent(int32_t powerState);
  68. bool subscribeToVhal();
  69. bool isPropertySupported(int32_t prop);
  70. private:
  71. struct VHidlDeathRecipient : public hidl_death_recipient {
  72. public:
  73. explicit VHidlDeathRecipient(const android::sp<GnssAutoPowerHandler>& handler)
  74. : mHandler(handler) {
  75. }
  76. ~VHidlDeathRecipient() = default;
  77. void serviceDied(uint64_t cookie,
  78. const wp<IBase>& who) override;
  79. private:
  80. sp<GnssAutoPowerHandler> mHandler;
  81. }; //VHidlDeathRecipient
  82. android::Mutex mMutex;
  83. std::unordered_map<int32_t, bool> mSupportedProperties;
  84. sp<VHidlDeathRecipient> mVHidlDeathRecipient;
  85. sp<IVehicle> mVhalService GUARDED_BY(mMutex);
  86. LocationControlAPI *mLocationControlApi;
  87. }; //class PowerStateHandler
  88. #endif //GNSSAUTOPOWERHANDLER_H