GnssGeofencing.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2017-2018, 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. #ifndef ANDROID_HARDWARE_GNSS_V1_1_GNSSGEOFENCING_H
  21. #define ANDROID_HARDWARE_GNSS_V1_1_GNSSGEOFENCING_H
  22. #include <android/hardware/gnss/1.0/IGnssGeofencing.h>
  23. #include <hidl/Status.h>
  24. namespace android {
  25. namespace hardware {
  26. namespace gnss {
  27. namespace V1_1 {
  28. namespace implementation {
  29. using ::android::hardware::gnss::V1_0::IGnssGeofenceCallback;
  30. using ::android::hardware::gnss::V1_0::IGnssGeofencing;
  31. using ::android::hardware::Return;
  32. using ::android::hardware::Void;
  33. using ::android::hardware::hidl_vec;
  34. using ::android::hardware::hidl_string;
  35. using ::android::sp;
  36. class GeofenceAPIClient;
  37. struct GnssGeofencing : public IGnssGeofencing {
  38. inline GnssGeofencing(const sp<GnssGeofencing>& self) : mSelf(self), mApi(nullptr) {}
  39. ~GnssGeofencing();
  40. /*
  41. * Methods from ::android::hardware::gnss::V1_0::IGnssGeofencing follow.
  42. * These declarations were generated from IGnssGeofencing.hal.
  43. */
  44. Return<void> setCallback(const sp<IGnssGeofenceCallback>& callback) override;
  45. Return<void> addGeofence(int32_t geofenceId,
  46. double latitudeDegrees,
  47. double longitudeDegrees,
  48. double radiusMeters,
  49. IGnssGeofenceCallback::GeofenceTransition lastTransition,
  50. int32_t monitorTransitions,
  51. uint32_t notificationResponsivenessMs,
  52. uint32_t unknownTimerMs) override;
  53. Return<void> pauseGeofence(int32_t geofenceId) override;
  54. Return<void> resumeGeofence(int32_t geofenceId, int32_t monitorTransitions) override;
  55. Return<void> removeGeofence(int32_t geofenceId) override;
  56. private:
  57. // This method is not part of the IGnss base class.
  58. // It is called by GnssGeofencingDeathRecipient to remove all geofences added so far.
  59. Return<void> removeAllGeofences();
  60. private:
  61. struct GnssGeofencingDeathRecipient : hidl_death_recipient {
  62. GnssGeofencingDeathRecipient(const sp<GnssGeofencing>& gnssGeofencing) :
  63. mGnssGeofencing(gnssGeofencing) {
  64. }
  65. ~GnssGeofencingDeathRecipient() = default;
  66. virtual void serviceDied(uint64_t cookie, const wp<IBase>& who) override;
  67. const wp<GnssGeofencing> mGnssGeofencing;
  68. };
  69. void handleClientDeath();
  70. private:
  71. // this has to be a reference, not a copy
  72. // because the pointer is not set when mSelf is assigned
  73. const sp<GnssGeofencing>& mSelf;
  74. sp<GnssGeofencingDeathRecipient> mGnssGeofencingDeathRecipient = nullptr;
  75. sp<IGnssGeofenceCallback> mGnssGeofencingCbIface = nullptr;
  76. GeofenceAPIClient* mApi = nullptr;
  77. };
  78. } // namespace implementation
  79. } // namespace V1_1
  80. } // namespace gnss
  81. } // namespace hardware
  82. } // namespace android
  83. #endif // ANDROID_HARDWARE_GNSS_V1_1_GNSSGEOFENCING_H